File: VK_Indirect.py

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (317 lines) | stat: -rw-r--r-- 12,931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import rdtest
import struct
import renderdoc as rd


class VK_Indirect(rdtest.TestCase):
    def get_capture(self):
        return rdtest.run_and_capture("demos_x64", "VK_Indirect", 5)

    def check_overlay(self, eventId: int, out: rd.ReplayOutput, tex: rd.TextureDisplay, save_data: rd.TextureSave):
        pipe: rd.PipeState = self.controller.GetPipelineState()

        # Check that the highlight draw overlay is empty
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId

        out.SetTextureDisplay(tex)

        overlay_path = rdtest.get_tmp_path(str(eventId) + '_draw.png')
        ref_path = self.get_ref_path(str(eventId) + '_draw.png')

        save_data.resourceId = out.GetDebugOverlayTexID()

        self.controller.SaveTexture(save_data, overlay_path)

        if not rdtest.image_compare(overlay_path, ref_path):
            raise rdtest.TestFailureException("Reference and output image differ @ EID {}".format(str(eventId)),
                                              ref_path, overlay_path)

    def check_capture(self):
        self.check_final_backbuffer()

        dispatches = self.find_draw("Dispatches")

        # Set up a ReplayOutput and TextureSave for quickly testing the drawcall highlight overlay
        out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(),
                                                            rd.ReplayOutputType.Texture)

        self.check(out is not None)

        out.SetDimensions(100, 100)

        tex = rd.TextureDisplay()
        tex.overlay = rd.DebugOverlay.Drawcall

        save_data = rd.TextureSave()
        save_data.destType = rd.FileType.PNG

        # Rewind to the start of the capture
        draw: rd.DrawcallDescription = dispatches.children[0]
        while draw.previous is not None:
            draw = draw.previous

        # Ensure we can select all draws
        while draw is not None:
            self.controller.SetFrameEvent(draw.eventId, False)
            draw = draw.next

        rdtest.log.success("Selected all draws")

        self.check(dispatches and len(dispatches.children) == 3)

        self.check(dispatches.children[0].dispatchDimension == [0,0,0])
        self.check(dispatches.children[1].dispatchDimension == [1,1,1])
        self.check(dispatches.children[2].dispatchDimension == [3,4,5])

        rdtest.log.success("Indirect dispatches are the correct dimensions")

        self.controller.SetFrameEvent(dispatches.children[2].eventId, False)

        pipe: rd.PipeState = self.controller.GetPipelineState()

        ssbo: rd.BoundResource = pipe.GetReadWriteResources(rd.ShaderStage.Compute)[0].resources[0]
        data: bytes = self.controller.GetBufferData(ssbo.resourceId, 0, 0)

        rdtest.log.print("Got {} bytes of uints".format(len(data)))

        uints = [struct.unpack_from('=4L', data, offs) for offs in range(0, len(data), 16)]

        for x in range(0, 6):  # 3 groups of 2 threads each
            for y in range(0, 8):  # 3 groups of 2 threads each
                for z in range(0, 5):  # 5 groups of 1 thread each
                    idx = 100 + z*8*6 + y*6 + x
                    rdtest.value_compare(uints[idx], [x, y, z, 12345])

        rdtest.log.success("Dispatched buffer contents are as expected")

        empties = self.find_draw("Empty draws")

        self.check(empties and len(empties.children) == 2)

        draw: rd.DrawcallDescription
        for draw in empties.children:
            self.check(draw.numIndices == 0)
            self.check(draw.numInstances == 0)

            self.controller.SetFrameEvent(draw.eventId, False)

            # Check that we have empty PostVS
            postvs_data = self.get_postvs(rd.MeshDataStage.VSOut, 0, 1)
            self.check(len(postvs_data) == 0)

            self.check_overlay(draw.eventId, out, tex, save_data)

        rdtest.log.success("Empty draws are empty")

        indirects = self.find_draw("Indirect draws")

        self.check('vkCmdDrawIndirect' in indirects.children[0].name)
        self.check('vkCmdDrawIndexedIndirect' in indirects.children[1].name)
        self.check(len(indirects.children[1].children) == 2)

        rdtest.log.success("Correct number of indirect draws")

        # vkCmdDrawIndirect(...)
        draw = indirects.children[0]
        self.check(draw.numIndices == 3)
        self.check(draw.numInstances == 2)

        self.controller.SetFrameEvent(draw.eventId, False)

        # Check that we have PostVS as expected
        postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

        postvs_ref = {
            0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.8, -0.5, 0.0, 1.0]},
            1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.7, -0.8, 0.0, 1.0]},
            2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.6, -0.5, 0.0, 1.0]},
        }

        self.check_mesh_data(postvs_ref, postvs_data)
        self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

        self.check_overlay(draw.eventId, out, tex, save_data)

        rdtest.log.success("{} is as expected".format(draw.name))

        # vkCmdDrawIndexedIndirect[0](...)
        draw = indirects.children[1].children[0]
        self.check(draw.numIndices == 3)
        self.check(draw.numInstances == 3)

        self.controller.SetFrameEvent(draw.eventId, False)

        # Check that we have PostVS as expected
        postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

        # These indices are the *output* indices, which have been rebased/remapped, so are not the same as the input
        # indices
        postvs_ref = {
            0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.6, -0.5, 0.0, 1.0]},
            1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.5, -0.8, 0.0, 1.0]},
            2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.4, -0.5, 0.0, 1.0]},
        }

        self.check_mesh_data(postvs_ref, postvs_data)
        self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

        self.check_overlay(draw.eventId, out, tex, save_data)

        rdtest.log.success("{} is as expected".format(draw.name))

        # vkCmdDrawIndexedIndirect[1](...)
        draw = indirects.children[1].children[1]
        self.check(draw.numIndices == 6)
        self.check(draw.numInstances == 2)

        self.controller.SetFrameEvent(draw.eventId, False)

        # Check that we have PostVS as expected
        postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

        postvs_ref = {
            0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.4, -0.5, 0.0, 1.0]},
            1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.3, -0.8, 0.0, 1.0]},
            2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.2, -0.8, 0.0, 1.0]},

            3: {'vtx': 3, 'idx': 3, 'gl_PerVertex.gl_Position': [-0.1, -0.5, 0.0, 1.0]},
            4: {'vtx': 4, 'idx': 4, 'gl_PerVertex.gl_Position': [ 0.0, -0.8, 0.0, 1.0]},
            5: {'vtx': 5, 'idx': 5, 'gl_PerVertex.gl_Position': [ 0.1, -0.8, 0.0, 1.0]},
        }

        self.check_mesh_data(postvs_ref, postvs_data)
        self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

        self.check_overlay(draw.eventId, out, tex, save_data)

        rdtest.log.success("{} is as expected".format(draw.name))

        indirect_count_root = self.find_draw("KHR_draw_indirect_count")

        if indirect_count_root is not None:
            self.check(indirect_count_root.children[0].name == 'Empty count draws')
            self.check(indirect_count_root.children[1].name == 'Indirect count draws')

            empties = indirect_count_root.children[0]

            self.check(empties and len(empties.children) == 2)

            draw: rd.DrawcallDescription
            for draw in empties.children:
                self.check(draw.numIndices == 0)
                self.check(draw.numInstances == 0)

                self.controller.SetFrameEvent(draw.eventId, False)

                # Check that we have empty PostVS
                postvs_data = self.get_postvs(rd.MeshDataStage.VSOut, 0, 1)
                self.check(len(postvs_data) == 0)

                self.check_overlay(draw.eventId, out, tex, save_data)

            # vkCmdDrawIndirectCountKHR
            draw_indirect = indirect_count_root.children[1].children[0]

            self.check(draw_indirect and len(draw_indirect.children) == 1)

            # vkCmdDrawIndirectCountKHR[0]
            draw = draw_indirect.children[0]

            self.check(draw.numIndices == 3)
            self.check(draw.numInstances == 4)

            self.controller.SetFrameEvent(draw.eventId, False)

            # Check that we have PostVS as expected
            postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

            # These indices are the *output* indices, which have been rebased/remapped, so are not the same as the input
            # indices
            postvs_ref = {
                0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.8, 0.5, 0.0, 1.0]},
                1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.7, 0.2, 0.0, 1.0]},
                2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.6, 0.5, 0.0, 1.0]},
            }

            self.check_mesh_data(postvs_ref, postvs_data)
            self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

            self.check_overlay(draw.eventId, out, tex, save_data)

            rdtest.log.success("{} is as expected".format(draw.name))

            # vkCmdDrawIndexedIndirectCountKHR
            draw_indirect = indirect_count_root.children[1].children[1]

            self.check(draw_indirect and len(draw_indirect.children) == 3)

            # vkCmdDrawIndirectCountKHR[0]
            draw = draw_indirect.children[0]
            self.check(draw.numIndices == 3)
            self.check(draw.numInstances == 1)

            self.controller.SetFrameEvent(draw.eventId, False)

            # Check that we have PostVS as expected
            postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

            # These indices are the *output* indices, which have been rebased/remapped, so are not the same as the input
            # indices
            postvs_ref = {
                0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.6, 0.5, 0.0, 1.0]},
                1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.5, 0.2, 0.0, 1.0]},
                2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.4, 0.5, 0.0, 1.0]},
            }

            self.check_mesh_data(postvs_ref, postvs_data)
            self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

            self.check_overlay(draw.eventId, out, tex, save_data)

            rdtest.log.success("{} is as expected".format(draw.name))

            # vkCmdDrawIndirectCountKHR[1]
            draw = draw_indirect.children[1]
            self.check(draw.numIndices == 0)
            self.check(draw.numInstances == 0)

            self.controller.SetFrameEvent(draw.eventId, False)

            postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

            self.check(len(postvs_data) == 0)

            self.check_overlay(draw.eventId, out, tex, save_data)

            rdtest.log.success("{} is as expected".format(draw.name))

            # vkCmdDrawIndirectCountKHR[2]
            draw = draw_indirect.children[2]
            self.check(draw.numIndices == 6)
            self.check(draw.numInstances == 2)

            self.controller.SetFrameEvent(draw.eventId, False)

            # Check that we have PostVS as expected
            postvs_data = self.get_postvs(rd.MeshDataStage.VSOut)

            # These indices are the *output* indices, which have been rebased/remapped, so are not the same as the input
            # indices
            postvs_ref = {
                0: {'vtx': 0, 'idx': 0, 'gl_PerVertex.gl_Position': [-0.4, 0.5, 0.0, 1.0]},
                1: {'vtx': 1, 'idx': 1, 'gl_PerVertex.gl_Position': [-0.3, 0.2, 0.0, 1.0]},
                2: {'vtx': 2, 'idx': 2, 'gl_PerVertex.gl_Position': [-0.2, 0.2, 0.0, 1.0]},

                3: {'vtx': 3, 'idx': 3, 'gl_PerVertex.gl_Position': [-0.1, 0.5, 0.0, 1.0]},
                4: {'vtx': 4, 'idx': 4, 'gl_PerVertex.gl_Position': [ 0.0, 0.2, 0.0, 1.0]},
                5: {'vtx': 5, 'idx': 5, 'gl_PerVertex.gl_Position': [ 0.1, 0.2, 0.0, 1.0]},
            }

            self.check_mesh_data(postvs_ref, postvs_data)
            self.check(len(postvs_data) == len(postvs_ref))  # We shouldn't have any extra vertices

            self.check_overlay(draw.eventId, out, tex, save_data)

            rdtest.log.success("{} is as expected".format(draw.name))
        else:
            rdtest.log.print("KHR_draw_indirect_count not tested")