From d1856f0e7fe0c0118fecda52c9c9ae2b553d4205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sun, 8 Feb 2026 14:21:11 +0100 Subject: [PATCH] fixed undefined behavior in volumetric cloud and aerial perspective cubemap capture --- WickedEngine/shaders/ShaderInterop_Renderer.h | 6 +++--- WickedEngine/shaders/aerialPerspectiveCS.hlsl | 3 +-- WickedEngine/shaders/volumetricCloud_renderCS.hlsl | 3 +-- WickedEngine/wiRenderer.cpp | 2 -- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index 761000f1b..ecf9d5b77 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -1720,10 +1720,10 @@ struct AerialPerspectiveCapturePushConstants uint2 resolution; float2 resolution_rcp; - int texture_input; int texture_output; float padding0; float padding1; + float padding2; }; struct VolumetricCloudCapturePushConstants @@ -1731,15 +1731,15 @@ struct VolumetricCloudCapturePushConstants uint2 resolution; float2 resolution_rcp; - int texture_input; int texture_output; int maxStepCount; float LODMin; - float shadowSampleCount; + float groundContributionSampleCount; float padding0; float padding1; + float padding2; }; diff --git a/WickedEngine/shaders/aerialPerspectiveCS.hlsl b/WickedEngine/shaders/aerialPerspectiveCS.hlsl index cc413f9f5..dda50597c 100644 --- a/WickedEngine/shaders/aerialPerspectiveCS.hlsl +++ b/WickedEngine/shaders/aerialPerspectiveCS.hlsl @@ -95,7 +95,6 @@ void RenderAerialPerspective(uint3 DTid, float2 uv, float depth, float3 depthWor [numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)] void main(uint3 DTid : SV_DispatchThreadID) { - TextureCube input = bindless_cubemaps[descriptor_index(capture.texture_input)]; RWTexture2DArray output = bindless_rwtextures2DArray[descriptor_index(capture.texture_output)]; const float2 uv = (DTid.xy + 0.5) * capture.resolution_rcp; @@ -113,7 +112,7 @@ void main(uint3 DTid : SV_DispatchThreadID) const float depth = texture_input_depth.SampleLevel(sampler_point_clamp, N, 0).r; #endif // MSAA - float4 composite = input.SampleLevel(sampler_linear_clamp, N, 0); + float4 composite = output[uint3(DTid.xy, DTid.z)]; // Ignore skybox if (depth == 0.0) diff --git a/WickedEngine/shaders/volumetricCloud_renderCS.hlsl b/WickedEngine/shaders/volumetricCloud_renderCS.hlsl index 22c3fd9d9..f4266682b 100644 --- a/WickedEngine/shaders/volumetricCloud_renderCS.hlsl +++ b/WickedEngine/shaders/volumetricCloud_renderCS.hlsl @@ -724,7 +724,6 @@ void RenderClouds(uint3 DTid, float2 uv, float depth, float3 depthWorldPosition, [numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)] void main(uint3 DTid : SV_DispatchThreadID) { - TextureCube input = bindless_cubemaps[descriptor_index(capture.texture_input)]; RWTexture2DArray output = bindless_rwtextures2DArray[descriptor_index(capture.texture_output)]; const float2 uv = (DTid.xy + 0.5) * capture.resolution_rcp; @@ -751,7 +750,7 @@ void main(uint3 DTid : SV_DispatchThreadID) float2 cloudDepth = 0; RenderClouds(DTid, uv, depth, depthWorldPosition, rayOrigin, rayDirection, cloudColor, cloudDepth); - float4 composite = input.SampleLevel(sampler_linear_clamp, N, 0); + float4 composite = output[uint3(DTid.xy, DTid.z)]; // Output output[uint3(DTid.xy, DTid.z)] = float4(composite.rgb * (1.0 - cloudColor.a) + cloudColor.rgb, composite.a * (1.0 - cloudColor.a)); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index c40a0bc21..6a55e136b 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -9361,7 +9361,6 @@ void RefreshEnvProbes(const Visibility& vis, CommandList cmd) push.resolution.y = desc.height; push.resolution_rcp.x = 1.0f / push.resolution.x; push.resolution_rcp.y = 1.0f / push.resolution.y; - push.texture_input = device->GetDescriptorIndex(&envrenderingColorBuffer, SubresourceType::SRV); push.texture_output = device->GetDescriptorIndex(&envrenderingColorBuffer, SubresourceType::UAV); device->PushConstants(&push, sizeof(push), cmd); @@ -9425,7 +9424,6 @@ void RefreshEnvProbes(const Visibility& vis, CommandList cmd) push.resolution.y = desc.height; push.resolution_rcp.x = 1.0f / push.resolution.x; push.resolution_rcp.y = 1.0f / push.resolution.y; - push.texture_input = device->GetDescriptorIndex(&envrenderingColorBuffer, SubresourceType::SRV); push.texture_output = device->GetDescriptorIndex(&envrenderingColorBuffer, SubresourceType::UAV); if (probe.IsRealTime())