Skip to content

shader: lower pixel structured-to-raw buffer loads - #3100

Open
SimSalabimse wants to merge 7 commits into
R0Y00:mainfrom
SimSalabimse:cursor/ps-raw-descriptor-conversion
Open

SimSalabimse wants to merge 7 commits into
R0Y00:mainfrom
SimSalabimse:cursor/ps-raw-descriptor-conversion

Conversation

@SimSalabimse

@SimSalabimse SimSalabimse commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

Since #2910, a non-indexed MUBUF load in a pixel stage through the standard structured-to-raw descriptor conversion is refused as buffer load through a modified descriptor. load_descriptor() already accepts that shape, but raw_descriptor_alu() only ran for compute and vertex stages.

This change:

  • Consults raw_descriptor_alu() in a pixel stage as well, so the four conversion words are tracked the same way as for compute and vertex stages.
  • Lowers a matching non-indexed pixel load as a raw byte-address read bounded by the 32-bit product NUM_RECORDS * stride (NUM_RECORDS * max(stride, 1) when the stride extract was clamped). A wrapped address reads as zero.
  • Records a distinct byte_count+min1 tag when that extract was clamped. Stores already accepted either product; they now match both tags explicitly.
  • Leaves in-place rewrites, partial conversions, and idxen loads refused under their current messages.

A stride-only clear still lowers as an unbounded raw load, as in compute and vertex stages. Compute and vertex load emission is unchanged.

The graphics stand-in fills stride and does not yet publish numrecords, so a completed title pipeline still needs that constant before a draw applies the bound. The offscreen fixture supplies both.

Verification

Commit under test: 185b7decd0e0cb0bf359990c6a5dc6ead9e03dc7, rebased onto upstream main 77d1ba4d63ba31abaf4ca3635d4159189a423201.

A source-built pixel fixture converts a table descriptor and reads it with buffer_load_dword ... offen at four offsets, including one word past NUM_RECORDS * stride. Negative controls, each refused by name: byte count missing, OOB step missing, in-place word rewrite, and an idxen load. A clamped extract uses max(stride, 1) * NUM_RECORDS. A draw readback is compared with a CPU model of the same product. Dropping the bound must read the word past the limit.

The Mesh57 upload-range path constructs its indirect buffer view with indirect_buffer_view(range.resource, range.offset, range.bytes, 0u, 0u, true, 0), so the upload flag cannot shift into records. The pixel fixture asserts that construction.

Windows test PC (MSVC, --preset dev, -j 1), at 185b7dec:

ctest --preset dev --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor.*|native_fixed_mesh57_buffers_(warp|hardware))$' -E 'startup_audio_(output|pacing|provider)'

6/6 passed, ctest exit 0: native_fixed_mesh57_buffers_warp, native_fixed_mesh57_buffers_hardware, startup_gfx2hlsl_ps_raw_descriptor_udsrc, startup_gfx2hlsl_ps_raw_descriptor, startup_gfx2hlsl_ps_raw_descriptor_warp, startup_gfx2hlsl_ps_raw_descriptor_hardware. Build exit 0.

Earlier on c0d43994, the same worktree ran startup_gfx2hlsl_ps_raw_descriptor and startup_compute_dispatch_input_ (6/6, exit 0). On an earlier head the full startup_gfx2hlsl_ list was 379/379, exit 0.

The fixtures are hand-assembled gfx1013 words. No game files or captured programs.

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.

Fixes #3064

AI-assisted (Cursor)

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

Independent Debug and Release /O2 each passed 3/3 (ctest --test-dir <build> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_ps_raw_descriptor', built offscreen_check), on 551708c4 integrated over 300b93f0 (tree 23601ed0692b940e59b6f2515077a0734a34099a). The ordinary address case and the existing bound-drop mutant behaved as expected.

Two added source-built probes expose gaps:

  1. The generated manifest contains ud 5 and udsrc 4 numrecords 0. load_translation in src/startup_stubs/d3d12_draw.inl skips the unrecognized source and sizes the root constants from the four accepted entries. I reproduced that exact omission with the offscreen fixture by calling draw_once(..., constants[:-1], expected_words()). The draw succeeded through PSO creation with no debug warnings or errors. WARP returned four zeros, and RTX returned 3f800000,40800000,41000000,deadbeef instead of 3f800000,40800000,41000000,00000000. Please bind the count or keep the unsupported ordinary draw on an explicit refusal path. A synthetic regression should exercise one of those two outcomes through the manifest loader.
  2. The new range check detects wrap in a + payload after a has already been truncated. In the same fixture, replace the instruction v_mov(0, 0) with struct.pack('<I', 0x7e0002c4) to make v0=0xfffffffc. At immediate offsets 12, 28 and 32, the generated HLSL wraps the byte address to 8, 24 and 28 before testing it. Both WARP and RTX then read 40400000,40e00000,41000000 from the wrong portion of the view. Please check overflow when forming the initial byte address and add a guard for this case. The RDNA 2 ISA, §8.1 and Table 35 describes the immediate-plus-VGPR offset and raw bounds check.

Windows 26200.9974, SDK/DXC 10.0.26100.0, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled.

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

Reviewed head 551708c42 (Linux, Python only: no Windows run on my side).

What works:

  • python3 -B tests/startup_gfx2hlsl_ps_raw_descriptor_check.py passes at the head: the four controls are refused by name and the CPU model gives 3f800000,40800000,41000000,00000000.
  • Running raw_descriptor_alu() in the pixel stage is the right fix. The conversion words are tagged the same way as in compute and vertex stages, and raw_conversion_shapes() keeps the clamped and unclamped products apart.
  • The bound for buffer_load_dword* matches the raw out-of-range rule for OOB_SELECT 3. The "RDNA 2" ISA guide, 8.1.8 Table 37 and 8.1.5, describes the converted NUM_RECORDS as a byte count.

One more gap, besides the two already reported (the numrecords entry the runtime drops, and the wrap after truncation):

  1. tbuffer_load_format_* now gets through unbounded. tbuffer() reaches load_descriptor() through buffer_address(), so a pixel tbuffer read through the converted descriptor now passes the check and sets raw_load_bound. But only op_buffer_load_dword reads that bound. Source-built case: in your fixture program(conversion()), replace the four buffer_load_dword reads with one tbuffer_load_format_x v1, v0, s[16:19], 0 format:[BUF_FMT_32_FLOAT] offen offset:32. That is the word right past NUM_RECORDS * stride = 32.

    • At the parent db28a796, it is refused: buffer load through a modified descriptor.
    • At 551708c42, it translates as a = v0 + 32; v1 = r0.Load(a);. There is no bound and no stride/numrecords entry, so it reads 0xdeadbeef where the hardware returns 0.

    Two ways to fix it. Apply the same bound in tbuffer() (and load_format()), with one byte count per element. Or keep raw_conversion_ok=False for the MTBUF path, so it stays refused as before. A control for this case in the existing check would lock it in.

Commands run:

git fetch origin pull/3100/head
python3 -B tests/startup_gfx2hlsl_ps_raw_descriptor_check.py          # at 551708c42: pass
python3 -B probe_tbuffer.py <tree at 551708c42>                       # translates, unbounded r0.Load(a)
python3 -B probe_tbuffer.py <tree at db28a796 + this PR's check file> # refused: buffer load through a modified descriptor

(probe_tbuffer.py imports your check module and builds the program above: smem_load_x4(DESC, 8) + conversion() + v_mov(0, 0) + <MTBUF word> + s_waitcnt + exp_mrt0(1, 1, 1, 1). The MTBUF word is op 0, FORMAT 22, offen, offset 32, srsrc s[16:19], soffset inline 0.)

AI-assisted; commands listed were executed locally.

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

Review of 551708c4. Comment only.

The translator part is good. It turns the pixel structured-to-raw descriptor conversion into a raw load with a bound. Everything else that touches those words still refuses. I tried 17 bad variants locally (wrong masks, wrong constants, words from a second descriptor, steps out of order) and all of them refused.

Blocking: the draw never fills numrecords. The new stage asks for udsrc N numrecords <srv>. The udsrc parser in d3d12_draw.inl only knows rect, basevertex, startinstance, rootconst, stride, d16unorm16, descword3 and mrtbits. So the entry is never added, and because of the i == tr.uds.size() check, every udsrc after it is dropped too. In a real draw that means either the root signature doesn't match the shader, or the limit reads 0 and every converted load returns zero, with no warning. Fix: fill numrecords from words[2] of the table SRV, the way stride is filled, or refuse unknown udsrc kinds. The --startup-raw-buffer test fills its constants by hand, so it can't catch this.

Should fix:

  • test an x2 or x4 load that crosses the limit, stride 0, a non-zero soffset, and the out-of-place (s_mov copy) form;
  • add a few of the bad variants above as negative controls, especially the second-descriptor ones;
  • "in-place" in the text and in the control name is misleading: the accepted fixture rewrites the registers in place too.

Nits: unaligned addresses lose their low two bits without a refusal. The DW1 swizzle bits, ADD_TID and the DW3 format are kept but never checked; one line in the docs would cover it.

Ran on this head: tests/startup_gfx2hlsl_ps_raw_descriptor_check.py passes, with all 4 controls refusing. tools/run_checks_parallel.py over tests/checks/python-linux passes 235/235. CI is green.

@Leyukaka

Leyukaka commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Review of 551708c4. Comment only. Edited: I have since built and run it; see the measurement below.

Beyond what is already reported here (the dropped numrecords entry, the wrap after truncation, MTBUF without the bound, and the extra test cases), I found one small thing:

  • --startup-raw-buffer accepts 1 to 64 entry constants (tests/offscreen_check.cpp and tests/startup_flat_param.cpp). The root signature puts them in one 32-bit-constants parameter and adds a one-range descriptor table, which costs one more DWORD. With 64 constants that is 65 DWORDs, over the D3D12 limit of 64. Measured on 551708c4 merged over main 14d56502: with the fixture padded to 63 constants the draw passes on WARP and on an RTX 5080; with 64, CreateRootSignature fails with 0x80070057 ("Create raw buffer root signature failed") on both. Capping it at 63 would fix it. The 1..64 bound is unchanged at 327d134c. The fixture in this PR uses fewer, so it is not affected.

I also checked two things that are not problems in this PR:

  • s_buffer_load_dword through the converted quartet is not refused. But op_s_buffer_load_dword takes the descriptor key without checking for modifications in any stage on main, so this PR does not introduce it.
  • The "stride clear only" form now translates in a pixel stage as an unbounded load. That matches the rule compute and vertex already use on main, and the PR tests it on purpose.

AI-assisted.

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

I tried to review 327d134c merged over main 4b0350ea. The merge is clean (tree 90ef8851) and git diff --cached --check is clean, but the stand-in does not compile. This matches the Build and test on Windows failure on this head.

Finding: IndirectBufferView initialisers don't match the new field order.

  • The struct: it now declares stride, records, upload, with UINT records = 0; added before bool upload = false;.
  • The initialisers: the brace-initialisers in indirect_table_buffer pass the values in the other order, as {..., stride, true, records}, {..., stride, false, records} and {native, offset, bytes, stride, upload, records}.
  • Result: MSVC rejects all three as narrowing:
. .\tools\dev.ps1; cmake --preset dev; cmake --build --preset dev --target d3d12_xs_shim
src\startup_stubs/d3d12_draw.inl(2365): error C2397: conversion from 'UINT' to 'bool' requires a narrowing conversion
src\startup_stubs/d3d12_draw.inl(2377): error C2397: conversion from 'UINT' to 'bool' requires a narrowing conversion
src\startup_stubs/d3d12_draw.inl(2407): error C2397: conversion from 'UINT' to 'bool' requires a narrowing conversion

Even with narrowing allowed, records would land in upload and the upload flag in records.

Suggested direction: declare records after upload, so the existing initialisers line up. Or swap the last two values in the three initialisers. The draw path that reads records should then be covered by the numrecords manifest case you added.

Earlier findings. I read 327d134c against the requests on 551708c4. Because the stand-in doesn't build, I couldn't run the Windows fixture, so none of these is confirmed yet:

  • numrecords dropped by the loader (R0Y00 1, rasptum): accept_udsrc_line now accepts numrecords, and an unknown udsrc makes load_translation refuse the manifest instead of skipping it.
  • Wrap after truncation (R0Y00 2): the pixel raw path now adds each address term with an overflow check before the range compare.
  • MTBUF without the bound (tedin7 3): tbuffer passes raw_conversion_ok=False, so a typed load through the converted descriptor stays refused.

I'll run the fixture and the 0xfffffffc and MTBUF probes once the stand-in builds.

Verdict: request changes on 327d134c, because the head does not compile.

Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0.
CI: Build and test on Windows fails on 327d134c with the same C2397 errors.

This reply was AI-assisted.

@pigalot

pigalot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to the changes-requested review on 327d134c (same trial tree 90ef8851 over main 4b0350ea), with two additions.

A second blocker: startup_gfx2hlsl_ps_raw_descriptor needs g++ on Windows. check_udsrc() builds its driver with g++ unconditionally. The test is registered for Windows CTest as well as in the python-linux list, so on a Windows host without g++ it fails before any check runs. The _warp and _hardware variants call controls() first, so they fail the same way:

ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_ps_raw_descriptor$' --output-on-failure
check_udsrc -> subprocess.run(['g++', ...]) -> FileNotFoundError: [WinError 2]

CI never reaches this step because the build fails first. Possible directions (unconfirmed): skip the driver when g++ is missing; build it as a small CMake test target; or use cl on Windows.

The translator fixes run clean. With only the g++ step stubbed out, every case in controls() passes:

  • the v0 = 0xfffffffc wrap at offsets 12, 28 and 32 reads 0;
  • the typed tbuffer load is refused with buffer load through a modified descriptor;
  • the dwordx2 and dwordx4 crossings, stride 0, non-zero soffset and the s_mov-copied descriptor all pass;
  • the nine refused variants refuse, including the stride from a second descriptor.

Still open (non-blocking): Leyukaka's limit. tests/offscreen_check.cpp and tests/startup_flat_param.cpp still accept 64 entry constants. With the descriptor table that is 65 DWORDs, over the 64-DWORD root-signature limit.

This reply was AI-assisted.

@pigalot

pigalot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

One more blocking item on 327d134c, which I left out of the review above.

check_udsrc() in tests/startup_gfx2hlsl_ps_raw_descriptor_check.py always builds its driver with g++ (line 409). controls() calls it, and so do the no-argument and draw modes. All three tests are registered in the Windows CTest block: startup_gfx2hlsl_ps_raw_descriptor, _warp and _hardware. On a Windows host with no g++ on PATH, like this one, all three fail before any check runs:

check_udsrc -> subprocess.run(['g++', ...]) -> FileNotFoundError: [WinError 2]

Possible directions, none of them tried:

  • build the driver as a small CMake test target and pass its path in;
  • use cl on Windows;
  • skip with 77 when no compiler is found, keeping the Linux run as the enforcing one.

This reply was AI-assisted.

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

Retested 587a3dec integrated over main 2e12dd8e (tree 8448e705). The merge is clean and git diff --cached --check is clean.

My changes-requested review on 327d134c.

  • IndirectBufferView field order: addressed. All six construction sites now go through indirect_buffer_view(resource, offset, bytes, stride, records, upload), which assigns by member name. That covers the three in indirect_table_buffer and the alias return that only passed four values. It also covers the two in compute_root_srv_buffer, where {..., 0, true} had been compiling silently with true in records and upload left false. d3d12_xs_shim builds in dev and release.
  • g++ on Windows: addressed. The udsrc cases are now tests/startup_udsrc_line_check.cpp, built as the CMake target startup_udsrc_line_check and registered as startup_gfx2hlsl_ps_raw_descriptor_udsrc. The Python check gets the built binary through X2W_UDSRC_CHECK. A direct run compiles the same source with cl on Windows and g++ elsewhere.
  • Earlier translator findings. The wrap check, the MTBUF refusal and the numrecords loader fix are covered by the mutants below.

What I traced. In a pixel stage the full conversion now matches either byte_count or byte_count+min1. The load is bounded per dword by a + 4(i+1) <= lim, where lim is the 32-bit product of the view's stride (or max(stride, 1)) and numrecords entry constants. Each address term is added with an unsigned carry check. tbuffer passes raw_conversion_ok=False. On the stand-in side, records is filled from descriptor word 2 in both branches and copied into record_counts[i], and the numrecords udsrc reads it. An unknown udsrc kind or an index gap now makes load_translation refuse the manifest; it used to skip the line.

What I ran. I built d3d12_xs_shim offscreen_check startup_udsrc_line_check in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp|_hardware)?|startup_flat_param_(controls|warp|hardware)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls)$'

All 9 pass in Debug and in Release /O2, with no skips. Both startup_gfx2hlsl_ps_raw_descriptor_hardware runs read back 3f800000,40800000,41000000,00000000 for DXC and for FXC. startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case. I also ran the 155 startup_gfx2hlsl_* tests that have no _warp/_hardware suffix, plus startup_flat_param_controls, in dev: 156/156 pass.

Negative control and mutants. Each mutant was run against the tests above. The C++ ones were rebuilt in dev.

Mutant Result
tools/startup/gfx2hlsl.py back to main killed: _ps_raw_descriptor, _warp and _hardware fail; _udsrc still passes
pixel load ignores the bound killed (udsrc stride manifest expectation)
no carry check on the address terms killed (bounded-load text and the draw)
typed tbuffer accepts the conversion killed (typed buffer load: translated)
<= lim → < lim killed
numrecords constant reads strides[] killed (source assertion in check_udsrc)
udsrc index gap accepted killed (udsrc driver exit 4)
stride and records swapped in the desktop-buffer indirect_buffer_view call survives
compute_root_srv_buffer passes records 1, upload false survives

Restored and rebuilt afterwards; the restored build passes again and git diff --quiet is clean.

Non-blocking.

  1. The stand-in's records path has no runtime test. The draw fixture binds through offscreen_check, not the stand-in. On the stand-in side only check_udsrc()'s source assertions cover it, so a wrong argument order at an indirect_buffer_view call site still passes. The same holds for the compute_root_srv_buffer fix, which is a real behaviour change: upload used to be false on that path. A CPU-side check of indirect_table_buffer or compute_root_srv_buffer, or an indirect-draw case through d3d12_xs_shim, would pin it.
  2. Leyukaka's limit is still open. run_startup_raw_buffer and check_startup_raw_buffer accept up to 64 entry constants. With the descriptor table that is 65 DWORDs, over the 64-DWORD root-signature limit. The fixture itself uses far fewer.
  3. The description is stale. "Commit under test" is still 551708c4. It also says the stand-in "does not yet publish numrecords", but this head does.

Verdict: approve on 587a3dec. This supersedes my changes-requested review on 327d134c. R0Y00's changes request on 551708c4 still needs its own sign-off, so I'm not merging.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC and FXC (the ones CTest picked up); Python 3.12.10; D3D12 debug layer on in startup_flat_param_hardware.
CI: Build and test on Windows passes on 587a3dec; Run platform-independent Python checks on Linux passes too, so the g++ path builds there.

This reply was AI-assisted.

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

Retested 587a3dec integrated over main 2e12dd8e (tree 8448e705). The merge is clean and git diff --cached --check is clean.

My changes-requested review on 327d134c.

  • IndirectBufferView field order: addressed. All six construction sites now go through indirect_buffer_view(resource, offset, bytes, stride, records, upload), which assigns by member name. That covers the three in indirect_table_buffer and the alias return that only passed four values. It also covers the two in compute_root_srv_buffer, where {..., 0, true} had been compiling silently with true in records and upload left false. d3d12_xs_shim builds in dev and release.
  • g++ on Windows: addressed. The udsrc cases are now tests/startup_udsrc_line_check.cpp, built as the CMake target startup_udsrc_line_check and registered as startup_gfx2hlsl_ps_raw_descriptor_udsrc. The Python check gets the built binary through X2W_UDSRC_CHECK. A direct run compiles the same source with cl on Windows and g++ elsewhere.
  • Earlier translator findings. The wrap check, the MTBUF refusal and the numrecords loader fix are covered by the mutants below.

What I traced. In a pixel stage the full conversion now matches either byte_count or byte_count+min1. The load is bounded per dword by a + 4(i+1) <= lim, where lim is the 32-bit product of the view's stride (or max(stride, 1)) and numrecords entry constants. Each address term is added with an unsigned carry check. tbuffer passes raw_conversion_ok=False. On the stand-in side, records is filled from descriptor word 2 in both branches and copied into record_counts[i], and the numrecords udsrc reads it. An unknown udsrc kind or an index gap now makes load_translation refuse the manifest; it used to skip the line.

What I ran. I built d3d12_xs_shim offscreen_check startup_udsrc_line_check in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp|_hardware)?|startup_flat_param_(controls|warp|hardware)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls)$'

All 9 pass in Debug and in Release /O2, with no skips. Both startup_gfx2hlsl_ps_raw_descriptor_hardware runs read back 3f800000,40800000,41000000,00000000 for DXC and for FXC. startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case. I also ran the 155 startup_gfx2hlsl_* tests that have no _warp/_hardware suffix, plus startup_flat_param_controls, in dev: 156/156 pass.

Negative control and mutants. Each mutant was run against the tests above. The C++ ones were rebuilt in dev.

Mutant Result
tools/startup/gfx2hlsl.py back to main killed: _ps_raw_descriptor, _warp and _hardware fail; _udsrc still passes
pixel load ignores the bound killed (udsrc stride manifest expectation)
no carry check on the address terms killed (bounded-load text and the draw)
typed tbuffer accepts the conversion killed (typed buffer load: translated)
<= lim → < lim killed
numrecords constant reads strides[] killed (source assertion in check_udsrc)
udsrc index gap accepted killed (udsrc driver exit 4)
stride and records swapped in the desktop-buffer indirect_buffer_view call survives
compute_root_srv_buffer passes records 1, upload false survives

