Skip to content

Commit aaefec8

Browse files
committed
D3D12_Shader_Debug_Zoo tests for loading from global variables
Includes updating the python test to validate the results from compute shader debugging
1 parent ab3e46d commit aaefec8

File tree

2 files changed

+104
-19
lines changed

2 files changed

+104
-19
lines changed

util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp

+44-5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ StructuredBuffer<int16_t> int16srv : register(t42);
191191
Buffer<int> int16srv : register(t43);
192192
#endif
193193
194+
static const int gConstInt = 10;
195+
static const int gConstIntArray[6] = { 1, 2, 3, 4, 5, 6 };
196+
static int gInt = 3;
197+
static int gIntArray[2] = { 5, 6 };
198+
194199
float4 main(v2f IN) : SV_Target0
195200
{
196201
float posinf = IN.oneVal/IN.zeroVal.x;
@@ -968,6 +973,21 @@ float4 main(v2f IN) : SV_Target0
968973
969974
return structrwtest[z2+5].b;
970975
}
976+
if(IN.tri == 105)
977+
{
978+
// idx = 0
979+
int idx = intval - IN.tri - 7;
980+
return float4(gConstInt, gConstIntArray[idx+5], gConstIntArray[idx+1], gConstIntArray[idx+4]);
981+
}
982+
if(IN.tri == 106)
983+
{
984+
// idx = 0
985+
int idx = intval - IN.tri - 7;
986+
int prev = gInt;
987+
gInt += (idx+1);
988+
gIntArray[idx] = gInt;
989+
return float4(prev, gInt, gIntArray[idx], gIntArray[idx+1]);
990+
}
971991
972992
return float4(0.4f, 0.4f, 0.4f, 0.4f);
973993
}
@@ -1017,13 +1037,32 @@ cbuffer consts : register(b0)
10171037
RWStructuredBuffer<uint4> bufIn : register(u0);
10181038
RWStructuredBuffer<uint4> bufOut : register(u1);
10191039
1040+
groupshared int gsmInt[128];
1041+
10201042
[numthreads(1,1,1)]
1021-
void main()
1043+
void main(int3 inTestIndex : SV_GroupID)
10221044
{
1023-
bufOut[0].x += bufIn[0].x * (uint)boolX;
1024-
bufOut[0].y += bufIn[0].y * (uint)intY;
1025-
bufOut[0].z += bufIn[0].z * (uint)floatZ;
1026-
bufOut[0].w += bufIn[0].w * (uint)doubleX;
1045+
int testIndex = inTestIndex.x;
1046+
int4 testResult = 123;
1047+
if (testIndex == 0)
1048+
{
1049+
testResult = bufOut[0];
1050+
testResult.x += bufIn[0].x * (uint)boolX;
1051+
testResult.y += bufIn[0].y * (uint)intY;
1052+
testResult.z += bufIn[0].z * (uint)floatZ;
1053+
testResult.w += bufIn[0].w * (uint)doubleX;
1054+
}
1055+
else if (testIndex == 1)
1056+
{
1057+
gsmInt[testIndex-1] = testIndex;
1058+
testResult.x = gsmInt[testIndex-1];
1059+
testResult.y = testIndex;
1060+
}
1061+
else
1062+
{
1063+
testResult.x = inTestIndex.x;
1064+
}
1065+
bufOut[testIndex] = testResult;
10271066
}
10281067
10291068
)EOSHADER";

util/test/tests/D3D12/D3D12_Shader_Debug_Zoo.py

+60-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
import renderdoc as rd
22
from typing import List
33
import rdtest
4-
4+
import struct
55

66
class D3D12_Shader_Debug_Zoo(rdtest.TestCase):
77
demos_test_name = 'D3D12_Shader_Debug_Zoo'
88

