Skip to content

fix(kyty): avoid vector OpSpecConstantOp Select in tiler shaders - #342

Open
birdmarty wants to merge 3 commits into
simnJS:AnyKytyfrom
birdmarty:fix/kyty-tiler-scalar-spec-select
Open

birdmarty wants to merge 3 commits into
simnJS:AnyKytyfrom
birdmarty:fix/kyty-tiler-scalar-spec-select

Conversation

@birdmarty

Copy link
Copy Markdown
Contributor

What

Replace chained uvec4 ternary expressions on the ELEMENT_BYTES specialization constant with if / else if / else statements in three tiler shaders:

  • core/kyty/graphics/host_gpu/shaders/gpu_tiler_prt.comp
  • core/kyty/graphics/host_gpu/shaders/gpu_tiler_prt_3d.comp
  • core/kyty/graphics/host_gpu/shaders/gpu_tiler_standard64_3d.inc

With glslang -V --target-env vulkan1.3 -Os, those chained vector ternaries lowered to OpSpecConstantOp %v4uint Select, which crashes AMD's Windows Vulkan driver (amdvlk64.dll+0x22240ac, 0xc0000005) inside vkCreateComputePipelines when TileManager::CreatePipeline specializes the 64 KB 3D or PRT tiler pipelines (see #341). An audit of all other shaders in core/kyty/graphics/host_gpu/shaders/ found no other vector OpSpecConstantOp Select instructions.

Add kyty_shim_tiler_shaders (CPU, also runs under Linux ASan/TSan) to validate all 13 embedded tiler SPIR-V modules with spirv-val and reject vector OpSpecConstantOp Select, and kyty_shim_tiler_shaders_gpu (added to GPU_TESTS in .github/workflows/anykyty.yml) to compile all 90 specialized tiler compute pipelines and verify GPU Tile and Detile output for Standard64KB3D, Prt64KB, and Prt64KB3D across all five element sizes (1, 2, 4, 8, 16 bytes) bit-for-bit against CPU TileGetBlockOffset.

