Skip to content

Runtime: CreateReservedResource takes ALLOW_CROSS_ADAPTER, as the host does (D3D-468) - #4496

Open
emirduran707 wants to merge 911 commits into
ItsNotRexed:mainfrom
emirduran707:d3d-468-reserved-cross-adapter
Open

emirduran707 wants to merge 911 commits into
ItsNotRexed:mainfrom
emirduran707:d3d-468-reserved-cross-adapter

Conversation

@emirduran707

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-468, #4421 (comment)

What and why

CreateReservedResource refused a description with D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER (E_INVALIDARG), which the host creates (@gabsilvs's finding, 9 random reserved buffers).

  • Cause. create_reserved checks the description with committed_resource_refusal, whose flag masks leave ALLOW_CROSS_ADAPTER out: a committed resource only takes it on a SHARED | SHARED_CROSS_ADAPTER heap, which the layer doesn't have.
  • What the host does (measured, table below). It takes the flag on a reserved buffer or texture wherever it takes the same description without it, and GetDesc reports it. A description it refuses anyway stays refused.
  • Change. create_reserved checks and backs the resource without the flag, and make_reserved keeps the application's flags for GetDesc. A reserved resource has no heap to share and the layer has one adapter, so the flag changes nothing else.
  • Tests. 19 cases in compare_placed_reserved (d3d12_vulkan_device_test), and a line in docs/d3d12_vulkan.md.

The item names buffers. Textures go through the same check and the host answers them the same way, so they are in here too.

reserved description with ALLOW_CROSS_ADAPTER host (AMD and WARP) layer before layer now
buffer: 64 KiB, 1 byte, 1 MiB, in COPY_DEST, with ALLOW_UNORDERED_ACCESS, with DENY_SHADER_RESOURCE S_OK E_INVALIDARG S_OK
buffer with ALLOW_SIMULTANEOUS_ACCESS, ALLOW_DEPTH_STENCIL or flag 0x200 E_INVALIDARG E_INVALIDARG E_INVALIDARG
2D texture: plain, with ALLOW_UNORDERED_ACCESS, with ALLOW_SIMULTANEOUS_ACCESS, BC1, full mip chain, 4-layer array; 3D texture S_OK E_INVALIDARG S_OK
2D texture with layout ROW_MAJOR E_INVALIDARG E_INVALIDARG E_INVALIDARG
GetDesc().Flags of the buffer and of the texture 0x10 (not created) 0x10

Two combinations are not in the test, because a host driver loses its device on them (DXGI_ERROR_DEVICE_REMOVED, and every later case with it):

  • a buffer with ALLOW_CROSS_ADAPTER | ALLOW_RENDER_TARGET: S_OK on the AMD driver, device removed on WARP;
  • a D32_FLOAT depth texture with ALLOW_CROSS_ADAPTER | ALLOW_DEPTH_STENCIL: S_OK on WARP, device removed on the AMD driver.

The layer creates both. The test's comment says why they are left out.

Not in this PR: GetResourceAllocationInfo with this flag (D3D-467), and CreatePlacedResource.

@SHAURYASANYAL3, our claims for D3D-468 crossed two seconds apart (mine 01:37:33 UTC, yours 01:37:35), so this one is covered; D3D-467 and D3D-469 are untouched here.

Tested

Windows 11 Pro 10.0.26300, AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (Vulkan driver 2.0.395), MSVC 14.44 (VS 2022), Windows SDK 10.0.26100, base 03b09a0.

  • d3d12_vulkan_device_test with LEONIDA_D3D49_VERBOSE=1: the 19 new cases match the host, and the test exits 0, with the default host (the AMD adapter) and with LEONIDA_HOST_ADAPTER=warp.
  • Red on main: with the same cases and main's d3d12_vulkan_device.cpp, the 15 cases the host accepts are mismatches (ours 0x80070057, host 0x00000000, or 0x00010010 for the two GetDesc cases) on both hosts.
  • ctest (full build): 154 of 154 passed. Skipped as on main: the package-gated tests, vk_sync_validation, d3d12_first_light.
  • git diff --check clean.

Not tested: NVIDIA or Intel hosts, and a Vulkan device without sparse buffers (there a reserved buffer is a fully backed committed resource; the flag is stripped before that path too).

No game files. AI-assisted (Claude Code): the measurement, the change and the tests were made and run with it on my machine.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

🤖 Generated with Claude Code

# Conflicts:
#	docs/animation.md
# Conflicts:
#	docs/design.md
# Conflicts:
#	docs/character_skeleton.md
# Conflicts:
#	docs/design.md
# Conflicts:
#	docs/design.md
ItsNotRexed and others added 3 commits November 22, 2026 18:52
- replay_cpu_bench: ItsNotRexed#3693 moved a draw's render targets and vertex buffers into Draw::views (D3D-391); the bench
  builds a DrawViews block instead of writing the old inline arrays.
- xgameruntime_user_test links file_system.cpp, which now defines rt::fs::game_dir that xgameruntime.cpp calls.
- check_sparse_queue_family: a vkCreateInstance refused because the api_dump/validation layer is not installed is
  the documented "layer absent" skip (77), not a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit 718f105, reversing
changes made to 9aa16b2.
…t does (D3D-468)

create_reserved checked the description with committed_resource_refusal, which
refuses ALLOW_CROSS_ADAPTER (a committed resource needs a shared cross-adapter
heap for it). The host creates a reserved buffer or texture with the flag
wherever it creates the same description without it, and GetDesc reports it.

The description is now checked and backed without the flag, and the resource
keeps the application's flags for GetDesc. 19 cases in
d3d12_vulkan_device_test's compare_placed_reserved, the same on an RX 9060 XT
(AMD 26.10.44) and on WARP.

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

@Kam471 Kam471 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.

Built and ran d3d12_vulkan_device_test at 5c6544ee on Windows 11, RTX 5070 Ti: exit 0; the reserved-resource cases and the full device suite pass, matching the host. CreateReservedResource now accepts ALLOW_CROSS_ADAPTER with the host's behavior. No blocking issue.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5c6544e on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and on AMD Radeon(TM) Graphics (driver 32.0.21043.5001), Windows 11, MSVC 14.51: pass for the reserved-resource checks. The build has no validation layers.

I set LEONIDA_VK_DEVICE and LEONIDA_HOST_ADAPTER to the same adapter for each run and ran d3d12_vulkan_device_test.exe with LEONIDA_D3D49_VERBOSE=1. Both runs exit with 0.
On each GPU, all 19 new cases match native D3D12. The buffer and texture GetDesc checks both give the flag 0x10.

Extra case: a buffer of 65,537 bytes with ALLOW_CROSS_ADAPTER and ALLOW_UNORDERED_ACCESS. The two native drivers and the layer all give the flags 0x14.

Negative control: the test object of this head, linked with the D3D12 libraries of the merge base 03b09a08, gives 15 of 19 cases that differ from native D3D12 on each GPU, and exits with 1.

I found no defect. AI-assisted.

@AGInformatique81 AGInformatique81 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.

I ran the synthetic d3d12_vulkan_device CTest at 5c6544e on Windows 11 build 26300, with MSVC 19.52 and the 10.0.26100 Windows SDK, in RelWithDebInfo. Leonida used Vulkan on an NVIDIA GeForce RTX 2060 (driver 32.0.16.2124).

Native D3D12 reference PR revision Parent implementation with the PR tests
RTX 2060 CTest passed, 19/19 cross-adapter cases matched CTest failed, 15/19 cross-adapter cases differed
WARP (Microsoft Basic Render Driver) CTest passed, 19/19 cross-adapter cases matched CTest failed, 15/19 cross-adapter cases differed

Both GetDesc cases matched the native reference with the PR. For the control, I rebuilt with only runtime/shims/d3d12_vulkan_device.cpp sourced from parent 03b09a0 and kept the PR's test harness. The runs used synthetic inputs only. Codex assisted with the validation and this report.

@Flyander Flyander 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.

[P2] Preserve the simultaneous-access behavior implied by ALLOW_CROSS_ADAPTER. Microsoft documents that this flag also enables the features of ALLOW_SIMULTANEOUS_ACCESS (resource flags). This implementation strips ALLOW_CROSS_ADAPTER before creating the backing resource, then restores only the public GetDesc flags. Resource::create_image has already set binding.simultaneous_access from ALLOW_SIMULTANEOUS_ACCESS alone and registered that binding, so a reserved texture with ALLOW_CROSS_ADAPTER alone is still backed as exclusive and misses the GENERAL-layout path. Preserve that semantic in the Vulkan binding or reject the unsupported use, and add a concurrent-queue regression for CROSS_ADAPTER alone.

- test_bary_fallback: ItsNotRexed#3647 (BUILD-1046) made a missing input folder exit 2 with "does not exist"; the test from
  ItsNotRexed#1379 still expected exit 1.
- test_format_decode_branch: the f16 reference uses the interpreter's pinned half_to_float (a NaN half widens to
  the canonical quiet NaN) instead of struct's '<e', whose NaN payload changed in Python 3.14 (CPython gh-130317).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 5c6544ee on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • d3d12_vulkan_device passes.
  • ctest: 145 passed, 10 skipped, 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main 03b09a08.
  • In the first ctest -j 8 run, d3d12_fence_timing crashed once (SEGFAULT). It did not recur: 10/10 passes run alone and two more full ctest -j 8 runs at 154/154, and main behaved the same. This PR does not touch fence code, so I read it as an intermittent crash in that test, not something this change causes.

