Skip to content

d3d12: a buffer in an upload or readback heap refuses ALLOW_RENDER_TARGET, committed or placed, as on the host - #5239

Closed
Exopus-0x65f7ad0 wants to merge 1 commit into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:d3d12/cpu-heap-rt-buffers
Closed

Exopus-0x65f7ad0 wants to merge 1 commit into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:d3d12/cpu-heap-rt-buffers

Conversation

@Exopus-0x65f7ad0

@Exopus-0x65f7ad0 Exopus-0x65f7ad0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: a new D3D item (claim).

Depends on: none.

What and why

The PC runtime takes no flag but DENY_SHADER_RESOURCE on a buffer in an upload or readback heap. The layer already refused ALLOW_UNORDERED_ACCESS there, but it created render-target buffers, both committed and placed. An application or test that probes a description like this gets a resource the host would refuse.

How it was found: a random CreateCommittedResource sweep (heap type × dimension × format × flags × initial state). It compares the layer with the host adapter and WARP and keeps only the descriptions where the two hosts agree.

Results over 40,000 descriptions:

Buffer in an upload/readback heap, flags Cases Host accepts main accepts
none 1,996 285 285
DENY_SHADER_RESOURCE 411 51 51
ALLOW_RENDER_TARGET 386 0 52
ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE 80 0 13
any other combination 2,099 0 0

Where the host accepts fewer than all cases, the rest are refused for other reasons, such as the initial state.

A direct probe confirms CreatePlacedResource. In a 64 KiB ALLOW_ONLY_BUFFERS heap:

  • ALLOW_RENDER_TARGET, with or without DENY_SHADER_RESOURCE, gives E_INVALIDARG on the host and on WARP, in both upload and readback heaps; main returns S_OK;
  • no flag, or DENY_SHADER_RESOURCE alone, gives S_OK everywhere.

The changes:

  • committed_resource_refusal: the upload and readback conditions now also refuse rt.
  • CreatePlacedResource: its upload/readback check now also refuses ALLOW_RENDER_TARGET, next to ALLOW_UNORDERED_ACCESS.
  • d3d12_vulkan_device_test compares five new rows with the host: a committed upload buffer with ALLOW_RENDER_TARGET, a committed readback buffer with ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE, a committed upload buffer with DENY_SHADER_RESOURCE (accepted, the positive control), and placed upload and readback buffers with ALLOW_RENDER_TARGET.

Tested

Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, RelWithDebInfo.

  • Full LEONIDA_VK_VALIDATION=1 ctest -j4: 167/167 pass, 0 VUIDs.
  • Negative control: with d3d12_vulkan_device.cpp back at main, d3d12_vulkan_device_test exits 1 with:
    invalid arguments committed: upload buffer with ALLOW_RENDER_TARGET: ours 0x00000000, host 0x80070057
    invalid arguments committed: readback buffer with ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE: ours 0x00000000, host 0x80070057
    

This is the same host/WARP differential approach as #5180 (fences) and #5218 (GetCopyableFootprints). AI-assisted (Claude Code). Synthetic descriptions only, no game files.

🤖 Generated with Claude Code

@thehollowedone

Copy link
Copy Markdown

Independent Windows x64 check of 4762d469 on base 3faac557. Windows 11 build 26300, RTX 3080 Ti, driver 621.35, MSVC 19.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, RelWithDebInfo.

All five published resource cases matched host D3D12 on the same adapter. The four committed or placed upload/readback cases with ALLOW_RENDER_TARGET returned E_INVALIDARG on both implementations. The committed upload control with only DENY_SHADER_RESOURCE returned S_OK on both.

The focused d3d12_vulkan_device CTest passed (1/1) with LEONIDA_VK_VALIDATION=1 and zero VUIDs. I used the exact PR production code and a scratch test entry point limited to the five published synthetic cases. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: PR #5239 @ 4762d46 (base 3faac55; Windows 11, MSVC 19.44, Ninja, RelWithDebInfo)

Configured C:/Users/kam/AppData/Local/Temp/opencode/review-5239/runtime/build-5239 (VULKAN_SDK=1.4.363.0, LEONIDA_VK_DEVICE="RTX 5070 Ti"):

cmake -S C:/Users/kam/AppData/Local/Temp/opencode/review-5239/runtime -B C:/Users/kam/AppData/Local/Temp/opencode/review-5239/runtime/build-5239 -G Ninja -DCMAKE_MAKE_PROGRAM="C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib -DVulkan_GLSLANG_VALIDATOR_EXECUTABLE=C:/VulkanSDK/1.4.363.0/Bin/glslangValidator.exe

