Skip to content

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

Closed
Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/shader-buffer-bounds
Closed

Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/shader-buffer-bounds

Conversation

@Moriz82

@Moriz82 Moriz82 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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

…ER-BUFFER-BOUNDS)

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 <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Plaaasma

Copy link
Copy Markdown
Contributor

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.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@whoalin1

Copy link
Copy Markdown
Contributor

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):

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.

@iFeyz

iFeyz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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).

@Deedlyy

Deedlyy commented Nov 24, 2026

Copy link
Copy Markdown

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

clquwu pushed a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…984 LAYOUT_UNDEFINED, Wave-21b CMake & leonida-ce 525c44e1 ReadFile fast-path

- ProjectLeonida/mandy#1100 (RT-PLACED-IMAGE-DEFER): unify Resource deferred memory binding onto leonida::DeferredImageBinding (deduping duplicate flags/mutex), add LEONIDA_PLACED_IMAGE_DEFER=0 rollback, defer placed depth/UAV/RT attachments + cpu_copy bind + race-free memory_flags(), preserve MemoryPriority, add check_placed_target_backing test & docs/d3d12_vulkan.md note.
- ProjectLeonida/mandy#1099 (RT-STREAM-TRANSFER-BARRIER): deduped against existing ultimate CopyBuffer/CopyResource transfer barriers; add LEONIDA_ORDER_BUFFER_COPIES=0 opt-out toggle, --expect-unordered test mode, and docs/d3d12_vulkan.md note.
- ProjectLeonida/mandy#1097 (SHADER-BUFFER-BOUNDS): use OobSelect::structured_with_offset for structured buffer SRVs in d3d12_vulkan_device.cpp, add cross-record GPU readbacks in d3d12_compute_test.cpp + cs_user_data.comp (and align Xbox slot-17 CBV expectations with wave18b vector-row encoding).
- ProjectLeonida/mandy#1096 (RT-STARTUP-TRACE): add VirtualQuery memory region metadata on access violations in startup_trace.h & startup_trace_test.cpp.
- ProjectLeonida/mandy#1023 & #1007: update docs/directstorage.md (measured factory IID & slot 8) and docs/d3d12_vulkan.md (device slot 62 5-arg arity & slot 76 FFX-only note).
- Wave-21b deferred CMake: add loader TIMEOUT 180 (Reforge#169) and tiny_game_ga / run_tiny_game_ga_tls (ubiq#947 Patch 2).
- ProjectLeonida/mandy#984 (self-contained Windows-native port): accept enhanced TextureBarrier into LAYOUT_UNDEFINED without violating VUID-VkImageMemoryBarrier2-newLayout-01198 (command_list.h, vulkan_replay.h, command_list_test, replay_texture_barrier_test, d3d12_close_parity_test).
- IAmNotSiob/leonida-ce 525c44e1 (GPL-3.0, deduped): wire optional xmem::commit_physical_range_fn hook into file_system.cpp ReadFile ERROR_NOACCESS retry path to commit large console buffers without per-page VEH faults while keeping zero-cost fast path and touch_pages fallback.
- DesignWithTommy/Neonbridge eaf7e7e0: audited and skipped (ultimate has no refresh read-back byte/time cap skipping Bink R8/R8G8 planes).
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@Moriz82

Moriz82 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

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 Moriz82 closed this by deleting the head repository Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants