gpu: translate 2D array images in the startup shader translator #1374

Merged
JohnConnorNPC merged 2 commits from upstream-pr/1381 into main 2026-11-24 10:14:48 +00:00
JohnConnorNPC commented 2026-11-24 10:00:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T10:00:50Z.


Change

tools/startup/gfx2hlsl.py refused every image instruction with dim:SQ_RSRC_IMG_2D_ARRAY (image dimension SQ_RSRC_IMG_2D_ARRAY). A pipeline whose pixel stage reads an array texture was therefore never translated, and the draw path skipped all of its draws.

image_sample, image_sample_lz, image_sample_l and image_load on a 2D array now translate:

  • the resource is declared Texture2DArray<float4> and listed in the manifest as tex2da, the kind the draw path already binds as D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
  • the slice is the third address component, where a volume has z: float3(u, v, slice) for a sample, int4(x, y, slice, 0) for a load. image_sample_l takes the level from the last address register, as it does for 2D and 3D.

The change in the translator is three lines: the accepted dimensions, the manifest kind, and the declared type. Cube, multisampled and 1D images are still refused.

Tests

New tests/startup_image_2d_array_check.py, modelled on startup_image_3d_check.py:

  • Translation controls (pure Python, added to the platform-independent list): the declared type, the exact Sample, SampleLevel and Load calls, the manifest lines, no sampler for the load stage. The same words with only the dim field changed still give Texture3D / tex3d, and SQ_RSRC_IMG_2D_MSAA is still refused.
  • Fixture words against llvm-mc (binary mode, added to the Ubuntu job).
  • Draw (startup_image_2d_array_warp / _hardware): tests/startup_image_3d.cpp gains an array mode (offscreen_check --startup-image-2d-array) that binds a 2x2 texture with two slices holding the same eight texels as the 3D fixture. A sample stage and a load stage each read back the texel of the slice the root constant selects (slices 0 and 1; for the sample also 0.25 and 0.75, which round to 0 and 1). Negative controls on the translated HLSL: the slice fixed to 0, and two coordinates exchanged, must each read a different, named texel.

tests/startup_image_sample_l_check.py listed the array form among the refused ones. That case now asserts the lowering instead: u, v, slice from v0, v1, v2 and the level from v3, on a Texture2DArray. No other expectation there changes.

Results

At 34f03603:

$ python -B tests/startup_image_2d_array_check.py
image_sample: Texture2DArray r0, r0.Sample(q0, float3(F(v0), F(v1), F(v2))) with v2 = ud1 (root constant 1); manifest srv 0 tex2da
image_sample_lz: SampleLevel(q0, float3(F(v0), F(v1), F(v2)), 0)
image_load: r0.Load(int4(v0, v1, v2, 0)); manifest srv 0 tex2da, no sampler
dim 3D (same words, dim field changed): still Texture3D, manifest srv 0 tex3d
dim 2D MSAA: refused

$ python -B tests/startup_image_2d_array_check.py binary llvm-mc-19
fixture words match llvm-mc

startup_image_sample_l_check.py (also binary), startup_image_3d_check.py, startup_translator_check.py, startup_sampler_heap_check.py, docs_links_check.py and bidi_controls_check.py pass.

Draw, clang-cl build under Wine 11.0 with vkd3d-proton on an RTX 4070 Ti SUPER (translation layer, hardware only), FXC ps_5_1:

fxc sample slice=0: 3e800000,3f800000,00000000,00000000
fxc sample slice=1: 3f400000,3f800000,00000000,3f800000
fxc sample slice=0.25: 3e800000,3f800000,00000000,00000000
fxc sample slice=0.75: 3f400000,3f800000,00000000,3f800000
fxc sample slice fixed to 0: fails as expected, reads 3e800000,3f800000,00000000,00000000
fxc sample x and y exchanged: fails as expected, reads 3f600000,00000000,3f800000,3f800000
fxc load slice=0: 3e800000,3f800000,00000000,00000000
fxc load slice=1: 3f400000,3f800000,00000000,3f800000
fxc load slice fixed to 0: fails as expected, reads 3e800000,3f800000,00000000,00000000
fxc load x and slice exchanged: fails as expected, reads 3f200000,00000000,00000000,3f800000

The existing 3D draw (startup_image_3d_check.py draw) still passes on the same build through the shared renderer.

Measured on one console executable under the startup debugger, same host: before, one of 14 pipelines stayed untranslated with the message above and 13,460 draws were skipped in a 220 s run; with this change all 14 translate and no draw is skipped in a 200 s run (133,254 translated draws). The stage in question reads the array with image_load. Null bindings rose from 2,813 to 12,642 between those two runs, which were not identical in length or input; I have not looked into which bindings those are.