Build: cmake --build <build-5239> --target d3d12_vulkan_device_test -> exit 0 (two pre-existing C4456 warnings at test lines 6776/6783).
Run: .\d3d12_vulkan_device_test.exe -> exit 0, 0 validation errors. Verbose run (LEONIDA_D3D49_VERBOSE=1) shows the new rows executed and matching the host:
committed: upload buffer with ALLOW_RENDER_TARGET: ours 0x80070057 host 0x80070057
committed: readback buffer with ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE: ours 0x80070057 host 0x80070057
committed: upload buffer with DENY_SHADER_RESOURCE: ours 0x00000000 host 0x00000000
placed: upload buffer with ALLOW_RENDER_TARGET: ours 0x80070057 host 0x80070057
placed: readback buffer with ALLOW_RENDER_TARGET: ours 0x80070057 host 0x80070057
Summary lines: Resolve comparison: 60 compared, 60 matched, 10 unsupported or host-unavailable cases skipped, 0 mismatches; final line reports all matched.
git diff --check -> clean, exit 0.

Verdict: no blocking issue. Committed and placed rows agree with the host; the permissible DENY_SHADER_RESOURCE-only row still succeeds.

@searyecheesepeaceful

Copy link
Copy Markdown

Tested 4762d46 on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_vulkan_device_test exits 0 and prints no "invalid arguments committed" failure line. The placed cases log the layer's refusals, "CreatePlacedResource refused (UAV access or a render target in an upload or readback heap), dimension 1" and "dimension 3". The new rows print nothing on a pass, so exit 0 is the only signal for them, and I did not run main for the failing control in the description.

AI-assisted.

@SirKingg

Copy link
Copy Markdown
Contributor

Independent focused Windows check of head 4762d469195ce5210ede3132e3351656f29b2745 against base 3faac557b1584d39004357918e60325b4d4ff0fe. Windows 11 build 26300, NVIDIA GeForce RTX 4070 Ti, driver 610.88 (32.0.16.1088), MSVC 19.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, RelWithDebInfo.

Using the exact PR production code and a temporary test entry point limited to its five new cases, I compared the NVIDIA-backed layer separately against native D3D12 on the RTX 4070 Ti and against WARP. All five matched for both hosts: the four committed/placed upload/readback cases with ALLOW_RENDER_TARGET returned E_INVALIDARG on both sides; committed upload with DENY_SHADER_RESOURCE alone returned S_OK on both. Both focused runs exited 0.

LEONIDA_VK_VALIDATION=1 enabled VK_LAYER_KHRONOS_validation (loader confirmed insertion); neither run emitted a VUID or validation error. As a negative control I rebuilt with the base production implementation and the same PR test cases, against WARP: all four render-target cases returned S_OK on the layer versus E_INVALIDARG on WARP, while the positive control still matched; the focused run exited 1. No game files or 40,000-description sweep were used; this was not the full device suite. AI-assisted.

@kormocicsaba

Copy link
Copy Markdown

Tested 4762d469 (up to date with main 3faac557) on Windows 11 Pro 26300, VS 2026 (MSVC) + Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, no game files: pass on both GPUs in this machine.

GPU driver d3d12_vulkan_device_test with LEONIDA_VK_VALIDATION=1
NVIDIA GeForce RTX 4070 621.01 exit 0 exit 0, 0 validation messages
AMD Radeon iGPU (VK_LOADER_DRIVERS_SELECT=*amd*) 24.10.34 exit 0 exit 0, 0 validation messages

The host comparison follows the layer's adapter, so the five new rows were checked against the NVIDIA D3D12 driver in one run and the AMD driver in the other.

Full LEONIDA_VK_VALIDATION=1 ctest -j4 on the RTX 4070: 177/177 passed. 9 didn't run, none related to this PR: 7 need the package or first-light data, gameinput is disabled (no SDL3), and d3d12_rgb9e5_rtv skips because RGB9E5 render targets aren't available on this adapter.

Negative controls, each half reverted separately:

  • With main's d3d12_vulkan_device.cpp, the test exits 1 on both GPUs: committed: upload buffer with ALLOW_RENDER_TARGET: ours 0x00000000, host 0x80070057, and the same for the readback row. This matches your result.
  • That run stops in the invalid-arguments section, so it never reaches the placed rows. To cover them, I kept the PR's committed change and reverted only the CreatePlacedResource condition. The test then exits 1 with placed: upload buffer with ALLOW_RENDER_TARGET and placed: readback buffer with ALLOW_RENDER_TARGET, both ours 0x00000000, host 0x80070057.

