Skip to content

Commit

Permalink
Update to show everything reported by bug report. Note that "indexed"…
Browse files Browse the repository at this point in the history
… works when we do the bug_patch, but not otherwise.
  • Loading branch information
fyellin committed Sep 20, 2024
1 parent 021241e commit 2bd5408
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions tests/test_wgpu_vertex_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def __init__(self):
# The zeros at the end are because the _count methods require to buffer to
# be at least byte_offset + 16 * max_count bytes long
data=np.uint32([0, 0, *self.draw_args1, *self.draw_args2, *([0] * 50)]),
usage="INDIRECT",
usage="INDIRECT", # copy dst for patching
)
self.draw_data_buffer_indexed = self.device.create_buffer_with_data(
# The zeros at the beginning are to test "offset".
Expand All @@ -182,6 +182,26 @@ def __init__(self):
usage="INDIRECT",
)

self.count_buffer = self.device.create_buffer_with_data(
data=(np.int32([10, 2])), usage="INDIRECT"
)
self.draw_data_buffer_patched = self.device.create_buffer_with_data(
# The zeros at the beginning are to test the "offset".
# The zeros at the end are because the _count methods require to buffer to
# be at least byte_offset + 16 * max_count bytes long
data=np.uint32([10, 2, *self.draw_args1, *self.draw_args2, *([0] * 50)]),
usage="INDIRECT", # copy dst for patching
)
self.draw_data_buffer_indexed_patched = self.device.create_buffer_with_data(
# The zeros at the beginning are to test "offset".
# The zeros at the end are because the _count methods require to buffer to
# be at least byte_offset + 20 * max_count bytes long
data=np.uint32(
[10, 2, *self.draw_indexed_args1, *self.draw_indexed_args2, *([0] * 50)]
),
usage="INDIRECT",
)

# And let's not forget our index buffer.
self.index_buffer = self.device.create_buffer_with_data(
data=(np.uint32(indices)), usage="INDEX"
Expand Down Expand Up @@ -223,7 +243,7 @@ def run_draw_test(self, draw_function, indexed, *, expected_result=None):
else:
expected_result = self.expected_result_draw
if info_set != expected_result:
pytest.fail(f"Expected {sorted(info_set)}\nGot {sorted(expected_result)}")
pytest.fail(f"Expected {sorted(expected_result)}\nGot {sorted(info_set)}")


if not Runner.is_usable():
Expand Down Expand Up @@ -349,24 +369,30 @@ def draw(encoder):
)


@pytest.mark.parametrize("bug_patch", [False, True])
@pytest.mark.parametrize("indexed", [False, True])
@pytest.mark.parametrize("test_max_count", [False, True])
def test_multi_draw_indirect_count(runner, test_max_count, indexed):
def test_multi_draw_indirect_count(runner, test_max_count, indexed, bug_patch):
if "multi-draw-indirect-count" not in runner.device.features:
pytest.skip("Must have 'multi-draw-indirect-count' to run")

print(f"{test_max_count=}, {indexed=} \n")
print(f"{bug_patch=}, {indexed=}, {test_max_count=} \n")

count_buffer = runner.device.create_buffer_with_data(
data=(np.int32([10, 2])), usage="INDIRECT"
)
if indexed:
function = multi_draw_indexed_indirect_count
buffer = runner.draw_data_buffer_indexed
if not bug_patch:
buffer = runner.draw_data_buffer_indexed
else:
buffer = runner.draw_data_buffer_indexed_patched
else:
function = multi_draw_indirect_count
buffer = runner.draw_data_buffer
if not bug_patch:
buffer = runner.draw_data_buffer
else:
buffer = runner.draw_data_buffer_patched

# Either way, we're going to do 2 draws. But one via the max_count and one via the
# information in the buffer.
if test_max_count:
# We pull a count of 10, but we're limiting it to 2 via max_count
count_buffer_offset, max_count = 0, 2
Expand All @@ -380,7 +406,7 @@ def draw(encoder):
encoder,
buffer,
offset=8,
count_buffer=count_buffer,
count_buffer=runner.count_buffer,
count_buffer_offset=count_buffer_offset,
max_count=max_count,
)
Expand Down

0 comments on commit 2bd5408

Please sign in to comment.