Skip to content

Runtime: texture views and samplers go into the bindless set (M2, the device's part) - #328

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
aslan2142:d3d12-views
Nov 21, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
aslan2142:d3d12-views

Conversation

@aslan2142

Copy link
Copy Markdown
Contributor

Claimed in #156 as: D3D-5 (second part; the first was #230)

What it does

  • CreateShaderResourceView and CreateUnorderedAccessView of textures write a T# into the heap slot. CreateSampler writes an S#.
  • Each view or sampler goes into the device's bindless set 0, and its key into the descriptor hash table. The key is the slot's bytes, so a copied descriptor needs nothing more.
  • A destroyed texture takes its views and keys out again.
  • Every ExecuteCommandLists flushes the set first.
  • With the set, a texture's shader-resource states use GENERAL, so a descriptor's one layout is always right.

What it does not do

Tests

d3d12_descriptor_test, through the Xbox-ABI proxy:

  • It decodes what the slots hold: a 2D view, a sampler, a BGRA cube view with a component mapping, an unordered-access view, null descriptors.
  • It runs a compute shader on the device's set. The shader looks a slot's T# and the sampler's S# up in the hash table and samples. The texture comes back texel for texel through the view's slot and through a copy of it.
  • An unknown descriptor, and the view's bytes after its texture is destroyed, give the fallback.
  • The layer has no pipelines yet, so the test creates that one pipeline in Vulkan.
  • Removing the hash-table insert, or the removal at destruction, makes the test fail.

Tested on

  • RX 7900 XTX (RADV, Mesa 26.3.1), validation layer on. The Windows-only tests were cross-built with mingw-w64 and run under Wine. Not built with MSVC here.
  • CI's steps run locally: the standard-library and pytest suites, the Linux build against Vulkan 1.3.275 headers, and the build without Vulkan.

AI-assisted (Claude Code, Claude Fable 5.2).

@evilclanker9000

Copy link
Copy Markdown
Contributor

Two findings on 8623043, tested on Windows 11 x64 with MSVC 19.44.35230, Vulkan SDK 1.4.350.0 and an RTX 5080 (driver 616.92).

  1. The unmodified checkout fails to build d3d12_descriptor_test with C2397 at d3d12_vulkan_device.cpp:221. MSVC rejects the conditional VkImageAspectFlagBits expression in the VkImageAspectFlags aggregate field as narrowing. Wrapping the conditional in VkImageAspectFlags(...) in a private copy was sufficient to build the target. With just that local change, the test ran on the 5080 with Khronos validation enabled and passed its original, copied, unknown and destroyed-view checks.
  2. The current readback cannot detect a missed S# lookup. In that private build, I changed only smp = lookup(sampler_key) to smp = 0u in cs_sample.comp. The test still passed. Its point/clamp sampler and the fallback yield the same texels at the sampled coordinates.

A small control made the sampler identity observable. I set the D3D12 sampler's U mode to WRAP, kept V/W at CLAMP, updated the decoded address-mode assertion, and added 1.0 to the sampled U coordinate. The existing expected texels then worked unchanged. The real lookup matched all 128 comparisons (64 from the original and 64 from the copy). Forcing sampler index zero produced 112 mismatches and exit 1. At texel 0, both reads returned RGBA8 (224, 0, 135, 255) instead of (0, 0, 128, 255), as expected from the fallback clamping U to the right edge.

aslan2142 added a commit to aslan2142/Leonida that referenced this pull request Nov 21, 2026
…lookup

Two findings from the review of ItsNotRexed#328, on MSVC 19.44 and an RTX 5080.

- bind_image did not compile with MSVC (C2397): the view's aspect, picked
  between two VkImageAspectFlagBits values, went into a VkImageAspectFlags
  field in braces. MSVC's enums are ints, so that is a narrowing
  conversion there; GCC and clang give the enum an unsigned type and accept
  it. The value is cast now.
- d3d12_descriptor_test passed with the sampler index forced to 0, because
  its point, clamping sampler and the fallback sampler read the same
  texels. The test's sampler now wraps in U and the shader samples one
  tile to the right: the right sampler gives the texture, the fallback its
  right edge. With the index forced to 0 the test fails (texel 0 reads
  224, 0, 135, 255 instead of 0, 0, 128, 255).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Contributor Author

Thanks @Vonsek, both findings are right. Fixed in d7ef6e4.

1. MSVC build (C2397)

  • The aspect in bind_image is now cast to VkImageAspectFlags, the change you made locally.
  • I can't build with MSVC here, and GCC and clang accept the old line (their enum is unsigned), so I could not reproduce it. Could you confirm the new head builds?

2. Sampler lookup

  • I adopted your control: the test's sampler wraps in U (V and W clamp), and the shader samples one tile to the right.
  • With the real lookup all 128 comparisons match. With the sampler index forced to 0 the test fails, and texel 0 reads (224, 0, 135, 255) instead of (0, 0, 128, 255), the same as you saw.

Re-tested on an RX 7900 XTX (RADV, Mesa 26.3.1) with validation on, built with mingw-w64 and run under Wine.

AI-assisted (Claude Code, Claude Fable 5.2).

aslan2142 and others added 2 commits November 21, 2026 18:28
… device's part)

The device now keeps set 0 of the translated shaders and puts into it what
views and samplers name. No pipeline binds the set yet: that comes with
the compute path. Until then rt::d3d12::bindless_set / bindless_set_layout
hand it out.

- Device: CreateShaderResourceView and CreateUnorderedAccessView of
  textures write a T# into the slot, CreateSampler an S#
  (gfx10_descriptors.h); each makes sure set 0 has the view or sampler and
  the hash table has the key. The key is the descriptor's bytes, so a
  copied descriptor needs nothing more. A view that cannot be shown (a
  volume, a multisampled texture, the stencil plane, a range past the
  texture) leaves a null descriptor, which finds the fallback. A texture
  is named by an address of its own above 4 GiB that nothing dereferences;
  its keys are erased and its indices freed when it is destroyed.
- VulkanDeviceInfo::bindless says the Vulkan device has the features; the
  standalone device and the test helper enable them where the GPU has
  them, with samplerAnisotropy and samplerMirrorClampToEdge.
- Every ExecuteCommandLists flushes the set before its commands are
  written (VulkanContext::set_bindless_prepare).
- Layouts: a bindless descriptor has one image layout, but D3D12 samples a
  texture both in a shader-resource state and while promoted from COMMON
  (GENERAL here). With the set, a texture's shader-resource states use
  GENERAL too (ResourceBinding::sampled_in_general). This follows from the
  Vulkan rule for descriptor layouts; no test can see it broken, since the
  validation layer does not follow dynamic indices into runtime arrays.

Not done, and listed in docs/d3d12_vulkan.md: buffer and constant-buffer
views, 1D/3D/multisampled and stencil views, descriptors the game writes
itself, static samplers and shaders' literal S#s, and holding back a flush
that moves table entries while earlier command lists still run.

Test: d3d12_descriptor_test, through the Xbox-ABI proxy. It decodes what
the slots hold (a view of an uploaded 8x8 texture, a sampler, a BGRA cube
view with a component mapping, an unordered-access view, null
descriptors). Then a compute shader (test/glsl/cs_sample.comp, compiled
with glslangValidator where it is found) is handed a slot's T# and the
sampler's S#, looks them up in the hash table as a translated shader does
and samples; the test creates that pipeline in Vulkan and binds the
device's set. It reads the texture through the view's own slot and
through a copy of it, and gets the fallback from a slot of bytes no view
was made for and, once the texture is destroyed, from the view's own
bytes. Without the table insert, or without the removal at destruction,
the test fails. The test no longer compiles d3d12_xs_device.cpp itself:
the COM library has it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…lookup

Two findings from the review of ItsNotRexed#328, on MSVC 19.44 and an RTX 5080.

- bind_image did not compile with MSVC (C2397): the view's aspect, picked
  between two VkImageAspectFlagBits values, went into a VkImageAspectFlags
  field in braces. MSVC's enums are ints, so that is a narrowing
  conversion there; GCC and clang give the enum an unsigned type and accept
  it. The value is cast now.
- d3d12_descriptor_test passed with the sampler index forced to 0, because
  its point, clamping sampler and the fallback sampler read the same
  texels. The test's sampler now wraps in U and the shader samples one
  tile to the right: the right sampler gives the texture, the fallback its
  right edge. With the index forced to 0 the test fails (texel 0 reads
  224, 0, 135, 255 instead of 0, 0, 128, 255).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@MrCheese5

Copy link
Copy Markdown
Contributor

Tested d7ef6e4 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 15/15 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

This is an MSVC build, which the PR description says hadn't been tried yet.

No game files used. AI-assisted run (Claude Code).

@0xTehuti 0xTehuti 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.

Independent Windows Hardware Test & Review (D3D-5: Texture views and samplers into bindless set, M2)

Tested and verified on Windows 11 with an NVIDIA GeForce RTX 2070 SUPER (Driver 595.79, Vulkan 1.4.321) in isolated worktree D:\Workspaces\Leonida-pr328 (d7ef6e4), providing native Windows MSVC hardware test coverage for the author (who cross-compiled via MinGW/Wine).


Hardware & Toolchain Environment

  • OS: Windows 11 Pro 24H2 (x64)
  • GPU: NVIDIA GeForce RTX 2070 SUPER (8203 MB dedicated VRAM)
  • Driver: NVIDIA 595.79 (Vulkan 1.4.321, WDDM 3.2)
  • Toolchain: MSVC 2022 v14.44 (19.44.35225) + Ninja 1.13 + CMake 3.31 (RelWithDebInfo)
  • Flags: /std:c++20 /W4 /permissive- /utf-8

Compilation Results

  • 99 / 99 targets compiled cleanly under MSVC.
  • Diagnostics: 0 errors, 0 warnings under /W4 /permissive- /utf-8.

Test Execution Summary

Test Target / Suite Status Execution Summary
d3d12_descriptor_test.exe PASSED Verified through Xbox-ABI proxy: slot copies matched; texture views (2D SRV, BGRA cube with component mapping, UAV, null descriptors) and samplers wrote expected GFX10 T# and S# bitfields; invalid view rejection handled gracefully.
CTest Suite (15 / 15) PASSED 100% pass rate (loader, pe_loader, device_proxy, root_sig, command_list, descriptor_table, bink_decode, bink_audio, xmem, xgameruntime, root_signature, root_signature_oracle, d3d12_gcl8, d3d12_state_map, gfx10_descriptors).
d3d12_com_test.exe PASSED 16 colour, depth and stencil texels matched; queue wait held GPU.
d3d12_vulkan_device_test.exe PASSED All copy, upload, footprint, and device tests passed.

Execution Log Excerpt:

device: NVIDIA GeForce RTX 2070 SUPER
descriptors: copies matched; views and samplers wrote the T#s and S#s expected; the sampling shader was not built (no glslangValidator)

Clean, robust MSVC compilation and verified execution on Windows 11 hardware. LGTM!


AI-assisted verification following repository guidelines (AGENTS.md).

@ItsNotRexed
ItsNotRexed merged commit e70a4f3 into ItsNotRexed:main Nov 21, 2026
8 checks passed
NRXM added a commit to NRXM/Leonida that referenced this pull request Nov 22, 2026
README: the GPU-test row counts the 30+ entries now in ItsNotRexed#166 (adds AMD
GCN3/RDNA1/RDNA4, Intel Gen9, llvmpipe) and drops the cs_w64x_partial
note that ItsNotRexed#204 fixed; the translation row says wave64 emulation makes
compute and mesh exact on 32-wide GPUs; the texture row names the
BCPack decoder from ItsNotRexed#312 and that the export doesn't use it yet; the
D3D12 row lists texture views, samplers and resolves (ItsNotRexed#228, ItsNotRexed#328).
docs/design.md: the TTPF row points at the decoder instead of calling
BCPack the hard blocker. docs/textures.md: drop the superseded
'no decoder is added' paragraph left above the new one.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D7JEiKsTUaHQbCTdc4Eghy
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…-25)

The CPU handle's slot is read while recording as the GFX10 T#/V# a shader
would load (docs section 3.4), so the clear works with whichever view
creation lands (#157, #328, #334) and with game-built descriptors.

- Buffers: vkCmdFillBuffer for elements up to 4 bytes, with the unaligned
  ends copied from the filled middle; 8/16-byte elements are written with
  vkCmdUpdateBuffer and doubled with copies. Rects are element ranges.
- Textures: vkCmdClearColorImage for whole views, vkCmdClearAttachments
  for rects (UAV textures also get COLOR_ATTACHMENT usage when the format
  supports it), in place in GENERAL; mip and layer range from the T#.
- Values follow D3D's Uint (raw low bits) and Float (converting) rules,
  encoded in the view's format and cleared into the image as the value
  that decodes those bytes in the image's own format (typeless resources).
- d3d12_uav_clear_test: hand-computed conversion checks, then raw,
  structured and typed buffers and 2D, array and volume textures cleared
  and read back through D3D12; refusals at record and replay.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants