d3d12: check field offsets within structured buffer SRV records (SHADER-BUFFER-BOUNDS) #1097

Closed
github-bot wants to merge 1 commit from gh-pr/1097/head into gh-pr/1097/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 18:21 UTC · original
split/shader-buffer-bounds → main · +23 −10 · 4 files · 1 commits · closed without merging

Claimed in the coordination issue as: SHADER-BUFFER-BOUNDS (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #220 validates SRV descriptions, #513 changes CBV stride, and #1068 widens translator address arithmetic. This change selects the descriptor bounds mode for structured buffer SRVs.

What and why

A structured buffer SRV used the typed view's index-only bounds mode. A four-byte field starting at the end of an indexed record could therefore read the next record. Select mode 0 for structured SRVs, matching the structured UAV encoding. Raw views keep byte bounds. Typed views keep record-index bounds.

The synthetic GPU fixture reads the same field offset through a structured view and a typed view. With 16-byte records, offset 16 must read zero for the structured view. The typed control reads the next value for each valid index.

Tested

Cross-built with clang-cl 23 and the xwin SDK. Ran under CachyOS Linux 7.3, Proton Experimental (Wine 11), Ryzen 5 5600X, 16 GB RAM, RTX 4070 12 GB and NVIDIA 620.73.

cmake --build runtime/build/boot --target gta6rt d3d12_compute_test -j6
spirv-val --target-env vulkan1.3 runtime/build/boot/generated/cs_user_data.spv
(cd runtime/build/boot && "$WINE" d3d12_compute_test.exe)
Configuration Descriptor and readback results
Main plus tests The structured descriptor assertion failed on the first of two structured views. The fixture stopped before GPU readback.
Child Both structured descriptors encoded mode 0. The GPU returned 64/64 zero values through the structured view and the expected 24 values and 40 zeros through the typed view (64/64).

The fixture skipped its native D3D12 CachedPSO comparison under Wine. Native Windows, AMD, Intel and a game boot were not tested.
GPUs tested: NVIDIA GeForce RTX 4070.
AI-assisted: yes

Checklist

  • One commit on upstream main at the cut. Clean merge check.
  • One descriptor change with structured and typed controls.
  • Changed-file game-data guard and whitespace check passed.
  • No translator rule changed.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 18:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097) `split/shader-buffer-bounds` → `main` · +23 −10 · 4 files · 1 commits · closed without merging Claimed in the coordination issue as: SHADER-BUFFER-BOUNDS ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #220 validates SRV descriptions, #513 changes CBV stride, and #1068 widens translator address arithmetic. This change selects the descriptor bounds mode for structured buffer SRVs. ### What and why A structured buffer SRV used the typed view's index-only bounds mode. A four-byte field starting at the end of an indexed record could therefore read the next record. Select mode 0 for structured SRVs, matching the structured UAV encoding. Raw views keep byte bounds. Typed views keep record-index bounds. The synthetic GPU fixture reads the same field offset through a structured view and a typed view. With 16-byte records, offset 16 must read zero for the structured view. The typed control reads the next value for each valid index. ### Tested Cross-built with clang-cl 23 and the xwin SDK. Ran under CachyOS Linux 7.3, Proton Experimental (Wine 11), Ryzen 5 5600X, 16 GB RAM, RTX 4070 12 GB and NVIDIA 620.73. ```sh cmake --build runtime/build/boot --target gta6rt d3d12_compute_test -j6 spirv-val --target-env vulkan1.3 runtime/build/boot/generated/cs_user_data.spv (cd runtime/build/boot && "$WINE" d3d12_compute_test.exe) ``` | Configuration | Descriptor and readback results | | --- | --- | | Main plus tests | The structured descriptor assertion failed on the first of two structured views. The fixture stopped before GPU readback. | | Child | Both structured descriptors encoded mode 0. The GPU returned 64/64 zero values through the structured view and the expected 24 values and 40 zeros through the typed view (64/64). | The fixture skipped its native D3D12 CachedPSO comparison under Wine. Native Windows, AMD, Intel and a game boot were not tested. GPUs tested: NVIDIA GeForce RTX 4070. AI-assisted: yes ### Checklist - [x] One commit on upstream main at the cut. Clean merge check. - [x] One descriptor change with structured and typed controls. - [x] Changed-file game-data guard and whitespace check passed. - [x] No translator rule changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A structured SRV used the typed index-only bounds mode, allowing a load
beyond the end of one record to read the next.

Select the same field-offset bounds mode as a structured UAV, consistent
with five-star-recomp 3d287ab. Leave raw and typed views unchanged.

Main plus the test failed at the first structured descriptor. The child
passed both descriptor checks and all 128 structured and typed GPU readbacks
on Proton. The synthetic module passed SPIR-V validation.


AI-assisted (Codex and Claude Code agents).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:00 +00:00
github-bot closed this pull request 2026-11-26 09:38:00 +00:00
Author
Owner

@⁠Plaaasma on GitHub · 2026-11-24 18:37 UTC · original

Native Windows check, AI-assisted (Claude Code). Windows 11, i9-13900K, 64 GB, RTX 4070 Ti 12 GB (NVIDIA 630.20), MSVC 2022 (VS 17 generator, Release), Vulkan.

Head 8fc4abbf0. Built d3d12_compute_test (rebuilds cs_user_data.comp), then ctest -C Release -R "^d3d12_compute$" --output-on-failure --timeout 300:

  • d3d12_compute: passed, 1.27 s, including the two new cross-record passes (field offset past the structured record reads zero; same offset with the typed index-only check reads data)
  • CreateShaderResourceView(buffer): raw (32 in-bounds + 32 OOB-zero), structured (32 + 32 OOB-zero), typed (24 + 40 OOB-zero) matched; negative controls flipped 32/32 (raw B), 32/32 (struct B), 32/32 (null)

1 passed, 0 failed.

**@⁠Plaaasma** on GitHub · 2026-11-24 18:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#issuecomment-7140911175) Native Windows check, AI-assisted (Claude Code). Windows 11, i9-13900K, 64 GB, RTX 4070 Ti 12 GB (NVIDIA 630.20), MSVC 2022 (VS 17 generator, Release), Vulkan. Head `8fc4abbf0`. Built `d3d12_compute_test` (rebuilds `cs_user_data.comp`), then `ctest -C Release -R "^d3d12_compute$" --output-on-failure --timeout 300`: - `d3d12_compute`: **passed**, 1.27 s, including the two new cross-record passes (field offset past the structured record reads zero; same offset with the typed index-only check reads data) - `CreateShaderResourceView(buffer): raw (32 in-bounds + 32 OOB-zero), structured (32 + 32 OOB-zero), typed (24 + 40 OOB-zero) matched; negative controls flipped 32/32 (raw B), 32/32 (struct B), 32/32 (null)` 1 passed, 0 failed.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:41 UTC · original · approved these changes

Audited and verified. Configures structured buffer SRV descriptors to use OobSelect::structured_with_offset (mode 0) in
untime/shims/d3d12_vulkan_device.cpp, enforcing field offset bounds checks within record stride matching structured UAV and hardware GFX11 behavior. Verified in
untime/test/d3d12_compute_test.cpp. Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#pullrequestreview-6045219235) · **approved these changes** Audited and verified. Configures structured buffer SRV descriptors to use OobSelect::structured_with_offset (mode 0) in untime/shims/d3d12_vulkan_device.cpp, enforcing field offset bounds checks within record stride matching structured UAV and hardware GFX11 behavior. Verified in untime/test/d3d12_compute_test.cpp. Approved.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:50 UTC · original · approved these changes

Clean-Room Audit — PR #1097 (SHADER-BUFFER-BOUNDS Structured SRV Offset Check)

Solid alignment between structured buffer SRVs and UAVs (OobSelect::structured_with_offset in runtime/shims/d3d12_vulkan_device.cpp), ensuring out-of-bounds field offsets past record stride are properly checked on GFX11/RDNA2.

Clean GLSL shader test coverage in cs_user_data.comp and d3d12_compute_test.cpp; accurate docs/buffer_bounds.md documentation. 0 game data.

Verdict: APPROVED

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#pullrequestreview-6045348162) · **approved these changes** ### Clean-Room Audit — PR #1097 (`SHADER-BUFFER-BOUNDS` Structured SRV Offset Check) Solid alignment between structured buffer SRVs and UAVs (`OobSelect::structured_with_offset` in `runtime/shims/d3d12_vulkan_device.cpp`), ensuring out-of-bounds field offsets past record stride are properly checked on GFX11/RDNA2. Clean GLSL shader test coverage in `cs_user_data.comp` and `d3d12_compute_test.cpp`; accurate `docs/buffer_bounds.md` documentation. 0 game data. **Verdict: APPROVED**
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 19:24 UTC · original