So each of the two changes is needed, and the new rows catch each one. The DENY_SHADER_RESOURCE-only upload row is accepted by both us and the host, so it works as the positive control.

AI-assisted (Claude Code).

@Codejustcode12

Copy link
Copy Markdown

Tested 4762d46 on a resource heap tier 1 host: NVIDIA GeForce GTX 1050 Ti (Pascal), driver 560.94, Windows 10 Enterprise LTSC 21H2 (19044), MSVC 14.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363, RelWithDebInfo + Ninja. Synthetic only, no game files.

Tree: main 3faac55 + #4682 (9c69b41) + #5000 (5713bf8) + this PR. Without #4682 this driver stops d3d12_vulkan_device at line 172 (TEST-995), and without #5000 at line 7051 (D3D-504). d3d12_vulkan_device_test exits 0 with and without LEONIDA_VK_VALIDATION=1: no failing line, 0 VUIDs.

LEONIDA_D3D49_VERBOSE=1 rows:

  • committed upload + ALLOW_RENDER_TARGET: ours 0x80070057, host 0x80070057
  • committed readback + ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE: ours 0x80070057, host 0x80070057
  • committed upload + DENY_SHADER_RESOURCE: ours 0x00000000, host 0x00000000
  • placed upload / readback + ALLOW_RENDER_TARGET: ours 0x80070057, host 0x8000ffff, reported as "the tier 1 host refuses a heap of mixed resources"

So on a tier 1 host the two placed rows are not compared: PlacedArgs defaults to a D3D12_HEAP_FLAG_NONE heap (d3d12_vulkan_device_test.cpp:2993), which a tier 1 host refuses, so placed() returns E_UNEXPECTED before CreatePlacedResource runs. A standalone D3D12 probe on the same GPU, with a 64 KiB D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS heap, gives the rule this PR adds:

  • upload or readback + ALLOW_RENDER_TARGET, and upload + ALLOW_RENDER_TARGET | DENY_SHADER_RESOURCE: CreatePlacedResource E_INVALIDARG
  • upload with no flag, readback + DENY_SHADER_RESOURCE: S_OK

Suggestion, not blocking: set a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS in the two new placed rows, as your direct probe did, so tier 1 hosts compare them too (tier 2 hosts accept that heap as well).

How: test executable run directly (not ctest), twice. The merged tree is a local merge of the PR heads.

AI-assisted (Claude Code).

…RGET, committed or placed

The PC runtime (an RTX 5060 Ti and WARP alike) takes no flag but DENY_SHADER_RESOURCE on a buffer in an upload or
readback heap; the layer refused ALLOW_UNORDERED_ACCESS there but created render-target buffers. Found by a random
CreateCommittedResource sweep against both hosts (812 such descriptions: the host accepts none, the layer 65) and
confirmed for CreatePlacedResource. committed_resource_refusal and the placed path now refuse it;
d3d12_vulkan_device_test compares five new rows with the host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exopus-0x65f7ad0
Exopus-0x65f7ad0 force-pushed the d3d12/cpu-heap-rt-buffers branch from 4762d46 to ada2832 Compare November 23, 2026 13:09
@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor Author

Rebased on main 561b65a8 (new head ada28322). main added the ALLOW_SHADER_ATOMICS without ALLOW_UNORDERED_ACCESS refusal right before this PR's upload/readback checks. The resolution keeps it first, then this PR's checks, which also refuse ALLOW_RENDER_TARGET on CPU heaps. RTX 5060 Ti / 621.14, clean build with -DLEONIDA_LLVM_MC: LEONIDA_VK_VALIDATION=1 ctest -j4 gives 234 of 236, d3d12_vulkan_device included. The two failures, d3d12_indirect_rt and d3d12_indirect_dispatch_count, fail on main alone too here. AI-assisted (Claude Code).

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of ada28322 on 561b65a8. Windows 11 x64, RTX 3080 Ti / 621.35, MSVC, Vulkan SDK 1.4.363.0.

The focused d3d12_vulkan_device test matched native D3D12 on both the RTX and WARP. All four upload or readback buffer requests with ALLOW_RENDER_TARGET returned E_INVALIDARG. The upload request with only DENY_SHADER_RESOURCE and the four unflagged committed and placed controls returned S_OK. Both runs passed without skips or Vulkan core or synchronization validation errors.

The test selected these nine cases from the published fixture. Runtime code matched the PR head. Synthetic inputs only. AI-assisted.

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.

8 participants