Tested

  • Negative control (test binary built against 6af9ec8's 3 shader files on Windows 11 Pro build 26300, AMD Radeon RX 6800, AMD proprietary driver 26.11.2 / AMDVLK 2.0.353, Vulkan 1.4.315):
    • kyty_shim_tiler_shaders: failed as expected (FAILED: standard64_3d: contains vector OpSpecConstantOp Select).
    • kyty_shim_tiler_shaders_gpu: crashed as expected (***Exception: SegFault inside amdvlk64.dll).
  • With this change (848892a on 6af9ec8), same machine and GPU, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer:
    • ctest --test-dir build -R '^kyty_shim_(tiler_shaders(|_gpu)|tiled_layout(|_stop))$' -V: 4/4 passed (kyty_shim_tiled_layout 0.06 s, kyty_shim_tiled_layout_stop 0.06 s, kyty_shim_tiler_shaders 0.11 s, kyty_shim_tiler_shaders_gpu 0.48 s).
    • Confirmed Insert instance layer "VK_LAYER_KHRONOS_validation" (C:\VulkanSDK\1.4.363.0\Bin\VkLayer_khronos_validation.dll), no was not found, and 0 VUID- validation errors.
  • Checks: py -3 tools/check_conventions.py --base origin/AnyKyty passed; py -3 tools/check_kyty_settings.py passed (87/87 settings documented); py -3 tools/debt_fold.py --check passed.
  • Title check: Lies of P (PPSA10621 01.012.000) on Windows 11 / RX 6800 (with fix(kyty): place mesh per-primitive built-ins in a Block struct #328 + this shader fix) gets past the 3D title menu amdvlk64.dll+0x22240ac crash into gameplay.
  • Not verified: Linux / RADV, NVIDIA, Intel GPUs (pending CI / outside runs).

Checklist

Replace chained vector ternaries on the ELEMENT_BYTES specialization constant with if/else statements in gpu_tiler_prt.comp, gpu_tiler_prt_3d.comp and gpu_tiler_standard64_3d.inc.

With glslang -Os, those vector ternaries lowered to OpSpecConstantOp Select returning uvec4, which crashes AMDVLK (amdvlk64.dll, AMD proprietary driver 26.11.2 / 2.0.353 on RX 6800) inside vkCreateComputePipelines when specializing the 3D/PRT tiler pipelines.

Add kyty_shim_tiler_shaders to check all embedded tiler SPIR-V modules with spirv-val and reject vector OpSpecConstantOp Select, plus kyty_shim_tiler_shaders_gpu to compile all 90 specialized tiler pipelines and verify GPU tiling and detiling for Standard64KB3D, Prt64KB and Prt64KB3D across all five element sizes against TileGetBlockOffset.
@birdmarty
birdmarty temporarily deployed to repository-maintenance November 26, 2026 21:31 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown

The GPU test waits for the queue to go idle, but it never makes the compute shader’s writes visible to the host before reading the mapped output. Host-coherent memory removes the need to invalidate the mapping; it does not replace the memory dependency. Add a compute shader write → host read barrier after the dispatch so both memcmp checks are valid across drivers.

Also, the Require(validator.Validate(...), ... + errors) call can build the failure message before the validator’s callback populates errors. Store the validation result first, then call Require so failures include the SPIR-V diagnostic.

@birdmarty

birdmarty commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed both in 2cc6301292:

  • Added a VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT (VK_ACCESS_SHADER_WRITE_BIT) -> VK_PIPELINE_STAGE_HOST_BIT (VK_ACCESS_HOST_READ_BIT) memory barrier after cmd.dispatch(...) in RunTilerDispatch.
  • Stored the validator.Validate(...) result in a local before calling Require so errors is populated before formatting the failure message.

Re-ran kyty_shim_tiler_shaders and kyty_shim_tiler_shaders_gpu on RX 6800 with VK_LAYER_KHRONOS_validation (4/4 passed, 0 VUID- errors).

@github-actions

Copy link
Copy Markdown

Thanks. The updated diff makes the shader writes visible to the host before readback and captures the validator diagnostics before formatting the error. That addresses both earlier findings.

One synchronization gap remains: detile reads tiled_buf on the GPU after tile writes it. The compute-to-host barrier covers memcmp, but not the next dispatch’s shader read. Add a compute shader write → compute shader read dependency for tiled_buf before the detile dispatch.

@birdmarty
birdmarty temporarily deployed to repository-maintenance November 26, 2026 21:37 — with GitHub Actions Inactive
@birdmarty

Copy link
Copy Markdown
Contributor Author

Added the compute-write -> compute-read (and host-write) dependency in 7e321baa91:

  • Extended the post-dispatch vk::MemoryBarrier in RunTilerDispatch to VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT with VK_ACCESS_HOST_READ_BIT | VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT, making tiled_buf writes from the tile dispatch visible to both host memcmp and the subsequent detile compute dispatch (as well as host resets between iterations).

Re-ran kyty_shim_tiler_shaders and kyty_shim_tiler_shaders_gpu on RX 6800 with VK_LAYER_KHRONOS_validation and synchronization validation enabled (4/4 passed, 0 VUID- / SYNC- errors).

@github-actions

Copy link
Copy Markdown

The updated barrier covers both host readback and the detile dispatch’s shader read, so the remaining synchronization finding is resolved. Thanks for rerunning with synchronization validation enabled and reporting no errors.

This branch was previously deployed

1 inactive (outdated) deployment
repository-maintenance — 2cc63012 Deployed Nov 26, 2026 by birdmarty via review #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kyty: AMDVLK crashes in vkCreateComputePipelines on 3D/PRT tiler shaders with vector OpSpecConstantOp Select

1 participant