Restored and rebuilt afterwards; the restored build passes again and git diff --quiet is clean.

Non-blocking.

  1. The stand-in's records path has no runtime test. The draw fixture binds through offscreen_check, not the stand-in. On the stand-in side only check_udsrc()'s source assertions cover it, so a wrong argument order at an indirect_buffer_view call site still passes. The same holds for the compute_root_srv_buffer fix, which is a real behaviour change: upload used to be false on that path. A CPU-side check of indirect_table_buffer or compute_root_srv_buffer, or an indirect-draw case through d3d12_xs_shim, would pin it.
  2. Leyukaka's limit is still open. run_startup_raw_buffer and check_startup_raw_buffer accept up to 64 entry constants. With the descriptor table that is 65 DWORDs, over the 64-DWORD root-signature limit. The fixture itself uses far fewer.
  3. The description is stale. "Commit under test" is still 551708c4. It also says the stand-in "does not yet publish numrecords", but this head does.

Verdict: approve on 587a3dec. This supersedes my changes-requested review on 327d134c. R0Y00's changes request on 551708c4 still needs its own sign-off, so I'm not merging.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC and FXC (the ones CTest picked up); Python 3.12.10; D3D12 debug layer on in startup_flat_param_hardware.
CI: Build and test on Windows passes on 587a3dec; Run platform-independent Python checks on Linux passes too, so the g++ path builds there.

This reply was AI-assisted.

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

Correction: the changes-requested review at 23:28 on 587a3dec was posted by mistake. It is a second copy of the 23:23 approval, sent with the wrong state, so please disregard it. The verdict on 587a3dec is approve, as written in the 23:23 review.

A second, independent run over main 9345c21f agrees with that review:

  • Tests: the ps_raw_descriptor tests and their neighbours (indirect, root-SRV and compute dispatch) pass in Debug and Release, on WARP and on hardware, with no skips. startup_compute_dispatch_native_* fails with "left ['revision.txt'] in the cache", and it fails the same way on main fad97f47.
  • The untested stand-in path (non-blocking 1 in that review): this run confirms it. Swapping records and the upload flag at any of the three indirect_table_buffer call sites survives every test. A stand-in case where NUM_RECORDS is not 1 would pin it.

R0Y00's changes request on 551708c4 still needs its own sign-off, so this isn't being merged from here.

This reply was AI-assisted.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, all three points are fixed on 327d134.

@R0Y00, overflow and numrecords

The draw stand-in now keeps a numrecords constant. It reads that count from dword 2 of the table descriptor, and an unknown udsrc line refuses the translation instead of dropping every line after it. The bounded pixel load also checks each address term for overflow before the range compare, so a vgpr of 0xfffffffc plus 12, 28 or 32 stays zero instead of wrapping into the buffer.

I ran python3 -B tests/startup_gfx2hlsl_ps_raw_descriptor_check.py. Mutants that drop the overflow check, the numrecords kind, or the record-count store each fail, and the restored check passes. python3 -B tests/startup_tools_lint_check.py tools/startup exited 0. The Linux Python suite from the CI list, python3 -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux plus the listed scripts, passed 246 checks and exited 0.

@tedin7, typed buffer load

A typed tbuffer load through the converted descriptor is refused again, with the same message as before this change. The control is one float load at offset 32, the first word past the record count times the stride. A mutant that lets that load through fails the check, because the shader translates with no bound.

I ran python3 -B tests/startup_gfx2hlsl_ps_raw_descriptor_check.py, python3 -B tests/startup_tools_lint_check.py tools/startup (exit 0), and the Linux Python suite python3 -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux plus the listed scripts (246 checks, exit 0).

@rasptum, runtime bound and extra controls

The runtime parser knows numrecords now and fills it from dword 2 of the table descriptor, the same place stride comes from. An unknown kind or a gap refuses the manifest, so a later udsrc line is not dropped. The check covers a dwordx2 and a dwordx4 that cross the limit, stride 0, a non-zero soffset, and a conversion that runs on an s_mov copy. The old in-place control is renamed to a word overwritten with zero. Extra refusals cover a wrong stride mask, OOB select 2, a constant scale, steps out of order, and a stride taken from a second descriptor. Unaligned addresses, the swizzle bits, ADD_TID and the format field stay unchecked; that is noted in the experiment writeup.

Each of those new checks failed when I took out only its fix, then passed again after restoring it. python3 -B tests/startup_gfx2hlsl_ps_raw_descriptor_check.py passes. python3 -B tests/startup_tools_lint_check.py tools/startup exited 0. The Linux Python suite, python3 -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux plus the listed scripts, passed 246 checks and exited 0.

Windows test PC: at 587a3de, the ps_raw_descriptor tests passed twice (4/4, ctest exit 0) and startup_gfx2hlsl_ 389/389 passed, ctest exit 0.

AI-Assisted

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

Retested 130d32cb, your merge of main 7fcde81f, integrated over current main fdb6faaa. The merge is clean (tree d7bf28d8) and git diff --cached --check is clean.

Your merge. git show --remerge-diff 130d32cb shows one conflict, in src/startup_stubs/d3d12_draw.inl, on Translation. It keeps this branch's UdKind enum, whose values are tied to the udsrc_* constants and include num_records, together with main's Srv comment that adds kind 5 (cube) from #2938. That is the right combination. Apart from that hunk, the PR's diff over main is byte-identical to 587a3dec's diff over its own base. So the earlier review of 587a3dec, including the traced behaviour and the mutants, still applies to this code.

What I ran.

  • Builds: full dev and release /O2.

  • The PR's tests:

    ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp|_hardware)?|startup_flat_param_(controls|warp|hardware)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls)$'

    9/9 pass in Debug and in Release, with no skips. startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case.

  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2002 tests: 1945 pass, 0 fail, 57 capability skips.

Still open (non-blocking, unchanged since 587a3dec).

  1. The stand-in's records path has no runtime test. A wrong argument order at an indirect_buffer_view call site still passes.
  2. Leyukaka's limit is still open. 64 entry constants plus the descriptor table make 65 DWORDs.
  3. The description is stale. It still names 551708c4 as the commit under test.

Verdict: approve on 130d32cb. R0Y00's changes-requested review on 551708c4 still needs R0Y00's own sign-off, so I'm not merging.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC and FXC (the ones CTest picked up); Python 3.12.10; D3D12 debug layer on in startup_flat_param_hardware.

This reply was AI-assisted.

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

I tested a local reconciliation of 130d32cb with main fbef6381 (tree 10cb6814). The published head still conflicts in d3d12_draw.inl. Keep both the snapshot option and the named indirect_buffer_view constructor. The constructor needs both records and source; the former carries the pixel NUM_RECORDS value and the latter carries main's slot-67 snapshot source. The normal, null and recycled snapshot returns all use the named constructor so the fields stay in the proper slots.

Release /O2 passed 6/6 with no skips: the parser, raw descriptor controls, WARP and physical pixel readbacks, and both adjacent Compute input snapshot fixtures.

