Ejemplo n.º 1
0
    def check_capture(self):
        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

        # find the first draw
        draw = self.find_draw("Draw")

        # check the centre pixel of the viewport is white
        self.controller.SetFrameEvent(draw.eventId, False)

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

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        view: rd.Viewport = pipe.GetViewport(0)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(view.width / 2),
                                              int(view.height / 2), 0, 0, 0)

        if not rdtest.value_compare(picked.floatValue, [1.0, 1.0, 1.0, 1.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("Picked value for first draw is as expected")

        # find the second draw
        draw = self.find_draw("Draw", draw.eventId + 1)

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

        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        view: rd.Viewport = pipe.GetViewport(0)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(view.width / 2),
                                              int(view.height / 2), 0, 0, 0)

        if not rdtest.value_compare(picked.floatValue, [1.0, 1.0, 1.0, 1.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("Picked value for second draw is as expected")
Ejemplo n.º 2
0
    def check_debug(self, vtx, idx, inst, postvs):
        trace: rd.ShaderDebugTrace = self.controller.DebugVertex(vtx, inst, idx, 0)

        if trace.debugger is None:
            self.controller.FreeTrace(trace)

            raise rdtest.TestFailureException("Couldn't debug vertex {} in instance {}".format(vtx, inst))

        cycles, variables = self.process_trace(trace)

        for var in trace.sourceVars:
            var: rd.SourceVariableMapping
            if var.variables[0].type == rd.DebugVariableType.Variable and var.signatureIndex >= 0:
                name = var.name

                if name not in postvs[vtx].keys():
                    raise rdtest.TestFailureException("Don't have expected output for {}".format(name))

                expect = postvs[vtx][name]
                value = self.evaluate_source_var(var, variables)

                if len(expect) != value.columns:
                    raise rdtest.TestFailureException(
                        "Output {} at vert {} (idx {}) instance {} has different size ({} values) to expectation ({} values)"
                            .format(name, vtx, idx, inst, value.columns, len(expect)))

                debugged = value.value.f32v[0:value.columns]

                if not rdtest.value_compare(expect, debugged):
                    raise rdtest.TestFailureException(
                        "Debugged value {} at vert {} (idx {}) instance {}: {} doesn't exactly match postvs output {}".format(
                            name, vtx, idx, inst, debugged, expect))
        rdtest.log.success('Successfully debugged vertex {} in instance {}'
                           .format(vtx, inst))
Ejemplo n.º 3
0
    def check_vertex(self, x, y, result):
        pick = self.out.PickVertex(x, y)

        if not rdtest.value_compare(result, pick):
            raise rdtest.TestFailureException("When picking ({},{}) expected vertex {} in instance {}, but found {} in {}".format(x, y, result[0], result[1], pick[0], pick[1]))

        rdtest.log.success("Picking {},{} returns vertex {} in instance {} as expected".format(x, y, result[0], result[1]))
Ejemplo n.º 4
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

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

        stage = rd.ShaderStage.Pixel

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        variables = self.controller.GetCBufferVariableContents(
            pipe.GetGraphicsPipelineObject(), pipe.GetShader(stage),
            pipe.GetShaderEntryPoint(stage), 0, cbuf.resourceId,
            cbuf.byteOffset, cbuf.byteSize)

        outcol: rd.ShaderVariable = variables[1]

        self.check(outcol.name == "outcol")
        if not rdtest.value_compare(outcol.value.fv[0:4],
                                    [0.0, 0.0, 0.0, 0.0]):
            raise rdtest.TestFailureException(
                "expected outcol to be 0s, but got {}".format(
                    outcol.value.fv[0:4]))

        rdtest.log.success("CBuffer value was truncated as expected")
Ejemplo n.º 5
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture)

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

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0)

        if not rdtest.value_compare(picked.floatValue, [1.0, 0.0, 0.0, 1.0]):
            raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue))

        rdtest.log.success("picked value is as expected")

        out.Shutdown()
Ejemplo n.º 6
0
    def check_modifs_consistent(self, modifs):
        # postmod of each should match premod of the next
        for i in range(len(modifs) - 1):
            a = value_selector(modifs[i].postMod.col)
            b = value_selector(modifs[i + 1].preMod.col)

            if self.is_depth:
                a = (modifs[i].postMod.depth, modifs[i].postMod.stencil)
                b = (modifs[i + 1].preMod.depth, modifs[i + 1].preMod.stencil)

            if a != b:
                raise rdtest.TestFailureException(
                    "postmod at {} primitive {}: {} doesn't match premod at {} primitive {}: {}"
                    .format(modifs[i].eventId, modifs[i].primitiveID, a,
                            modifs[i + 1].eventId, modifs[i + 1].primitiveID,
                            b))

        # Check that if the test failed, its postmod is the same as premod
        for i in range(len(modifs)):
            if not modifs[i].Passed():
                a = value_selector(modifs[i].preMod.col)
                b = value_selector(modifs[i].postMod.col)

                if self.is_depth:
                    a = (modifs[i].preMod.depth, modifs[i].preMod.stencil)
                    b = (modifs[i].postMod.depth, modifs[i].postMod.stencil)

                if not rdtest.value_compare(a, b):
                    raise rdtest.TestFailureException(
                        "postmod at {} primitive {}: {} doesn't match premod: {}"
                        .format(modifs[i].eventId, modifs[i].primitiveID, b,
                                a))
Ejemplo n.º 7
0
    def check_val(self, picked, val, fmt):
        if type(val) != list:
            val = [val, val, val, val]

        if fmt.compType == rd.CompType.UInt or fmt.compType == rd.CompType.SInt:
            val = [int(a) for a in val]
            return rdtest.value_compare(picked.intValue[0:fmt.compCount],
                                        val[0:fmt.compCount])
        else:
            comp_val = picked.floatValue[0:fmt.compCount]
            if fmt.compType == rd.CompType.Depth or fmt.type in [
                    rd.ResourceFormatType.D16S8, rd.ResourceFormatType.D24S8,
                    rd.ResourceFormatType.D32S8
            ]:
                comp_val = [min(1.0, a) for a in comp_val]

            return rdtest.value_compare(comp_val, val[0:fmt.compCount])
Ejemplo n.º 8
0
    def check_capture(self):
        last_action: rd.ActionDescription = self.get_last_action()

        self.controller.SetFrameEvent(last_action.eventId, True)

        action: rd.ActionDescription = self.find_action('Duration')

        min_duration = float(action.customName.split(' = ')[1])

        if rd.IsReleaseBuild():
            if min_duration >= 15.0:
                raise rdtest.TestFailureException(
                    "Minimum duration noted {} ms is too high".format(
                        min_duration))
            rdtest.log.success(
                "Minimum duration ({}) is OK".format(min_duration))
        else:
            rdtest.log.print(
                "Not checking duration ({}) in non-release build".format(
                    min_duration))

        resources = self.controller.GetResources()
        for i in range(8):
            res: rd.ResourceDescription = [
                r for r in resources if r.name == 'Offscreen{}'.format(i)
            ][0]
            tex: rd.TextureDescription = self.get_texture(res.resourceId)

            data = self.controller.GetTextureData(res.resourceId,
                                                  rd.Subresource(0, 0, 0))

            pixels = [
                struct.unpack_from("4f", data, 16 * p)
                for p in range(tex.width * tex.height)
            ]

            unique_pixels = list(set(pixels))

            if len(unique_pixels) > 2:
                raise rdtest.TestFailureException(
                    "Too many pixel values found ({})".format(
                        len(unique_pixels)))

            if (0.0, 0.0, 0.0, 1.0) not in unique_pixels:
                raise rdtest.TestFailureException(
                    "Didn't find background colour in unique pixels list")

            unique_pixels.remove((0.0, 0.0, 0.0, 1.0))

            if not rdtest.value_compare(
                (0.8, 0.8, 0.8, 0.4), unique_pixels[0]):
                raise rdtest.TestFailureException(
                    "Didn't find foreground colour in unique pixels list")

            rdtest.log.success("{} has correct contents".format(res.name))
Ejemplo n.º 9
0
    def sample(self, row, col):
        ret = []
        for p in self.points:
            x = self.view[0] * col + p[0]
            y = self.view[1] * row + p[1]

            picked: rd.PixelValue = self.out.PickPixel(self.tex.resourceId,
                                                       False, x, y, 0, 0, 0)
            ret.append(
                rdtest.value_compare(picked.floatValue, [0.0, 1.0, 1.0, 1.0]))
        return ret
Ejemplo n.º 10
0
    def sample(self, row, col):
        ret = []
        for p in self.points:
            x = self.view[0] * col + p[0]
            y = self.view[1] * row + p[1]

            picked: rd.PixelValue = self.controller.PickPixel(
                self.tex, x, y, rd.Subresource(0, 0, 0), rd.CompType.Typeless)
            ret.append(
                rdtest.value_compare(picked.floatValue, [0.0, 1.0, 1.0, 1.0]))
        return ret
Ejemplo n.º 11
0
 def check_events(self, events, modifs):
     self.check(len(modifs) == len(events))
     # Check for consistency first
     self.check_modifs_consistent(modifs)
     for i in range(len(modifs)):
         for c in range(len(events[i])):
             expected = events[i][c][1]
             actual = events[i][c][0](modifs[i])
             if not rdtest.value_compare(actual, expected):
                 raise rdtest.TestFailureException(
                     "eventId {}, testing {} expected {}, got {}".format(
                         modifs[i].eventId, events[i][c][0].__name__,
                         expected, actual))
Ejemplo n.º 12
0
 def check_events(self, events, modifs, hasSecondary):
     self.check(len(modifs) == len(events), "Expected {} events, got {}".format(len(events), len(modifs)))
     # Check for consistency first. For secondary command buffers,
     # might not have all information, so don't check for consistency
     if not hasSecondary:
         self.check_modifs_consistent(modifs)
     for i in range(len(modifs)):
         for c in range(len(events[i])):
             expected = events[i][c][1]
             actual = events[i][c][0](modifs[i])
             if not rdtest.value_compare(actual, expected, eps=1.0/256.0):
                 raise rdtest.TestFailureException(
                     "eventId {}, primitiveID {}: testing {} expected {}, got {}".format(modifs[i].eventId, modifs[i].primitiveID,
                                                                         events[i][c][0].__name__,
                                                                         expected,
                                                                         actual))
Ejemplo n.º 13
0
    def check_capture(self):
        # Jump to the draw
        draw = self.find_draw("Draw")

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

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

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        # Loop over every test
        for test in range(draw.numInstances):
            # Pick the pixel
            picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                                  4 * test, 0, 0, 0, 0)

            # Debug the shader
            trace: rd.ShaderDebugTrace = self.controller.DebugPixel(
                4 * test, 0, rd.ReplayController.NoPreference,
                rd.ReplayController.NoPreference)

            last_state: rd.ShaderDebugState = trace.states[-1]

            if not rdtest.value_compare(picked.floatValue,
                                        last_state.outputs[0].value.fv[0:4]):
                raise rdtest.TestFailureException(
                    "Test {}: debugged output {} doesn't match actual output {}"
                    .format(test, last_state.outputs[0].value.fv[0:4],
                            picked.floatValue))

            rdtest.log.success("Test {} matched as expected".format(test))

        rdtest.log.success("All tests matched")
Ejemplo n.º 14
0
    def check_modifs_consistent(self, modifs):
        # postmod of each should match premod of the next
        for i in range(len(modifs) - 1):
            if value_selector(modifs[i].postMod.col) != value_selector(
                    modifs[i + 1].preMod.col):
                raise rdtest.TestFailureException(
                    "postmod at {}: {} doesn't match premod at {}: {}".format(
                        modifs[i].eventId,
                        value_selector(modifs[i].postMod.col),
                        modifs[i + 1].eventId,
                        value_selector(modifs[i].preMod.col)))

        # Check that if the test failed, its postmod is the same as premod
        for i in range(len(modifs)):
            if not modifs[i].Passed():
                if not rdtest.value_compare(
                        value_selector(modifs[i].preMod.col),
                        value_selector(modifs[i].postMod.col)):
                    raise rdtest.TestFailureException(
                        "postmod at {}: {} doesn't match premod: {}".format(
                            modifs[i].eventId,
                            value_selector(modifs[i].postMod.col),
                            value_selector(modifs[i].preMod.col)))
Ejemplo n.º 15
0
    def check_capture(self):
        draw = self.find_draw("vkCmdEndRenderPass")

        self.check(draw is not None)

        draw = draw.previous

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

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

        self.tex = pipe.GetOutputTargets()[0].resourceId

        texdetails = self.get_texture(self.tex)

        # Top left we expect a regular line segment.
        s = self.sample(0, 0)

        # All points should be the line color
        if not rdtest.value_compare(s, [True, True, True]):
            raise rdtest.TestFailureException(
                "Normal line picked values {} doesn't match expectation".
                format(s))

        # Next row is unstippled. The lines should either be all present, or not present
        names = ["Rectangle", "Bresenham", "Rectangle Round"]
        for col in [0, 1, 2]:
            s = self.sample(1, col)

            n = "Unstippled {}".format(names[col])

            if s[0]:
                if not rdtest.value_compare(s, [True, True, True]):
                    raise rdtest.TestFailureException(
                        "{} picked values {} doesn't match expectation".format(
                            n, s))
                rdtest.log.success("{} line looks as expected".format(n))
            else:
                if not rdtest.value_compare(s, [False, False, False]):
                    raise rdtest.TestFailureException(
                        "{} picked values {} doesn't match expectation".format(
                            n, s))
                rdtest.log.success("{} line not supported".format(n))

        # Final row is stippled. The lines should be present on each end, and not present in the middle
        # (or not present at all)
        for col in [0, 1, 2]:
            s = self.sample(2, col)

            n = "Stippled {}".format(names[col])

            if s[0]:
                if not rdtest.value_compare(s, [True, False, True]):
                    raise rdtest.TestFailureException(
                        "{} picked values {} doesn't match expectation".format(
                            n, s))
                rdtest.log.success("{} line looks as expected".format(n))
            else:
                if not rdtest.value_compare(s, [False, False, False]):
                    raise rdtest.TestFailureException(
                        "{} picked values {} doesn't match expectation".format(
                            n, s))
                rdtest.log.success("{} line not supported".format(n))

        rdtest.log.success("All lines look as expected")