9+
def parse_var_type(self, varType):
10+
scalarType = varType
11+
countElems = 1
12+
if str(varType[-1]).isdigit():
13+
if str(varType[-2]).isdigit():
14+
scalarType = varType[:-2]
15+
countElems = int(varType[-2:])
16+
else:
17+
scalarType = varType[:-1]
18+
countElems = int(varType[-1:])
19+
return (scalarType, countElems)
20+
21+
def get_source_var_value(self, sourceVars: List[rd.SourceVariableMapping], name, varType, debuggerVars):
22+
sourceVar = [v for v in sourceVars if v.name == name]
23+
if len(sourceVar) != 1:
24+
raise rdtest.TestFailureException(f"Couldn't find source variable {name} {varType}")
25+
26+
scalarType, countElems = self.parse_var_type(varType)
27+
28+
debugged = self.evaluate_source_var(sourceVar[0], debuggerVars)
29+
if scalarType == 'float':
30+
return list(debugged.value.f32v[0:countElems])
31+
elif scalarType == 'int':
32+
return list(debugged.value.s32v[0:countElems])
33+
else:
34+
raise rdtest.TestFailureException(f"Unhandled scalarType {scalarType} {varType}")
35+
return None
36+
937
def check_capture(self):
1038
if not self.controller.GetAPIProperties().shaderDebugging:
1139
rdtest.log.success("Shader debugging not enabled, skipping test")
@@ -166,9 +194,6 @@ def check_capture(self):
166194
else:
167195
rdtest.log.print(f"Skipping undebuggable Pixel shader at {action.eventId} for {shaderModels[sm]}.")
168196

169-
if failed:
170-
raise rdtest.TestFailureException("Some tests were not as expected")
171-
172197
rdtest.log.end_section("VertexSample tests")
173198

174199
test_marker: rd.ActionDescription = self.find_action("Banned")
@@ -235,17 +260,38 @@ def check_capture(self):
235260
continue
236261

237262
# Debug the shader
238-
trace: rd.ShaderDebugTrace = self.controller.DebugThread([0,0,0], [0,0,0])
239-
cycles, variables = self.process_trace(trace)
240-
# Check for non-zero cycles
241-
# TODO: Check source variables have expected values (bit like output variables in Vertex and Pixel Shaders)
242-
self.controller.FreeTrace(trace)
243-
if cycles == 0:
244-
rdtest.log.error("Shader debug cycle count was zero")
245-
failed = True
246-
continue
263+
for groupX in range(action.dispatchDimension[0]):
264+
groupid = (groupX, 0, 0)
265+
threadid = (0, 0, 0)
266+
testIndex = groupX
267+
trace: rd.ShaderDebugTrace = self.controller.DebugThread(groupid, threadid)
268+
cycles, variables = self.process_trace(trace)
269+
# Check for non-zero cycles
270+
if cycles == 0:
271+
rdtest.log.error("Shader debug cycle count was zero")
272+
self.controller.FreeTrace(trace)
273+
failed = True
274+
continue
275+
276+
bufOut = pipe.GetReadWriteResources(rd.ShaderStage.Compute)[1].descriptor.resource
277+
bufdata = self.controller.GetBufferData(bufOut, testIndex*16, 16)
278+
expectedValue = struct.unpack_from("4i", bufdata, 0)
279+
# Test result is in variable called "int4 testResult"
280+
name = 'testResult'
281+
varType = 'int4'
282+
try:
283+
debuggedValue = self.get_source_var_value(trace.instInfo[-1].sourceVars, name, varType, variables)
284+
if not rdtest.value_compare(expectedValue, debuggedValue):
285+
raise rdtest.TestFailureException(f"'{name}' debugger {debuggedValue} doesn't match expected {expectedValue}")
286+
287+
except rdtest.TestFailureException as ex:
288+
rdtest.log.error(f"Test {test} Group:{groupid} Thread:{threadid} Index:{testIndex} failed {ex}")
289+
failed = True
290+
continue
291+
finally:
292+
self.controller.FreeTrace(trace)
247293

248-
rdtest.log.success("Test {} matched as expected".format(test))
294+
rdtest.log.success(f"Test {test} Group:{groupid} Thread:{threadid} as expected")
249295
rdtest.log.end_section(section)
250296

251297
if failed:

0 commit comments

Comments
 (0)