cmake --build --preset release --target d3d12_xs_shim startup_stream_consumer offscreen_check startup_udsrc_line_check
ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^startup_(gfx2hlsl_ps_raw_descriptor|compute_dispatch_input_)'

Windows 11 26200.9974, inbox WARP 10.0.26100.9818 and RTX 4060 Laptop driver 32.0.16.1656. The source-built readbacks cover the first word past the converted range and the named refusal controls. Please refresh this source with current main before the hosted checks rerun.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Merged current main (only d3d12_draw.inl conflicted; kept the cube comment and the num_records enumerator) and retested 130d32c on Windows: startup_gfx2hlsl_ps_raw_descriptor 4/4 passed, twice. No startup_udsrc test exists in this tree.

AI-Assisted

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the fixes on 130d32cb. I re-checked that head against main c3204a9c. The translator side looks sound, but two items still need a change before this can merge.

Must fix

  1. The head still conflicts with startup: read translated compute inputs that live only in title memory from a snapshot #2862 (5033d2d3): git merge-tree --write-tree c3204a9c 130d32cb → rc=1, 2 hunks in src/startup_stubs/d3d12_draw.inl. Main added int source after upload, so the merged struct reads stride, records, upload, source. Two returns merge cleanly but fill the wrong fields: return {zero_ring, zero_offset, 16, 0, true, 3}; and return {ring, ring_offset, bytes, stride, true, 2}; (true lands in records, the source value in upload). The check's udsrc text asserts don't cover those lines, so it stays green either way. Please use the resolution from R0Y00's 04:16 comment, where every return goes through the named indirect_buffer_view constructor with both records and source. Then push so CI reruns.
  2. SRVs that the title creates get a zero bound. Both view-token branches (indirect_table_buffer and the slot-18 branch of draw_translated) set stride/strides[i] but never records/record_counts[i]. git show 130d32cb:src/startup_stubs/d3d12_draw.inl | grep -n 'record_counts\[i\] = ' finds only the view.records and words[2] lines. As a result, { uint lim = ud3 * ud4; is 0, and every converted pixel load from such a view reads 0 without a log line. On main, the translator refuses a load through a modified descriptor. I found this by reading the code and did not run it. Please set the record count from the view's NumElements, or refuse a numrecords constant on a token SRV.

Should fix
3. The wrap guard is never drawn. check_draw draws only program(conversion()) (v0=0). The v0=0xfffffffc program is checked as HLSL text and through raw_dwords, which is the check's own model. Drawing it as well would show the expected 0,0,0,0 on a real device.
4. The manifest-loader refusal is unpinned. Mutant: change return; to continue; after x2w-draw unsupported udsrc → the check still passes, because it asserts only the log string. A regression through the loader, as R0Y00 asked, would catch this.
5. A stale bound is unpinned. Mutant: drop self.raw_load_bound = None in tools/startup/gfx2hlsl.py → the check still passes. With two descriptors, the load from untouched descriptor B then picks up A's limit: v2 = (ok && a + 4u >= a && a + 4u <= lim) ? r1.Load(a + 0) : 0u;, where the original gives v2 = r1.Load(a + 0);. A two-descriptor control would pin this.

Still open: Leyukaka's constant limit is unchanged (constants.size() > 64 in tests/offscreen_check.cpp, constant_count > 64 in tests/startup_flat_param.cpp; the descriptor table costs one more DWORD). The PR body still names 551708c4 and says the stand-in "does not yet publish numrecords".

What I ran: tests/startup_gfx2hlsl_ps_raw_descriptor_check.py exits 0 at 130d32cb. Each mutant ran on a copy that was restored and hash-verified afterwards. I did not build or run anything under Wine, WARP or a GPU.

This comment was AI-assisted.

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

Retested 445abdf7 integrated over main ec71c290 (tree 7b6c6606). The trial merge is clean and git diff --cached --check is clean.

What changed since 130d32cb. 445abdf7 is a merge of main 3926a289, and git show --remerge-diff 445abdf7 shows it also carries new work beyond the conflict resolution. I read all of it:

  • Conflict in d3d12_draw.inl (R0Y00 04:16Z, JohnConnorNPC 1): resolved as asked. IndirectBufferView is now IndirectBufferViewOf<ID3D12Resource> in the new indirect_buffer_view.h, with stride, records, upload, source. All seven construction sites (five in indirect_table_buffer, two in compute_root_srv_buffer) go through the named constructor with both records and source. main's snapshot option is kept; the null return passes source 3 and the snapshot return source 2. No brace-initialised return is left.
  • Zero bound on title-created views (JohnConnorNPC 2): addressed. Both view-token branches now set the count from view.Buffer.NumElements (records in indirect_table_buffer, record_counts[i] in draw_translated).
  • Wrap guard never drawn (JohnConnorNPC 3): addressed. check_draw now draws the v0 = 0xfffffffc program and expects 0,0,0,0, with DXC and FXC.
  • Loader refusal (JohnConnorNPC 4): addressed by a source assertion that the text after x2w-draw unsupported udsrc has return; and no continue;.
  • Stale bound (JohnConnorNPC 5): addressed. A two-descriptor control expects v2 = r1.Load(a + 0); for the untouched descriptor.
  • Leyukaka's limit: addressed. Both fixtures now cap the entry constants at 63.

What I ran. Full dev and release /O2 builds, then

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp)?|startup_flat_param_(controls|warp)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls|startup_compute_dispatch_input_warp|startup_slot67_indirect_dispatch_warp|startup_indirect_translated_(draw|indexed|indexed_upload|indexed_alias)_warp)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_gfx2hlsl_ps_raw_descriptor_hardware|startup_flat_param_hardware|startup_compute_dispatch_input_hardware)$'

13/13 and 3/3 pass in Debug and in Release, with no skips. On hardware, both compilers read back 3f800000,40800000,41000000,00000000 and "a wrapping address reads four zeros". startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case.

Negative control and mutants. Each was rebuilt in dev and run against the seven ps_raw_descriptor, indirect_translated, slot67_indirect_dispatch and compute_dispatch_input tests (WARP). The unmodified tree passes 7/7.

Mutant Result
tools/startup/gfx2hlsl.py back to main killed: _ps_raw_descriptor and _warp fail
drop self.raw_load_bound = None killed (two-descriptor control)
no carry check on the address terms killed (bounded-load text)
unsupported udsrc: return; → continue; killed (source assertion)
constructor drops source killed (udsrc driver exit 9; startup_compute_dispatch_input_warp also fails)
constructor puts stride in records killed (udsrc driver exit 10)
stride and records swapped at the desktop-buffer return killed (source assertion, and startup_indirect_translated_draw_warp fails at run time)
snapshot return reports source 0 killed (source assertion, and startup_compute_dispatch_input_warp)
records = 0; added after records = view.Buffer.NumElements; survives
record_counts[i] = 0; added after record_counts[i] = view.Buffer.NumElements; survives
record_counts[i] = view.stride; added after record_counts[i] = view.records; survives
offscreen_check accepts 64 constants again survives

No equivalent mutants. The files were restored afterwards and git diff --quiet is clean.

