Skip to content

runtime: give unknown-dimension views a default view and skip mismatched ones - #2649

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
pigalot:d3d12/unknown-view-dimension
Nov 26, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
pigalot:d3d12/unknown-view-dimension

Conversation

@pigalot

@pigalot pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Change

Slice 3 of 4 from #2591.

On desktop D3D12, a view description with ViewDimension 0 (UNKNOWN) removes the device instead of
failing the call. A dimension that does not suit the resource does the same (debug layer: "The
ViewDimension in the View Desc is incompatible with the type of the Resource"). A console package
module made such SRVs on 2D RGBA8 textures. The views of device slots 18 to 21 (SRV, UAV, RTV, DSV)
are now checked before they are forwarded (src/startup_stubs/view_dimension.h):

  • Dimension 0: the view gets the resource's default view (a null description) where desktop
    allows one. Desktop does not allow one for buffers, typeless or unknown formats, or depth formats in
    an SRV, so those views are skipped and logged.
  • Mismatched dimension: a view whose dimension needs a different resource dimension than the
    resource has is skipped and logged.
  • Diagnostic: when a view of these slots still removes the device, the wrapper logs the forwarded
    description bytes and the resource's shape (removing view desc).

A skipped view is recorded unmaterialized, the same way as the existing "resource lacks ..." skips.

Refs #2591. Independent of the other three slices.

Verification

Build: this branch, one commit 639895a2 on main at 02368737. From the worktree in PowerShell:
. .\tools\dev.ps1, cmake --preset release, cmake --build --preset release (Python env
out/pe-env from requirements-dev.txt).

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974. The new fixture
creates no device.

  • ctest --preset release --no-tests=error -R '^startup_view_dimension(_control)?$' -V: 2/2 passed.
    The control prints 12 FAIL: lines.
  • ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_': 640 tests, 634 passed, 6 skipped (capability, exit 77), 0 failed. (Run before a final amend that only moved an #include / CMake block to avoid a merge conflict with the sibling slices; the slice's own tests were rerun after it and pass.)
  • python -B tests/docs_links_check.py: pass (19 Markdown files, 507 links).
    python -B tests/bidi_controls_check.py: pass. git diff --check origin/main...HEAD: clean.

Evidence