Ejemplo n.º 16
0
    def pixel_debug(self, draw: rd.DrawcallDescription):
        pipe: rd.PipeState = self.controller.GetPipelineState()

        if pipe.GetShader(rd.ShaderStage.Pixel) == rd.ResourceId.Null():
            rdtest.log.print("No pixel shader bound at {}: {}".format(
                draw.eventId, draw.name))
            return

        if len(pipe.GetOutputTargets()) == 0 and pipe.GetDepthTarget(
        ).resourceId == rd.ResourceId.Null():
            rdtest.log.print("No render targets bound at {}: {}".format(
                draw.eventId, draw.name))
            return

        if not (draw.flags & rd.DrawFlags.Drawcall):
            rdtest.log.print("{}: {} is not a debuggable drawcall".format(
                draw.eventId, draw.name))
            return

        viewport = pipe.GetViewport(0)

        # TODO, query for some pixel this drawcall actually touched.
        x = int(random.random() * viewport.width + viewport.x)
        y = int(random.random() * viewport.height + viewport.y)

        target = rd.ResourceId.Null()

        if len(pipe.GetOutputTargets()) > 0:
            target = pipe.GetOutputTargets()[0].resourceId

        if target == rd.ResourceId.Null():
            target = pipe.GetDepthTarget().resourceId

        if target == rd.ResourceId.Null():
            rdtest.log.print(
                "No targets bound! Can't fetch history at {}".format(
                    draw.eventId))
            return

        rdtest.log.print("Fetching history for %d,%d on target %s" %
                         (x, y, str(target)))

        history = self.controller.PixelHistory(target, x, y, 0, 0, 0,
                                               rd.CompType.Typeless)

        rdtest.log.success("Pixel %d,%d has %d history events" %
                           (x, y, len(history)))

        lastmod: rd.PixelModification = None

        for i in range(len(history) - 1, 0, -1):
            mod = history[i]
            draw = self.find_draw('', mod.eventId)

            rdtest.log.print("  hit %d at %d is %s (%s)" %
                             (i, mod.eventId, draw.name, str(draw.flags)))

            if draw is None or not (draw.flags & rd.DrawFlags.Drawcall):
                continue

            lastmod = history[i]

            rdtest.log.print("Got a hit on a drawcall at event %d" %
                             lastmod.eventId)

            if mod.sampleMasked or mod.backfaceCulled or mod.depthClipped or mod.viewClipped or mod.scissorClipped or mod.depthTestFailed or mod.stencilTestFailed:
                rdtest.log.print(
                    "This hit failed, looking for one that passed....")
                lastmod = None
                continue

            break

        if lastmod is not None:
            rdtest.log.print("Debugging pixel {},{} @ {}, primitve {}".format(
                x, y, lastmod.eventId, lastmod.primitiveID))
            self.controller.SetFrameEvent(lastmod.eventId, True)

            trace = self.controller.DebugPixel(x, y, 0, lastmod.primitiveID)

            if draw.outputs[0] == rd.ResourceId.Null():
                rdtest.log.success(
                    'Successfully debugged pixel in {} cycles, skipping result check due to no output'
                    .format(len(trace.states)))
            elif draw.numInstances == 1:
                lastState: rd.ShaderDebugState = trace.states[-1]

                debugged: rd.ShaderVariable = lastState.outputs[0]

                debuggedValue = [
                    debugged.value.f.x, debugged.value.f.y, debugged.value.f.z,
                    debugged.value.f.w
                ]

                if not rdtest.value_compare(lastmod.shaderOut.col.floatValue, [
                        debugged.value.f.x, debugged.value.f.y,
                        debugged.value.f.z, debugged.value.f.w
                ]):
                    raise rdtest.TestFailureException(
                        "Debugged value {} doesn't match picked value {}".
                        format(debuggedValue,
                               lastmod.shaderOut.col.floatValue))

                rdtest.log.success(
                    'Successfully debugged pixel in {} cycles, result matches'.
                    format(len(trace.states)))
            else:
                rdtest.log.success(
                    'Successfully debugged pixel in {} cycles, skipping result check due to instancing'
                    .format(len(trace.states)))

            self.controller.SetFrameEvent(draw.eventId, True)
Ejemplo n.º 17
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture)

        self.check(out is not None)

        ref = {
            0: {
                'SNorm': [1.0, -1.0, 1.0, -1.0],
                'UNorm': [12345.0/65535.0, 6789.0/65535.0, 1234.0/65535.0, 567.0/65535.0],
                'UScaled': [12345.0, 6789.0, 1234.0, 567.0],
                'UInt': [12345, 6789, 1234, 567],
                'Double': [9.8765432109, -5.6789012345],
                'Array[0]': [1.0, 2.0],
                'Array[1]': [3.0, 4.0],
                'Array[2]': [5.0, 6.0],
                'Matrix:row0': [7.0, 8.0],
                'Matrix:row1': [9.0, 10.0],
            },
            1: {
                'SNorm': [32766.0/32767.0, -32766.0/32767.0, 16000.0/32767.0, -16000.0/32767.0],
                'UNorm': [56.0/65535.0, 7890.0/65535.0, 123.0/65535.0, 4567.0/65535.0],
                'UScaled': [56.0, 7890.0, 123.0, 4567.0],
                'UInt': [56, 7890, 123, 4567],
                'Double': [-7.89012345678, 6.54321098765],
                'Array[0]': [11.0, 12.0],
                'Array[1]': [13.0, 14.0],
                'Array[2]': [15.0, 16.0],
                'Matrix:row0': [17.0, 18.0],
                'Matrix:row1': [19.0, 20.0],
            },
            2: {
                'SNorm': [5.0/32767.0, -5.0/32767.0, 0.0, 0.0],
                'UNorm': [8765.0/65535.0, 43210.0/65535.0, 987.0/65535.0, 65432.0/65535.0],
                'UScaled': [8765.0, 43210.0, 987.0, 65432.0],
                'UInt': [8765, 43210, 987, 65432],
                'Double': [0.1234567890123, 4.5678901234],
                'Array[0]': [21.0, 22.0],
                'Array[1]': [23.0, 24.0],
                'Array[2]': [25.0, 26.0],
                'Matrix:row0': [27.0, 28.0],
                'Matrix:row1': [29.0, 30.0],
            },
        }

        # Copy the ref values and prepend 'In'
        in_ref = {}
        for idx in ref:
            in_ref[idx] = {}
            for key in ref[idx]:
                in_ref[idx]['In' + key] = ref[idx][key]

        # Copy the ref values and prepend 'Out'
        out_ref = {}
        for idx in ref:
            out_ref[idx] = {}
            for key in ref[idx]:
                out_ref[idx]['Out' + key] = ref[idx][key]

        vsout_ref = copy.deepcopy(out_ref)
        gsout_ref = out_ref

        vsout_ref[0]['gl_PerVertex.gl_Position'] = [-0.5, 0.5, 0.0, 1.0]
        gsout_ref[0]['gl_PerVertex.gl_Position'] = [0.5, -0.5, 0.4, 1.2]

        vsout_ref[1]['gl_PerVertex.gl_Position'] = [0.0, -0.5, 0.0, 1.0]
        gsout_ref[1]['gl_PerVertex.gl_Position'] = [-0.5, 0.0, 0.4, 1.2]

        vsout_ref[2]['gl_PerVertex.gl_Position'] = [0.5, 0.5, 0.0, 1.0]
        gsout_ref[2]['gl_PerVertex.gl_Position'] = [0.5, 0.5, 0.4, 1.2]

        self.check_mesh_data(in_ref, self.get_vsin(draw))
        rdtest.log.success("Vertex input data is as expected")

        self.check_mesh_data(vsout_ref, self.get_postvs(rd.MeshDataStage.VSOut))

        rdtest.log.success("Vertex output data is as expected")

        # This is optional to account for drivers without XFB
        postgs_data = self.get_postvs(rd.MeshDataStage.GSOut)
        if len(postgs_data) > 0:
            self.check_mesh_data(gsout_ref, postgs_data)

            rdtest.log.success("Geometry output data is as expected")
        else:
            rdtest.log.print("Geometry output not tested")

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

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0)

        if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]):
            raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue))

        rdtest.log.success("Triangle picked value is as expected")

        out.Shutdown()
