From 82e991f98e2cab9bc6b2995efee0f32a3c2b1750 Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Tue, 24 Nov 2026 23:05:32 +0100 Subject: [PATCH 1/2] Loader: committed textures take their console size from the title's memory The game hands its two 3840x2160 render targets a 64 MiB region through its XMemAlloc hook and breaks at 0x1456a2afd when they overrun it. The shim sized that allocation with the desktop driver's answer, which an RDNA3 card pads to 0x2010000 bytes per target. Textures now take their XG console size (0x1fe0000 for those targets); buffers keep the desktop size. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru --- docs/d3d12x-shim.md | 6 +++-- .../Shims/D3D12X/ConsoleAllocationSizes.cs | 22 ++++++++++++++++++ .../Shims/D3D12X/XboxCommittedResources.cs | 18 ++++++++++++--- .../ConsoleAllocationSizesTests.cs | 23 +++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/docs/d3d12x-shim.md b/docs/d3d12x-shim.md index 751af5ac..be13ed52 100644 --- a/docs/d3d12x-shim.md +++ b/docs/d3d12x-shim.md @@ -408,8 +408,10 @@ in a boot split; the elements past a cut read 0 until such a buffer is one deskt **Committed resources (slot 127).** Created in the state of the initial barrier layout (buffers COMMON), heap flags 0 (the game passes 8). On the console D3D12.X takes their memory from the title's XMemAlloc hook, and the game checks it: around its two 4K render targets (0x14247ad10) it pushes a hook for D3D allocations with page-size field 2 that -hands out a 64 MiB region, and breaks into the debugger unless all but 2 MiB of it was used. The shim allocates the -desktop size with attributes 0x11808000 (allocator 128, page size 2, 64 KiB alignment) and frees it with the resource. +hands out a 64 MiB region, and breaks into the debugger unless all but 2 MiB of it was used. The shim allocates a +texture's XG console size (a desktop driver pads: an RDNA3 card asks 0x2010000 bytes per 4K target, and two overrun the +region) and a buffer's desktop size, with attributes 0x11808000 (allocator 128, page size 2, 64 KiB alignment), and +frees it with the resource. **Root signatures.** `D3D12SerializeVersionedRootSignature` drops the flag bits above 0xFFF (`XboxBvhBuilder.dll` passes 0x3000000) and logs the serializer's message when it still fails. diff --git a/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs b/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs index 7a83f192..dcefdb11 100644 --- a/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs +++ b/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs @@ -19,6 +19,9 @@ internal static unsafe class ConsoleAllocationSizes /// ALLOW_RENDER_TARGET, ALLOW_DEPTH_STENCIL and ALLOW_UNORDERED_ACCESS. private const int TargetFlags = 0x7; + /// DXGI_SAMPLE_DESC.Count of a texture that is not multisampled. + private const uint SingleSample = 1; + /// /// Replaces (and , when given) with the console sizes when every /// desc is a texture in a console layout; false, leaving them as they are, otherwise. @@ -53,6 +56,25 @@ public static bool TryApply(ResourceDescription* descriptions, uint count, Resou return true; } + /// + /// The console size of a texture the game creates committed, render and depth targets included (XG lays those out + /// with the mode it suggests); false for buffers and multisampled textures, which keep the desktop size. + /// + public static bool TryCommittedTextureSize(ResourceDescription* description, out ulong size) + { + size = 0; + + if (description->Dimension == ResourceDescription.BufferDimension || description->SampleCount > SingleSample) + { + return false; + } + + XgLayoutBuilder.Build(*(XgResourceDesc*)description, out var surface); + size = surface.Size; + + return true; + } + /// /// Whether a desc is a texture the console lays out with XG: its layout field carries a swizzle mode, or it is /// UNKNOWN on a texture that is neither render target, depth target nor UAV (XG suggests the mode; the game sizes diff --git a/src/FiveStar.Loader/Shims/D3D12X/XboxCommittedResources.cs b/src/FiveStar.Loader/Shims/D3D12X/XboxCommittedResources.cs index 81ac906b..2a547084 100644 --- a/src/FiveStar.Loader/Shims/D3D12X/XboxCommittedResources.cs +++ b/src/FiveStar.Loader/Shims/D3D12X/XboxCommittedResources.cs @@ -13,8 +13,10 @@ namespace FiveStar.Loader.Shims.D3D12X; /// Device slot 127, the committed resources. On the console D3D12.X takes their memory from the title's XMemAlloc /// hook, and the game counts on it: around its render targets (0x14247ad10) it pushes a hook that hands out a 64 MiB /// region for D3D allocations with page-size field 2, then breaks into the debugger unless all but 2 MiB of it went -/// to the resources. The shim makes the same allocation, of the desktop resource's size, and frees it with the -/// resource; the desktop resource itself lives in desktop memory. +/// to the resources. The shim makes the same allocation, of the console's size for a texture (a desktop driver adds +/// metadata of its own: 0x2010000 bytes for a 3840x2160 RGBA8 target on an RDNA3 card, and two of those overrun the +/// region) and of the desktop size for a buffer, and frees it with the resource; the desktop resource itself lives in +/// desktop memory. /// internal sealed unsafe class XboxCommittedResources { @@ -68,7 +70,7 @@ public int Create(nint device, void* properties, int heapFlags, ResourceDescript if (!HResult.Failed(hr) && resource != null && *resource != 0) { var wrapper = (XboxResourceObject*)*resource; - wrapper->TitleMemory = _hooks.Allocate((nuint)AllocationSize(device, &desktop), ResourceAttributes); + wrapper->TitleMemory = _hooks.Allocate((nuint)TitleAllocationSize(device, description, &desktop), ResourceAttributes); ResourceStates.Record(wrapper, desktop.Dimension, state, desktop.Flags); } @@ -110,6 +112,16 @@ public static uint ReleaseResource(XboxResourceObject* self) } } + private static ulong TitleAllocationSize(nint device, ResourceDescription* console, ResourceDescription* desktop) + { + if (ConsoleAllocationSizes.TryCommittedTextureSize(console, out ulong size)) + { + return size; + } + + return AllocationSize(device, desktop); + } + private static ulong AllocationSize(nint device, ResourceDescription* description) { ResourceAllocationInfo info; diff --git a/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs b/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs index 8b3e4b2d..2a30c3eb 100644 --- a/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs +++ b/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs @@ -15,6 +15,13 @@ public sealed unsafe class ConsoleAllocationSizesTests private const int Rgba16Unorm = 11; private const int ConsoleFlags = 0x300000; private const int AllowRenderTarget = 1; + private const int Rgba8Unorm = 28; + private const ulong RenderTargetRegion = 64ul << 20; + private const ulong RegionSlack = 2ul << 20; + + /// A 64 KiB block holds 128x128 four-byte elements (docs/xg.md); 3840x2160 takes 30 x 17 of them. + private const ulong LargeBlockBytes = 0x10000; + private const ulong Blocks4kTarget = 30 * 17; [Fact] public void A_console_layout_texture_gets_its_xg_size_and_a_buffer_keeps_the_desktop_answer() @@ -48,4 +55,20 @@ public void A_streamed_texture_without_a_layout_gets_the_suggested_4_kb_blocks() desc.Flags |= AllowRenderTarget; Assert.False(ConsoleAllocationSizes.TryApply(&desc, 1, &result, null)); } + + [Fact] + public void Two_4k_render_targets_fill_the_region_the_game_hands_out_for_them() + { + // 0x14247ad10 creates two 3840x2160 RGBA8 targets from a 64 MiB region and breaks unless they fill all but + // 2 MiB of it; an RDNA3 desktop driver asks 0x2010000 bytes for each, which overruns it. + + var desc = new ResourceDescription { Dimension = Texture2D, Width = 3840, Height = 2160, DepthOrArraySize = 1, MipLevels = 1, Format = Rgba8Unorm, SampleCount = 1, Flags = ConsoleFlags | AllowRenderTarget }; + + Assert.True(ConsoleAllocationSizes.TryCommittedTextureSize(&desc, out ulong size)); + Assert.Equal(Blocks4kTarget * LargeBlockBytes, size); + Assert.InRange(2 * size, RenderTargetRegion - RegionSlack, RenderTargetRegion); + + desc.Dimension = ResourceDescription.BufferDimension; + Assert.False(ConsoleAllocationSizes.TryCommittedTextureSize(&desc, out _)); + } } From a5e1f25bdc992f84b002a3b0569df5a373dc1d00 Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Wed, 25 Nov 2026 03:04:30 +0100 Subject: [PATCH 2/2] Loader: render, depth and UAV textures take their XG size in allocation info Slot 108 now answers XG's size for single-sample render targets, depth targets and UAV textures without a layout, as for console-layout textures. The game places them in its 2.2 GiB graphics heap at that size (0x140abfad0) while the shim backs them with desktop textures of their own, so the desktop size only took heap: an RX 7800 XT adds its compression metadata (0x1330000 bytes for a 2560x1440 D16S8 depth target where XG gives 0xb40000). With the desktop sizes the heap held 2050 MB of 2199 MB after boot and the story load stopped on a 46 MiB request in the allocator's fatal path (0x142219650). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru --- docs/d3d12x-shim.md | 7 ++++- .../Shims/D3D12X/ConsoleAllocationSizes.cs | 26 ++++++++++++++++--- .../ConsoleAllocationSizesTests.cs | 22 ++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/docs/d3d12x-shim.md b/docs/d3d12x-shim.md index be13ed52..698b04b8 100644 --- a/docs/d3d12x-shim.md +++ b/docs/d3d12x-shim.md @@ -324,7 +324,12 @@ B5G6R5, B5G5R5A1 or B4G4R4A4 take a substitute format; see [gpu-resources.md](gp **Allocation info (slots 25, 108).** A texture desc in a console layout (0x100 + swizzle mode), or with layout UNKNOWN and none of ALLOW_RENDER_TARGET, ALLOW_DEPTH_STENCIL, ALLOW_UNORDERED_ACCESS, gets the XG layout's size and alignment ([xg.md](xg.md); UNKNOWN takes the suggested mode), as the console reports it, not the desktop driver's -(`ConsoleAllocationSizes`; other descs, or a query mixing them, keep the desktop answer). The game sizes streamed +(`ConsoleAllocationSizes`). So does a single-sample render target, depth target or UAV texture with layout UNKNOWN: +the game places those in its 2.2 GiB graphics heap at the size slot 108 answers (0x140abfad0), while the shim backs +them with desktop textures of their own. AMD's driver (RX 7800 XT) adds its compression metadata, 0x1330000 bytes for +a 2560x1440 depth target where XG gives 0xb40000; with the desktop sizes the heap held 2050 MB of its 2199 MB after +boot and the story load stopped on a 46 MiB request (the allocator's fatal path, 0x142219650). Buffers, multisampled +textures, or a query mixing them keep the desktop answer. The game sizes streamed textures without size fields in their header this way (0x1451fb8f3 through 0x140343e80, desc built without a layout), stores the size in 4 KiB units in its streaming table (0x149c3e1d0, 0x38-byte entries, words +0x18 offsets and +0x20 sizes) and reads exactly that many bytes from the archive (0x1443c4850); the archive's compressed chunks diff --git a/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs b/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs index dcefdb11..73639b6b 100644 --- a/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs +++ b/src/FiveStar.Loader/Shims/D3D12X/ConsoleAllocationSizes.cs @@ -24,11 +24,12 @@ internal static unsafe class ConsoleAllocationSizes /// /// Replaces (and , when given) with the console sizes when every - /// desc is a texture in a console layout; false, leaving them as they are, otherwise. + /// desc is a texture the console sizes with XG (); false, leaving them as they are, + /// otherwise. /// public static bool TryApply(ResourceDescription* descriptions, uint count, ResourceAllocationInfo* result, ResourceAllocationInfo1* infos) { - if (count == 0 || !AllConsoleTextures(descriptions, count)) + if (count == 0 || !AllConsoleSized(descriptions, count)) { return false; } @@ -90,11 +91,28 @@ public static bool IsConsoleTexture(in ResourceDescription description) return (uint)description.Layout >= XgSwizzleModes.ModeBase || (description.Layout == UnknownLayout && (description.Flags & TargetFlags) == 0); } - private static bool AllConsoleTextures(ResourceDescription* descriptions, uint count) + /// + /// Whether the console reports XG's size for a desc: a texture in a console layout, or a single-sample render + /// target, depth target or UAV texture without a layout. The game places those in its 2.2 GiB graphics heap at the + /// size slot 108 answers (0x140abfad0), while the shim backs them with desktop textures of their own, so the + /// desktop driver's size only takes heap: AMD's (RX 7800 XT) adds its compression metadata, 0x1330000 bytes for a + /// 2560x1440 depth target where XG gives 0xb40000, and the story load ran the heap out at a 46 MiB request. + /// + public static bool IsConsoleSized(in ResourceDescription description) + { + if (IsConsoleTexture(description)) + { + return true; + } + + return description.Dimension != ResourceDescription.BufferDimension && description.Layout == UnknownLayout && description.SampleCount <= SingleSample; + } + + private static bool AllConsoleSized(ResourceDescription* descriptions, uint count) { for (uint i = 0; i < count; i++) { - if (!IsConsoleTexture(descriptions[i])) + if (!IsConsoleSized(descriptions[i])) { return false; } diff --git a/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs b/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs index 2a30c3eb..985313a0 100644 --- a/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs +++ b/tests/FiveStar.Loader.Tests/ConsoleAllocationSizesTests.cs @@ -15,6 +15,11 @@ public sealed unsafe class ConsoleAllocationSizesTests private const int Rgba16Unorm = 11; private const int ConsoleFlags = 0x300000; private const int AllowRenderTarget = 1; + private const int AllowDepthStencil = 2; + private const int AllowUnorderedAccess = 4; + private const int D16S8 = 118; + private const uint Msaa4 = 4; + private const ulong DepthTargetXgBytes = 0xb40000; private const int Rgba8Unorm = 28; private const ulong RenderTargetRegion = 64ul << 20; private const ulong RegionSlack = 2ul << 20; @@ -53,9 +58,26 @@ public void A_streamed_texture_without_a_layout_gets_the_suggested_4_kb_blocks() Assert.Equal(0x4000ul, result.Size); desc.Flags |= AllowRenderTarget; + Assert.True(ConsoleAllocationSizes.TryApply(&desc, 1, &result, null)); + Assert.True(ConsoleAllocationSizes.TryCommittedTextureSize(&desc, out ulong targetSize)); + Assert.Equal(targetSize, result.Size); + + desc.SampleCount = Msaa4; Assert.False(ConsoleAllocationSizes.TryApply(&desc, 1, &result, null)); } + [Fact] + public void A_depth_target_gets_its_xg_size_and_not_the_desktop_metadata() + { + // The 2560x1440 D16S8 depth targets the game places in its graphics heap: an RX 7800 XT answers 0x1330000 + // bytes, XG 0xb40000 (the heap ran out at the story load with the desktop sizes). + var desc = new ResourceDescription { Dimension = Texture2D, Width = 2560, Height = 1440, DepthOrArraySize = 1, MipLevels = 1, Format = D16S8, SampleCount = 1, Flags = ConsoleFlags | AllowDepthStencil | AllowUnorderedAccess }; + ResourceAllocationInfo result = default; + + Assert.True(ConsoleAllocationSizes.TryApply(&desc, 1, &result, null)); + Assert.Equal(DepthTargetXgBytes, result.Size); + } + [Fact] public void Two_4k_render_targets_fill_the_region_the_game_hands_out_for_them() {