Skip to content

Shaders: gradient samples on cube images - #138

Closed
LaunchDoesntCode wants to merge 4 commits into
Marvisak:mainfrom
LaunchDoesntCode:shader/cube-gradient-samples
Closed

LaunchDoesntCode wants to merge 4 commits into
Marvisak:mainfrom
LaunchDoesntCode:shader/cube-gradient-samples

Conversation

@LaunchDoesntCode

Copy link
Copy Markdown
Contributor

Depends on: #73. This branch is built on #73's head, so until that merges the diff shows its commit too. Only the last commit, 492e948, is new here.

What

image_sample_d and image_sample_d_cl on cube images were refused ("a cube sample with texel coordinates, gradients or a level query"). They now translate. Texel coordinates and level queries on cubes are still refused.

How

  • A cube's explicit gradients are those of its two face coordinates, so there are two per direction, not three. The gradient count (and with it where the coordinates and the clamp start) now uses that for cubes.
  • cube_direction is linear in the face coordinates, so the new cube_gradient returns its derivative for the host's sampleGrad: twice each face gradient, signed per face, zero along the face's own axis. Both share a small cube_face helper for the per-face select.

Measured

victory translate over the Xbox 1.0.2.1 shader containers (26,503 containers, 26,084 programs), #73's head against this branch:

#73 this branch
Vertex and pixel programs emitted (of 14,001) 12,316 12,341
"a cube sample with texel coordinates, gradients or a level query" 27 0

No other category got worse; "a cross-lane operation outside compute" goes 48 → 50 because two programs now get further. The corpus has 52 image_sample_d and 248 image_sample_d_cl on cubes, none with a16.

Tested

  • Cross-built for x86_64-pc-windows-msvc on Linux and run under Proton 10 (vkd3d-proton), RTX 5090.
  • cargo test -p victory-shader: all pass except stub_pipeline_is_created, which also fails on unmodified main under Proton (vkd3d-proton accepts the zero digest).
  • Current main + Shaders: support image_sample_b with a16 and _cl LOD-clamp variants #73 + this commit merges cleanly, builds, and passes the same tests.
  • A host pipeline was created from 14 of the newly emitted programs, one at a time, under vkd3d-proton.

Not tested: a Windows run, please

I have no Windows build of this yet, so two things are unchecked:

  1. victory translate --validate with dxil.dll on the newly emitted programs.
  2. The picture. The gradient conversion is derived from cube_direction, not confirmed against the console's output. If someone on Windows can look at a cube-lit surface or reflection in the title with this branch, that would settle it. A wrong sign or scale would show as the wrong mip level (too blurry or too sharp) rather than a crash.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Yaekai and others added 2 commits November 24, 2026 01:14
In GFX10/RDNA2 MIMG instructions with a16=1, offset (_o), bias (_b) and z-compare (_c) remain full 32-bit VGPRs at the start of vaddr, while gradients, coordinates, LOD and clamp are packed in 16-bit pairs starting after them (matching gfx10::fields::image_addr_dwords).

- Split address reading into full 32-bit prefix VGPRs and a16-packed trailing components, removing the a16+image_sample_b bailout.
- Support _cl LOD-clamp variants (image_sample_cl, image_sample_b_cl, image_sample_d_cl, image_sample_c_cl) by passing the trailing clamp component to DXIL's clamp parameter.
- Check unsupported cube sample modes before reading coordinates so cube gradient samples report the right error instead of an out-of-bounds address.
A cube image's explicit gradients are those of its two face coordinates,
so image_sample_d and image_sample_d_cl carry two per direction there,
not three. cube_direction is linear in the face coordinates, so the
gradients of the direction the host wants are twice each, signed per
face, and zero along the face's own axis.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DaviTostes

Copy link
Copy Markdown

Tested 492e948 on Arch Linux x86_64, rustc 1.98.1: cargo test -p victory-shader: 51 passed, 0 failed (2 test binaries). The full workspace still needs #112 for the victory-gpu E0425.

