@@ -50,6 +50,46 @@ def image_save(self, action: rd.ActionDescription):
5050
5151 rdtest .log .success ('Successfully saved images at {}' .format (action .eventId ))
5252
53+ def compute_debug (self , action : rd .ActionDescription ):
54+ pipe : rd .PipeState = self .controller .GetPipelineState ()
55+
56+ refl : rd .ShaderReflection = pipe .GetShaderReflection (rd .ShaderStage .Compute )
57+
58+ if pipe .GetShader (rd .ShaderStage .Compute ) == rd .ResourceId .Null ():
59+ rdtest .log .print (f"No compute shader bound at { action .eventId } " )
60+ return
61+
62+ if not (action .flags & rd .ActionFlags .Dispatch ) and action .drawIndex == 0 :
63+ rdtest .log .print (f"{ action .eventId } is not a debuggable action" )
64+ return
65+
66+ wgSize = action .dispatchDimension
67+ if any (dim == 0 for dim in wgSize ):
68+ rdtest .log .print (f"Empty dispatch ({ wgSize [0 ]} x{ wgSize [1 ]} x{ wgSize [2 ]} ), skipping" )
69+ return
70+
71+ groupid = [0 ,0 ,0 ]
72+ for i in range (3 ):
73+ groupid [i ] = random .randint (0 , wgSize [i ]- 1 )
74+
75+ threadid = [0 ,0 ,0 ]
76+ for i in range (3 ):
77+ threadid [i ] = random .randint (0 , refl .dispatchThreadsDimension [i ]- 1 )
78+
79+ rdtest .log .print (f"Debug Thread Workgroup:{ wgSize } groupid:{ tuple (groupid )} threadid:{ tuple (threadid )} " )
80+ trace : rd .ShaderDebugTrace = self .controller .DebugThread (tuple (groupid ), tuple (threadid ))
81+
82+ if trace .debugger is None :
83+ self .controller .FreeTrace (trace )
84+ rdtest .log .print ("No debug result" )
85+ return
86+
87+ cycles , variables = self .process_trace (trace )
88+
89+ rdtest .log .success (f'Successfully debugged compute shader in { cycles } cycles { len (refl .outputSignature )} ' )
90+
91+ self .controller .FreeTrace (trace )
92+
5393 def vert_debug (self , action : rd .ActionDescription ):
5494 pipe : rd .PipeState = self .controller .GetPipelineState ()
5595
@@ -364,6 +404,7 @@ def iter_test(self):
364404
365405 test_chance = 0.1 # Chance of doing anything at all
366406 do_image_save = 0.25 # Chance of saving images of the outputs
407+ do_compute_debug = 1.0 # Chance of debugging a compute thread
367408 do_vert_debug = 1.0 # Chance of debugging a vertex (if valid)
368409 do_pixel_debug = 1.0 # Chance of doing pixel history at the current event and debugging a pixel (if valid)
369410 mesh_output = 1.0 # Chance of fetching mesh output data
@@ -373,6 +414,7 @@ def iter_test(self):
373414
374415 event_tests = {
375416 'Image Save' : {'chance' : do_image_save , 'func' : self .image_save },
417+ 'Compute Debug' : {'chance' : do_compute_debug , 'func' : self .compute_debug },
376418 'Vertex Debug' : {'chance' : do_vert_debug , 'func' : self .vert_debug },
377419 'Pixel History & Debug' : {'chance' : do_pixel_debug , 'func' : self .pixel_debug },
378420 'Mesh Output' : {'chance' : mesh_output , 'func' : self .mesh_output },
0 commit comments