From 7e68488a76e40d31ef3763bfa2b7a5fe0bbaca80 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Thu, 10 Mar 2022 09:57:59 +0800 Subject: [PATCH] shadingScale moved from PipelineSceneData to Pipeline (#10292) --- cocos/core/pipeline/custom/pipeline.ts | 2 + cocos/core/pipeline/pipeline-scene-data.ts | 8 +--- cocos/core/pipeline/render-pipeline.ts | 11 ++++++ cocos/core/platform/screen.ts | 2 +- .../cocos/bindings/auto/jsb_pipeline_auto.cpp | 39 +++++++++++++++++++ .../cocos/bindings/auto/jsb_render_auto.cpp | 39 +++++++++++++++++++ .../renderer/pipeline/RenderPipeline.cpp | 8 ++++ .../cocos/renderer/pipeline/RenderPipeline.h | 3 ++ .../pipeline/custom/RenderInterfaceTypes.h | 6 ++- native/tools/tojs/pipeline.ini | 2 +- native/tools/tojs/render.ini | 2 +- 11 files changed, 112 insertions(+), 10 deletions(-) diff --git a/cocos/core/pipeline/custom/pipeline.ts b/cocos/core/pipeline/custom/pipeline.ts index a27f7667f3..eacfbc023e 100644 --- a/cocos/core/pipeline/custom/pipeline.ts +++ b/cocos/core/pipeline/custom/pipeline.ts @@ -53,6 +53,8 @@ export abstract class PipelineRuntime { public abstract get constantMacros(): string; public abstract get profiler(): Model | null; public abstract set profiler(profiler: Model | null); + public abstract get shadingScale(): number; + public abstract set shadingScale(scale: number); public abstract onGlobalPipelineStateChanged(): void; } diff --git a/cocos/core/pipeline/pipeline-scene-data.ts b/cocos/core/pipeline/pipeline-scene-data.ts index bc3fef8dc2..0ce13d9787 100644 --- a/cocos/core/pipeline/pipeline-scene-data.ts +++ b/cocos/core/pipeline/pipeline-scene-data.ts @@ -29,7 +29,6 @@ import { Device, Framebuffer, InputAssembler, InputAssemblerInfo, Buffer, Buffer BufferUsageBit, MemoryUsageBit, Attribute, Format, Shader } from '../gfx'; import { RenderPipeline } from './render-pipeline'; import { Light } from '../renderer/scene/light'; -import { PipelineEventType } from './pipeline-event'; import { Material } from '../assets'; import { Pass } from '../renderer/core/pass'; @@ -53,10 +52,7 @@ export class PipelineSceneData { } public set shadingScale (val: number) { - if (this._shadingScale !== val) { - this._shadingScale = val; - this._pipeline.emit(PipelineEventType.ATTACHMENT_SCALE_CAHNGED, val); - } + this._shadingScale = val; } public fog: Fog = new Fog(); @@ -93,7 +89,7 @@ export class PipelineSceneData { protected _shadingScale = 1.0; constructor () { - this.shadingScale = 1.0; + this._shadingScale = 1.0; } public activate (device: Device, pipeline: RenderPipeline) { diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 71a4c66805..1085550ae4 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -376,6 +376,17 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent, Pi return out; } + public get shadingScale () { + return this._pipelineSceneData.shadingScale; + } + + public set shadingScale (val: number) { + if (this._pipelineSceneData.shadingScale !== val) { + this._pipelineSceneData.shadingScale = val; + this.emit(PipelineEventType.ATTACHMENT_SCALE_CAHNGED, val); + } + } + /** * @en Activate the render pipeline after loaded, it mainly activate the flows * @zh 当渲染管线资源加载完成后,启用管线,主要是启用管线内的 flow diff --git a/cocos/core/platform/screen.ts b/cocos/core/platform/screen.ts index 8fb951eb3d..42e606d744 100644 --- a/cocos/core/platform/screen.ts +++ b/cocos/core/platform/screen.ts @@ -46,7 +46,7 @@ class Screen { warnID(1220); return; } - director.root.pipeline.pipelineSceneData.shadingScale = screenAdapter.resolutionScale; + director.root.pipeline.shadingScale = screenAdapter.resolutionScale; }); } diff --git a/native/cocos/bindings/auto/jsb_pipeline_auto.cpp b/native/cocos/bindings/auto/jsb_pipeline_auto.cpp index 7745d7e18a..ed49d0c122 100644 --- a/native/cocos/bindings/auto/jsb_pipeline_auto.cpp +++ b/native/cocos/bindings/auto/jsb_pipeline_auto.cpp @@ -895,6 +895,25 @@ static bool js_pipeline_RenderPipeline_getScissor(se::State& s) // NOLINT(readab } SE_BIND_FUNC(js_pipeline_RenderPipeline_getScissor) +static bool js_pipeline_RenderPipeline_getShadingScale(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_pipeline_RenderPipeline_getShadingScale : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + float result = cobj->getShadingScale(); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_pipeline_RenderPipeline_getShadingScale : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC_AS_PROP_GET(js_pipeline_RenderPipeline_getShadingScale) + static bool js_pipeline_RenderPipeline_getViewport(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -1187,6 +1206,25 @@ static bool js_pipeline_RenderPipeline_setProfiler(se::State& s) // NOLINT(reada } SE_BIND_FUNC_AS_PROP_SET(js_pipeline_RenderPipeline_setProfiler) +static bool js_pipeline_RenderPipeline_setShadingScale(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_pipeline_RenderPipeline_setShadingScale : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + HolderType arg0 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_pipeline_RenderPipeline_setShadingScale : Error processing arguments"); + cobj->setShadingScale(arg0.value()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC_AS_PROP_SET(js_pipeline_RenderPipeline_setShadingScale) + static bool js_pipeline_RenderPipeline_setValue(se::State& s) // NOLINT(readability-identifier-naming) { CC_UNUSED bool ok = true; @@ -1310,6 +1348,7 @@ bool js_register_pipeline_RenderPipeline(se::Object* obj) // NOLINT(readability- cls->defineProperty("bloomEnabled", nullptr, _SE(js_pipeline_RenderPipeline_setBloomEnabled_asSetter)); cls->defineProperty("pipelineSceneData", _SE(js_pipeline_RenderPipeline_getPipelineSceneData_asGetter), nullptr); cls->defineProperty("profiler", _SE(js_pipeline_RenderPipeline_getProfiler_asGetter), _SE(js_pipeline_RenderPipeline_setProfiler_asSetter)); + cls->defineProperty("shadingScale", _SE(js_pipeline_RenderPipeline_getShadingScale_asGetter), _SE(js_pipeline_RenderPipeline_setShadingScale_asSetter)); cls->defineFunction("activate", _SE(js_pipeline_RenderPipeline_activate)); cls->defineFunction("createQuadInputAssembler", _SE(js_pipeline_RenderPipeline_createQuadInputAssembler)); cls->defineFunction("ensureEnoughSize", _SE(js_pipeline_RenderPipeline_ensureEnoughSize)); diff --git a/native/cocos/bindings/auto/jsb_render_auto.cpp b/native/cocos/bindings/auto/jsb_render_auto.cpp index 24fc6a3f15..81733e78c2 100644 --- a/native/cocos/bindings/auto/jsb_render_auto.cpp +++ b/native/cocos/bindings/auto/jsb_render_auto.cpp @@ -174,6 +174,25 @@ static bool js_render_PipelineRuntime_getProfiler(se::State& s) // NOLINT(readab } SE_BIND_FUNC_AS_PROP_GET(js_render_PipelineRuntime_getProfiler) +static bool js_render_PipelineRuntime_getShadingScale(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_render_PipelineRuntime_getShadingScale : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + float result = cobj->getShadingScale(); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_render_PipelineRuntime_getShadingScale : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC_AS_PROP_GET(js_render_PipelineRuntime_getShadingScale) + static bool js_render_PipelineRuntime_onGlobalPipelineStateChanged(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -227,6 +246,25 @@ static bool js_render_PipelineRuntime_setProfiler(se::State& s) // NOLINT(readab } SE_BIND_FUNC_AS_PROP_SET(js_render_PipelineRuntime_setProfiler) +static bool js_render_PipelineRuntime_setShadingScale(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_render_PipelineRuntime_setShadingScale : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + HolderType arg0 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_render_PipelineRuntime_setShadingScale : Error processing arguments"); + cobj->setShadingScale(arg0.value()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC_AS_PROP_SET(js_render_PipelineRuntime_setShadingScale) + bool js_register_render_PipelineRuntime(se::Object* obj) // NOLINT(readability-identifier-naming) { auto* cls = se::Class::create("PipelineRuntime", obj, nullptr, nullptr); @@ -237,6 +275,7 @@ bool js_register_render_PipelineRuntime(se::Object* obj) // NOLINT(readability-i cls->defineProperty("pipelineSceneData", _SE(js_render_PipelineRuntime_getPipelineSceneData_asGetter), nullptr); cls->defineProperty("constantMacros", _SE(js_render_PipelineRuntime_getConstantMacros_asGetter), nullptr); cls->defineProperty("profiler", _SE(js_render_PipelineRuntime_getProfiler_asGetter), _SE(js_render_PipelineRuntime_setProfiler_asSetter)); + cls->defineProperty("shadingScale", _SE(js_render_PipelineRuntime_getShadingScale_asGetter), _SE(js_render_PipelineRuntime_setShadingScale_asSetter)); cls->defineFunction("activate", _SE(js_render_PipelineRuntime_activate)); cls->defineFunction("destroy", _SE(js_render_PipelineRuntime_destroy)); cls->defineFunction("onGlobalPipelineStateChanged", _SE(js_render_PipelineRuntime_onGlobalPipelineStateChanged)); diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index 0335b89821..a8d6517d82 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -258,6 +258,14 @@ gfx::Rect RenderPipeline::getRenderArea(scene::Camera *camera) { }; } +float RenderPipeline::getShadingScale() const { + return _pipelineSceneData->getShadingScale(); +} + +void RenderPipeline::setShadingScale(float scale) { + _pipelineSceneData->setShadingScale(scale); +} + void RenderPipeline::genQuadVertexData(const Vec4 &viewport, float *vbData) { auto minX = static_cast(viewport.x); auto maxX = static_cast(viewport.x + viewport.z); diff --git a/native/cocos/renderer/pipeline/RenderPipeline.h b/native/cocos/renderer/pipeline/RenderPipeline.h index 59c240ef23..ff0edd1026 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.h +++ b/native/cocos/renderer/pipeline/RenderPipeline.h @@ -110,6 +110,9 @@ public: void ensureEnoughSize(const vector &cameras); bool createQuadInputAssembler(gfx::Buffer *quadIB, gfx::Buffer **quadVB, gfx::InputAssembler **quadIA); + float getShadingScale() const; + void setShadingScale(float scale); + inline scene::Model *getProfiler() const { return _profiler; } inline void setProfiler(scene::Model *value) { _profiler = value; } diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index e7627f4712..d000a5e9d5 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -89,7 +89,11 @@ public: virtual const std::string &getConstantMacros() const = 0; virtual scene::Model *getProfiler() const = 0; virtual void setProfiler(scene::Model *profiler) const = 0; - virtual void onGlobalPipelineStateChanged() = 0; + + virtual float getShadingScale() const = 0; + virtual void setShadingScale(float scale) = 0; + + virtual void onGlobalPipelineStateChanged() = 0; }; inline PipelineRuntime::~PipelineRuntime() noexcept = default; diff --git a/native/tools/tojs/pipeline.ini b/native/tools/tojs/pipeline.ini index 899ac491df..fe11be22c8 100644 --- a/native/tools/tojs/pipeline.ini +++ b/native/tools/tojs/pipeline.ini @@ -61,7 +61,7 @@ skip = ForwardPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLi rename_functions = -getter_setter= RenderPipeline::[globalDSManager descriptorSet descriptorSetLayout constantMacros clusterEnabled bloomEnabled pipelineSceneData profiler], +getter_setter= RenderPipeline::[globalDSManager descriptorSet descriptorSetLayout constantMacros clusterEnabled bloomEnabled pipelineSceneData profiler shadingScale], PipelineSceneData::[isHDR/isHDR/setHDR shadingScale fog ambient skybox shadows/getShadows], BloomStage::[threshold intensity iterations] diff --git a/native/tools/tojs/render.ini b/native/tools/tojs/render.ini index 95472d6db7..fb3aa4d3e8 100644 --- a/native/tools/tojs/render.ini +++ b/native/tools/tojs/render.ini @@ -52,7 +52,7 @@ skip = SceneVisitor::[updateBuffer] skip_public_fields = -getter_setter = PipelineRuntime::[macros globalDSManager descriptorSetLayout pipelineSceneData constantMacros profiler], +getter_setter = PipelineRuntime::[macros globalDSManager descriptorSetLayout pipelineSceneData constantMacros profiler shadingScale], SceneTask::[taskType] rename_functions =