mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-16 02:35:49 +00:00
* These come from long ago when using PyCharm with not as good type checking and with renderdoc module stubs that were incomplete so needed help identifying types.
164 lines
6.0 KiB
Python
164 lines
6.0 KiB
Python
import renderdoc as rd
|
|
import rdtest
|
|
|
|
|
|
# Not a direct test, re-used by API-specific tests
|
|
class Buffer_Truncation(rdtest.TestCase):
|
|
internal = True
|
|
draw_action = None
|
|
|
|
def check_capture(self):
|
|
action = self.draw_action
|
|
if action is None:
|
|
action = self.find_action("Draw")
|
|
|
|
assert action is not None
|
|
|
|
self.controller.SetFrameEvent(action.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(action))
|
|
|
|
postvs_data = self.get_postvs(action, rd.MeshDataStage.VSOut, 0, action.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 = self.controller.GetPipelineState()
|
|
|
|
stage = rd.ShaderStage.Pixel
|
|
|
|
cbuf = pipe.GetConstantBlock(stage, 0, 0).descriptor
|
|
|
|
if self.find_action('NoCBufferRange') == None:
|
|
assert cbuf.byteSize == 256
|
|
|
|
variables = self.controller.GetCBufferVariableContents(pipe.GetGraphicsPipelineObject(),
|
|
pipe.GetShader(stage), stage,
|
|
pipe.GetShaderEntryPoint(stage), 0,
|
|
cbuf.resource, cbuf.byteOffset, cbuf.byteSize)
|
|
|
|
outcol = variables[1]
|
|
|
|
assert 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 = self.controller.DebugPixel(
|
|
int(pipe.GetViewport(0).width / 2),
|
|
int(pipe.GetViewport(0).height / 2),
|
|
rd.DebugPixelInputs(),
|
|
)
|
|
|
|
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]
|
|
|
|
assert debugged_cb.members[0].name == 'padding'
|
|
assert 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]
|
|
|
|
assert all(['consts.padding[' in c.name for c in cbuf_sourceVars[0:16]])
|
|
assert cbuf_sourceVars[16].name == 'consts.outcol'
|
|
|
|
assert cbuf_sourceVars[16].variables[0].name == 'cb0[16]' or cbuf_sourceVars[16].variables[0].name == 'consts[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")
|