Ejemplo n.º 18
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

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

        stage = rd.ShaderStage.Pixel

        # Verify that the GLSL draw is first
        disasm = self.controller.DisassembleShader(
            pipe.GetGraphicsPipelineObject(), pipe.GetShaderReflection(stage),
            '')

        self.check('GLSL' in disasm)

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetShader(stage), pipe.GetShaderEntryPoint(stage), 0,
                cbuf.resourceId, cbuf.byteOffset))

        # For more detailed reference for the below checks, see the commented definition of the cbuffer
        # in the shader source code in the demo itself

        # vec4 a;
        var_check.check('a').cols(4).rows(1).value([0.0, 1.0, 2.0, 3.0])

        # vec3 b;
        var_check.check('b').cols(3).rows(1).value([4.0, 5.0, 6.0])

        # vec2 c; vec2 d;
        var_check.check('c').cols(2).rows(1).value([8.0, 9.0])
        var_check.check('d').cols(2).rows(1).value([10.0, 11.0])

        # float e; vec3 f;
        var_check.check('e').cols(1).rows(1).value([12.0])
        var_check.check('f').cols(3).rows(1).value([16.0, 17.0, 18.0])

        # vec4 dummy0;
        var_check.check('dummy0')

        # float j; vec2 k;
        var_check.check('j').cols(1).rows(1).value([24.0])
        var_check.check('k').cols(2).rows(1).value([26.0, 27.0])

        # vec2 l; float m;
        var_check.check('l').cols(2).rows(1).value([28.0, 29.0])
        var_check.check('m').cols(1).rows(1).value([30.0])

        # float n[4];
        var_check.check('n').cols(0).rows(0).arraySize(4).members({
            0:
            lambda x: x.cols(1).rows(1).value([32.0]),
            1:
            lambda x: x.cols(1).rows(1).value([36.0]),
            2:
            lambda x: x.cols(1).rows(1).value([40.0]),
            3:
            lambda x: x.cols(1).rows(1).value([44.0]),
        })

        # vec4 dummy1;
        var_check.check('dummy1')

        # float o[4];
        var_check.check('o').cols(0).rows(0).arraySize(4).members({
            0:
            lambda x: x.cols(1).rows(1).value([52.0]),
            1:
            lambda x: x.cols(1).rows(1).value([56.0]),
            2:
            lambda x: x.cols(1).rows(1).value([60.0]),
            3:
            lambda x: x.cols(1).rows(1).value([64.0]),
        })

        # float p;
        var_check.check('p').cols(1).rows(1).value([68.0])

        # vec4 dummy2;
        var_check.check('dummy2')

        # column_major vec4x4 q;
        var_check.check('q').cols(4).rows(4).column_major().value([
            76.0, 80.0, 84.0, 88.0, 77.0, 81.0, 85.0, 89.0, 78.0, 82.0, 86.0,
            90.0, 79.0, 83.0, 87.0, 91.0
        ])

        # row_major vec4x4 r;
        var_check.check('r').cols(4).rows(4).row_major().value([
            92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 100.0, 101.0,
            102.0, 103.0
        ])

        # column_major vec4x3 s;
        var_check.check('s').cols(4).rows(3).column_major().value([
            108.0, 112.0, 116.0, 120.0, 109.0, 113.0, 117.0, 121.0, 110.0,
            114.0, 118.0, 122.0
        ])

        # vec4 dummy3;
        var_check.check('dummy3')

        # row_major vec4x3 t;
        var_check.check('t').cols(4).rows(3).row_major().value([
            128.0, 129.0, 130.0, 131.0, 132.0, 133.0, 134.0, 135.0, 136.0,
            137.0, 138.0, 139.0
        ])

        # vec4 dummy4;
        var_check.check('dummy4')

        # column_major vec2x3 u;
        var_check.check('u').cols(3).rows(2).column_major().value(
            [144.0, 148.0, 152.0, 145.0, 149.0, 153.0])

        # vec4 dummy5;
        var_check.check('dummy5')

        # row_major vec3x2 v;
        var_check.check('v').cols(3).rows(2).row_major().value(
            [160.0, 161.0, 162.0, 164.0, 165.0, 166.0])

        # vec4 dummy6;
        var_check.check('dummy6')

        # column_major vec3x2 w;
        var_check.check('w').cols(2).rows(2).column_major().value(
            [172.0, 176.0, 173.0, 177.0])

        # vec4 dummy7;
        var_check.check('dummy7')

        # row_major vec3x2 x;
        var_check.check('x').cols(2).rows(2).row_major().value(
            [184.0, 185.0, 188.0, 189.0])

        # vec4 dummy8;
        var_check.check('dummy8')

        # row_major vec2x2 y;
        var_check.check('y').cols(2).rows(2).row_major().value(
            [196.0, 197.0, 200.0, 201.0])

        # float z;
        var_check.check('z').cols(1).rows(1).value([204.0])

        # vec4 dummy9;
        var_check.check('dummy9')

        # vec4 multiarray[3][2];
        var_check.check('multiarray').cols(0).rows(0).arraySize(3).members({
            0:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([228.0, 229.0, 230.0, 231.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([232.0, 233.0, 234.0, 235.0]
                                                  ),
            }),
            1:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([236.0, 237.0, 238.0, 239.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([240.0, 241.0, 242.0, 243.0]
                                                  ),
            }),
            2:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([244.0, 245.0, 246.0, 247.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([248.0, 249.0, 250.0, 251.0]
                                                  ),
            }),
        })

        # struct vec3_1 { vec3 a; float b; };
        # struct nested { vec3_1 a; vec4 b[4]; vec3_1 c[4]; };
        # nested structa[2];
        var_check.check('structa').cols(0).rows(0).arraySize(2).members({
            # structa[0]
            0:
            lambda s: s.cols(0).rows(0).structSize(3).members({
                'a':
                lambda x: x.cols(0).rows(0).structSize(2).members({
                    'a':
                    lambda y: y.cols(3).rows(1).value([252.0, 253.0, 254.0]),
                    'b':
                    lambda y: y.cols(1).rows(1).value([255.0]),
                }),
                'b':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda y: y.cols(4).rows(1).value(
                        [256.0, 257.0, 258.0, 259.0]),
                    1:
                    lambda y: y.cols(4).rows(1).value(
                        [260.0, 261.0, 262.0, 263.0]),
                    2:
                    lambda y: y.cols(4).rows(1).value(
                        [264.0, 265.0, 266.0, 267.0]),
                    3:
                    lambda y: y.cols(4).rows(1).value(
                        [268.0, 269.0, 270.0, 271.0]),
                }),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [272.0, 273.0, 274.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([275.0]),
                    }),
                    1:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [276.0, 277.0, 278.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([279.0]),
                    }),
                    2:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [280.0, 281.0, 282.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([283.0]),
                    }),
                    3:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [284.0, 285.0, 286.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([287.0]),
                    }),
                }),
            }),
            # structa[1]
            1:
            lambda s: s.cols(0).rows(0).structSize(3).members({
                'a':
                lambda x: x.cols(0).rows(0).structSize(2).members({
                    'a':
                    lambda y: y.cols(3).rows(1).value([288.0, 289.0, 290.0]),
                    'b':
                    lambda y: y.cols(1).rows(1).value([291.0]),
                }),
                'b':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda y: y.cols(4).rows(1).value(
                        [292.0, 293.0, 294.0, 295.0]),
                    1:
                    lambda y: y.cols(4).rows(1).value(
                        [296.0, 297.0, 298.0, 299.0]),
                    2:
                    lambda y: y.cols(4).rows(1).value(
                        [300.0, 301.0, 302.0, 303.0]),
                    3:
                    lambda y: y.cols(4).rows(1).value(
                        [304.0, 305.0, 306.0, 307.0]),
                }),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [308.0, 309.0, 310.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([311.0]),
                    }),
                    1:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [312.0, 313.0, 314.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([315.0]),
                    }),
                    2:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [316.0, 317.0, 318.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([319.0]),
                    }),
                    3:
                    lambda y: y.cols(0).rows(0).structSize(2).members({
                        'a':
                        lambda z: z.cols(3).rows(1).value(
                            [320.0, 321.0, 322.0]),
                        'b':
                        lambda z: z.cols(1).rows(1).value([323.0]),
                    }),
                }),
            }),
        })

        # column_major mat2x3 ac;
        var_check.check('ac').cols(2).rows(3).column_major().value(
            [324.0, 328.0, 325.0, 329.0, 326.0, 330.0])

        # row_major mat2x3 ad;
        var_check.check('ad').cols(2).rows(3).row_major().value(
            [332.0, 333.0, 336.0, 337.0, 340.0, 341.0])

        # column_major mat2x3 ae[2];
        var_check.check('ae').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(2).rows(3).column_major().value(
                [344.0, 348.0, 345.0, 349.0, 346.0, 350.0]),
            1:
            lambda x: x.cols(2).rows(3).column_major().value(
                [352.0, 356.0, 353.0, 357.0, 354.0, 358.0]),
        })

        # row_major mat2x3 af[2];
        var_check.check('af').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(2).rows(3).row_major().value(
                [360.0, 361.0, 364.0, 365.0, 368.0, 369.0]),
            1:
            lambda x: x.cols(2).rows(3).row_major().value(
                [372.0, 373.0, 376.0, 377.0, 380.0, 381.0]),
        })

        # vec2 dummy10;
        var_check.check('dummy10')

        # row_major mat2x2 ag;
        var_check.check('ag').cols(2).rows(2).row_major().value(
            [388.0, 389.0, 392.0, 393.0])

        # vec2 dummy11;
        var_check.check('dummy11')

        # column_major mat2x2 ah;
        var_check.check('ah').cols(2).rows(2).column_major().value(
            [400.0, 404.0, 401.0, 405.0])

        # row_major mat2x2 ai[2];
        var_check.check('ai').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.cols(2).rows(2).row_major().value(
                [408.0, 409.0, 412.0, 413.0]),
            1:
            lambda x: x.cols(2).rows(2).row_major().value(
                [416.0, 417.0, 420.0, 421.0]),
        })

        # column_major mat2x2 aj[2];
        var_check.check('aj').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.cols(2).rows(2).column_major().value(
                [424.0, 428.0, 425.0, 429.0]),
            1:
            lambda x: x.cols(2).rows(2).column_major().value(
                [432.0, 436.0, 433.0, 437.0]),
        })

        # vec4 test;
        var_check.check('test').rows(1).cols(4).value(
            [440.0, 441.0, 442.0, 443.0])

        var_check.done()

        rdtest.log.success("GLSL CBuffer variables are as expected")

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2),
                                              int(texdetails.height / 2), 0, 0,
                                              0)

        if not rdtest.value_compare(picked.floatValue,
                                    [440.1, 441.0, 442.0, 443.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("GLSL picked value is as expected")

        # Check the specialization constants
        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 1, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetShader(stage), pipe.GetShaderEntryPoint(stage), 1,
                cbuf.resourceId, cbuf.byteOffset))

        # int A;
        # Default value 10, untouched
        var_check.check('A').type(rd.VarType.SInt).rows(1).cols(1).value([10])

        # float B;
        # Value 20 from spec constants
        var_check.check('B').type(rd.VarType.Float).rows(1).cols(1).value(
            [20.0])

        # bool C;
        # Value True from spec constants
        var_check.check('C').type(rd.VarType.UInt).rows(1).cols(1).value([1])

        var_check.done()

        rdtest.log.success("Specialization constants are as expected")

        # Move to the HLSL draw
        draw = draw.next

        self.check(draw is not None)

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

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

        # Verify that this is the HLSL draw
        disasm = self.controller.DisassembleShader(
            pipe.GetGraphicsPipelineObject(), pipe.GetShaderReflection(stage),
            '')

        self.check('HLSL' in disasm)

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetShader(stage), pipe.GetShaderEntryPoint(stage), 0,
                cbuf.resourceId, cbuf.byteOffset))

        # For more detailed reference for the below checks, see the commented definition of the cbuffer
        # in the shader source code in the demo itself

        # float4 a;
        var_check.check('a').rows(1).cols(4).value([0.0, 1.0, 2.0, 3.0])

        # float3 b;
        var_check.check('b').rows(1).cols(3).value([4.0, 5.0, 6.0])

        # float2 c; float2 d;
        var_check.check('c').rows(1).cols(2).value([8.0, 9.0])
        var_check.check('d').rows(1).cols(2).value([10.0, 11.0])

        # float e; float3 f;
        var_check.check('e').rows(1).cols(1).value([12.0])
        var_check.check('f').rows(1).cols(3).value([13.0, 14.0, 15.0])

        # float g; float2 h; float i;
        var_check.check('g').rows(1).cols(1).value([16.0])
        var_check.check('h').rows(1).cols(2).value([17.0, 18.0])
        var_check.check('i').rows(1).cols(1).value([19.0])

        # float j; float2 k;
        var_check.check('j').rows(1).cols(1).value([20.0])
        var_check.check('k').rows(1).cols(2).value([21.0, 22.0])

        # float2 l; float m;
        var_check.check('l').rows(1).cols(2).value([24.0, 25.0])
        var_check.check('m').rows(1).cols(1).value([26.0])

        # float n[4];
        var_check.check('n').rows(0).cols(0).arraySize(4).members({
            0:
            lambda x: x.rows(1).cols(1).value([28.0]),
            1:
            lambda x: x.rows(1).cols(1).value([32.0]),
            2:
            lambda x: x.rows(1).cols(1).value([36.0]),
            3:
            lambda x: x.rows(1).cols(1).value([40.0]),
        })

        # float4 dummy1;
        var_check.check('dummy1')

        # float o[4];
        var_check.check('o').rows(0).cols(0).arraySize(4).members({
            0:
            lambda x: x.rows(1).cols(1).value([48.0]),
            1:
            lambda x: x.rows(1).cols(1).value([52.0]),
            2:
            lambda x: x.rows(1).cols(1).value([56.0]),
            3:
            lambda x: x.rows(1).cols(1).value([60.0]),
        })

        # float p; with std140 vulkan packing
        var_check.check('p').rows(1).cols(1).value([64.0])

        # float4 dummy2;
        var_check.check('dummy2')

        # float4 gldummy;
        var_check.check('gldummy')

        # HLSL majorness is flipped to match column-major SPIR-V with row-major HLSL.
        # This means column major declared matrices will show up as row major in any reflection and SPIR-V
        # it also means that dimensions are flipped, so a float3x4 is declared as a float4x3, and a 'row'
        # is really a column, and vice-versa a 'column' is really a row.

        # column_major float4x4 q;
        var_check.check('q').rows(4).cols(4).row_major().value([
            76.0, 77.0, 78.0, 79.0, 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0,
            87.0, 88.0, 89.0, 90.0, 91.0
        ])

        # row_major float4x4 r;
        var_check.check('r').rows(4).cols(4).column_major().value([
            92.0, 96.0, 100.0, 104.0, 93.0, 97.0, 101.0, 105.0, 94.0, 98.0,
            102.0, 106.0, 95.0, 99.0, 103.0, 107.0
        ])

        # column_major float3x4 s;
        var_check.check('s').rows(4).cols(3).row_major().value([
            108.0, 109.0, 110.0, 112.0, 113.0, 114.0, 116.0, 117.0, 118.0,
            120.0, 121.0, 122.0
        ])

        # float4 dummy3;
        var_check.check('dummy3')

        # row_major float3x4 t;
        var_check.check('t').rows(4).cols(3).column_major().value([
            128.0, 132.0, 136.0, 129.0, 133.0, 137.0, 130.0, 134.0, 138.0,
            131.0, 135.0, 139.0
        ])

        # float4 dummy4;
        var_check.check('dummy4')

        # column_major float2x3 u;
        var_check.check('u').rows(3).cols(2).row_major().value(
            [144.0, 145.0, 148.0, 149.0, 152.0, 153.0])

        # float4 dummy5;
        var_check.check('dummy5')

        # row_major float2x3 v;
        var_check.check('v').rows(3).cols(2).column_major().value(
            [160.0, 164.0, 161.0, 165.0, 162.0, 166.0])

        # float4 dummy6;
        var_check.check('dummy6')

        # column_major float2x2 w;
        var_check.check('w').rows(2).cols(2).row_major().value(
            [172.0, 173.0, 176.0, 177.0])

        # float4 dummy7;
        var_check.check('dummy7')

        # row_major float2x2 x;
        var_check.check('x').rows(2).cols(2).column_major().value(
            [184.0, 188.0, 185.0, 189.0])

        # float4 dummy8;
        var_check.check('dummy8')

        # row_major float2x2 y;
        var_check.check('y').rows(2).cols(2).column_major().value(
            [196.0, 200.0, 197.0, 201.0])

        # float z;
        var_check.check('z').rows(1).cols(1).value([204.0])

        # Temporarily until SPIR-V support for degenerate HLSL matrices is determined
        var_check.check('dummy9')

        # row_major float4x1 aa;
        #var_check.check('aa').rows(1).cols(4).value([208.0, 212.0, 216.0, 220.0])

        # column_major float4x1 ab;
        #var_check.check('ab').rows(1).cols(4).value([224.0, 225.0, 226.0, 227.0])

        # float4 multiarray[3][2];
        var_check.check('multiarray').cols(0).rows(0).arraySize(3).members({
            0:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([228.0, 229.0, 230.0, 231.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([232.0, 233.0, 234.0, 235.0]
                                                  ),
            }),
            1:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([236.0, 237.0, 238.0, 239.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([240.0, 241.0, 242.0, 243.0]
                                                  ),
            }),
            2:
            lambda x: x.cols(0).rows(0).arraySize(2).members({
                0:
                lambda y: y.cols(4).rows(1).value([244.0, 245.0, 246.0, 247.0]
                                                  ),
                1:
                lambda y: y.cols(4).rows(1).value([248.0, 249.0, 250.0, 251.0]
                                                  ),
            }),
        })

        # struct float3_1 { float3 a; float b; };
        # struct nested { float3_1 a; float4 b[4]; float3_1 c[4]; };
        # nested structa[2];
        var_check.check('structa').rows(0).cols(0).arraySize(2).members({
            # structa[0]
            0:
            lambda s: s.rows(0).cols(0).structSize(3).members({
                'a':
                lambda x: x.rows(0).cols(0).structSize(2).members({
                    'a':
                    lambda y: y.rows(1).cols(3).value([252.0, 253.0, 254.0]),
                    'b':
                    lambda y: y.rows(1).cols(1).value([255.0]),
                }),
                'b':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(1).cols(4).value(
                        [256.0, 257.0, 258.0, 259.0]),
                    1:
                    lambda y: y.rows(1).cols(4).value(
                        [260.0, 261.0, 262.0, 263.0]),
                    2:
                    lambda y: y.rows(1).cols(4).value(
                        [264.0, 265.0, 266.0, 267.0]),
                    3:
                    lambda y: y.rows(1).cols(4).value(
                        [268.0, 269.0, 270.0, 271.0]),
                }),
                'c':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [272.0, 273.0, 274.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([275.0]),
                    }),
                    1:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [276.0, 277.0, 278.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([279.0]),
                    }),
                    2:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [280.0, 281.0, 282.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([283.0]),
                    }),
                    3:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [284.0, 285.0, 286.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([287.0]),
                    }),
                }),
            }),
            # structa[1]
            1:
            lambda s: s.rows(0).cols(0).structSize(3).members({
                'a':
                lambda x: x.rows(0).cols(0).structSize(2).members({
                    'a':
                    lambda y: y.rows(1).cols(3).value([288.0, 289.0, 290.0]),
                    'b':
                    lambda y: y.rows(1).cols(1).value([291.0]),
                }),
                'b':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(1).cols(4).value(
                        [292.0, 293.0, 294.0, 295.0]),
                    1:
                    lambda y: y.rows(1).cols(4).value(
                        [296.0, 297.0, 298.0, 299.0]),
                    2:
                    lambda y: y.rows(1).cols(4).value(
                        [300.0, 301.0, 302.0, 303.0]),
                    3:
                    lambda y: y.rows(1).cols(4).value(
                        [304.0, 305.0, 306.0, 307.0]),
                }),
                'c':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [308.0, 309.0, 310.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([311.0]),
                    }),
                    1:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [312.0, 313.0, 314.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([315.0]),
                    }),
                    2:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [316.0, 317.0, 318.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([319.0]),
                    }),
                    3:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [320.0, 321.0, 322.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([323.0]),
                    }),
                }),
            }),
        })

        # column_major float3x2 ac;
        var_check.check('ac').rows(2).cols(3).row_major().value(
            [324.0, 325.0, 326.0, 328.0, 329.0, 330.0])

        # row_major float3x2 ad;
        var_check.check('ad').rows(2).cols(3).column_major().value(
            [332.0, 336.0, 340.0, 333.0, 337.0, 341.0])

        # column_major float3x2 ae[2];
        var_check.check('ae').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(3).row_major().value(
                [344.0, 345.0, 346.0, 348.0, 349.0, 350.0]),
            1:
            lambda x: x.rows(2).cols(3).row_major().value(
                [352.0, 353.0, 354.0, 356.0, 357.0, 358.0]),
        })

        # row_major float3x2 af[2];
        var_check.check('af').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(3).column_major().value(
                [360.0, 364.0, 368.0, 361.0, 365.0, 369.0]),
            1:
            lambda x: x.rows(2).cols(3).column_major().value(
                [372.0, 376.0, 380.0, 373.0, 377.0, 381.0]),
        })

        # float2 dummy10;
        var_check.check('dummy10')

        # float2 dummy11;
        var_check.check('dummy11')

        # row_major float2x2 ag;
        var_check.check('ag').rows(2).cols(2).column_major().value(
            [388.0, 392.0, 389.0, 393.0])

        # float2 dummy12;
        var_check.check('dummy12')

        # float2 dummy13;
        var_check.check('dummy13')

        # column_major float2x2 ah;
        var_check.check('ah').rows(2).cols(2).row_major().value(
            [400.0, 401.0, 404.0, 405.0])

        # row_major float2x2 ai[2];
        var_check.check('ai').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(2).column_major().value(
                [408.0, 412.0, 409.0, 413.0]),
            1:
            lambda x: x.rows(2).cols(2).column_major().value(
                [416.0, 420.0, 417.0, 421.0]),
        })

        # column_major float2x2 aj[2];
        var_check.check('aj').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(2).row_major().value(
                [424.0, 425.0, 428.0, 429.0]),
            1:
            lambda x: x.rows(2).cols(2).row_major().value(
                [432.0, 433.0, 436.0, 437.0]),
        })

        # float4 test;
        var_check.check('test').rows(1).cols(4).value(
            [440.0, 441.0, 442.0, 443.0])

        var_check.done()

        rdtest.log.success("HLSL CBuffer variables are as expected")

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2),
                                              int(texdetails.height / 2), 0, 0,
                                              0)

        if not rdtest.value_compare(picked.floatValue,
                                    [440.1, 441.0, 442.0, 443.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("HLSL picked value is as expected")

        out.Shutdown()
Ejemplo n.º 19
0
    def check_capture(self):
        # find the first draw
        draw = self.find_draw("Draw")

        # We should have 4 draws, with spec constant values 0, 1, 2, 3
        for num_colors in range(4):
            self.check(draw is not None)

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

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

            shader: rd.ShaderReflection = pipe.GetShaderReflection(rd.ShaderStage.Pixel)

            # uniform buffer and spec constants
            self.check(len(shader.constantBlocks) == 2)
            self.check(shader.constantBlocks[0].bufferBacked)
            self.check(not shader.constantBlocks[1].bufferBacked)
            self.check(len(shader.constantBlocks[1].variables) == 1)

            # should be an array of num_colors+1 elements
            array_len = shader.constantBlocks[0].variables[0].type.descriptor.elements
            if not rdtest.value_compare(array_len, num_colors+1):
                raise rdtest.TestFailureException("CBuffer variable is array of {}, not {}".format(array_len, num_colors+1))

            if num_colors > 0:
                cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(rd.ShaderStage.Pixel, 0, 0)

                cb_vars = self.controller.GetCBufferVariableContents(pipe.GetGraphicsPipelineObject(),
                                                                     pipe.GetShader(rd.ShaderStage.Pixel),
                                                                     pipe.GetShaderEntryPoint(rd.ShaderStage.Pixel), 0,
                                                                     cbuf.resourceId, cbuf.byteOffset)

                self.check(len(cb_vars) == 1)

                if not rdtest.value_compare(len(cb_vars[0].members), num_colors+1):
                    raise rdtest.TestFailureException("CBuffer variable is array of {}, not {}".format(len(cb_vars[0].members), num_colors+1))

                for col in range(num_colors):
                    expected = [0.0, 0.0, 0.0, 0.0]
                    expected[col] = 1.0

                    val = [i for i in cb_vars[0].members[col].value.fv[0:4]]

                    if not rdtest.value_compare(val, expected):
                        raise rdtest.TestFailureException("Cbuffer[{}] value {} doesn't match expectation {}".format(col, val, expected))

                rdtest.log.success("Draw with {} colors uniform buffer is as expected".format(num_colors))

            cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(rd.ShaderStage.Pixel, 1, 0)

            cb_vars = self.controller.GetCBufferVariableContents(pipe.GetGraphicsPipelineObject(),
                                                                 pipe.GetShader(rd.ShaderStage.Pixel),
                                                                 pipe.GetShaderEntryPoint(rd.ShaderStage.Pixel), 1,
                                                                 cbuf.resourceId, cbuf.byteOffset)

            self.check(len(cb_vars) == 1)

            if not rdtest.value_compare(cb_vars[0].value.i.x, num_colors):
                raise rdtest.TestFailureException("Spec constant is {}, not {}".format(cb_vars[0].value.i.x, num_colors))

            rdtest.log.success("Draw with {} colors specialisation constant is as expected".format(num_colors))

            view = pipe.GetViewport(0)

            # the first num_colors components should be 0.6, the rest should be 0.1 (alpha is always 1.0)
            expected = [0.0, 0.0, 0.0, 1.0]
            for col in range(num_colors):
                expected[col] += 1.0

            # Sample the centre of the viewport
            self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, int(view.x) + int(view.width / 2), int(view.height / 2), expected)

            rdtest.log.success("Draw with {} colors picked value is as expected".format(num_colors))

            draw = draw.next
Ejemplo n.º 20
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

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

        stage = rd.ShaderStage.Vertex

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetShader(stage), pipe.GetShaderEntryPoint(stage), 0,
                cbuf.resourceId, cbuf.byteOffset))

        # For more detailed reference for the below checks, see the commented definition of the cbuffer
        # in the shader source code in the demo itself

        # float a;
        var_check.check('a').cols(1).rows(1).type(rd.VarType.Float).value(
            [1.0])

        # vec2 b;
        var_check.check('b').cols(2).rows(1).type(rd.VarType.Float).value(
            [2.0, 0.0])

        # vec3 c;
        var_check.check('c').cols(3).rows(1).type(rd.VarType.Float).value(
            [0.0, 3.0])

        # float d[2];
        var_check.check('d').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([4.0]),
            1:
            lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([5.0]),
        })

        # mat2x3 e;
        var_check.check('e').cols(2).rows(3).column_major().type(
            rd.VarType.Float).value([6.0, 999.0, 7.0, 0.0, 0.0, 0.0])

        # mat2x3 f[2];
        var_check.check('f').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(2).rows(3).column_major().type(
                rd.VarType.Float).value([8.0, 999.0, 9.0, 0.0, 0.0, 0.0]),
            1:
            lambda x: x.cols(2).rows(3).column_major().type(rd.VarType.Float).
            value([10.0, 999.0, 11.0, 0.0, 0.0, 0.0]),
        })

        # float g;
        var_check.check('g').cols(1).rows(1).type(rd.VarType.Float).value(
            [12.0])

        # struct S
        # {
        #   float a;
        #   vec2 b;
        #   double c;
        #   float d;
        #   vec3 e;
        #   float f;
        # };
        # S h;

        var_check.check('h').cols(0).rows(0).structSize(6).members({
            'a':
            lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]),
            'b':
            lambda x: x.cols(2).rows(1).type(rd.VarType.Float).value([0.0]),
            'c':
            lambda x: x.cols(1).rows(1).type(rd.VarType.Double).longvalue(
                [13.0]),
            'd':
            lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([14.0]),
            'e':
            lambda x: x.cols(3).rows(1).type(rd.VarType.Float).value([0.0]),
            'f':
            lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]),
        })

        # S i[2];
        var_check.check('i').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(0).rows(0).structSize(6).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'b':
                lambda x: x.cols(2).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'c':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Double).longvalue(
                    [15.0]),
                'd':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'e':
                lambda x: x.cols(3).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'f':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
            }),
            1:
            lambda x: x.cols(0).rows(0).structSize(6).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'b':
                lambda x: x.cols(2).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'c':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Double).longvalue(
                    [0.0]),
                'd':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value(
                    [16.0]),
                'e':
                lambda x: x.cols(3).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
                'f':
                lambda x: x.cols(1).rows(1).type(rd.VarType.Float).value([0.0]
                                                                         ),
            }),
        })

        # i8vec4 pad1;
        var_check.check('pad1')

        # int8_t j;
        var_check.check('j').cols(1).rows(1).type(rd.VarType.SByte).value([17])

        # struct S8
        # {
        #   int8_t a;
        #   i8vec4 b;
        #   i8vec2 c[4];
        # };
        # S8 k;
        var_check.check('k').cols(0).rows(0).structSize(3).members({
            'a':
            lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([0]),
            'b':
            lambda x: x.cols(4).rows(1).type(rd.VarType.SByte).value(
                [0, 0, 0, 0]),
            'c':
            lambda x: x.cols(0).rows(0).arraySize(4).members({
                0:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                    [0, 0]),
                1:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                    [0, 18]),
                2:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                    [0, 0]),
                3:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                    [0, 0]),
            }),
        })

        # S8 l[2];
        var_check.check('l').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(0).rows(0).structSize(3).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([19]),
                'b':
                lambda x: x.cols(4).rows(1).type(rd.VarType.SByte).value(
                    [0, 0, 0, 0]),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                    1:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 20]),
                    2:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                    3:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                }),
            }),
            1:
            lambda x: x.cols(0).rows(0).structSize(3).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([21]),
                'b':
                lambda x: x.cols(4).rows(1).type(rd.VarType.SByte).value(
                    [0, 0, 0, 0]),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 22]),
                    1:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                    2:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                    3:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SByte).value(
                        [0, 0]),
                }),
            })
        })

        # int8_t m;
        var_check.check('m').cols(1).rows(1).type(rd.VarType.SByte).value(
            [-23])

        # struct S16
        # {
        #   uint16_t a;
        #   i16vec4 b;
        #   i16vec2 c[4];
        #   int8_t d;
        # };
        # S16 n;
        var_check.check('n').cols(0).rows(0).structSize(4).members({
            'a':
            lambda x: x.cols(1).rows(1).type(rd.VarType.UShort).value([65524]),
            'b':
            lambda x: x.cols(4).rows(1).type(rd.VarType.SShort).value(
                [0, 0, 0, -2424]),
            'c':
            lambda x: x.cols(0).rows(0).arraySize(4).members({
                0:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                    [0, 0]),
                1:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                    [0, 0]),
                2:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                    [0, 0]),
                3:
                lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                    [0, 0]),
            }),
            'd':
            lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([25]),
        })

        # i8vec4 pad2;
        var_check.check('pad2')

        # uint8_t o;
        var_check.check('o').cols(1).rows(1).type(rd.VarType.UByte).value(
            [226])

        # S16 p[2];
        var_check.check('p').cols(0).rows(0).arraySize(2).members({
            0:
            lambda x: x.cols(0).rows(0).structSize(4).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.UShort).value([0]),
                'b':
                lambda x: x.cols(4).rows(1).type(rd.VarType.SShort).value(
                    [0, 0, 2727, 0]),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    1:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    2:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    3:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                }),
                'd':
                lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([28]),
            }),
            1:
            lambda x: x.cols(0).rows(0).structSize(4).members({
                'a':
                lambda x: x.cols(1).rows(1).type(rd.VarType.UShort).value([0]),
                'b':
                lambda x: x.cols(4).rows(1).type(rd.VarType.SShort).value(
                    [0, 0, 0, 2929]),
                'c':
                lambda x: x.cols(0).rows(0).arraySize(4).members({
                    0:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    1:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    2:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                    3:
                    lambda x: x.cols(2).rows(1).type(rd.VarType.SShort).value(
                        [0, 0]),
                }),
                'd':
                lambda x: x.cols(1).rows(1).type(rd.VarType.SByte).value([0]),
            })
        })

        # i8vec4 pad3;
        var_check.check('pad3')

        # uint64_t q;
        var_check.check('q').cols(1).rows(1).type(rd.VarType.ULong).longvalue(
            [30303030303030])

        # int64_t r;
        var_check.check('r').cols(1).rows(1).type(rd.VarType.SLong).longvalue(
            [-31313131313131])

        # half s;
        var_check.check('s').cols(1).rows(1).type(rd.VarType.Half).value(
            [16.25])

        # int8_t test;
        var_check.check('test').cols(1).rows(1).type(rd.VarType.SByte).value(
            [42])

        var_check.done()

        rdtest.log.success("CBuffer variables are as expected")

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2),
                                              int(texdetails.height / 2), 0, 0,
                                              0)

        # We just output green from the shader when the value is as expected
        if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 0.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("Picked value is as expected")

        out.Shutdown()
