Skip to content

startup: size device view descriptions by the title record - #3552

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
KelboLive:fix/3536-view-record-width
Nov 30, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
KelboLive:fix/3536-view-record-width

Conversation

@KelboLive

@KelboLive KelboLive commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Change

view_slot() sized its own checks on a slot 18-21 description from the desktop header, and forwarded the
title's pointer to the desktop for the desktop to read at its width. The title supplies a 40-byte record;
the Agility SDK 1.620.2 header makes D3D12_UNORDERED_ACCESS_VIEW_DESC 48 bytes. A description ending
exactly at a readable page therefore failed the 48-byte readability test, the 3D mip range check was
skipped, and the desktop then read its own struct from a 40-byte record and removed the device with
DXGI_ERROR_INVALID_CALL (0x887a0001).

Two changes:

  • The shim's checks use the record width (ViewRecord::srv_desc_bytes, ViewRecord::uav_desc_bytes, 20 for
    a render target, 16 for a depth-stencil view), which is what note_view() already records for the same
    slots, with static_asserts holding each desktop struct to at least that width.
  • The record is copied into a zero-filled 64-byte buffer and that is forwarded, so the desktop can
    never read past the title's record. The null-view adaptation reads the same copy rather than the title
    pointer.

startup_view_dimension_device gains two cases that place the description at the end of a committed page
with a PAGE_NOACCESS page after it.

Verification

Base 44a3ad5aa. Agility SDK 1.620.2, WARP 1.0.22, NVIDIA GeForce RTX 4070 Ti SUPER (driver 32.0.16.2101).

ctest --test-dir out/build/warp-agility -R '^startup_view_dimension_' -V
Case Before After
Out-of-range 3D mip at an ordinary address refused, descriptor kept refused, descriptor kept
Out-of-range 3D mip at a page boundary device removed 0x887a0001 refused, descriptor kept
Valid 3D mip at a page boundary device removed 0x887a0001 created, device alive

The same three rows hold on warp and on hardware. The control row is what separates a working range
check from a skipped one; the middle row is the refusal the fixture expects.

Negative control: with the source change stashed and the fixture rebuilt, both boundary cases fail on
both adapters:

FAIL: (e) the page-boundary description removed the device
FAIL: (f) a valid description at the page boundary removed the device

No regression. The change touches every view creation, so:

# Agility tree
ctest --test-dir out/build/warp-agility -R 'view|descriptor|uav|srv'
100% tests passed out of 236

# In-box tree, complete non-hardware suite
ctest --preset dev --parallel 4 -E '_hardware$'
99% tests passed, 5 tests failed out of 2224   (2169 passed, 50 skipped)

All five in-box failures are on main already and unrelated: native_cvt_f16_i16_{ir,controls} and
native_sdwa_profiles_{ir,dxil} (issue #3547) and startup_triage_run (#3546). Each startup_view_dimension_*,
startup_null_views_* and startup_present_view* entry passed.

Why CI cannot see this

In-box headers already report 40 bytes, so the check succeeded before and after and the fixture passes in
both Windows jobs. The reproduction needs the Agility configuration. The three earlier instances of this
40/48 split are #3510 and #3523 (merged) and #3536 (issue); this closes the device-slot instance.

Measured detail and the case table are also recorded in docs/experiments/agility-compute-views.md.

Fixes #3536.

Follow-up at 386db6092

  • Review MUST: slots 20 and 21 now use sizeof(D3D12_RENDER_TARGET_VIEW_DESC) and sizeof(D3D12_DEPTH_STENCIL_VIEW_DESC) (24 each) instead of 20 and 16, which truncated ArraySize at offset 16 and PlaneSlice at 20.
  • Review SHOULD: record_view's width for those slots is the same 24, so recorded array RTV/DSV views keep their fields.
  • static_asserts pin both to 24 bytes, so the truncation cannot return silently.
  • Rebased onto 844e57d.

Verification at this head:

in-box:  ctest -R 'view|descriptor|depth|dsv'                          171/171
agility: ctest -R 'view|descriptor|uav|srv|rtv|dsv'                    247/250

The three Agility failures (startup_memory_srv_diag_{warp,hardware}, startup_compute_comparison_srv_warp) fail identically with this change stashed, so they are not from it.

@KelboLive

Copy link
Copy Markdown
Contributor Author

The Linux job's failure is inherited from main at 44a3ad5aa, not caused by this change:

FAIL source reasons missing from COMPUTE_DISPATCH_REASONS: 'an output UAV interval exceeds the D3D12 buffer view element limit'
FAILED: tests/startup_triage_run_check.py

That is the entry #3546 adds. #3535, #3538 and #3546 are green because their branches predate #3471; this PR is based on current main, so it carries the failure. Nothing here touches d3d12_compute_dispatch.inl or the triage reasons.

I will rebase this branch on main once #3546 lands and re-run the check, rather than duplicate the one-line fix here.

@KelboLive

Copy link
Copy Markdown
Contributor Author

Audited the rest of the shim for this class, so the answer to "is this the last one" is measured rather than assumed.

Compiled a probe that prints sizeof and �lignof for every struct the shim sizes or forwards, once against the in-box headers and once with -I out/build/warp-agility/agility-headers/build/native/include. Of 63 structs, exactly one differs:

inbox : D3D12_UNORDERED_ACCESS_VIEW_DESC   40  8
agility: D3D12_UNORDERED_ACCESS_VIEW_DESC   48  8

Everything else agrees: D3D12_SHADER_RESOURCE_VIEW_DESC, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC, the blend/rasterizer/depth-stencil descriptions, D3D12_GRAPHICS_PIPELINE_STATE_DESC, D3D12_COMPUTE_PIPELINE_STATE_DESC, the indirect argument and draw/dispatch argument structs, root signature and descriptor range descriptions, D3D12_RESOURCE_DESC, heap, barrier, rect, viewport, copy-location and subresource structs.

Cross-check of every remaining use of a UAV description in the shim:

Site Handling
iew_slot slots 18-21 this change: record width, zero-filled copy forwarded
compute output tokens (#3510) record width into a zero-initialised struct

|
esolve_pixel_uavs (#3523) | record width into a zero-initialised itle_view, with static_assert |
| pixel_uav_view (d3d12_draw.inl:107) | dereferences only Format, ViewDimension and the first union member, all inside the first 24 bytes |
| d3d12_draw.inl:3659, d3d12_compute_dispatch.inl:1331,1341 | pass a local struct, never a title pointer |

So the 40/48 split has no remaining instance. The probe is untracked scratch right now; I can add it under ools/ with the two compile lines if you would rather future SDK bumps be re-measured than re-audited by reading.

@R0Y00 R0Y00 added the priority: P0 Highest project priority label Nov 30, 2026 — with ChatGPT Codex Connector

@lukaslw-lab lukaslw-lab 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 a07bf2df by reading the diff; not built or run.

Verdict: changes requested. The SRV/UAV part is right. The RTV/DSV widths it reuses are too short, and since the copy is now always forwarded, array views lose fields.

  • MUST view_bytes takes 20 for slot 20 and 16 for slot 21 (src/startup_stubs/d3d12_xs_device.cpp:5655). Line 5664 now forwards that zero-filled copy for every view; before, it was forwarded only when the format was remapped, and then with sizeof (24) bytes.

    In the public d3d12.h layout (24 bytes in both the in-box and Agility headers, as your audit found), D3D12_DEPTH_STENCIL_VIEW_DESC has Flags at byte 8 and the union at 12. So the first 16 bytes stop after MipSlice. Under this PR:

    • Texture1DArray / Texture2DArray DSVs reach the desktop with FirstArraySlice = 0 and ArraySize = 0;
    • Texture2DMSArray DSVs get ArraySize = 0;
    • an RTV Texture2DArray loses PlaneSlice (bytes 20-23).

    An ArraySize of 0 is an invalid description, so shadow-map cascades or cube depth views break where they worked before. Fix: use sizeof(D3D12_RENDER_TARGET_VIEW_DESC) and sizeof(D3D12_DEPTH_STENCIL_VIEW_DESC) (24/24; the split is only 40/48 for UAVs) and keep the static_asserts.

  • SHOULD The same 20/16 comes from record_view (:5558, older than this PR), so recorded RTV/DSV views lack those fields too. That's worth fixing in the same line change. A test case with a Texture2DArray DSV of ArraySize > 1 through slot 21 would pin it. Today nothing creates an array RTV/DSV through the device slots, which is why the dev suite stayed green.

  • Checked, no finding:

    • Slots 18/19 at 40 bytes match ViewRecord.
    • The null-view adaptation now reads the copy, and with no readable description it is skipped as before.
    • desc_copy is zero-filled before the copy, so the 8 Agility-only UAV bytes are 0.
    • The format remap still writes into the same buffer.

Tests: (e) and (f) put a slot 19 description at a page edge. (e) proves the range check now reads 40 bytes; (f) proves the forwarded copy keeps the device alive. Neither reaches slots 20/21. CI did not run them: the Windows job uses the pr test filter, which leaves out startup_view_dimension_*. The in-box headers also could not show the 40/48 split, as the PR says.

view_slot() took the length of a slot 18-21 description from the desktop header and forwarded the
title's pointer to the desktop. With the Agility SDK 1.620.2 headers
D3D12_UNORDERED_ACCESS_VIEW_DESC is 48 bytes where the title supplies a 40-byte record: a
description ending at a readable page failed the 48-byte readability test, the 3D mip range check
was skipped, and the desktop then read its own struct from a 40-byte record and removed the device
with DXGI_ERROR_INVALID_CALL. A valid description at the same boundary removed it too.

Size the shim's own checks by the record width, as the compute dispatch path already does, and
forward a zero-filled desktop-sized copy of the record instead of the title pointer, so the desktop
can never read past it. startup_view_dimension_device gains two cases that place the description at
the end of a readable page with an unreadable page after it.
The forwarded copy and the recorded width for slots 20 and 21 took 20 and 16 bytes, from
record_view. D3D12_RENDER_TARGET_VIEW_DESC and D3D12_DEPTH_STENCIL_VIEW_DESC are 24 bytes each
in both header sets, with ArraySize at offset 16 and PlaneSlice at 20, so a truncated copy
reaches the desktop with ArraySize 0: an array RTV or DSV loses its slice range and the device is
removed. The copy is now always forwarded, so this would have regressed views that worked before.

Use sizeof for both widths and assert the 24-byte layout.
@KelboLive
KelboLive force-pushed the fix/3536-view-record-width branch from a07bf2d to 386db60 Compare November 30, 2026 12:38
@KelboLive

Copy link
Copy Markdown
Contributor Author

Both points are fixed at 386db6092, and you were right about the consequence: the truncated copy would have regressed array views that worked before.

Measured layout, both header sets:

RTV 24  DSV 24
DSV Flags@8  Texture2DArray@12   (ArraySize at 16)
RTV Texture2DArray@8  PlaneSlice@20
  • view_bytes for slots 20 and 21 now uses sizeof(D3D12_RENDER_TARGET_VIEW_DESC) and sizeof(D3D12_DEPTH_STENCIL_VIEW_DESC).
  • record_view's width for those slots is the same 24, so recorded array RTV/DSV views keep the fields too (the SHOULD).
  • static_asserts hold both to 24 bytes, so this cannot come back silently.

Verification at this head, after rebasing onto 844e57d:

in-box:  ctest -R 'view|descriptor|depth|dsv'          171/171
agility: ctest -R 'view|descriptor|uav|srv|rtv|dsv'    247/250

The three Agility failures are startup_memory_srv_diag_{warp,hardware} and startup_compute_comparison_srv_warp; they fail identically with this change stashed, so they are not from it.

On the suggested test: I could not get an array-DSV case to work in startup_view_dimension_device, so I removed it rather than ship a fixture I do not understand. Creating the view removed the device even for a plain TEXTURE2D DSV on a desktop-created resource with a guest DSV heap, while startup_clear_depth_stencil passes doing the same thing through the same slots. That is either a mistake in my setup that I have not found or something specific to that fixture, and I would rather report it than encode it. The static_asserts are the guard in the meantime; if you can point at what I got wrong in the setup I will add the case.

@lukaslw-lab lukaslw-lab 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 386db609 by reading the diff; not built or run.

Verdict: approve. Slots 20/21 now copy and forward all 24 bytes in both view_slot paths, so array RTV/DSV fields survive. No MUST.

  • SHOULD docs/experiments/agility-compute-views.md:60 still says "20 for a render target and 16 for a depth-stencil view". The code now uses 24 for both (src/startup_stubs/d3d12_xs_device.cpp:5754, :5852). A one-line doc fix; it can go in this PR or follow.
  • NIT The header comment of tests/startup_view_dimension_device.cpp:17 lists (e) but not (f).
  • On the array-DSV case you could not get working: if that fixture made its texture from uav_desc as (e) does, the resource has ALLOW_UNORDERED_ACCESS and a colour format. A DSV on that is invalid whatever the shim forwards. startup_clear_depth_stencil uses D32_FLOAT with only ALLOW_DEPTH_STENCIL. With the static_asserts in place, this test does not block.
  • Checked, no finding:
    • record_view and the forwarded copy use the same widths for slots 18-21.
    • Both static_assert(... == 24) hold for the in-box and Agility headers, as your layout probe showed.
    • The null-view adaptation now reads desc_copy. desktop_format remaps only formats 116-120, and the packed check needs a resource. So B5G5R5A1/B4G4R4A4 null views reach adapt_null_view with the title's format, as before.
    • desc_copy lives until the desktop call and the removal dump.

Tests: (e) and (f) still reach only slot 19 at a page edge. No case covers slots 20/21; the static_asserts pin their width. CI did not run (e) or (f): the pr test filter leaves out startup_view_dimension_*, and the in-box headers cannot show the 40/48 split.

The Agility note still said 20 for a render target and 16 for a depth-stencil view after the
widths became 24 and 24, and the fixture header listed (e) without (f).

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

Re-reviewed be173937: since the previous approval only the experiment note and fixture header comment changed. The note now matches the 24-byte RTV/DSV code and 40-byte guest SRV/UAV records. Independently built the device fixture in Release and ran ctest --preset release --no-tests=error -R '^startup_view_dimension_(warp|hardware|off_control_warp)$'. All three passed, including inbox WARP, RTX and the disabled-default-view control. This local check used inbox headers; the Agility size split is covered by the author's separate report.

@R0Y00
R0Y00 merged commit cf43986 into R0Y00:main Nov 30, 2026
5 checks passed
@KelboLive
KelboLive deleted the fix/3536-view-record-width branch December 1, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup: a view description at a readable page boundary loses the shim's view checks under the Agility headers

4 participants