Skip to content

shader: lower pixel image descriptor size fields read as numbers - #3225

Open
SimSalabimse wants to merge 4 commits into
R0Y00:mainfrom
SimSalabimse:cursor/ps-desc-word-numeric
Open

SimSalabimse wants to merge 4 commits into
R0Y00:mainfrom
SimSalabimse:cursor/ps-desc-word-numeric

Conversation

@SimSalabimse

@SimSalabimse SimSalabimse commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Pixel shaders can now read the size fields of an image descriptor as numbers.

In gfx2hlsl, a pixel stage that uses an 8-dword image descriptor can extract width, height, and (for a 3D image) depth with the exact s_bfe_u32, s_and_b32, or s_lshr_b32 for that field. Those lower to GetDimensions(0) on the texture the image instruction already binds. Width is the usual split: word 1 bits 31:30 and word 2 bits 11:0, stored as width minus one. Height is word 2 bits 27:14. Depth is word 4 bits 12:0 and only for 3D.

A whole word, any other word or field, a shift of word 2 that also keeps the resource-level bit, depth on a 1D, 2D, or 2D-array image, height on a 1D image, a modified word, and m0 still refuse, and the message says which word or op. Buffer descriptors and the compute and vertex stages are unchanged.

A marked SRV is refused when MostDetailedMip is not 0 and when the direct draw would bind no texture. image_size_bind() in src/startup_stubs/image_size_mip.h makes that decision. An unmarked sample is unchanged. startup_image_size_mip covers a non-square 8 x 4 view at resource mip 0, the same view at MostDetailedMip 1, a marked SRV with no texture, and the imagedim parser. The three WILL_FAIL controls drop the mip refusal, drop the null refusal, or reject valid imagedim lines. The pr preset now also runs startup_gfx2hlsl_image_desc_word_controls and startup_image_size_mip.

Verification

Commit 1820f8763ce4488848e6701ab35edf17c72910bb, rebased onto main af1cab5ceb7b9ecbe06acf358b5b6477c265de9b. The branch is 5 commits behind current main c04e0dd6e9b73cf7ecd096ef71aa3e9115035e3c and still merges cleanly.

Windows test PC (MSVC, --preset dev, -j 1). Build exit 0. Then:

ctest --preset dev --no-tests=error -j 1 -R '^(startup_gfx2hlsl_image_desc_word_controls|startup_image_size_mip(_[a-z_]+)?)$' -E 'startup_audio_(output|pacing|provider)' --output-on-failure

5 of 5 passed, ctest exit 0. The three startup_image_size_mip_*_control tests are WILL_FAIL and failed as required.

Not in this head: the _control tests still override the helper's result inside the test rather than mutating src/, and there is no device draw at mip 0 and at MostDetailedMip=1.

Fixes part of #2022

AI-assisted (Cursor)

@KelboLive KelboLive 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 PR #3225 — shader: lower pixel image descriptor size fields read as numbers

Summary

This PR adds support for lowering exact GFX10 image descriptor size fields (width, height, depth) as numeric values in the pixel stage HLSL translator. The implementation is well-scoped and correct.

Changes reviewed

  • tools/startup/gfx2hlsl.py: New IMAGE_FIELDS dictionary mapping (word_index, instruction, control) → (field_name, expression). New image_field_expr() method to match scalar ops against known size-field patterns. image_span tracking in Stage class follows descriptor data across register moves. Helper function generation for GetDimensions calls at the Pipeline level.
  • tests/startup_gfx2hlsl_image_desc_word_check.py: Comprehensive test suite — 10 accepted cases (width/height/depth for tex1d/tex2d/tex2da/tex3d), plus refused cases covering wrong words, wrong operations, vertex stage, buffer descriptors, m0 usage, and modified descriptor words.
  • Build/config files: CMakeLists.txt adds the test; .github/workflows/windows.yml includes it in CI; AGENTS.md documents the command; docs/experiments.md documents the feature with reproduction steps.

Assessment

  • The implementation is well-scoped: only exact GFX10 size-field patterns are accepted, everything else stays refused.
  • The image_span tracking correctly follows descriptor data across s_mov_b32 moves, which is important for correctness when registers are reused.
  • Test coverage is thorough — both positive (accepted translations) and negative (refused cases), plus the "without_field_expr" control that verifies every accepted case fails when the feature is removed.
  • The comments reference Mesa radv_image.c for traceability of the field layout.

Minor notes

  1. IMAGE_DIM_HAS dictionary is defined but never used — could be removed or used as an assertion guard, though its absence doesn't affect correctness since refusal logic already handles this via per-dimension checks (e.g., refusing depth for 1D/2D/tex2da).
  2. IMAGE_DIM_NAME dictionary is also defined but unused — same assessment as above.

Verdict: Approve

@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 reviewed e264b8c7 merged over current main 58e3183a. The merge is clean (tree d99811ce) and git diff --cached --check is clean.

What I traced.

  • The field table: it matches the GFX10 image descriptor layout. WIDTH−1 is split as word 1 bits 31:30 plus word 2 bits 11:0, HEIGHT−1 is word 2 bits 27:14, and DEPTH−1 is word 4 bits 12:0. Each s_bfe_u32 control, s_and_b32 mask and s_lshr_b32 shift in IMAGE_FIELDS extracts exactly that field.
  • The templates: each one rebuilds those bits from GetDimensions(0), so the & 3, >> 2, & 0x3fff and << 14/<< 30 forms are right.
  • The CI and AGENTS.md edits: they only register the new check.

Finding: the image dimension is assigned per register, not per descriptor load.

  • What happens: note_image_descriptors() scans the whole program once and gives each SGPR the dim: of any image instruction that uses it. image_word() then checks only that the register currently holds some 8-dword load. So a size-field read of one descriptor gets its dimension from an image instruction that samples a different descriptor loaded into the same registers.

  • Probe: it uses the lz fixture from your check. Before the fixture's own s_load_dwordx8 s[16:23], s[8:9], 0x0, I prepend:

    s_load_dwordx8 s[16:23], s[8:9], 0x20
    s_waitcnt lgkmcnt(0)
    s_and_b32 s10, s18, 0xfff
    

    and then add v_mov_b32_e32 v4, s10 after the image instruction (splice(WORDS['lz'], ('v_mov_b32_e32 v4, s10',), 'after-image')).

  • Result: Pipeline(VS_WORDS, code, root_blob(flags=0)) accepts it. It emits s10 = ((img_width_tex2d(r0) - 1u) >> 2);, and the manifest has srv 0 tex2d table 0 32 next to srv 1 tex2d table 0 0.

  • Why it matters: the descriptor at table offset 32 is never used by an image instruction, yet it is bound as a Texture2D only because the reload at offset 0 is sampled with dim:SQ_RSRC_IMG_2D. If that slot holds a 3D or 1D image, or a buffer, the bound view type is wrong, and the size read is wrong with it. Your docstring says "a load with no image instruction" stays refused. This is that case, reached through register reuse.

  • Suggested direction (unconfirmed): key the dimension by the descriptor load the image instruction actually reads, for example (sym[1], sym[2] + 4 * (sym[3] & ~7)) from the desc symbol at the image instruction. Then require the field read's symbol to match it. The probe above would make a good negative control.

What I ran.

  • python -B tests/<name>.py for startup_gfx2hlsl_image_desc_word_check, startup_image_sample_l_check, startup_gfx2hlsl_cselect_descnum_check, startup_gfx2hlsl_load_desc_check, startup_gfx2hlsl_scalar_m0_check and startup_gfx2hlsl_image_get_lod_check: all exit 0.
  • python -B tests/startup_tools_lint_check.py tools/startup: PASS.
  • ctest --test-dir out/build/dev --no-tests=error -j 8 -R '^startup_gfx2hlsl_' -E '(_warp|_hardware|startup_audio)': 153 of the 154 registered tests pass. The one failure is a test from another PR that was still registered in my build directory. Its file is not in this tree.

Non-blocking. The checks compare HLSL text only. No draw shows that GetDimensions(0) on the view the stand-in creates for srv N tex2d|tex1d|tex2da|tex3d returns the descriptor's size. That holds only under the base-mip contract the docs describe.

Verdict: changes requested on e264b8c7 for the per-register dimension.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; translator checks only, no GPU run.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on e264b8c7.

This reply was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I reproduced the same provenance bug in the opposite instruction order on e264b8c7 over main c7215add (trial tree 313b5535). The existing descriptor-field Python suite passes, and the following source-built pair adds a distinction a fix should preserve.

In the lz fixture, copy s18 to s28 before image_sample, which uses the descriptor from table byte offset 0. After image_sample, reload s[16:23] from table byte offset 32 and wait. Extract s_and_b32 s10, s28, 0xfff in the positive case or use s18 in the negative case, then move s10 to v4.

The copied value correctly emits img_width_tex2d(r0) and one SRV at offset 0. The reloaded s18 incorrectly emits img_width_tex2d(r1) and a second SRV at offset 32, even though no image instruction uses that descriptor. Keep the copied-descriptor case accepted and refuse the later unobserved reload. This complements the existing before-image repro and guards against a fix that rejects valid copies whenever a register is reused.

Copy link
Copy Markdown

After the provenance fix, a useful dimension-specific control is a non-square 3D texture with a view starting above resource mip 0. The VIctory #3613 gather test depends on the first accessible mip's dimensions, so it is a good separate example of why resource and view sizes must be distinguished. Compare the lowered GetDimensions(0) against the guest descriptor's width/height/depth fields for both base-mip and shifted cases. This is a proposed synthetic check, not proof of a mismatch.

@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 4f75193e integrated over current main 32221f1a.

Conflict with main. The merge now conflicts in tools/startup/gfx2hlsl.py, in Pipeline's SRV declaration loop. #2960 added 'texcube': 'TextureCube<float4>' to the same type map that this branch follows with the img_<component>_<kind> helper loop. For testing, I kept main's line and added this branch's helper loop under it (tree 5bf8a8d1, git diff --cached --check clean).

  • That conflict is textual only. This branch's IMAGE_DIM has no SQ_RSRC_IMG_CUBE entry, so a cube-sampled descriptor gets no key in image_desc_dim, and its size-field reads stay refused.
  • The branch needs a main merge before it can land.

My changes request on e264b8c7 (dimension per register): addressed. note_image_descriptors() now keys the dimension by the descriptor load the image instruction reads, image_desc_key = (source, byte offset of the 8-dword image). It requires all eight operand words to be that load, unmodified. image_word() looks up the field read's own symbol.

  • My probe, the offset-32 load into s[16:23] before the fixture's load, read through s_and_b32 s10, s18, 0xfff: now refused (numeric use of s10 holding descnum). It is in the check as early.
  • R0Y00's order, a reload after the sample: the reloaded s18 refuses, and the copy s28 taken before the reload is still accepted, with one SRV, srv 0 tex2d table 0 0. Both are in the check (reloaded, kept).
  • The plain same-descriptor case is still accepted.

What I ran.

  • Build: full dev.
  • Tests: ctest --test-dir out/build/dev --no-tests=error -j 8 -R '(^startup_gfx2hlsl_|image|cube)' -E '(_hardware$|startup_audio)' gives 346 tests: 338 pass, 0 fail and 8 are capability skips (native_image_store_exact_width_warp_*, native_image_atomic_warp and native_image_cache_flags_cs_warp).
  • Lint: python -B tests/startup_tools_lint_check.py tools/startup passes.

Mutants of tools/startup/gfx2hlsl.py, each run against tests/startup_gfx2hlsl_image_desc_word_check.py after an unmutated baseline that passes:

Mutant Result
image_word takes any keyed load's dimension (per-register borrowing back) killed (early)
key aligned to 4 dwords, not 8 killed (3D depth refused)
two dimensions on one key keep the first fails, though on a different assertion (used as tex2d and tex3d)
key drops the dword index survives
the 8-word same check is replaced by key is not None survives
a scalar write other than a load or s_mov keeps the word's symbol in the pre-scan survives
the branch early-return is removed survives
the pre-scan ignores offset: survives
the pre-scan s_mov drops the copy survives
the pre-scan load keeps the old words survives

Restored afterwards; git diff --quiet is clean.

Non-blocking. The fix itself is pinned. The pre-scan's own guards are not: each surviving mutant widens what gets a key, and no control fails.

  • What would be unsound if removed:
    • Dword index: the second image of an s_load_dwordx16 would borrow the first image's dimension.
    • The 8-word same check: a mixed or modified operand would still be keyed.
    • Other scalar writes: a word overwritten by arithmetic would keep its descriptor symbol.
    • The branch refusal: the linear pre-scan would follow a path that isn't taken.
  • Controls that would pin them: a near-miss for each, for example:
    • an x16 load whose two halves are sampled with different dim:;
    • an image operand with one word replaced by s_mov_b32 s17, 0;
    • an s_add_u32 s16, s16, 0 before the sample;
    • a forward s_cbranch_scc0 around the load.
  • The two remaining survivors only refuse more: dropping the s_mov copy or keeping the old words.

Verdict: the per-register finding is addressed on 4f75193e. Approve on 4f75193e as reviewed. It needs a main merge for the #2960 conflict before it can land, and the merged head needs another look then. This supersedes my changes-requested review on e264b8c7.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; translator checks only, no GPU run.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 4f75193e.

This reply was AI-assisted.

@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I pushed a merge of current main 240e0fb9 into this branch as 735924db. It is a merge commit on top of 4f75193e, with no rebase or force-push.

Conflict resolved. The only conflict was in tools/startup/gfx2hlsl.py, in Pipeline's SRV declaration loop. #2960 added 'texcube': 'TextureCube<float4>' to the type map. I kept that line and this branch's img_<component>_<kind> helper loop after it. Nothing else changed in the resolution. This branch's IMAGE_DIM has no cube entry, so a cube-sampled descriptor's size fields stay refused.

What I ran on 735924db.

  • Builds: full dev and release /O2.
  • Image and translator tests: ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '(^startup_gfx2hlsl_|image|cube)' -E '(_hardware$|startup_audio)' gives 346 tests in each preset: 338 pass, 0 fail and 8 are capability skips (native_image_*_warp).
  • The PR's check: python -B tests/startup_gfx2hlsl_image_desc_word_check.py passes. My earlier probe still refuses both reload orderings and accepts the copied-descriptor case.
  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2032 tests: 1973 pass, 0 fail and 59 are capability skips.

Because I made this merge, my approval on 4f75193e doesn't cover 735924db. Another reviewer will check the merged head.

This reply was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I reran the descriptor-word, 2D-array, 3D, image-arity and startup-tool lint checks on 735924db. The existing provenance cases passed, and the merge retains the cube declaration.

There is still an unsupported case entering the ordinary draw path. The experiment and image_field_expr both scope the lowering to views that start at resource mip 0. The generated helper always queries GetDimensions(0u, ...), while the manifest emits an ordinary texture SRV. In d3d12_draw.inl, the texture path copies the recorded SRV descriptor and passes it to CreateShaderResourceView without checking MostDetailedMip for this translation. Shader mip 0 is then the shifted view's first mip if the recorded view starts above resource mip 0. The current fixture checks the HLSL string and provenance, so it does not establish equivalence to the guest descriptor fields for that binding.

Please enforce the documented base-mip requirement for translations that read these fields, or demonstrate equivalent descriptor values for a shifted view. A source-built non-square texture bound once at resource mip 0 and once with MostDetailedMip=1 should distinguish the two. Keep the check scoped to numeric descriptor reads so ordinary sampling through a shifted view still works.

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

Re-reviewed the merge of main into this branch at 735924db (parents 4f75193e and main 240e0fb9). git diff --check origin/main...735924db is clean.

Resolution. git show --remerge-diff 735924db shows one conflict hunk, in Pipeline SRV declarations in tools/startup/gfx2hlsl.py. The merge keeps main's 'texcube': 'TextureCube<float4>' entry from #2960 and this branch's img_<component>_<kind> helper loop. Nothing else changed. I also checked that the two sides don't meet: the branch's IMAGE_DIM map has no SQ_RSRC_IMG_CUBE. A cube descriptor therefore never enters image_desc_dim, so its size fields stay on the existing path. The new IMAGE_DIM_HAS / IMAGE_DIM_TYPE / IMAGE_DIM_READ lookups can't raise KeyError on texcube.

What I ran. I built offscreen_check in dev and release and ran ctest --test-dir out/build/<preset> --no-tests=error -R '^startup_(gfx2hlsl_.*|image_.*)$', with the _hardware tests at -j 1:

  • 307 tests without hardware pass in Debug and Release /O2, including startup_gfx2hlsl_image_desc_word_controls and startup_image_cube_controls.
  • 134 hardware tests pass, including startup_image_cube_hardware.

Control and mutants on the resolved lines. Each was run against startup_gfx2hlsl_image_desc_word_controls and startup_image_cube_{controls,warp,hardware}:

Change Result
tools/startup/gfx2hlsl.py back to main 240e0fb9 (control) the descriptor-word check fails ("numeric use of s10 holding descnum"); the cube tests pass
resolution drops main's texcube SRV entry all three cube tests fail
resolution drops this branch's helper loop the descriptor-word check fails (width lo bfe); the cube tests pass

Restored afterwards; git diff --quiet is clean.

Open request. R0Y00's changes request on 735924db still applies, and the merge doesn't touch it. I read the code and it agrees with that request. The helper always calls GetDimensions(0u, ...) on the SRV the draw path creates from the recorded descriptor. With MostDetailedMip=1, that returns the size of the view's first mip. The descriptor's width and height fields still describe the resource's mip 0. I haven't run the shifted-view case, so this rests on reading only.

Verdict: the merge resolution is correct. No approval while R0Y00's request is open.

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.exe (the one CTest picked up); Python 3.12.10.

This reply was AI-assisted.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Thanks both. I keyed the image dimension by the descriptor load the image instruction actually reads, not by the register. The key is the source and the byte offset of that 8-dword image, and the field read's symbol has to match it. So a load at offset 32 into the same SGPRs no longer borrows the dimension from a sample of the offset-0 load.

Both orders are in the check now. The offset-32 load, the wait and the and of s18 before the fixture's own offset-0 load get refused. Copying s18 to s28 before the sample and then reloading s[16:23] from offset 32 still accepts the and of s28 as the one SRV at offset 0, and refuses the and of the reloaded s18. IMAGE_DIM_HAS and IMAGE_DIM_NAME are used for the dimension check and the refusal text now.

Retested 4f75193 on Windows: image_desc_word passed twice, startup_gfx2hlsl_ 386/386 passed.

AI-Assisted

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the provenance fix. pigalot's per-register request is addressed on this head, and the field masks match the GFX10 layout and the translator's own s_bfe_u32 template. I reviewed 735924db, merged over current main, and three issues still need fixing before this can land:

  1. Conflict with main. git merge-tree --write-tree origin/main 735924db exits 1 with CONFLICT (content): Merge conflict in tools/startup/gfx2hlsl.py. All three hunks are against shader: lower bounded per-lane heap record indices in compute waterfalls (#2644 T3) #2861 (resheap): the new methods, the descriptor-ALU s_add_u32 path and the SRV declaration loop. When I kept both sides, with main's lines first, this PR's check, the image sample_l, cselect_descnum, load_desc, scalar_m0, image_get_lod, cube, 2d_array and 3d checks, startup_compute_waterfall_heap_check.py and startup_tools_lint_check.py tools/startup all exit 0. Please merge main and confirm that image_field_expr still runs after the resheap s_add_u32 early return.
  2. The base-mip request on this head is still open. The helper always calls tex.GetDimensions(0u, ...). In src/startup_stubs/d3d12_draw.inl, the texture path runs std::memcpy(&desc, record.desc, 40) and never checks MostDetailedMip, so a view that starts at mip 1 returns that mip's size and not the descriptor's mip-0 fields. Please refuse these field reads unless the view starts at mip 0, or add the non-square mip-0 vs MostDetailedMip=1 control that was requested.
  3. One operand order lowers to the wrong value. s_lshr_b32 s10, 30, s17 (the descriptor word as the shift amount) is accepted as WIDTH_LO. I spliced it into the lz fixture with the check's own use() and ps(), and both this head and the merge emit s10 = ((img_width_tex2d(r0) - 1u) & 3u);. The translator's template is 's_lshr_b32': ('{0} >> ({1} & 31)', so the real value is 30 >> (word1 & 31). Only s_bfe_u32 has the operand-order guard (if base == 's_bfe_u32' and i != 0). Applying it to the shift as well, plus a refusal control for the swapped form, would fix this.

Two non-blocking points:

  • Mutants that survive. I ran single-line mutants of gfx2hlsl.py against startup_gfx2hlsl_image_desc_word_check.py on the merge. Stubbing image_field_expr and dropping dims[key] = None both fail the check. It still passes (exit 0) with the operand-order guard disabled, with image_desc_key returning (sym[1], sym[2]) (no dword index), and with the branch early return in note_image_descriptors removed. pigalot's near-miss controls from the earlier review would pin these: an x16 load with two dim:, and an s_cbranch_scc0 around the load.
  • CI coverage. Only the Linux Python job runs the new check: its log has tests/startup_gfx2hlsl_image_desc_word_check.py (ok, 0.5s), and the Windows job's ctest --preset pr log never mentions image_desc_word.

Environment: Linux, Python 3.13.5, translator checks only, no build or GPU run.

This comment was AI-assisted.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Retested efb89b9 on the Windows test PC (NVIDIA, 32-lane waves) after merging current main.

The gfx2hlsl.py merge with the resource-heap change is resolved. Size-field reads mark the SRV imagedim, and the draw path refuses that view when MostDetailedMip is not 0. s_lshr_b32 of a size field lowers only when the descriptor word is the value being shifted, not the shift amount. That covers JohnConnorNPC's three items (merge, base mip, shift operand order). No image_desc_word hardware/draw tests are registered; coverage there is startup_gfx2hlsl_image_desc_word_controls.

ctest --preset dev --no-tests=error -j 1 -R '^(startup_gfx2hlsl_image_desc_word_controls|startup_image_sample_l|startup_gfx2hlsl_cselect_descnum_controls|startup_gfx2hlsl_load_desc_controls|startup_gfx2hlsl_scalar_m0_controls|startup_gfx2hlsl_image_get_lod_controls|startup_image_cube_controls|startup_image_2d_array_controls|startup_image_3d_controls|startup_tools_lint)$' -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"

passed 10/10 twice, exit 0.

ctest --preset dev --no-tests=error -j 1 -R waterfall_heap -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"

passed 4/4 once, exit 0.

ctest --preset dev --no-tests=error -j 1 -R startup_gfx2hlsl_ -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"

passed 388/388 once, exit 0.

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.

Read efb89b92 as a diff against main c3259f27. git merge-tree --write-tree is clean and git diff --check is clean. Nothing was built or run; everything below is from reading.

Base-mip request on 735924db: partly fixed

  • The refusal exists. image_dim_call adds the SRV to image_size_srvs, the manifest emits imagedim %d, and draw_translated returns false on
    if (tr->image_size_srvs.requires(i) && !image_size_view_starts_at_resource_mip0(desc)) (d3d12_draw.inl:2940). It only applies to marked SRVs, so a shifted view that is only sampled still binds.
  • Only the Python side is tested: '\nimagedim 0\n' in manifest on the accepted fields, 'imagedim' not in sample_manifest, and 'imagedim 1' not in manifest.
  • Nothing under tests/ refers to ImageSizeSrvs, image_size_srvs or image_size_mip. Removing the MostDetailedMip refusal, or making read_manifest_line return false for every line, fails no test.
  • The requested control, one non-square texture bound at resource mip 0 and again with MostDetailedMip=1, is not in the PR.
  • tests/startup_d16_image_format_check.cpp already tests the parser of the similar d16srv line (duplicate, leading zero, out of range). The same form would cover imagedim.

Earlier review points: fixed

  • Merge with main: image_field_expr is called after the resource-heap s_add_u32 path has returned ("After the resource-heap add returns: a pixel size field is not that pointer add.").
  • Swapped shift: if base in ('s_bfe_u32', 's_lshr_b32') and i != 0: makes it opaque, and the check has refused(use('lz', 's_lshr_b32 s10, 0x1e, s17'), 's_lshr_b32 of image descriptor word 1').

Finding: on a direct draw, a marked SRV can still bind null

  • The mip check is inside if (texture && record.desc_bytes >= 40), so it is skipped when there is no texture. In the same loop texture is or becomes nullptr when:
    • the view token is unknown (resource is null, line 2936);
    • packed_view returns refused (line 2963);
    • upload_texture fails (line 2984);
    • the recorded ViewDimension does not match the shader (line 3000).
  • Only if (indirect && !texture) (line 3008) refuses. A direct draw continues to CreateShaderResourceView(texture, ...) with a null resource (line 3028).
  • The helper then calls GetDimensions(0u, ...) on a null view, which does not return the descriptor's size. If it reports 0, (({0} - 1u) & 0x3fffu) gives 0x3fff, (({0} - 1u) & 3u) gives 3, and (({0} - 1u) >> 2) gives 0x3fffffff, which is wider than the 12-bit field.
  • A sample from a null view already reads zeros. A size field read is different: it returns a wrong number where the translator promised the descriptor's value.
  • Suggested: refuse the draw when tr->image_size_srvs.requires(i) && !texture, next to the MostDetailedMip case.

Test coverage

  • startup_gfx2hlsl_image_desc_word_controls is registered in CMakeLists.txt, but the pr test preset filter in CMakePresets.json does not include it. The d3d12_draw.inl change is compiled there and not tested.

Comment on efb89b92: the shifted-view refusal is in place but has no test, and a null binding of a marked SRV still reaches a direct draw.

@cursor
cursor Bot force-pushed the cursor/ps-desc-word-numeric branch from efb89b9 to 0364b66 Compare November 29, 2026 12:31
@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 0364b669 (merge-base = main 77d1ba4d). Verdict: hold for R0Y00's change request on 735924db. In my reading it is addressed: the PR takes R0Y00's first option and enforces the base-mip rule. Only R0Y00 can clear it.

Leyukaka's two items are fixed. The decision now lives in image_size_mip.h as image_size_bind(). It refuses a marked SRV with no texture (refuse_null) and one whose recorded view has MostDetailedMip != 0 (refuse_mip), and the call moved after every path that sets texture = nullptr, so a null texture is refused whatever desc holds. The paths that keep a texture and rewrite desc (the packed stand-in) change only the format. What I ran (Linux, g++ 14, Python 3.13):

  • g++ -std=c++17 -Isrc tests/startup_image_size_mip_check.cpp → rc 0, non-square 8 x 4 mip 0 allowed, MostDetailedMip 1 refused, null marked SRV refused, imagedim parser verified. --mutate drop-mip, drop-null and reject-lines each exit 1.
  • tests/startup_gfx2hlsl_image_desc_word_check.py → rc 0.
  • CI's Windows job ran them through the pr preset: Test #587: startup_image_size_mip ... Passed, Test #967: startup_gfx2hlsl_image_desc_word_controls ... Passed, 100% tests passed out of 86.

SHOULD

  1. The _control tests override the helper's result inside the test (bind() maps refuse_mip/refuse_null back to proceed). They show the test would notice a changed result, but they don't mutate src/. Nothing reaches the call site either: git grep -n image_size_bind 0364b669 -- tests finds only the unit test. Replacing tr->image_size_srvs.marks(i) in draw_translated with false would pass every test. R0Y00's suggested device control (one non-square texture through a draw at mip 0 and at MostDetailedMip=1) would pin the wiring.

This change only affects -Translate runs: pixel manifests aren't loaded with X2W_NATIVE_SHADERS_ONLY=1, the launcher default since #3449.

AI-assisted.

cursoragent and others added 4 commits November 29, 2026 12:59
A pixel stage can read the exact GFX10 width, height and 3D depth fields of an image descriptor as numbers. Other words and uses stay refused.

Fixes part of R0Y00#2022

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
A pixel size-field read uses the dimension of the descriptor load the
image instruction reads. Another load into the same SGPRs does not
borrow it. A copy of the sampled words still does.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
s_lshr_b32 of a size field lowers only when the descriptor word is the
value being shifted. A size-field SRV is marked imagedim, and the draw
path refuses that view when MostDetailedMip is not 0. Sampling a shifted
view that does not read a size field is unchanged.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
A marked SRV is refused when MostDetailedMip is not 0 and when the
direct draw would bind no texture. The imagedim parser and both
refusals are covered without a device. An unmarked sample is unchanged.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/ps-desc-word-numeric branch from 0364b66 to 1820f87 Compare November 29, 2026 13:00
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Windows test PC (MSVC, --preset dev, -j 1), at 1820f8763ce4488848e6701ab35edf17c72910bb. cmake --build --preset dev exit 0.

ctest --preset dev --no-tests=error -j 1 -R '^(startup_gfx2hlsl_image_desc_word_controls|startup_image_size_mip(_[a-z_]+)?)$' -E 'startup_audio_(output|pacing|provider)' --output-on-failure

5/5 passed, ctest exit 0.

  • startup_image_size_mip: non-square 8 x 4 mip 0 allowed, MostDetailedMip 1 refused, null marked SRV refused, imagedim parser verified.
  • startup_image_size_mip_drop_mip_control (WILL_FAIL): MostDetailedMip 1 of 8 x 4 was not refused.
  • startup_image_size_mip_drop_null_control (WILL_FAIL): marked SRV with no texture was not refused.
  • startup_image_size_mip_reject_lines_control (WILL_FAIL): imagedim 0 or 31 refused.
  • startup_gfx2hlsl_image_desc_word_controls: pixel image descriptor size fields: width, height and 3D depth lowered; other words refused.

The branch is rebased onto main af1cab5c. It is 5 commits behind current main c04e0dd6 and still merges cleanly. Not in this head: the _control tests still override the helper's result inside the test rather than mutating src/, and there is no device draw at mip 0 and at MostDetailedMip=1.

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 1820f876 integrated over main c04e0dd6 (tree c78a8fed). The merge is clean and git diff --cached --check is clean.

A correction first. On 2026-11-28 I wrote here that another reviewer would check the merged head 735924db. That was wrong: this account reviewed 735924db itself the same day, and I'm reviewing this head myself now. The branch has been rewritten since, so my merge commit 735924db is no longer in it. All four commits on this head are the author's.

Earlier findings at this head.

  • Dimension per register (my request on e264b8c7): still addressed. The early, kept and reloaded cases are in the check and pass. A mutant that lets image_word take any keyed load's dimension fails on early.
  • Swapped shift (JohnConnorNPC): addressed. s_lshr_b32 s10, 0x1e, s17 is refused. Narrowing the operand-order guard back to s_bfe_u32 fails the check.
  • Null marked SRV on a direct draw (Leyukaka): addressed in the code. image_size_bind() is called after every path that sets texture = nullptr, and it returns refuse_null before it looks at the descriptor.
  • Base mip (R0Y00's request on 735924db): enforced in the code, but not shown by a test. See the finding.

What I traced.

  • image_size_bind() reads desc.Texture2D.MostDetailedMip. That is the first union field of every texture view the manifest can mark (srv.kind 1 to 5), and a view of another dimension has already been turned into a null texture by then. Without a recorded 40-byte descriptor the view is created with a null descriptor, which starts at mip 0, so proceed is right there.
  • The manifest index is the position in tr->srvs (load_translation only appends srv i when i == tr.srvs.size()), so marks(i) tests the SRV the translator marked.
  • Translator probes with the check's own helpers: a size field written to m0 is refused; s_and_b32 s10, 0xfff, s18 (constant first) and s_lshr_b32 s10, s17, 30 (inline constant) lower to the same expressions as the fixture forms; s_lshr_b32 s10, s17, 62 is refused.

Finding: nothing reaches the new refusal in draw_translated.

  • Mutant. In src/startup_stubs/d3d12_draw.inl I replaced tr->image_size_srvs.marks(i) with false, made the imagedim manifest branch accept every line without reading it, and dropped the image_size_srvs.valid_for_srvs() check. That removes the whole feature from the runtime.
  • Result. I rebuilt offscreen_check, d3d12_xs_shim, startup_indirect_draw_indexed and startup_image_size_mip_check, then ran ctest --test-dir out/build/dev --no-tests=error -j 8 -R '(^startup_gfx2hlsl_|image|cube|^startup_indirect_|mip)' -E '(_hardware$|startup_audio)': 419 tests selected, 0 failed.
  • Why. imagedim appears only in the Python check (manifest text) and in tests/startup_image_size_mip_check.cpp (the header alone). No test loads a manifest with an imagedim line into the runtime, and no test draws through a marked SRV.
  • The unit test's wording. It prints non-square 8 x 4 mip 0 allowed, MostDetailedMip 1 refused. The 8 and 4 are two constants compared with themselves. No texture or view exists in that test, so it does not distinguish a mip-0 view from a shifted one in the way R0Y00's request describes. It also doesn't show that GetDimensions(0) on a mip-0 view gives the descriptor's fields: that still rests on the HLSL text.
  • Suggested direction (unconfirmed). tests/startup_indirect_draw_indexed.cpp already loads hand-written manifests (srv 0 tex2d table 0 0), records views with MostDetailedMip=1, and asserts refusal reasons from the census (sampled_texture_mismatch). A case there with imagedim 0 and a non-square texture would do it: the mip-0 view draws, the MostDetailedMip=1 view reports image_size_mip, and the same shifted view without the imagedim line still draws. A failing control is the call-site mutant above. A pixel fixture that returns the lowered width and height from the mip-0 draw would also show the equivalence.

What I ran.

  • Builds: full dev and release /O2.
  • Tests: ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '(^startup_gfx2hlsl_|image|cube|^startup_indirect_|^startup_tools_lint$)' -E '(_hardware$|startup_audio)' gives 414 tests in each preset: 403 pass, 0 fail and 11 are capability skips (native_image_*_warp). startup_image_size_mip, its three controls and startup_gfx2hlsl_image_desc_word_controls pass in both.
  • Hardware: ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^(startup_indirect_.*|startup_image_.*)_hardware$' with the debug layer on: 47 of 47 pass, no skips.
  • On main c04e0dd6 the two new tests are not registered. With image_field_expr stubbed to return None, the Python check fails at numeric use of s10 holding descnum.
  • Real-title run of this head against the baseline: pass.

Mutants. Each ran after an unmutated baseline that passes; files were restored afterwards and git diff --quiet is clean.

tools/startup/gfx2hlsl.py against tests/startup_gfx2hlsl_image_desc_word_check.py:

Mutant Result
image_field_expr returns None killed
operand-order guard covers s_bfe_u32 only, or is removed killed (both)
a size read does not mark the SRV killed
the manifest drops imagedim lines killed
every SRV is marked imagedim killed
the mark is index + 1 killed
depth template mask 0x1fff to 0xfff killed
helper calls GetDimensions(1u, ...) killed
image_word takes any keyed load's dimension killed (early)
depth allowed on tex2d killed (KeyError)
key drops the dword index survives
the 8-word same check becomes key is not None survives
the pre-scan's branch early return is removed survives
the pre-scan ignores offset: survives
the pre-scan keeps a symbol across other scalar writes survives
the not pair and dst[1] == dst[2] condition on the value path is dropped survives
the value path sets no SCC survives
image_word accepts a 4-dword load's span survives

src/startup_stubs/image_size_mip.h against startup_image_size_mip and its controls:

Mutant Result
refuse_mip dropped killed
refuse_null dropped killed
mip refused without a recorded descriptor killed
unmarked SRV checked too killed
leading zero accepted killed
duplicate accepted killed
mark past the SRV count accepted killed
kind check dropped, kind 5 rejected, kind 0 accepted killed (all three)
digits.size() > 2 becomes > 3 survives

src/startup_stubs/d3d12_draw.inl: the call-site mutant in the finding survives. I found no equivalent mutants.

Non-blocking.

  • The first five surviving translator mutants are the ones from my review of 4f75193e. The near-miss controls I listed there would still pin them: an x16 load sampled with two dim:, an operand with one word replaced, an s_add_u32 on a word before the sample, and a forward branch around the load.
  • A size field read with an scc consumer and a three-digit imagedim 031 line have no case.
  • indirect_refusal_code::image_size_null can't be reported: on an indirect draw, if (indirect && !texture) returns sampled_texture_unbindable first. Only image_size_mip is reachable there.
  • AGENTS.md asks for new notes in docs/experiments/<topic>.md and one tests/cmake/<family>.cmake per family; this PR adds to docs/experiments.md and CMakeLists.txt.

Verdict: changes requested on 1820f876. The refusal R0Y00 asked for is in the code and reads correctly, but the runtime wiring can be removed without failing a test. R0Y00's changes request on 735924db is still open as well.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; debug layer on for the hardware tests.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 1820f876.

This reply was 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.

8 participants