Ejemplo n.º 21
0
    def check_test(self, fmt_name: str, name: str, test_mode: int):
        pipe: rd.PipeState = self.controller.GetPipelineState()

        image_view = (test_mode != Texture_Zoo.TEST_CAPTURE)

        if image_view:
            bound_res: rd.BoundResource = pipe.GetOutputTargets()[0]
        else:
            bound_res: rd.BoundResource = pipe.GetReadOnlyResources(
                rd.ShaderStage.Pixel)[0].resources[0]

        texs = self.controller.GetTextures()
        for t in texs:
            self.textures[t.resourceId] = t

        tex_id: rd.ResourceId = bound_res.resourceId
        tex: rd.TextureDescription = self.textures[tex_id]

        comp_type: rd.CompType = tex.format.compType
        if bound_res.typeCast != rd.CompType.Typeless:
            comp_type = bound_res.typeCast

        # When not running proxied, save non-typecasted textures to disk
        if not image_view and not self.proxied and (
                tex.format.compType == comp_type
                or tex.format.type == rd.ResourceFormatType.D24S8
                or tex.format.type == rd.ResourceFormatType.D32S8):
            save_data = rd.TextureSave()
            save_data.resourceId = tex_id
            save_data.destType = rd.FileType.DDS
            save_data.sample.mapToArray = True

            self.textures[self.filename] = tex

            path = rdtest.get_tmp_path(self.filename + '.dds')

            success: bool = self.controller.SaveTexture(save_data, path)

            if not success:
                try:
                    os.remove(path)
                except Exception:
                    pass

            save_data.destType = rd.FileType.PNG
            save_data.slice.sliceIndex = 0
            save_data.sample.sampleIndex = 0
            path = path.replace('.dds', '.png')

            if comp_type == rd.CompType.UInt:
                save_data.comp.blackPoint = 0.0
                save_data.comp.whitePoint = 255.0
            elif comp_type == rd.CompType.SInt:
                save_data.comp.blackPoint = -255.0
                save_data.comp.whitePoint = 0.0
            elif comp_type == rd.CompType.SNorm:
                save_data.comp.blackPoint = -1.0
                save_data.comp.whitePoint = 0.0

            success: bool = self.controller.SaveTexture(save_data, path)

            if not success:
                try:
                    os.remove(path)
                except Exception:
                    pass

        value0 = []

        comp_count = tex.format.compCount

        # When viewing PNGs only compare the components that the original texture had
        if test_mode == Texture_Zoo.TEST_PNG:
            comp_count = self.textures[self.filename]
            tex.msSamp = 0
            tex.arraysize = 1
            tex.depth = 1
            self.fake_msaa = 'MSAA' in name
        elif test_mode == Texture_Zoo.TEST_DDS:
            tex.arraysize = self.textures[self.filename].arraysize
            tex.msSamp = self.textures[self.filename].msSamp
            self.fake_msaa = 'MSAA' in name

        # HACK: We don't properly support BGRX, so just drop the alpha channel. We can't set this to compCount = 3
        # internally because that's a 24-bit format with no padding...
        if 'B8G8R8X8' in fmt_name:
            comp_count = 3

        # Completely ignore the alpha for BC1, our encoder doesn't pay attention to it
        if tex.format.type == rd.ResourceFormatType.BC1:
            comp_count = 3

        # Calculate format-appropriate epsilon
        eps_significand = 1.0
        # Account for the sRGB curve by more generous epsilon

        if comp_type == rd.CompType.UNormSRGB:
            eps_significand = 2.5
        # Similarly SNorm essentially loses a bit of accuracy due to us only using negative values
        elif comp_type == rd.CompType.SNorm:
            eps_significand = 2.0

        if tex.format.type == rd.ResourceFormatType.R4G4B4A4 or tex.format.type == rd.ResourceFormatType.R4G4:
            eps = (eps_significand / 15.0)
        elif rd.ResourceFormatType.BC1 <= tex.format.type <= rd.ResourceFormatType.BC3:
            eps = (eps_significand / 15.0)  # 4-bit precision in some channels
        elif tex.format.type == rd.ResourceFormatType.R5G5B5A1 or tex.format.type == rd.ResourceFormatType.R5G6B5:
            eps = (eps_significand / 31.0)
        elif tex.format.type == rd.ResourceFormatType.R11G11B10:
            eps = (eps_significand / 31.0)  # 5-bit mantissa in blue
        elif tex.format.type == rd.ResourceFormatType.R9G9B9E5:
            eps = (
                eps_significand / 63.0
            )  # we have 9 bits of data, but might lose 2-3 due to shared exponent
        elif tex.format.type == rd.ResourceFormatType.BC6 and tex.format.compType == rd.CompType.SNorm:
            eps = (eps_significand / 63.0
                   )  # Lose a bit worth of precision for the signed version
        elif rd.ResourceFormatType.BC4 <= tex.format.type <= rd.ResourceFormatType.BC7:
            eps = (eps_significand / 127.0)
        elif tex.format.compByteWidth == 1:
            eps = (eps_significand / 255.0)
        elif comp_type == rd.CompType.Depth and tex.format.compCount == 2:
            eps = (eps_significand / 255.0)  # stencil is only 8-bit
        elif tex.format.type == rd.ResourceFormatType.A8:
            eps = (eps_significand / 255.0)
        elif tex.format.type == rd.ResourceFormatType.R10G10B10A2:
            eps = (eps_significand / 1023.0)
        else:
            # half-floats have 11-bit mantissa. This epsilon is tight enough that we can be sure
            # any remaining errors are implementation inaccuracy and not our bug
            eps = (eps_significand / 2047.0)

        for mp in range(tex.mips):
            for sl in range(max(tex.arraysize, max(1, tex.depth >> mp))):
                z = 0
                if tex.depth > 1:
                    z = sl

                for sm in range(tex.msSamp):
                    for x in range(max(1, tex.width >> mp)):
                        for y in range(max(1, tex.height >> mp)):
                            picked: rd.PixelValue = self.pick(
                                tex_id, x, y, self.sub(mp, sl, sm), comp_type)

                            # each 3D slice cycles the x. This only affects the primary diagonal
                            offs_x = (x + z) % max(1, tex.width >> mp)

                            # The diagonal inverts the colors
                            inverted = (offs_x != y)

                            # second slice adds a coarse checkerboard pattern of inversion
                            if tex.arraysize > 1 and sl == 1 and (
                                (int(x / 2) % 2) != (int(y / 2) % 2)):
                                inverted = not inverted

                            if comp_type == rd.CompType.UInt or comp_type == rd.CompType.SInt:
                                expected = [10, 40, 70, 100]

                                if inverted:
                                    expected = list(reversed(expected))

                                expected = [
                                    c + 10 * (sm + mp) for c in expected
                                ]

                                if comp_type == rd.CompType.SInt:
                                    picked = picked.intValue
                                else:
                                    picked = picked.uintValue
                            elif (tex.format.type
                                  == rd.ResourceFormatType.D16S8
                                  or tex.format.type
                                  == rd.ResourceFormatType.D24S8
                                  or tex.format.type
                                  == rd.ResourceFormatType.D32S8):
                                # depth/stencil is a bit special
                                expected = [0.1, 10, 100, 0.85]

                                if inverted:
                                    expected = list(reversed(expected))

                                expected[0] += 0.075 * (sm + mp)
                                expected[1] += 10 * (sm + mp)

                                # Normalise stencil value
                                expected[1] = expected[1] / 255.0

                                picked = picked.floatValue
                            else:
                                expected = [0.1, 0.35, 0.6, 0.85]

                                if inverted:
                                    expected = list(reversed(expected))

                                expected = [
                                    c + 0.075 * (sm + mp) for c in expected
                                ]

                                picked = picked.floatValue

                            # SNorm/SInt is negative
                            if comp_type == rd.CompType.SNorm or comp_type == rd.CompType.SInt:
                                expected = [-c for c in expected]

                            # BGRA textures have a swizzle applied
                            if tex.format.BGRAOrder():
                                expected[0:3] = reversed(expected[0:3])

                            # alpha channel in 10:10:10:2 has extremely low precision, and the ULP requirements mean
                            # we basically can't trust anything between 0 and 1 on float formats. Just round in that
                            # case as it still lets us differentiate between alpha 0.0-0.5 and 0.5-1.0
                            if tex.format.type == rd.ResourceFormatType.R10G10B10A2:
                                if comp_type == rd.CompType.UInt:
                                    expected[3] = min(3, expected[3])
                                else:
                                    expected[3] = round(expected[3]) * 1.0
                                    picked[3] = round(picked[3]) * 1.0

                            # Handle 1-bit alpha
                            if tex.format.type == rd.ResourceFormatType.R5G5B5A1:
                                expected[
                                    3] = 1.0 if expected[3] >= 0.5 else 0.0
                                picked[3] = 1.0 if picked[3] >= 0.5 else 0.0

                            # A8 picked values come out in alpha, but we want to compare against the single channel
                            if tex.format.type == rd.ResourceFormatType.A8:
                                picked[0] = picked[3]

                            # Clamp to number of components in the texture
                            expected = expected[0:comp_count]
                            picked = picked[0:comp_count]

                            if mp == 0 and sl == 0 and sm == 0 and x == 0 and y == 0:
                                value0 = picked

                            # For SRGB textures picked values will come out as linear
                            def srgb2linear(f):
                                if f <= 0.04045:
                                    return f / 12.92
                                else:
                                    return ((f + 0.055) / 1.055)**2.4

                            if comp_type == rd.CompType.UNormSRGB:
                                expected[0:3] = [
                                    srgb2linear(x) for x in expected[0:3]
                                ]

                            if test_mode == Texture_Zoo.TEST_PNG:
                                orig_comp = self.textures[
                                    self.filename].format.compType
                                if orig_comp == rd.CompType.SNorm or orig_comp == rd.CompType.SInt:
                                    expected = [1.0 - x for x in expected]

                            if not rdtest.value_compare(picked, expected, eps):
                                raise rdtest.TestFailureException(
                                    "At ({},{}) of slice {}, mip {}, sample {} of {} {} got {}. Expected {}"
                                    .format(x, y, sl, mp, sm, name, fmt_name,
                                            picked, expected))

        if not image_view:
            output_tex = pipe.GetOutputTargets()[0].resourceId

            # in the test captures pick the output texture, it should be identical to the
            # (0,0) pixel in slice 0, mip 0, sample 0
            view: rd.Viewport = pipe.GetViewport(0)

            val: rd.PixelValue = self.pick(
                pipe.GetOutputTargets()[0].resourceId,
                int(view.x + view.width / 2), int(view.y + view.height / 2),
                rd.Subresource(), rd.CompType.Typeless)

            picked = val.floatValue

            # A8 picked values come out in alpha, but we want to compare against the single channel
            if tex.format.type == rd.ResourceFormatType.A8:
                picked[0] = picked[3]

            # Clamp to number of components in the texture
            picked = picked[0:comp_count]

            # Up-convert any non-float expected values to floats
            value0 = [float(x) for x in value0]

            # For depth/stencil images, one of either depth or stencil should match
            if comp_type == rd.CompType.Depth and len(value0) == 2:
                if picked[0] == 0.0:
                    value0[0] = 0.0
                    # normalise stencil value if it isn't already
                    if picked[1] > 1.0:
                        picked[1] /= 255.0
                elif picked[0] > 1.0:
                    # un-normalised stencil being rendered in red, match against our stencil expectation
                    picked[0] /= 255.0
                    value0[0] = value0[1]
                    value0[1] = 0.0
                else:
                    value0[1] = 0.0

            if not rdtest.value_compare(picked, value0, eps):
                raise rdtest.TestFailureException(
                    "In {} {} Top-left pixel as rendered is {}. Expected {}".
                    format(name, fmt_name, picked, value0))
