Skip to content

d3d12_xs: map console texture D3D12_BARRIER_LAYOUT initial states on committed and placed resources - #9338

Closed
TheAirborneCoder wants to merge 5 commits into
ProjectLeonida:mainfrom
TheAirborneCoder:d3d12-xs-texture-barrier-layouts
Closed

TheAirborneCoder wants to merge 5 commits into
ProjectLeonida:mainfrom
TheAirborneCoder:d3d12-xs-texture-barrier-layouts

Conversation

@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Claimed in: #8683 (comment)
Depends on: #7356, #8384

Summary

Following #7356 and #8384, @Jadiac5's live boot trace on #8344 hit E_INVALIDARG (0x80070057) in CreatePlacedResource (device slot 29) for a 512x512 BC4_UNORM TEXTURE2D with Flags == 0 and initial state 0x6 (D3D12_BARRIER_LAYOUT_SHADER_RESOURCE):

  1. Slot 29 (CreatePlacedResource) was not yet routed through pc_initial_state_word (only slots 27, 53, and 76 were).
  2. pc_initial_state_word only handled layouts 3 (RT+UAV) and 4 (depth-stencil), leaving 0x6 (D3D12_BARRIER_LAYOUT_SHADER_RESOURCE, whose bits 0x2 | 0x4 mean buffer-only INDEX_BUFFER | RENDER_TARGET in legacy D3D12_RESOURCE_STATES) and the remaining texture D3D12_BARRIER_LAYOUT ordinals unmapped.

This change:

  • Routes device slot 29 (CreatePlacedResource) through pc_initial_state_word via a 7-argument proxy_create_resource_state7<Slot> shared with slot 27 (CreateCommittedResource), keeping 8-argument proxy_create_committed_resource1 separate for slot 53 so 7-argument calls never touch a8, and marks slot 29 in slot_name() / device_slot_overridden().
  • Extends pc_initial_state_word across TEXTURE1D / TEXTURE2D / TEXTURE3D using leonida::d3d12_layout (runtime/src/command_list.h), disambiguating the two ordinals (4 and 8) whose numeric values overlap valid texture D3D12_RESOURCE_STATES bits via desc->Flags:
    • 0xFFFFFFFF (UNDEFINED), 18/24 (DIRECT/COMPUTE_QUEUE_COMMON) -> D3D12_RESOURCE_STATE_COMMON (0)
    • 1, 19, 25 (GENERIC_READ) -> D3D12_RESOURCE_STATE_GENERIC_READ (0xAC3)
    • 2 (RENDER_TARGET) with ALLOW_RENDER_TARGET -> D3D12_RESOURCE_STATE_RENDER_TARGET (0x4)
    • 3, 20, 26 (UNORDERED_ACCESS) with ALLOW_UNORDERED_ACCESS -> D3D12_RESOURCE_STATE_UNORDERED_ACCESS (0x8, covering UAV-only as well as RT+UAV textures)
    • 4: with ALLOW_DEPTH_STENCIL and not ALLOW_RENDER_TARGET, maps DEPTH_STENCIL_WRITE -> D3D12_RESOURCE_STATE_DEPTH_WRITE (0x10); with ALLOW_RENDER_TARGET, preserves legacy 0x4 (RENDER_TARGET)
    • 5 (DEPTH_STENCIL_READ) with ALLOW_DEPTH_STENCIL -> D3D12_RESOURCE_STATE_DEPTH_READ (0x20)
    • 6, 21, 27 (SHADER_RESOURCE) without DENY_SHADER_RESOURCE -> D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE (0xC0)
    • 7, 22, 28 (COPY_SOURCE) -> D3D12_RESOURCE_STATE_COPY_SOURCE (0x800)
    • 8: without ALLOW_UNORDERED_ACCESS, maps COPY_DEST -> D3D12_RESOURCE_STATE_COPY_DEST (0x400); with ALLOW_UNORDERED_ACCESS, preserves 0x8 (ambiguous with legacy UNORDERED_ACCESS, which PC D3D12 accepts); 23/29 (DIRECT/COMPUTE_QUEUE_COPY_DEST) -> D3D12_RESOURCE_STATE_COPY_DEST (0x400)
    • 9 (RESOLVE_SOURCE) -> 0x2000, 10 (RESOLVE_DEST) -> 0x1000
    • Valid PC texture state masks (0x10, 0x20, 0x40, 0x80, 0xC0, 0x400, 0x800, etc.) and DIMENSION_BUFFER / DIMENSION_UNKNOWN / null desc pass through unchanged.

Testing

