Skip to content

Commit

Permalink
removed split downsampling pass because of increased limits for webgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
christing12 committed Nov 17, 2023
1 parent f5d6832 commit 54ceed8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public MultiScaleVO(AmbientOcclusion settings)
m_R16Format = RenderTextureFormat.RFloat;
}
}

#else
if (!SystemInfo.IsFormatSupported(GraphicsFormatUtility.GetGraphicsFormat(m_R8Format, false), FormatUsage.LoadStore))
{
Expand Down Expand Up @@ -331,10 +332,6 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
}

// 1st downsampling pass.

// Some platforms only support 4 writable storage textures, so we need to split the downsampling
// into two passes. The first pass downsamples the depth buffer to 2x2 tiles, the second pass
// downsamples to 4x4 tiles.
var cs = m_Resources.computeShaders.multiScaleAODownsample1;
int kernel = cs.FindKernel(isMSAA ? "MultiScaleVODownsample1_MSAA" : "MultiScaleVODownsample1");

Expand All @@ -343,14 +340,8 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
cmd.SetComputeTextureParam(cs, kernel, "DS2xAtlas", ShaderIDs.TiledDepth1);
cmd.SetComputeVectorParam(cs, "ZBufferParams", CalculateZBufferParams(camera));
cmd.SetComputeTextureParam(cs, kernel, "Depth", depthMapId);

cmd.DispatchCompute(cs, kernel, m_ScaledWidths[(int)MipLevel.L4], m_ScaledHeights[(int)MipLevel.L4], 1);

kernel = cs.FindKernel(isMSAA ? "MultiScaleVODownsample1_MSAA_4x" : "MultiScaleVODownsample1_4x");
cmd.SetComputeTextureParam(cs, kernel, "DS4x", ShaderIDs.LowDepth2);
cmd.SetComputeTextureParam(cs, kernel, "DS4xAtlas", ShaderIDs.TiledDepth2);
cmd.SetComputeTextureParam(cs, kernel, "Depth", depthMapId);

cmd.DispatchCompute(cs, kernel, m_ScaledWidths[(int)MipLevel.L4], m_ScaledHeights[(int)MipLevel.L4], 1);

if (needDepthMapRelease)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@
#pragma exclude_renderers gles gles3 d3d11_9x

#pragma kernel MultiScaleVODownsample1 main=MultiScaleVODownsample1
#pragma kernel MultiScaleVODownsample1_4x main=MultiScaleVODownsample1_4x DS4x_
#pragma kernel MultiScaleVODownsample1_MSAA main=MultiScaleVODownsample1_MSAA MSAA
#pragma kernel MultiScaleVODownsample1_MSAA_4x main=MultiScaleVODownsample1_MSAA_4x MSAA DS4x_

#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"

#ifdef MSAA
// Output textures
#ifdef DS4x_
RWTexture2D<float2> DS4x;
RWTexture2DArray<float2> DS4xAtlas;
#else
RWTexture2D<float2> LinearZ;
RWTexture2D<float2> DS2x;
RWTexture2DArray<float2> DS2xAtlas;
#endif

// Input textures
Texture2D<float4> Depth;
Expand All @@ -47,14 +42,11 @@ Texture2D<float4> Depth;
groupshared float2 g_CacheW[256];
#else
// Output textures
#ifdef DS4x_
RWTexture2D<float> DS4x;
RWTexture2DArray<float> DS4xAtlas;
#else
RWTexture2D<float> LinearZ;
RWTexture2D<float> DS2x;
RWTexture2DArray<float> DS2xAtlas;
#endif

// Input textures
Texture2D<float> Depth;
Expand Down Expand Up @@ -82,9 +74,7 @@ float2 Linearize(uint2 st)
if (depth.x == 1) dist.x = 1e5;
if (depth.y == 1) dist.y = 1e5;
#endif
#ifndef DS4x_
LinearZ[st] = dist;
#endif
return dist;
}
#else
Expand All @@ -97,9 +87,7 @@ float Linearize(uint2 st)
#else
if (depth == 1) dist = 1e5;
#endif
#ifndef DS4x_
LinearZ[st] = dist;
#endif
return dist;
}
#endif
Expand Down Expand Up @@ -132,18 +120,15 @@ void main(uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex, uint3 GTid : SV_Group
#endif
uint2 st = DTid.xy;
uint slice = ((st.x & 3) | (st.y << 2)) & 15;
#ifndef DS4x_
DS2x[st] = w1;
DS2xAtlas[uint3(st >> 2, slice)] = w1;
#else
if ((GI & 011) == 0)
{
st = DTid.xy >> 1;
slice = ((st.x & 3) | (st.y << 2)) & 15;
DS4x[st] = w1;
DS4xAtlas[uint3(st >> 2, slice)] = w1;
}
#endif
}

#endif

0 comments on commit 54ceed8

Please sign in to comment.