Ejemplo n.º 22
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        vsin_ref = {
            0: {
                'vtx': 0,
                'idx': 1,
                'POSITION': [-0.5, -0.5, 0.0],
                'COLOR': [0.0, 1.0, 0.0, 1.0],
            },
            1: {
                'vtx': 1,
                'idx': 2,
                'POSITION': [0.0, 0.5, 0.0],
                'COLOR': [0.0, 1.0, 0.0, 1.0],
            },
            2: {
                'vtx': 2,
                'idx': 3,
                'POSITION': [0.5, -0.5, 0.0],
                'COLOR': [0.0, 1.0, 0.0, 1.0],
            },
            3: {
                'vtx': 3,
                'idx': 4,
                'POSITION': [8.8, 0.0, 0.0],
                'COLOR': [0.0, 0.0, 0.0, 1.0],
            },
            4: {
                'vtx': 4,
                'idx': 5,
                'POSITION': None,
                'COLOR': None,
            },
            5: {
                'vtx': 5,
                'idx': None,
                'POSITION': None,
                'COLOR': None,
            },
        }

        self.check_mesh_data(vsin_ref, self.get_vsin(draw))

        postvs_data = self.get_postvs(draw, rd.MeshDataStage.VSOut, 0,
                                      draw.numIndices)

        postvs_ref = {
            0: {
                'vtx': 0,
                'idx': 1,
                'OUTPOSITION': [-0.5, -0.5, 0.0, 1.0],
                'OUTCOLOR': [0.0, 1.0, 0.0, 1.0],
            },
            1: {
                'vtx': 1,
                'idx': 2,
                'OUTPOSITION': [0.0, 0.5, 0.0, 1.0],
                'OUTCOLOR': [0.0, 1.0, 0.0, 1.0],
            },
            2: {
                'vtx': 2,
                'idx': 3,
                'OUTPOSITION': [0.5, -0.5, 0.0, 1.0],
                'OUTCOLOR': [0.0, 1.0, 0.0, 1.0],
            },
            3: {
                'vtx': 3,
                'idx': 4,
                'OUTPOSITION': [8.8, 0.0, 0.0, 1.0],
                'OUTCOLOR': [0.0, 0.0, 0.0, 1.0],
            },
            4: {
                'vtx': 4,
                'idx': 5,
                # don't rely on any particular OOB behaviour for postvs, as this may come from the driver/API
            },
            5: {
                'vtx': 5,
                'idx': None,
                # don't rely on any particular OOB behaviour for postvs, as this may come from the driver/API
            },
        }

        self.check_mesh_data(postvs_ref, postvs_data)

        rdtest.log.success("vertex/index buffers were truncated as expected")

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

        stage = rd.ShaderStage.Pixel

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        if self.find_draw('NoCBufferRange') == None:
            self.check(cbuf.byteSize == 256)

        variables = self.controller.GetCBufferVariableContents(
            pipe.GetGraphicsPipelineObject(), pipe.GetShader(stage),
            pipe.GetShaderEntryPoint(stage), 0, cbuf.resourceId,
            cbuf.byteOffset, cbuf.byteSize)

        outcol: rd.ShaderVariable = variables[1]

        self.check(outcol.name == "outcol")
        if not rdtest.value_compare(outcol.value.f32v[0:4],
                                    [0.0, 0.0, 0.0, 0.0]):
            raise rdtest.TestFailureException(
                "expected outcol to be 0s, but got {}".format(
                    outcol.value.f32v[0:4]))

        if self.controller.GetAPIProperties(
        ).shaderDebugging and pipe.GetShaderReflection(
                rd.ShaderStage.Pixel).debugInfo.debuggable:
            # Debug the shader
            trace: rd.ShaderDebugTrace = self.controller.DebugPixel(
                int(pipe.GetViewport(0).width / 2),
                int(pipe.GetViewport(0).height / 2),
                rd.ReplayController.NoPreference,
                rd.ReplayController.NoPreference)

            if trace.debugger is None:
                self.controller.FreeTrace(trace)
                raise rdtest.TestFailureException(
                    "Shader did not debug at all")
            else:
                cycles, variables = self.process_trace(trace)

                cbuf_sourceVars = [
                    s for s in trace.sourceVars
                    if s.variables[0].type == rd.DebugVariableType.Constant
                    and s.rows > 0
                ]

                # Vulkan style, one source var for the cbuffer
                if len(cbuf_sourceVars) == 1:
                    debugged_cb = trace.constantBlocks[0]

                    self.check(debugged_cb.members[0].name == 'padding')
                    self.check(debugged_cb.members[1].name == 'outcol')

                    if not rdtest.value_compare(
                            debugged_cb.members[1].value.f32v[0:4],
                        [0.0, 0.0, 0.0, 0.0]):
                        raise rdtest.TestFailureException(
                            "expected outcol to be 0s, but got {}".format(
                                debugged_cb.members[1].value.f32v[0:4]))
                # D3D style, one source var for each member mapping to a register
                elif len(cbuf_sourceVars) == 17:
                    debugged_cb = trace.constantBlocks[0].members[16]

                    self.check(
                        all([
                            'consts.padding[' in c.name
                            for c in cbuf_sourceVars[0:16]
                        ]))
                    self.check(cbuf_sourceVars[16].name == 'consts.outcol')

                    self.check(
                        cbuf_sourceVars[16].variables[0].name == 'cb0[16]')

                    if not rdtest.value_compare(debugged_cb.value.f32v[0:4],
                                                [0.0, 0.0, 0.0, 0.0]):
                        raise rdtest.TestFailureException(
                            "expected outcol to be 0s, but got {}".format(
                                debugged_cb.members[1].value.f32v[0:4]))
                else:
                    raise rdtest.TestFailureException(
                        "Unexpected number of constant buffer source vars {}".
                        format(len(cbuf_sourceVars)))

        rdtest.log.success("CBuffer value was truncated as expected")
