xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/d3d11/shaders/ResolveDepthStencil.hlsl (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1static const float2 g_Corners[6] =
2{
3    float2(-1.0f,  1.0f),
4    float2( 1.0f, -1.0f),
5    float2(-1.0f, -1.0f),
6    float2(-1.0f,  1.0f),
7    float2( 1.0f,  1.0f),
8    float2( 1.0f, -1.0f),
9};
10
11void VS_ResolveDepthStencil(in uint id : SV_VertexID,
12                         out float4 position : SV_Position,
13                         out float2 texCoord : TEXCOORD0)
14{
15    float2 corner = g_Corners[id];
16    position = float4(corner.x, corner.y, 0.0f, 1.0f);
17    texCoord = float2((corner.x + 1.0f) * 0.5f, (-corner.y + 1.0f) * 0.5f);
18}
19
20Texture2DMS<float> Depth   : register(t0);
21Texture2DMS<uint2> Stencil : register(t1);
22
23void PS_ResolveDepth(in float4 position : SV_Position,
24                     in float2 texCoord : TEXCOORD0,
25                     out float depth : SV_Depth)
26{
27    // MS samplers must use Load
28    uint width, height, samples;
29    Depth.GetDimensions(width, height, samples);
30    uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height));
31    depth = Depth.Load(coord, 0).r;
32}
33
34void PS_ResolveDepthStencil(in float4 position : SV_Position,
35                            in float2 texCoord : TEXCOORD0,
36                            out float2 depthStencil : SV_Target0)
37{
38    // MS samplers must use Load
39    uint width, height, samples;
40    Depth.GetDimensions(width, height, samples);
41    uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height));
42    depthStencil.r = Depth.Load(coord, 0).r;
43    depthStencil.g = float(Stencil.Load(coord, 0).g);
44}
45
46void PS_ResolveStencil(in float4 position : SV_Position,
47                       in float2 texCoord : TEXCOORD0,
48                       out float2 stencil : SV_Target0)
49{
50    // MS samplers must use Load
51    uint width, height, samples;
52    Stencil.GetDimensions(width, height, samples);
53    uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height));
54    stencil.r = 0.0f;
55    stencil.g = float(Stencil.Load(coord, 0).g);
56}
57