The diff adds no test for the cube gradient samples, so this only shows the existing shader suite stays green; a synthetic image_sample_d/gradient case on a cube would cover the new path.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

A hand-built pixel program (two table descriptors, one MIMG, an export)
goes through every stage to DXIL for image_sample_d and
image_sample_d_cl on a 2D image and on a cube. Without the cube support
it stops at the cube case with the old refusal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Confirmed the Windows validation and pipeline creation for three pixel shaders seen during first-story rendering on Windows 10 22H2, RTX 3060 Ti, driver 610.88, Agility SDK 620. On our downstream build with #73, all three reached the unsupported cube-gradient case. Adding only 492e948 let all three pass Microsoft dxil.dll (Windows SDK 10.0.26100.0) and create D3D12 pipelines with the translate command's generated vertex shader.

The shader hashes were 2deec721a63fe8a5, 7bdefdfde461f6e3, and ee41ebc3eb3fbbdc. This check covers shader translation and host PSO creation. Visual correctness and frame time were outside the test. AI-assisted with Codex.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@LaunchDoesntCode

Copy link
Copy Markdown
Contributor Author

Thanks for the run. Added the synthetic case in ff95daf: gradient_samples_lower_on_planes_and_cubes hand-builds a pixel program (two table descriptors, one MIMG, an export) and takes it through every stage to DXIL for image_sample_d and image_sample_d_cl, each on a 2D image and on a cube.

  • Against Shaders: support image_sample_b with a16 and _cl LOD-clamp variants #73's head without the cube commit it fails at the cube case with the old refusal ("a cube sample with texel coordinates, gradients or a level query"); with it, all four pass.
  • 800227d merges current main (the lowering tests gained a second helper there; both are kept).
  • cargo test -p victory-shader under Proton 10: 69 passed; the one failure is stub_pipeline_is_created, which fails the same way on main there.

What the test does not show is that the gradients are right, only that the path lowers. The request for a look at a cube-lit surface on Windows still stands.

No game data used. AI-assisted (Claude Code).

AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
…cl LOD-clamp variants; gradient samples on cube images) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review note on the a16 layout in this PR ("With a16, sampling coordinates, gradients, LOD and clamp are f16"). On GFX10.3 a16 does not make the derivatives 16-bit; only the _g16 opcodes do. LLVM's MC test gfx10_asm_mimg.s has

image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16    ; 5 address dwords

which is four 32-bit derivatives and one dword of packed coordinates. With the derivatives read as packed halves, the coordinates come from the wrong dword. Also, with a16 the bias is an f16 in the low half of its dword (SITargetLowering::lowerImage: "Bias is of type half but occupies full 32-bit"), not an f32.

The decoder on main counts a16 derivatives as packed too (gfx10/fields.rs), so this is easy to inherit; I did in #160 and fixed it there (7265593).

From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

I ran a Windows pixel readback on exact head 800227d, with an original six-face cube and four mip levels. On both RTX 5090 and WARP, all 32 lanes for image_sample_d and all 32 for image_sample_d_cl matched native HLSL TextureCube.SampleGrad. The native outputs also matched an independent expected face/mip selection for every lane.

The probe covers ordinary-precision face-center samples, both in-face gradient axes, and several minimum-LOD values. It validates face and mip selection in this fixture.

@Marvisak Marvisak closed this Nov 24, 2026
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
…IL validator failures) into the integration

Its fixes are already here (a16 biased samples from Marvisak#138/Marvisak#160, the centroid position under conservative depth, one interpolation mode per packed row, signature parts in the validator's order), and compute samples take quad gradients (Marvisak#180) instead of validator 1.8. The code stays ours; three of the PR's tests are taken (conservative depth, signature order within a row, the a16 biased sample) and pass. Its tests of harmonize_row_interp and of dx.valver 1.8 test code that is not taken.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
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.

7 participants