Ejemplo n.º 23
0
    def check_test(self, fmt_name: str, name: str, test_mode: int):
        pipe: rd.PipeState = self.controller.GetPipelineState()

        image_view = (test_mode != Texture_Zoo.TEST_CAPTURE)

        if image_view:
            bound_res: rd.BoundResource = pipe.GetOutputTargets()[0]
        else:
            bound_res: rd.BoundResource = pipe.GetReadOnlyResources(
                rd.ShaderStage.Pixel)[0].resources[0]

        texs = self.controller.GetTextures()
        for t in texs:
            self.textures[t.resourceId] = t

        tex_id: rd.ResourceId = bound_res.resourceId
        tex: rd.TextureDescription = self.textures[tex_id]

        comp_type: rd.CompType = tex.format.compType
        if bound_res.typeCast != rd.CompType.Typeless:
            comp_type = bound_res.typeCast

        # When not running proxied, save non-typecasted textures to disk
        if not image_view and not self.proxied and (
                tex.format.compType == comp_type
                or tex.format.type == rd.ResourceFormatType.D24S8
                or tex.format.type == rd.ResourceFormatType.D32S8):
            save_data = rd.TextureSave()
            save_data.resourceId = tex_id
            save_data.destType = rd.FileType.DDS
            save_data.sample.mapToArray = True

            self.textures[self.filename] = tex

            path = rdtest.get_tmp_path(self.filename + '.dds')

            success: bool = self.controller.SaveTexture(save_data, path)

            if not success:
                if self.d3d_mode:
                    raise rdtest.TestFailureException(
                        "Couldn't save DDS to {} on D3D.".format(
                            self.filename))

                try:
                    os.remove(path)
                except Exception:
                    pass

            save_data.destType = rd.FileType.PNG
            save_data.slice.sliceIndex = 0
            save_data.sample.sampleIndex = 0
            path = path.replace('.dds', '.png')

            if comp_type == rd.CompType.UInt:
                save_data.comp.blackPoint = 0.0
                save_data.comp.whitePoint = 255.0
            elif comp_type == rd.CompType.SInt:
                save_data.comp.blackPoint = -255.0
                save_data.comp.whitePoint = 0.0
            elif comp_type == rd.CompType.SNorm:
                save_data.comp.blackPoint = -1.0
                save_data.comp.whitePoint = 0.0

            success: bool = self.controller.SaveTexture(save_data, path)

            if not success:
                try:
                    os.remove(path)
                except Exception:
                    pass

        value0 = []

        comp_count = tex.format.compCount

        # When viewing PNGs only compare the components that the original texture had
        if test_mode == Texture_Zoo.TEST_PNG:
            comp_count = self.textures[self.filename]
            tex.msSamp = 0
            tex.arraysize = 1
            tex.depth = 1
            self.fake_msaa = 'MSAA' in name
        elif test_mode == Texture_Zoo.TEST_DDS:
            tex.arraysize = self.textures[self.filename].arraysize
            tex.msSamp = self.textures[self.filename].msSamp
            self.fake_msaa = 'MSAA' in name

        # HACK: We don't properly support BGRX, so just drop the alpha channel. We can't set this to compCount = 3
        # internally because that's a 24-bit format with no padding...
        if 'B8G8R8X8' in fmt_name:
            comp_count = 3

        # Completely ignore the alpha for BC1, our encoder doesn't pay attention to it
        if tex.format.type == rd.ResourceFormatType.BC1:
            comp_count = 3

        # Calculate format-appropriate epsilon
        eps_significand = 1.0
        # Account for the sRGB curve by more generous epsilon

        if comp_type == rd.CompType.UNormSRGB:
            eps_significand = 2.5
        # Similarly SNorm essentially loses a bit of accuracy due to us only using negative values
        elif comp_type == rd.CompType.SNorm:
            eps_significand = 2.0

        if tex.format.type == rd.ResourceFormatType.R4G4B4A4 or tex.format.type == rd.ResourceFormatType.R4G4:
            eps = (eps_significand / 15.0)
        elif rd.ResourceFormatType.BC1 <= tex.format.type <= rd.ResourceFormatType.BC3:
            eps = (eps_significand / 15.0)  # 4-bit precision in some channels
        elif tex.format.type == rd.ResourceFormatType.R5G5B5A1 or tex.format.type == rd.ResourceFormatType.R5G6B5:
            eps = (eps_significand / 31.0)
        elif tex.format.type == rd.ResourceFormatType.R11G11B10:
            eps = (eps_significand / 31.0)  # 5-bit mantissa in blue
        elif tex.format.type == rd.ResourceFormatType.R9G9B9E5:
            eps = (
                eps_significand / 63.0
            )  # we have 9 bits of data, but might lose 2-3 due to shared exponent
        elif tex.format.type == rd.ResourceFormatType.BC6 and tex.format.compType == rd.CompType.SNorm:
            eps = (eps_significand / 63.0
                   )  # Lose a bit worth of precision for the signed version
        elif rd.ResourceFormatType.BC4 <= tex.format.type <= rd.ResourceFormatType.BC7:
            eps = (eps_significand / 127.0)
        elif tex.format.compByteWidth == 1:
            eps = (eps_significand / 255.0)
        elif comp_type == rd.CompType.Depth and tex.format.compCount == 2:
            eps = (eps_significand / 255.0)  # stencil is only 8-bit
        elif tex.format.type == rd.ResourceFormatType.A8:
            eps = (eps_significand / 255.0)
        elif tex.format.type == rd.ResourceFormatType.R10G10B10A2:
            eps = (eps_significand / 1023.0)
        else:
            # half-floats have 11-bit mantissa. This epsilon is tight enough that we can be sure
            # any remaining errors are implementation inaccuracy and not our bug
            eps = (eps_significand / 2047.0)

        for mp in range(tex.mips):
            for sl in range(max(tex.arraysize, max(1, tex.depth >> mp))):
                z = 0
                if tex.depth > 1:
                    z = sl

                for sm in range(tex.msSamp):
                    cur_sub = self.sub(mp, sl, sm)

                    tex_display = rd.TextureDisplay()
                    tex_display.resourceId = tex_id
                    tex_display.subresource = cur_sub
                    tex_display.flipY = self.opengl_mode
                    tex_display.typeCast = comp_type
                    tex_display.alpha = False
                    tex_display.scale = 1.0 / float(1 << mp)
                    tex_display.backgroundColor = rd.FloatVector(
                        0.0, 0.0, 0.0, 1.0)

                    if comp_type == rd.CompType.UInt:
                        tex_display.rangeMin = 0.0
                        tex_display.rangeMax = 255.0
                    elif comp_type == rd.CompType.SInt:
                        tex_display.rangeMin = -255.0
                        tex_display.rangeMax = 0.0
                    elif comp_type == rd.CompType.SNorm:
                        tex_display.rangeMin = -1.0
                        tex_display.rangeMax = 0.0

                    self.out.SetTextureDisplay(tex_display)

                    self.out.Display()

                    pixels: bytes = self.out.ReadbackOutputTexture()
                    dim = self.out.GetDimensions()

                    stencilpixels = None

                    # Grab stencil separately
                    if tex.format.type == rd.ResourceFormatType.D16S8 or tex.format.type == rd.ResourceFormatType.D24S8 or tex.format.type == rd.ResourceFormatType.D32S8:
                        tex_display.red = False
                        tex_display.green = True
                        tex_display.blue = False
                        tex_display.alpha = False

                        self.out.SetTextureDisplay(tex_display)
                        self.out.Display()

                        stencilpixels: bytes = self.out.ReadbackOutputTexture()

                    # Grab alpha if needed (since the readback output is RGB only)
                    if comp_count == 4 or tex.format.type == rd.ResourceFormatType.A8:
                        tex_display.red = False
                        tex_display.green = False
                        tex_display.blue = False
                        tex_display.alpha = True

                        self.out.SetTextureDisplay(tex_display)
                        self.out.Display()

                        alphapixels: bytes = self.out.ReadbackOutputTexture()

                    all_good = True

                    for x in range(max(1, tex.width >> mp)):
                        if not all_good:
                            break
                        for y in range(max(1, tex.height >> mp)):
                            expected = self.get_expected_value(
                                comp_count, comp_type, cur_sub, test_mode, tex,
                                x, y, z)

                            # for this test to work the expected values have to be within the range we selected for
                            # display above
                            for i in expected:
                                if i < tex_display.rangeMin or tex_display.rangeMax < i:
                                    raise rdtest.TestFailureException(
                                        "expected value {} is outside of texture display range! {} - {}"
                                        .format(i, tex_display.rangeMin,
                                                tex_display.rangeMax))

                            # convert the expected values to range-adapted values
                            for i in range(len(expected)):
                                expected[i] = (expected[i] -
                                               tex_display.rangeMin) / (
                                                   tex_display.rangeMax -
                                                   tex_display.rangeMin)

                            # get the bytes from the displayed pixel
                            offs = y * dim[0] * 3 + x * 3
                            displayed = [
                                int(a) for a in pixels[offs:offs + comp_count]
                            ]
                            if comp_count == 4:
                                del displayed[3]
                                displayed.append(int(alphapixels[offs]))
                            if stencilpixels is not None:
                                del displayed[1:]
                                displayed.append(int(stencilpixels[offs]))
                            if tex.format.type == rd.ResourceFormatType.A8:
                                displayed = [int(alphapixels[offs])]

                            # normalise the displayed values
                            for i in range(len(displayed)):
                                displayed[i] = float(displayed[i]) / 255.0

                            # For SRGB textures match linear picked values. We do this for alpha too since it's rendered
                            # via RGB
                            if comp_type == rd.CompType.UNormSRGB:
                                displayed[0:4] = [
                                    srgb2linear(x) for x in displayed[0:4]
                                ]

                            # alpha channel in 10:10:10:2 has extremely low precision, and the ULP requirements mean
                            # we basically can't trust anything between 0 and 1 on float formats. Just round in that
                            # case as it still lets us differentiate between alpha 0.0-0.5 and 0.5-1.0
                            if tex.format.type == rd.ResourceFormatType.R10G10B10A2 and comp_type != rd.CompType.UInt:
                                displayed[3] = round(displayed[3]) * 1.0

                            # Handle 1-bit alpha
                            if tex.format.type == rd.ResourceFormatType.R5G5B5A1:
                                displayed[
                                    3] = 1.0 if displayed[3] >= 0.5 else 0.0

                            # Need an additional 1/255 epsilon to account for us going via a 8-bit backbuffer for display
                            if not rdtest.value_compare(
                                    displayed, expected, 1.0 / 255.0 + eps):
                                #rdtest.log.print(
                                #    "Quick-checking ({},{}) of slice {}, mip {}, sample {} of {} {} got {}. Expected {}.".format(
                                #        x, y, sl, mp, sm, name, fmt_name, displayed, expected) +
                                #    "Falling back to pixel picking tests.")
                                # Currently this seems to fail in some proxy scenarios with sRGB, but since it's not a
                                # real error we just silently swallow it
                                all_good = False
                                break

                    if all_good:
                        continue

                    for x in range(max(1, tex.width >> mp)):
                        for y in range(max(1, tex.height >> mp)):
                            expected = self.get_expected_value(
                                comp_count, comp_type, cur_sub, test_mode, tex,
                                x, y, z)
                            picked = self.get_picked_pixel_value(
                                comp_count, comp_type, cur_sub, tex, tex_id, x,
                                y)

                            if mp == 0 and sl == 0 and sm == 0 and x == 0 and y == 0:
                                value0 = picked

                            if not rdtest.value_compare(picked, expected, eps):
                                raise rdtest.TestFailureException(
                                    "At ({},{}) of slice {}, mip {}, sample {} of {} {} got {}. Expected {}"
                                    .format(x, y, sl, mp, sm, name, fmt_name,
                                            picked, expected))

        if not image_view:
            output_tex = pipe.GetOutputTargets()[0].resourceId

            # in the test captures pick the output texture, it should be identical to the
            # (0,0) pixel in slice 0, mip 0, sample 0
            view: rd.Viewport = pipe.GetViewport(0)

            val: rd.PixelValue = self.pick(
                pipe.GetOutputTargets()[0].resourceId,
                int(view.x + view.width / 2), int(view.y + view.height / 2),
                rd.Subresource(), rd.CompType.Typeless)

            picked = list(val.floatValue)

            # A8 picked values come out in alpha, but we want to compare against the single channel
            if tex.format.type == rd.ResourceFormatType.A8:
                picked[0] = picked[3]

            # Clamp to number of components in the texture
            picked = picked[0:comp_count]

            # If we didn't get a value0 (because we did all texture render compares) then fetch it here
            if len(value0) == 0:
                value0 = self.get_picked_pixel_value(comp_count, comp_type,
                                                     rd.Subresource(), tex,
                                                     tex_id, 0, 0)

            # Up-convert any non-float expected values to floats
            value0 = [float(x) for x in value0]

            # For depth/stencil images, one of either depth or stencil should match
            if comp_type == rd.CompType.Depth and len(value0) == 2:
                if picked[0] == 0.0:
                    value0[0] = 0.0
                    # normalise stencil value if it isn't already
                    if picked[1] > 1.0:
                        picked[1] /= 255.0
                elif picked[0] > 1.0:
                    # un-normalised stencil being rendered in red, match against our stencil expectation
                    picked[0] /= 255.0
                    value0[0] = value0[1]
                    value0[1] = 0.0
                else:
                    if picked[1] == 0.0:
                        value0[1] = 0.0
                    if picked[1] > 1.0:
                        picked[1] /= 255.0

            if not rdtest.value_compare(picked, value0, eps):
                raise rdtest.TestFailureException(
                    "In {} {} Top-left pixel as rendered is {}. Expected {}".
                    format(name, fmt_name, picked, value0))
