From 26011307a632780be8e1e61dca465efd7fd9a90b Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Fri, 8 Sep 2023 11:08:04 +0800 Subject: [PATCH 1/4] fix debugView UBO error for custom pipeline --- cocos/rendering/pipeline-ubo.ts | 22 ++++---- .../pipeline/custom/NativeBuiltinUtils.cpp | 54 ++++++------------- 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/cocos/rendering/pipeline-ubo.ts b/cocos/rendering/pipeline-ubo.ts index 38bfb231123..6772597d10b 100644 --- a/cocos/rendering/pipeline-ubo.ts +++ b/cocos/rendering/pipeline-ubo.ts @@ -75,19 +75,21 @@ export class PipelineUBO { } const debugView = root.debugView; - fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET] = debugView.singleMode as number; - - for (let i = 1; i <= 3; i++) { + for (let i = 0; i <= 3; i++) { fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + i] = 0.0; } - for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < DebugViewCompositeType.MAX_BIT_COUNT; i++) { - const offset = i >> 3; - const bit = i % 8; - fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 1 + offset] += (debugView.isCompositeModeEnabled(i) ? 1.0 : 0.0) * (10.0 ** bit); - } + if (debugView.isEnabled) { + fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET] = debugView.singleMode as number; - fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 3] += (debugView.lightingWithAlbedo ? 1.0 : 0.0) * (10.0 ** 6.0); - fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 3] += (debugView.csmLayerColoration ? 1.0 : 0.0) * (10.0 ** 7.0); + for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < DebugViewCompositeType.MAX_BIT_COUNT; i++) { + const offset = i >> 3; + const bit = i % 8; + fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 1 + offset] += (debugView.isCompositeModeEnabled(i) ? 1.0 : 0.0) * (10.0 ** bit); + } + + fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 3] += (debugView.lightingWithAlbedo ? 1.0 : 0.0) * (10.0 ** 6.0); + fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 3] += (debugView.csmLayerColoration ? 1.0 : 0.0) * (10.0 ** 7.0); + } } public static updateCameraUBOView ( diff --git a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp index 07c7d0aaa33..17812be6bdc 100644 --- a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp @@ -42,10 +42,10 @@ namespace cc { namespace render { void setupQuadVertexBuffer(gfx::Device &device, const Vec4 &viewport, float vbData[16]) { - auto minX = static_cast(viewport.x); - auto maxX = static_cast(viewport.x + viewport.z); - auto minY = static_cast(viewport.y); - auto maxY = static_cast(viewport.y + viewport.w); + const float minX = viewport.x; + const float maxX = viewport.x + viewport.z; + float minY = viewport.y; + float maxY = viewport.y + viewport.w; if (device.getCapabilities().screenSpaceSignY > 0) { std::swap(minY, maxY); } @@ -87,43 +87,23 @@ void updateRasterPassConstants(uint32_t width, uint32_t height, Setter &setter) setter.setVec4( "cc_nativeSize", Vec4(shadingWidth, shadingHeight, 1.0F / shadingWidth, 1.0F / shadingHeight)); -#if 0 + const auto *debugView = root.getDebugView(); - if (debugView) { - setter.setVec4( - "cc_debug_view_mode", - Vec4(static_cast(debugView->getSingleMode()), - debugView->isLightingWithAlbedo() ? 1.0F : 0.0F, - debugView->isCsmLayerColoration() ? 1.0F : 0.0F, - 0.0F)); - Vec4 debugPackVec{}; - for (auto i = static_cast(pipeline::DebugViewCompositeType::DIRECT_DIFFUSE); - i < static_cast(pipeline::DebugViewCompositeType::MAX_BIT_COUNT); ++i) { - const auto idx = i % 4; - (&debugPackVec.x)[idx] = debugView->isCompositeModeEnabled(i) ? 1.0F : 0.0F; - const auto packIdx = static_cast(floor(static_cast(i) / 4.0F)); - if (idx == 3) { - std::string name("cc_debug_view_composite_pack_"); - name.append(std::to_string(packIdx + 1)); - setter.setVec4(name, debugPackVec); - } - } - } else { - setter.setVec4("cc_debug_view_mode", Vec4(0.0F, 1.0F, 0.0F, 0.0F)); - Vec4 debugPackVec{}; + float debugViewData[4] = {0.0F, 0.0F, 0.0F, 0.0F}; + if (debugView && debugView->isEnabled()) { + debugViewData[0] = static_cast(debugView->getSingleMode()); for (auto i = static_cast(pipeline::DebugViewCompositeType::DIRECT_DIFFUSE); i < static_cast(pipeline::DebugViewCompositeType::MAX_BIT_COUNT); ++i) { - const auto idx = i % 4; - (&debugPackVec.x)[idx] = 1.0F; - const auto packIdx = static_cast(floor(i / 4.0)); - if (idx == 3) { - std::string name("cc_debug_view_composite_pack_"); - name.append(std::to_string(packIdx + 1)); - setter.setVec4(name, debugPackVec); - } + const uint32_t offset = i >> 3; + const uint32_t bit = i % 8; + debugViewData[1 + offset] += (debugView->isCompositeModeEnabled(i) ? 1.0F : 0.0F) * std::powf(10.0F, static_cast(bit)); } + debugViewData[3] += (debugView->isLightingWithAlbedo() ? 1.0F : 0.0F) * std::powf(10.0F, 6); + debugViewData[3] += (debugView->isCsmLayerColoration() ? 1.0F : 0.0F) * std::powf(10.0F, 7); } -#endif + setter.setVec4( + "cc_debug_view_mode", + Vec4(debugViewData[0], debugViewData[1], debugViewData[2], debugViewData[3])); } namespace { @@ -373,7 +353,7 @@ void setShadowUBOView( } } } else { - Vec3 tempVec3 = shadowInfo.getNormal().getNormalized(); + const Vec3 tempVec3 = shadowInfo.getNormal().getNormalized(); setVec4Impl(data, layoutGraph, "cc_planarNDInfo", Vec4(tempVec3.x, tempVec3.y, tempVec3.z, -shadowInfo.getDistance())); From 945791cdd17b6143959436cca38a82d933357d1b Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Fri, 8 Sep 2023 11:20:27 +0800 Subject: [PATCH 2/4] fix CI error --- cocos/rendering/pipeline-ubo.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cocos/rendering/pipeline-ubo.ts b/cocos/rendering/pipeline-ubo.ts index 6772597d10b..076c681ba54 100644 --- a/cocos/rendering/pipeline-ubo.ts +++ b/cocos/rendering/pipeline-ubo.ts @@ -36,6 +36,7 @@ import { builtinResMgr } from '../asset/asset-manager/builtin-res-mgr'; import { Texture2D } from '../asset/assets'; import { DebugViewCompositeType } from './debug-view'; import { getDescBindingFromName } from './custom/define'; +import { Root } from '../root'; const _matShadowView = new Mat4(); const _matShadowProj = new Mat4(); @@ -47,7 +48,7 @@ const _tempVec3 = new Vec3(); export class PipelineUBO { public static updateGlobalUBOView (window: RenderWindow, bufferView: Float32Array): void { const director = cclegacy.director; - const root = director.root; + const root = director.root as Root; const fv = bufferView; const shadingWidth = Math.floor(window.width); @@ -78,10 +79,10 @@ export class PipelineUBO { for (let i = 0; i <= 3; i++) { fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + i] = 0.0; } - if (debugView.isEnabled) { + if (debugView.isEnabled()) { fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET] = debugView.singleMode as number; - for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < DebugViewCompositeType.MAX_BIT_COUNT; i++) { + for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < (DebugViewCompositeType.MAX_BIT_COUNT as unknown as number); i++) { const offset = i >> 3; const bit = i % 8; fv[UBOGlobal.DEBUG_VIEW_MODE_OFFSET + 1 + offset] += (debugView.isCompositeModeEnabled(i) ? 1.0 : 0.0) * (10.0 ** bit); @@ -98,7 +99,7 @@ export class PipelineUBO { camera: Camera, ): void { const scene = camera.scene ? camera.scene : cclegacy.director.getScene().renderScene; - const mainLight = scene.mainLight; + const mainLight = scene.mainLight as DirectionalLight; const sceneData = pipeline.pipelineSceneData; const ambient = sceneData.ambient; const skybox = sceneData.skybox; @@ -341,9 +342,9 @@ export class PipelineUBO { if (shadowInfo.type === ShadowType.ShadowMap) { let near = 0.1; let far = 0; - let matShadowView; - let matShadowProj; - let matShadowViewProj; + let matShadowView: Mat4; + let matShadowProj: Mat4; + let matShadowViewProj: Mat4; let levelCount = 0; if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1 || !csmSupported) { matShadowView = csmLayers.specialLayer.matShadowView; @@ -405,10 +406,10 @@ export class PipelineUBO { Mat4.perspective( _matShadowProj, - (light as any).angle, + spotLight.angle, 1.0, 0.001, - (light as any).range, + spotLight.range, true, cap.clipSpaceMinZ, cap.clipSpaceSignY, @@ -565,7 +566,4 @@ export class PipelineUBO { Color.toArray(this._shadowUBO, data, offset); } } - - public destroy (): void { - } } From d1e354d62c527b8342be6138d7a9c2bf3a0de34b Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Fri, 8 Sep 2023 11:32:31 +0800 Subject: [PATCH 3/4] fix ci error --- cocos/rendering/pipeline-ubo.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos/rendering/pipeline-ubo.ts b/cocos/rendering/pipeline-ubo.ts index 076c681ba54..81c84ebcf3f 100644 --- a/cocos/rendering/pipeline-ubo.ts +++ b/cocos/rendering/pipeline-ubo.ts @@ -566,4 +566,7 @@ export class PipelineUBO { Color.toArray(this._shadowUBO, data, offset); } } + + // eslint-disable-next-line @typescript-eslint/no-empty-function + public destroy (): void {} } From 6eaa257e08ffe8cc6d1d4e5948a74e9fa3980274 Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Fri, 8 Sep 2023 11:42:35 +0800 Subject: [PATCH 4/4] fix ci error 3 --- .../cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp index 17812be6bdc..fabf92f5d61 100644 --- a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp @@ -96,10 +96,10 @@ void updateRasterPassConstants(uint32_t width, uint32_t height, Setter &setter) i < static_cast(pipeline::DebugViewCompositeType::MAX_BIT_COUNT); ++i) { const uint32_t offset = i >> 3; const uint32_t bit = i % 8; - debugViewData[1 + offset] += (debugView->isCompositeModeEnabled(i) ? 1.0F : 0.0F) * std::powf(10.0F, static_cast(bit)); + debugViewData[1 + offset] += (debugView->isCompositeModeEnabled(i) ? 1.0F : 0.0F) * powf(10.0F, static_cast(bit)); } - debugViewData[3] += (debugView->isLightingWithAlbedo() ? 1.0F : 0.0F) * std::powf(10.0F, 6); - debugViewData[3] += (debugView->isCsmLayerColoration() ? 1.0F : 0.0F) * std::powf(10.0F, 7); + debugViewData[3] += (debugView->isLightingWithAlbedo() ? 1.0F : 0.0F) * powf(10.0F, static_cast(6)); + debugViewData[3] += (debugView->isCsmLayerColoration() ? 1.0F : 0.0F) * powf(10.0F, static_cast(7)); } setter.setVec4( "cc_debug_view_mode",