AI-assisted independent GPU verification (overnight shift, worker w4).

Environment: Windows, Git Bash; runtime built RelWithDebInfo (Ninja, VS2022 BuildTools, SDK 10.0.26100, Vulkan SDK 1.4.363.0, LLVM_MC=WSL llvm-21). LEONIDA_VK_VALIDATION=1 on AMD.

ctest (buffer/SRV-related d3d12 subset), NVIDIA RTX 4070 SUPER (driver 610.88, 256B push constants):
ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R 'd3d12_(compute|fspx_compute|set0_compute|buffer_uav|buffer_tiles|descriptor|set_descriptor_heaps|m4_compute|uav_clear|short_uav_clear)'

  • 10/10 passed, 0 failed — including d3d12_compute (the modified test), d3d12_buffer_uav, d3d12_m4_compute, d3d12_fspx_compute, d3d12_set0_compute, d3d12_buffer_tiles, d3d12_descriptor, d3d12_set_descriptor_heaps, d3d12_uav_clear, d3d12_short_uav_clear.

ctest, AMD Radeon iGPU (RDNA2 gfx1035, driver 24.10.24, 128B push constants):

  • Passed: d3d12_buffer_tiles, d3d12_descriptor, d3d12_set_descriptor_heaps, d3d12_uav_clear, d3d12_short_uav_clear, d3d12_srgb_uav, d3d12_r9g9b9e5_uav (d3d12_b5g5r5a1_uav self-skipped).
  • 5 tests cannot run on this iGPU — documented device limitation, not this PR: the D3D12 layer refuses pipelines needing >128 push-constant bytes (push_constants_fit in d3d12_vulkan_device.cpp; docs/design.md push-constant table: 'uniform-buffer fallback not built yet'). Affected: d3d12_compute, d3d12_buffer_uav, d3d12_m4_compute (fail at CreateComputePipelineState), d3d12_fspx_compute, d3d12_set0_compute (self-skip). Same failures occur on unmodified main — the iGPU's maxPushConstantsSize is 128.