Ejemplo n.º 24
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

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

        stage = rd.ShaderStage.Pixel
        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 0, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetGraphicsPipelineObject(), pipe.GetShader(stage),
                pipe.GetShaderEntryPoint(stage), 0, cbuf.resourceId,
                cbuf.byteOffset))

        # For more detailed reference for the below checks, see the commented definition of the cbuffer
        # in the shader source code in the demo itself

        # float4 a;
        var_check.check('a').rows(1).cols(4).value([0.0, 1.0, 2.0, 3.0])

        # float3 b;
        var_check.check('b').rows(1).cols(3).value([4.0, 5.0, 6.0])

        # float2 c; float2 d;
        var_check.check('c').rows(1).cols(2).value([8.0, 9.0])
        var_check.check('d').rows(1).cols(2).value([10.0, 11.0])

        # float e; float3 f;
        var_check.check('e').rows(1).cols(1).value([12.0])
        var_check.check('f').rows(1).cols(3).value([13.0, 14.0, 15.0])

        # float g; float2 h; float i;
        var_check.check('g').rows(1).cols(1).value([16.0])
        var_check.check('h').rows(1).cols(2).value([17.0, 18.0])
        var_check.check('i').rows(1).cols(1).value([19.0])

        # float j; float2 k;
        var_check.check('j').rows(1).cols(1).value([20.0])
        var_check.check('k').rows(1).cols(2).value([21.0, 22.0])

        # float2 l; float m;
        var_check.check('l').rows(1).cols(2).value([24.0, 25.0])
        var_check.check('m').rows(1).cols(1).value([26.0])

        # float n[4];
        var_check.check('n').rows(0).cols(0).arraySize(4).members({
            0:
            lambda x: x.rows(1).cols(1).value([28.0]),
            1:
            lambda x: x.rows(1).cols(1).value([32.0]),
            2:
            lambda x: x.rows(1).cols(1).value([36.0]),
            3:
            lambda x: x.rows(1).cols(1).value([40.0]),
        })

        # float4 dummy1;
        var_check.check('dummy1')

        # float o[4];
        var_check.check('o').rows(0).cols(0).arraySize(4).members({
            0:
            lambda x: x.rows(1).cols(1).value([48.0]),
            1:
            lambda x: x.rows(1).cols(1).value([52.0]),
            2:
            lambda x: x.rows(1).cols(1).value([56.0]),
            3:
            lambda x: x.rows(1).cols(1).value([60.0]),
        })

        # float p;
        var_check.check('p').rows(1).cols(1).value([61.0])

        # float4 dummy2;
        var_check.check('dummy2')

        # float4 dummygl1;
        # float4 dummygl2;
        var_check.check('dummygl1')
        var_check.check('dummygl2')

        # column_major float4x4 q;
        var_check.check('q').rows(4).cols(4).column_major().value([
            76.0, 80.0, 84.0, 88.0, 77.0, 81.0, 85.0, 89.0, 78.0, 82.0, 86.0,
            90.0, 79.0, 83.0, 87.0, 91.0
        ])

        # row_major float4x4 r;
        var_check.check('r').rows(4).cols(4).row_major().value([
            92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 100.0, 101.0,
            102.0, 103.0, 104.0, 105.0, 106.0, 107.0
        ])

        # column_major float3x4 s;
        var_check.check('s').rows(3).cols(4).column_major().value([
            108.0, 112.0, 116.0, 120.0, 109.0, 113.0, 117.0, 121.0, 110.0,
            114.0, 118.0, 122.0
        ])

        # float4 dummy3;
        var_check.check('dummy3')

        # row_major float3x4 t;
        var_check.check('t').rows(3).cols(4).row_major().value([
            128.0, 129.0, 130.0, 131.0, 132.0, 133.0, 134.0, 135.0, 136.0,
            137.0, 138.0, 139.0
        ])

        # float4 dummy4;
        var_check.check('dummy4')

        # column_major float2x3 u;
        var_check.check('u').rows(2).cols(3).column_major().value(
            [144.0, 148.0, 152.0, 145.0, 149.0, 153.0])

        # float4 dummy5;
        var_check.check('dummy5')

        # row_major float2x3 v;
        var_check.check('v').rows(2).cols(3).row_major().value(
            [160.0, 161.0, 162.0, 164.0, 165.0, 166.0])

        # float4 dummy6;
        var_check.check('dummy6')

        # column_major float2x2 w;
        var_check.check('w').rows(2).cols(2).column_major().value(
            [172.0, 176.0, 173.0, 177.0])

        # float4 dummy7;
        var_check.check('dummy7')

        # row_major float2x2 x;
        var_check.check('x').rows(2).cols(2).row_major().value(
            [184.0, 185.0, 188.0, 189.0])

        # float4 dummy8;
        var_check.check('dummy8')

        # row_major float2x2 y;
        var_check.check('y').rows(2).cols(2).row_major().value(
            [196.0, 197.0, 200.0, 201.0])

        # float z;
        var_check.check('z').rows(1).cols(1).value([202.0])

        # float4 gldummy3;
        var_check.check('gldummy3')

        # row_major float4x1 aa;
        var_check.check('aa').rows(4).cols(1).value(
            [208.0, 212.0, 216.0, 220.0])

        # column_major float4x1 ab;
        var_check.check('ab').rows(4).cols(1).value(
            [224.0, 225.0, 226.0, 227.0])

        # float4 multiarray[3][2];
        # this is flattened to just multiarray[6]
        var_check.check('multiarray').rows(0).cols(0).arraySize(6).members({
            0:
            lambda x: x.rows(1).cols(4).value([228.0, 229.0, 230.0, 231.0]),
            1:
            lambda x: x.rows(1).cols(4).value([232.0, 233.0, 234.0, 235.0]),
            2:
            lambda x: x.rows(1).cols(4).value([236.0, 237.0, 238.0, 239.0]),
            3:
            lambda x: x.rows(1).cols(4).value([240.0, 241.0, 242.0, 243.0]),
            4:
            lambda x: x.rows(1).cols(4).value([244.0, 245.0, 246.0, 247.0]),
            5:
            lambda x: x.rows(1).cols(4).value([248.0, 249.0, 250.0, 251.0]),
        })

        # struct float3_1 { float3 a; float b; };
        # struct nested { float3_1 a; float4 b[4]; float3_1 c[4]; };
        # nested structa[2];
        var_check.check('structa').rows(0).cols(0).arraySize(2).members({
            # structa[0]
            0:
            lambda s: s.rows(0).cols(0).structSize(3).members({
                'a':
                lambda x: x.rows(0).cols(0).structSize(2).members({
                    'a':
                    lambda y: y.rows(1).cols(3).value([252.0, 253.0, 254.0]),
                    'b':
                    lambda y: y.rows(1).cols(1).value([255.0]),
                }),
                'b':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(1).cols(4).value(
                        [256.0, 257.0, 258.0, 259.0]),
                    1:
                    lambda y: y.rows(1).cols(4).value(
                        [260.0, 261.0, 262.0, 263.0]),
                    2:
                    lambda y: y.rows(1).cols(4).value(
                        [264.0, 265.0, 266.0, 267.0]),
                    3:
                    lambda y: y.rows(1).cols(4).value(
                        [268.0, 269.0, 270.0, 271.0]),
                }),
                'c':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [272.0, 273.0, 274.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([275.0]),
                    }),
                    1:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [276.0, 277.0, 278.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([279.0]),
                    }),
                    2:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [280.0, 281.0, 282.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([283.0]),
                    }),
                    3:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [284.0, 285.0, 286.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([287.0]),
                    }),
                }),
            }),
            # structa[1]
            1:
            lambda s: s.rows(0).cols(0).structSize(3).members({
                'a':
                lambda x: x.rows(0).cols(0).structSize(2).members({
                    'a':
                    lambda y: y.rows(1).cols(3).value([288.0, 289.0, 290.0]),
                    'b':
                    lambda y: y.rows(1).cols(1).value([291.0]),
                }),
                'b':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(1).cols(4).value(
                        [292.0, 293.0, 294.0, 295.0]),
                    1:
                    lambda y: y.rows(1).cols(4).value(
                        [296.0, 297.0, 298.0, 299.0]),
                    2:
                    lambda y: y.rows(1).cols(4).value(
                        [300.0, 301.0, 302.0, 303.0]),
                    3:
                    lambda y: y.rows(1).cols(4).value(
                        [304.0, 305.0, 306.0, 307.0]),
                }),
                'c':
                lambda x: x.rows(0).cols(0).arraySize(4).members({
                    0:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [308.0, 309.0, 310.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([311.0]),
                    }),
                    1:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [312.0, 313.0, 314.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([315.0]),
                    }),
                    2:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [316.0, 317.0, 318.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([319.0]),
                    }),
                    3:
                    lambda y: y.rows(0).cols(0).structSize(2).members({
                        'a':
                        lambda z: z.rows(1).cols(3).value(
                            [320.0, 321.0, 322.0]),
                        'b':
                        lambda z: z.rows(1).cols(1).value([323.0]),
                    }),
                }),
            }),
        })

        # column_major float3x2 ac;
        var_check.check('ac').rows(3).cols(2).column_major().value(
            [324.0, 328.0, 325.0, 329.0, 326.0, 330.0])

        # row_major float3x2 ad;
        var_check.check('ad').rows(3).cols(2).row_major().value(
            [332.0, 333.0, 336.0, 337.0, 340.0, 341.0])

        # column_major float3x2 ae[2];
        var_check.check('ae').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(3).cols(2).column_major().value(
                [344.0, 348.0, 345.0, 349.0, 346.0, 350.0]),
            1:
            lambda x: x.rows(3).cols(2).column_major().value(
                [352.0, 356.0, 353.0, 357.0, 354.0, 358.0]),
        })

        # row_major float3x2 af[2];
        var_check.check('af').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(3).cols(2).row_major().value(
                [360.0, 361.0, 364.0, 365.0, 368.0, 369.0]),
            1:
            lambda x: x.rows(3).cols(2).row_major().value(
                [372.0, 373.0, 376.0, 377.0, 380.0, 381.0]),
        })

        # float2 dummy9;
        var_check.check('dummy9')

        # float2 dummy10;
        var_check.check('dummy10')

        # row_major float2x2 ag;
        var_check.check('ag').rows(2).cols(2).row_major().value(
            [388.0, 389.0, 392.0, 393.0])

        # float2 dummy11;
        var_check.check('dummy11')

        # float2 dummy12;
        var_check.check('dummy12')

        # column_major float2x2 ah;
        var_check.check('ah').rows(2).cols(2).column_major().value(
            [400.0, 404.0, 401.0, 405.0])

        # row_major float2x2 ai[2];
        var_check.check('ai').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(2).row_major().value(
                [408.0, 409.0, 412.0, 413.0]),
            1:
            lambda x: x.rows(2).cols(2).row_major().value(
                [416.0, 417.0, 420.0, 421.0]),
        })

        # column_major float2x2 aj[2];
        var_check.check('aj').rows(0).cols(0).arraySize(2).members({
            0:
            lambda x: x.rows(2).cols(2).column_major().value(
                [424.0, 428.0, 425.0, 429.0]),
            1:
            lambda x: x.rows(2).cols(2).column_major().value(
                [432.0, 436.0, 433.0, 437.0]),
        })

        # float4 test;
        var_check.check('test').rows(1).cols(4).value(
            [440.0, 441.0, 442.0, 443.0])

        var_check.done()

        rdtest.log.success("CBuffer variables are as expected")

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2),
                                              int(texdetails.height / 2), 0, 0,
                                              0)

        if not rdtest.value_compare(picked.floatValue,
                                    [440.1, 441.0, 442.0, 443.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("Picked value is as expected")

        cbuf: rd.BoundCBuffer = pipe.GetConstantBuffer(stage, 1, 0)

        var_check = rdtest.ConstantBufferChecker(
            self.controller.GetCBufferVariableContents(
                pipe.GetGraphicsPipelineObject(), pipe.GetShader(stage),
                pipe.GetShaderEntryPoint(stage), 1, cbuf.resourceId,
                cbuf.byteOffset))

        # float4 zero;
        var_check.check('root_zero').rows(1).cols(4).value(
            [0.0, 0.0, 0.0, 0.0])

        # float4 a;
        var_check.check('root_a').rows(1).cols(4).value(
            [10.0, 20.0, 30.0, 40.0])

        # float2 b;
        var_check.check('root_b').rows(1).cols(2).value([50.0, 60.0])

        # float2 c;
        var_check.check('root_c').rows(1).cols(2).value([70.0, 80.0])

        # float3_1 d;
        var_check.check('root_d').rows(0).cols(0).structSize(2).members({
            'a':
            lambda y: y.rows(1).cols(3).value([90.0, 100.0, 110.0]),
            'b':
            lambda y: y.rows(1).cols(1).value([120.0]),
        })

        var_check.done()

        rdtest.log.success("Root signature variables are as expected")

        out.Shutdown()
Ejemplo n.º 25
0
    def check_capture(self):
        actions = self.controller.GetRootActions()

        for d in self.controller.GetRootActions():
            # Only process test actions
            if not d.customName.startswith('Test'):
                continue

            # Go to the last child action
            self.controller.SetFrameEvent(d.children[-1].eventId, True)

            if any(['UInt tex' in d.customName for d in d.children]):
                value_selector = lambda x: x.uintValue
                shader_out = (0, 1, 1234, 5)
            elif any(['SInt tex' in d.customName for d in d.children]):
                value_selector = lambda x: x.intValue
                shader_out = (0, 1, -1234, 5)
            else:
                value_selector = lambda x: x.floatValue
                shader_out = (0.0, 1.0, 0.1234, 0.5)

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

            rt: rd.BoundResource = pipe.GetOutputTargets()[0]

            vp: rd.Viewport = pipe.GetViewport(0)

            tex = rt.resourceId
            x, y = (int(vp.width / 2), int(vp.height / 2))

            tex_details = self.get_texture(tex)

            sub = rd.Subresource()
            if tex_details.arraysize > 1:
                sub.slice = rt.firstSlice
            if tex_details.mips > 1:
                sub.mip = rt.firstMip

            modifs: List[rd.PixelModification] = self.controller.PixelHistory(tex, x, y, sub, rt.typeCast)

            # Should be at least two modifications in every test - clear and action
            self.check(len(modifs) >= 2)

            # Check that the modifications are self consistent - postmod of each should match premod of the next
            for i in range(len(modifs) - 1):
                if value_selector(modifs[i].postMod.col) != value_selector(modifs[i + 1].preMod.col):
                    raise rdtest.TestFailureException(
                        "postmod at {}: {} doesn't match premod at {}: {}".format(modifs[i].eventId,
                                                                                  value_selector(modifs[i].postMod.col),
                                                                                  modifs[i + 1].eventId,
                                                                                  value_selector(modifs[i].preMod.col)))

                if self.get_action(modifs[i].eventId).flags & rd.ActionFlags.Drawcall:
                    if not rdtest.value_compare(value_selector(modifs[i].shaderOut.col), shader_out):
                        raise rdtest.TestFailureException(
                            "Shader output {} isn't as expected {}".format(value_selector(modifs[i].shaderOut.col),
                                                                           shader_out))

            rdtest.log.success("shader output and premod/postmod is consistent")

            # The current pixel value should match the last postMod
            self.check_pixel_value(tex, x, y, value_selector(modifs[-1].postMod.col), sub=sub, cast=rt.typeCast)

            # Also the red channel should be zero, as it indicates errors
            self.check(float(value_selector(modifs[-1].postMod.col)[0]) == 0.0)
Ejemplo n.º 26
0
    def check_capture(self):
        id = self.get_last_draw().copyDestination

        tex_details = self.get_texture(id)

        self.controller.SetFrameEvent(self.get_last_draw().eventId, True)

        data = self.controller.GetTextureData(id, rd.Subresource(0, 0, 0))
        first_pixel = struct.unpack_from("BBBB", data, 0)

        val = [255, 0, 255, 255]
        if not rdtest.value_compare(first_pixel, val):
            raise rdtest.TestFailureException(
                "First pixel should be clear color {}, not {}".format(
                    val, first_pixel))

        magic_pixel = struct.unpack_from("BBBB", data,
                                         (50 * tex_details.width + 320) * 4)

        # allow 127 or 128 for alpha
        val = [0, 0, 255, magic_pixel[3]]
        if not rdtest.value_compare(magic_pixel,
                                    val) or magic_pixel[3] not in [127, 128]:
            raise rdtest.TestFailureException(
                "Pixel @ 320,50 should be blue: {}, not {}".format(
                    val, magic_pixel))

        rdtest.log.success("Decoded pixels from texture data are correct")

        img_path = rdtest.get_tmp_path('preserved_alpha.png')

        self.controller.SetFrameEvent(self.get_last_draw().eventId, True)

        save_data = rd.TextureSave()
        save_data.resourceId = id
        save_data.destType = rd.FileType.PNG
        save_data.alpha = rd.AlphaMapping.Discard  # this should not discard the alpha

        self.controller.SaveTexture(save_data, img_path)

        data = rdtest.png_load_data(img_path)

        magic_pixel = struct.unpack_from("BBBB", data[-1 - 50], 320 * 4)

        val = [0, 0, 255, magic_pixel[3]]
        if not rdtest.value_compare(magic_pixel,
                                    val) or magic_pixel[3] not in [127, 128]:
            raise rdtest.TestFailureException(
                "Pixel @ 320,50 should be blue: {}, not {}".format(
                    val, magic_pixel))

        draw = self.find_draw("Draw")

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

        postvs_data = self.get_postvs(rd.MeshDataStage.VSOut, 0,
                                      draw.numIndices)

        postvs_ref = {
            0: {
                'vtx': 0,
                'idx': 0,
                'gl_Position': [-0.5, -0.5, 0.0, 1.0],
                'v2fcol': [1.0, 0.0, 0.0, 1.0],
            },
            1: {
                'vtx': 1,
                'idx': 1,
                'gl_Position': [0.0, 0.5, 0.0, 1.0],
                'v2fcol': [0.0, 1.0, 0.0, 1.0],
            },
            2: {
                'vtx': 2,
                'idx': 2,
                'gl_Position': [0.5, -0.5, 0.0, 1.0],
                'v2fcol': [0.0, 0.0, 1.0, 1.0],
            },
        }

        self.check_mesh_data(postvs_ref, postvs_data)

        results = self.controller.FetchCounters([
            rd.GPUCounter.RasterizedPrimitives, rd.GPUCounter.VSInvocations,
            rd.GPUCounter.FSInvocations
        ])

        results = [r for r in results if r.eventId == draw.eventId]

        if len(results) != 3:
            raise rdtest.TestFailureException(
                "Expected 3 results, got {} results".format(len(results)))

        for r in results:
            r: rd.CounterResult
            val = r.value.u32
            if r.counter == rd.GPUCounter.RasterizedPrimitives:
                if not rdtest.value_compare(val, 1):
                    raise rdtest.TestFailureException(
                        "RasterizedPrimitives result {} is not as expected".
                        format(val))
                else:
                    rdtest.log.success(
                        "RasterizedPrimitives result is as expected")
            elif r.counter == rd.GPUCounter.VSInvocations:
                if not rdtest.value_compare(val, 3):
                    raise rdtest.TestFailureException(
                        "VSInvocations result {} is not as expected".format(
                            val))
                else:
                    rdtest.log.success("VSInvocations result is as expected")
            elif r.counter == rd.GPUCounter.FSInvocations:
                if val < int(0.1 * tex_details.width * tex_details.height):
                    raise rdtest.TestFailureException(
                        "FSInvocations result {} is not as expected".format(
                            val))
                else:
                    rdtest.log.success("FSInvocations result is as expected")
            else:
                raise rdtest.TestFailureException(
                    "Unexpected counter result {}".format(r.counter))

        rdtest.log.success("Counter data retrieved successfully")
Ejemplo n.º 27
0
    def check_capture(self):
        draw = self.find_draw("Draw")

        self.check(draw is not None)

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

        # Make an output so we can pick pixels
        out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        self.check(out is not None)

        ref = {
            0: {
                'SNORM': [1.0, -1.0, 1.0, -1.0],
                'UNORM': [
                    12345.0 / 65535.0, 6789.0 / 65535.0, 1234.0 / 65535.0,
                    567.0 / 65535.0
                ],
                'UINT': [12345, 6789, 1234, 567],
                'ARRAY0': [1.0, 2.0],
                'ARRAY1': [3.0, 4.0],
                'ARRAY2': [5.0, 6.0],
                'MATRIX0': [7.0, 8.0],
                'MATRIX1': [9.0, 10.0],
            },
            1: {
                'SNORM': [
                    32766.0 / 32767.0, -32766.0 / 32767.0, 16000.0 / 32767.0,
                    -16000.0 / 32767.0
                ],
                'UNORM': [
                    56.0 / 65535.0, 7890.0 / 65535.0, 123.0 / 65535.0,
                    4567.0 / 65535.0
                ],
                'UINT': [56, 7890, 123, 4567],
                'ARRAY0': [11.0, 12.0],
                'ARRAY1': [13.0, 14.0],
                'ARRAY2': [15.0, 16.0],
                'MATRIX0': [17.0, 18.0],
                'MATRIX1': [19.0, 20.0],
            },
            2: {
                'SNORM': [5.0 / 32767.0, -5.0 / 32767.0, 0.0, 0.0],
                'UNORM': [
                    8765.0 / 65535.0, 43210.0 / 65535.0, 987.0 / 65535.0,
                    65432.0 / 65535.0
                ],
                'UINT': [8765, 43210, 987, 65432],
                'ARRAY0': [21.0, 22.0],
                'ARRAY1': [23.0, 24.0],
                'ARRAY2': [25.0, 26.0],
                'MATRIX0': [27.0, 28.0],
                'MATRIX1': [29.0, 30.0],
            },
        }

        in_ref = copy.deepcopy(ref)
        vsout_ref = copy.deepcopy(ref)
        gsout_ref = ref

        vsout_ref[0]['SV_Position'] = [-0.5, 0.5, 0.0, 1.0]
        gsout_ref[0]['SV_Position'] = [0.5, -0.5, 0.4, 1.2]

        vsout_ref[1]['SV_Position'] = [0.0, -0.5, 0.0, 1.0]
        gsout_ref[1]['SV_Position'] = [-0.5, 0.0, 0.4, 1.2]

        vsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.0, 1.0]
        gsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.4, 1.2]

        self.check_mesh_data(in_ref, self.get_vsin(draw))
        rdtest.log.success("Vertex input data is as expected")

        self.check_mesh_data(vsout_ref,
                             self.get_postvs(rd.MeshDataStage.VSOut))

        rdtest.log.success("Vertex output data is as expected")

        self.check_mesh_data(gsout_ref,
                             self.get_postvs(rd.MeshDataStage.GSOut))

        rdtest.log.success("Geometry output data is as expected")

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

        tex = rd.TextureDisplay()
        tex.resourceId = pipe.GetOutputTargets()[0].resourceId
        out.SetTextureDisplay(tex)

        texdetails = self.get_texture(tex.resourceId)

        picked: rd.PixelValue = out.PickPixel(tex.resourceId, False,
                                              int(texdetails.width / 2),
                                              int(texdetails.height / 2), 0, 0,
                                              0)

        if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]):
            raise rdtest.TestFailureException(
                "Picked value {} doesn't match expectation".format(
                    picked.floatValue))

        rdtest.log.success("Triangle picked value is as expected")

        out.Shutdown()
