shader: size queries of writable images read their size, not 0 #247

Manually merged
github merged 1 commit from github-bot/gh-247 into main 2026-11-27 04:57:39 +00:00 AGit
Owner

@⁠marcus-4 on GitHub · 2026-11-27 04:34 UTC · original
marcus-4:fix/uav-size-query-level → main · +126 −6 · 3 files · 1 commits · merged 2026-11-27 04:56 UTC

What this changes

A program that asks a writable image (UAV) for its size gets 0x0 on the native host. image_get_resinfo on a UAV wrote the query's level as DXIL's undefined value, as DXC does for an RWTexture, and Metal through the Shader Converter answers that with 0. Sizes the host rebuilds into an image descriptor's own dwords (Lower::descriptor_data, when a program reads a width or height from the descriptor's bits instead of querying it) came from the same query and read 0 too.

Under Wine, D3DMetal's same answer gave the title's sun-shadow min/max program (07f451a14b13fecb) a 0x0 image, so whole 16x16 tiles were lit or shadowed together (halfwave50/VIctory-macOS-halfwave50@0f3ed38, opt-in per program there). This is the native-host side of it. It will only show once the lighting compute translates (#182).

  • image_get_resinfo takes the level in the program's first address for every image, as it already did for SRVs. Level 0 is the view's own size.
  • An image's descriptor fields come from level 0, writable or not. A buffer's record count keeps the undefined level, which a buffer ignores.
  • Guess (marked in the code and in docs/native-host.md): a level past a writable view's one reads 0 on the console, as it does here. Forcing level 0 in every program under Wine changed the TAA disocclusion mask and put speckles on skin, which suggests some programs ask about another level. Those keep reading 0, as before, so they cannot regress.

How it was tested

New GPU test heap_tests::a_size_query_of_a_writable_image_reads_its_size. A hand-assembled program queries a 16x8 texture UAV declared in a table (metadata kind 3) and reads its height from the descriptor's bits, on Metal. Writable-ness comes from that table record; an image_store alone on a heap-loaded descriptor does not make it a UAV, which a control run showed.

Translator width, height, descriptor height - 1
main [0, 0, 16383]
query fix only [16, 8, 16383]
this PR [16, 8, 7]

M1 Pro, 16 GB, macOS 27.2.1, Xcode 27.2, Metal Shader Converter 4.0.3, Homebrew llvm/lld 23.1.6 and mingw-w64 14.0.0, at 3b7bc7a:

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 378 passed, 1 failed, 4 ignored. All native probe tests pass. The one failure is victory-loader malformed_relocations_return_error_and_release_mapping, which fails only under parallel load (on main too) and passes alone.
  • Whole workspace on arm64 (victory-hle, victory, victory-gpu, xtask, victory-shader, victory-metal, victory-platform, victory-loader, victory-formats, victory-backend, victory-core): 929 passed, 1 failed, 13 ignored. The one failure is texture_tests::a_texture_rewritten_whole_is_read_whole_only_now_and_then, which likewise fails only under parallel load, on main too, and passes alone.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean.
  • cargo xtask policy: 369 files ok.
  • Ran the game: not yet (no game files on this Mac yet).

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠marcus-4** on GitHub · 2026-11-27 04:34 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/247) `marcus-4:fix/uav-size-query-level` → `main` · +126 −6 · 3 files · 1 commits · merged 2026-11-27 04:56 UTC ## What this changes A program that asks a writable image (UAV) for its size gets 0x0 on the native host. `image_get_resinfo` on a UAV wrote the query's level as DXIL's undefined value, as DXC does for an `RWTexture`, and Metal through the Shader Converter answers that with 0. Sizes the host rebuilds into an image descriptor's own dwords (`Lower::descriptor_data`, when a program reads a width or height from the descriptor's bits instead of querying it) came from the same query and read 0 too. Under Wine, D3DMetal's same answer gave the title's sun-shadow min/max program (`07f451a14b13fecb`) a 0x0 image, so whole 16x16 tiles were lit or shadowed together ([halfwave50/VIctory-macOS-halfwave50@0f3ed38](https://github.com/halfwave50/VIctory-macOS-halfwave50/commit/0f3ed38), opt-in per program there). This is the native-host side of it. It will only show once the lighting compute translates (#182). - `image_get_resinfo` takes the level in the program's first address for every image, as it already did for SRVs. Level 0 is the view's own size. - An image's descriptor fields come from level 0, writable or not. A buffer's record count keeps the undefined level, which a buffer ignores. - **Guess (marked in the code and in docs/native-host.md):** a level past a writable view's one reads 0 on the console, as it does here. Forcing level 0 in every program under Wine changed the TAA disocclusion mask and put speckles on skin, which suggests some programs ask about another level. Those keep reading 0, as before, so they cannot regress. ## How it was tested New GPU test `heap_tests::a_size_query_of_a_writable_image_reads_its_size`. A hand-assembled program queries a 16x8 texture UAV declared in a table (metadata kind 3) and reads its height from the descriptor's bits, on Metal. Writable-ness comes from that table record; an `image_store` alone on a heap-loaded descriptor does not make it a UAV, which a control run showed. | Translator | width, height, descriptor height - 1 | |---|---| | `main` | `[0, 0, 16383]` | | query fix only | `[16, 8, 16383]` | | this PR | `[16, 8, 7]` | M1 Pro, 16 GB, macOS 27.2.1, Xcode 27.2, Metal Shader Converter 4.0.3, Homebrew `llvm`/`lld` 23.1.6 and `mingw-w64` 14.0.0, at 3b7bc7a: - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: 378 passed, 1 failed, 4 ignored. All native probe tests pass. The one failure is `victory-loader` `malformed_relocations_return_error_and_release_mapping`, which fails only under parallel load (on `main` too) and passes alone. - [x] Whole workspace on arm64 (`victory-hle`, `victory`, `victory-gpu`, `xtask`, `victory-shader`, `victory-metal`, `victory-platform`, `victory-loader`, `victory-formats`, `victory-backend`, `victory-core`): 929 passed, 1 failed, 13 ignored. The one failure is `texture_tests::a_texture_rewritten_whole_is_read_whole_only_now_and_then`, which likewise fails only under parallel load, on `main` too, and passes alone. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. - [x] `cargo xtask policy`: 369 files ok. - [ ] Ran the game: not yet (no game files on this Mac yet). ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
A program asking a writable image (UAV) for its size got 0x0. The query's
level was written as DXIL's undefined value for a UAV, as DXC does, and
Metal through the Shader Converter answers that with 0. Sizes the host
rebuilds into an image descriptor's dwords (a width or height read from
the descriptor's bits) came from the same query and read 0 as well.