startup_view_dimension (from #2591, unchanged) checks view_dimension.h on the public d3d12.h
enumerations. It covers which resource dimension each SRV/UAV/RTV/DSV dimension needs, and when a
dimension-0 view may become the default view. --control swaps the resource dimension of the
mismatched cases for the matching one, so the refusal rows print FAIL:. The test is registered with
PASS_REGULAR_EXPRESSION "FAIL: ".

Measured in a start-up run with a local console executable (not included), on the Series S profile:
with dimension 0, the module's SRVs removed the device. With this change they get the default view and
the run continues (#2591). The wiring in view_slot has no source-built device fixture. The test
covers the decision, not the forwarded call.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

…hed ones

Desktop D3D12 removes the device for a view description with
ViewDimension 0 (UNKNOWN) or a dimension that does not suit the
resource, instead of failing the call. A console package module made
such SRVs on 2D RGBA8 textures.

Views of device slots 18 to 21 are now checked first (view_dimension.h):
dimension 0 gets the resource's default view (null description) where
desktop allows one, else the view is skipped; a mismatched dimension is
skipped. Both are logged, and a view that still removes the device logs
its forwarded description and the resource's shape.

New fixture with a negative control: startup_view_dimension; the control
swaps the resource dimension of the mismatched cases.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of head 639895a against main (comment only).

Code read: src/startup_stubs/view_dimension.h, the view_slot wiring in d3d12_xs_device.cpp, tests/startup_view_dimension_check.cpp.

  • The SRV/UAV/RTV/DSV dimension tables match the public d3d12.h numbering. The description offset (args[2] for slot 19, args[1] otherwise) is consistent with the existing code.
  • The default-view rules (no buffers, no typeless or unknown formats, no depth format in an SRV) match desktop behavior. The skips go through the existing "unmaterialized" path.
  • Other open or merged PRs on the same slice: none found (only the parent #2591 and the earlier #1677 / #2338, which are different).

Commands run locally on the exact head:

  • g++ -std=c++17 -Isrc tests/startup_view_dimension_check.cpp: ok; --control prints 12 FAIL: lines.
  • Mutation: SRV dimension 8 mapped to texture2d makes the test fail (4 FAIL). Removing the typeless/unknown-format refusal makes it fail (3 FAIL).
  • python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py, git diff --check origin/main...HEAD: all clean.

Findings:

  • The fixture covers the decision header only. The view_slot wiring (default_view, args[desc_index] = 0, the skip, the removing view desc log) has no source-built fixture, as the PR body says. Nothing here shows the null description reaches the real call.
  • The PR says the change lets a console module's start-up run continue. That is an executable claim that I cannot check. Only the fixture results are reported here. I did not run Win2025, and I am not merging this.
  • The merge stays with MasterDomino or @R0Y00, who can verify the start-up claim on the game.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The CPU table establishes dimension classification. The production fallback also strips the entire view description, including its requested format and component mapping, for four slot families. The reported SRV observation does not establish that contract for UAV, RTV or DSV. Please narrow the initial fallback to the evidenced typed SRV case or gate the wider mapping as an explicit experiment. Add a source-built wrapper test that samples a distinct colour through the created SRV, proves an incompatible explicit view is refused without device removal, and verifies that a rejected replacement cannot later bind the old valid descriptor from the same slot. Keep the existing resource and live-descriptor lifetime checks.

… refused SRVs

The default view for a view description with ViewDimension 0 replaces
the whole description, including its format and component mapping.
Only the shader resource view case is measured, so by default only
slot 18 views of typed, non-depth textures get it. UAV, RTV and DSV
descriptions with dimension 0 are skipped unless the experimental
X2W_D3D12_VIEW_DEFAULTS=all is set; =off skips the SRV case too.

A refused SRV now writes a null SRV into its destination descriptor.
The skipped call used to leave the slot's previous descriptor there,
bindable and copied by CopyDescriptors, after the slot's record had
dropped the reference that kept its resource alive.

New fixture startup_view_dimension_warp (and _hardware) through
d3d12_xs.dll: an unknown-dimension SRV samples its texture's colour,
an explicit TEXTURE3D SRV of a 2D texture is refused without device
removal, and a refused replacement over a valid view reads zero, as
does a copy of that slot. startup_view_dimension_off_control_warp
runs it with X2W_D3D12_VIEW_DEFAULTS=off and must fail on the missing
default view alone, with the device not removed.
@pigalot

pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed in c759b14 (new commit on top of 639895a, no rebase).

1. Fallback narrowed to the evidenced typed-SRV case

  • view_dimension.h: default_view_allowed() now takes a DefaultViews mode. The default (srv) allows the default view only for slot 18 (CreateShaderResourceView) on a texture with a typed, non-depth format. That is the observed case.
  • UAV, RTV and DSV descriptions with ViewDimension 0 are now skipped by default. The skip log says that a default view of that type needs X2W_D3D12_VIEW_DEFAULTS=all.
  • X2W_D3D12_VIEW_DEFAULTS=all turns on the wider mapping as an explicit experiment. =off also skips the SRV case, and the negative control uses it. Any other value, or none, is srv.
  • The docs (switch table and "Unknown and mismatched view dimensions") now say that the default view drops the requested format and component mapping, and that only the SRV case is measured.
  • The CPU table (startup_view_dimension) adds checks for the gate (slots 19 to 21 refused under srv, everything refused under off) and for the env parsing. Its --control turns the gate on for all slots, so those three checks print FAIL:.

2. Source-built wrapper test: startup_view_dimension_warp (also _hardware), tests/startup_view_dimension_device.cpp

The test goes through d3d12_xs.dll!D3D12XboxCreateDevice, the same way as startup_resource_retire_views. A compute probe on the fixture's own desktop queue samples (0,0) with a point sampler through each slot of a shader-visible guest heap, using the desktop heap behind it.

  • (a) The test makes an SRV through slot 18 with ViewDimension 0 and format R32G32B32A32_FLOAT. The texture is an R8G8B8A8_UNORM texture filled with (51,153,204,255). It reads back 0.200 0.600 0.800 1.000.
  • (b) An explicit TEXTURE3D SRV of the 2D texture is refused. GetDeviceRemovedReason returns S_OK afterwards on both the desktop device and the wrapper (slot 37).
  • (c) Contract for a refused replacement: a refused SRV, for any reason, writes a null SRV into its destination descriptor. The null is R8G8B8A8_UNORM and takes the requested dimension when it is a texture dimension, else 2D. It reuses the null description that X2W_D3D12_RELEASE_RETIRED_VIEWS already writes.
    • Before this change, the skipped call left the slot's previous desktop descriptor in place. That descriptor was still bindable and was copied by CopyDescriptors, while record_view(false) had already dropped the reference that kept its resource alive.
    • The test puts a valid view of a second texture (255,64,0,128) in a slot and reads it back. It then sends a refused TEXTURE2D SRV of a buffer into the same slot. The device is not removed and the slot reads 0 0 0 0.
    • A CopyDescriptorsSimple (slot 24) of that slot over another valid view also reads 0 0 0 0.
  • Negative control: startup_view_dimension_off_control_warp runs the same fixture with X2W_D3D12_VIEW_DEFAULTS=off. It must print FAIL: (a) default view reads 0.000 0.000 0.000 0.000, expected 0.200 0.600 0.800 1.000; device not removed followed by cases complete. FAIL_REGULAR_EXPRESSION rejects any setup failure, any failure in (b) or (c), and any device removal. Without WARP, all of these return 77.

3. Resource and live-descriptor lifetime checks kept

No existing test was changed except the CPU table, which gains the mode argument and new checks; no existing check was removed or relaxed. retire_null_srv_desc now calls the shared null_srv_desc() and produces the same description as before. The retire, retire-views, retire-title, null-views and view-census tests all pass (below).

Mutation checks (each reverted afterwards):

  • Removing args[desc_index] = 0 for the default view makes startup_view_dimension_warp fail with FAIL: (a) the unknown-dimension SRV removed the device.
  • Removing the null write on refusal makes it fail with FAIL: (c) slot after the refused replacement reads 1.000 0.251 0.000 0.502, expected null (all zero); device not removed. The copy check fails the same way.

Commands and results (commit c759b14; release preset; NVIDIA GeForce RTX 5090, driver 32.0.16.1088; Windows 10.0.26200.9974; debug layer off; WARP = Microsoft Basic Render Driver)

. .\tools\dev.ps1
cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error -R 'view' -V

54 tests: 50 passed, 4 capability skips, 0 failed. Skips: startup_view_heap_warp and startup_logical_view_warp (the adapter accepts the descriptor count directly), spirv_sampler_views_warp and spirv_sampler_views_hardware (SPIR-V tools not installed). The new tests passed: startup_view_dimension, startup_view_dimension_control, startup_view_dimension_warp, startup_view_dimension_hardware (RTX 5090) and startup_view_dimension_off_control_warp.

ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_'

642 tests: 636 passed, 6 capability skips, 0 failed. Skips: startup_gameinput_script_syntax, startup_logical_view_warp, startup_run_sh, startup_sharedexp_target_warp, startup_small_texture_4k_addrlib and startup_view_heap_warp.

python -B tests/docs_links_check.py      # 19 Markdown files, 508 links: ok
python -B tests/bidi_controls_check.py   # 1869 files: no bidirectional controls
git diff --check origin/main...HEAD      # clean

Not addressed here: a refused UAV, RTV or DSV still leaves its slot's previous descriptor in place. The reported observation and this fixture cover SRVs only, so I kept this change to slot 18.

New head: c759b14

This change was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Windows Release passed all five view-dimension cases at ae6aa4a, including WARP and RTX 4060 Laptop. The typed SRV samples its expected color. The mismatched SRV remains harmless and both the replaced slot and its copy return zero. The added UAV case failed on c759b14 because the refused replacement changed the token while the desktop descriptor stayed live. It now preserves the old token on both adapters. The off control distinguishes the missing default view from other failures.

@R0Y00
R0Y00 merged commit b256401 into R0Y00:main Nov 26, 2026
5 checks passed
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.

3 participants