Skip to content

D3D12.X: stand-in pixel shaders write both dual-source colours - #666

Draft
Ahmet-Dedeler wants to merge 1 commit into
xcl-dev:mainfrom
Ahmet-Dedeler:pr/standin-dual-source
Draft

Ahmet-Dedeler wants to merge 1 commit into
xcl-dev:mainfrom
Ahmet-Dedeler:pr/standin-dual-source

Conversation

@Ahmet-Dedeler

Copy link
Copy Markdown

The stand-in pixel shaders (what a pipeline gets while its console shaders have no translation yet, or when the driver refuses them) write SV_Target0 only, but the stand-in pipeline keeps the title's blend state. When that blend state uses SRC1 factors on render target 0 (dual-source blending), Apple's D3DMetal refuses the pair: it builds the pixel stage for the blend state, logs "Failed to compile fragment function" and marks the pipeline a no-op. This PR makes both stand-ins write SV_Target0 and SV_Target1. Part of #258.

This is the shared path: the stand-in shader changes on every host. Nothing is drawn with it either way (its vertex / mesh shader makes no pixels), and without dual-source blending a second output is ignored. It still needs a Windows regression pair, which I cannot make (see Not tested).

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: one source string, STANDIN_PS, for the DXBC stand-in of dummy (ps_5_0) and the DXIL stand-in of dummy_mesh (ps_6_0). It writes SV_Target0 = (1, 0, 1, 1) as before and SV_Target1 = 0.
  • Unit test standin_pixel_shaders_write_both_dual_source_colours: reads the output signature of both blobs and expects SV_Target 0 and 1. Skips the DXIL half with no DXC when DXC is missing.

Tested

  • MacBook Pro, Apple M5 Max, 64 GB, macOS 27.3. CrossOver 26.3 (Wine) with D3DMetal as the D3D12, Rosetta 2. The adapter reports itself as AMD Compatibility Mode (32-lane waves). Rust 1.100.0, target x86_64-pc-windows-gnu (mingw-w64 14.0.0), DXC 1.9.2609.5. Debug build for the tests, release for the title.

  • The new test on 4574f2e, under Wine: 1 passed. With STANDIN_PS set back to the one-colour shader it fails: the DXBC stand-in: left [0], right [0, 1].

  • cargo test --workspace -- --test-threads=4: not run yet on this host, neither on main nor on this branch. Only the new test was run. I'll add the counts for both, and the SKIPPED GPU tests on this adapter, before marking this ready.

  • D3DMetal itself, with a probe that creates one pipeline per call from the two shader sources and a blend state (no XCL, no game), 1 render target:

    pixel shader blend on target 0 graphics pipeline (DXBC) mesh pipeline (DXIL)
    SV_Target0 only (before) off made made
    SV_Target0 only (before) SRC_ALPHA / INV_SRC_ALPHA made made
    SV_Target0 only (before) ONE / INV_SRC1_COLOR "Failed to compile fragment function", no-op same
    SV_Target0 only (before) SRC1_ALPHA / INV_SRC1_ALPHA "Failed to compile fragment function", no-op same
    both targets (this PR) each of the four made made

    CreateGraphicsPipelineState / CreatePipelineState return S_OK in every row; the failure is only in D3DMetal's log.

  • The newer retail game from the README table, in earlier sessions of the Mac port of macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #258 on this machine (not this branch, and not runs made for this PR: main does not reach a frame on this host): one session without this change logged the message 2,815 times; a later run with it through the title's menus logged it 0 times.

Regression run

From this Mac, scripts/smoke.ps1 unchanged under PowerShell 7.7.0, with a wrapper as -Xcl that starts xcl.exe under Wine. Both runs start from the same copy of the shader caches. On this host main shows no frame (the title stops about 3 s in, before it creates its device), so neither run reaches a stand-in pipeline. This pair shows that the build starts and ends as main does, nothing more.

main:

xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: AMD Compatibility Mode
title: retail-title
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 4574f2e04c8f480436e4183121e8f251b264c992
gpu: AMD Compatibility Mode
title: retail-title
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

(peak commit is 0 because Wine reports no commit charge.)

Not tested

  • Windows. I have no Windows machine, so there is no Windows xcl-smoke pair and no run of the suite there. This change touches the shared path and needs one: could someone with a Windows PC post the pair for 4574f2e?
  • AMD, NVIDIA and Intel GPUs.
  • The MSVC build (CI covers the build).
  • A pipeline that draws with a stand-in on Windows: the stand-ins are meant to draw nothing, and I did not check a driver's view of the extra output.
  • More than one render target with dual-source blending: the probe's 4-target case was made, but D3D12 allows dual-source blending with one target only.

AI use

  • Claude Code with Claude Mythos 5.2: found the cause with the D3DMetal probe, wrote the change, the test and this description, and ran the builds, the tests and the smoke runs on the Mac named above.

A stand-in pipeline keeps the title's blend state, and a title's blend state can use SRC1
factors on render target 0 (dual-source blending). The stand-in pixel shaders wrote
SV_Target0 only. Apple's D3DMetal builds the pixel stage for the blend state and refuses
such a pair: "Failed to compile fragment function", logged 2,815 times in one session of a
retail game, and the pipeline is marked a no-op.

Both stand-ins (the DXBC one of `dummy`, the DXIL one of `dummy_mesh`) now write SV_Target0
and SV_Target1 from one source string. Nothing is drawn with them, and without dual-source
blending a second output is ignored.

Test: standin_pixel_shaders_write_both_dual_source_colours reads the output signature of
both blobs.

Part of xcl-dev#258.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@us3r40456

Copy link
Copy Markdown

Tested 4574f2e (this PR's head) on a second Apple Silicon Mac, compared test by test with its base main 508a0c7 (with #553 on top, so the 7 draw tests do not hang there). Same script for both runs.

Tested

  • MacBook Pro, Apple M5 Pro (20-core GPU), 24 GB, macOS 27.2.1, Rosetta 2. CrossOver 26.3.0.39832 with D3DMetal 3.0. DXC 1.9.2609 (XCL_DXC_DIR).
  • MSVC build, cross-built with cargo-xwin 0.24.1 (Rust 1.100.0, clang-cl / lld 23.1.6), debug. Builds for x86_64-pc-windows-msvc with no new warning.
  • lib unit tests, one module group at a time (--test-threads=4); a group that hangs or crashes is rerun one test per process. 603 passed (1 of them SKIPPED: no wave64), 26 failed, 8 hung, 3 crashed, 21 ignored. The only difference from main is the 7 draw tests hanging (Recompiler: keep a draw's descriptor heaps alive until the list has run #553 is not in this branch). The failures, hangs and crashes are the same tests as on main (FP64, the hle::d3d12x ones listed in macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #258).
  • standin_pixel_shaders_write_both_dual_source_colours passes, DXIL half included (DXC present).
  • Integration binaries (--test-threads=1): the same results as main.
  • Nothing that passes on main fails here.

Not tested

  • Windows, a retail title, a release build.

AI use

  • Claude Code, Claude Opus 5.5 ran the builds and tests on this machine and wrote this report.

@CryingLaughing

Copy link
Copy Markdown

Tested

  • Head 4574f2e04c8f480436e4183121e8f251b264c992 and its parent 508a0c74d7c0625d6d2de8d24494e69dc2e1926f with the same scratch-only native probe in real.rs. NVIDIA GeForce RTX 4080, driver 621.01, Intel Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC x64, Windows SDK DXC 1.8.2502.11, debug. XCL_ADAPTER=4080, XCL_REQUIRE_GPU=mesh, all XCL_SAMPLE_* variables unset.
  • Built each revision with cargo test -p xcl --lib --locked -j 4 --no-run --message-format=json. Ran native_standin_dual_source_pixels standin_pixel_shaders_write_both_dual_source_colours --test-threads=1 --nocapture on the PR head, 2/2 passed. Ran only native_standin_dual_source_pixels with the same test options on the parent, 1/1 passed. Neither run skipped.
  • The probe gave each production stand-in PS (DXBC and DXIL) a synthetic triangle VS and one RGBA32F target. With ONE / INV_SRC1_COLOR for color and SRC1_ALPHA / INV_SRC1_ALPHA for alpha, both shaders on the PR head matched all 256 expected pixels. A covered pixel was [1, 0.25, 1, 0.5] and the untouched clear pixel was [0, 0.25, 0, 0.5]. Disabling blending drew [1, 0, 1, 1] where covered, and an otherwise matching synthetic SV_Target1=1 control gave the same image as the blend-disabled draw.
  • Native PSO creation returned S_OK with the dual-source blend state for the complete stock DXBC graphic and DXIL mesh stand-ins on both revisions. The stock DXBC stand-in's degenerate VS left the target clear on the defined paths tested. On the parent, the triangle probe recorded only PSO creation for the one-output PS with dual-source blending. Its ordinary draw and the independent SRC1=1 control both passed.

Not tested

  • Native retail smoke, full workspace tests on this PR, a mesh dispatch, or D3DMetal. The DXIL readback used the exact production pixel shader with a synthetic vertex shader.

AI use

  • OpenAI Codex (GPT-6 family, exact variant unavailable) prepared the scratch probe, ran the checks, and drafted this report.

@JoaoPauluu

Copy link
Copy Markdown

Test report: #666 under Wine (Linux, NVIDIA): GTA VI regression pair on vkd3d-proton

The description asks for a regression pair it couldn't make. This one isn't Windows, but it's a host where the two-output stand-in goes through a different compiler (DXC → DXIL → vkd3d-proton's dxil-spirv → NVIDIA's Vulkan driver). It is this PR's head 4574f2e against its base main 508a0c7, on GTA VI. No regression either way.

Setup

build frames shown removals / crashes
508a0c7 934, 950 0 / 0
4574f2e 939, 939 0 / 0
  • Both builds log pipelines whose shaders are not compiled yet get a stand-in and are built in the background. Neither logs no stand-in pipeline (…) or stand-in mesh shaders: …, and Wine's stderr has no err: lines on any of the four runs.
  • The same 40 console shaders in the PSO without a translation: … – refused lines on both builds (mesh pipelines, unrelated to this PR).
  • XCL's log doesn't count the stand-ins it hands out, so I can't say how many pipelines used the new stand-in in these runs, only that none failed to build.
xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 934 (PresentX 934)
presents per 2 s (last 3): 54 28 24
device removals: 0
crashes: 0
peak commit: 0 MB
xcl-smoke v1
commit: 4574f2e04c8f480436e4183121e8f251b264c992
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 939 (PresentX 939)
presents per 2 s (last 3): 34 1 39
device removals: 0
crashes: 0
peak commit: 0 MB

(The first pair. peak commit: 0 MB is XCL reading 0 MB committed under Wine, see #257.)

Not tested

  • Windows (the pair the description asks for), D3DMetal, AMD; a pipeline with dual-source blending reaching the stand-in (I don't know whether GTA VI has one); the picture

AI use: Claude Code (Claude Opus 5.5) built both commits, ran every run above on the machine above and wrote this report. The blocks and log lines are pasted from those runs. The account owner asked for test reports to be posted while they were away and has not reviewed this one.

@Ahmet-Dedeler

Copy link
Copy Markdown
Author

Thanks for the three runs. That covers a second Mac (@us3r40456), the stand-in on a Windows NVIDIA card with the probe (@CryingLaughing) and a GTA VI pair under Wine on Linux (@JoaoPauluu), none with a regression.

What's still missing for the merge rules is the scripts/smoke.ps1 pair on Windows (main 508a0c7 and head 4574f2e, same title, same time), since this changes the shared stand-in shader. I can't make that one. @Kalmarv you offered Windows pairs for the Mac lane PRs in #258, could this one go on the list? I'll keep it a draft until that pair is here and won't push to the branch in the meantime, so the head stays 4574f2e.

@Ahmet-Dedeler

Copy link
Copy Markdown
Author

@Kalmarv one reminder and then I will leave it: this is still waiting on a Windows scripts/smoke.ps1 pair (main 508a0c7 against head 4574f2e). No rush, and if it is easier for you on a newer main, say so and I will rebase it and ask the earlier testers to rerun.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@Ahmet-Dedeler, here is the pair you asked for: main 508a0c7 (this PR's base) against this PR's head 4574f2e. Both runs pass: no device removal, no crash, 487 / 473 frames (103 %), peak commit 15101 / 14770 MB (102 %).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, release builds, no uncommitted changes.
  • scripts/smoke.ps1, the same retail title for 60 s each, main first, then this PR, one after the other.

main 508a0c7:

xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 473 (PresentX 473)
presents per 2 s (last 3): 13 13 13
device removals: 0
crashes: 0
peak commit: 14770 MB

this PR, 4574f2e:

xcl-smoke v1
commit: 4574f2e04c8f480436e4183121e8f251b264c992
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 487 (PresentX 487)
presents per 2 s (last 3): 14 15 13
device removals: 0
crashes: 0
peak commit: 15101 MB

Both sides run at about 13 presents per 2 s here, against about 1 250 frames per 60 s on today's main c160d86 on this machine, so 508a0c7 itself is slow on this title; the two sides match. A rebase onto c160d86 and a new pair there would show the PR on current main, if you'd rather have that.

Not tested

  • The dual-source path itself: these runs don't show whether the title binds a stand-in pixel shader with dual-source blending.
  • The test suite, AMD, Linux.

AI use: Claude Code (Claude Opus 5.5) ran the pair and wrote this comment.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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.

6 participants