mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-11-13 09:20:13 +00:00
90 lines
3.8 KiB
Python
90 lines
3.8 KiB
Python
from __future__ import annotations
|
|
import renderdoc as rd
|
|
import rdtest
|
|
|
|
|
|
class D3D11_PrimitiveID(rdtest.TestCase):
|
|
demos_test_name = 'D3D11_PrimitiveID'
|
|
|
|
def test_action(
|
|
self,
|
|
action: rd.ActionDescription,
|
|
x: int,
|
|
y: int,
|
|
prim: int,
|
|
expected_prim: rdtest.VectorValue,
|
|
expected_output: rdtest.VectorValue | None,
|
|
):
|
|
self.set_event(action.eventId, True)
|
|
pipe = self.controller.GetPipelineState()
|
|
|
|
pixel_inputs = rd.DebugPixelInputs()
|
|
pixel_inputs.primitive = prim
|
|
with self.debug_pixel(x, y, pixel_inputs) as debug:
|
|
_, variables = self.process_trace(debug.trace)
|
|
|
|
# Find the SV_PrimitiveID variable
|
|
if not self.has_input_source_var(debug.trace, rd.ShaderBuiltin.PrimitiveIndex):
|
|
# If we didn't find it, then we should be expecting a 0
|
|
if len(expected_prim) != 1 or expected_prim[0] != 0:
|
|
rdtest.log.error(f"Expected prim {expected_prim!s} at {x},{y} did not match actual prim {prim}.")
|
|
return False
|
|
else:
|
|
primInput = self.find_input_source_var(debug.trace, rd.ShaderBuiltin.PrimitiveIndex)
|
|
|
|
# Look up the matching register in the inputs, and see if the expected value matches
|
|
inputs = list(debug.trace.inputs)
|
|
primValue = [var for var in inputs if var.name == primInput.variables[0].name][0]
|
|
if primValue.value.u32v[0] not in expected_prim:
|
|
rdtest.log.error(f"Expected prim {expected_prim!s} at {x},{y} did not match actual prim {primValue.value.u32v[0]}.")
|
|
return False
|
|
|
|
# Compare shader debug output against an expected value instead of the RT's output,
|
|
# since we're testing overlapping primitives in a single action
|
|
if expected_output is not None:
|
|
output = self.find_output_source_var(debug.trace, rd.ShaderBuiltin.ColorOutput, 0)
|
|
|
|
debugged = self.evaluate_source_var(output, variables)
|
|
if list(debugged.value.f32v[0:4]) != expected_output:
|
|
rdtest.log.error(f"Expected value {expected_output} at {x},{y} did not match actual {debugged.value.f32v[0:4]}.")
|
|
return False
|
|
|
|
rdtest.log.success(f"Test at {x},{y} matched as expected")
|
|
return True
|
|
|
|
def check_capture(self):
|
|
success = True
|
|
|
|
# Jump to the action
|
|
test_marker = self.find_action("Test")
|
|
|
|
assert test_marker is not None
|
|
|
|
# Draw 1: No GS, PS without prim
|
|
action = test_marker.nextAction
|
|
assert action is not None
|
|
success &= self.test_action(action, 100, 80, rd.ReplayController.NoPreference, [0], [0, 1, 0, 1])
|
|
|
|
# Draw 2: No GS, PS with prim
|
|
action = action.nextAction
|
|
assert action is not None
|
|
success &= self.test_action(action, 300, 80, rd.ReplayController.NoPreference, [0], [0, 1, 0, 1])
|
|
|
|
# Draw 3: GS, PS without prim
|
|
action = action.nextAction
|
|
assert action is not None
|
|
success &= self.test_action(action, 125, 250, rd.ReplayController.NoPreference, [0], [0, 1, 0, 1])
|
|
|
|
# Draw 4: GS, PS with prim
|
|
action = action.nextAction
|
|
assert action is not None
|
|
success &= self.test_action(action, 325, 250, 2, [2], [0.5, 1, 0, 1])
|
|
success &= self.test_action(action, 325, 250, 3, [3], [0.75, 1, 0, 1])
|
|
# No expected output here, since it's nondeterministic which primitive gets selected
|
|
success &= self.test_action(action, 325, 250, rd.ReplayController.NoPreference, [2, 3], None)
|
|
|
|
if not success:
|
|
raise rdtest.TestFailureException("Some tests were not as expected")
|
|
|
|
rdtest.log.success("All tests matched")
|