Skip to content

D3D12.X: strip console-only fence flags on CreateFence - #3386

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/fence-flags-sanitize
Dec 1, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/fence-flags-sanitize

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What is in it

  • Sanitize D3D12_FENCE_FLAGS in dev_create_fence (crates/xcl/src/hle/d3d12x/real.rs) via pc_fence_flags(flags) before calling PC CreateFence:
    • Strip console-only flag bits outside the valid PC mask 0x7 (D3D12_FENCE_FLAG_SHARED | D3D12_FENCE_FLAG_SHARED_CROSS_ADAPTER | D3D12_FENCE_FLAG_NON_MONITORED) and any upper-32-bit caller garbage, preventing PC CreateFence from rejecting console fence flags with E_INVALIDARG (0x80070057).
    • Log once when console-only fence flag bits are dropped.
  • Add unit and WARP integration tests in hle::d3d12x::real::fence_flags_tests (pc_fence_flags_strips_console_and_upper_bits and dev_create_fence_sanitizes_console_flags).

Tested

  • Verified dev_create_fence_sanitizes_console_flags fails before the fix on WARP with 0x80070057 (E_INVALIDARG) when passed console flag bit 0x10000.
  • Targeted tests after the fix (cargo test -p xcl --lib -j 4 -- hle::d3d12x::real::fence_flags_tests:: --nocapture): 2 passed, 0 failed, 0 ignored.
  • Full workspace suite (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: with XCL_DXC_DIR set to DXC 1.9 on RTX 5070 Ti): 41 test binaries, 2611 passed, 0 failed, 49 ignored, 9 filtered out.
  • SKIPPED breakdown (26 total): 21 no wave64 (RTX 5070 Ti is wave32), 3 refused (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32 #1426 semantics), 2 no heap windows (XCL_HEAP_WINDOWS=1 opt-in).

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 2e09e72ff5b8f91736fdfaa46a5b1242e6edecbe
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 54 11 0
device removals: 0
crashes: 0
peak commit: 33220 MB

Not tested

  • D3D12_FENCE_FLAG_NON_MONITORED was only checked in the pure bitmask unit test because the WARP software adapter does not support non-monitored fences.
  • Retail titles that pass console-only fence flags on CreateFence were not run directly; those paths are covered by the synthetic unit and WARP tests.
  • test_title_runs_and_game_folder_is_untouched, uma_driver::tests::, wave64 GPU tests, and XCL_HEAP_WINDOWS=1 opt-in unit tests were not run in the workspace suite.

AI use

  • Authored, verified, and tested with an AI coding agent; all changes and test results were verified directly against the local repository, compiler, test suite, and 150 s smoke run.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

Reviewed and tested at 2e09e72f.

Looks clean and minimal — pc_fence_flags masks to the valid PC D3D12_FENCE_FLAGS bits and drops upper-32-bit garbage, logs once on console-only bits, and the isolated WARP child test covers all cases.

Tested locally

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0.
  • cargo test -p xcl --lib hle::d3d12x::real::fence_flags_tests:: -- --test-threads=1: 2 passed, 0 failed.

AI use

  • Antigravity (Gemini 4 Neon) assisted with code review and drafting; all builds and tests were executed locally on the hardware above.

@ClosetPie107

Copy link
Copy Markdown

Test report for #3386 at 2e09e72ff5b8f91736fdfaa46a5b1242e6edecbe, against its merge-base with main, d8bd9a38, under Wine on AMD.

Tested

Not tested

  • native Windows
  • NVIDIA
  • the gpu:: tests in the suite runs
  • the workspace's other crates and integration tests (only -p xcl --lib)
  • a game run (no regression block)

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 2e09e72
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (real.rs, +85/-2). Every CreateFence now has its flags masked to the PC's valid ones (SHARED, SHARED_CROSS_ADAPTER, NON_MONITORED); XCL's own NONE calls are unchanged. Findings: (1) the description doesn't say which console fence bits these are, what they mean on the console, or which title sends them, and Not tested says no such title was run, so the need isn't shown. (2) The log fires once per process (~4807-4811), so later, different console bits are dropped silently; logging each new combination once would keep that visible. (3) dev_create_fence_sanitizes_console_flags runs in a child process whose output is dropped on success, so a skip_test there shows as a plain pass (same pattern as console_heap.rs). (4) AI use names no tool or model; no what-and-why paragraph or issue link. Fine: dropping the upper 32 bits is right for a 32-bit enum, fence tracking and the extra reference are unchanged, the child process keeps adopt's vtable patch out of other tests, and the bitmask unit test checks the mask.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (7fd32a77): 1516 -> 1667 frames shown (109 %; last presents per 2 s: 60 61 60), peak commit 18133 -> 17027 MB, 0 device removals, 0 crashes. git diff --check flags a new blank line at the end of real.rs.
verdict: safe to merge (say which title sends the console fence bits, and log each new combination rather than once per process)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Source review of head 2e09e72f: pc_fence_flags keeps only bits 0x1|0x2|0x4. Microsoft's current D3D12 header also defines D3D12_FENCE_FLAG_ALLOW_COMMAND_LIST_BARRIERS (0x8) and D3D12_FENCE_FLAG_ALLOW_QUEUE_AND_CPU_SYNC (0x10). Agility SDK 1.620 retail includes Fence Barriers Tier 1. The PR's test treats 0x8 as console-only.

On a runtime and device supporting fence barriers, CreateFence(value, 0x18) therefore reaches native D3D12 as CreateFence(value, 0). That changes the fence contract: Microsoft specifies these flags for command-list barriers and queue/CPU synchronization. This is a source-level compatibility concern; I have not measured a title or GPU failure from it.

Please preserve the two defined PC bits while stripping confirmed console-only bits and upper-32-bit garbage. Let native D3D12 validate feature support and flag combinations rather than silently changing valid requested flags. Replace the 0x8-is-console-only test and add a regression such as pc_fence_flags(0x10018) == 0x18. On a fence-barrier-capable adapter, check that ID3D12Fence1::GetCreationFlags retains the requested bits; keep a separate test for the confirmed console-only bit.

Minimal mask and unit-test candidate
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
@@
 const PC_FENCE_FLAGS_MASK: u32 = (D3D12_FENCE_FLAG_SHARED.0
     | D3D12_FENCE_FLAG_SHARED_CROSS_ADAPTER.0
-    | D3D12_FENCE_FLAG_NON_MONITORED.0) as u32;
+    | D3D12_FENCE_FLAG_NON_MONITORED.0
+    | 0x8  // D3D12_FENCE_FLAG_ALLOW_COMMAND_LIST_BARRIERS
+    | 0x10) as u32; // D3D12_FENCE_FLAG_ALLOW_QUEUE_AND_CPU_SYNC
@@
-        assert_eq!(pc_fence_flags(0x8 | non_mon), non_mon);
+        assert_eq!(pc_fence_flags(0x8 | non_mon), 0x8 | non_mon);
+        assert_eq!(pc_fence_flags(0x10018), 0x18);

