Skip to content

d3d12: enforce Vulkan BC image-view compatibility classes - #2223

Open
GGandCo wants to merge 6 commits into
ProjectLeonida:mainfrom
GGandCo:fix/bc-image-view-classes
Open

GGandCo wants to merge 6 commits into
ProjectLeonida:mainfrom
GGandCo:fix/bc-image-view-classes

Conversation

@GGandCo

@GGandCo GGandCo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Claim: RT-BC-VIEW-COMPATIBILITY (#1608, #1608 (comment)).

Same-sized compressed blocks were treated as compatible Vulkan image views. In particular, BC6H could enter a BC7 image's format list, and matching channel order could resolve BC7 to a BC1 view. These violate Vulkan compatibility classes even when the block footprint matches.

Restrict BC view resolution and castable lists to each codec's Vulkan compatibility class. Numeric twins within a codec use mutable images. CPU-filled streamed textures requested in another same-footprint BC codec get a replacement image in that requested codec, retaining their original console layout for byte addressing and removing retired codecs from the new format list. Existing uncompressed casts remain unchanged.

Validation:

  • Current-main negative control (db1a22d29 header with the new synthetic descriptor test) fails the BC class invariant; the fixed test passes.
  • Clean contribution build: gfx10_descriptors and d3d12_bc_stream_views pass with LEONIDA_VK_VALIDATION=1 on Intel UHD Graphics, driver 32.0.101.6314, Windows 11. The stream fixture registers BC7 sRGB, BC6H unsigned/signed, then BC7 linear at one synthetic allocation, checks nonzero descriptor indices, and retires the images without validation errors.
  • Combined local integration: texture UAV, view slices, textured M2, and descriptor tests passed. This is additional integration evidence, not a full-suite result.
  • git diff --check and check_no_game_data.py passed.

Limits: the new stream fixture checks native view registration and lifetime, not sampled pixel readback. No main-menu, audio, frame-rate or playability claim. No game data included. The full runtime/translator suites were not run for this C++ image-view change.

GPUs tested: Intel UHD Graphics (32.0.101.6314), Windows 11.
AI-assisted with OpenAI Codex.

Updated onto main a73a57e in 348901f. Focused clean-tree tests repeated: 2/2 pass with Vulkan validation. Preserves upstream asynchronous mapped-plane fixture. Draft only because the repository limits non-maintainers to one ready-for-review PR; #2072 currently occupies that slot.

@GGandCo

GGandCo commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated to main a73a57e in 348901f. Resolved the test argument-parsing conflict by preserving both the BC-only fixture and upstream's asynchronous mapped-plane case.

Clean contribution build and focused tests repeated on Windows 11, Intel UHD Graphics 32.0.101.6314: gfx10_descriptors and d3d12_bc_stream_views both pass with LEONIDA_VK_VALIDATION=1 (2/2). git diff --check and check_no_game_data.py pass on the six changed files. No full-suite or sampled-pixel claim.

Kept as a draft because this repository limits users without write access to one open ready-for-review PR; #2072 occupies that slot. This is the reason the prior ordinary PR-creation API requests were denied.

AI-assisted: OpenAI Codex.

@ecox982745

Copy link
Copy Markdown
Contributor

All 1,024 sampled texels matched on an RTX 4090 (Windows 11, NVIDIA 616.64) at 348901f79. The two stock tests, gfx10_descriptors (CPU) and d3d12_bc_stream_views (GPU), passed. I then extended the descriptor test locally to read the pixels from the bindless texture views.

For each step, I registered a new slot-70 view of the same 8 × 8 allocation, submitted a command list, waited on its fence, and sampled the 64 texels. A separate allocation created directly in the requested format held identical bytes and provided a fresh reference for each step.

View sequence on one allocation Result per run
BC7 sRGB → BC6H unsigned → BC6H signed → BC7 linear → BC7 sRGB 320/320 matched. The four formats produced four distinct reference images. Returning to sRGB reproduced the first image.
BC2 → BC3 → BC2 192/192 matched. I also checked every reference texel against the expected red and alpha values derived directly from the synthetic block.

I ran this once with staged uploads configured and once with host image copy enabled and staging disabled. Both used synchronous fills. Both completed descriptor retirement and device destruction with exit 0 and no Khronos validation messages in the full logs. This covers synthetic point-sampled RGBA8 output at the tested revision.

@lixonik lixonik 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.

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

The Vulkan BC image-view compatibility class mapping cleanly covers the consecutive UNORM/SRGB pairs across BC1_RGB..BC7_SRGB, and the new stream-view and descriptor coverage passes on real Vulkan hardware.

Tests run

  • ctest --output-on-failure -R ^(gfx10_descriptors|d3d12_bc_stream_views|d3d12_existing_heap)$: 3/3 passed (d3d12_existing_heap 9.87 s, d3d12_bc_stream_views 3.28 s, gfx10_descriptors 0.07 s).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).

