Skip to content

Commit f69e87c

Browse files
kechoEvergreen
authored andcommitted
[JIRA # UMM-64133] Fixing hardware DRS half res downsample.
* Fixing the wrong texture being set (due to resource name leaking) for half res downsample: instead of using _CameraDepthTexture which could be anything, using an new explicit name _SourceDownsampleDepth * When hardware DRS is on, we can safely assume that the ratio between the input and output textures is 1 because the GPU hardware sizes are watertight. Jira: https://jira.unity3d.com/browse/UUM-64133
1 parent c96bae6 commit f69e87c

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ class DownsampleDepthForLowResPassData
14561456
public float downsampleScale;
14571457
public Material downsampleDepthMaterial;
14581458
public TextureHandle depthTexture;
1459+
public TextureHandle depthPyramidTexture;
14591460
public TextureHandle downsampledDepthBuffer;
14601461
public Rect viewport;
14611462

@@ -1499,11 +1500,9 @@ void DownsampleDepthForLowResTransparency(RenderGraph renderGraph, HDCamera hdCa
14991500
passData.computesMip1OfAtlas = computeMip1OfPyramid;
15001501
passData.downsampleScale = hdCamera.lowResScale;
15011502
passData.viewport = hdCamera.lowResViewport;
1502-
passData.depthTexture = builder.ReadTexture(output.depthPyramidTexture);
1503+
passData.depthTexture = builder.ReadTexture(output.resolvedDepthBuffer);
15031504
if (computeMip1OfPyramid)
1504-
{
1505-
passData.depthTexture = builder.WriteTexture(passData.depthTexture);
1506-
}
1505+
passData.depthPyramidTexture = builder.WriteTexture(output.depthPyramidTexture);
15071506

15081507
passData.downsampledDepthBuffer = builder.UseDepthBuffer(renderGraph.CreateTexture(
15091508
new TextureDesc(Vector2.one * hdCamera.lowResScale, true, true) { depthBufferBits = DepthBits.Depth32, name = "LowResDepthBuffer" }), DepthAccess.Write);
@@ -1514,20 +1513,27 @@ void DownsampleDepthForLowResTransparency(RenderGraph renderGraph, HDCamera hdCa
15141513
if (data.computesMip1OfAtlas)
15151514
{
15161515
data.downsampleDepthMaterial.SetVector(HDShaderIDs._DstOffset, new Vector4(data.mip0Offset.x, data.mip0Offset.y, 0.0f, 0.0f));
1517-
context.cmd.SetRandomWriteTarget(1, data.depthTexture);
1516+
context.cmd.SetRandomWriteTarget(1, data.depthPyramidTexture);
15181517
}
15191518

15201519
if (data.useGatherDownsample)
15211520
{
15221521
float downsampleScaleInv = 1.0f / data.downsampleScale;
15231522
RenderTexture srcTexture = data.depthTexture;
15241523
RenderTexture destTexture = data.downsampledDepthBuffer;
1525-
float uvScaleX = ((float)destTexture.width / (float)srcTexture.width) * downsampleScaleInv;
1526-
float uvScaleY = ((float)destTexture.height / (float)srcTexture.height) * downsampleScaleInv;
1524+
float uvScaleX = 1.0f;
1525+
float uvScaleY = 1.0f;
1526+
if (!DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled())
1527+
{
1528+
uvScaleX = ((float)destTexture.width / (float)srcTexture.width) * downsampleScaleInv;
1529+
uvScaleY = ((float)destTexture.height / (float)srcTexture.height) * downsampleScaleInv;
1530+
}
1531+
15271532
data.downsampleDepthMaterial.SetVector(HDShaderIDs._ScaleBias, new Vector4(uvScaleX, uvScaleY, 0.0f, 0.0f));
15281533
}
15291534

15301535
context.cmd.SetViewport(data.viewport);
1536+
context.cmd.SetGlobalTexture(HDShaderIDs._SourceDownsampleDepth, data.depthTexture);
15311537
context.cmd.DrawProcedural(Matrix4x4.identity, data.downsampleDepthMaterial, 0, MeshTopology.Triangles, 3, 1, null);
15321538

15331539
if (data.computesMip1OfAtlas)

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ static class HDShaderIDs
521521
public static readonly int _ComputeThicknessScale = Shader.PropertyToID("_ComputeThicknessScale");
522522
public static readonly int _ComputeThicknessShowOverlapCount = Shader.PropertyToID("_ComputeThicknessShowOverlapCount");
523523
public static readonly int _VolumetricCloudsDebugMode = Shader.PropertyToID("_VolumetricCloudsDebugMode");
524+
public static readonly int _SourceDownsampleDepth = Shader.PropertyToID("_SourceDownsampleDepth");
524525

525526
public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap");
526527
public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap");

Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/DownsampleDepth.shader

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Shader "Hidden/HDRP/DownsampleDepth"
5252
#endif
5353
}
5454

55+
TEXTURE2D_X(_SourceDownsampleDepth);
56+
5557
#ifdef OUTPUT_FIRST_MIP_OF_MIPCHAIN
5658
#ifdef SHADER_API_PSSL
5759
RW_TEXTURE2D_X(float, _OutputTexture) : register(u0);
@@ -67,15 +69,15 @@ Shader "Hidden/HDRP/DownsampleDepth"
6769
{
6870
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
6971
#ifdef GATHER_DOWNSAMPLE
70-
float4 depths = GATHER_RED_TEXTURE2D_X(_CameraDepthTexture, s_linear_clamp_sampler, input.texcoord * _ScaleBias.xy + _ScaleBias.zw);
72+
float4 depths = GATHER_RED_TEXTURE2D_X(_SourceDownsampleDepth, s_linear_clamp_sampler, input.texcoord * _ScaleBias.xy + _ScaleBias.zw);
7173
outputDepth = MinDepth(depths);
7274
#else
7375
uint2 fullResUpperCorner = uint2((((float2)input.positionCS.xy - 0.5f) * 2.0) + 0.5f);
7476
float4 depths;
75-
depths.x = LoadCameraDepth(fullResUpperCorner);
76-
depths.y = LoadCameraDepth(fullResUpperCorner + uint2(0, 1));
77-
depths.z = LoadCameraDepth(fullResUpperCorner + uint2(1, 0));
78-
depths.w = LoadCameraDepth(fullResUpperCorner + uint2(1, 1));
77+
depths.x = LOAD_TEXTURE2D_X_LOD(_SourceDownsampleDepth, fullResUpperCorner, 0);
78+
depths.y = LOAD_TEXTURE2D_X_LOD(_SourceDownsampleDepth, fullResUpperCorner + uint2(0, 1), 0);
79+
depths.z = LOAD_TEXTURE2D_X_LOD(_SourceDownsampleDepth, fullResUpperCorner + uint2(1, 0), 0);
80+
depths.w = LOAD_TEXTURE2D_X_LOD(_SourceDownsampleDepth, fullResUpperCorner + uint2(1, 1), 0);
7981

8082
float minDepth = MinDepth(depths);
8183
#if MIN_DOWNSAMPLE

0 commit comments

Comments
 (0)