Files
mandy/tests/test_cs_wave_probe_spv.py
Jolymmiles 777d218770 vk_compute_test: run 32-lane tests where the size is fixed but not requirable (MoltenVK)
MoltenVK reports subgroups 4..32 and requiredSubgroupSizeStages 0, so VKC_SUBGROUP_SIZE=32 printed "not available"
and the 32-lane compute tests skipped. The translator emits SPIR-V 1.5, where varying subgroup sizes are not allowed,
so Vulkan fixes SubgroupSize at the device's subgroupSize (32 there). vk_compute_test now runs a probe shader
(cs_wave_probe.comp, embedded) with the test's local size and flags first, checks every invocation's lane, subgroup
number and ballot width, and runs the test if they match. If they don't, the test fails (exit 1) instead of being
skipped. Full subgroups are requested where local size X is a multiple of maxSubgroupSize. Devices whose default
isn't the requested size keep printing "not available".
2026-11-23 00:04:20 +04:00

48 lines
2.0 KiB
Python

"""runtime/test/cs_wave_probe_spv.h is the SPIR-V of runtime/test/glsl/cs_wave_probe.comp (vk_compute_test's
subgroup probe). Run: python -I tests/test_cs_wave_probe_spv.py"""
import os
import re
import shutil
import struct
import subprocess
import tempfile
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
HEADER = os.path.join(ROOT, "runtime", "test", "cs_wave_probe_spv.h")
SOURCE = os.path.join(ROOT, "runtime", "test", "glsl", "cs_wave_probe.comp")
def header_words():
with open(HEADER, encoding="utf-8") as f:
return [int(x, 16) for x in re.findall(r"0x([0-9a-f]{8})u", f.read())]
class WaveProbeSpirv(unittest.TestCase):
def test_header_is_spirv_1_5(self):
# Below 1.6, so varying subgroup sizes are not allowed in the probe either (as in the translator's output).
w = header_words()
self.assertEqual(w[0], 0x07230203)
self.assertEqual(w[1], 0x00010500)
def test_header_matches_the_glsl(self):
glslang = shutil.which("glslangValidator")
if not glslang:
self.skipTest("glslangValidator is not on PATH")
version = subprocess.run([glslang, "--version"], capture_output=True, text=True).stdout
if "16.6.0" not in version: # another glslang may emit other (equally valid) code
self.skipTest("the header was generated with glslang 16.6.0")
with tempfile.TemporaryDirectory() as tmp:
out = os.path.join(tmp, "cs_wave_probe.spv")
subprocess.run([glslang, "-V", "--target-env", "vulkan1.2", "-Os", "-o", out, SOURCE], check=True,
stdout=subprocess.DEVNULL)
with open(out, "rb") as f:
data = f.read()
words = list(struct.unpack(f"<{len(data) // 4}I", data))
# Word 2 is the generator (glslang's version); the rest must be what the header holds.
self.assertEqual(words[:2] + words[3:], header_words()[:2] + header_words()[3:])
if __name__ == "__main__":
unittest.main()