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
|
import struct
import math
import renderdoc as rd
import rdtest
class GL_Parameter_Zoo(rdtest.TestCase):
demos_test_name = 'GL_Parameter_Zoo'
demos_frame_cap = 6
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(draw, rd.MeshDataStage.VSOut, 0, draw.numIndices)
postvs_ref = {
0: {
'vtx': 0,
'idx': 0,
'gl_Position': [-0.5, -0.5, 0.0, 1.0],
'v2fcol': [0.0, 1.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, 1.0, 0.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")
|