Non-blocking.

  1. The record count the stand-in publishes is pinned by text only. The three surviving count mutants keep the asserted source lines and change the value, and no test notices. This is the same gap as non-blocking 1 in my review of 587a3dec, now narrower: the constructor and the argument order are covered, the value that reaches ud<numrecords> in a stand-in draw is not. A stand-in draw through a converted descriptor with NUM_RECORDS other than the stride would pin it.
  2. A raw title-created view gets a count in elements, not bytes (read from the code, not run). For a raw view, both token branches use stride 0 and bytes = NumElements * 4, and now records = NumElements. The table-descriptor branch treats stride 0 as one byte per record (bytes = (stride ? stride : 1) * words[2]). With the clamped conversion the shader's limit is max(0, 1) * NumElements, a quarter of the view, so loads from the upper three quarters would read 0. With the plain conversion the limit is 0. Suggested direction, unconfirmed: publish bytes as the count when the view is raw, or refuse a numrecords constant on a raw token view.
  3. The 63-constant cap has no test. A 64-constant control in either fixture would pin it.
  4. The description is stale. It names 551708c4 as the commit under test and says the stand-in "does not yet publish numrecords". The fixes for the latest review are inside a commit titled as a merge of main; a line in the description listing them would help the next reader.

Verdict: approve on 445abdf7. The findings from my earlier reviews and the ones from R0Y00's 04:16Z comment and JohnConnorNPC's 07:34Z comment are addressed at this head as listed above. R0Y00's changes-requested review on 551708c4 is still recorded and needs R0Y00's own sign-off, so I am not merging this.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 debug layer on for the hardware runs (X2W_TEST_DEBUG_LAYER=1).
CI: Build and test on Windows passes on 445abdf7.

This reply was AI-assisted.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

The five review items are fixed on 445abdf7, which merges main 3926a289.

  1. Every IndirectBufferView return goes through the named indirect_buffer_view constructor with both records and source, as in the 04:16 resolution. The check asserts those exact return lines (and that the old brace-init returns are gone), so a swapped field fails. startup_udsrc_line_check also builds three views and checks the fields.
  2. A buffer view the title created now sets records from the view's NumElements.
  3. The wrap program (v0=0xfffffffc) is drawn as well, and the device readback is 0,0,0,0.
  4. After x2w-draw unsupported udsrc, the check requires return; and fails if that becomes continue;.
  5. A two-descriptor control pins the stale bound: a load from an untouched descriptor does not keep the first limit.

Windows test PC (NVIDIA 32-lane), head 445abdf75fa3d0be20db11262a570478b5ad749e:

ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_ps_raw_descriptor' -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider'
ctest --preset dev --no-tests=error -j 1 -R '^startup_compute_dispatch_input_' -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider'
ctest --preset dev --no-tests=error -j 1 -R startup_gfx2hlsl_ -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider'

startup_gfx2hlsl_ps_raw_descriptor, startup_gfx2hlsl_ps_raw_descriptor_udsrc, startup_gfx2hlsl_ps_raw_descriptor_warp and startup_gfx2hlsl_ps_raw_descriptor_hardware passed twice (4/4, ctest exit 0, no skips; 4.62 s and 4.50 s). startup_compute_dispatch_input_warp and startup_compute_dispatch_input_hardware passed (2/2, ctest exit 0, no skips, 11.13 s). The same worktree then ran the full startup_gfx2hlsl_ list: 391/391 passed, 0 failed, 0 skipped, ctest exit 0, 737.60 s.

AI-Assisted

@cursor
cursor Bot force-pushed the cursor/ps-raw-descriptor-conversion branch from 445abdf to 49a1590 Compare November 28, 2026 22:20
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Retested the rebased head c0d43994 on the Windows test PC (MSVC, --preset dev, -j 1).

49a1590e (the first push after the rebase) did not build with MSVC: d3d12_compute_dispatch.inl(791) C2397, int to bool narrowing. The scalar-window snapshot brace put the upload flag into records and the source number into upload. c0d43994 builds that view by member name and adds a check for this call.

  • build: exit 0
  • ctest -R '^startup_gfx2hlsl_ps_raw_descriptor|^startup_compute_dispatch_input_': 6/6 passed, exit 0 (udsrc, ps_raw_descriptor, warp, hardware, compute_dispatch_input warp and hardware)

The only conflict with main was in d3d12_draw.inl; the PR still has 13 files changed. @pigalot could you take another look since the approval was on the pre-rebase head?

AI-Assisted

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

Retested c0d43994 integrated over main 212d4b5f (tree c576752c). The trial merge is clean and git diff --cached --check is clean.

What changed since my approval on 445abdf7. The branch was rebased onto main 0614f68c, so I compared the PR's own diff at both heads (git diff <base>...<head> over the 13 files). Two lines differ, and nothing else:

  • src/startup_stubs/d3d12_compute_dispatch.inl: the scalar-window snapshot that main added since then, view = {chunk, start, bytes, stride, true, 2};, is now view = indirect_buffer_view(chunk, start, bytes, stride, words[2], true, 2);. With the PR's extra records member the brace form put true in records and 2 in upload (the C2397 the author reports on 49a1590e). The named call keeps upload = true and source = 2 as on main.
  • tests/startup_gfx2hlsl_ps_raw_descriptor_check.py: one assertion for that exact line.

I also looked for any other positional initialisation of the view in the merged tree. There is none: the eight construction sites all go through indirect_buffer_view, and native_mesh57.inl only reads members by name.

The items from my earlier reviews, R0Y00's 04:16Z comment and JohnConnorNPC's 07:34Z comment are unchanged from 445abdf7, where I checked them one by one; the controls for them still kill their mutants below.

What I ran. Full dev and release /O2 builds, then

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp)?|startup_flat_param_(controls|warp)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls|startup_compute_dispatch_input_warp|startup_compute_dispatch_native_warp|startup_slot67_indirect_dispatch_warp|startup_indirect_translated_(draw|indexed|indexed_upload|indexed_alias)_warp)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_gfx2hlsl_ps_raw_descriptor_hardware|startup_flat_param_hardware|startup_compute_dispatch_input_hardware|startup_compute_dispatch_native_hardware)$'
  • CPU and WARP: 13 passed and 1 capability skip in Debug and in Release. The skip is startup_compute_dispatch_native_warp (77), so the scalar-window case ran on hardware only.
  • Hardware: 4/4 in Debug and in Release, no skips. Both compilers read back 3f800000,40800000,41000000,00000000 and "a wrapping address reads four zeros"; startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case.

A first Release hardware attempt failed startup_gfx2hlsl_ps_raw_descriptor_hardware because my own mutation run was editing the sources that check reads at the time. With the tree untouched it passes; the 4/4 above is that rerun.

Title run. prwatch's real-title run of this head merged onto the baseline commit: pass (job 12).

Negative control and mutants. Each was rebuilt in dev and run against startup_gfx2hlsl_ps_raw_descriptor, _udsrc, _warp, startup_compute_dispatch_input_warp and startup_compute_dispatch_native_warp (the last one skips, as above). The unmodified tree passes.

Mutant Result
tools/startup/gfx2hlsl.py back to main killed: _ps_raw_descriptor and _warp fail
scalar-window snapshot: source 2 → 0 killed (new source assertion)
scalar-window snapshot: upload true → false killed (new source assertion)
scalar-window snapshot: stride and records swapped killed (new source assertion)
scalar-window snapshot: records words[2] → 0 killed (new source assertion); equivalent at run time, see note 1
unsupported udsrc: return; → continue; killed (source assertion)
drop self.raw_load_bound = None killed (two-descriptor control)
constructor drops source killed (_udsrc, and startup_compute_dispatch_input_warp fails)
constructor drops records killed (_udsrc)
records = 0; added after records = view.Buffer.NumElements; survives (same as on 445abdf7)

