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

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: 551708c42ba15bb8eddc4b5fc4be97bf5d7a7c91, on top of upstream main db28a796.

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.

Windows test PC (RTX 4070 Ti, driver 621.35, Windows 11 25H2, MSVC 19.44):

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_gfx2hlsl_' -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider'

startup_gfx2hlsl_ps_raw_descriptor, startup_gfx2hlsl_ps_raw_descriptor_warp and startup_gfx2hlsl_ps_raw_descriptor_hardware passed twice (3/3, ctest exit 0, no skips; 3.00 s and 2.76 s). The same worktree then ran the full startup_gfx2hlsl_ list: 379/379 passed, 0 failed, 0 skipped, ctest exit 0, 1158.04 s.

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)

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>

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

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@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.

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>

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

cursoragent and others added 2 commits November 27, 2026 23:00
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>

@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

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

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

Every indirect buffer view is built by the named constructor, so records
and the snapshot source stay in their own fields. A buffer view the title
created publishes its element count, and the raw-buffer fixture leaves one
root dword for its descriptor table.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

@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

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