mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 13:48:36 +00:00
#2230 bounds a dispatch record by the device's maxComputeWorkGroupCount instead of 65 535. Nothing said how wide the title's dispatches are, nor when a device's own limit still cuts one (llvmpipe allows 65 535 in x; RADV 2^32 - 1), which its review asked for. The title's tile passes ask for 67 440 groups in x at 2560x1440 (found in the VIctory-Belobug-AMD fork of VIctory, crates/victory-gpu/src/indirect.rs; no code of it is used). - indirect_clamp.comp: stats words 12-15 count dispatch records that run wider than 65 535 groups in x, the widest x that runs, those cut at the device's limits (and still running), and all of them. - vulkan_indirect_clamp.h: the counters, read with the others (16 words a slot, words 8-15 zeroed before the pass), and a line every 10 s while dispatch records are clamped: `indirect clamp dispatch: N records, W wider than 65535 groups in x, widest x X, C cut at the device's limits (x x y x z)`. - indirect_clamp_spv.h regenerated from the .comp as its header says (glslangValidator 16.6.0). - docs/d3d12_vulkan.md section 4.7: the device's bound per dimension (it still said 65 535), the line, and the test. Tests: indirect_clamp_test's cases 6b and 6c check the counters (70 000 x 1 x 1: wider than 65 535 where the device runs it, cut at its limit and counted where not). tests/test_indirect_clamp_telemetry.py checks the new atomics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
"""Check the pre-clamp counters in the runtime's embedded shader without a Vulkan device or SDK.
|
|
|
|
Regenerate the binary from runtime/src with:
|
|
glslangValidator -V --target-env vulkan1.2 -Os --spirv-val -o indirect_clamp.spv indirect_clamp.comp
|
|
indirect_clamp_spv.h stores those bytes as little-endian uint32_t words, eight per line.
|
|
"""
|
|
from pathlib import Path
|
|
import re
|
|
import unittest
|
|
|
|
|
|
def mesh_counter_ops(header):
|
|
# Follow the SPIR-V pointer for each counter atomic: load push.stats, then access Stats.data[word].
|
|
# push.list_budget uses the same Stats type but is a different member; never count its atomics here.
|
|
words = [int(w, 16) for w in re.findall(r"0x([0-9a-fA-F]+)u", header)]
|
|
if len(words) < 5 or words[0] != 0x07230203:
|
|
raise ValueError("invalid SPIR-V header")
|
|
constants, loads, chains, push = {}, {}, {}, set()
|
|
found = set()
|
|
i = 5
|
|
while i < len(words):
|
|
length, op = words[i] >> 16, words[i] & 0xffff
|
|
if not length or i + length > len(words):
|
|
raise ValueError("invalid SPIR-V instruction")
|
|
a = words[i + 1:i + length]
|
|
i += length
|
|
if op == 43: # OpConstant
|
|
constants[a[1]] = a[2]
|
|
elif op == 59 and a[2] == 9: # OpVariable, PushConstant
|
|
push.add(a[1])
|
|
elif op == 61: # OpLoad
|
|
loads[a[1]] = a[2]
|
|
elif op == 65: # OpAccessChain
|
|
chains[a[1]] = a[2:]
|
|
elif op in (234, 239): # OpAtomicIAdd, OpAtomicUMax
|
|
dst = chains.get(a[2], [])
|
|
if len(dst) != 3 or constants.get(dst[1]) != 0:
|
|
continue
|
|
member = chains.get(loads.get(dst[0]), [])
|
|
if len(member) == 2 and member[0] in push and constants.get(member[1]) == 4:
|
|
word = constants[dst[2]]
|
|
if word >= 8:
|
|
found.add((word, op))
|
|
return found
|
|
|
|
|
|
class TestIndirectClampTelemetry(unittest.TestCase):
|
|
def test_embedded_preclamp_mesh_counters(self):
|
|
src = Path(__file__).resolve().parents[1] / "runtime" / "src"
|
|
# Active mesh records + records requesting y/z > 1; max y and max z before clamping. Then the dispatch
|
|
# records: wider than 65 535 groups in x, the widest x, cut at the device's limits, and all of them.
|
|
self.assertEqual(mesh_counter_ops((src / "indirect_clamp_spv.h").read_text(encoding="ascii")),
|
|
{(8, 234), (9, 234), (10, 239), (11, 239), (12, 234), (13, 239), (14, 234), (15, 234)})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|