From 523d9828fee46973d38817a4c651e4dcfc804898 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Fri, 7 Feb 2025 14:01:45 +0800 Subject: [PATCH] remove deferred reflection shaders (#18281) * remove deferred reflection shaders * fix test shader * remove reflectionTex --- cocos/render-scene/scene/submodel.ts | 53 +-- cocos/rendering/define.ts | 43 +-- .../uniforms/cc-reflection-probe.chunk | 8 +- .../builtin-reflection-deferred.effect | 253 ------------- .../builtin-reflection-deferred.effect.meta | 11 - native/cocos/base/TypeDef.h | 32 +- native/cocos/renderer/pipeline/Define.cpp | 60 +--- native/cocos/renderer/pipeline/Define.h | 28 +- .../pipeline/GlobalDescriptorSetManager.cpp | 4 - .../pipeline/deferred/LightingStage.cpp | 334 +----------------- .../pipeline/deferred/LightingStage.h | 1 - .../pipeline/deferred/ReflectionComp.cpp | 212 +---------- native/cocos/scene/SubModel.cpp | 40 +-- native/cocos/scene/SubModel.h | 48 ++- ...PORT_CASCADED_SHADOW_MAP1_CC_USE_HDR1.frag | 4 +- 15 files changed, 107 insertions(+), 1024 deletions(-) delete mode 100644 editor/assets/effects/internal/builtin-reflection-deferred.effect delete mode 100644 editor/assets/effects/internal/builtin-reflection-deferred.effect.meta diff --git a/cocos/render-scene/scene/submodel.ts b/cocos/render-scene/scene/submodel.ts index 1314583796..e0420500e0 100644 --- a/cocos/render-scene/scene/submodel.ts +++ b/cocos/render-scene/scene/submodel.ts @@ -23,15 +23,14 @@ */ import { RenderingSubMesh } from '../../asset/assets/rendering-sub-mesh'; -import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING, - INST_MAT_WORLD, INST_SH, isEnableEffect, +import { RenderPriority, + INST_MAT_WORLD, INST_SH, UBOSHEnum } from '../../rendering/define'; import { BatchingSchemes, IMacroPatch, Pass } from '../core/pass'; -import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, TextureType, TextureUsageBit, TextureInfo, - Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager, +import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, + Sampler, Shader, deviceManager, Attribute, Feature, FormatInfos, getTypedArrayConstructor } from '../../gfx'; import { errorID, Mat4, cclegacy } from '../../core'; -import { getPhaseID } from '../../rendering/pass-phase'; import { Root } from '../../root'; const _dsInfo = new DescriptorSetInfo(null!); @@ -59,8 +58,6 @@ export class SubModel { protected _inputAssembler: InputAssembler | null = null; protected _descriptorSet: DescriptorSet | null = null; protected _worldBoundDescriptorSet: DescriptorSet | null = null; - protected _reflectionTex: Texture | null = null; - protected _reflectionSampler: Sampler | null = null; protected _instancedAttributeBlock: IInstancedAttributeBlock = { buffer: null!, views: [], attributes: [] }; protected _instancedWorldMatrixIndex = -1; protected _instancedSHIndex = -1; @@ -239,44 +236,6 @@ export class SubModel { this._flushPassInfo(); this.priority = RenderPriority.DEFAULT; - - const r = cclegacy.rendering; - // initialize resources for reflection material - if (((!r || !r.enableEffectImport) && passes[0].phase === getPhaseID('reflection')) - || (isEnableEffect() && passes[0].phaseID === r.getPhaseID(r.getPassID('default'), 'reflection'))) { - let texWidth = root.mainWindow!.width; - let texHeight = root.mainWindow!.height; - const minSize = 512; - - if (texHeight < texWidth) { - texWidth = minSize * texWidth / texHeight; - texHeight = minSize; - } else { - texWidth = minSize; - texHeight = minSize * texHeight / texWidth; - } - - this._reflectionTex = this._device.createTexture(new TextureInfo( - TextureType.TEX2D, - TextureUsageBit.STORAGE | TextureUsageBit.TRANSFER_SRC | TextureUsageBit.SAMPLED, - Format.RGBA8, - texWidth, - texHeight, - )); - - this.descriptorSet.bindTexture(UNIFORM_REFLECTION_TEXTURE_BINDING, this._reflectionTex); - - this._reflectionSampler = this._device.getSampler(new SamplerInfo( - Filter.LINEAR, - Filter.LINEAR, - Filter.NONE, - Address.CLAMP, - Address.CLAMP, - Address.CLAMP, - )); - this.descriptorSet.bindSampler(UNIFORM_REFLECTION_TEXTURE_BINDING, this._reflectionSampler); - this.descriptorSet.bindTexture(UNIFORM_REFLECTION_STORAGE_BINDING, this._reflectionTex); - } } /** @@ -304,10 +263,6 @@ export class SubModel { this._passes = null; this._shaders = null; - - if (this._reflectionTex) this._reflectionTex.destroy(); - this._reflectionTex = null; - this._reflectionSampler = null; } /** diff --git a/cocos/rendering/define.ts b/cocos/rendering/define.ts index 49277be6d8..127022adf0 100644 --- a/cocos/rendering/define.ts +++ b/cocos/rendering/define.ts @@ -149,9 +149,6 @@ export enum ModelLocalBindings { SAMPLER_MORPH_TANGENT, SAMPLER_LIGHTMAP, SAMPLER_SPRITE, - SAMPLER_REFLECTION, - - STORAGE_REFLECTION, SAMPLER_REFLECTION_PROBE_CUBE, SAMPLER_REFLECTION_PROBE_PLANAR, @@ -161,7 +158,7 @@ export enum ModelLocalBindings { COUNT, } const LOCAL_UBO_COUNT = ModelLocalBindings.SAMPLER_JOINTS; -const LOCAL_SAMPLER_COUNT = ModelLocalBindings.STORAGE_REFLECTION - LOCAL_UBO_COUNT; +const LOCAL_SAMPLER_COUNT = ModelLocalBindings.COUNT - LOCAL_UBO_COUNT; const LOCAL_STORAGE_IMAGE_COUNT = ModelLocalBindings.COUNT - LOCAL_UBO_COUNT - LOCAL_SAMPLER_COUNT; export enum SetIndex { @@ -950,44 +947,6 @@ const UNIFORM_SPRITE_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, localDescriptorSetLayout.layouts[UNIFORM_SPRITE_TEXTURE_NAME] = UNIFORM_SPRITE_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_SPRITE_TEXTURE_BINDING] = UNIFORM_SPRITE_TEXTURE_DESCRIPTOR; -/** - * @en The sampler for reflection - * @zh 反射纹理采样器。 - */ -const UNIFORM_REFLECTION_TEXTURE_NAME = 'cc_reflectionTexture'; -export const UNIFORM_REFLECTION_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_REFLECTION; -const UNIFORM_REFLECTION_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding( - UNIFORM_REFLECTION_TEXTURE_BINDING, - DescriptorType.SAMPLER_TEXTURE, - 1, - ShaderStageFlagBit.FRAGMENT, - MemoryAccessBit.READ_ONLY, - ViewDimension.TEX2D, -); -const UNIFORM_REFLECTION_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_TEXTURE_NAME, Type.SAMPLER2D, 1); -localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_TEXTURE_NAME] = UNIFORM_REFLECTION_TEXTURE_LAYOUT; -localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_TEXTURE_BINDING] = UNIFORM_REFLECTION_TEXTURE_DESCRIPTOR; - -/** - * @en The storage image for reflection - * @zh 反射纹理存储。 - */ -const UNIFORM_REFLECTION_STORAGE_NAME = 'cc_reflectionStorage'; -export const UNIFORM_REFLECTION_STORAGE_BINDING = ModelLocalBindings.STORAGE_REFLECTION; -const UNIFORM_REFLECTION_STORAGE_DESCRIPTOR = new DescriptorSetLayoutBinding( - UNIFORM_REFLECTION_STORAGE_BINDING, - DescriptorType.STORAGE_IMAGE, - 1, - ShaderStageFlagBit.COMPUTE, - MemoryAccessBit.READ_WRITE, - ViewDimension.TEX2D, - SampleType.FLOAT, - Format.RGBA8, -); -const UNIFORM_REFLECTION_STORAGE_LAYOUT = new UniformStorageImage(SetIndex.LOCAL, UNIFORM_REFLECTION_STORAGE_BINDING, UNIFORM_REFLECTION_STORAGE_NAME, Type.IMAGE2D, 1); -localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_STORAGE_NAME] = UNIFORM_REFLECTION_STORAGE_LAYOUT; -localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_STORAGE_BINDING] = UNIFORM_REFLECTION_STORAGE_DESCRIPTOR; - /** * @en The sampler for reflection probe cubemap * @zh 反射探针立方体贴图纹理采样器。 diff --git a/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk b/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk index 2bdef8a06e..8905121dc2 100644 --- a/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk +++ b/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk @@ -1,13 +1,13 @@ // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. #pragma builtin(local) -layout(set = 2, binding = 15) uniform samplerCube cc_reflectionProbeCubemap; +layout(set = 2, binding = 13) uniform samplerCube cc_reflectionProbeCubemap; #pragma builtin(local) -layout(set = 2, binding = 16) uniform sampler2D cc_reflectionProbePlanarMap; +layout(set = 2, binding = 14) uniform sampler2D cc_reflectionProbePlanarMap; #pragma builtin(local) -layout(set = 2, binding = 17) uniform sampler2D cc_reflectionProbeDataMap; +layout(set = 2, binding = 15) uniform sampler2D cc_reflectionProbeDataMap; #pragma builtin(local) -layout(set = 2, binding = 18) uniform samplerCube cc_reflectionProbeBlendCubemap; +layout(set = 2, binding = 16) uniform samplerCube cc_reflectionProbeBlendCubemap; diff --git a/editor/assets/effects/internal/builtin-reflection-deferred.effect b/editor/assets/effects/internal/builtin-reflection-deferred.effect deleted file mode 100644 index 3757d60777..0000000000 --- a/editor/assets/effects/internal/builtin-reflection-deferred.effect +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. - -CCEffect %{ - techniques: - - passes: - - vert: standard-vs - frag: standard-fs - phase: reflection - depthStencilState: - depthTest: true - depthWrite: false - blendState: - targets: - - blend: true - blendSrc: src_alpha - blendDst: one_minus_src_alpha - blendDstAlpha: one_minus_src_alpha - properties: &props - tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } - mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } } - albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } - alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } - occlusion: { value: 0.0, target: pbrParams.x } - roughness: { value: 0.8, target: pbrParams.y } - metallic: { value: 0.6, target: pbrParams.z } - normalStrenth: { value: 1.0, target: pbrParams.w, editor: { parent: USE_NORMAL_MAP } } - emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } - emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz } - mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } - normalMap: { value: normal } - pbrMap: { value: grey } - metallicRoughnessMap: { value: grey } - occlusionMap: { value: white } - emissiveMap: { value: grey } -}% - -CCProgram shared-ubos %{ - uniform Constants { - vec4 tilingOffset; - vec4 albedo; - vec4 albedoScaleAndCutoff; - vec4 pbrParams; - vec4 emissive; - vec4 emissiveScaleParam; - }; -}% - -CCProgram standard-vs %{ - precision highp float; - #include - #include - #include - #include - #include - #include - #include - #include - - #if USE_VERTEX_COLOR - in vec4 a_color; - out vec4 v_color; - #endif - - out vec3 v_position; - out vec3 v_normal; - out vec2 v_uv; - out vec2 v_uv1; - - #if USE_NORMAL_MAP - out vec3 v_tangent; - out vec3 v_bitangent; - #endif - - #if HAS_SECOND_UV || CC_USE_LIGHTMAP - in vec2 a_texCoord1; - #endif - - #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD - #include - #endif - - void main () { - StandardVertInput In; - CCVertInput(In); - - mat4 matWorld, matWorldIT; - CCGetWorldMatrixFull(matWorld, matWorldIT); - - vec4 pos = matWorld * In.position; - - v_position = pos.xyz; - v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz); - #if USE_NORMAL_MAP - v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz); - v_bitangent = cross(v_normal, v_tangent) * In.tangent.w; // note the cross order - #endif - - v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw; - #if HAS_SECOND_UV - v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw; - #endif - - #if USE_VERTEX_COLOR - v_color = a_color; - #endif - - CC_TRANSFER_FOG(pos); - CC_TRANSFER_SHADOW(pos); - CC_TRANSFER_SH(); - - #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD - CCLightingMapCaclUV(); - #endif - - - gl_Position = cc_matProj * (cc_matView * matWorld) * In.position; - } -}% - -CCProgram standard-fs %{ - precision highp float; - #include - #include - #include - #include - #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD - #include - #endif - - in vec3 v_position; - in vec2 v_uv; - in vec2 v_uv1; - in vec3 v_normal; - - #if USE_VERTEX_COLOR - in vec4 v_color; - #endif - - #if USE_ALBEDO_MAP - uniform sampler2D albedoMap; - #pragma define-meta ALBEDO_UV options([v_uv, v_uv1]) - #endif - #if USE_NORMAL_MAP - in vec3 v_tangent; - in vec3 v_bitangent; - uniform sampler2D normalMap; - #pragma define-meta NORMAL_UV options([v_uv, v_uv1]) - #endif - #pragma define-meta PBR_UV options([v_uv, v_uv1]) - #if USE_PBR_MAP - uniform sampler2D pbrMap; - #endif - #if USE_METALLIC_ROUGHNESS_MAP - uniform sampler2D metallicRoughnessMap; - #endif - #if USE_OCCLUSION_MAP - uniform sampler2D occlusionMap; - #endif - #if USE_EMISSIVE_MAP - uniform sampler2D emissiveMap; - #pragma define-meta EMISSIVE_UV options([v_uv, v_uv1]) - #endif - - #pragma define OCCLUSION_CHANNEL r - #pragma define ROUGHNESS_CHANNEL g - #pragma define METALLIC_CHANNEL b - - #if USE_ALPHA_TEST - #pragma define-meta ALPHA_TEST_CHANNEL options([a, r]) - #endif - - void surf (out StandardSurface s) { - vec4 baseColor = albedo; - #if USE_VERTEX_COLOR - baseColor *= v_color; - #endif - #if USE_ALBEDO_MAP - vec4 texColor = texture(albedoMap, ALBEDO_UV); - texColor.rgb = SRGBToLinear(texColor.rgb); - baseColor *= texColor; - #endif - s.albedo = baseColor; - s.albedo.rgb *= albedoScaleAndCutoff.xyz; - - #if USE_ALPHA_TEST - if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; - #endif - - s.normal = v_normal; - #if USE_NORMAL_MAP - vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5); - s.normal = - (nmmp.x * pbrParams.w) * normalize(v_tangent) + - (nmmp.y * pbrParams.w) * normalize(v_bitangent) + - nmmp.z * normalize(s.normal); - #endif - - #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD - SampleAndDecodeLightMapColor(s.lightmap.rgb, s.lightmap.a, s.lightmap_test, cc_lightingMap, v_luv.xy, v_luv.z, s.normal); - #endif - - HIGHP_VALUE_TO_STRUCT_DEFINED(v_position, s.position); - - vec4 pbr = pbrParams; - pbr.x = 1.0 - pbr.x; - #if USE_PBR_MAP - vec4 res = texture(pbrMap, PBR_UV); - pbr.x *= res.OCCLUSION_CHANNEL; - pbr.y *= res.ROUGHNESS_CHANNEL; - pbr.z *= res.METALLIC_CHANNEL; - #endif - #if USE_METALLIC_ROUGHNESS_MAP - vec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV); - pbr.z *= metallicRoughness.METALLIC_CHANNEL; - pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL; - #endif - #if USE_OCCLUSION_MAP - pbr.x *= texture(occlusionMap, PBR_UV).OCCLUSION_CHANNEL; - #endif - s.occlusion = pbr.x; - s.roughness = pbr.y; - s.specularIntensity = 0.5; - s.metallic = pbr.z; - - s.emissive = emissive.rgb * emissiveScaleParam.xyz; - #if USE_EMISSIVE_MAP - s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb); - #endif - } - - #pragma builtin(local) - layout(set = 2, binding = 13) uniform sampler2D cc_reflectionTexture; - - layout(location = 0) out vec4 fragColorX; - - void main () { - StandardSurface s; surf(s); - vec4 color = CCStandardShadingBase(s, CC_SHADOW_POSITION); - CC_APPLY_FOG(color, s.position.xyz); - vec4 baseColor = CCFragOutput(color); - - vec2 noise = v_normal.xy * 0.02; - #if USE_NORMAL_MAP - noise = texture(normalMap, ALBEDO_UV).xy * 0.02; - #endif - - vec2 resolution = cc_screenSize.xy; - vec2 uv = (gl_FragCoord.xy / resolution) + noise; - vec4 reflectionColor = texture(cc_reflectionTexture, uv); - fragColorX = mix(baseColor, reflectionColor, 0.5); - fragColorX.w = 1.0; - } -}% \ No newline at end of file diff --git a/editor/assets/effects/internal/builtin-reflection-deferred.effect.meta b/editor/assets/effects/internal/builtin-reflection-deferred.effect.meta deleted file mode 100644 index 672651d87a..0000000000 --- a/editor/assets/effects/internal/builtin-reflection-deferred.effect.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "1.7.1", - "importer": "effect", - "imported": true, - "uuid": "99498f84-efe6-43a6-a9a7-e6e93eb845c1", - "files": [ - ".json" - ], - "subMetas": {}, - "userData": {} -} diff --git a/native/cocos/base/TypeDef.h b/native/cocos/base/TypeDef.h index 5a05a7534e..7f5997649c 100644 --- a/native/cocos/base/TypeDef.h +++ b/native/cocos/base/TypeDef.h @@ -40,32 +40,32 @@ using index_t = int32_t; #define CC_INVALID_INDEX (-1) #define CC_ENUM_CONVERSION_OPERATOR(T) \ - inline std::underlying_type::type toNumber(const T v) { return static_cast::type>(v); } + inline std::underlying_type_t toNumber(const T v) { return static_cast>(v); } #define CC_ENUM_BITWISE_OPERATORS(T) \ - constexpr bool operator!(const T v) { return !static_cast::type>(v); } \ - constexpr T operator~(const T v) { return static_cast(~static_cast::type>(v)); } \ - constexpr bool operator||(const T lhs, const T rhs) { return (static_cast::type>(lhs) || static_cast::type>(rhs)); } \ - constexpr bool operator&&(const T lhs, const T rhs) { return (static_cast::type>(lhs) && static_cast::type>(rhs)); } \ - constexpr T operator|(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) | static_cast::type>(rhs)); } \ - constexpr T operator&(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) & static_cast::type>(rhs)); } \ - constexpr T operator^(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) ^ static_cast::type>(rhs)); } \ - constexpr T operator+(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) + static_cast::type>(rhs)); } \ - constexpr T operator+(const T lhs, bool rhs) { return static_cast(static_cast::type>(lhs) + rhs); } \ - constexpr void operator|=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) | static_cast::type>(rhs)); } \ - constexpr void operator&=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) & static_cast::type>(rhs)); } \ - constexpr void operator^=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) ^ static_cast::type>(rhs)); } \ + constexpr bool operator!(const T v) { return !static_cast>(v); } \ + constexpr T operator~(const T v) { return static_cast(~static_cast>(v)); } \ + constexpr bool operator||(const T lhs, const T rhs) { return (static_cast>(lhs) || static_cast>(rhs)); } \ + constexpr bool operator&&(const T lhs, const T rhs) { return (static_cast>(lhs) && static_cast>(rhs)); } \ + constexpr T operator|(const T lhs, const T rhs) { return static_cast(static_cast>(lhs) | static_cast>(rhs)); } \ + constexpr T operator&(const T lhs, const T rhs) { return static_cast(static_cast>(lhs) & static_cast>(rhs)); } \ + constexpr T operator^(const T lhs, const T rhs) { return static_cast(static_cast>(lhs) ^ static_cast>(rhs)); } \ + constexpr T operator+(const T lhs, const T rhs) { return static_cast(static_cast>(lhs) + static_cast>(rhs)); } \ + constexpr T operator+(const T lhs, bool rhs) { return static_cast(static_cast>(lhs) + rhs); } \ + constexpr void operator|=(T &lhs, const T rhs) { lhs = static_cast(static_cast>(lhs) | static_cast>(rhs)); } \ + constexpr void operator&=(T &lhs, const T rhs) { lhs = static_cast(static_cast>(lhs) & static_cast>(rhs)); } \ + constexpr void operator^=(T &lhs, const T rhs) { lhs = static_cast(static_cast>(lhs) ^ static_cast>(rhs)); } \ constexpr bool hasFlag(const T flags, const T flagToTest) { \ - using ValueType = std::underlying_type::type; \ + using ValueType = std::underlying_type_t; \ CC_ASSERT((static_cast(flagToTest) & (static_cast(flagToTest) - 1)) == 0); \ return (static_cast(flags) & static_cast(flagToTest)) != 0; \ } \ constexpr bool hasAnyFlags(const T flags, const T flagsToTest) { \ - using ValueType = std::underlying_type::type; \ + using ValueType = std::underlying_type_t; \ return (static_cast(flags) & static_cast(flagsToTest)) != 0; \ } \ constexpr bool hasAllFlags(const T flags, const T flagsToTest) { \ - using ValueType = std::underlying_type::type; \ + using ValueType = std::underlying_type_t; \ return (static_cast(flags) & static_cast(flagsToTest)) == static_cast(flagsToTest); \ } \ constexpr T addFlags(T &flags, const T flagsToAdd) { \ diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index 483a0634a3..ea09f2bf3b 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -30,24 +30,28 @@ namespace cc { namespace pipeline { -static uint32_t globalUBOCount = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); -static uint32_t globalSamplerCount = static_cast(PipelineGlobalBindings::COUNT) - globalUBOCount; +namespace { -static uint32_t localUBOCount = static_cast(ModelLocalBindings::SAMPLER_JOINTS); -static uint32_t localSamplerCount = static_cast(ModelLocalBindings::STORAGE_REFLECTION) - localUBOCount; -static uint32_t localStorageImageCount = static_cast(ModelLocalBindings::COUNT) - localUBOCount - localSamplerCount; +constexpr uint32_t GLOBAL_UBO_COUNT = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); +constexpr uint32_t GLOBAL_SAMPLER_COUNT = static_cast(PipelineGlobalBindings::COUNT) - GLOBAL_UBO_COUNT; + +constexpr uint32_t LOCAL_UBO_COUNT = static_cast(ModelLocalBindings::SAMPLER_JOINTS); +constexpr uint32_t LOCAL_SAMPLER_COUNT = static_cast(ModelLocalBindings::COUNT) - LOCAL_UBO_COUNT; +constexpr uint32_t LOCAL_STORAGE_IMAGE_COUNT = static_cast(ModelLocalBindings::COUNT) - LOCAL_UBO_COUNT - LOCAL_SAMPLER_COUNT; + +} // namespace uint32_t globalSet = static_cast(SetIndex::GLOBAL); uint32_t materialSet = static_cast(SetIndex::MATERIAL); uint32_t localSet = static_cast(SetIndex::LOCAL); gfx::BindingMappingInfo bindingMappingInfo = { - {globalUBOCount, 0, localUBOCount, 0}, // Uniform Buffer Counts - {globalSamplerCount, 0, localSamplerCount, 0}, // Combined Sampler Texture Counts + {GLOBAL_UBO_COUNT, 0, LOCAL_UBO_COUNT, 0}, // Uniform Buffer Counts + {GLOBAL_SAMPLER_COUNT, 0, LOCAL_SAMPLER_COUNT, 0}, // Combined Sampler Texture Counts {0, 0, 0, 0}, // Sampler Counts {0, 0, 0, 0}, // Texture Counts {0, 0, 0, 0}, // Storage Buffer Counts - {0, 0, localStorageImageCount, 0}, // Storage Image Counts + {0, 0, LOCAL_STORAGE_IMAGE_COUNT, 0}, // Storage Image Counts {0, 0, 0, 0}, // Subpass Input Counts {0, 2, 1, 3}, // Set Order Indices }; @@ -549,38 +553,6 @@ const gfx::UniformSamplerTexture SPRITETEXTURE::LAYOUT = { 1, }; -const ccstd::string REFLECTIONTEXTURE::NAME = "cc_reflectionTexture"; -const gfx::DescriptorSetLayoutBinding REFLECTIONTEXTURE::DESCRIPTOR = { - REFLECTIONTEXTURE::BINDING, - gfx::DescriptorType::SAMPLER_TEXTURE, - 1, - gfx::ShaderStageFlagBit::FRAGMENT, - {}, -}; -const gfx::UniformSamplerTexture REFLECTIONTEXTURE::LAYOUT = { - localSet, - static_cast(ModelLocalBindings::SAMPLER_REFLECTION), - "cc_reflectionTexture", - gfx::Type::SAMPLER2D, - 1, -}; - -const ccstd::string REFLECTIONSTORAGE::NAME = "cc_reflectionStorage"; -const gfx::DescriptorSetLayoutBinding REFLECTIONSTORAGE::DESCRIPTOR = { - REFLECTIONSTORAGE::BINDING, - gfx::DescriptorType::STORAGE_IMAGE, - 1, - gfx::ShaderStageFlagBit::COMPUTE, - {}, -}; -const gfx::UniformStorageImage REFLECTIONSTORAGE::LAYOUT = { - localSet, - static_cast(ModelLocalBindings::STORAGE_REFLECTION), - "cc_reflectionStorage", - gfx::Type::IMAGE2D, - 1, -}; - const ccstd::string REFLECTIONPROBECUBEMAP::NAME = "cc_reflectionProbeCubemap"; const gfx::DescriptorSetLayoutBinding REFLECTIONPROBECUBEMAP::DESCRIPTOR = { REFLECTIONPROBECUBEMAP::BINDING, @@ -672,8 +644,12 @@ bool supportsRGBA32FloatTexture(const gfx::Device* device) { return hasAllFlags(device->getFormatFeatures(gfx::Format::RGBA32F), gfx::FormatFeature::RENDER_TARGET | gfx::FormatFeature::SAMPLED_TEXTURE); } -static ccstd::unordered_map phases; //cjh how to clear this global variable when exiting game? -static uint32_t phaseNum = 0; +namespace { + +ccstd::unordered_map phases; //cjh how to clear this global variable when exiting game? +uint32_t phaseNum = 0; + +} // namespace uint32_t getPhaseID(const ccstd::string& phaseName) { const auto iter = phases.find(phaseName); diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index 30ae82ac3e..01d8603a7d 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -120,6 +120,7 @@ using RenderFlowList = ccstd::vector>; using LightList = ccstd::vector; using UintList = ccstd::vector; +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL RenderPassStage { DEFAULT = 100, UI = 200, @@ -145,6 +146,7 @@ struct CC_DLL RenderQueueCreateInfo { std::function sortFunc; }; +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL RenderPriority { MIN = 0, MAX = 0xff, @@ -152,6 +154,7 @@ enum class CC_DLL RenderPriority { }; CC_ENUM_CONVERSION_OPERATOR(RenderPriority) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL RenderQueueSortMode { FRONT_TO_BACK, BACK_TO_FRONT, @@ -225,6 +228,7 @@ inline RenderQueueSortFunc convertQueueSortFunc(const RenderQueueSortMode &mode) return sortFunc; } +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL PipelineGlobalBindings { UBO_GLOBAL, UBO_CAMERA, @@ -240,6 +244,7 @@ enum class CC_DLL PipelineGlobalBindings { }; CC_ENUM_CONVERSION_OPERATOR(PipelineGlobalBindings) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL ModelLocalBindings { UBO_LOCAL, UBO_FORWARD_LIGHTS, @@ -255,9 +260,6 @@ enum class CC_DLL ModelLocalBindings { SAMPLER_MORPH_TANGENT, SAMPLER_LIGHTMAP, SAMPLER_SPRITE, - SAMPLER_REFLECTION, - - STORAGE_REFLECTION, SAMPLER_REFLECTION_PROBE_CUBE, SAMPLER_REFLECTION_PROBE_PLANAR, @@ -267,6 +269,7 @@ enum class CC_DLL ModelLocalBindings { }; CC_ENUM_CONVERSION_OPERATOR(ModelLocalBindings) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL SetIndex { GLOBAL, MATERIAL, @@ -406,6 +409,7 @@ struct CC_DLL UBOSH { static const ccstd::string NAME; }; +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL ForwardStagePriority { AR = 5, FORWARD = 10, @@ -413,6 +417,7 @@ enum class CC_DLL ForwardStagePriority { }; CC_ENUM_CONVERSION_OPERATOR(ForwardStagePriority) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL ForwardFlowPriority { SHADOW = 0, FORWARD = 1, @@ -420,6 +425,7 @@ enum class CC_DLL ForwardFlowPriority { }; CC_ENUM_CONVERSION_OPERATOR(ForwardFlowPriority) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL RenderFlowTag { SCENE, POSTPROCESS, @@ -427,6 +433,7 @@ enum class CC_DLL RenderFlowTag { }; CC_ENUM_CONVERSION_OPERATOR(RenderFlowTag) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL DeferredStagePriority { GBUFFER = 10, LIGHTING = 15, @@ -437,6 +444,7 @@ enum class CC_DLL DeferredStagePriority { }; CC_ENUM_CONVERSION_OPERATOR(DeferredStagePriority) +// NOLINTNEXTLINE(performance-enum-size) enum class CC_DLL DeferredFlowPriority { SHADOW = 0, MAIN = 1, @@ -641,20 +649,6 @@ struct CC_DLL SPRITETEXTURE { static const ccstd::string NAME; }; -struct CC_DLL REFLECTIONTEXTURE { - static constexpr uint32_t BINDING = static_cast(ModelLocalBindings::SAMPLER_REFLECTION); - static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; - static const gfx::UniformSamplerTexture LAYOUT; - static const ccstd::string NAME; -}; - -struct CC_DLL REFLECTIONSTORAGE { - static constexpr uint32_t BINDING = static_cast(ModelLocalBindings::STORAGE_REFLECTION); - static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; - static const gfx::UniformStorageImage LAYOUT; - static const ccstd::string NAME; -}; - struct CC_DLL REFLECTIONPROBECUBEMAP { static constexpr uint32_t BINDING = static_cast(ModelLocalBindings::SAMPLER_REFLECTION_PROBE_CUBE); static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp index ae8ce3b96f..1f90d6217f 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp @@ -226,10 +226,6 @@ void GlobalDSManager::setDescriptorSetLayout() { localDescriptorSetLayout.bindings[LIGHTMAPTEXTURE::BINDING] = LIGHTMAPTEXTURE::DESCRIPTOR; localDescriptorSetLayout.samplers[SPRITETEXTURE::NAME] = SPRITETEXTURE::LAYOUT; localDescriptorSetLayout.bindings[SPRITETEXTURE::BINDING] = SPRITETEXTURE::DESCRIPTOR; - localDescriptorSetLayout.samplers[REFLECTIONTEXTURE::NAME] = REFLECTIONTEXTURE::LAYOUT; - localDescriptorSetLayout.bindings[REFLECTIONTEXTURE::BINDING] = REFLECTIONTEXTURE::DESCRIPTOR; - localDescriptorSetLayout.storeImages[REFLECTIONSTORAGE::NAME] = REFLECTIONSTORAGE::LAYOUT; - localDescriptorSetLayout.bindings[REFLECTIONSTORAGE::BINDING] = REFLECTIONSTORAGE::DESCRIPTOR; localDescriptorSetLayout.samplers[REFLECTIONPROBECUBEMAP::NAME] = REFLECTIONPROBECUBEMAP::LAYOUT; localDescriptorSetLayout.bindings[REFLECTIONPROBECUBEMAP::BINDING] = REFLECTIONPROBECUBEMAP::DESCRIPTOR; diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index d4ec5a806d..f36fa635b2 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -122,8 +122,8 @@ void LightingStage::gatherLights(scene::Camera *camera) { geometry::Sphere sphere; auto exposure = camera->getExposure(); uint32_t idx = 0; - int elementLen = sizeof(cc::Vec4) / sizeof(float); - uint32_t fieldLen = elementLen * _maxDeferredLights; + const int elementLen = sizeof(cc::Vec4) / sizeof(float); + const uint32_t fieldLen = elementLen * _maxDeferredLights; uint32_t offset = 0; cc::Vec4 tmpArray; @@ -360,11 +360,11 @@ void LightingStage::initLightingBuffer() { // color/pos/dir/angle 都是vec4存储, 最后一个vec4只要x存储光源个数 auto stride = utils::alignTo(sizeof(Vec4) * 4, device->getCapabilities().uboOffsetAlignment); - uint32_t totalSize = stride * _maxDeferredLights; + const uint32_t totalSize = stride * _maxDeferredLights; // create lighting buffer and view if (_deferredLitsBufs == nullptr) { - gfx::BufferInfo bfInfo = { + const gfx::BufferInfo bfInfo = { gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, totalSize, @@ -374,7 +374,7 @@ void LightingStage::initLightingBuffer() { } if (_deferredLitsBufView == nullptr) { - gfx::BufferViewInfo bvInfo = {_deferredLitsBufs, 0, totalSize}; + const gfx::BufferViewInfo bvInfo = {_deferredLitsBufs, 0, totalSize}; _deferredLitsBufView = device->createBuffer(bvInfo); _descriptorSet->bindBuffer(static_cast(ModelLocalBindings::UBO_FORWARD_LIGHTS), _deferredLitsBufView); } @@ -388,8 +388,8 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { auto *const device = pipeline->getDevice(); for (const auto &descriptor : _renderQueueDescriptors) { - uint32_t phase = convertPhase(descriptor->stages); - RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor->sortMode); + const uint32_t phase = convertPhase(descriptor->stages); + const RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor->sortMode); RenderQueueCreateInfo info = {descriptor->isTransparent, phase, sortFunc}; _renderQueues.emplace_back(ccnew RenderQueue(_pipeline, std::move(info), true)); } @@ -397,10 +397,10 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { // not use cluster shading, go normal deferred render path if (!pipeline->isClusterEnabled()) { // create descriptor set/layout - gfx::DescriptorSetLayoutInfo layoutInfo = {localDescriptorSetLayout.bindings}; + const gfx::DescriptorSetLayoutInfo layoutInfo = {localDescriptorSetLayout.bindings}; _descLayout = device->createDescriptorSetLayout(layoutInfo); - gfx::DescriptorSetInfo setInfo = {_descLayout}; + const gfx::DescriptorSetInfo setInfo = {_descLayout}; _descriptorSet = device->createDescriptorSet(setInfo); // create lighting buffer and view @@ -520,7 +520,7 @@ void LightingStage::fgLightingPass(scene::Camera *camera) { // no need to bind localSet in cluster if (!_pipeline->isClusterEnabled()) { - ccstd::vector dynamicOffsets = {0}; + const ccstd::vector dynamicOffsets = {0}; cmdBuff->bindDescriptorSet(localSet, _descriptorSet, dynamicOffsets); } @@ -584,7 +584,7 @@ void LightingStage::fgTransparent(scene::Camera *camera) { colorAttachmentInfo.endAccesses = gfx::AccessFlagBit::FRAGMENT_SHADER_READ_TEXTURE; data.outputTex = framegraph::TextureHandle(builder.readFromBlackboard(DeferredPipeline::fgStrHandleOutColorTexture)); - bool lightingPassValid = data.outputTex.isValid(); + const bool lightingPassValid = data.outputTex.isValid(); if (!lightingPassValid) { framegraph::Texture::Descriptor colorTexInfo; colorTexInfo.format = gfx::Format::RGBA16F; @@ -609,7 +609,7 @@ void LightingStage::fgTransparent(scene::Camera *camera) { data.depth = framegraph::TextureHandle(builder.readFromBlackboard(DeferredPipeline::fgStrHandleOutDepthTexture)); if (!data.depth.isValid()) { // when there is no opaque object present - gfx::TextureInfo depthTexInfo = { + const gfx::TextureInfo depthTexInfo = { gfx::TextureType::TEX2D, gfx::TextureUsageBit::DEPTH_STENCIL_ATTACHMENT, gfx::Format::DEPTH_STENCIL, @@ -632,7 +632,7 @@ void LightingStage::fgTransparent(scene::Camera *camera) { // no need to bind localSet in cluster if (!_pipeline->isClusterEnabled()) { - ccstd::vector dynamicOffsets = {0}; + const ccstd::vector dynamicOffsets = {0}; cmdBuff->bindDescriptorSet(localSet, _descriptorSet, dynamicOffsets); } @@ -693,308 +693,6 @@ void LightingStage::putTransparentObj2Queue() { } } -void LightingStage::fgSsprPass(scene::Camera *camera) { - // The max reflector objects is 5. - // for each reflector, there are 4 pass, clear pass/reflection pass/denoise pass/render pass - // each reflector has its own denoise texture, and will be used in render pass - // All the reflectors use the same reflect texture which is temp resource for the reflectors, and the reflect texture should be cleared for each reflector - // we first calculate denoise textures of all reflectors one by one, the first 3 pass will be executed - // then we render all reflectors one by one, the last render pass will be executed - - if (!_device->hasFeature(gfx::Feature::COMPUTE_SHADER)) { - return; - } - auto *pipeline = static_cast(_pipeline); - - _denoiseIndex = 0; - _matViewProj = camera->getMatViewProj(); - _reflectionElems.clear(); - - // step 1 prepare clear model's reflection texture pass. should switch to image clear command after available - uint32_t minSize = 512; - uint32_t width = pipeline->getWidth(); - uint32_t height = pipeline->getHeight(); - if (height < width) { - _ssprTexWidth = minSize * width / height; - _ssprTexHeight = minSize; - } else { - _ssprTexWidth = minSize; - _ssprTexHeight = minSize * height / width; - } - - struct DataClear { - framegraph::TextureHandle reflection; - }; - - auto clearSetup = [&](framegraph::PassNodeBuilder &builder, DataClear &data) { - framegraph::Texture::Descriptor colorTexInfo; - colorTexInfo.format = gfx::Format::RGBA8; - colorTexInfo.usage = gfx::TextureUsageBit::COLOR_ATTACHMENT | gfx::TextureUsageBit::STORAGE | - gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC | gfx::TextureUsageBit::TRANSFER_DST; - colorTexInfo.width = _ssprTexWidth; - colorTexInfo.height = _ssprTexHeight; - data.reflection = builder.create(reflectTexHandle, colorTexInfo); - - framegraph::RenderTargetAttachment::Descriptor colorAttachmentInfo; - colorAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::COLOR; - colorAttachmentInfo.loadOp = gfx::LoadOp::CLEAR; - colorAttachmentInfo.clearColor = {0.F, 0.F, 0.F, 0.F}; - colorAttachmentInfo.endAccesses = gfx::AccessFlagBit::COMPUTE_SHADER_WRITE; - data.reflection = builder.write(data.reflection, colorAttachmentInfo); - builder.writeToBlackboard(reflectTexHandle, data.reflection); - builder.sideEffect(); - }; - - auto clearExec = [](DataClear const &data, const framegraph::DevicePassResourceTable &table) {}; - - // step 2 prepare compute the reflection pass, contain 1 dispatch commands, compute pipeline - struct DataCompReflect { - framegraph::TextureHandle reflection; // compute result texture - framegraph::TextureHandle lightingOut; // read from lighting pass output texture - framegraph::TextureHandle depth; // read from gbuffer.depth texture - }; - - auto compReflectSetup = [&](framegraph::PassNodeBuilder &builder, DataCompReflect &data) { - // if there is no attachment in the pass, render pass will not be created - // read lighting out as input - data.lightingOut = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(DeferredPipeline::fgStrHandleOutColorTexture))); - builder.writeToBlackboard(DeferredPipeline::fgStrHandleOutColorTexture, data.lightingOut); - - data.depth = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(RenderPipeline::fgStrHandleOutDepthTexture))); - builder.writeToBlackboard(RenderPipeline::fgStrHandleOutDepthTexture, data.depth); - - // write to reflection - data.reflection = framegraph::TextureHandle(builder.readFromBlackboard(reflectTexHandle)); - if (!data.reflection.isValid()) { - framegraph::Texture::Descriptor colorTexInfo; - colorTexInfo.format = gfx::Format::RGBA8; - colorTexInfo.usage = gfx::TextureUsageBit::STORAGE | gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC | gfx::TextureUsageBit::TRANSFER_DST; - colorTexInfo.width = _ssprTexWidth; - colorTexInfo.height = _ssprTexHeight; - data.reflection = builder.create(reflectTexHandle, colorTexInfo); - } - - data.reflection = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(reflectTexHandle))); - builder.writeToBlackboard(reflectTexHandle, data.reflection); - - data.reflection = builder.write(data.reflection); - builder.writeToBlackboard(reflectTexHandle, data.reflection); - }; - - auto compReflectExec = [this, camera](DataCompReflect const &data, const framegraph::DevicePassResourceTable &table) { - auto *pipeline = static_cast(_pipeline); - - gfx::Viewport vp = pipeline->getViewport(camera); - Vec4 value = Vec4(static_cast(vp.left), static_cast(vp.top), - static_cast(vp.width), static_cast(vp.height)); - _reflectionComp->applyTexSize(_ssprTexWidth, _ssprTexHeight, camera->getMatView(), camera->getMatViewProj(), - camera->getMatViewProjInv(), camera->getMatProjInv(), value); - - auto *texReflection = static_cast(table.getWrite(data.reflection)); - auto *texLightingOut = static_cast(table.getRead(data.lightingOut)); - auto *texDepth = static_cast(table.getRead(data.depth)); - - // step 1 pipeline barrier before exec - auto *cmdBuff = pipeline->getCommandBuffers()[0]; - cmdBuff->pipelineBarrier(_reflectionComp->getBarrierPre()); - - auto *textureBarrier{_device->getTextureBarrier({ - gfx::AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_WRITE, - gfx::AccessFlagBit::COMPUTE_SHADER_READ_TEXTURE, - })}; - cmdBuff->pipelineBarrier(nullptr, nullptr, nullptr, 0, &textureBarrier, &texDepth, 1); - - // step 2 bind descriptors - gfx::DescriptorSet *reflectDesc = _reflectionComp->getDescriptorSet(); - gfx::Sampler *sampler = _reflectionComp->getSampler(); - gfx::Buffer *constBuffer = _reflectionComp->getConstantsBuffer(); - - reflectDesc->bindBuffer(0, constBuffer); - reflectDesc->bindSampler(1, sampler); - reflectDesc->bindTexture(1, texLightingOut); - reflectDesc->bindSampler(2, sampler); - reflectDesc->bindTexture(2, texDepth); - reflectDesc->bindTexture(3, texReflection); - reflectDesc->bindBuffer(4, _reflectionElems[_denoiseIndex].set->getBuffer(0)); - reflectDesc->update(); - - // set 1, subModel->getDescriptorSet(0) - cmdBuff->bindPipelineState(const_cast(_reflectionComp->getPipelineState(pipeline->isEnvmapEnabled()))); - cmdBuff->bindDescriptorSet(globalSet, reflectDesc); - cmdBuff->dispatch(_reflectionComp->getDispatchInfo()); - }; - - // step 3 prepare compute the denoise pass, contain 1 dispatch commands, compute pipeline - struct DataCompDenoise { - framegraph::TextureHandle denoise; // each reflector has its own denoise texture - framegraph::TextureHandle reflection; // the texture from last pass - framegraph::TextureHandle depth; // each reflector has its own denoise texture - }; - - auto compDenoiseSetup = [&](framegraph::PassNodeBuilder &builder, DataCompDenoise &data) { - // if there is no attachment in the pass, render pass will not be created - // read reflectTexHandle - data.reflection = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(reflectTexHandle))); - builder.writeToBlackboard(reflectTexHandle, data.reflection); - - // write to reflection - framegraph::Texture::Descriptor colorTexInfo; - colorTexInfo.format = gfx::Format::RGBA8; - colorTexInfo.usage = gfx::TextureUsageBit::STORAGE | gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC; - colorTexInfo.width = _ssprTexWidth; - colorTexInfo.height = _ssprTexHeight; - data.denoise = builder.create(denoiseTexHandle[_denoiseIndex], colorTexInfo); - - data.depth = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(RenderPipeline::fgStrHandleOutDepthTexture))); - builder.writeToBlackboard(RenderPipeline::fgStrHandleOutDepthTexture, data.depth); - - data.denoise = builder.write(data.denoise); - builder.writeToBlackboard(denoiseTexHandle[_denoiseIndex], data.denoise); - }; - - auto compDenoiseExec = [this](DataCompDenoise const &data, const framegraph::DevicePassResourceTable &table) { - auto *pipeline = static_cast(_pipeline); - - auto *denoiseTex = static_cast(table.getWrite(data.denoise)); - auto *reflectionTex = static_cast(table.getRead(data.reflection)); - auto *depth = static_cast(table.getRead(data.depth)); - auto &elem = _reflectionElems[_denoiseIndex]; - - // pipeline barrier - auto *cmdBuff = pipeline->getCommandBuffers()[0]; - cmdBuff->pipelineBarrier(nullptr, {}, {}, const_cast(_reflectionComp->getBarrierBeforeDenoise()), {reflectionTex, denoiseTex}); - - // bind descriptor set - bool useEnvmap = pipeline->isEnvmapEnabled(); - _reflectionComp->getDenoiseDescriptorSet()->bindTexture(0, reflectionTex); - _reflectionComp->getDenoiseDescriptorSet()->bindSampler(0, _reflectionComp->getSampler()); - - if (useEnvmap) { - _reflectionComp->getDenoiseDescriptorSet()->bindTexture(1, pipeline->getDescriptorSet()->getTexture(static_cast(PipelineGlobalBindings::SAMPLER_ENVIRONMENT))); - _reflectionComp->getDenoiseDescriptorSet()->bindSampler(1, _reflectionComp->getSampler()); - _reflectionComp->getDenoiseDescriptorSet()->bindTexture(2, depth); - _reflectionComp->getDenoiseDescriptorSet()->bindSampler(2, _reflectionComp->getSampler()); - _reflectionComp->getDenoiseDescriptorSet()->bindBuffer(3, _reflectionComp->getConstantsBuffer()); - } - - _reflectionComp->getDenoiseDescriptorSet()->update(); - - elem.set->bindTexture(static_cast(ModelLocalBindings::STORAGE_REFLECTION), denoiseTex); - elem.set->bindSampler(static_cast(ModelLocalBindings::STORAGE_REFLECTION), _defaultSampler); - - // for render stage usage - elem.set->bindTexture(static_cast(ModelLocalBindings::SAMPLER_REFLECTION), denoiseTex); - elem.set->bindSampler(static_cast(ModelLocalBindings::SAMPLER_REFLECTION), _defaultSampler); - elem.set->update(); - - cmdBuff->bindPipelineState(const_cast(_reflectionComp->getDenoisePipelineState(useEnvmap))); - cmdBuff->bindDescriptorSet(globalSet, const_cast(_reflectionComp->getDenoiseDescriptorSet())); - cmdBuff->bindDescriptorSet(materialSet, elem.set); - cmdBuff->dispatch(_reflectionComp->getDenoiseDispatchInfo()); - - // pipeline barrier - // dispatch -> fragment - cmdBuff->pipelineBarrier(nullptr, {}, {}, _reflectionComp->getBarrierAfterDenoise(), {denoiseTex}); - - _denoiseIndex = (_denoiseIndex + 1) % _reflectionElems.size(); - }; - - // step 4 prepare render reflector objects pass, graphics pipeline - struct DataRender { - framegraph::TextureHandle denoise; // input texture - framegraph::TextureHandle lightingOut; // attachment, load and write - framegraph::TextureHandle depth; // attachment, load and write - }; - - auto renderSetup = [&](framegraph::PassNodeBuilder &builder, DataRender &data) { - data.denoise = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(denoiseTexHandle[_denoiseIndex]))); - builder.writeToBlackboard(denoiseTexHandle[_denoiseIndex], data.denoise); - - // write lighting out, as an attachment - framegraph::RenderTargetAttachment::Descriptor colorAttachmentInfo; - colorAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::COLOR; - colorAttachmentInfo.loadOp = gfx::LoadOp::LOAD; - colorAttachmentInfo.clearColor = gfx::Color(); - colorAttachmentInfo.beginAccesses = gfx::AccessFlagBit::FRAGMENT_SHADER_READ_TEXTURE; - colorAttachmentInfo.endAccesses = gfx::AccessFlagBit::FRAGMENT_SHADER_READ_TEXTURE; - - data.lightingOut = builder.write(framegraph::TextureHandle(builder.readFromBlackboard(DeferredPipeline::fgStrHandleOutColorTexture)), colorAttachmentInfo); - builder.writeToBlackboard(DeferredPipeline::fgStrHandleOutColorTexture, data.lightingOut); - - // read depth, as an attachment - framegraph::RenderTargetAttachment::Descriptor depthAttachmentInfo; - depthAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::DEPTH_STENCIL; - depthAttachmentInfo.loadOp = gfx::LoadOp::LOAD; - depthAttachmentInfo.clearColor = gfx::Color(); - depthAttachmentInfo.beginAccesses = gfx::AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_READ; - depthAttachmentInfo.endAccesses = gfx::AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_READ; - - data.depth = builder.write(framegraph::TextureHandle(builder.readFromBlackboard(DeferredPipeline::fgStrHandleOutDepthTexture)), depthAttachmentInfo); - builder.writeToBlackboard(DeferredPipeline::fgStrHandleOutDepthTexture, data.depth); - - builder.setViewport(pipeline->getViewport(camera), pipeline->getScissor(camera)); - }; - - auto renderExec = [this, camera](DataRender const &data, const framegraph::DevicePassResourceTable &table) { - auto *pipeline = static_cast(_pipeline); - auto *cmdBuff = pipeline->getCommandBuffers()[0]; - auto &elem = _reflectionElems[_denoiseIndex]; - - // bind descriptor - cmdBuff->bindDescriptorSet(globalSet, pipeline->getDescriptorSet()); - - gfx::DescriptorSet *descLocal = elem.set; // sub model descriptor set - auto *denoiseTex = static_cast(table.getRead(data.denoise)); - - descLocal->bindTexture(static_cast(ModelLocalBindings::SAMPLER_REFLECTION), denoiseTex); - descLocal->bindSampler(static_cast(ModelLocalBindings::SAMPLER_REFLECTION), _defaultSampler); - descLocal->update(); - cmdBuff->bindDescriptorSet(localSet, descLocal); - - _reflectionRenderQueue->clear(); - _reflectionRenderQueue->insertRenderPass(elem.renderObject, elem.modelIndex, elem.passIndex); - - gfx::RenderPass *renderPass = table.getRenderPass(); - _reflectionRenderQueue->sort(); - _reflectionRenderQueue->recordCommandBuffer(pipeline->getDevice(), camera, renderPass, cmdBuff); - }; - - // step 5 add framegraph passes - auto *const sceneData = _pipeline->getPipelineSceneData(); - const auto &renderObjects = sceneData->getRenderObjects(); - uint32_t m = 0; - uint32_t p = 0; - for (const auto &ro : renderObjects) { - const auto *model = ro.model; - const auto &subModels = model->getSubModels(); - for (m = 0; m < subModels.size(); ++m) { - const auto &subModel = subModels[m]; - const auto &passes = *(subModel->getPasses()); - auto passCount = passes.size(); - for (p = 0; p < passCount; ++p) { - const auto &pass = passes[p]; - if (pass->getPhase() == _reflectionPhaseID) { - RenderElem elem = {ro, subModel->getDescriptorSet(), m, p}; - _reflectionElems.push_back(elem); - } - } - } - } - - auto insertPoint = static_cast(DeferredInsertPoint::DIP_SSPR); - for (uint32_t i = 0; i < _reflectionElems.size(); ++i) { - // add clear and comp passes here - pipeline->getFrameGraph().addPass(insertPoint++, ssprClearPass[i], clearSetup, clearExec); - pipeline->getFrameGraph().addPass(insertPoint++, ssprCompReflectPass[i], compReflectSetup, compReflectExec); - pipeline->getFrameGraph().addPass(insertPoint++, ssprCompDenoisePass[i], compDenoiseSetup, compDenoiseExec); - } - - for (uint32_t i = 0; i < _reflectionElems.size(); ++i) { - // add graphic pass here - pipeline->getFrameGraph().addPass(insertPoint++, ssprRenderPass[i], renderSetup, renderExec); - } -} - void LightingStage::render(scene::Camera *camera) { CC_PROFILE(LightingStageRender); auto *pipeline = static_cast(_pipeline); @@ -1007,12 +705,6 @@ void LightingStage::render(scene::Camera *camera) { } fgTransparent(camera); - - // if lighting pass does not exist, skip SSPR pass. - // switch to clear image API when available - if (pipeline->getFrameGraph().hasPass(DeferredPipeline::fgStrHandleLightingPass)) { - fgSsprPass(camera); - } } } // namespace pipeline diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.h b/native/cocos/renderer/pipeline/deferred/LightingStage.h index 82ab4830be..2953db69e5 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.h +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.h @@ -63,7 +63,6 @@ private: void initLightingBuffer(); void fgLightingPass(scene::Camera *camera); void fgTransparent(scene::Camera *camera); - void fgSsprPass(scene::Camera *camera); void putTransparentObj2Queue(); diff --git a/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp b/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp index d6f8a48d99..c947334dbc 100644 --- a/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp +++ b/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp @@ -66,10 +66,10 @@ struct ConstantBuffer { void ReflectionComp::applyTexSize(uint32_t width, uint32_t height, const Mat4 &matView, const Mat4 &matViewProj, const Mat4 &matViewProjInv, const Mat4 &matProjInv, const Vec4 &viewPort) { - uint32_t globalWidth = width; - uint32_t globalHeight = height; - uint32_t groupWidth = this->getGroupSizeX(); - uint32_t groupHeight = this->getGroupSizeY(); + const uint32_t globalWidth = width; + const uint32_t globalHeight = height; + const uint32_t groupWidth = this->getGroupSizeX(); + const uint32_t groupHeight = this->getGroupSizeY(); _dispatchInfo = {(globalWidth - 1) / groupWidth + 1, (globalHeight - 1) / groupHeight + 1, 1}; _denoiseDispatchInfo = {((globalWidth - 1) / 2) / groupWidth + 1, ((globalHeight - 1) / 2) / groupHeight + 1, 1}; @@ -80,7 +80,7 @@ void ReflectionComp::applyTexSize(uint32_t width, uint32_t height, const Mat4 &m constants.matViewProj = matViewProj; constants.matViewProjInv = matViewProjInv; constants.viewPort = viewPort; - constants.texSize = {float(width), float(height)}; + constants.texSize = {static_cast(width), static_cast(height)}; constants.viewPort = viewPort; if (_compConstantsBuffer) { @@ -100,29 +100,29 @@ void ReflectionComp::init(gfx::Device *dev, uint32_t groupSizeX, uint32_t groupS samplerInfo.magFilter = gfx::Filter::POINT; _sampler = _device->getSampler(samplerInfo); - uint32_t maxInvocations = _device->getCapabilities().maxComputeWorkGroupInvocations; + const uint32_t maxInvocations = _device->getCapabilities().maxComputeWorkGroupInvocations; CC_ASSERT(_groupSizeX * _groupSizeY <= maxInvocations); // maxInvocations is too small CC_LOG_INFO(" work group size: %dx%d", _groupSizeX, _groupSizeY); - gfx::DescriptorSetLayoutInfo layoutInfo = {pipeline::localDescriptorSetLayout.bindings}; + const gfx::DescriptorSetLayoutInfo layoutInfo = {pipeline::localDescriptorSetLayout.bindings}; _localDescriptorSetLayout = _device->createDescriptorSetLayout(layoutInfo); - gfx::GeneralBarrierInfo infoPre = { + const gfx::GeneralBarrierInfo infoPre = { gfx::AccessFlagBit::COLOR_ATTACHMENT_WRITE, gfx::AccessFlagBit::COMPUTE_SHADER_READ_TEXTURE, }; - gfx::TextureBarrierInfo infoBeforeDenoise = { + const gfx::TextureBarrierInfo infoBeforeDenoise = { gfx::AccessFlagBit::COMPUTE_SHADER_WRITE, gfx::AccessFlagBit::COMPUTE_SHADER_READ_TEXTURE, }; - gfx::TextureBarrierInfo infoBeforeDenoise2 = { + const gfx::TextureBarrierInfo infoBeforeDenoise2 = { gfx::AccessFlagBit::NONE, gfx::AccessFlagBit::COMPUTE_SHADER_WRITE, }; - gfx::TextureBarrierInfo infoAfterDenoise = { + const gfx::TextureBarrierInfo infoAfterDenoise = { gfx::AccessFlagBit::COMPUTE_SHADER_WRITE, gfx::AccessFlagBit::FRAGMENT_SHADER_READ_TEXTURE, }; @@ -330,193 +330,9 @@ void ReflectionComp::initReflectionRes() { } void ReflectionComp::getDenoiseShader(ShaderSources &sources, bool useEnvmap) const { - sources.glsl4 = StringUtil::format( - R"( - #define CC_USE_ENVMAP %d - layout(local_size_x = %d, local_size_y = %d, local_size_z = 1) in; - layout(set = 0, binding = 1) uniform sampler2D reflectionTex; - layout(set = 1, binding = %d, rgba8) writeonly uniform lowp image2D denoiseTex; - - #if CC_USE_ENVMAP == 1 - layout(set = 0, binding = 2) uniform samplerCube envMap; - layout(set = 0, binding = 3) uniform sampler2D depth; - layout(set = 0, binding = 0) uniform Constants - { - mat4 matView; - mat4 matProjInv; - mat4 matViewProj; - mat4 matViewProjInv; - vec4 viewPort; - vec2 texSize; - }; - - vec4 screen2ES(vec3 coord) { - vec4 ndc = vec4(2.0 * (coord.x - viewPort.x) / viewPort.z - 1.0, - 2.0 * (coord.y - viewPort.y) / viewPort.w - 1.0, - coord.z, - 1.0); - - vec4 eye = matProjInv * ndc; - eye = eye / eye.w; - return eye; - } - - vec3 calEnvmapUV(vec3 eyeCoord) { - vec4 planeNornalWS = vec4(0, 1.0, 0, 1.0); - vec3 planeNormalES = normalize((matView * planeNornalWS).xyz); - vec3 incidenceES = normalize(eyeCoord); - return normalize(reflect(incidenceES, planeNormalES)); - } - - vec4 sampleEnvmap(ivec2 id) { - vec2 uv = vec2(id) / texSize; - vec4 depValue = texture(depth, uv); - vec2 screenPos = uv * vec2(viewPort.z, viewPort.w) + vec2(viewPort.x, viewPort.y); - vec3 posES = screen2ES(vec3(screenPos, depValue.r)).xyz; - vec3 envmapUV = calEnvmapUV(posES); - return texture(envMap, envmapUV); - } - #endif - - void main() { - ivec2 id = ivec2(gl_GlobalInvocationID.xy) * 2; - - vec4 center = texelFetch(reflectionTex, id + ivec2(0, 0), 0); - vec4 right = texelFetch(reflectionTex, id + ivec2(0, 1), 0); - vec4 bottom = texelFetch(reflectionTex, id + ivec2(1, 0), 0); - vec4 bottomRight = texelFetch(reflectionTex, id + ivec2(1, 1), 0); - - vec4 best = center; - best = right.a > best.a + 0.1 ? right : best; - best = bottom.a > best.a + 0.1 ? bottom : best; - best = bottomRight.a > best.a + 0.1 ? bottomRight : best; - - #if !CC_USE_ENVMAP - vec4 res = best.a > center.a + 0.1 ? best : center; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(0, 0), res); - - res = best.a > right.a + 0.1 ? best : right; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(0, 1), res); - - res = best.a > bottom.a + 0.1 ? best : bottom; - if (res.xyz != vec3(0,0, 0)) imageStore(denoiseTex, id + ivec2(1, 0), res); - - res = best.a > bottomRight.a + 0.1 ? best : bottomRight; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(1, 1), res); - #else - vec4 res = best.a > center.a + 0.1 ? best : center; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id) : res; - imageStore(denoiseTex, id + ivec2(0, 0), res); - - res = best.a > right.a + 0.1 ? best : right; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(0, 1)) : res; - imageStore(denoiseTex, id + ivec2(0, 1), res); - - res = best.a > bottom.a + 0.1 ? best : bottom; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(1, 0)) : res; - imageStore(denoiseTex, id + ivec2(1, 0), res); - - res = best.a > bottomRight.a + 0.1 ? best : bottomRight; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(1, 1)) : res; - imageStore(denoiseTex, id + ivec2(1, 1), res); - #endif - })", - useEnvmap, _groupSizeX, _groupSizeY, pipeline::REFLECTIONSTORAGE::BINDING); - sources.glsl3 = StringUtil::format( - R"( - #define CC_USE_ENVMAP %d - layout(local_size_x = %d, local_size_y = %d, local_size_z = 1) in; - uniform sampler2D reflectionTex; - - #if CC_USE_ENVMAP - uniform samplerCube envMap; - uniform sampler2D depth; - layout(std140) uniform Constants - { - mat4 matView; - mat4 matProjInv; - mat4 matViewProj; - mat4 matViewProjInv; - vec4 viewPort; - vec2 texSize; - }; - #endif - - layout(rgba8) writeonly uniform lowp image2D denoiseTex; - - #if CC_USE_ENVMAP - vec4 screen2ES(vec3 coord) { - vec4 ndc = vec4(2.0 * (coord.x - viewPort.x) / viewPort.z - 1.0, - 2.0 * (coord.y - viewPort.y) / viewPort.w - 1.0, - 2.0 * coord.z - 1.0, - 1.0); - - vec4 eye = matProjInv * ndc; - eye = eye / eye.w; - return eye; - } - - vec3 calEnvmapUV(vec3 eyeCoord) { - vec4 planeNornalWS = vec4(0, 1.0, 0, 1.0); - vec3 planeNormalES = normalize((matView * planeNornalWS).xyz); - vec3 incidenceES = normalize(eyeCoord); - return normalize(reflect(incidenceES, planeNormalES)); - } - - vec4 sampleEnvmap(ivec2 id) { - vec2 uv = vec2(id) / texSize; - vec4 depValue = texture(depth, uv); - vec2 screenPos = uv * vec2(viewPort.z, viewPort.w) + vec2(viewPort.x, viewPort.y); - vec3 posES = screen2ES(vec3(screenPos, depValue.r)).xyz; - vec3 envmapUV = calEnvmapUV(posES); - return texture(envMap, envmapUV); - } - #endif - - void main() { - ivec2 id = ivec2(gl_GlobalInvocationID.xy) * 2; - - vec4 center = texelFetch(reflectionTex, id + ivec2(0, 0), 0); - vec4 right = texelFetch(reflectionTex, id + ivec2(0, 1), 0); - vec4 bottom = texelFetch(reflectionTex, id + ivec2(1, 0), 0); - vec4 bottomRight = texelFetch(reflectionTex, id + ivec2(1, 1), 0); - - vec4 best = center; - best = right.a > best.a + 0.1 ? right : best; - best = bottom.a > best.a + 0.1 ? bottom : best; - best = bottomRight.a > best.a + 0.1 ? bottomRight : best; - - #if !CC_USE_ENVMAP - vec4 res = best.a > center.a + 0.1 ? best : center; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(0, 0), res); - - res = best.a > right.a + 0.1 ? best : right; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(0, 1), res); - - res = best.a > bottom.a + 0.1 ? best : bottom; - if (res.xyz != vec3(0,0, 0)) imageStore(denoiseTex, id + ivec2(1, 0), res); - - res = best.a > bottomRight.a + 0.1 ? best : bottomRight; - if (res.xyz != vec3(0, 0, 0)) imageStore(denoiseTex, id + ivec2(1, 1), res); - #else - vec4 res = best.a > center.a + 0.1 ? best : center; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id) : res; - imageStore(denoiseTex, id + ivec2(0, 0), res); - - res = best.a > right.a + 0.1 ? best : right; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(0, 1)) : res; - imageStore(denoiseTex, id + ivec2(0, 1), res); - - res = best.a > bottom.a + 0.1 ? best : bottom; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(1, 0)) : res; - imageStore(denoiseTex, id + ivec2(1, 0), res); - - res = best.a > bottomRight.a + 0.1 ? best : bottomRight; - res = res == vec4(0, 0, 0, 0) ? sampleEnvmap(id + ivec2(1, 1)) : res; - imageStore(denoiseTex, id + ivec2(1, 1), res); - #endif - })", - useEnvmap, _groupSizeX, _groupSizeY); + std::ignore = sources; + std::ignore = useEnvmap; + std::ignore = _device; } void ReflectionComp::initDenoiseRes() { diff --git a/native/cocos/scene/SubModel.cpp b/native/cocos/scene/SubModel.cpp index 652687d2d2..7c1081106f 100644 --- a/native/cocos/scene/SubModel.cpp +++ b/native/cocos/scene/SubModel.cpp @@ -154,41 +154,6 @@ void SubModel::initialize(RenderingSubMesh *subMesh, const SharedPassArray &pPas const auto &passes = *_passes; _priority = pipeline::RenderPriority::DEFAULT; - - // initialize resources for reflection material - if (passes[0]->getPhase() == pipeline::getPhaseID("reflection")) { - const auto *mainWindow = Root::getInstance()->getMainWindow(); - uint32_t texWidth = mainWindow->getWidth(); - uint32_t texHeight = mainWindow->getHeight(); - const uint32_t minSize = 512; - if (texHeight < texWidth) { - texWidth = minSize * texWidth / texHeight; - texHeight = minSize; - } else { - texWidth = minSize; - texHeight = minSize * texHeight / texWidth; - } - _reflectionTex = _device->createTexture(gfx::TextureInfo{ - gfx::TextureType::TEX2D, - gfx::TextureUsageBit::STORAGE | gfx::TextureUsageBit::TRANSFER_SRC | gfx::TextureUsageBit::SAMPLED, - gfx::Format::RGBA8, - texWidth, - texHeight, - }); - _descriptorSet->bindTexture(pipeline::REFLECTIONTEXTURE::BINDING, _reflectionTex); - - const gfx::SamplerInfo samplerInfo{ - gfx::Filter::LINEAR, - gfx::Filter::LINEAR, - gfx::Filter::NONE, - gfx::Address::CLAMP, - gfx::Address::CLAMP, - gfx::Address::CLAMP, - }; - _reflectionSampler = _device->getSampler(samplerInfo); - _descriptorSet->bindSampler(pipeline::REFLECTIONTEXTURE::BINDING, _reflectionSampler); - _descriptorSet->bindTexture(pipeline::REFLECTIONSTORAGE::BINDING, _reflectionTex); - } } void SubModel::destroy() { @@ -203,9 +168,6 @@ void SubModel::destroy() { _subMesh = nullptr; _passes.reset(); _shaders.clear(); - - CC_SAFE_DESTROY_NULL(_reflectionTex); - _reflectionSampler = nullptr; } void SubModel::onPipelineStateChanged() { @@ -315,7 +277,7 @@ void SubModel::updateInstancedWorldMatrix(const Mat4 &mat, int32_t idx) { auto &v2 = ccstd::get(attrs[idx + 1]); auto &v3 = ccstd::get(attrs[idx + +2]); const uint32_t copyBytes = sizeof(float) * 3; - auto *buffer = const_cast(v1.buffer()->getData()); + auto *buffer = v1.buffer()->getData(); uint8_t *dst = buffer + v1.byteOffset(); memcpy(dst, mat.m, copyBytes); diff --git a/native/cocos/scene/SubModel.h b/native/cocos/scene/SubModel.h index 780ff53ded..c6b3e063ca 100644 --- a/native/cocos/scene/SubModel.h +++ b/native/cocos/scene/SubModel.h @@ -56,31 +56,31 @@ public: gfx::Shader *getShader(uint32_t) const; Pass *getPass(uint32_t) const; - inline void setWorldBoundDescriptorSet(gfx::DescriptorSet *descriptorSet) { _worldBoundDescriptorSet = descriptorSet; } - inline void setDescriptorSet(gfx::DescriptorSet *descriptorSet) { _descriptorSet = descriptorSet; } - inline void setInputAssembler(gfx::InputAssembler *ia) { _inputAssembler = ia; } - inline void setShaders(const ccstd::vector> &shaders) { _shaders = shaders; } + void setWorldBoundDescriptorSet(gfx::DescriptorSet *descriptorSet) { _worldBoundDescriptorSet = descriptorSet; } + void setDescriptorSet(gfx::DescriptorSet *descriptorSet) { _descriptorSet = descriptorSet; } + void setInputAssembler(gfx::InputAssembler *ia) { _inputAssembler = ia; } + void setShaders(const ccstd::vector> &shaders) { _shaders = shaders; } void setPasses(const SharedPassArray &passes); - inline void setPriority(pipeline::RenderPriority priority) { _priority = priority; } - inline void setOwner(Model *model) { _owner = model; } + void setPriority(pipeline::RenderPriority priority) { _priority = priority; } + void setOwner(Model *model) { _owner = model; } void setSubMesh(RenderingSubMesh *subMesh); - inline void setInstancedWorldMatrixIndex(int32_t worldMatrixIndex) { _instancedWorldMatrixIndex = worldMatrixIndex; } - inline void setInstancedSHIndex(int32_t index) { _instancedSHIndex = index; } + void setInstancedWorldMatrixIndex(int32_t worldMatrixIndex) { _instancedWorldMatrixIndex = worldMatrixIndex; } + void setInstancedSHIndex(int32_t index) { _instancedSHIndex = index; } void setInstancedAttribute(const ccstd::string &name, const TypedArray &value); - inline gfx::DescriptorSet *getDescriptorSet() const { return _descriptorSet; } - inline gfx::DescriptorSet *getWorldBoundDescriptorSet() const { return _worldBoundDescriptorSet; } - inline gfx::InputAssembler *getInputAssembler() const { return _inputAssembler; } - inline const ccstd::vector> &getShaders() const { return _shaders; } - inline const SharedPassArray &getPasses() const { return _passes; } - inline const ccstd::vector &getPatches() const { return _patches; } - inline pipeline::RenderPriority getPriority() const { return _priority; } - inline RenderingSubMesh *getSubMesh() const { return _subMesh; } - inline Model *getOwner() const { return _owner; } - inline uint32_t getId() const { return _id; } - inline InstancedAttributeBlock &getInstancedAttributeBlock() { return _instancedAttributeBlock; } - inline int32_t getInstancedWorldMatrixIndex() const { return _instancedWorldMatrixIndex; } - inline int32_t getInstancedSHIndex() const { return _instancedSHIndex; } + gfx::DescriptorSet *getDescriptorSet() const { return _descriptorSet; } + gfx::DescriptorSet *getWorldBoundDescriptorSet() const { return _worldBoundDescriptorSet; } + gfx::InputAssembler *getInputAssembler() const { return _inputAssembler; } + const ccstd::vector> &getShaders() const { return _shaders; } + const SharedPassArray &getPasses() const { return _passes; } + const ccstd::vector &getPatches() const { return _patches; } + pipeline::RenderPriority getPriority() const { return _priority; } + RenderingSubMesh *getSubMesh() const { return _subMesh; } + Model *getOwner() const { return _owner; } + uint32_t getId() const { return _id; } + InstancedAttributeBlock &getInstancedAttributeBlock() { return _instancedAttributeBlock; } + int32_t getInstancedWorldMatrixIndex() const { return _instancedWorldMatrixIndex; } + int32_t getInstancedSHIndex() const { return _instancedSHIndex; } int32_t getInstancedAttributeIndex(const ccstd::string &name) const; void initialize(RenderingSubMesh *subMesh, const SharedPassArray &passes, const ccstd::vector &patches); @@ -91,7 +91,7 @@ public: void updateInstancedAttributes(const ccstd::vector &attributes); void updateInstancedWorldMatrix(const Mat4 &mat, int32_t idx); void updateInstancedSH(const Float32Array &data, int32_t idx); - inline int32_t getReflectionProbeType() const { return _reflectionProbeType; } + int32_t getReflectionProbeType() const { return _reflectionProbeType; } void setReflectionProbeType(int32_t val) { _reflectionProbeType = val; } protected: @@ -105,12 +105,10 @@ protected: gfx::Device *_device{nullptr}; Model *_owner{nullptr}; - gfx::Sampler *_reflectionSampler{nullptr}; IntrusivePtr _inputAssembler; IntrusivePtr _descriptorSet; IntrusivePtr _worldBoundDescriptorSet; - IntrusivePtr _reflectionTex; IntrusivePtr _subMesh; InstancedAttributeBlock _instancedAttributeBlock{}; @@ -124,7 +122,7 @@ protected: int32_t _reflectionProbeType{0}; private: - static inline int32_t generateId() { + static int32_t generateId() { static int32_t generator = 0; return generator++; } diff --git a/tests/assets/shader-test/builtin-standard_standard-vs_standard-fs_CC_SUPPORT_CASCADED_SHADOW_MAP1_CC_USE_HDR1.frag b/tests/assets/shader-test/builtin-standard_standard-vs_standard-fs_CC_SUPPORT_CASCADED_SHADOW_MAP1_CC_USE_HDR1.frag index e0fdfffbf7..60959f5269 100644 --- a/tests/assets/shader-test/builtin-standard_standard-vs_standard-fs_CC_SUPPORT_CASCADED_SHADOW_MAP1_CC_USE_HDR1.frag +++ b/tests/assets/shader-test/builtin-standard_standard-vs_standard-fs_CC_SUPPORT_CASCADED_SHADOW_MAP1_CC_USE_HDR1.frag @@ -945,8 +945,8 @@ vec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) { #endif #endif #if CC_USE_REFLECTION_PROBE - layout(set = 2, binding = 14) uniform samplerCube cc_reflectionProbeCubemap; - layout(set = 2, binding = 15) uniform sampler2D cc_reflectionProbePlanarMap; + layout(set = 2, binding = 13) uniform samplerCube cc_reflectionProbeCubemap; + layout(set = 2, binding = 14) uniform sampler2D cc_reflectionProbePlanarMap; #endif #if CC_USE_LIGHT_PROBE #if CC_USE_LIGHT_PROBE