AI-assisted (Claude Code).

@mrbean56

Copy link
Copy Markdown

Reading review (no Windows/D3D12 here), plus the API documentation and a cross-PR merge check.

Cannot run the Windows test. No game data. AI-assisted.

@Alpaca-exe

Copy link
Copy Markdown

AI-assisted Windows hardware verification for D3D-468 on AMD Radeon RX 6750 XT (0x1002:0x73df, RDNA2, Windows 11, AMD driver 26.11.2 / 32.0.21045.29003, Vulkan 1.4.315, MSVC 19.44.35230.0, VK_LOADER_LAYERS_DISABLE=~implicit~):

  • Built d3d12_vulkan_device_test from commit 5c6544eee (rc=0).
  • Ran d3d12_vulkan_device_test.exe with LEONIDA_D3D49_VERBOSE=1 against the host Windows D3D12 runtime: rc=0 (1093 verbose lines).
  • All 22 SHARED_CROSS_ADAPTER / ALLOW_CROSS_ADAPTER checks matched the host runtime:
  invalid arguments committed: heap flag SHARED_CROSS_ADAPTER on a buffer: ours 0x80070057 host 0x80070057
  invalid arguments committed: resource flag ALLOW_CROSS_ADAPTER on a buffer: ours 0x80070057 host 0x80070057
  invalid arguments committed: resource flag ALLOW_CROSS_ADAPTER on a texture: ours 0x80070057 host 0x80070057
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: 1-byte buffer with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: 1 MiB buffer with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER in COPY_DEST: ours 0x00000000 host 0x00000000
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER | ALLOW_UNORDERED_ACCESS: ours 0x00000000 host 0x00000000
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER | DENY_SHADER_RESOURCE: ours 0x00000000 host 0x00000000
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER | ALLOW_SIMULTANEOUS_ACCESS: ours 0x80070057 host 0x80070057
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER | ALLOW_DEPTH_STENCIL: ours 0x80070057 host 0x80070057
  invalid arguments reserved: buffer with ALLOW_CROSS_ADAPTER | 0x200: ours 0x80070057 host 0x80070057
  invalid arguments reserved: GetDesc of a buffer with ALLOW_CROSS_ADAPTER: ours 0x00010010 host 0x00010010
  invalid arguments reserved: texture with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: texture with ALLOW_CROSS_ADAPTER | ALLOW_UNORDERED_ACCESS: ours 0x00000000 host 0x00000000
  invalid arguments reserved: texture with ALLOW_CROSS_ADAPTER | ALLOW_SIMULTANEOUS_ACCESS: ours 0x00000000 host 0x00000000
  invalid arguments reserved: BC1 texture with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: full mip chain with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: texture array with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: 3D texture with ALLOW_CROSS_ADAPTER: ours 0x00000000 host 0x00000000
  invalid arguments reserved: texture with ALLOW_CROSS_ADAPTER and layout ROW_MAJOR: ours 0x80070057 host 0x80070057
  invalid arguments reserved: GetDesc of a texture with ALLOW_CROSS_ADAPTER: ours 0x00010010 host 0x00010010