10 run: 9 killed, 1 survives. One of the killed ones is equivalent at run time and is caught by text only. The files were restored afterwards and git diff --quiet is clean.

Non-blocking.

  1. The scalar-window line is pinned by text only. I rebuilt the first three scalar-window mutants and ran startup_compute_dispatch_native_hardware and startup_compute_dispatch_input_hardware on the RTX 5090: all three still pass 2/2. So only the new source assertion tells them apart. This gap is in main's own scalar-window fixture, not something this PR introduced. The records argument at this site is not read by the compute path (views[i] copies resource, offset, bytes, upload and stride only), so words[2] there has no effect today.
  2. The record count the stand-in publishes for a title-created view is still unpinned (the surviving mutant). Same as non-blocking 1 in my review of 445abdf7.
  3. A raw title-created view gets a count in elements, not bytes. Unchanged from non-blocking 2 on 445abdf7 (read from the code, not run).
  4. The description is still stale. It names 551708c4 as the commit under test and says the stand-in "does not yet publish numrecords".

Verdict: approve on c0d43994. The rebase kept the reviewed change intact and the one new construction site is correct. R0Y00's changes-requested review on 551708c4 is still recorded; its two points (the dropped numrecords entry and the wrap after truncation) are addressed at this head, but that review needs R0Y00's own sign-off, so I am not merging this.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 debug layer on for the hardware runs (X2W_TEST_DEBUG_LAYER=1).
CI: Build and test on Windows passes on c0d43994.

This reply was AI-assisted.

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

Head c0d43994, read against main 20bd1553 (git merge-tree clean, tree ce8c6bf4). Diff and source reading only, nothing built or run.

One construction site is still positional: src/startup_stubs/native_mesh57.inl:23, view = {range.resource, range.offset, range.bytes, 0, true};. view is an element of std::array<IndirectBufferView,32> (:14, :18). The line is the same on main, at this head and in the merged tree.

  • On main the members are resource, offset, bytes, stride, upload, source, so true is upload.
  • With IndirectBufferViewOf (stride, records, upload, source), true goes to records and upload stays false. bool to unsigned is not a narrowing conversion, so this compiles.

Effect, from reading the code: native_mesh57.inl:205 at this head does if (!views[i].upload) require_state(self, views[i].resource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);. The range at :22 comes from list_upload_range, whose pages are committed on an upload heap in GENERIC_READ (list_upload_pages.h). For a resource it does not track, require_state issues a COMMON to NON_PIXEL_SHADER_RESOURCE transition. On main the flag is true and no barrier is issued. The file is included outside any #ifdef (d3d12_xs_device.cpp:7077 at this head).

Fix: view = indirect_buffer_view(range.resource, range.offset, range.bytes, 0u, 0u, true, 0);.

check_udsrc() asserts construction lines in d3d12_draw.inl and d3d12_compute_dispatch.inl only, so it does not see this file. An assertion for the line above would cover it.

The approval on c0d43994 says native_mesh57.inl only reads members by name; line 23 is the exception. A git grep over src/startup_stubs in the merged tree for brace initializers ending in a bool finds no other one of this type (the two in d3d12_compute_dispatch.inl are the local struct View).

cursoragent and others added 7 commits November 29, 2026 12:23
Track the structured-to-raw descriptor conversion in a pixel stage and
lower a non-indexed buffer load as a raw byte-address read bounded by
the converted byte count.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
A pixel load through the structured-to-raw conversion adds each address term with an overflow check before the range compare. A typed buffer load through that descriptor stays refused. The draw stand-in stores numrecords from dword 2 of the table descriptor and refuses an unknown udsrc line.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Brace initialization put the upload flag in records and narrowed the record count into the bool. The view is filled by member name, including the compute root returns.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
The parser cases live in a small C++ target the Windows build compiles with MSVC. The Python check runs that binary, and compiles the same source with cl or g++ when CTest has not handed it one.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Created buffer views publish their element count, and every indirect
buffer view is still built by the named constructor so records and the
snapshot source stay in their own fields. The raw-buffer fixture leaves
one root dword for its descriptor table.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
The brace list put the snapshot source into the upload flag, which
narrows an int into a bool. The record count stays in its own field.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/ps-raw-descriptor-conversion branch from c0d4399 to 185b7de Compare November 29, 2026 12:24
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Fixed at 185b7decd0e0cb0bf359990c6a5dc6ead9e03dc7. The Mesh57 upload-range path now uses indirect_buffer_view(range.resource, range.offset, range.bytes, 0u, 0u, true, 0), so upload stays true. I added an assertion for that construction. The branch is rebased onto main 77d1ba4d.

Windows test PC (MSVC, --preset dev, -j 1):

  • build: exit 0
  • ctest --preset dev --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor.*|native_fixed_mesh57_buffers_(warp|hardware))$' -E 'startup_audio_(output|pacing|provider)': 6/6 passed, exit 0 (native_fixed_mesh57_buffers_warp, native_fixed_mesh57_buffers_hardware, startup_gfx2hlsl_ps_raw_descriptor_udsrc, startup_gfx2hlsl_ps_raw_descriptor, startup_gfx2hlsl_ps_raw_descriptor_warp, startup_gfx2hlsl_ps_raw_descriptor_hardware)

AI-Assisted

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

Head 185b7dec, rebased onto main 77d1ba4d. Diff and source reading only, nothing built or run. This replaces my review of c0d43994.

git range-diff against c0d43994: the six earlier commits are unchanged apart from rebase context in one of them. 185b7dec is new (2 files, +4/-1).

Fixed: src/startup_stubs/native_mesh57.inl:23 is now view = indirect_buffer_view(range.resource, range.offset, range.bytes, 0u, 0u, true, 0);. With the signature in indirect_buffer_view.h:21 (stride, records, upload, source), upload is true and records is 0, as on main, so the if (!views[i].upload) require_state(...) loop issues no transition for the upload range.