Tested on Windows 11 (10.0.26200), MSVC 19.51.36260.0 (RelWithDebInfo, /W4 zero warnings), D3D12 + WARP, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088) / AMD Radeon Graphics (driver 32.0.21042.62):

  • ctest --test-dir build -C RelWithDebInfo --output-on-failure: 103/103 runnable tests passed (0 failures; 7 retail-package tests skipped when LEONIDA_GAME_DIR is unset), including expanded mock coverage in runtime/test/xs_proxy_mock_test.cpp (7-word vs 8-word forwarding, all mapped ordinals, flag disambiguations, TEXTURE1D/2D/3D, non-colliding PC states, untouched buffers) and live WARP coverage in runtime/test/device_proxy_test.cpp across slots 27, 29 (tier-safe heaps), 53, and 76 (with raw WARP negative controls confirming unmapped 0x6 and 0x8 fail with E_INVALIDARG on 512x512 BC4_UNORM TEXTURE2D Flags=0).
  • python -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_device.cpp runtime/test/device_proxy_test.cpp runtime/test/xs_proxy_mock_test.cpp (clean)

AI-assisted (Antigravity).

tedin7 and others added 5 commits November 23, 2026 17:36
…so the state map is checked with the riid and output in place
…VC leaves the upper half of the stack slot), and else-branch the generic forwarder (C4702); found by MartinIndra02 on ItsNotRexed#7356
…S (CLAIM 7110346733)

Stacked on ItsNotRexed#7356's pc_initial_state_word. Barrier layout 0x3 was refused as
buffer-only bits; with ALLOW_UNORDERED_ACCESS it becomes UNORDERED_ACCESS.
…committed and placed resources

Console CreateCommittedResource (slot 27), CreatePlacedResource (slot 29),
CreateCommittedResource1 (slot 53) and slot 76 pass a D3D12_BARRIER_LAYOUT
ordinal in the initial-state word rather than a legacy D3D12_RESOURCE_STATES
mask. On textures (TEXTURE1D / TEXTURE2D / TEXTURE3D), most barrier-layout
ordinals carry buffer-only or conflicting bits that PC D3D12 rejects with
E_INVALIDARG (such as layout 6 SHADER_RESOURCE on placed BC4_UNORM textures).

Route slot 29 CreatePlacedResource through pc_initial_state_word alongside
slots 27, 53 and 76 (keeping 7-word forwarding for slots 27 and 29 separate
from 8-word slot 53), and map all unambiguous texture D3D12_BARRIER_LAYOUT
ordinals to PC D3D12_RESOURCE_STATES gated by the resource flags each layout
requires, disambiguating ordinals 4 (RENDER_TARGET vs DEPTH_STENCIL_WRITE)
and 8 (UNORDERED_ACCESS vs COPY_DEST) by Flags while leaving buffer and
non-colliding PC texture states untouched.

Claim: ItsNotRexed#8683 (comment 7111877498)
Depends on: ItsNotRexed#7356, ItsNotRexed#8384

@rideinstead rideinstead left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leonida automated security-monitor note

The static monitor found items that need maintainer inspection. These are heuristic signals, not confirmed vulnerabilities.

Findings

  • LOW — Sensitive terminology at runtime/shims/d3d12_xs_device.cpp:1478
    Evidence: // Valid PC texture state masks (0x10 DEPTH_WRITE, 0x20 DEPTH_READ, 0x40/0x80/0xC0 shader reads, etc.) and all

Diff-only heuristic scan; contributor code was not executed. This is advisory and does not replace maintainer review.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows & MSVC Review

What changed:

  • runtime/shims/d3d12_xs_device.cpp:
    • Maps console D3D12_BARRIER_LAYOUT initial-state ordinals to PC D3D12_RESOURCE_STATES on CreateCommittedResource, CreatePlacedResource, and CreateCommittedResource1.
    • Disambiguates ordinals 4 and 8 using resource flags, avoiding E_INVALIDARG rejections on texture creations.

Verification on Windows 11 host:

  • Build passes under MSVC 19.44 / CMake.
  • device_proxy_test and xs_proxy_mock_test pass all barrier layout checks.
  • Clean diff: no game files.

LGTM!

@rideinstead rideinstead left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction — false positive

Please disregard the previous automated note. It was triggered solely by the word shader in a descriptive comment about D3D12 texture-state masks. That is ordinary graphics terminology, not a security indicator. This finding did not identify suspicious behavior. The keyword-only terminology rule has been removed from the monitor.

@MiguelMatMar

Copy link
Copy Markdown

Tested 575e7a0 on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo (fresh build folder), applied on main 6312c05, no game data: pass.

  • device_proxy and xs_proxy_mock: both pass.
  • Negative control: only the test-side files applied (no source change): both fail.

(AI-assisted check, Claude Code.)

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