…access (D3D-468 review)

D3D12_RESOURCE_FLAGS documents ALLOW_CROSS_ADAPTER as enabling the features of
ALLOW_SIMULTANEOUS_ACCESS. create_reserved dropped the flag before backing the
resource, so a reserved texture with it alone was backed as exclusive and its
image did not stay in GENERAL.

The backing texture now gets ALLOW_SIMULTANEOUS_ACCESS in its place, except a
depth-stencil or multisampled one, where the runtime refuses simultaneous
access. Buffers have no layouts. GetDesc still reports the application's flags.

vulkan_simultaneous_access (for tests) reads the binding; d3d12_vulkan_device_test
checks it for CROSS_ADAPTER alone, SIMULTANEOUS_ACCESS, a plain texture, a depth
texture and a buffer. Also notes that the resource still cannot be shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor Author

@Flyander, you're right: stripping the flag also dropped the simultaneous-access behaviour it enables. Fixed in af00d12.

  • create_reserved now backs a texture that has ALLOW_CROSS_ADAPTER with ALLOW_SIMULTANEOUS_ACCESS in its place, so Resource::create_image sets binding.simultaneous_access and the image stays in GENERAL (image_layout in vulkan_replay.h, the one place that reads the bit). GetDesc still reports only the application's flags.
  • Not on a depth-stencil or multisampled texture: the layer refuses simultaneous access there, as the runtime does (allocation), so those are backed without it. Buffers have no layouts.
  • Test: rt::d3d12::vulkan_simultaneous_access (a test accessor next to vulkan_memory_flags) reads the binding, and d3d12_vulkan_device_test checks it for CROSS_ADAPTER alone (true, GetDesc().Flags still 0x10), ALLOW_SIMULTANEOUS_ACCESS (true), a plain reserved texture (false), a D32 depth texture with CROSS_ADAPTER (false) and a buffer with it (false).
  • Red without the fix: with the new backing.Flags |= line disabled, the test fails at vulkan_simultaneous_access(cross_texture.p).