check_udsrc() now asserts that line and the absence of view = {range.resource (tests/startup_gfx2hlsl_ps_raw_descriptor_check.py:422-424). Restoring the old line fails both. This is a source-text assertion; no test I read checks the flag at run time.

No other brace initializer of IndirectBufferView remains under src/startup_stubs; the ones in d3d12_compute_dispatch.inl (:651, :839, :884, :926) are the local struct View (:587).

Not run by PR CI: startup_gfx2hlsl_ps_raw_descriptor_(udsrc|warp|hardware) and native_fixed_mesh57_buffers_(warp|hardware) are not in the pr test filter. The Linux job runs the Python script with the assertion above. The device tests rest on your 6/6 on 185b7dec.

git merge-tree --write-tree onto origin/main 77d1ba4d: clean.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 185b7dec (merge-base = main 77d1ba4d). Verdict: hold. Leyukaka approved this head, so the change request that still blocks the merge is R0Y00's on 551708c4, which needs R0Y00's re-review. pigalot's and my earlier points from that round look addressed. One point should be fixed before merging.

SHOULD

  1. pigalot's note about raw title-created views still holds at this head, and the PR's own clamp makes it reachable.
    • Both token branches publish the element count for a raw view: stride = raw ? 0 : element; then records = view.Buffer.NumElements; (d3d12_draw.inl:2578-2579), and strides[i] = typed_view ? element : view.Buffer.StructureByteStride; then record_counts[i] = view.Buffer.NumElements; (:3457-3458).
    • The converted bound is max(ud<stride>, 1u) * ud<numrecords> (the factor = 'max(ud%d, 1u)' line in gfx2hlsl). Per the PR's own comment, it exists because "The clamp (s_max_u32 with 1) makes a stride of 0 count as one byte per record".
    • So for a R32_TYPELESS raw view of N elements the limit is N bytes against 4N in the view. Loads in the upper three quarters read 0, with no log line.
    • Publishing the byte count for raw views (records = raw ? bytes : NumElements, and the same at :3458), plus a raw-view case in the udsrc driver, would close it. The default launcher path (X2W_NATIVE_SHADERS_ONLY=1, which skips these manifests) is unaffected. -Translate runs are where it would show.

CI on this head: Windows, fixtures and Linux Python pass. I didn't build or run the device tests.

AI-assisted.

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

Retested 185b7dec integrated over main 77d1ba4d (tree a9cdca5f), the commit it is rebased onto. That trial merge is clean and git diff --cached --check is clean.

This head now conflicts with main. While I was testing, main moved to 4b0586d4 (#3398 and #3400). git merge-tree reports one conflict, in src/startup_stubs/d3d12_draw.inl: main added #include "startup_stubs/input_view_token.h" and four static_assert lines at the place where this PR adds its two includes (udsrc_line.h, indirect_buffer_view.h). Both sides are needed. CMakeLists.txt and d3d12_compute_dispatch.inl merge automatically. Everything below was measured over 77d1ba4d, not over 4b0586d4; I have not built the resolved merge. main's new commits add no new IndirectBufferView construction site (git diff 77d1ba4d origin/main -- src/startup_stubs/).

A correction to my review of c0d43994. There I wrote that native_mesh57.inl "only reads members by name" and that every construction site went through indirect_buffer_view. That was wrong: line 23 was still view = {range.resource, range.offset, range.bytes, 0, true};, which with the new records member put true in records and left upload false. Leyukaka found it; my approval of c0d43994 should not have been given with that line in place.

What changed since c0d43994. git range-diff over the two bases: the six earlier commits are the same apart from rebase context in one hunk of d3d12_draw.inl. 185b7dec is new, two files:

  • native_mesh57.inl:23 is now view = indirect_buffer_view(range.resource, range.offset, range.bytes, 0u, 0u, true, 0);. Against the signature in indirect_buffer_view.h (stride, records, upload, source) that gives upload = true, records = 0, source = 0, which is what main has. The loop at :202 (if (!views[i].upload) require_state(...)) therefore skips the upload range again.
  • check_udsrc() asserts that line and that view = {range.resource is gone.

I searched the merged tree again for brace initialisation of the view type, this time by pattern over all three files that use it (view = {, typed = {, views[...] = {, return {, IndirectBufferView{...}). The nine construction sites all call indirect_buffer_view. The remaining brace assignments are other types: the local struct View in d3d12_compute_dispatch.inl and the index-buffer view at d3d12_draw.inl:3706.

What I ran. Full dev and release /O2 builds over 77d1ba4d, then

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_ps_raw_descriptor(_udsrc|_warp)?|startup_flat_param_(controls|warp)|startup_gfx2hlsl_buffer_store|startup_gfx2hlsl_load_desc_controls|startup_compute_dispatch_input_warp|startup_compute_dispatch_native_warp|startup_slot67_indirect_dispatch_warp|startup_indirect_translated_(draw|indexed|indexed_upload|indexed_alias)_warp|native_fixed_mesh57_buffers_warp)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_gfx2hlsl_ps_raw_descriptor_hardware|startup_flat_param_hardware|startup_compute_dispatch_input_hardware|startup_compute_dispatch_native_hardware|native_fixed_mesh57_buffers_hardware)$'
  • CPU and WARP: 14 passed and 1 capability skip in Debug and in Release. The skip is startup_compute_dispatch_native_warp (77).
  • Hardware: 5/5 in Debug and in Release, no skips. Both compilers read back 3f800000,40800000,41000000,00000000 and "a wrapping address reads four zeros"; startup_flat_param_hardware reports debug_errors=0 debug_warnings=0 for every case.

Title run. prwatch's real-title run of this head: pass (job 35).

Negative control and mutants. Each was rebuilt in dev and run against startup_gfx2hlsl_ps_raw_descriptor, _udsrc, _warp, native_fixed_mesh57_buffers_warp and startup_compute_dispatch_input_warp. The Mesh57 mutants and "constructor drops upload" were also run against native_fixed_mesh57_buffers_hardware with the debug layer on. The unmodified tree passes all of them.

Mutant Result
tools/startup/gfx2hlsl.py back to main killed: _ps_raw_descriptor and _warp fail ("through a modified descriptor")
Mesh57: old positional brace restored killed by the new source assertion only; both Mesh57 device tests pass
Mesh57: upload true → false killed by the new source assertion only; both Mesh57 device tests pass
Mesh57: records 0u → 1u killed by the new source assertion; equivalent at run time (nothing in native_mesh57.inl reads records)
scalar-window snapshot: source 2 → 0 killed (source assertion)
constructor drops records killed (_udsrc and the source assertion)
constructor drops upload killed (_udsrc and the source assertion); native_fixed_mesh57_buffers_hardware passes
records = 0; added after records = view.Buffer.NumElements; survives (same as on 445abdf7 and c0d43994)

8 run: 7 killed, 1 survives. One of the killed ones is equivalent at run time. The files were restored afterwards and git diff --quiet is clean.

Non-blocking.

  1. The Mesh57 upload flag is pinned by text only. With upload false on that line, native_fixed_mesh57_buffers_warp and native_fixed_mesh57_buffers_hardware (RTX 5090, debug layer on) still pass. So the device tests would not have caught the regression at c0d43994, and would not catch it coming back in a different spelling. I did not check whether the fixture's root SRV address is inside an upload range at all; if it is not, the changed line is never reached by a test. That gap is in main's Mesh57 fixture, not introduced here.
  2. The record count the stand-in publishes for a title-created view is still unpinned (the surviving mutant). Unchanged from my earlier reviews.
  3. The description is still stale. It names 551708c4 as the commit under test and says the stand-in "does not yet publish numrecords".

Verdict: comment, not an approval, because the head no longer merges into main. Over 77d1ba4d I found nothing blocking: the Mesh57 site is fixed and the rest is unchanged from what I tested before. Please merge main 4b0586d4 (keep both include blocks in d3d12_draw.inl); I will retest that head. R0Y00's changes-requested review on 551708c4 is still recorded; its two points (the dropped numrecords entry and the wrap after truncation) are addressed at this head. I am not merging this.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 debug layer on for the hardware runs (X2W_TEST_DEBUG_LAYER=1).
CI: Build and test on Windows passes on 185b7dec.

This reply was AI-assisted.

@Leyukaka

Leyukaka commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Taking this over since there has been no activity for 48 h; will hand back if you resume. Your commits stay as they are and keep your authorship; I will rebase onto current main, address the open review points and report the test results here.

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.

startup: pixel-stage raw buffer loads through the structured-to-raw descriptor conversion are refused as "modified descriptor" since #2910

9 participants