Skip to content

Commit

Permalink
D3D12 Shader Debug Zoo : add a test for UAV Interlocked*
Browse files Browse the repository at this point in the history
RWTexture<int>

InterlockedAdd
InterlockedAnd
InterlockedOr
InterlockedXor
InterlockedMin
InterlockedMax
InterlockedCompareExchange
InterlockedCompareStore
InterlockedExchange
  • Loading branch information
Zorro666 committed Dec 10, 2024
1 parent 8f75a16 commit 8de06cf
Showing 1 changed file with 102 additions and 7 deletions.
109 changes: 102 additions & 7 deletions util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ RWTexture2D<float> unbounduav2 : register(u5);
RWBuffer<float> narrowtypeduav : register(u6);
RWTexture2D<float4> textrwtest : register(u7);
RWTexture2D<float4> floattexrwtest : register(u7);
RWTexture2D<int> inttexrwtest : register(u8);
Buffer<float> narrowtypedsrv : register(t102);
Expand All @@ -184,7 +185,7 @@ Texture2D<float> dimtex_edge : register(t41);
#if (SM_6_2 || SM_6_6) && HAS_16BIT_SHADER_OPS
StructuredBuffer<int16_t> int16srv : register(t42);
#else
StructuredBuffer<int> int16srv : register(t42);
Buffer<int> int16srv : register(t42);
#endif
float4 main(v2f IN) : SV_Target0
Expand Down Expand Up @@ -765,13 +766,106 @@ float4 main(v2f IN) : SV_Target0
{
float4 value = float4(posone, posone/3, posone/4, posone/5);
int2 uv = int2(31,37);
textrwtest[uv] = value;
return textrwtest[uv];
floattexrwtest[uv] = value;
return floattexrwtest[uv];
}
#if SM_6_2 || SM_6_6
if(IN.tri == 84)
{
return float4(int16srv[0].x, int16srv[1].x, int16srv[2].x, int16srv[3].x);
#endif
}
// Only test Atomic operations on SM6_0 and above
#if SM_6_0 || SM_6_2 || SM_6_6
if(IN.tri == 85)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedAdd(inttexrwtest[uv], value, original);
InterlockedAdd(inttexrwtest[uv], -value, original);
return inttexrwtest[uv];
}
if(IN.tri == 86)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedAnd(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 87)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedOr(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 88)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedXor(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 89)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedMin(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 90)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedMax(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 91)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedExchange(inttexrwtest[uv], value, original);
return inttexrwtest[uv];
}
if(IN.tri == 92)
{
int value = IN.tri;
int original;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedCompareExchange(inttexrwtest[uv], value, value+1, original);
return inttexrwtest[uv];
}
if(IN.tri == 93)
{
int value = IN.tri;
int u = 3 * (IN.tri - 85) + 17;
int2 uv = int2(u,37);
inttexrwtest[uv] = 100;
InterlockedCompareStore(inttexrwtest[uv], value, value+1);
return inttexrwtest[uv];
}
#endif // #if SM_6_0 || SM_6_2 || SM_6_6
return float4(0.4f, 0.4f, 0.4f, 0.4f);
}
Expand Down Expand Up @@ -962,7 +1056,7 @@ void main()
tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0, 0, 8, 0),
tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 0, 1, 2, 10),
tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0, 100, 5, 20),
tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 0, 4, 4, 30),
tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 0, 4, 5, 30),
multiRangeParam,
uavParam(D3D12_SHADER_VISIBILITY_PIXEL, 0, 21),
srvParam(D3D12_SHADER_VISIBILITY_PIXEL, 0, 20),
Expand Down Expand Up @@ -1193,6 +1287,7 @@ void main()
MakeUAV(narrowtypedbuf).Format(DXGI_FORMAT_R16_FLOAT).CreateGPU(32);

MakeUAV(smiley).Format(DXGI_FORMAT_R8G8B8A8_UNORM).CreateGPU(33);
MakeUAV(smiley).Format(DXGI_FORMAT_R32_SINT).CreateGPU(34);

float structdata[220];
for(int i = 0; i < 220; i++)
Expand Down

0 comments on commit 8de06cf

Please sign in to comment.