Not verified

  • Windows, WARP and the DXC ps_6_0 compile of the draw. I have no way to run DXC from the Wine-side test here, so the draw above used FXC only; CI is the first run of the rest.
  • image_load_mip on an array, and array textures with more than one mip.
  • The draw path with a real array view: the fixture draws through offscreen_check, not through the device wrapper, so it shows the translated HLSL, not the binding of a title-created view to the tex2da slot.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579258163 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1381). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-24T10:00:50Z. --- ## Change `tools/startup/gfx2hlsl.py` refused every image instruction with `dim:SQ_RSRC_IMG_2D_ARRAY` (`image dimension SQ_RSRC_IMG_2D_ARRAY`). A pipeline whose pixel stage reads an array texture was therefore never translated, and the draw path skipped all of its draws. `image_sample`, `image_sample_lz`, `image_sample_l` and `image_load` on a 2D array now translate: - the resource is declared `Texture2DArray<float4>` and listed in the manifest as `tex2da`, the kind the draw path already binds as `D3D12_SRV_DIMENSION_TEXTURE2DARRAY`; - the slice is the third address component, where a volume has z: `float3(u, v, slice)` for a sample, `int4(x, y, slice, 0)` for a load. `image_sample_l` takes the level from the last address register, as it does for 2D and 3D. The change in the translator is three lines: the accepted dimensions, the manifest kind, and the declared type. Cube, multisampled and 1D images are still refused. ## Tests New `tests/startup_image_2d_array_check.py`, modelled on `startup_image_3d_check.py`: - **Translation controls** (pure Python, added to the platform-independent list): the declared type, the exact `Sample`, `SampleLevel` and `Load` calls, the manifest lines, no sampler for the load stage. The same words with only the dim field changed still give `Texture3D` / `tex3d`, and `SQ_RSRC_IMG_2D_MSAA` is still refused. - **Fixture words** against `llvm-mc` (`binary` mode, added to the Ubuntu job). - **Draw** (`startup_image_2d_array_warp` / `_hardware`): `tests/startup_image_3d.cpp` gains an array mode (`offscreen_check --startup-image-2d-array`) that binds a 2x2 texture with two slices holding the same eight texels as the 3D fixture. A sample stage and a load stage each read back the texel of the slice the root constant selects (slices 0 and 1; for the sample also 0.25 and 0.75, which round to 0 and 1). Negative controls on the translated HLSL: the slice fixed to 0, and two coordinates exchanged, must each read a different, named texel. `tests/startup_image_sample_l_check.py` listed the array form among the refused ones. That case now asserts the lowering instead: `u, v, slice` from `v0, v1, v2` and the level from `v3`, on a `Texture2DArray`. No other expectation there changes. ## Results At `34f03603`: ```text $ python -B tests/startup_image_2d_array_check.py image_sample: Texture2DArray r0, r0.Sample(q0, float3(F(v0), F(v1), F(v2))) with v2 = ud1 (root constant 1); manifest srv 0 tex2da image_sample_lz: SampleLevel(q0, float3(F(v0), F(v1), F(v2)), 0) image_load: r0.Load(int4(v0, v1, v2, 0)); manifest srv 0 tex2da, no sampler dim 3D (same words, dim field changed): still Texture3D, manifest srv 0 tex3d dim 2D MSAA: refused $ python -B tests/startup_image_2d_array_check.py binary llvm-mc-19 fixture words match llvm-mc ``` `startup_image_sample_l_check.py` (also `binary`), `startup_image_3d_check.py`, `startup_translator_check.py`, `startup_sampler_heap_check.py`, `docs_links_check.py` and `bidi_controls_check.py` pass. Draw, clang-cl build under Wine 11.0 with vkd3d-proton on an RTX 4070 Ti SUPER (translation layer, `hardware` only), FXC `ps_5_1`: ```text fxc sample slice=0: 3e800000,3f800000,00000000,00000000 fxc sample slice=1: 3f400000,3f800000,00000000,3f800000 fxc sample slice=0.25: 3e800000,3f800000,00000000,00000000 fxc sample slice=0.75: 3f400000,3f800000,00000000,3f800000 fxc sample slice fixed to 0: fails as expected, reads 3e800000,3f800000,00000000,00000000 fxc sample x and y exchanged: fails as expected, reads 3f600000,00000000,3f800000,3f800000 fxc load slice=0: 3e800000,3f800000,00000000,00000000 fxc load slice=1: 3f400000,3f800000,00000000,3f800000 fxc load slice fixed to 0: fails as expected, reads 3e800000,3f800000,00000000,00000000 fxc load x and slice exchanged: fails as expected, reads 3f200000,00000000,00000000,3f800000 ``` The existing 3D draw (`startup_image_3d_check.py draw`) still passes on the same build through the shared renderer. Measured on one console executable under the startup debugger, same host: before, one of 14 pipelines stayed untranslated with the message above and 13,460 draws were skipped in a 220 s run; with this change all 14 translate and no draw is skipped in a 200 s run (133,254 translated draws). The stage in question reads the array with `image_load`. Null bindings rose from 2,813 to 12,642 between those two runs, which were not identical in length or input; I have not looked into which bindings those are. ## Not verified - Windows, WARP and the DXC `ps_6_0` compile of the draw. I have no way to run DXC from the Wine-side test here, so the draw above used FXC only; CI is the first run of the rest. - `image_load_mip` on an array, and array textures with more than one mip. - The draw path with a real array view: the fixture draws through `offscreen_check`, not through the device wrapper, so it shows the translated HLSL, not the binding of a title-created view to the `tex2da` slot.
upstream-sync closed this pull request 2026-11-24 11:02:42 +00:00
R0Y00 commented 2026-11-24 11:02:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:10:53Z.

Review: APPROVED


Approved the 2D array lowering on this tested head: the third coordinate selects the array layer and tex2da is recognized by the draw binding reader. Preserve all tests when resolving the current conflicts. Runtime texture binding remains outside the fixture evidence.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037300558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1381#pullrequestreview-6037300558). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T10:10:53Z. **Review:** APPROVED --- Approved the 2D array lowering on this tested head: the third coordinate selects the array layer and tex2da is recognized by the draw binding reader. Preserve all tests when resolving the current conflicts. Runtime texture binding remains outside the fixture evidence.
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
R0Y00/Xbox2Windows!1374
No description provided.