GPU suite (run_gpu_tests.py):

  • AMD iGPU (validation on, LEONIDA_PC_TAIL_UBO=1): 230/252 passed, 20 skipped, 2 failed — known pre-existing ms_clip/ms_wave_info_s3 AMD LLPC 0xC0000005 mesh-shader crashes (SHADER-167; fixes in open #802/#808). 0 Vulkan validation errors.
  • NVIDIA RTX 4070 SUPER: 203/252 passed, 49 skipped, 0 failed. 0 validation errors.

Verdict: verified. Structured-buffer SRV bounds-mode-0 records produce no validation errors and no regressions; every runnable buffer/SRV test passes on both GPUs.

**@⁠whoalin1** on GitHub · 2026-11-24 19:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#issuecomment-7142045219) AI-assisted independent GPU verification (overnight shift, worker w4). **Environment:** Windows, Git Bash; runtime built RelWithDebInfo (Ninja, VS2022 BuildTools, SDK 10.0.26100, Vulkan SDK 1.4.363.0, LLVM_MC=WSL llvm-21). `LEONIDA_VK_VALIDATION=1` on AMD. **ctest (buffer/SRV-related d3d12 subset), NVIDIA RTX 4070 SUPER (driver 610.88, 256B push constants):** `ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R 'd3d12_(compute|fspx_compute|set0_compute|buffer_uav|buffer_tiles|descriptor|set_descriptor_heaps|m4_compute|uav_clear|short_uav_clear)'` - **10/10 passed, 0 failed** — including `d3d12_compute` (the modified test), `d3d12_buffer_uav`, `d3d12_m4_compute`, `d3d12_fspx_compute`, `d3d12_set0_compute`, `d3d12_buffer_tiles`, `d3d12_descriptor`, `d3d12_set_descriptor_heaps`, `d3d12_uav_clear`, `d3d12_short_uav_clear`. **ctest, AMD Radeon iGPU (RDNA2 gfx1035, driver 24.10.24, 128B push constants):** - Passed: `d3d12_buffer_tiles`, `d3d12_descriptor`, `d3d12_set_descriptor_heaps`, `d3d12_uav_clear`, `d3d12_short_uav_clear`, `d3d12_srgb_uav`, `d3d12_r9g9b9e5_uav` (`d3d12_b5g5r5a1_uav` self-skipped). - **5 tests cannot run on this iGPU — documented device limitation, not this PR:** the D3D12 layer refuses pipelines needing >128 push-constant bytes (`push_constants_fit` in `d3d12_vulkan_device.cpp`; `docs/design.md` push-constant table: 'uniform-buffer fallback not built yet'). Affected: `d3d12_compute`, `d3d12_buffer_uav`, `d3d12_m4_compute` (fail at CreateComputePipelineState), `d3d12_fspx_compute`, `d3d12_set0_compute` (self-skip). Same failures occur on unmodified main — the iGPU's maxPushConstantsSize is 128. **GPU suite (`run_gpu_tests.py`):** - AMD iGPU (validation on, LEONIDA_PC_TAIL_UBO=1): 230/252 passed, 20 skipped, **2 failed — known pre-existing** `ms_clip`/`ms_wave_info_s3` AMD LLPC 0xC0000005 mesh-shader crashes (SHADER-167; fixes in open #802/#808). **0 Vulkan validation errors.** - NVIDIA RTX 4070 SUPER: 203/252 passed, 49 skipped, **0 failed**. 0 validation errors. **Verdict: verified.** Structured-buffer SRV bounds-mode-0 records produce no validation errors and no regressions; every runnable buffer/SRV test passes on both GPUs.
Author
Owner

@⁠iFeyz on GitHub · 2026-11-24 19:51 UTC · original

AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo.

Head 8fc4abbf0: d3d12_compute built from it passes (no build error or warning in the touched files).

**@⁠iFeyz** on GitHub · 2026-11-24 19:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#issuecomment-7142679015) AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo. Head `8fc4abbf0`: `d3d12_compute` built from it **passes** (no build error or warning in the touched files).
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:18 UTC · original

Recommendation: [MERGE]

Reasoning: Structured-buffer SRVs now use bounds mode 0 so a field read at the end of a record cannot spill into the next record; test and cs_user_data.comp extended with cross-record cases. Small runtime change with real correctness impact on shader memory reads. Independently verified on NVIDIA RTX 4070 Ti, RTX 4070 SUPER and AMD RX 9070 XT. Coordinate with #220/#1195 (SRV validation), which touch the same area. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 5/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#issuecomment-7143336523) **Recommendation:** [MERGE] **Reasoning:** Structured-buffer SRVs now use bounds mode 0 so a field read at the end of a record cannot spill into the next record; test and `cs_user_data.comp` extended with cross-record cases. Small runtime change with real correctness impact on shader memory reads. Independently verified on NVIDIA RTX 4070 Ti, RTX 4070 SUPER and AMD RX 9070 XT. Coordinate with #220/#1195 (SRV validation), which touch the same area. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 5/10
Author
Owner

@⁠Moriz82 on GitHub · 2026-11-25 03:41 UTC · original · edited 2026-11-25 04:01 UTC

Current main has the structured SRV mode-0 check in write_buffer_srv and includes this PR’s compute regression cases. #984 brought in the behavior and tests. The remaining conflict is with the refactored SRV path and the expanded bounds documentation, so this branch would duplicate what is already on main.

On 8fc4abb, Runtime, CI, and No Game Data ran zero jobs while awaiting maintainer approval. The conflict-label job was cancelled before it reached a runner. I rechecked 5129be10; the trial merge adds no changes to either regression test file. Main already selects mode 0 for structured SRVs and documents the field-offset limit.

AI-assisted.

**@⁠Moriz82** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1097#issuecomment-7152147491) · edited 2026-11-25 04:01 UTC Current main has the structured SRV mode-0 check in `write_buffer_srv` and includes this PR’s compute regression cases. #984 brought in the behavior and tests. The remaining conflict is with the refactored SRV path and the expanded bounds documentation, so this branch would duplicate what is already on main. On `8fc4abb`, Runtime, CI, and No Game Data ran zero jobs while awaiting maintainer approval. The conflict-label job was cancelled before it reached a runner. I rechecked `5129be10`; the trial merge adds no changes to either regression test file. Main already selects mode 0 for structured SRVs and documents the field-offset limit. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.