The candidate above illustrates the mask change; use the SDK's named constants if available in the binding. This review did not run builds, tests, or a title. AI use: OpenAI Codex (GPT-6.2 Sol) traced the PR and current D3D12 definitions; OpenAI Codex (GPT-6.2 Astra) independently checked the fence-barrier contract.

@throny

throny commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: 2e09e72
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; failing: none (25 SKIPPED lines, all GPU tests on this adapter, e.g. no wave64)
review: Read the whole diff (1 file, real.rs). CreateFence now masks the flags to the PC's valid set (SHARED, SHARED_CROSS_ADAPTER, NON_MONITORED) and drops upper-32-bit garbage, logging the first dropped value once. The tests cover the helper and a WARP-device run of dev_create_fence (child process of the test binary, the only process code) with console bits, checking creation, the completed value and tracking. The child returns silently when WARP is missing. Scope is one function; the stripped bits were invalid on the PC anyway.
performance: no cost: one mask per fence creation and one atomic load on the rare path; reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report (the diff review is Sonnet's)

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny
throny merged commit b335c2a into xcl-dev:main Dec 1, 2026
3 checks passed
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merged at the checked head after a combined trial of #3400, #3386, #3393 and #3535 on main d0832e61 (RTX 4080 16 GB, cargo test --workspace --no-fail-fast -- --test-threads=4: 2896 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks: Foniass and ours.

AI use: Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants