Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5dbc30b
d3d12_xs: device slots 25/26 take the title's C-ABI struct return
sneylol Nov 23, 2026
86b8e04
d3d12_xs: device slot 26 takes the console's struct-return form
sennecools Nov 23, 2026
936675b
d3d12_xs: appendix A.4 names the one claim from the executable; wrap …
sennecools Nov 23, 2026
23e9c95
d3d12_xs: say what is known about slots 25 and 43
sennecools Nov 23, 2026
8897855
d3d12_xs: device slot 25 pads a render target to whole console tiles …
tedin7 Nov 23, 2026
c7ca0f2
d3d12_xs: device slot 25 gives the PC device clean resource descripti…
tedin7 Nov 23, 2026
0d73e8b
Merge origin/main: slot 26 next to the Xbox slot routes
sennecools Nov 23, 2026
824a17f
Merge origin/main into fast-rtbudget
tedin7 Nov 23, 2026
40360cc
Merge #6964 (slot 26 console form) into fast-rtbudget: slot 26 from #…
tedin7 Nov 23, 2026
3593908
d3d12_xs: console render target sizes follow each resource's alignmen…
tedin7 Nov 23, 2026
aeb2537
Merge fast-rtbudget into fast-desc-clean
tedin7 Nov 23, 2026
d7451f9
test: device_proxy_test expects slot 25 to answer for the cleaned des…
tedin7 Nov 23, 2026
b4d1ba1
d3d12: preserve PC descriptor validation in slot 25
TripleJ160 Nov 23, 2026
3ace986
fix: slot 56 gives the same console total when the caller passes no p…
tedin7 Nov 23, 2026
7853964
Merge branch 'fast-rtbudget' into fast-desc-clean
tedin7 Nov 23, 2026
77878e3
Merge pull request #2 from TripleJ160/codex/slot25-pc-validation
tedin7 Nov 23, 2026
4a86034
d3d12_xs: a console depth-stencil texture with unordered access is si…
NiiRoZz Nov 23, 2026
b8cbab6
d3d12: normalize additional console layouts in slot 25
tedin7 Nov 23, 2026
a9c5960
d3d12: strip incompatible UAV flags from Xbox resource descriptions
tedin7 Nov 23, 2026
2f2fb2f
Merge origin/main into fast-desc-clean (docs: GetCustomHeapProperties…
tedin7 Nov 23, 2026
f27f5f0
Merge origin/main into d3d12-xs/ds-uav-standin
NiiRoZz Nov 23, 2026
7c1dc14
Merge #7110's head into d3d12-xs/ds-uav-standin
NiiRoZz Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,23 @@ The trace will enumerate them.
Intel Raptor Lake-S (101.7092) and RTX 5060 Laptop (621.24) hosts wrap, two 2^63 buffers to 0, and WARP on that
PC still saturates. A wrapped total could make a caller allocate less than one of its resources, so the layer
keeps saturating, and the test accepts a host that wraps.
Behind the Xbox-ABI proxy (device slots 25 and 56) a 2D render target of a listed colour format with one sample is
padded to whole console tiles: the size is the sum over its mips (MipLevels 0 is the full chain, an odd extent
rounds up), each mip rounded up to the RDNA2 SW_64KB_D tile shape (`runtime/src/gfx10_tiling.h`: 256 x 128 pixels
for 2-byte elements, 128 x 128 for 4-byte, 128 x 64 for 8-byte, 64 x 64 for 16-byte), with the first mip that fits
in half a tile's width and a whole tile's height, and the mips after it, sharing one tail tile, times the array
size. A 1920 x 1080 RGBA8 target is 135 tiles, 8,847,360 bytes, where the PC answer is 8,323,072. The proxy lays
the descriptions out as the PC device does (each at its own alignment, the total rounded up to the largest
alignment, sums saturating) with each render target at the larger of its console size and its PC size; a 4 MiB
aligned multisampled neighbour therefore keeps its place (a 1 x 1 four-sample target and a 1080p target need 16 MiB,
not 12.5). Slot 56 reports the same offsets. The PC layout stands when no description grows
(`d3d12_xs_alloc_size.h`; `xs_proxy_mock_test`). **Assumption**: the
retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or
CMask memory is open until they are.
The descriptions the title passes to slot 25 carry console values (layout word `0x101`/`0x1`, flag bits above the PC
ones). For console-form calls or descriptors explicitly using layout `0x101`, the proxy strips Xbox-only flags and
translates layout `0x101` to ROW_MAJOR for buffers or UNKNOWN for textures. Other PC-form descriptors reach the host
unchanged for validation (`d3d12_xs_desc_clean.h`; #6982 section 3.7).
- `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI
adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver
621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged.
Expand All @@ -2229,6 +2246,13 @@ The trace will enumerate them.
unknown types and node masks above 1 get an all-zero answer, logged. The test compares `DEFAULT`, `UPLOAD` and
`READBACK` byte for byte with the host runtime's answer when the host adapter has the layer's architecture (RTX
4090: identical); `d3d12_heap_properties` compares the `L1` heaps with the layer's own adapter.
The retail executable calls it (device slot 26) with the buffer for the returned struct in RCX and the device in
RDX, node mask in R8 and heap type in R9: three calls right after device creation, node mask 1 and types 1, 2
and 3 (measured under `gta6rt --run` with a register probe in the slot's thunk). A PC C++ method has the device
in RCX and the buffer in RDX, so the Xbox-ABI proxy takes the console form when RDX holds the proxy
(`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slot 43 returns a struct too and the
proxy still forwards it in the PC form: no call of slot 43 has been seen. Slots 25 and 56 take the same form by the
same rule (reported later in the boot, #6982; not measured), as #6973 first did for slot 25.
- Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in
`d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until
`vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident.
Expand Down Expand Up @@ -4158,8 +4182,9 @@ on a PC device behind the Xbox-ABI proxy). Measured:

- `amd_fidelityfx_loader_xbox.dll`, `Bink2Scarlett.dll`, `libHttpClient.GDK.dll`, `XCurl.dll`: no `d3d12_xs`
imports.
- The package layout XML, chunk 1001, lists `game_scarlett_master.exe`; the file is absent from the folder. No
claim in this document depends on the executable's contents.
- The package layout XML, chunk 1001, lists `game_scarlett_master.exe`; the file is absent from the folder. One
claim in this document comes from running the executable from a player's own copy: how it calls device slot 26
(section 4.1; register roles and argument values only). No other claim depends on the executable's contents.
- The repository's existing import survey (`docs/design.md`, "Baseline already recorded") records that the 16
bundled DLLs need only `xmem` and the two `d3d12_xs` root-signature calls; our scan of the six non-CRT DLLs is
consistent.
Expand Down
4 changes: 3 additions & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ Full-scan indexes are also saved to `%LOCALAPPDATA%\RpfPreview\Indexes`, so the
`CreateCommittedResource` with the Xbox `0x101`/`0x1` layout word replaced by the PC layout. Slots 9/10 are
`ID3D12DescriptorHeap` methods, not device methods. The PC heap getters take a hidden return pointer (RDX),
while Xbox expects the 8-byte handle in RAX, so slot 14 wraps the heap and slots 9/10 convert it. The heap holds
a reference to the device proxy and its `GetDevice` returns that same proxy. Queues, fences, command lists and
a reference to the device proxy and its `GetDevice` returns that same proxy. The retail executable calls the
struct-returning device methods with the C ABI, return buffer first: `GetCustomHeapProperties` (slot 26) is
measured as `rcx` = buffer, `rdx` = device. Slots 25 and 26 take that form, and still take the PC one. Queues, fences, command lists and
`PresentX` extensions remain unimplemented.
- PSO metadata is a new variant (`PSIN`, `LSCH` schema, `LENM`, `LSNS`, `LGID`, `LRSC`, `CHKS`, little-endian).
CodeWalker's parser reads the container but not the new schema; dump it once the exe gives the field names.
Expand Down
156 changes: 156 additions & 0 deletions runtime/shims/d3d12_xs_alloc_size.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Console allocation sizes for render targets, for the Xbox-ABI device proxy's slots 25 and 56 (GetResourceAllocationInfo and GetResourceAllocationInfo1).
//
// Why: the retail title checks a fixed memory budget against what its first full-screen render targets used and asserts
// when more than 2 MiB is left over (docs/retail_boot_chain.md, stop 17, #6982). The PC device sizes a 2D render target
// from the Vulkan driver's memory requirements, which is about width x height x element bytes. The console lays a
// render target out in 64 KiB tiles (the RDNA2 SW_64KB layouts), so its allocation is the surface padded to whole
// tiles: for 4-byte elements a tile is 128 x 128 pixels, and 1080 rows take nine tile rows, not 8.4. The PC size is
// smaller by that padding, summed over every full-screen target.
//
// What this is: the tile shapes are the RDNA2 SW_64KB_D shapes of runtime/src/gfx10_tiling.h (Mesa addrlib patterns,
// validated against real textures in docs/textures.md). That a console render target uses these shapes and no extra
// (DCC, CMask) memory in its allocation size is an assumption: the title's own sizes are not measured. The rule only
// ever makes a size larger than the PC device's own answer, never smaller. The mip tail follows AMD's addrlib
// (gfx10, 2D): a mip extent is rounded up (ShiftCeil), and the tail starts at the first mip that fits in half a tile's
// width and a whole tile's height; the tail is one tile.
#pragma once

#include "../src/gfx10_tiling.h"

#include <windows.h>
#include <d3d12.h>

#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>

namespace rt::d3d12_xs {

constexpr UINT64 kConsoleTileBytes = 64 * 1024; // one SW_64KB tile

// Bytes per element of the colour formats a render target takes, or 0 for any other format (the PC size then stays).
inline std::size_t render_target_element_bytes(DXGI_FORMAT format) {
switch (format) {
case DXGI_FORMAT_R8_TYPELESS: case DXGI_FORMAT_R8_UNORM: case DXGI_FORMAT_R8_UINT:
case DXGI_FORMAT_R8_SNORM: case DXGI_FORMAT_R8_SINT: case DXGI_FORMAT_A8_UNORM:
return 1;
case DXGI_FORMAT_R8G8_TYPELESS: case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8G8_UINT:
case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8G8_SINT: case DXGI_FORMAT_R16_TYPELESS:
case DXGI_FORMAT_R16_FLOAT: case DXGI_FORMAT_R16_UNORM: case DXGI_FORMAT_R16_UINT:
case DXGI_FORMAT_R16_SNORM: case DXGI_FORMAT_R16_SINT: case DXGI_FORMAT_B5G6R5_UNORM:
case DXGI_FORMAT_B5G5R5A1_UNORM:
return 2;
case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R11G11B10_FLOAT:
case DXGI_FORMAT_R8G8B8A8_TYPELESS: case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: case DXGI_FORMAT_R8G8B8A8_UINT:
case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8B8A8_SINT:
case DXGI_FORMAT_B8G8R8A8_TYPELESS: case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8X8_TYPELESS:
case DXGI_FORMAT_B8G8R8X8_UNORM: case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
case DXGI_FORMAT_R16G16_TYPELESS: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16G16_UNORM:
case DXGI_FORMAT_R16G16_UINT: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16G16_SINT:
case DXGI_FORMAT_R32_TYPELESS: case DXGI_FORMAT_R32_FLOAT: case DXGI_FORMAT_R32_UINT:
case DXGI_FORMAT_R32_SINT:
return 4;
case DXGI_FORMAT_R16G16B16A16_TYPELESS: case DXGI_FORMAT_R16G16B16A16_FLOAT:
case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16B16A16_UINT:
case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16B16A16_SINT:
case DXGI_FORMAT_R32G32_TYPELESS: case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32G32_UINT:
case DXGI_FORMAT_R32G32_SINT:
return 8;
case DXGI_FORMAT_R32G32B32A32_TYPELESS: case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R32G32B32A32_UINT: case DXGI_FORMAT_R32G32B32A32_SINT:
return 16;
default:
return 0;
}
}

// The console's allocation size for a single-sampled 2D render target, or 0 when the rule does not apply (not a 2D
// texture, not a render target, more than one sample, an unlisted format, an empty extent, or a size that overflows).
// MipLevels 0 is the full chain, as on the PC device. A mip extent is rounded up. Mips before the tail are padded to
// whole tiles; the first mip that fits in half a tile's width and the whole tile height, and every mip after it, share
// one tail tile. Slices add up.
inline UINT64 console_render_target_size(const D3D12_RESOURCE_DESC& desc) {
if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return 0;
if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)) return 0;
if (desc.SampleDesc.Count > 1) return 0;
const std::size_t element_bytes = render_target_element_bytes(desc.Format);
if (!element_bytes || !desc.Width || !desc.Height || !desc.DepthOrArraySize) return 0;

const UINT full_chain = static_cast<UINT>(std::bit_width(std::max<UINT64>(desc.Width, desc.Height)));
const UINT mips = desc.MipLevels ? std::min<UINT>(desc.MipLevels, full_chain) : full_chain;
UINT64 slice = 0;
bool tail = false;
for (UINT mip = 0; mip < mips; ++mip) {
const UINT64 width = std::max<UINT64>((desc.Width + (UINT64{1} << mip) - 1) >> mip, 1);
const UINT64 height = std::max<UINT64>((UINT64{desc.Height} + (UINT64{1} << mip) - 1) >> mip, 1);
leonida::gfx10::TiledSurface2D surface;
if (width > UINT32_MAX ||
!leonida::gfx10::TiledSurface2D::make(leonida::gfx10::TileMode::sw_64kb_d, element_bytes,
static_cast<std::size_t>(width), static_cast<std::size_t>(height),
surface))
return 0;
if (width <= surface.tile_width() / 2 && height <= surface.tile_height()) {
tail = true;
break;
}
slice += surface.tiled_size();
}
if (tail) slice += kConsoleTileBytes;
const UINT64 slices = desc.DepthOrArraySize;
if (slice > UINT64_MAX / slices) return 0;
return slice * slices;
}

// Rounds up to a multiple of `to`, stopping at the last multiple below 2^64 instead of wrapping (as the PC device's
// totals do).
inline UINT64 align_up_saturating(UINT64 value, UINT64 to) {
return value > UINT64_MAX - (to - 1) ? UINT64_MAX / to * to : (value + to - 1) / to * to;
}

// Lays the descriptions out as the PC device does (one after another, each at its own alignment, the total rounded up
// to the largest alignment), with a render target's size taken as its console size when that is larger than the PC
// size. pc_one(i) is the PC device's answer for description i alone. Sizes are rounded to each description's own
// alignment, so a multisampled neighbour at 4 MiB keeps its place, and sums saturate instead of wrapping. When
// `each` is given it receives every description's offset, alignment and size.
//
// Returns false, and writes nothing, when no description is a console render target that grows, or when the PC
// device refuses one: the PC answer then stands. A true answer is never below what the PC device gave for the same
// descriptions laid out in that way.
template <class PcOne>
bool console_placement(const D3D12_RESOURCE_DESC* descs, UINT count, PcOne pc_one,
D3D12_RESOURCE_ALLOCATION_INFO& total, D3D12_RESOURCE_ALLOCATION_INFO1* each) {
if (!descs) return false;
bool any_target = false;
for (UINT i = 0; i < count && !any_target; ++i) any_target = console_render_target_size(descs[i]) != 0;
if (!any_target) return false;
// Two passes when `each` is wanted: the first decides, the second writes, so a refusal or a list that does not
// grow leaves the array as the PC device filled it.
for (const bool write : {false, true}) {
if (write && !each) break;
bool grows = false;
UINT64 end = 0, alignment = 1;
for (UINT i = 0; i < count; ++i) {
const D3D12_RESOURCE_ALLOCATION_INFO one = pc_one(i);
if (one.SizeInBytes == UINT64_MAX || !one.Alignment) return false;
UINT64 size = one.SizeInBytes;
const UINT64 console = console_render_target_size(descs[i]);
if (console > size) {
size = align_up_saturating(console, one.Alignment);
grows = true;
}
const UINT64 offset = align_up_saturating(end, one.Alignment);
if (write) each[i] = {offset, one.Alignment, size};
end = size > UINT64_MAX - offset ? UINT64_MAX : offset + size;
alignment = std::max(alignment, one.Alignment);
}
if (!grows) return false;
total = {align_up_saturating(end, alignment), alignment};
}
return true;
}

} // namespace rt::d3d12_xs
73 changes: 73 additions & 0 deletions runtime/shims/d3d12_xs_desc_clean.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// The PC form of a resource description the retail title builds for the console, for the Xbox-ABI device proxy.
//
// The title's D3D12_RESOURCE_DESC carries console layout words and flag bits the PC device cannot take
// (docs/retail_boot_chain.md, #6982). The slot 25 cleaner returns a copy of the title's description.
#pragma once

#include <windows.h>
#include <d3d12.h>

#include <cstdint>

namespace rt::d3d12_xs {

// The D3D12_RESOURCE_FLAGS bits the PC runtime defines; every other bit is a console one.
constexpr std::uint32_t kPcResourceFlagsMask =
D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL |
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE |
D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS |
D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY |
D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE;

inline const auto kXboxTiledResourceLayout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);

// The console allows a depth-stencil texture to allow unordered access too (measured locally at a title's call sites:
// a 2D R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, sized through slot 25), but the PC
// runtime refuses that pair, and Vulkan has no depth format with storage support to make it with. Stand-in: such a
// texture is a depth-stencil texture without unordered access (slot 76 through this; slot 25 through
// pc_resource_desc). Its unordered-access views write no descriptor (the PC layer refuses a UAV of a texture without
// the flag), so what a shader writes through them goes nowhere and their reads see whatever the descriptor held.
inline std::uint32_t without_depth_stencil_uav(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t flags) {
if (dimension != D3D12_RESOURCE_DIMENSION_BUFFER && (flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL))
flags &= ~static_cast<std::uint32_t>(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
return flags;
}

inline bool is_depth_resource_format(DXGI_FORMAT format) {
switch (format) {
case DXGI_FORMAT_D16_UNORM:
case DXGI_FORMAT_D24_UNORM_S8_UINT:
case DXGI_FORMAT_D32_FLOAT:
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
case DXGI_FORMAT_R16_TYPELESS:
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_R32_TYPELESS:
case DXGI_FORMAT_R32G8X24_TYPELESS:
return true;
default:
return false;
}
}

// Strip Xbox-only flags and preserve the three supported PC layouts. In addition to 0x101, zebraso measured
// layout words 0x102 and 0x105 reaching slot 25 during a retail boot.
inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) {
D3D12_RESOURCE_DESC pc = xbox;
if (pc.Layout != D3D12_TEXTURE_LAYOUT_UNKNOWN &&
pc.Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR &&
pc.Layout != D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE) {
pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR
: D3D12_TEXTURE_LAYOUT_UNKNOWN;
}
std::uint32_t flags = static_cast<std::uint32_t>(xbox.Flags) & kPcResourceFlagsMask;
// zebraso measured slot 25 rejecting B5G5R5A1 render targets with UAV on an RTX 5080 without
// storage-image support for that format. Depth-stencil resources also cannot be UAVs on PC.
if (pc.Format == DXGI_FORMAT_B5G5R5A1_UNORM ||
((flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) && is_depth_resource_format(pc.Format))) {
flags &= ~static_cast<std::uint32_t>(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
}
pc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(flags);
return pc;
}

} // namespace rt::d3d12_xs
Loading
Loading