File: Discard_Zoo.py

package info (click to toggle)
renderdoc 1.11%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 93,988 kB
  • sloc: cpp: 662,188; ansic: 350,046; python: 22,871; xml: 14,473; java: 11,365; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; sh: 2,277; php: 2,119; lisp: 1,835; javascript: 1,524; tcl: 1,068; ml: 747
file content (210 lines) | stat: -rw-r--r-- 9,852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import renderdoc as rd
import rdtest

# Not a real test, re-used by API-specific tests
class Discard_Zoo(rdtest.TestCase):
    internal = True

    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])

    def check_texture(self, id, discarded: bool):
        tex: rd.TextureDescription = self.get_texture(id)
        res: rd.ResourceDescription = self.get_resource(id)

        fmt: rd.ResourceFormat = tex.format

        props: rd.APIProperties = self.controller.GetAPIProperties()
        gl = (props.pipelineType == rd.GraphicsAPI.OpenGL)

        name = '{} - {}x{} {} mip {} slice {}x MSAA {} format texture'.format(res.name, tex.width, tex.height,
                                                                              tex.mips, tex.arraysize,
                                                                              tex.msSamp, tex.format.Name())

        minval = 0.0
        maxval = 1000.0

        if fmt.type == rd.ResourceFormatType.R9G9B9E5:
            maxval = 998.0
        elif fmt.type == rd.ResourceFormatType.BC6:
            maxval = 996.0
        elif fmt.type == rd.ResourceFormatType.R10G10B10A2 and fmt.compType == rd.CompType.UInt:
            maxval = [1023.0, 1023.0, 1023.0, 3.0]
        elif fmt.type in [rd.ResourceFormatType.D16S8, rd.ResourceFormatType.D24S8, rd.ResourceFormatType.D32S8]:
            maxval = 1.0
            fmt.compCount = 2

            if "DepthOnly" in res.name:
                minval = [minval, float(0x40)/float(255)]
                maxval = [maxval, float(0x40)/float(255)]
            elif "StencilOnly" in res.name:
                minval = [0.4, minval]
                maxval = [0.4, maxval]
        elif fmt.type == rd.ResourceFormatType.S8:
            minval = [0.0, 0.0]
            maxval = [0.0, 1.0]
            fmt.compCount = 2
        elif fmt.compType == rd.CompType.UNorm or fmt.compType == rd.CompType.Depth:
            maxval = 1.0

        # ignore alpha in BC1 and BC6
        if fmt.type == rd.ResourceFormatType.BC1 or fmt.type == rd.ResourceFormatType.BC6:
            fmt.compCount = 3

        for mip in range(tex.mips):
            for slice in range(tex.arraysize):
                for samp in range(tex.msSamp):
                    sub = rd.Subresource(mip, slice, samp)

                    sub_discarded = discarded

                    if "Mip" in res.name:
                        idx = res.name.index('Mip')+3
                        try:
                            idx2 = res.name.index(' ', idx)
                        except ValueError:
                            idx2 = len(res.name)
                        if mip not in [int(m) for m in res.name[idx:idx2].split(',')]:
                            sub_discarded = False

                    if "Slice" in res.name:
                        idx = res.name.index('Slice') + 5
                        try:
                            idx2 = res.name.index(' ', idx)
                        except ValueError:
                            idx2 = len(res.name)
                        if slice not in [int(s) for s in res.name[idx:idx2].split(',')]:
                            sub_discarded = False

                    if "NoDiscard" in res.name:
                        sub_discarded = False

                    w = max(1, tex.width >> mip)
                    h = max(1, tex.height >> mip)

                    if not sub_discarded or "DiscardRect" in res.name:
                        # if not discarded, or we only discarded a rect, check a few locations in the corners and ensure
                        # that we don't see our pattern colours.
                        for (x, y) in [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (1, 1), (2, 2), (3, 3),
                                       (4, 4), (w - 1, h - 1), (w - 2, h - 2), (w - 1, 0), (w - 1, 1), (w - 1, 2),
                                       (0, h - 1), (1, h - 1), (2, h - 1), (3, h - 2)]:
                            # underflow can happen with 1D textures or tiny mips
                            if x < 0:
                                x = 0
                            if y < 0:
                                y = 0

                            if gl and h > 1:
                                y = h - 1 - y

                            picked: rd.PixelValue = self.controller.PickPixel(id, x, y, sub, rd.CompType.Typeless)

                            if self.check_val(picked, minval, fmt) or self.check_val(picked, maxval, fmt):
                                raise rdtest.TestFailureException(
                                    '{} has unexpected value at {},{}: {}'.format(name, x, y,
                                                                                  picked.floatValue))

                    if sub_discarded:
                        seen = [False, False]
                        # Check that pixels inside the rect only show our pattern colours (we don't check the actual
                        # pattern)
                        for (x, y) in [(50, 50), (51, 50), (52, 50), (53, 50), (54, 50), (55, 50), (51, 52), (120, 123),
                                       (124, 124), (119, 122), (119, 124), (122, 124), (70, 70), (80, 85), (73, 124),
                                       (123, 60)]:
                            # overflow can happen with 1D textures or tiny mips
                            if x >= w:
                                x = w-1
                            if y >= h:
                                y = h-1

                            if gl and h > 1:
                                y = h - 1 - y

                            picked: rd.PixelValue = self.controller.PickPixel(id, x, y, sub, rd.CompType.Typeless)

                            is_min = self.check_val(picked, minval, fmt)
                            is_max = self.check_val(picked, maxval, fmt)

                            if not is_min and not is_max:
                                raise rdtest.TestFailureException(
                                    '{} has unexpected value at {},{}: {}'.format(name, x, y,
                                                                                  picked.floatValue))

                            if is_min:
                                seen[0] = True
                            if is_max:
                                seen[1] = True

                        # Do an additional checks outside the rect
                        if "DiscardRect" not in res.name:
                            for (x, y) in [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (1, 1), (2, 2), (3, 3),
                                           (4, 4), (w - 1, h - 1), (w - 2, h - 2), (w - 1, 0), (w - 1, 1), (w - 1, 2),
                                           (0, h - 1), (1, h - 1), (2, h - 1), (3, h - 2)]:
                                # underflow can happen with 1D textures or tiny mips
                                if x < 0:
                                    x = 0
                                if y < 0:
                                    y = 0

                                if gl and h > 1:
                                    y = h - 1 - y

                                picked: rd.PixelValue = self.controller.PickPixel(id, x, y, sub, rd.CompType.Typeless)

                                is_min = self.check_val(picked, minval, fmt)
                                is_max = self.check_val(picked, maxval, fmt)

                                if not is_min and not is_max:
                                    raise rdtest.TestFailureException(
                                        '{} has unexpected value at {},{}: {}'.format(name, x, y,
                                                                                      picked.floatValue))

                                if is_min:
                                    seen[0] = True
                                if is_max:
                                    seen[1] = True

                        # We also expect to have seen both colours. That means if we only saw black for example then we
                        # fail
                        if not seen[0] or not seen[1]:
                            raise rdtest.TestFailureException('{} doesn\'t contain expected pattern'.format(name))

        rdtest.log.success('{} is OK {} discarding'.format(name, "after" if discarded else "before"))

    def check_textures(self):
        draw = self.find_draw("TestStart")

        self.check(draw is not None)

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

        for tex in self.controller.GetTextures():
            tex: rd.TextureDescription
            res: rd.ResourceDescription = self.get_resource(tex.resourceId)

            if "Discard" in res.name:
                self.check_texture(tex.resourceId, False)

        draw = self.find_draw("TestEnd")

        self.check(draw is not None)

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

        for tex in self.controller.GetTextures():
            tex: rd.TextureDescription
            res: rd.ResourceDescription = self.get_resource(tex.resourceId)

            if "Discard" in res.name:
                self.check_texture(tex.resourceId, True)