Ejemplo n.º 28
0
    def check_capture(self):
        self.check_final_backbuffer()

        for level in ["Primary", "Secondary"]:
            rdtest.log.print("Checking {} indirect calls".format(level))

            dispatches = self.find_draw("{}: Dispatches".format(level))

            # 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".format(level))

            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".format(
                    level))

            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
                        if not rdtest.value_compare(uints[idx],
                                                    [x, y, z, 12345]):
                            raise rdtest.TestFailureException(
                                'expected thread index data @ {},{},{}: {} is not as expected: {}'
                                .format(x, y, z, uints[idx], [x, y, z, 12345]))

            rdtest.log.success(
                "Dispatched buffer contents are as expected for {}".format(
                    level))

            empties = self.find_draw("{}: Empty draws".format(level))

            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".format(level))

            indirects = self.find_draw("{}: Indirect draws".format(level))

            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".format(level))

            # 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(level, 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(level, 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(level, draw.name))

            indirect_count_root = self.find_draw(
                "{}: KHR_draw_indirect_count".format(level))

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

                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(
                    level, 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(
                    level, 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(
                    level, 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(
                    level, draw.name))
            else:
                rdtest.log.print("KHR_draw_indirect_count not tested")
Ejemplo n.º 29
0
    def check_capture(self):
        fill = self.find_action("vkCmdFillBuffer")

        self.check(fill is not None)

        buffer_usage = {}

        for usage in self.controller.GetUsage(fill.copyDestination):
            usage: rd.EventUsage
            if usage.eventId not in buffer_usage:
                buffer_usage[usage.eventId] = []
            buffer_usage[usage.eventId].append(usage.usage)

        # The texture is the backbuffer
        tex = self.get_last_action().copyDestination

        for level in ["Primary", "Secondary"]:
            rdtest.log.print("Checking {} indirect calls".format(level))

            final = self.find_action("{}: Final".format(level))

            indirect_count_root = self.find_action(
                "{}: KHR_action_indirect_count".format(level))

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

            # Check the top row, non indirect count and always present
            self.check_pixel_value(tex, 60, 60, [1.0, 0.0, 0.0, 1.0])
            self.check_pixel_value(tex, 100, 60, [0.0, 0.0, 1.0, 1.0])
            self.check_pixel_value(tex, 145, 35, [1.0, 1.0, 0.0, 1.0])
            self.check_pixel_value(tex, 205, 35, [0.0, 1.0, 1.0, 1.0])

            # if present, check bottom row of indirect count as well as post-count calls
            if indirect_count_root is not None:
                self.check_pixel_value(tex, 60, 220, [0.0, 1.0, 0.0, 1.0])
                self.check_pixel_value(tex, 100, 220, [1.0, 0.0, 1.0, 1.0])
                self.check_pixel_value(tex, 145, 185, [0.5, 1.0, 0.0, 1.0])
                self.check_pixel_value(tex, 205, 185, [0.5, 0.0, 1.0, 1.0])

                self.check_pixel_value(tex, 340, 40, [1.0, 0.5, 0.0, 1.0])
                self.check_pixel_value(tex, 340, 115, [1.0, 0.5, 0.5, 1.0])
                self.check_pixel_value(tex, 340, 190, [1.0, 0.0, 0.5, 1.0])

            dispatches = self.find_action("{}: Dispatches".format(level))

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

            self.check(self.out is not None)

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

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

            rdtest.log.success("Selected all {} actions".format(level))

            self.check(dispatches
                       and len(real_action_children(dispatches)) == 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".format(
                    level))

            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
                        if not rdtest.value_compare(uints[idx],
                                                    [x, y, z, 12345]):
                            raise rdtest.TestFailureException(
                                'expected thread index data @ {},{},{}: {} is not as expected: {}'
                                .format(x, y, z, uints[idx], [x, y, z, 12345]))

            rdtest.log.success(
                "Dispatched buffer contents are as expected for {}".format(
                    level))

            empties = self.find_action("{}: Empty draws".format(level))

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

            action: rd.ActionDescription
            for action in real_action_children(empties):
                self.check(action.numIndices == 0)
                self.check(action.numInstances == 0)

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

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

                # No samples should be passing in the empties
                self.check_overlay([])

            rdtest.log.success("{} empty actions are empty".format(level))

            indirects = self.find_action("{}: Indirect draws".format(level))

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

            rdtest.log.success(
                "Correct number of {} indirect draws".format(level))

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

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

            self.check(
                rd.ResourceUsage.Indirect in buffer_usage[action.eventId])

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

            postvs_ref = {
                0: {
                    'vtx': 0,
                    'idx': 0,
                    'gl_PerVertex_var.gl_Position': [-0.8, -0.5, 0.0, 1.0]
                },
                1: {
                    'vtx': 1,
                    'idx': 1,
                    'gl_PerVertex_var.gl_Position': [-0.7, -0.8, 0.0, 1.0]
                },
                2: {
                    'vtx': 2,
                    'idx': 2,
                    'gl_PerVertex_var.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([(60, 40)])

            rdtest.log.success("{} {} is as expected".format(
                level, action.customName))

            self.check(rd.ResourceUsage.Indirect in buffer_usage[
                indirects.children[1].eventId])

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

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

            # Check that we have PostVS as expected
            postvs_data = self.get_postvs(action, 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': 6,
                    'gl_PerVertex_var.gl_Position': [-0.6, -0.5, 0.0, 1.0]
                },
                1: {
                    'vtx': 1,
                    'idx': 7,
                    'gl_PerVertex_var.gl_Position': [-0.5, -0.8, 0.0, 1.0]
                },
                2: {
                    'vtx': 2,
                    'idx': 8,
                    'gl_PerVertex_var.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([(100, 40)])

            rdtest.log.success("{} {} is as expected".format(
                level, action.customName))

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

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

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

            postvs_ref = {
                0: {
                    'vtx': 0,
                    'idx': 9,
                    'gl_PerVertex_var.gl_Position': [-0.4, -0.5, 0.0, 1.0]
                },
                1: {
                    'vtx': 1,
                    'idx': 10,
                    'gl_PerVertex_var.gl_Position': [-0.3, -0.8, 0.0, 1.0]
                },
                2: {
                    'vtx': 2,
                    'idx': 11,
                    'gl_PerVertex_var.gl_Position': [-0.2, -0.8, 0.0, 1.0]
                },
                3: {
                    'vtx': 3,
                    'idx': 12,
                    'gl_PerVertex_var.gl_Position': [-0.1, -0.5, 0.0, 1.0]
                },
                4: {
                    'vtx': 4,
                    'idx': 13,
                    'gl_PerVertex_var.gl_Position': [0.0, -0.8, 0.0, 1.0]
                },
                5: {
                    'vtx': 5,
                    'idx': 14,
                    'gl_PerVertex_var.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([(140, 40), (200, 40)])

            rdtest.log.success("{} {} is as expected".format(
                level, action.customName))

            if indirect_count_root is not None:
                self.check(indirect_count_root.children[0].customName ==
                           '{}: Empty count draws'.format(level))
                self.check(indirect_count_root.children[1].customName ==
                           '{}: Indirect count draws'.format(level))

                empties = indirect_count_root.children[0]

                self.check(empties and len(real_action_children(empties)) == 3)

                action: rd.ActionDescription
                for action in real_action_children(empties.children):
                    self.check(action.numIndices == 0)
                    self.check(action.numInstances == 0)

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

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

                    self.check_overlay([], no_overlay=True)

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

                self.check(rd.ResourceUsage.Indirect in buffer_usage[
                    action_indirect.eventId])

                self.check(action_indirect
                           and len(real_action_children(action_indirect)) == 1)

                # vkCmdDrawIndirectCountKHR[0]
                action = action_indirect.children[0]

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

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

                # Check that we have PostVS as expected
                postvs_data = self.get_postvs(action, 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_var.gl_Position': [-0.8, 0.5, 0.0, 1.0]
                    },
                    1: {
                        'vtx': 1,
                        'idx': 1,
                        'gl_PerVertex_var.gl_Position': [-0.7, 0.2, 0.0, 1.0]
                    },
                    2: {
                        'vtx': 2,
                        'idx': 2,
                        'gl_PerVertex_var.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([(60, 190)])

                rdtest.log.success("{} {} is as expected".format(
                    level, action.customName))

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

                self.check(action_indirect
                           and len(real_action_children(action_indirect)) == 3)

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

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

                # Check that we have PostVS as expected
                postvs_data = self.get_postvs(action, 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': 15,
                        'gl_PerVertex_var.gl_Position': [-0.6, 0.5, 0.0, 1.0]
                    },
                    1: {
                        'vtx': 1,
                        'idx': 16,
                        'gl_PerVertex_var.gl_Position': [-0.5, 0.2, 0.0, 1.0]
                    },
                    2: {
                        'vtx': 2,
                        'idx': 17,
                        'gl_PerVertex_var.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([(100, 190)])

                rdtest.log.success("{} {} is as expected".format(
                    level, action.customName))

                # vkCmdDrawIndirectCountKHR[1]
                action = action_indirect.children[1]
                self.check(action.numIndices == 0)
                self.check(action.numInstances == 0)

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

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

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

                self.check_overlay([])

                rdtest.log.success("{} {} is as expected".format(
                    level, action.customName))

                # vkCmdDrawIndirectCountKHR[2]
                action = action_indirect.children[2]
                self.check(action.numIndices == 6)
                self.check(action.numInstances == 2)

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

                # Check that we have PostVS as expected
                postvs_data = self.get_postvs(action, 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': 18,
                        'gl_PerVertex_var.gl_Position': [-0.4, 0.5, 0.0, 1.0]
                    },
                    1: {
                        'vtx': 1,
                        'idx': 19,
                        'gl_PerVertex_var.gl_Position': [-0.3, 0.2, 0.0, 1.0]
                    },
                    2: {
                        'vtx': 2,
                        'idx': 20,
                        'gl_PerVertex_var.gl_Position': [-0.2, 0.2, 0.0, 1.0]
                    },
                    3: {
                        'vtx': 3,
                        'idx': 21,
                        'gl_PerVertex_var.gl_Position': [-0.1, 0.5, 0.0, 1.0]
                    },
                    4: {
                        'vtx': 4,
                        'idx': 22,
                        'gl_PerVertex_var.gl_Position': [0.0, 0.2, 0.0, 1.0]
                    },
                    5: {
                        'vtx': 5,
                        'idx': 23,
                        'gl_PerVertex_var.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([(140, 190), (200, 190)])

                rdtest.log.success("{} {} is as expected".format(
                    level, action.customName))

                # Now check that the draws post-count are correctly highlighted
                self.controller.SetFrameEvent(
                    self.find_action(
                        "{}: Post-count 1".format(level)).children[0].eventId,
                    False)
                self.check_overlay([(340, 40)])
                self.controller.SetFrameEvent(
                    self.find_action(
                        "{}: Post-count 2".format(level)).children[0].eventId,
                    False)
                self.check_overlay([(340, 190)])
                self.controller.SetFrameEvent(
                    self.find_action(
                        "{}: Post-count 3".format(level)).children[0].eventId,
                    False)
                self.check_overlay([(340, 115)])
            else:
                rdtest.log.print("KHR_action_indirect_count not tested")
Ejemplo n.º 30
0
    def check_capture_with_controller(self, proxy_api: str):
        self.controller: rd.ReplayController
        any_failed = False

        if proxy_api != '':
            rdtest.log.print('Running with {} local proxy'.format(proxy_api))
            self.proxied = True
        else:
            rdtest.log.print('Running on direct replay')
            self.proxied = False

        self.out: rd.ReplayOutput = self.controller.CreateOutput(
            rd.CreateHeadlessWindowingData(100, 100),
            rd.ReplayOutputType.Texture)

        for d in self.controller.GetRootActions():
            if 'slice tests' in d.customName:
                for sub in d.children:
                    if sub.flags & rd.ActionFlags.Drawcall:
                        self.controller.SetFrameEvent(sub.eventId, True)

                        pipe = self.controller.GetPipelineState()

                        tex_id = pipe.GetReadOnlyResources(
                            rd.ShaderStage.Pixel)[0].resources[0].resourceId

                        for mip in [0, 1]:
                            for sl in [16, 17, 18]:
                                expected = [0.0, 0.0, 1.0, 1.0]
                                if sl == 17:
                                    expected = [0.0, 1.0, 0.0, 1.0]

                                cur_sub = rd.Subresource(mip, sl)
                                comp_type = rd.CompType.Typeless

                                # test that pixel picking sees the right things
                                picked = self.controller.PickPixel(
                                    tex_id, 15, 15, cur_sub, comp_type)

                                if not rdtest.value_compare(
                                        picked.floatValue, expected):
                                    raise rdtest.TestFailureException(
                                        "Expected to pick {} at slice {} mip {}, got {}"
                                        .format(expected, sl, mip,
                                                picked.floatValue))

                                rdtest.log.success(
                                    'Picked pixel is correct at slice {} mip {}'
                                    .format(sl, mip))

                                # Render output texture a three scales - below 100%, 100%, above 100%
                                tex_display = rd.TextureDisplay()
                                tex_display.resourceId = tex_id
                                tex_display.subresource = cur_sub
                                tex_display.typeCast = comp_type

                                # convert the unorm values to byte values for comparison
                                expected = [
                                    int(a * 255) for a in expected[0:3]
                                ]

                                for scale in [0.9, 1.0, 1.1]:
                                    tex_display.scale = scale
                                    self.out.SetTextureDisplay(tex_display)
                                    self.out.Display()
                                    pixels: bytes = self.out.ReadbackOutputTexture(
                                    )

                                    actual = [int(a) for a in pixels[0:3]]

                                    if not rdtest.value_compare(
                                            actual, expected):
                                        raise rdtest.TestFailureException(
                                            "Expected to display {} at slice {} mip {} scale {}%, got {}"
                                            .format(expected, sl, mip,
                                                    int(scale * 100), actual))

                                    rdtest.log.success(
                                        'Displayed pixel is correct at scale {}% in slice {} mip {}'
                                        .format(int(scale * 100), sl, mip))
                    elif sub.flags & rd.ActionFlags.SetMarker:
                        rdtest.log.print(
                            'Checking {} for slice display'.format(
                                sub.customName))

                continue

            # Check each region for the tests within
            if d.flags & rd.ActionFlags.PushMarker:
                name = ''
                tests_run = 0

                failed = False

                # Iterate over actions in this region
                for sub in d.children:
                    sub: rd.ActionDescription

                    if sub.flags & rd.ActionFlags.SetMarker:
                        name = sub.customName

                    # Check this action
                    if sub.flags & rd.ActionFlags.Drawcall:
                        tests_run = tests_run + 1
                        try:
                            # Set this event as current
                            self.controller.SetFrameEvent(sub.eventId, True)

                            self.filename = (d.customName + '@' +
                                             name).replace('->', '_')

                            self.check_test(d.customName, name,
                                            Texture_Zoo.TEST_CAPTURE)
                        except rdtest.TestFailureException as ex:
                            failed = any_failed = True
                            rdtest.log.error(str(ex))

                if not failed:
                    rdtest.log.success(
                        "All {} texture tests for {} are OK".format(
                            tests_run, d.customName))

        self.out.Shutdown()
        self.out = None

        if not any_failed:
            if proxy_api != '':
                rdtest.log.success(
                    'All textures are OK with {} as local proxy'.format(
                        proxy_api))
            else:
                rdtest.log.success("All textures are OK on direct replay")
        else:
            raise rdtest.TestFailureException(
                "Some tests were not as expected")