Skip to content

Runtime: reserved resources and GetResourceTiling on Vulkan (D3D-20) - #295

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
traeb0n:d3d12-reserved-resources
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
traeb0n:d3d12-reserved-resources

Conversation

@traeb0n

@traeb0n traeb0n commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #156 as: D3D-20

What and why

docs/d3d12_vulkan.md §4.2 plans reserved resources for the first boot: "reserve the full size linearly; tile mapping calls are logged, not emulated". Before this PR, CreateReservedResource, GetResourceTiling and the queue's tile-mapping calls were all stubs. A game that streams textures through reserved resources reads GetResourceTiling to size its tile heaps and mapping calls, so this PR implements that too, and checks it against the PC runtime.

  • Creation (d3d12_vulkan_device.cpp): CreateReservedResource, CreateReservedResource1 and CreateReservedResource2 create a committed resource on a default heap underneath.

    • Every tile is backed and starts zeroed, which is how D3D12 tier 2 reads unmapped tiles.
    • CreateReservedResource1 refuses protected sessions. CreateReservedResource2 ignores castable formats, because typeless resources are already mutable-format images.
    • D3D12's description rules, as measured on the PC runtime: buffers must be ROW_MAJOR; textures must be 64KB_UNDEFINED_SWIZZLE, in a format with a tile shape. Anything else is E_INVALIDARG, including 64KB_STANDARD_SWIZZLE, because CheckFeatureSupport (Runtime: implement CheckFeatureSupport for format support, VA limits, and options (D3D-11) #241) reports StandardSwizzle64KBSupported as FALSE. GetHeapProperties on a reserved resource is also E_INVALIDARG.
    • The Xbox tiled layout word 0x101 (the slot-76 path, §4.2) is accepted as 64KB_UNDEFINED_SWIZZLE. This is marked as an assumption.
  • Tiling (runtime/src/resource_tiling.h, a pure header): what D3D12 defines.

    • The standard 64 KiB tile shapes for 1/2/4/8/16-byte elements in 2D and 3D, with BC shapes in texels.
    • Standard vs packed mips: packed from the first mip smaller than a tile on any axis.
    • The tile counts of each standard mip, and the tile order: each array slice holds its standard mips, then its packed tiles.
    • How many tiles the packed mips take is the driver's choice. Here it's their tight linear size in whole tiles.
  • GetResourceTiling fills D3D12_PACKED_MIP_INFO, D3D12_TILE_SHAPE and the subresource tilings, honouring FirstSubresourceTilingToGet and the in/out count. A resource that isn't reserved reports no tiles, as on the PC runtime.

  • UpdateTileMappings / CopyTileMappings log once and do nothing. What that loses is written down in §4.2:

    • two resources mapped to the same heap tiles don't alias;
    • a tile that is unmapped or remapped keeps its contents.

    If the trace shows the game relies on either, the next step is sparse binding on top of D3D-16's heaps. CopyTiles stays a stub.

Measured on the PC runtime (RTX 5070; recorded in §4.2 and in the test comments):

  • Packed-tile counts matched this rule on every layout probed, except three where the PC runtime reported one tile more: 1000×300 and 100×100 RGBA8, and a 128³ R8 volume.
  • On array slices after the first, the PC runtime writes a tile index into packed subresources. The docs specify D3D12_PACKED_TILE, so this implementation follows the docs.

Neighbours: #286 (D3D-16, heaps and placed resources). CheckFeatureSupport (#241, merged) still reports TiledResourcesTier as not supported, so a game that checks the tier will create committed resources instead; this PR leaves that alone. Raising the tier is a call for the maintainers once the trace shows what the game does, since tile mappings aren't emulated.

Tested

