Skip to content

native: read 2D table texture width and base level from entry words - #3500

Open
JB2WIN wants to merge 5 commits into
R0Y00:mainfrom
JB2WIN:native/image-descriptor-fields
Open

JB2WIN wants to merge 5 commits into
R0Y00:mainfrom
JB2WIN:native/image-descriptor-fields

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3224 (claimed in #3224 (comment)), #3023.

Compute programs read fields of a table image descriptor with scalar ALU ops. The direct translator refused those reads as unbound numeric SGPR sN. The read chain I found in the local cohort (category tags only):

  1. s_bfe_u32 word 1, 0x2001e: width low bits;
  2. s_and_b32 word 2, 0x3fff: width high bits;
  3. s_bfe_u32 word 3, 0x4000c: base level;
  4. s_cmp_eq/lg_* word 1 against inline 0: a null check.

Bit positions come from the public AMD PAL driver (MIT): the gfx10 member of sq_img_rsrc_t in gfx10_sq_ko_reg.h, and Device::SetImageSrdDims (width_lo = (width - 1) & 3; width_hi = (width - 1) >> 2). No console SDK material.

What changes, for a 2D texture_srv that the program also samples:

  • Translator: a pre-pass reserves entry words after the stride words. The four reads are replaced only when their symbol is a word of that exact slot, so buffer descriptor words keep their path. The null check becomes a constant: word 1 holds the 9-bit format, and the dispatch only runs with a resolved input texture. The SRV register comes from the image op's own binding after lowering.
  • Manifest: udsrc N imgwidth S and udsrc N imgbase S. Any view other than one 2D texture SRV is refused by name.
  • Runtime (published and in-process routes): new sources input_image_width / input_image_base before output_word3. They are filled from the bound view: the resource's mip-0 width - 1, and the described view's MostDetailedMip (0 when undescribed). 96-bit and BC formats are refused, and the fill switch gets a default that refuses.
  • NativeComputePipeline refuses these words instead of dropping them.
  • No output revision bump: no cached manifest of such a program can exist (they were refused before), and other programs give the same manifest bytes.

Impact on main 0ff17e2c, local 2,689-request cohort, compile_dxil --refusals: only 2 requests move (unbound numeric SGPR 169 to 167; translated stays 827). Most programs with this chain now stop at the resource-heap refusal first. This is mainly the next blocker for the #3023 heap-texture route, where the same chain follows the GPU-selected texture load.

Tests (RTX 3080 and WARP):

  • New startup_compute_dispatch_image_fields_{controls,warp,hardware}. The consumer mode dispatch-texdim-fields uses an R32_FLOAT 8x4 texture with 3 mips, each mip uploaded, viewed as TEXTURE2D from mip 1. Expected: width 8 (mip 0, not the view's 4), base 1, null-check store skipped, image_load (1,1) = 105.0. An undescribed view gives width 8, base 0, texel 9.0.
  • Controls: an scc1 mutant writes the sentinel (hardware), which shows the store is live. Mask 0x3ff, bfe 0x90014 (the format field) and a program without the image op keep their refusal. Manifests rewritten to a buffer source or a missing SRV are refused and leave the output untouched.
  • On WARP the wave32 module cannot run, so, as in the cube test, an HLSL stand-in replaces the .cs.cso. WARP therefore checks the manifest, reader and fill; the translated math and null check run on hardware only. The hardware run also checks the in-process route (X2W_NATIVE_SHADERS).
  • native_compute_manifest_reasons: the new lines, plus refusals for a buffer SRV, 1D, 2D array, a missing SRV, an unknown field, and more than 32 entry words.
  • Regression: 39/39 of startup_compute_dispatch|native_compute_manifest|native_compile_dxil|direct_compute|startup_compute_token (2 WARP skips as on main).
  • One-line src mutations, each caught: null_lg SCC 1 -> 0 and the field SCC ne -> eq (hardware run), the width_hi match 0x3fff -> 0x3ff (compile controls), the width_lo mask 3 -> 1 (hardware run). Details in the review thread.
  • Not in the pr CTest preset, like the other texture-dims tests.

Not tested: the 96-bit/BC and non-2D refusals in the runtime fill, the NativeComputePipeline refusal, and a warm-cache read of the new cache field. A tiled-address SRV's desktop texture is assumed to have the title's width. The assumption is the unpadded mip-0 extent (a padded view would differ).

AI-assisted.

🤖 Generated with Claude Code

Compute programs read an image descriptor's width (word 1 bits 30-31 and word 2 & 0x3fff), base level (word 3
bits 12-15) and a word-1 null check with scalar ALU ops. For a 2D table texture SRV the program samples, the
direct translator now replaces those four reads with entry words (udsrc imgwidth / imgbase) that the stand-in
fills from the bound view, and the null check with a constant. Other descriptor word reads keep their refusal.

Refs R0Y00#3224, R0Y00#3023

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Diff-only review of b33ca9c (not built, not run).

Must fix. The Linux Python job is red: tests/startup_triage_run_check.py reports five source reasons missing from COMPUTE_DISPATCH_REASONS (tools/startup/triage_run.py:71): an entry value source is unknown, an image field entry value names a view that is not a texture input, an image field source has a format whose descriptor extent is not its width, an image field source is not an input texture, more than 32 entry values. The PR does not touch that file.

Should. The fixture only uses s_cmp_eq_u32. The s_cmp_lg_* and _i32 forms (src/gfx1013_direct_compute.inl:3213-3216, the null_lg fold at :3413) are never assembled, and no branch consumes the SCC written for the replaced s_bfe_u32/s_and_b32 (:3416). One more fixture line with s_cmp_lg_u32 s25, 0 would cover the other constant.

Should. "With src/ reverted, the three new tests fail" counts native_compute_manifest_reasons, which then stops compiling (no image_fields member). CONTRIBUTING.md:100: a build error is not a catch. A one-line mutation of a mask or of a null-check constant (inl:3405-3413) would show what the tests catch.

The src change itself looks correct: the three masks match the fields described (inl:3405-3409), and the null-check fold is backed by the runtime refusing an input texture with no token or no desktop texture before the fill (src/startup_stubs/d3d12_compute_dispatch.inl:928-930).

Conflicts with #3498 in tests/native_compute_manifest_reasons.cpp (case list and final count); whichever lands second rebases.

…asons

Review of R0Y00#3500 (Leyukaka): startup_triage_run_check found five new source reasons missing.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The must-fix is in e37bd1a: the five reasons are in COMPUTE_DISPATCH_REASONS, and tests/startup_triage_run_check.py passes locally (0 failed). The two shoulds (an s_cmp_lg_u32 line plus a branch on the replaced SCC in the fixture, and a one-line mutation check instead of the build-break revert) are next on this branch.

AI-assisted.

JB2WIN added a commit to JB2WIN/Xbox2Windows that referenced this pull request Nov 29, 2026
The image field fixture now also assembles s_cmp_lg_u32 word 1, 0 with a
branch over a store, and two field reads (base, width_hi) each followed by
s_cbranch_scc0 over a store, so the SCC the translator writes for a replaced
read is consumed. Base 0 on the undescribed view covers the SCC 0 path.

A mutant now replaces only the first line it names, since
s_cbranch_scc0 4 occurs twice.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@Leyukaka both shoulds are in b04c1a7.

Fixture. It now also assembles s_cmp_lg_u32 s25, 0 with a branch over a store (word 4), and a base read and a width_hi read, each followed by s_cbranch_scc0 over a store (words 5 and 6). So the SCC of a replaced read is consumed. Base 0 on the undescribed view covers the SCC 0 path. The width_hi read is only seen with SCC 1, because both views have width 8.

One-line mutations in src/gfx1013_direct_compute.inl, each rebuilt and run (local RTX 3080, hardware adapter):

Line Mutation Caught by
3413 null_lg writes SCC "0" instead of "1" hardware: word 4 expected 600df00d, read c5c5c5c5. The old fixture passes.
3416 field SCC cmp("eq", ...) instead of "ne" hardware: word 5 expected 00000001, read c5c5c5c5. The old fixture passes.
3207 width_hi match 0x3ff instead of 0x3fff controls (compile, also in CI): the original is refused
3405 width_lo mask "1" instead of "3" hardware (old and new fixture)

The first two only show on hardware: WARP runs the HLSL stand-in, not the translator's DXIL. After the restore, ctest -R 'image_fields|manifest_reasons|triage_run' passes 7/7.

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.

Diff-only re-review of b04c1a7 (not built, not run). The earlier points are addressed: the five reasons are in tools/startup/triage_run.py (:119, :125-127, :228); the fixture now assembles s_cmp_lg_u32 s25, 0 and two field reads whose SCC is consumed by s_cbranch_scc0 (words 4-6); the revert question is answered by the four src mutations listed in the comment (not reproduced here).

Nits: the _i32 compare forms are still not assembled, and the PR body still says the three new tests fail with src/ reverted.

Only blocker: conflict with main (ff9dcef) in tests/startup_stream_consumer.cpp, in the "output at byte 32" condition. Keep both sides, joined by ||: main's (records32 && std::strcmp(records32, "1") == 0) and this PR's mode.rfind("dispatch-texdim-fields", 0) == 0. The other files auto-merge.

Will approve once rebased and CI is green (no checks reported on this head).

JB2WIN and others added 2 commits November 29, 2026 23:25
…ptor-fields

# Conflicts:
#	tests/startup_stream_consumer.cpp
s_cmp_eq_i32 and s_cmp_lg_i32 word 1, 0 each branch over a store that runs
for a non-empty view (words 7 and 8).

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@Leyukaka merged main in 39cbf13 (no rebase, so your earlier review comments keep their anchors). In tests/startup_stream_consumer.cpp I kept both conditions, joined with ||. 2902e50 adds the _i32 forms: s_cmp_eq_i32 and s_cmp_lg_i32 word 1, 0, each with a branch over a store (words 7 and 8). The PR body now lists the mutations instead of the revert.

Local, after the merge: ctest -R 'startup_compute|image_fields|manifest_reasons|triage_run' passes 210/210. The 10 skips are the WARP wave32 cases, as on main.

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.

Re-read at 2902e50 (diff only, not built here). The merge of main in tests/startup_stream_consumer.cpp keeps both conditions: the dispatch-texdim-fields prefix and main's X2W_TEST_RECORDS32=1 check, joined by ||.
The new words decode as intended: 198000bf is SOPC op 0 s_cmp_eq_i32 s25, 0 and 198001bf is op 1 s_cmp_lg_i32 s25, 0, each followed by a 2-dword branch over one buffer_store_dword (offsets 28 and 32), so the _i32 names accepted at gfx1013_direct_compute.inl:3282-3285 are now exercised.
The body now lists the four one-line src mutations instead of the earlier sentence, and CI is green on this head. Approving.

@Not-Saii Not-Saii 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 2902e50: a static read and an isolated sandbox build and run (details at the end).

The earlier review points are addressed at this head:

  • the five runtime reasons are in tools/startup/triage_run.py;
  • the fixture now assembles s_cmp_lg_u32 and the _i32 forms, with branches that consume the SCC of the replaced reads;
  • the body lists one-line mutations instead of the revert;
  • the merge with main keeps both byte-32 conditions, joined with ||.

Logic

I read the translator, manifest, cache and runtime changes. They look correct:

  • Bit fields. The s_bfe_u32 immediates decode as offset/width pairs: 0x2001e = bits 31:30, 0x4000c = bits 15:12, 0x90014 (the control) = bits 28:20. These match the public gfx10 image descriptor:

    • word 1: the 9-bit format at 28:20 and width_lo at 31:30;
    • word 2: width_hi at the bottom;
    • word 3: BASE_LEVEL at 15:12.

    The repo has no other decode of image width or base level, so I checked against the public layout, not against existing code. For any D3D12 2D width ≤ 16384, (width - 1) >> 2 ≤ 4095. So the 0x3fff mask and the translator's (w >> 2) & 16383 agree whether width_hi is 12 or 14 bits wide.

  • SCC. For the replaced s_bfe_u32/s_and_b32, SCC is result != 0 (src/gfx1013_direct_compute.inl:3485), which is the ISA definition. Folding the null check to a constant is backed by the runtime: it refuses an input that has no token or no desktop texture before the fill.

  • Word order. initialize_constants (:375-378), bind_image_fields (:3320) and the manifest and in-process orderings all walk the same std::map in key order, after the stride words. The entry-word layout therefore matches on both routes.

  • In-place overwrite. binding() already refuses a non-contiguous descriptor. A program that overwrites a descriptor word in place with one of these reads and then samples the descriptor is still refused.

  • Source enum. The new Source values sit before output_word3, so the >= output_word3 split between inputs and outputs is unchanged. The manifest name table (src/startup_stubs/d3d12_compute_dispatch.inl:330-331) maps s + 1 to the enum in order.

  • Cache. The .csir layout changes without an output revision bump, which is safe. slot67_digest and the container identity both start with X2W_NATIVE_SHADER_REVISION, a hash that covers direct_compute_cache.cpp and gfx1013_direct_compute.inl. An old payload is therefore never looked up under the new key.

  • Format refusal. The DXGI ranges are right: 5–8 (R32G32B32), 70–84 (BC1–BC5), 94–99 (BC6H–BC7).

Findings

None of these block merging.

SHOULD 1: evidence fields in the PR body. The body names "RTX 3080 and WARP", but it does not give:

  • the commit those runs used;
  • the driver version;
  • the Windows build;
  • the debug-layer status;
  • the exact ctest --preset dev … command (the comments give only -R patterns).

AGENTS.md "Evidence" asks for all of these. Please add them for the final head.

SHOULD 2: CI does not run any of this PR's tests. The PR run on 2902e50 (run 46317728773) passed, but:

  • The Windows job ran the pr preset (82/82). The preset matches none of startup_compute_dispatch_image_fields_{controls,warp,hardware} or native_compute_manifest_reasons, and the log has no image_fields line.
  • The Linux job ran tests/startup_triage_run_check.py (0 failed).

The b04c1a7 comment says the width_hi mutation is caught "by controls (compile, also in CI)". That is not true of this PR's CI. Please fix that wording, or, if the preset owners agree, add startup_compute_dispatch_image_fields_controls and native_compute_manifest_reasons to the pr preset. Neither needs WARP or a GPU: the first needs only compile_dxil and DXC, which the Windows PR job already builds.

NIT 1: the fixture's binary mode runs nowhere in CI. startup_compute_dispatch_image_fields_check.py binary is not in the CHECKS list of the LLVM 15 job (.github/workflows/windows.yml:41). I assembled all 45 recorded encodings with LLVM 15.0.7 for gfx1013 (42 program lines and 3 mutant replacements), and every one matches. Adding the line there would keep that true.

NIT 2: the run tests fail instead of skipping when the debug layer is not installed. tests/startup_compute_dispatch_image_fields_check.py:273 asserts that the layer was enabled. On a host without the Graphics Tools SDK layers, _warp and _hardware fail at that line, and the sections after it never run. This follows startup_compute_dispatch_cube_check.py:206, so it is optional here. (The sandbox below had the layer, so it was not hit.)

NIT 3: some paths have no test, beyond those the body already lists:

  • the three new translator refusals: more than 32 entry words with image fields, an image descriptor field has no sampled texture and ... more than one texture binding;
  • a program whose only use of the slot is the null check (an entry with no words);
  • a warm-cache decode of the new .csir field. Publishing twice over the same cache and rerunning check_manifest would cover it.

What each test proves

  • startup_compute_dispatch_image_fields_controls (compile only):

    • the fixture publishes natively with ud 4, udsrc 2 imgwidth 0, udsrc 3 imgbase 0 and srv 0 tex2d table 1 64;
    • the 0x3ff mask, the format-field bfe and the program without the image op each keep the unbound numeric SGPR refusal;
    • the scc1 mutant still publishes.

    This shows the matcher is narrow. It runs nothing.

  • startup_compute_dispatch_image_fields_warp: an HLSL stand-in replaces the published .cs.cso. The test covers:

    • the manifest reader;
    • the runtime fill: mip-0 width − 1, and MostDetailedMip (0 when the view has no description);
    • the two rewritten-manifest refusals.

    It does not run the translator's DXIL.

  • startup_compute_dispatch_image_fields_hardware: runs the translated wave32 DXIL end to end, including the null-check constants and the SCC consumers (words 4–8). It also runs the scc1 control, which shows the store is live, and the in-process route.

  • native_compute_manifest_reasons: the formatter's new lines and its refusals (buffer SRV, 1D, 2D array, missing SRV, unknown field, more than 32 words).

Mutation

A one-line revert of the fix, applied to a scratch copy only: in src/gfx1013_direct_compute.inl:5272, the prepare_image_fields(); call was commented out.

  • The rebuild check passed: compile_dxil.exe and native_compute_manifest_reasons.exe were relinked, so the mutant was built (no build error).
  • startup_compute_dispatch_image_fields_controls, _warp and _hardware all failed at publish, with the translator's native compute +0x20: unbound numeric SGPR s25 refusal.
  • The other six tests passed.
  • After restoring the head file (sha256 matches head) and rebuilding, all 9 passed again.

Sandbox run (AGENTS.md fields)

  • Commit: head 2902e500895ac2cd82bfa1c38e4048c42ca3eed5, exported with git archive, merge base 2ff74a6ac3. The sandbox had networking disabled and the tree mapped read-only.
  • OS: Windows 11 Enterprise 10.0.26100 (build 26100), inside Windows Sandbox.
  • Adapter: NVIDIA GeForce RTX 4090 through the sandbox vGPU. The driver reported inside the sandbox is 10.0.26100.1150 (the virtual adapter's WMI driver). WARP 1.0.22 is app-local, from the build's WARP directory.
  • Debug layer: enabled, with no error message in any fixture. The Graphics Tools SDK layers were installed in the sandbox, the D3D12GetDebugInterface probe returned hr=0x00000000, and X2W_D3D12_DEBUG=1 was set. The build was configured with the Agility SDK 1.620 directory.
  • Toolchain: MSVC 14.44, CMake 3.31.6, Debug, Python 3.14.8.
  • Commands:
    cmake --preset dev -DX2W_WITH_OPUS=OFF -DINTAKE_PYTHON=<venv python> -DOFFSCREEN_AGILITY_620_DIR=<agility> -DOFFSCREEN_WARP_DIR=<warp>
    cmake --build --preset dev --target compile_dxil startup_stream_consumer offscreen_check native_compute_manifest_reasons
    ctest --preset dev --no-tests=error --output-on-failure -V -R '^(startup_compute_dispatch_image_fields_(controls|warp|hardware)|native_compute_manifest_reasons|startup_compute_dispatch_texture_dims_(warp|hardware)|startup_compute_dispatch_cube_(controls|warp|hardware))$'
    
  • Head results: 9 passed, 0 failed, 0 skipped (77).
    • Passed: native_compute_manifest_reasons, startup_compute_dispatch_image_fields_{controls,warp,hardware}, startup_compute_dispatch_cube_{controls,warp,hardware}, startup_compute_dispatch_texture_dims_{warp,hardware}.
    • The cube and texture_dims tests are regression checks for the changed consumer branch.
    • On hardware the fixture printed: width 8 (mip 0, not the view's 4), base 1, the empty-check store skipped, texel 105.0; with s_cbranch_scc1 word 2 is 0xdeadbeef; the in-process route filled the same words (4 entry values, 1 input, 1 output); the rewritten manifests were refused with the output untouched.
  • Mutant results: 6 passed, 3 failed (the three image_fields tests, as expected), 0 skipped.
  • Restored results: 9 passed, 0 failed, 0 skipped.
  • CI: CI ran none of this PR's ctest tests, only tests/startup_triage_run_check.py on Linux (see SHOULD 2).

Approving. The SHOULDs are about evidence and CI coverage, not behavior.

@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

@JB2WIN this one has two approvals and green checks, but it now conflicts with main and has fallen quite far behind. Do you plan to rebase it? If you would rather not, we are happy to carry the rebase for you, keeping your commits as they are. Either way works for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants