Shaders: validate LOD queries across five texture shapes #235

Open
loyodea wants to merge 1 commit from upstream-pr/235 into a-publier
loyodea commented 2026-11-26 08:01:59 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by loyodea on 2026-11-26T08:01:59Z.


Related to the array-slice report in #218. The current default branch already omits array slice coordinates from LOD queries via 41d3184. This PR keeps the original synthetic regression.

The fixture validates both LOD outputs for 1D, 2D, and 3D textures and for 1D and 2D arrays. Both the existing array test and the five-shape test passed using the Microsoft DXIL validator on a-publier at 4eb6cfdf.

The code diff is unchanged from the previous revision. This PR now targets a-publier, where #328 and #330 fixed the WARP depth-bounds fixture and Clippy errors that failed CI on rx9070xt. The fixture uses generated shader instructions. Codex contributed the test and verification.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5506231326 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/235). Originally posted by [loyodea](https://github.com/loyodea) on 2026-11-26T08:01:59Z. --- Related to the array-slice report in #218. The current default branch already omits array slice coordinates from LOD queries via 41d3184. This PR keeps the original synthetic regression. The fixture validates both LOD outputs for 1D, 2D, and 3D textures and for 1D and 2D arrays. Both the existing array test and the five-shape test passed using the Microsoft DXIL validator on a-publier at 4eb6cfdf. The code diff is unchanged from the previous revision. This PR now targets a-publier, where #328 and #330 fixed the WARP depth-bounds fixture and Clippy errors that failed CI on rx9070xt. The fixture uses generated shader instructions. Codex contributed the test and verification.
gut0to commented 2026-11-26 16:19:32 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T16:19:32Z.

Review: COMMENTED


AI-assisted review. I inspected the LOD coordinate lowering and the added validator fixture statically; I did not run tests. This review suggests one additional texture-shape case.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6077442966 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/235#pullrequestreview-6077442966). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:19:32Z. **Review:** COMMENTED --- AI-assisted review. I inspected the LOD coordinate lowering and the added validator fixture statically; I did not run tests. This review suggests one additional texture-shape case.
gut0to commented 2026-11-26 16:19:32 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T16:19:32Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 11104

@@ -11099,6 +11099,9 @@ impl<'a> Lower<'a> {
                     return Err("an image result");
                 };
                 let f32t = self.s.t.f32;
+                // DXIL takes only the spatial coordinates. Leave the array slice undef.
+                let mut lod_coords = [fu; 3];
+                lod_coords[..spatial].copy_from_slice(&cs[..spatial]);

AI-assisted review; I did not run tests. Could the validator fixture include a cube-array query as well? The current matrix covers 1D/2D arrays and 3D textures, but a cube-array carries a fourth array-slice coordinate alongside its three spatial direction coordinates. That case would directly verify that the slice stays undefined while all three spatial coordinates are preserved.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4711018015 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/235#discussion_r4711018015). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:19:32Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 11104 ~~~~diff @@ -11099,6 +11099,9 @@ impl<'a> Lower<'a> { return Err("an image result"); }; let f32t = self.s.t.f32; + // DXIL takes only the spatial coordinates. Leave the array slice undef. + let mut lod_coords = [fu; 3]; + lod_coords[..spatial].copy_from_slice(&cs[..spatial]); ~~~~ --- AI-assisted review; I did not run tests. Could the validator fixture include a cube-array query as well? The current matrix covers 1D/2D arrays and 3D textures, but a cube-array carries a fourth array-slice coordinate alongside its three spatial direction coordinates. That case would directly verify that the slice stays undefined while all three spatial coordinates are preserved.
loyodea commented 2026-11-26 18:53:10 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by loyodea on 2026-11-26T18:53:10Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 11104

@@ -11099,6 +11099,9 @@ impl<'a> Lower<'a> {
                     return Err("an image result");
                 };
                 let f32t = self.s.t.f32;
+                // DXIL takes only the spatial coordinates. Leave the array slice undef.
+                let mut lod_coords = [fu; 3];
+                lod_coords[..spatial].copy_from_slice(&cs[..spatial]);

Thanks for checking the texture shapes. GFX10 uses one cube selector and packs the cube-array slice into the face operand. This branch currently rejects cube LOD queries. DXIL calculateLOD takes three direction coordinates for both cubes and cube arrays, so a cube-array fixture here would first need cube LOD lowering. The current fixture covers the five supported shapes. AMD RDNA 2 ISA, table 43 · DXIL CalculateLOD

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4712404929 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/235#discussion_r4712404929). Originally posted by [loyodea](https://github.com/loyodea) on 2026-11-26T18:53:10Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 11104 ~~~~diff @@ -11099,6 +11099,9 @@ impl<'a> Lower<'a> { return Err("an image result"); }; let f32t = self.s.t.f32; + // DXIL takes only the spatial coordinates. Leave the array slice undef. + let mut lod_coords = [fu; 3]; + lod_coords[..spatial].copy_from_slice(&cs[..spatial]); ~~~~ --- Thanks for checking the texture shapes. GFX10 uses one cube selector and packs the cube-array slice into the face operand. This branch currently rejects cube LOD queries. DXIL `calculateLOD` takes three direction coordinates for both cubes and cube arrays, so a cube-array fixture here would first need cube LOD lowering. The current fixture covers the five supported shapes. [AMD RDNA 2 ISA, table 43](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf#page=71) · [DXIL CalculateLOD](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#calculatelod)
adrianmjim commented 2026-11-26 22:42:43 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T22:42:43Z.


Checked by reading the code on rx9070xt cd8dfc0 (head 1e500d2); I did not build or run this PR.

  • cd8dfc0 already has the same fix in 41d3184 ("Shaders: a level query takes no array slice"). For op 81 only the spatial coordinates are read (crates/victory-shader/src/emit/lower.rs:11776-11782). cs starts undef (lower.rs:11763) and the call passes cs[0..3] (lower.rs:11815). The lod_coords copy here would be a no-op on that base.
  • The 1D array case is covered by the same code: dim 4 gives 2 coords with 1 spatial (lower.rs:11422, lower.rs:11750).
  • cd8dfc0 only tests the 2D array: a_level_query_of_an_array_takes_no_slice (emit/mod.rs:1209). Your five-shape fixture adds coverage for 1D, 2D, 3D and 1D array. It could stay as a test-only change rebased on cd8dfc0. texture_tables, Parts and S_ENDPGM are all there.
  • The branch still carries the old 81ebb7b. Merging it into cd8dfc0 conflicts in crates/victory-gpu/src/ambient.rs, host.rs and pipeline/make.rs. Commit 1e500d2 on its own applies to cd8dfc0's lower.rs without conflict.
  • a-publier has since moved to 4eb6cfd. None of those commits touch lower.rs or emit/mod.rs, so the above holds there too.
  • Separately, I ran a whole-archive translate --validate of cd8dfc0: 0 "out of bound coord" validator errors, and 14247 of 14247 vertex and pixel programs validated. That includes the three pixel programs named in 41d3184.

Not checked: building or running the fixture on cd8dfc0.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7204919411 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/235#issuecomment-7204919411). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T22:42:43Z. --- Checked by reading the code on rx9070xt cd8dfc0 (head 1e500d2); I did not build or run this PR. - cd8dfc0 already has the same fix in 41d3184 ("Shaders: a level query takes no array slice"). For op 81 only the spatial coordinates are read (`crates/victory-shader/src/emit/lower.rs:11776-11782`). `cs` starts undef (`lower.rs:11763`) and the call passes `cs[0..3]` (`lower.rs:11815`). The `lod_coords` copy here would be a no-op on that base. - The 1D array case is covered by the same code: dim 4 gives 2 coords with 1 spatial (`lower.rs:11422`, `lower.rs:11750`). - cd8dfc0 only tests the 2D array: `a_level_query_of_an_array_takes_no_slice` (`emit/mod.rs:1209`). Your five-shape fixture adds coverage for 1D, 2D, 3D and 1D array. It could stay as a test-only change rebased on cd8dfc0. `texture_tables`, `Parts` and `S_ENDPGM` are all there. - The branch still carries the old 81ebb7b. Merging it into cd8dfc0 conflicts in `crates/victory-gpu/src/ambient.rs`, `host.rs` and `pipeline/make.rs`. Commit 1e500d2 on its own applies to cd8dfc0's `lower.rs` without conflict. - a-publier has since moved to 4eb6cfd. None of those commits touch `lower.rs` or `emit/mod.rs`, so the above holds there too. - Separately, I ran a whole-archive `translate --validate` of cd8dfc0: 0 "out of bound coord" validator errors, and 14247 of 14247 vertex and pixel programs validated. That includes the three pixel programs named in 41d3184. Not checked: building or running the fixture on cd8dfc0.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/235:upstream-pr/235'
git switch 'upstream-pr/235'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'a-publier'
git merge --no-ff 'upstream-pr/235'
git switch 'upstream-pr/235'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/235'
git switch 'upstream-pr/235'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'upstream-pr/235'
git switch 'a-publier'
git merge --squash 'upstream-pr/235'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/235'
git switch 'a-publier'
git merge 'upstream-pr/235'
git push origin 'a-publier'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Belobug/VIctory-Belobug-AMD!235
No description provided.