Under Wine, D3DMetal's same answer gave the title's sun-shadow min/max
program (07f451a14b13fecb) a 0x0 image: whole 16x16 tiles lit or
shadowed together (halfwave50/VIctory-macOS-halfwave50 0f3ed38, opt-in
per program there).

image_get_resinfo now takes the program's own level for every image, as
for shader resource views: level 0 is the view's size, and a level past
a writable view's one keeps reading 0 (guess, marked: forcing 0 in every
program under Wine changed other passes). An image's descriptor fields
come from level 0, writable or not.

Test (fails without the fix): a hand-assembled program queries a 16x8
texture UAV declared in a table and reads its height from the
descriptor's bits, on Metal. Upstream [0, 0, 16383], the query fix alone
[16, 8, 16383], both [16, 8, 7].

Checked on an M1 Pro, macOS 27.2.1, Xcode 27.2, MSC 4.0.3: 924 passed,
3 failed (native_probe x2, which need Homebrew's cross tools; and
victory-loader malformed_relocations_return_error_and_release_mapping,
which fails only under parallel load, on main too). clippy
(windows-gnullvm, -D warnings) and xtask policy pass. Not tested: a game
run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:38:08 +00:00
github manually merged commit 6689954624 into main 2026-11-27 04:57:39 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 04:56 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 04:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/247#pullrequestreview-6083662577) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.