RTX 5070, NVIDIA driver 621.01, Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, Windows SDK 10.0.26100, rebased on 83d0637:

  • d3d12_vulkan_device_test with LEONIDA_VK_VALIDATION=1: passes with 0 validation errors (it also passes without validation). New coverage:
    • Comparison with the host runtime: GetResourceTiling against the host PC runtime for 18 reserved layouts (buffer; RGBA8/sRGB, R8, R16F, RGBA16F, RGBA32F; BC1/BC3/BC7; arrays; textures smaller or thinner than a tile; a short mip chain; four volumes).
    • Creation: the three creation entry points, the E_INVALIDARG cases, S_FALSE for a null output, and GetHeapProperties.
    • Copies: a pattern uploaded into a reserved texture and read back; bytes copied into the second tile of a reserved buffer and read back; a never-written reserved texture (Xbox layout) reads zero.
    • Mapping calls: they are accepted.
  • I also checked that the host comparison isn't vacuous: changing the 4-byte tile shape to 128×64 makes it report mismatches straight away.
  • resource_tiling_test (new, CPU-only, runs in CI): the same arithmetic, with expected values taken from the PC runtime.
  • d3d12_com_test and vk_command_replay_test pass under validation. ctest -E loader: 13/13 pass. python -m compileall -q make_game.py tools tests: ok.
  • loader_test was skipped. It hangs and then exits with 0xc0000409 on this machine, on main as well, and builds only from files this PR doesn't touch (see Runtime: query heaps on Vulkan: occlusion, timestamps, pipeline statistics (D3D-15) #278).

AI-assisted (Claude Code).

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

@traeb0n

traeb0n commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 83d0637. Since #241 now reports StandardSwizzle64KBSupported = FALSE, reserved textures with 64KB_STANDARD_SWIZZLE are refused with E_INVALIDARG, as D3D12 does on such a device (test added). TiledResourcesTier is still reported as not supported; I left that for you to decide. Retested on the RTX 5070 (621.01): d3d12_vulkan_device_test passes with 0 validation errors (host GetResourceTiling comparison included), ctest -E loader 13/13.

@CharlyRien

CharlyRien commented Nov 21, 2026 •

Copy link
Copy Markdown

Update: Tested 9087308 on RTX 3090, driver 616.56, Windows 11 23H2: pass. d3d12_vulkan_device_test passes with validation, and so does the host tiling comparison. ctest 15/15, run_gpu_tests.py 30/51 passed, 21 skipped. Tested the head as is, since it conflicts with current main.


Original report:

Tested 878929f (merged on current main) and 1f08173 on RTX 3090, driver 616.56, Windows 11: fail (d3d12_vulkan_device_test, host comparison: cases 2, 6, 8). Everything else passes. Built with MSVC 2022 / Ninja, Vulkan SDK 1.4.363.

What passed (878929f): ctest 16/16. All other D3D12/Vulkan device tests are validation-clean with LEONIDA_VK_VALIDATION=1. run_gpu_tests.py: 32/56 passed, 24 skipped (the wave64 skips on a 32-wide GPU).

The failure:

tiling case 2 creation (1 = ours failed): ours 0 host 1
tiling case 6 creation (1 = ours failed): ours 0 host 1
tiling case 8 creation (1 = ours failed): ours 0 host 1
line 388: tiling_mismatches <= 0

The layer is not the one failing here. The host PC runtime refuses these resources. All three cases are reserved Texture2D arrays with a full mip chain: 1000×300×3 RGBA8 sRGB, 512×512×2 RGBA32F and 2048×1024×2 BC7.

I checked with a small standalone program on the same machine. The host reports TiledResourcesTier = 3, yet CreateReservedResource returns E_INVALIDARG for each of the three. The same arrays are accepted with a short mip chain: case 13 (1024×1024×4, 3 mips) and 512×512×2 with 1 mip both return S_OK. So this driver refuses reserved arrays whose mip chain reaches packed mips, and your RTX 5070 / 621.01 accepts them. The test result depends on which host driver it runs on.

Suggestion: when only the host refuses (ours succeeds), log it and skip that case instead of counting a mismatch, and fail only when ours refuses something the host accepts. Do the same when the host refuses and ours accepts. Whether the layer should accept these at all is a separate question. The Xbox runtime is the reference there, not a given PC driver.

AI-assisted test run and analysis; synthetic tests only, no game files.

traeb0n added a commit to traeb0n/Leonida that referenced this pull request Nov 21, 2026
@CharlyRien found in ItsNotRexed#295 that an RTX 3090 on driver 616.56 (tiled tier 3)
refuses reserved texture arrays whose mips reach the packed tail (cases 2, 6
and 8), which an RTX 5070 on 621.01 accepts; the comparison counted that as a
mismatch. A layout the host refuses is now logged and skipped; one the host
accepts and the layer refuses is still a mismatch; with every layout skipped
the comparison reports itself skipped. The skip path was checked by making
the host refuse one case.

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

traeb0n commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @CharlyRien, that's exactly it, and the suggestion is what I did in 9087308: a layout the host refuses is now logged (GetResourceTiling case N: the host runtime refuses it (0x...), skipped) and skipped; one the host accepts and the layer refuses is still a mismatch; and if every layout is skipped the comparison reports itself skipped rather than passing. I checked the skip path by making the host refuse one case on purpose, since the RTX 5070 accepts all 18. Your 3090 finding is now in docs/d3d12_vulkan.md §4.2. Whether the layer should accept these arrays is left as is (it does, like the 5070's driver) until the console's behaviour is known.

Retested on the RTX 5070 (621.01): d3d12_vulkan_device_test passes with 0 validation errors, ctest -E loader 13/13.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested 9087308 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 15/15 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

The first run had loader fail with SegFault. It isn't from this PR: the PR doesn't touch the loader sources, a clean rebuild passed loader and then 3 more reruns, and the same flake showed up on other PRs and passed when re-run.

No game files used. AI-assisted run (Claude Code).

traeb0n and others added 2 commits November 21, 2026 17:57
CreateReservedResource (and 1 and 2) reserve the whole resource linearly, as
docs/d3d12_vulkan.md section 4.2 plans for the first boot: a committed
resource on a default heap underneath, so every tile is backed and starts
zeroed. D3D12's description rules are kept as measured on the PC runtime
(ROW_MAJOR buffers, 64KB swizzle layouts for textures, a format with a tile
shape; GetHeapProperties is E_INVALIDARG on a reserved resource). The Xbox
tiled layout word 0x101 is accepted as 64KB_UNDEFINED_SWIZZLE.

GetResourceTiling comes from src/resource_tiling.h: the standard 64 KiB tile
shapes, standard and packed mips, per-mip tile counts and the tile order. The
device test compares it with the host PC runtime for 18 buffer, 2D, array,
block-compressed and volume layouts; resource_tiling_test checks the same
arithmetic without a GPU. Packed-mip tile counts are the driver's choice and
are this layer's own rule (tight linear size in whole tiles).

UpdateTileMappings and CopyTileMappings log once and do nothing; what that
loses (aliasing, unmapped tiles keeping data) is written down in section 4.2.

Tested on an RTX 5070 (driver 621.01) under VK_LAYER_KHRONOS_validation.
AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CharlyRien found in ItsNotRexed#295 that an RTX 3090 on driver 616.56 (tiled tier 3)
refuses reserved texture arrays whose mips reach the packed tail (cases 2, 6
and 8), which an RTX 5070 on 621.01 accepts; the comparison counted that as a
mismatch. A layout the host refuses is now logged and skipped; one the host
accepts and the layer refuses is still a mismatch; with every layout skipped
the comparison reports itself skipped. The skip path was checked by making
the host refuse one case.

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

traeb0n commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @CharlyRien for the retest and @kotorvr for testing. Rebased onto 4abd545 (head b4e31e3), over GetResourceAllocationInfo, the texture views and the bindless set. One test-only change: the new resolve-region test signals the fence with 5 and 6, so the reserved-resource copies now wait on 9 (it also stays clear of #278's 7 and 8). Retested on the RTX 5070 (621.01): d3d12_vulkan_device_test passes with 0 validation errors, host tiling comparison included; ctest 20/20.

@traeb0n
traeb0n force-pushed the d3d12-reserved-resources branch from 9087308 to b4e31e3 Compare November 21, 2026 23:57
…value 9

The resolve-region test on main now signals 5 and 6, so a wait on 5 returned
before the copies ran.

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

Copy link
Copy Markdown
Contributor

Tested b4e31e3 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 20/20 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_uint_clear_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

This re-tests the new head (earlier pass: 9087308).

No game files used. AI-assisted run (Claude Code).

@lohant27-netizen

Copy link
Copy Markdown

Tested: PR head b4e31e3 merged onto main 4abd545, ctest 20/20. d3d12_vulkan_device_test reports the reserved resources as matched. Built and run on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11, Vulkan SDK 1.4.363, MSVC 14.44 (VS 2022 Build Tools). All D3D12 GPU tests (d3d12_com_test, d3d12_vulkan_device_test, d3d12_descriptor_test, d3d12_uint_clear_test, vk_command_replay_test) exit 0 with and without LEONIDA_VK_VALIDATION=1, so 0 validation errors. No game files. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 3a928c5 into ItsNotRexed:main Nov 22, 2026
8 checks passed
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.

5 participants