AI-assisted (Antigravity, Gemini).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

On physical gfx906 (RADV Mesa 26.0.8, Linux Wine 11.0), main 1bc055e6c could sample 2/4 formats requested in turn at one synthetic allocation. It proposed BC6H in a BC7 image format list; the test intercepted both incompatible requests before forwarding them to Vulkan. With 348901f79 merged, all 4/4 worked: BC7 sRGB, BC6H unsigned, BC6H signed, then BC7 linear. All 256 texels (1,024 float components) matched separately uploaded same-format references bit for bit.

The observer sampled the actual VkImageView handles published by the runtime. This verifies registration, replacement and sampling, not a translated shader’s bindless lookup. Four separate-allocation controls passed on both builds; superseded views were retired after the fenced checks. Independently, across 448 host resolver cases checked against the Vulkan registry classes, main matched 200 and the merge matched 448. All 64 same-class mappings were preserved. Guards held; the final paired GPU runs had no validation errors or synchronization hazards.

AI-assisted.

@timbot103 timbot103 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.

Static audit of head 348901f79. No builds, tests, or GPU runs were performed.

The pairs in runtime/src/gfx10_descriptors.h match Vulkan's format compatibility classes, including separate BC1 RGB and RGBA classes. BC1 and BC4 have 8-byte blocks, and BC2, BC3, BC5, BC6H, and BC7 have 16-byte blocks. Vulkan permits size-compatible uncompressed block views, such as R32G32 or R16G16B16A16 for 8-byte blocks and R32G32B32A32 for 16-byte blocks, with VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT and the applicable view restrictions. The audited D3D12 cast-list path already checks block extent, and the PR leaves the separate copy path alone.

  • Major — runtime/shims/d3d12_vulkan_device.cpp:15373. Keep a slot-70 resource description at BC7 sRGB and request BC6H unsigned at its CPU-backed address. A subsequent DXGI_FORMAT_UNKNOWN SRV with the same description hits the cached BC6H image and still samples BC6H. On a cache miss the same request resolves to BC7 sRGB. Resolve the default format from the incoming resource description before checking the cache and carry that format through the owned stream's SRV write. Please add this sequence to the fixture and assert the encoded format.
  • Minor — runtime/test/d3d12_existing_heap_test.cpp:2103. The test can reach its BC7 allocation on a bindless device that lacks BC support and fail as a result. Use the harness's vk.bc capability check to skip this case with exit code 77.

AI-assisted.

@GGandCo

GGandCo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed timbot103's review in a0b9b0e. Stream-owned views now resolve DXGI_FORMAT_UNKNOWN from the incoming resource description before cache matching, and carry that resolved format through SRV publication. Slot-133 views keep their existing behavior.

The synthetic slot-70 fixture now inserts UNKNOWN after BC6H unsigned, BC6H signed, and BC7 linear requests and asserts the encoded descriptor format. The BC-only fixture also skips with exit 77 when the device lacks BC support.

Validation: rebuilt the clean contribution checkout with MSVC on Windows 11 / Intel UHD Graphics 32.0.101.6314. gfx10_descriptors_test and d3d12_existing_heap_test --bc-views-only both pass (2/2), with LEONIDA_VK_VALIDATION=1. git diff --check and check_no_game_data.py pass for both changed files. No full-suite or new pixel-sampling result claimed.

AI-assisted: OpenAI Codex.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@merzleckeier

Copy link
Copy Markdown
Contributor

AGENT-MSG | 2026-11-29 13:33 UTC | merzleckeier | AI-assisted: Codex

BASE: 51d343b86 + #2223 at a0b9b0e8e. The local merge kept main's view_mip argument and this PR's resolved stream_srv at both conflicting make_title_texture calls.
MACHINE: Radeon 610M (RADV Mesa 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.04) | CachyOS, Wine 11.22
EVIDENCE: MEASURED. Both stock tests (gfx10_descriptors and d3d12_bc_stream_views) passed on both GPUs.

