From 0d27fdcf9a1e511bad33247b9753f3d3fa78d326 Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:10:08 -0600 Subject: [PATCH] GPU fixture cs_imgstore_cube: image_store on dim:SQ_RSRC_IMG_CUBE (GPU-CUBE-STORE) The "Typed image stores" contract row said a cube storage image was CPU-checked only (test_image_cube_store_glc.py) and that no GPU fixture covered it. This adds one: - runtime/test/shaders/cs_imgstore_cube.asm: rgba8 unorm, r32 uint and r32 sint T#s (word3 TYPE = SQ_RSRC_IMG_CUBE); 64 threads store to every texel of all six faces, with per-face values so a wrong layer shows. - vk_store_test "cube": three cube-compatible 8x8 six-layer images bound as six-layer 2D-array storage views at bindings 11/12/13, as the runtime binds a cube UAV; checks every texel of every layer. - run_gpu_tests.py and check.py run it; test_shader_checks.py counts it. - docs/design.md: the row names the fixture and the GPUs it passes on. Builds on #44, which rewrote that row. Passes on an RTX 4070 Ti (NVIDIA 620.70.06) and a Radeon 610M (gfx1036, RADV Mesa 26.2.6), native and LEONIDA_W64_EMULATE=1. The same fixture with the face held at 0 fails on both (320/384/384 bad texels). AI-assisted. No game files. Co-Authored-By: Claude Opus 5.5 --- docs/design.md | 2 +- runtime/test/shaders/check.py | 3 +- runtime/test/shaders/cs_imgstore_cube.asm | 95 +++++++++++++++++++ runtime/test/vk_store_test.cpp | 110 ++++++++++++++++++++-- scripts/run_gpu_tests.py | 3 + tests/test_shader_checks.py | 8 +- 6 files changed, 207 insertions(+), 14 deletions(-) create mode 100644 runtime/test/shaders/cs_imgstore_cube.asm diff --git a/docs/design.md b/docs/design.md index cec315722b..88bb5160bc 100644 --- a/docs/design.md +++ b/docs/design.md @@ -414,7 +414,7 @@ How the generated SPIR-V expects the runtime to work: | `ds_bpermute_b32` subgroup convergence | Native wave32 and wave64 apply bitwise masks to the shuffle result and the destination write so both the ballot and shuffle execute before lane predication. If the ballot has no source lane, the shuffle reads the calling lane before the result is masked to zero. MoltenVK 1.4.2 lowered the scalar selects to nested Metal ternaries, placing the subgroup operations in divergent control flow. The `cs_bpermute32` inactive-source case returned 64 on an Apple M1 Max, and all eight fixture words match with bitwise masking. | | LDS 2-address b64 (`ds_read2_b64`, `ds_write2_b64`, `ds_read2st64_b64`, `ds_write2st64_b64`) | Two elements at vaddr + offset0·unit and vaddr + offset1·unit, unit = 8 bytes (×64 for st64); each element is two consecutive dwords, low first. `read2_b64` fills v[d:d+3] after all four loads (a vdst overlapping vaddr is safe); `write2_b64` takes two VGPR pairs. The b32 forms share the code with unit 4. Source: RDNA2 ISA DS 2-address forms. CPU-checked by `tests/semantic/test_lds_read2_write2_b64.py` (compute listings, LDS as a Workgroup variable); GPU-checked by `runtime/test/shaders/cs_lds_b64_cmpst.asm` (unit 8 and the 512-byte st64 forms, plus vdst/vaddr overlap, on an RTX 3070, driver 621.01, Windows 11; the same eight words also on an AMD RX 7600 (`gfx1102`) and a Ryzen 5 9600X iGPU (`gfx1036`, RDNA2, RADV Mesa 27.0.0-devel)). | | Compute workgroup IDs Y/Z | With four user SGPRs and only TGID_Y and TGID_Z enabled (RSRC2 `0x308`), s4 receives Y and s5 receives Z. The synthetic `cs_workgroup_yz.asm` fixture checks a 2 × 3 × 4 dispatch and each of its 24 origins against a CPU reference. | -| Typed image stores | `image_store` (2D, 2D array, 3D, cube) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. A cube storage image is bound as a six-layer 2D array (bindings 11/12/13 for float/uint/sint, `OpTypeImage ... 2D 0 1 0 2 Unknown`, `%v3int` coordinates (x, y, face)); `tfe` and `lwe` are refused. CPU-checked by `tests/semantic/test_image_cube_store_glc.py`; **not GPU-verified**: no GPU fixture covers a cube store yet. | +| Typed image stores | `image_store` (2D, 2D array, 3D, cube) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. A cube storage image is bound as a six-layer 2D array (bindings 11/12/13 for float/uint/sint, `OpTypeImage ... 2D 0 1 0 2 Unknown`, `%v3int` coordinates (x, y, face)); `tfe` and `lwe` are refused. CPU-checked by `tests/semantic/test_image_cube_store_glc.py`. GPU-checked with `runtime/test/shaders/cs_imgstore_cube.asm` through `vk_store_test cube` (GPU-CUBE-STORE): rgba8 unorm, r32 uint and r32 sint cube images, each a cube-compatible 8x8 image of six layers bound through a six-layer 2D-array view at index 1-3 of bindings 11/12/13, and every texel of every face exact (the face selects the layer) on an RTX 4070 Ti (NVIDIA 620.70.06, Linux) and a Radeon 610M (`gfx1036`, RDNA2, RADV Mesa 26.2.6), natively and under `LEONIDA_W64_EMULATE=1`; the same fixture with the face held at 0 fails on both. | | Typed image loads | A noncoherent cube `image_load` reads the 2D-array sampled binding (3) with integer coordinates and layer. Its T# format selects the float, uint or sint alias, including for D16. The [RDNA2 ISA §8.2.1](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) assigns D16 conversion to the image format. The synthetic `cube_load_d16.asm` checks the generated views and format choices on the CPU. `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores, and fetches every format with `OpImageFetch` from the sampled array of its dimension (bindings 0, 3, 6, 5): UINT/SINT formats through **uint/sint aliases of that array** (same set and binding, an `OpTypeImage` of `%uint`/`%int`; Vulkan allows several variables on one binding when the descriptor type fits), everything else through the float array. A lookup miss (index 0) takes the float path, since the fallback there is RGBA8_UNORM. Results are the raw bits of the dmask components. **The runtime binds each image's view in its own format at its index of the sampled array** (what `bind_image` in `runtime/shims/d3d12_vulkan_device.cpp` already does for SRVs and UAVs), so the view's numeric type matches the alias that reads it. No storage image is read, so shaders that only load need neither `shaderStorageImageReadWithoutFormat` (missing on Intel Xe-LP, #619) nor `shaderStorageImageWriteWithoutFormat` (SHADER-151). Until 2026-11-22 integer formats were read with `OpImageRead` from the uint/sint storage arrays (bindings 8–19), which hold only unordered-access views and 256 entries: a read-only integer texture found the fallback there, or an index past the array's end. Like the float path, the fetch goes through the texture path, so it sees writes made before the dispatch, not ones made earlier in the same dispatch. **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, the low 16 bits of each value from the uint/sint aliases (truncated). **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, each value from the uint/sint aliases saturated to the 16-bit range of its signedness (`saturate_int16`). For odd component counts (1 or 3 in `dmask`), the trailing destination VGPR preserves its existing high 16 bits (`write_lo16`), matching native `gfx1036` hardware where a seeded `0x5a5a` high half survived 1-component UINT/SINT `image_load` and `image_load_mip`; until 2026-11-22 the unused high half was zeroed. Before #1136, a d16 load always read the float view, so a `Texture2D` `Load` returned garbage. CPU-checked by `tests/test_image_load_typed.py` (capabilities, bindings and component types for every dimension; the branch for all 512 FORMAT values, found and missed). GPU-checked with `runtime/test/shaders/cs_imgload.asm` through `vk_store_test load`, on a device made without `shaderStorageImageReadWithoutFormat`: r32 uint and r32 sint images filled before the dispatch, both read with `image_load` and their sum stored, every texel exact on an RTX 2080 Ti (NVIDIA 621.14, Windows 11), clean under the validation layer with GPU-assisted validation; the test fails a module that declares `StorageImageReadWithoutFormat`. d16: CPU-checked by `tests/test_image_load_d16_typed.py` (the uint/sint fetches go through the aliases, no storage image is read, the SPIR-V validates); GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070, and `cs_imgload_d16` passes unchanged on an AMD RX 7600 (gfx1102, RADV Mesa 27.0.0-devel) in `run_gpu_tests.py`). GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070). 2D `image_load_mip` uses the same numeric-type selection and passes the address register's mip to each fetch. Its D16 form packs the selected components in ascending order, two per VGPR. An RGBA8 two-level texture was checked on RTX 5080 and Radeon Graphics: all four exported halves matched the CPU reference for UINT, SINT and UNORM, and forcing level 0 changed every pixel. Checked on RTX 5080 and Radeon Graphics with R8G8B8A8 UINT, SINT and UNORM textures: level 1 matched the CPU reference at every pixel with GPU-assisted validation, and forcing level 0 changed all 4096 pixels for each format. Native gfx1036 saturated 32-bit UINT/SINT texels to the unsigned/signed 16-bit range in both D16 load forms; the translated 2D load matched both limits on RTX 5080 and Radeon Graphics. Native gfx1036 does the same on every dimension (SHADER-387, `tools/image_d16_probe.py`): 32_UINT and 32_32_UINT texels saturate to [0, 0xffff] and 32_SINT and 32_32_SINT texels to [-32768, 32767], never truncate, in 1D, 2D, 2D-array and 3D images, through `image_load` and `image_load_mip` alike; two-channel results pack x low and y high, and a one-channel result keeps the seeded high half. The translated d16 loads on 1D, 2D-array and 3D images still lack GPU checks. | | Packed 2D mip-load addresses | For `image_load_mip` with `a16`, the first VGPR holds unsigned X (low half) and Y (high half). The low half of the second VGPR selects the mip and its high half is unused. Both ordinary and D16 results use the same address. LLVM gfx1030 assembles both forms in `tests/semantic/fixtures/packed_mip_load_2d.asm`. `tests/test_image_load_typed.py` checks the texel and mip operands of the float, UINT and SINT fetches, including noncontiguous address registers. [AMD RDNA 2 ISA, MIMG A16 field](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) | | 3D explicit-mip loads | `image_load_mip` reads x, y, z and mip from four address VGPRs. T# FORMAT selects the float, UINT or SINT 3D sampled view at binding 6. D16 narrows the selected components before packing them low half first. The unit test `test_volume_mip_fetch_uses_xyz_level_and_descriptor_type` in `tests/test_image_load_typed.py` checks the four address registers and the RGBA32 format selection on the translated module. Native gfx1036 measured UINT and SINT saturation for 3D `image_load_mip` at mip zero. [Volume load measurements](https://github.com/ItsNotRexed/Leonida/pull/2217) | diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 7b37772874..3a7088e97b 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -1857,7 +1857,8 @@ def main(): results.append(("ms_wave_info_s3", mesh_w64x_test(tools, spirv, "ms_wave_info_s3"))) with tempfile.TemporaryDirectory(prefix="leonida-mesh-") as tmp: results.append(("ms_v5_workgroup", mesh_v5_test(tools, spirv, Path(tmp) / "groups.raw"))) - for name, args in (("cs_imgstore", []), ("cs_imgload", ["load"]), ("cs_imgload_tfe", ["load"]), + for name, args in (("cs_imgstore", []), ("cs_imgstore_cube", ["cube"]), ("cs_imgload", ["load"]), + ("cs_imgload_tfe", ["load"]), ("cs_imgload_d16", ["load-d16"]), ("cs_imgload_d16_tfe", ["load-d16"]), ("cs_sample_lz_int_d16", ["load-d16"])): code, out = run(os.path.join(tools, "vk_store_test" + EXE), os.path.join(spirv, name + ".spv"), *args) diff --git a/runtime/test/shaders/cs_imgstore_cube.asm b/runtime/test/shaders/cs_imgstore_cube.asm new file mode 100644 index 0000000000..9763e233f6 --- /dev/null +++ b/runtime/test/shaders/cs_imgstore_cube.asm @@ -0,0 +1,95 @@ +; Typed image_store on dim:SQ_RSRC_IMG_CUBE (GPU-CUBE-STORE): three T#s built in SGPRs (FORMAT 56 rgba8 unorm, 20 r32 +; uint, 21 r32 sint; word3 TYPE = 0xB, SQ_RSRC_IMG_CUBE), 64 threads, thread t at (x, y) = (t & 7, t >> 3) of an 8x8 +; face, each store to all six faces (v3 = face). The translator writes a cube through a six-layer 2D-array storage +; view (bindings 11/12/13, the layer is the face), as the runtime binds a cube UAV (runtime/src/vulkan_bindless.h). +; Run: vk_store_test cs_imgstore_cube.spv cube (checks every texel of all six layers of all three images): +; rgba8 unorm: (x / 7, y / 7, face / 5, 1) +; r32 uint: 100 + 1000 face + 8y + x +; r32 sint: -(1000 face + 8y + x) +v_and_b32_e32 v1, 7, v0 +v_lshrrev_b32_e32 v2, 3, v0 +v_cvt_f32_u32_e32 v4, v1 +v_cvt_f32_u32_e32 v5, v2 +v_mul_f32_e32 v4, 0x3e124925, v4 +v_mul_f32_e32 v5, 0x3e124925, v5 +v_mov_b32_e32 v7, 1.0 +v_add_nc_u32_e32 v16, 100, v0 +v_mov_b32_e32 v9, 0 +v_mov_b32_e32 v10, 0 +v_mov_b32_e32 v11, 0 +v_mov_b32_e32 v13, 0 +v_mov_b32_e32 v14, 0 +v_mov_b32_e32 v15, 0 +s_mov_b32 s8, 0x1000 +s_mov_b32 s9, 0x3800000 +s_mov_b32 s10, 0x11 +s_mov_b32 s11, 0xb0000011 +s_mov_b32 s12, 0x11 +s_mov_b32 s13, 0x11 +s_mov_b32 s14, 0x11 +s_mov_b32 s15, 0x11 +s_mov_b32 s16, 0x2000 +s_mov_b32 s17, 0x1400000 +s_mov_b32 s18, 0x22 +s_mov_b32 s19, 0xb0000022 +s_mov_b32 s20, 0x22 +s_mov_b32 s21, 0x22 +s_mov_b32 s22, 0x22 +s_mov_b32 s23, 0x22 +s_mov_b32 s24, 0x3000 +s_mov_b32 s25, 0x1500000 +s_mov_b32 s26, 0x33 +s_mov_b32 s27, 0xb0000033 +s_mov_b32 s28, 0x33 +s_mov_b32 s29, 0x33 +s_mov_b32 s30, 0x33 +s_mov_b32 s31, 0x33 +v_mov_b32_e32 v3, 0 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 0, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, 0, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_mov_b32_e32 v3, 1 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 1000, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, -1000, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_mov_b32_e32 v3, 2 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 2000, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, -2000, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_mov_b32_e32 v3, 3 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 3000, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, -3000, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_mov_b32_e32 v3, 4 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 4000, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, -4000, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_mov_b32_e32 v3, 5 +v_cvt_f32_u32_e32 v6, v3 +v_mul_f32_e32 v6, 0x3e4ccccd, v6 +image_store v[4:7], v[1:3], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_add_nc_u32_e32 v8, 5000, v16 +image_store v[8:11], v[1:3], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +v_sub_nc_u32_e32 v12, -5000, v0 +image_store v[12:15], v[1:3], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_CUBE unorm +s_endpgm diff --git a/runtime/test/vk_store_test.cpp b/runtime/test/vk_store_test.cpp index 5567511d0b..99a602aebd 100644 --- a/runtime/test/vk_store_test.cpp +++ b/runtime/test/vk_store_test.cpp @@ -16,6 +16,10 @@ // at binding 7, where 2D and 3D image atomics address their image, and at index 4 of the sampled array a 16x4 rgba8 // image with all five mip levels (never read, only queried), behind the T# the runtime writes for such an image. // "signed-zero" checks three direct float stores and all remaining RGBA32 guard words (SHADER-605). +// "cube" (cs_imgstore_cube.asm, GPU-CUBE-STORE): the shader stores to three cube images (the same three formats, T# +// word3 TYPE = SQ_RSRC_IMG_CUBE). As the runtime binds a cube UAV (runtime/src/vulkan_bindless.h), each is a +// cube-compatible 8x8 image of six layers whose storage view is a six-layer 2D array, at index k + 1 of the 2D-array +// storage arrays (bindings 11 / 12 / 13 for float / uint / sint). Checks every texel of every layer (the face). #include "vulkan_loader.h" #include "vk_device_pick.h" #include "vk_shader_fma.h" @@ -60,7 +64,10 @@ static void table_insert(std::vector& t, const uint32_t key[8], uint32 } int main(int argc, char** argv) { - if (argc < 2) { std::fprintf(stderr, "usage: vk_store_test cs.spv [load|load-d16|words|signed-zero]\n"); return 2; } + if (argc < 2) { + std::fprintf(stderr, "usage: vk_store_test cs.spv [load|load-d16|words|signed-zero|cube]\n"); + return 2; + } gipa = load_vulkan(); if (!gipa) return 1; #define LOADI(name) auto name = reinterpret_cast(gipa(inst, #name)) @@ -126,6 +133,7 @@ int main(int argc, char** argv) { // "words" mode: the two images filled as for "load"; the shader's results are whatever it leaves in them. const bool words_mode = argc > 2 && !std::strcmp(argv[2], "words"); const bool signed_zero = argc > 2 && !std::strcmp(argv[2], "signed-zero"); + const bool cube_mode = argc > 2 && !std::strcmp(argv[2], "cube"); if (signed_zero) { LOADI(vkGetPhysicalDeviceProperties2); VkPhysicalDeviceFloatControlsProperties controls{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES}; @@ -224,6 +232,10 @@ int main(int argc, char** argv) { uint32_t t[8] = {0x1000 * (k + 1), fmts[k] << 20}; for (int j = 2; j < 8; j++) t[j] = 0x11 * (k + 1); table_insert(table, t, k + 1); // its index in the 2D arrays; 0 is the fallback, as in the runtime + if (cube_mode) { // the cube T# (cs_imgstore_cube.asm): word3 also has TYPE = 0xB, index k + 1 of the 2D arrays + t[3] |= 0xB0000000u; + table_insert(table, t, k + 1); + } } // Index 4: a 16x4 rgba8 image with its whole mip chain (16x4, 8x2, 4x1, 2x1, 1x1) for image_get_resinfo. Its key // is the T# of exactly that image (gfx10_descriptors.h), which cs_resinfo.asm builds word for word. @@ -296,6 +308,26 @@ int main(int argc, char** argv) { vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; CHECK(vkCreateImageView(dev, &vi, nullptr, &vol_view)); } + // Cube mode: three cube-compatible 8x8 images of six layers, each seen through a six-layer 2D-array view. + const uint32_t FACES = 6; + VkImage cube[3]{}; VkImageView cube_view[3]{}; + for (int k = 0; cube_mode && k < 3; k++) { + VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + ii.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + ii.imageType = VK_IMAGE_TYPE_2D; ii.format = vkf[k]; ii.extent = {W, W, 1}; ii.mipLevels = 1; + ii.arrayLayers = FACES; ii.samples = VK_SAMPLE_COUNT_1_BIT; ii.tiling = VK_IMAGE_TILING_OPTIMAL; + ii.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + CHECK(vkCreateImage(dev, &ii, nullptr, &cube[k])); + VkMemoryRequirements mr; vkGetImageMemoryRequirements(dev, cube[k], &mr); + VkMemoryAllocateInfo mai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; + mai.allocationSize = mr.size; mai.memoryTypeIndex = memtype(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + VkDeviceMemory m; CHECK(vkAllocateMemory(dev, &mai, nullptr, &m)); + CHECK(vkBindImageMemory(dev, cube[k], m, 0)); + VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + vi.image = cube[k]; vi.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; vi.format = vkf[k]; + vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, FACES}; + CHECK(vkCreateImageView(dev, &vi, nullptr, &cube_view[k])); + } VkSamplerCreateInfo sci{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; VkSampler sampler; CHECK(vkCreateSampler(dev, &sci, nullptr, &sampler)); // Set 0: binding 0 = sampled images, 1 = samplers, 2 = hash table, 8/9/10 = float/uint/sint 2D storage image arrays. @@ -303,23 +335,27 @@ int main(int argc, char** argv) { // index 4. Binding 0 holds each image's view in its own format (typed image_load reads the uint and sint ones // through integer aliases); every element of a storage array holds the image of its class, so all of them are // valid descriptors. Bindings 4 and 7 = the 2D and 3D r32ui storage images of the image atomics: the uint image - // and the volume, in every element. + // and the volume, in every element. Cube mode adds 11/12/13 = the float/uint/sint 2D-array storage arrays, which + // hold the cube image of their class in every element. constexpr uint32_t N = 5; - VkDescriptorSetLayoutBinding b[8]{}; + const uint32_t bindings = cube_mode ? 11 : 8; + VkDescriptorSetLayoutBinding b[11]{}; b[0] = {0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, N, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; b[1] = {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; b[2] = {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; for (int k = 0; k < 3; k++) b[3 + k] = {uint32_t(8 + k), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, N, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; b[6] = {4, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, N, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; b[7] = {7, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, N, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; + for (int k = 0; k < 3; k++) + b[8 + k] = {uint32_t(11 + k), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, N, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}; VkDescriptorSetLayoutCreateInfo dli{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; - dli.bindingCount = 8; dli.pBindings = b; + dli.bindingCount = bindings; dli.pBindings = b; VkDescriptorSetLayout dsl; CHECK(vkCreateDescriptorSetLayout(dev, &dli, nullptr, &dsl)); VkDescriptorPoolSize ps[4] = { {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, N}, {VK_DESCRIPTOR_TYPE_SAMPLER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, - {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 5 * N}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, (bindings - 3) * N}, }; VkDescriptorPoolCreateInfo dpi{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; dpi.maxSets = 1; dpi.poolSizeCount = 4; dpi.pPoolSizes = ps; @@ -335,8 +371,8 @@ int main(int argc, char** argv) { {VK_NULL_HANDLE, wide_view, VK_IMAGE_LAYOUT_GENERAL}}; VkDescriptorImageInfo smpi{sampler, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_UNDEFINED}; VkDescriptorImageInfo dii[3][N]; - VkDescriptorImageInfo r32ui[N], r32ui_3d[N]; - VkWriteDescriptorSet wr[8]{}; + VkDescriptorImageInfo r32ui[N], r32ui_3d[N], cube_ii[3][N]; + VkWriteDescriptorSet wr[11]{}; for (auto& w : wr) { w.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; w.dstSet = ds; w.descriptorCount = 1; } wr[0].dstBinding = 0; wr[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; wr[0].pImageInfo = sii; wr[0].descriptorCount = N; @@ -353,7 +389,12 @@ int main(int argc, char** argv) { for (uint32_t e = 0; e < N; e++) r32ui_3d[e] = {VK_NULL_HANDLE, vol_view, VK_IMAGE_LAYOUT_GENERAL}; wr[7].dstBinding = 7; wr[7].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; wr[7].pImageInfo = r32ui_3d; wr[7].descriptorCount = N; - vkUpdateDescriptorSets(dev, 8, wr, 0, nullptr); + for (int k = 0; cube_mode && k < 3; k++) { + for (uint32_t e = 0; e < N; e++) cube_ii[k][e] = {VK_NULL_HANDLE, cube_view[k], VK_IMAGE_LAYOUT_GENERAL}; + wr[8 + k].dstBinding = 11 + k; wr[8 + k].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + wr[8 + k].pImageInfo = cube_ii[k]; wr[8 + k].descriptorCount = N; + } + vkUpdateDescriptorSets(dev, bindings, wr, 0, nullptr); VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; smi.codeSize = code.size(); smi.pCode = reinterpret_cast(code.data()); @@ -383,6 +424,11 @@ int main(int argc, char** argv) { const uint32_t image_words = W * W * (signed_zero ? 4 : 1); VkBuffer rb[3]; void* rbp[3]; for (int k = 0; k < 3; k++) CHECK(make_buffer(image_words * 4, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &rb[k], &rbp[k])); + // Cube mode: each cube image's six layers read back one after another, texel (x, y) of face f at 64f + 8y + x. + const uint32_t cube_words = W * W * FACES; + VkBuffer cube_rb[3]{}; void* cube_rbp[3]{}; + for (int k = 0; cube_mode && k < 3; k++) + CHECK(make_buffer(cube_words * 4, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &cube_rb[k], &cube_rbp[k])); // Load and words modes: what the uint and sint images hold before the dispatch, texel (x, y) at i = 8y + x. // The last row of the D16 fixture ("load-d16" only) exercises both sides of each 16-bit boundary. struct PackedLoad { uint32_t u; int32_t s, sum; }; @@ -471,6 +517,17 @@ int main(int argc, char** argv) { vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 3 - first_fill, ib + first_fill); } + VkImageMemoryBarrier cube_ib[3]{}; + for (int k = 0; cube_mode && k < 3; k++) { + cube_ib[k] = ib[0]; + cube_ib[k].image = cube[k]; cube_ib[k].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + cube_ib[k].newLayout = VK_IMAGE_LAYOUT_GENERAL; cube_ib[k].srcAccessMask = 0; + cube_ib[k].dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + cube_ib[k].subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, FACES}; + } + if (cube_mode) + vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, + 0, nullptr, 3, cube_ib); vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pl, 0, 1, &ds, 0, nullptr); uint32_t pc[36] = {}; @@ -493,6 +550,19 @@ int main(int argc, char** argv) { bic.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; bic.imageExtent = {W, W, 1}; vkCmdCopyImageToBuffer(cmd, img[k], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, rb[k], 1, &bic); } + if (cube_mode) { + for (int k = 0; k < 3; k++) { + cube_ib[k].oldLayout = VK_IMAGE_LAYOUT_GENERAL; cube_ib[k].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + cube_ib[k].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; cube_ib[k].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + } + vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, + nullptr, 3, cube_ib); + for (int k = 0; k < 3; k++) { + VkBufferImageCopy bic{}; // all six layers, tightly packed one after another + bic.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, FACES}; bic.imageExtent = {W, W, 1}; + vkCmdCopyImageToBuffer(cmd, cube[k], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cube_rb[k], 1, &bic); + } + } if (words_mode) { vol_ib.oldLayout = VK_IMAGE_LAYOUT_GENERAL; vol_ib.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; vol_ib.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; @@ -514,6 +584,30 @@ int main(int argc, char** argv) { CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); CHECK(vkQueueWaitIdle(q)); + if (cube_mode) { // every texel of every face, against what cs_imgstore_cube.asm writes there + uint32_t bad[3] = {}; + for (uint32_t face = 0; face < FACES; face++) + for (uint32_t y = 0; y < W; y++) + for (uint32_t x = 0; x < W; x++) { + const uint32_t i = y * W + x, at = face * W * W + i; + const uint8_t* c = static_cast(cube_rbp[0]) + 4 * at; + const int er = int(std::lround(x / 7.0 * 255)), eg = int(std::lround(y / 7.0 * 255)); + const int eb = int(std::lround(face / 5.0 * 255)); + if (std::abs(c[0] - er) > 1 || std::abs(c[1] - eg) > 1 || std::abs(c[2] - eb) > 1 || c[3] != 255) + bad[0]++; + if (static_cast(cube_rbp[1])[at] != 100 + 1000 * face + i) bad[1]++; + if (static_cast(cube_rbp[2])[at] != -int32_t(1000 * face + i)) bad[2]++; + } + const uint32_t at = 4 * W * W + 3 * W + 5; // texel (5, 3) of face 4 + const uint8_t* c = static_cast(cube_rbp[0]) + 4 * at; + std::printf("rgba8 unorm cube (float view): %u bad, face 4 texel(5,3) = %u %u %u %u\n", bad[0], c[0], c[1], + c[2], c[3]); + std::printf("r32 uint cube (uint view): %u bad, face 4 texel(5,3) = %u\n", bad[1], + static_cast(cube_rbp[1])[at]); + std::printf("r32 sint cube (sint view): %u bad, face 4 texel(5,3) = %d\n", bad[2], + static_cast(cube_rbp[2])[at]); + return (bad[0] || bad[1] || bad[2]) ? 1 : 0; + } if (signed_zero) { constexpr uint32_t neg = 0x80000000; constexpr uint32_t stores[] = {neg, 0, 0, 0, neg, 0x3f800000, 0, 0, neg, neg, 0, 0}; diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index a075c876a4..20e72668e0 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -1320,6 +1320,9 @@ def run_suite(a, work: str) -> int: elif name == "cs_imgstore": rc, msg = run_cmd([vk_store, spv]) results.append((name, *helper_result(rc, msg))) + elif name == "cs_imgstore_cube": # GPU-CUBE-STORE: six-layer 2D-array views at bindings 11/12/13 + rc, msg = run_cmd([vk_store, spv, "cube"]) + results.append((name, *helper_result(rc, msg))) elif name in ("cs_imgload", "cs_imgload_tfe", "cs_imgload_d16", "cs_imgload_d16_tfe", "cs_sample_lz_int_d16"): rc, msg = run_cmd([vk_store, spv, "load" if name in ("cs_imgload", "cs_imgload_tfe") else "load-d16"]) results.append((name, *helper_result(rc, msg))) diff --git a/tests/test_shader_checks.py b/tests/test_shader_checks.py index 20758886b0..665493a1f1 100644 --- a/tests/test_shader_checks.py +++ b/tests/test_shader_checks.py @@ -30,9 +30,9 @@ WAVE32_WORDS = {n: w for n, w in check.CS_DUMPS if n in check.WAVE32_DUMPS and n not in ("cs_store", "cs_smem_soffset_imm")} -# All check.py cases, including the six vk_store_test shaders and the three mesh fixtures, and TEST-184's +# All check.py cases, including the seven vk_store_test shaders and the three mesh fixtures, and TEST-184's # vk_store_test "words" fixtures and image_get_lod draws. -TOTAL = (len(check.COMPUTE) + 7 + len(check.CS_DUMPS) + len(check.W64X_DUMPS) + len(check.W64X_PARTIAL) + 6 +TOTAL = (len(check.COMPUTE) + 7 + len(check.CS_DUMPS) + len(check.W64X_DUMPS) + len(check.W64X_PARTIAL) + 7 + len(check.PIXEL_TESTS) + len(check.CLIP_TESTS) + len(check.BOUNDS) + len(check.GLOBAL_OFFSET) + len(check.MIP_TEST_PASSES) + len(check.GRADIENT_TESTS) + len(check.STORE_WORDS) + len(check.GET_LOD_TESTS) @@ -159,8 +159,8 @@ def harness(_tool, shader, *args, env=None): return 0, "out[0..7] = " + " ".join(map(str, (WAVE32_WORDS[name] + [0] * 8)[:8])) + "\n" if name == "cs_workgroup_yz": # #186: vk_compute_test's 2x3x4 Y/Z histogram line return 0, "2x3x4 workgroup Y/Z: 0 mismatches\n" - if name in ("cs_imgstore", "cs_imgload", "cs_imgload_tfe", "cs_imgload_d16", "cs_imgload_d16_tfe", - "cs_sample_lz_int_d16"): # vk_store_test checks + if name in ("cs_imgstore", "cs_imgstore_cube", "cs_imgload", "cs_imgload_tfe", "cs_imgload_d16", + "cs_imgload_d16_tfe", "cs_sample_lz_int_d16"): # vk_store_test checks return 0, "0 bad\n0 bad\n0 bad\n" if name in check.STORE_WORDS: # vk_store_test "words": the three images, judged by check.py self.assertEqual(args, ("words",))