On the concurrent-queue regression you asked for: I did not add one, and want to say so plainly. The check above shows that CROSS_ADAPTER alone and ALLOW_SIMULTANEOUS_ACCESS now give the same binding, so both take the same replay path; but I found no D3D12-level test that uses an ALLOW_SIMULTANEOUS_ACCESS texture from two queues at once (only vk_command_replay_test part D at the replay level). Writing that test would cover both flags and looks like its own item. If you would rather have it in this PR, tell me and I'll add it here.

@mrbean56, thanks: the comment in create_reserved and the line in docs/d3d12_vulkan.md now say that the resource still cannot be shared with another adapter, so a later attempt fails.

Tested at af00d12 on the RX 9060 XT (AMD 26.10.44), Windows 11: d3d12_vulkan_device_test exits 0 with the AMD host and with LEONIDA_HOST_ADAPTER=warp, the 19 comparison cases still match on both, and ctest is 154 of 154. A trial merge with main d0835dd is clean. AI-assisted (Claude Code).

ItsNotRexed and others added 3 commits November 22, 2026 22:07
Merges that each passed alone but clash together:
- v_cmp_class_f64: the earlier cmp_class_f64 (685d16e) (operand-form checks, test_cmp_class_f64) and the later f64 branch
  in cmp_class both handled the opcode; f64 goes to cmp_class_f64 again, f16 stays in cmp_class.