I also checked the latest DXGI_FORMAT_UNKNOWN change with pixel readback through the existing GPU bindless hash test shader. One synthetic 8×8 slot-70 allocation had a BC7 sRGB resource description throughout. I requested BC7 sRGB → BC6H unsigned → UNKNOWN → BC6H signed → UNKNOWN → BC7 linear → UNKNOWN → UNKNOWN, submitting and fencing each view before reading its 64 texels. Each reference used the same bytes on its own allocation, with its format set in the resource description.

  • With the fix, 8/8 views matched per run, including 4/4 UNKNOWN views. All 2,048 texels matched across four runs, with each GPU tested once with staging forced and once with host image copy enabled and staging disabled.
  • With only default-format resolution in place_title_view reverted, 6/8 views matched in each of the four paired runs. UNKNOWN immediately after either BC6H view gave the wrong pixels and tripped the assertion. The first mismatching pixel in both cases matched the BC6H unsigned reference. The explicit views and the two later UNKNOWN views still passed.

The test drained descriptor retirement after each run. Host Khronos validation reported the known Wine device-creation VUID 01387 in both variants.

…ix/bc-image-view-classes

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
@GGandCo

GGandCo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main 4364a4f in 534b334. The two make_title_texture conflicts preserve main's view_mip argument and this PR's resolved stream_srv. The DXGI_FORMAT_UNKNOWN regression sequence and BC capability skip are retained.

Rebuilt the contribution checkout with MSVC on Windows 11 / Intel UHD Graphics 32.0.101.6314. gfx10_descriptors_test and d3d12_existing_heap_test --bc-views-only both pass with LEONIDA_VK_VALIDATION=1 (2/2). git diff --check and check_no_game_data.py pass for the PR source/test files. No full-suite result claimed.

Read merzleckeier's independent pixel-readback verification; thanks for checking the default-format fix on both GPUs.

AI-assisted: OpenAI Codex.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@merzleckeier

Copy link
Copy Markdown
Contributor

Linux/Wine follow-up on the published merge resolution in 534b33455, merged onto eedd72e30 (tree b5aeeb0d2). CachyOS, Wine 11.22, clang-cl/xwin, Radeon 610M (RADV Mesa 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.04).

  • The unmodified gfx10_descriptors_test and d3d12_existing_heap_test --bc-views-only passed on both GPUs.
  • The same synthetic Mip 0 readback fixture matched all 8 views on each GPU with forced staging and with host image copy. That is 2,048 compared texels total. All four UNKNOWN cases in each run matched the BC7 sRGB reference.
  • The only validation diagnostic was the same device-creation VUID-vkCreateDevice-ppEnabledExtensionNames-01387 from the earlier run.

AI-assisted with OpenAI Codex.

@ammonium231

Copy link
Copy Markdown
Contributor

RTX 3090 / 621.40, validation on, 534b334 merged onto main edf0ff5: gfx10_descriptors, d3d12_bc_stream_views and d3d12_existing_heap pass. The only validation report is the 93-object vkDestroyDevice leak in d3d12_existing_heap, same on plain main. bc_stream_views covers the native BC6H/BC7 views; the CPU-backed path isn't exercised.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/test/d3d12_existing_heap_test.cpp
@GGandCo

GGandCo commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Merged main f9f3ec4 into this branch in b3554e2 (no force-push). The texture-creation conflict keeps resolved stream_srv together with main's deferred index_now=false, incompatible GPU-owned eviction and explicit indexing. The fixture conflict preserves both the BC-only test and main's geometry-guard, GPU-copied texture and partial-mip tests and options.

Rebuilt gfx10_descriptors_test and d3d12_existing_heap_test with MSVC on Windows 11 / Intel UHD Graphics 32.0.101.7092. gfx10_descriptors_test and d3d12_existing_heap_test --bc-views-only both pass (2/2), with LEONIDA_VK_VALIDATION=1. git diff --check and check_no_game_data.py pass. No full-suite or new sampled-pixel result claimed.

Read all current issue/review comments, including ammonium231's latest independent RTX 3090 checks. Existing CI failures are not claimed fixed by this merge.

AI-assisted: OpenAI Codex.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
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.

7 participants