- rdna2spirv CLI tests: spirv-as/spirv-val now run in the output folder with the staging file's bare name, so
  the test doubles resolve it against cwd; assemble_spirv decodes the output only when it is bytes. (The doubles
  had been writing .spirv-*.tmp files into the repository root.)
- ps_w64 fixtures (TEST-722): an 18th fixture (ps_w64_a_discard) landed; its killed lanes export nothing and
  keep the clear value.
- first_light: a run without an OBJ removes mesh.bin, and harness_env reads manifest["files"]; batch_glb's stats
  name failures and dropped textures; run_gpu_tests reports a frame never written as a missing readback
  (TEST-837).
- make_game TRANSLATION_SOURCES and runtime.yml's paths include spirv_opt.py and report_paths.py (and
  wave64_emulate_opt.py), which the translator imports.
Repo rules: stdout guard on six tools; encoding on two opens (gen_gdk_runtime_classes' helper is read_utf8);
newline on one write; anim_skeleton_match's joaat encodes like hashdict.joaat; test_feature_scan's new test is
listed with the others its globals() runner reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit ce318cd, reversing
changes made to a78f170.
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/xgameruntime.cpp
#	runtime/test/xmem_test.cpp
#	tools/rdna2spirv.py
@kapitche

Copy link
Copy Markdown
Contributor

Tested af00d12 merged with main d0835dd (merged tree 1d7ba28392) on Windows 11 with two GPUs (MSVC 14.51): built d3d12_vulkan_device_test and ran it directly twice per GPU.

  • NVIDIA RTX 4080 SUPER: exit 0, 2 of 2. Intel UHD 770 (driver 32.0.101.6129): exit 0, 2 of 2. (This test crashed intermittently on the NVIDIA GPU for Runtime: recreate host-transfer textures the driver gives no memory type #3077's build, not for this one in 2 runs.) The output prints no per-case line for the new reserved: ... ALLOW_CROSS_ADAPTER cases, only the exit code, so I can't quote their count.

Negative control (compile-only): with runtime/shims/d3d12_vulkan_device.cpp restored from main the test does not link (unresolved external symbol rt::d3d12::vulkan_simultaneous_access), so the new cases can't run against main as is; I did not write a smaller control. Not checked here: the claim about the AMD/WARP hosts.

ItsNotRexed and others added 3 commits November 22, 2026 22:30
- rdna2spirv: %fmt_size_tab (main's typed-load size table) registers its length and entry constants when a load
  first uses it; created at assembly, %c128 came after the OpTypeArray naming it and spirv-val refused
  buffer_store_format_d16 modules (test_u16_high_half).
- test_vs_packed_inputs matches main's wording of the same SHADER-644 rule ("mixed component types").
- test_mutations: the v_mul_legacy_f32 anchor follows the SHADER-340 flushes (it had stopped matching on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#2887 added the fixture to the M2 build; with no entry in OTHER_HARNESS the GPU suite reported it as
"no checker defined".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
create_reserved now returns through d3d12_trace::result (main) and still
passes the caller's flags to make_reserved (D3D-468).

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

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 826d4dd on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^d3d12_vulkan_device$" (the test this PR changes): pass on both GPUs, 1/1 each. No game files.

AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 826d4dd merged onto main 98fa503 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 174/174.
  • d3d12_vulkan_device: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.

AI-assisted (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.