upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/device_proxy_test.cpp
diff options
context:
space:
mode:
authorMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-24 11:42:12 -0600
committerMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-24 11:42:12 -0600
commit273b3bdf9d6e736442ad584ad464df6e86ee928b (patch)
tree3886a0af7c74ffa7d9415d662d8dc0fb708f1c08 /runtime/test/device_proxy_test.cpp
parentece4ba5b31ebc6f345c8e29eae1261f2f780057a (diff)
[integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
One squashed commit of a fork that was developed on a Linux/Proton machine and tested on two native Windows machines. On all of them the retail 1.0.2.1 package now launches, shows its launch movie, first-run pages and landing prompt, runs the story load to its end with the loading slideshow drawing its artwork, and enters the world phase. A first world frame is not verified yet. docs/linux_proton.md has the setup, a healthy boot's timeline, the machines and where it stops. Runtime: frames in the title's own window; DirectStorage pinned reads, page-list scatter/gather, BCPack and unshuffle with a locally generated predictor file; pooled, device-local and deferred image backing for streamed and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table that degrades instead of refusing a submission; a descriptor hash finalizer (off until a library carries it); directly indexed heap offsets for compute dispatches and VS/PS/GS draws; title buffer windows outside a fragmented arena; opt-in device-local copies of streamed buffer views; write-fault retries under the tracker lock, shared trackers and write-watched title memory for native Windows; device-loss, compute-input and memory probes. Translator: loop bounds at structured exits, the eight FidelityFX programs that use a packed-dot form the disassembler skips, buffer bounds modes per view kind, a compaction option, the hash finalizer option. Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows boot script, the paired compute translation script. No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted by people on the machines named in docs/linux_proton.md. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
-rw-r--r--runtime/test/device_proxy_test.cpp820
1 files changed, 817 insertions, 3 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 46a853e7c..5ff4b4da3 100644
--- a/runtime/test/device_proxy_test.cpp
+++ b/runtime/test/device_proxy_test.cpp
@@ -3,6 +3,7 @@
3// It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox 3// It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox
4// slots exactly as the guest would (raw function pointers, not the C++ interface): 4// slots exactly as the guest would (raw function pointers, not the C++ interface):
5// slot 14 CreateDescriptorHeap (returns a heap proxy) 5// slot 14 CreateDescriptorHeap (returns a heap proxy)
6// slot 25/26 GetResourceAllocationInfo/GetCustomHeapProperties in the title's C form (return buffer first)
6// heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the 7// heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the
7// hidden return pointer in RDX, so slot 14 wraps it) 8// hidden return pointer in RDX, so slot 14 wraps it)
8// slot 62 CreateComputePipelineState 9// slot 62 CreateComputePipelineState
@@ -10,11 +11,13 @@
10// slot 8/36 CreateCommandQueue/CreateFence (return queue and fence proxies that run GPU work) 11// slot 8/36 CreateCommandQueue/CreateFence (return queue and fence proxies that run GPU work)
11// Slot 9 on the device is CreateCommandAllocator on the PC vtable and must still forward, which proves the handle 12// Slot 9 on the device is CreateCommandAllocator on the PC vtable and must still forward, which proves the handle
12// getters were not wedged into the device slots. Console output also shows the proxy's first-call slot log. 13// getters were not wedged into the device slots. Console output also shows the proxy's first-call slot log.
14#include <vector>
13#include <windows.h> 15#include <windows.h>
14#include <d3d12.h> 16#include <d3d12.h>
15#include <d3dcompiler.h> 17#include <d3dcompiler.h>
16#include <dxgi1_4.h> 18#include <dxgi1_4.h>
17 19
20#include <cmath>
18#include <cstdint> 21#include <cstdint>
19#include <cstdio> 22#include <cstdio>
20#include <cstring> 23#include <cstring>
@@ -22,8 +25,14 @@
22#include <wrl/client.h> 25#include <wrl/client.h>
23 26
24#include "d3d12_trace.h" 27#include "d3d12_trace.h"
28#include "d3d12_xs_desc_clean.h"
25#include "d3d12_xs_device.h" 29#include "d3d12_xs_device.h"
26#include "shims.h" 30#include "shims.h"
31#include "../src/frame_pacer.h"
32#include "../src/shader_library.h"
33
34#include <filesystem>
35#include <fstream>
27 36
28namespace { 37namespace {
29 38
@@ -106,6 +115,190 @@ bool load_compute_shader(ComPtr<ID3DBlob>& bytecode) {
106 return SUCCEEDED(hr) && bytecode; 115 return SUCCEEDED(hr) && bytecode;
107} 116}
108 117
118// ---- Slot 55 (CreateDerivedPipelineState) ----
119
120constexpr std::size_t kRecordBytes = 0x14c;
121
122// One record: u32 tag, then the payload at +4 (d3d12_xs_pso_stream.h).
123void put_record(unsigned char* record, std::uint32_t tag, const void* payload, std::size_t size) {
124 std::memset(record, 0, kRecordBytes);
125 std::memcpy(record, &tag, sizeof(tag));
126 if (size) std::memcpy(record + 4, payload, size);
127}
128
129std::size_t align_up(std::size_t value, std::size_t align) { return (value + align - 1) / align * align; }
130
131// A stream written in the console's layout: u32 type, payload at its alignment, next entry 8-aligned.
132struct StreamBytes {
133 std::vector<unsigned char> bytes;
134 void add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type, const void* payload, std::size_t size, std::size_t align) {
135 const std::size_t at = bytes.size();
136 bytes.resize(at + 4);
137 const std::uint32_t t = type;
138 std::memcpy(bytes.data() + at, &t, sizeof(t));
139 bytes.resize(align_up(at + 4, align), 0);
140 const auto* p = static_cast<const unsigned char*>(payload);
141 bytes.insert(bytes.end(), p, p + size);
142 bytes.resize(align_up(bytes.size(), 8), 0);
143 }
144};
145
146bool compile_hlsl(const char* source, const char* target, ComPtr<ID3DBlob>& bytecode) {
147 HMODULE compiler = LoadLibraryExA("d3dcompiler_47.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
148 auto compile = compiler ? reinterpret_cast<pD3DCompile>(GetProcAddress(compiler, "D3DCompile")) : nullptr;
149 if (!compile) return false;
150 ComPtr<ID3DBlob> errors;
151 const HRESULT hr = compile(source, std::strlen(source), "device_proxy_slot55.hlsl", nullptr, nullptr, "main",
152 target, D3DCOMPILE_ENABLE_STRICTNESS, 0, bytecode.GetAddressOf(),
153 errors.GetAddressOf());
154 if (FAILED(hr) && errors) std::printf("shader compile error: %s\n", static_cast<const char*>(errors->GetBufferPointer()));
155 return SUCCEEDED(hr) && bytecode;
156}
157
158// Graphics stream with every state a derived record can patch: DEPTH_STENCIL1, RASTERIZER, BLEND, SAMPLE_MASK.
159std::vector<unsigned char> graphics_stream(ID3D12RootSignature* root, ID3DBlob* vs, ID3DBlob* ps) {
160 StreamBytes s;
161 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, &root, sizeof(root), alignof(void*));
162 const D3D12_SHADER_BYTECODE vs_code{vs->GetBufferPointer(), vs->GetBufferSize()};
163 const D3D12_SHADER_BYTECODE ps_code{ps->GetBufferPointer(), ps->GetBufferSize()};
164 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, &vs_code, sizeof(vs_code), alignof(void*));
165 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, &ps_code, sizeof(ps_code), alignof(void*));
166 D3D12_RT_FORMAT_ARRAY rt{};
167 rt.RTFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
168 rt.NumRenderTargets = 1;
169 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS, &rt, sizeof(rt), 4);
170 const DXGI_FORMAT dsv = DXGI_FORMAT_UNKNOWN;
171 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, &dsv, sizeof(dsv), 4);
172 const DXGI_SAMPLE_DESC sample{1, 0};
173 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC, &sample, sizeof(sample), 4);
174 const D3D12_PRIMITIVE_TOPOLOGY_TYPE topology = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
175 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY, &topology, sizeof(topology), 4);
176
177 D3D12_BLEND_DESC blend{};
178 for (auto& rtb : blend.RenderTarget) {
179 rtb.SrcBlend = rtb.SrcBlendAlpha = D3D12_BLEND_ONE;
180 rtb.DestBlend = rtb.DestBlendAlpha = D3D12_BLEND_ZERO;
181 rtb.BlendOp = rtb.BlendOpAlpha = D3D12_BLEND_OP_ADD;
182 rtb.LogicOp = D3D12_LOGIC_OP_NOOP;
183 rtb.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
184 }
185 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND, &blend, sizeof(blend), 4);
186 const UINT mask = 0xffffffffu;
187 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK, &mask, sizeof(mask), 4);
188 D3D12_RASTERIZER_DESC raster{};
189 raster.FillMode = D3D12_FILL_MODE_SOLID;
190 raster.CullMode = D3D12_CULL_MODE_BACK;
191 raster.DepthClipEnable = TRUE;
192 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER, &raster, sizeof(raster), 4);
193 D3D12_DEPTH_STENCIL_DESC1 ds{};
194 ds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
195 ds.DepthFunc = D3D12_COMPARISON_FUNC_LESS;
196 ds.StencilReadMask = ds.StencilWriteMask = 0xff;
197 for (D3D12_DEPTH_STENCILOP_DESC* op : {&ds.FrontFace, &ds.BackFace}) {
198 op->StencilFailOp = op->StencilDepthFailOp = op->StencilPassOp = D3D12_STENCIL_OP_KEEP;
199 op->StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
200 }
201 s.add(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, &ds, sizeof(ds), 4);
202 return s.bytes;
203}
204
205void check_derived_states(ID3D12Device* device, void** proxy_vtbl, ID3D12RootSignature* root,
206 ID3D12PipelineState* compute_base, ID3D12PipelineState* native_base) {
207 using DeriveFn = HRESULT(WINAPI*)(void*, void*, std::uint64_t, const void*, const IID*, void**);
208 auto derive = reinterpret_cast<DeriveFn>(proxy_vtbl[55]);
209 const IID iid = __uuidof(ID3D12PipelineState);
210 unsigned char rec_tag5[kRecordBytes], rec_raster[kRecordBytes];
211 unsigned char five[5 * kRecordBytes] = {};
212 put_record(rec_tag5, 5, nullptr, 0);
213 D3D12_RASTERIZER_DESC raster{};
214 raster.FillMode = D3D12_FILL_MODE_WIREFRAME;
215 raster.CullMode = D3D12_CULL_MODE_BACK;
216 raster.DepthClipEnable = TRUE;
217 put_record(rec_raster, 1, &raster, sizeof(raster));
218 ComPtr<ID3D12PipelineState> out;
219
220 // Refusals: a compute base has no graphics subobjects, a native compute PSO was never kept, and the arguments.
221 out.Reset();
222 check(derive(device, compute_base, 1, rec_tag5, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_INVALIDARG
223 && !out, "slot 55 refuses tag 5 (E_INVALIDARG, null output)");
224 out.Reset();
225 check(derive(device, compute_base, 1, rec_raster, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_INVALIDARG
226 && !out, "slot 55 refuses a rasterizer record on a base without RASTERIZER (E_INVALIDARG)");
227 out.Reset();
228 check(derive(device, native_base, 1, rec_raster, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_FAIL
229 && !out, "slot 55 refuses a base PSO that was never kept (null output, no derivation)");
230 out.Reset();
231 check(derive(device, compute_base, 1, nullptr, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_POINTER,
232 "slot 55 with null records is E_POINTER");
233 out.Reset();
234 check(derive(device, compute_base, 0, rec_raster, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_INVALIDARG,
235 "slot 55 with n = 0 is E_INVALIDARG");
236 check(derive(device, compute_base, 5, five, &iid, reinterpret_cast<void**>(out.GetAddressOf())) == E_INVALIDARG,
237 "slot 55 with n = 5 is E_INVALIDARG");
238 check(derive(device, compute_base, 1, rec_raster, nullptr, reinterpret_cast<void**>(out.GetAddressOf())) == E_POINTER,
239 "slot 55 with null riid is E_POINTER");
240
241 // Positive: a graphics base through slot 86, then tags 0, 1 and 3 in one call, tag 2 alone, and tag 2 again on
242 // the derived PSO (a derived PSO is a base too).
243 ComPtr<ID3DBlob> vs, ps;
244 if (!compile_hlsl("float4 main() : SV_Position { return float4(0, 0, 0, 1); }", "vs_5_0", vs) ||
245 !compile_hlsl("float4 main() : SV_Target { return float4(0, 0, 0, 1); }", "ps_5_0", ps)) {
246 check(false, "graphics shaders compile for the slot 55 positive test");
247 return;
248 }
249 const std::vector<unsigned char> stream = graphics_stream(root, vs.Get(), ps.Get());
250 D3D12_PIPELINE_STATE_STREAM_DESC stream_desc{stream.size(), const_cast<unsigned char*>(stream.data())};
251 using CreateStreamFn = HRESULT(WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, const IID*, void**);
252 ComPtr<ID3D12PipelineState> base;
253 HRESULT hr = reinterpret_cast<CreateStreamFn>(proxy_vtbl[86])(device, &stream_desc, &iid,
254 reinterpret_cast<void**>(base.GetAddressOf()));
255 check(SUCCEEDED(hr) && base, "slot 86 creates the graphics base PSO (WARP accepts the stream)");
256 if (!base) return;
257
258 D3D12_DEPTH_STENCIL_DESC ds{};
259 ds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
260 ds.DepthFunc = D3D12_COMPARISON_FUNC_LESS;
261 ds.StencilReadMask = ds.StencilWriteMask = 0xff;
262 for (D3D12_DEPTH_STENCILOP_DESC* op : {&ds.FrontFace, &ds.BackFace}) {
263 op->StencilFailOp = op->StencilDepthFailOp = op->StencilPassOp = D3D12_STENCIL_OP_KEEP;
264 op->StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
265 }
266 unsigned char recs[3 * kRecordBytes];
267 put_record(recs, 0, &ds, sizeof(ds));
268 put_record(recs + kRecordBytes, 1, &raster, sizeof(raster));
269 const UINT sample_mask = 0x1;
270 put_record(recs + 2 * kRecordBytes, 3, &sample_mask, sizeof(sample_mask));
271 ComPtr<ID3D12PipelineState> three;
272 hr = derive(device, base.Get(), 3, recs, &iid, reinterpret_cast<void**>(three.GetAddressOf()));
273 check(SUCCEEDED(hr) && three, "slot 55 derives a PSO from tags 0, 1 and 3 (n = 3) on the graphics base");
274
275 D3D12_BLEND_DESC blend{};
276 for (auto& rtb : blend.RenderTarget) {
277 rtb.SrcBlend = rtb.SrcBlendAlpha = D3D12_BLEND_ONE;
278 rtb.DestBlend = rtb.DestBlendAlpha = D3D12_BLEND_ZERO;
279 rtb.BlendOp = rtb.BlendOpAlpha = D3D12_BLEND_OP_ADD;
280 rtb.LogicOp = D3D12_LOGIC_OP_NOOP;
281 rtb.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
282 }
283 // Four records (raster, depth-stencil, sample mask, blend): the largest count the console builds.
284 unsigned char four_recs[4 * kRecordBytes];
285 std::memcpy(four_recs, recs, 3 * kRecordBytes);
286 put_record(four_recs + 3 * kRecordBytes, 2, &blend, sizeof(blend));
287 ComPtr<ID3D12PipelineState> quad;
288 hr = derive(device, base.Get(), 4, four_recs, &iid, reinterpret_cast<void**>(quad.GetAddressOf()));
289 check(SUCCEEDED(hr) && quad, "slot 55 derives a PSO from four records (n = 4)");
290
291 unsigned char rec_blend[kRecordBytes];
292 put_record(rec_blend, 2, &blend, sizeof(blend));
293 ComPtr<ID3D12PipelineState> blended;
294 hr = derive(device, base.Get(), 1, rec_blend, &iid, reinterpret_cast<void**>(blended.GetAddressOf()));
295 check(SUCCEEDED(hr) && blended, "slot 55 derives a PSO from tag 2 (blend), n = 1");
296
297 ComPtr<ID3D12PipelineState> chained;
298 hr = derive(device, three.Get(), 1, rec_blend, &iid, reinterpret_cast<void**>(chained.GetAddressOf()));
299 check(SUCCEEDED(hr) && chained, "slot 55 derives from a derived PSO (its stream is kept too)");
300}
301
109} // namespace 302} // namespace
110 303
111int main(int argc, char** argv) { 304int main(int argc, char** argv) {
@@ -159,6 +352,9 @@ int main(int argc, char** argv) {
159 check(rt::d3d12_xs::device_slot_overridden(14), "device slot 14 is the descriptor-heap override"); 352 check(rt::d3d12_xs::device_slot_overridden(14), "device slot 14 is the descriptor-heap override");
160 check(rt::d3d12_xs::device_slot_overridden(62), "device slot 62 is the compute-PSO override"); 353 check(rt::d3d12_xs::device_slot_overridden(62), "device slot 62 is the compute-PSO override");
161 check(rt::d3d12_xs::device_slot_overridden(76), "device slot 76 is the resource override"); 354 check(rt::d3d12_xs::device_slot_overridden(76), "device slot 76 is the resource override");
355 check(rt::d3d12_xs::device_slot_overridden(86), "device slot 86 is the CreatePipelineState override");
356 check(rt::d3d12_xs::device_slot_overridden(101), "device slot 101 is the CreateStateObject override");
357 check(rt::d3d12_xs::device_slot_overridden(108), "device slot 108 is the GetResourceAllocationInfo2 override");
162 check(rt::d3d12_xs::device_slot_overridden(67), 358 check(rt::d3d12_xs::device_slot_overridden(67),
163 "device slot 67 is the DeserializeComputePipelineStateX override (console native-code compute pipeline, not PC CreateProtectedResourceSession1)"); 359 "device slot 67 is the DeserializeComputePipelineStateX override (console native-code compute pipeline, not PC CreateProtectedResourceSession1)");
164 360
@@ -199,6 +395,98 @@ int main(int argc, char** argv) {
199 const LUID real_luid = real ? real->GetAdapterLuid() : LUID{}; 395 const LUID real_luid = real ? real->GetAdapterLuid() : LUID{};
200 check(proxy_luid.LowPart == real_luid.LowPart && proxy_luid.HighPart == real_luid.HighPart, 396 check(proxy_luid.LowPart == real_luid.LowPart && proxy_luid.HighPart == real_luid.HighPart,
201 "slot 43 forwards GetAdapterLuid (struct return)"); 397 "slot 43 forwards GetAdapterLuid (struct return)");
398 // Slot 25 returns a struct wider than 8 bytes. The console title calls it with the C ABI: the hidden
399 // return pointer first (RCX), then the device (RDX), then the arguments, and the buffer comes back in RAX
400 // (measured for slot 26 on the retail executable). Call slot 25 that way through a raw function pointer and compare
401 // with the PC device's own answer.
402 check(rt::d3d12_xs::device_slot_overridden(25), "device slot 25 is the C-ABI GetResourceAllocationInfo override");
403 if (real) {
404 using AllocInfoFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT,
405 const D3D12_RESOURCE_DESC*);
406 auto get_alloc_info = reinterpret_cast<AllocInfoFn>(proxy_vtbl[25]);
407 const D3D12_RESOURCE_DESC desc = buffer_desc();
408 D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull};
409 D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc);
410 // The proxy cleans the console layout word and flag bits before the PC call (stop 16), so the expected answer is
411 // the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX).
412 const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc);
413 const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean);
414 check(want.SizeInBytes != UINT64_MAX, "WARP accepts the normalized slot-25 buffer description");
415 check(returned == &got, "slot 25 returns the caller's buffer in RAX");
416 check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment,
417 "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer");
418
419 // The runtime's own code calls the proxy through d3d12.h (PC form: this, then the return buffer). Slot 25
420 // still answers that form.
421 const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc);
422 check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment,
423 "slot 25 still answers the PC (C++) form");
424
425 // A console depth-stencil texture that allows unordered access too, as a title sizes one: a 2D
426 // R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS and the console layout word. The
427 // PC device refuses the flag pair (negative control); slot 25 sizes it as the depth-stencil texture alone.
428 D3D12_RESOURCE_DESC ds_uav{};
429 ds_uav.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
430 ds_uav.Width = 2560;
431 ds_uav.Height = 1440;
432 ds_uav.DepthOrArraySize = 1;
433 ds_uav.MipLevels = 1;
434 ds_uav.Format = DXGI_FORMAT_R32G8X24_TYPELESS;
435 ds_uav.SampleDesc.Count = 1;
436 ds_uav.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);
437 ds_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
438 D3D12_RESOURCE_DESC pc_pair = ds_uav;
439 pc_pair.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
440 check(real->GetResourceAllocationInfo(0, 1, &pc_pair).SizeInBytes == UINT64_MAX,
441 "the PC device refuses a depth-stencil texture with unordered access (negative control)");
442 D3D12_RESOURCE_DESC ds_only = pc_pair;
443 ds_only.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
444 const D3D12_RESOURCE_ALLOCATION_INFO ds_want = real->GetResourceAllocationInfo(0, 1, &ds_only);
445 check(ds_want.SizeInBytes != UINT64_MAX, "WARP sizes the depth-stencil texture without unordered access");
446 const D3D12_RESOURCE_DESC ds_clean = rt::d3d12_xs::pc_resource_desc(ds_uav);
447 check(ds_clean.Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL,
448 "pc_resource_desc drops unordered access from a depth-stencil texture");
449 D3D12_RESOURCE_DESC uav_buffer = buffer_desc();
450 uav_buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
451 D3D12_RESOURCE_DESC rt_uav = ds_only;
452 rt_uav.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
453 rt_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
454 check(rt::d3d12_xs::pc_resource_desc(uav_buffer).Flags == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS &&
455 rt::d3d12_xs::pc_resource_desc(rt_uav).Flags == rt_uav.Flags,
456 "pc_resource_desc keeps unordered access on buffers and color textures");
457 D3D12_RESOURCE_ALLOCATION_INFO ds_got{~0ull, ~0ull};
458 get_alloc_info(&ds_got, device.Get(), 0, 1, &ds_uav);
459 // Sized as the console lays it out (12eb84f75: a depth plane and a stencil plane in 64 KiB tiles), which can
460 // be less than the PC answer for the depth-stencil texture alone, so only "sized, and in 32 bits" is checked.
461 check(ds_got.SizeInBytes != UINT64_MAX && ds_got.SizeInBytes != 0 && (ds_got.SizeInBytes >> 32) == 0,
462 "slot 25 (C ABI) sizes a console depth-stencil texture with unordered access");
463 }
464
465 constexpr auto kUav = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
466 constexpr auto kDepthStencil = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
467 constexpr auto kRenderTarget = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
468 const struct {
469 DXGI_FORMAT format;
470 D3D12_RESOURCE_FLAGS input;
471 D3D12_RESOURCE_FLAGS expected;
472 const char* message;
473 } flag_cases[] = {
474 {DXGI_FORMAT_B5G5R5A1_UNORM, kRenderTarget | kUav, kRenderTarget, "B5G5R5A1 keeps only RT"},
475 {DXGI_FORMAT_R32G8X24_TYPELESS, kDepthStencil | kUav, kDepthStencil, "R32G8X24 depth keeps only DS"},
476 {DXGI_FORMAT_R8G8B8A8_UNORM, kRenderTarget | kUav, kRenderTarget | kUav, "RGBA8 keeps RT and UAV"},
477 {DXGI_FORMAT_R32_FLOAT, kUav, kUav, "R32_FLOAT keeps UAV"},
478 {DXGI_FORMAT_R32_TYPELESS, kUav, kUav, "R32_TYPELESS without DS keeps UAV"},
479 {DXGI_FORMAT_D16_UNORM, kDepthStencil | kUav, kDepthStencil, "D16 depth keeps only DS"},
480 };
481 for (const auto& test : flag_cases) {
482 D3D12_RESOURCE_DESC desc{};
483 desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
484 desc.Format = test.format;
485 desc.Flags = test.input;
486 const auto clean = rt::d3d12_xs::pc_resource_desc(desc);
487 check(clean.Flags == test.expected && clean.Format == test.format && desc.Flags == test.input, test.message);
488 }
489
202 D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); 490 D3D12_RESOURCE_DESC reserved_desc = buffer_desc();
203 reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; 491 reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
204 ComPtr<ID3D12Resource> reserved; 492 ComPtr<ID3D12Resource> reserved;
@@ -206,6 +494,41 @@ int main(int argc, char** argv) {
206 IID_PPV_ARGS(reserved.GetAddressOf())); 494 IID_PPV_ARGS(reserved.GetAddressOf()));
207 check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)"); 495 check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)");
208 496
497 // Slot 26 the way the retail executable calls GetCustomHeapProperties: the buffer for the struct in RCX, the
498 // device in RDX, for the three heap types it asks about. The answer is the PC device's own, and nothing but
499 // the struct is written (the buffer sits in a pattern). On main this call read the PC vtable through the buffer.
500 check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 takes the console's struct-return form");
501 using XboxGetCustomHeapPropertiesFn =
502 D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE);
503 auto get_custom_heap = reinterpret_cast<XboxGetCustomHeapPropertiesFn>(proxy_vtbl[26]);
504 const D3D12_HEAP_TYPE heap_types[] = {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK};
505 bool console_returns_buffer = true, console_matches_pc = real != nullptr, console_writes_only_struct = true;
506 for (const D3D12_HEAP_TYPE type : heap_types) {
507 struct Padded {
508 D3D12_HEAP_PROPERTIES value;
509 std::uint8_t after[64];
510 } padded;
511 std::memset(&padded, 0xA5, sizeof(padded));
512 console_returns_buffer = get_custom_heap(&padded.value, device.Get(), 1, type) == &padded.value &&
513 console_returns_buffer;
514 const D3D12_HEAP_PROPERTIES want = real ? real->GetCustomHeapProperties(1, type) : D3D12_HEAP_PROPERTIES{};
515 console_matches_pc = console_matches_pc && std::memcmp(&padded.value, &want, sizeof(want)) == 0;
516 for (const std::uint8_t byte : padded.after)
517 console_writes_only_struct = console_writes_only_struct && byte == 0xA5;
518 }
519 check(console_returns_buffer, "slot 26 console form returns the buffer's address");
520 check(console_matches_pc, "slot 26 console form writes the PC device's DEFAULT, UPLOAD and READBACK properties");
521 check(console_writes_only_struct, "slot 26 console form writes nothing past the struct");
522 check(rt::d3d12_xs::device_slot_hits(26) == 3, "slot 26 hit counter is 3");
523 check(rt::d3d12_xs::is_device_proxy(device.Get()) && rt::d3d12_xs::device_proxy_real_device(device.Get()) == real,
524 "the proxy is intact after the console-form calls");
525 // A PC C++ call through the proxy (the proxy in RCX, the buffer in RDX) is still forwarded.
526 const D3D12_HEAP_PROPERTIES pc_form = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD);
527 const D3D12_HEAP_PROPERTIES pc_want = real ? real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD)
528 : D3D12_HEAP_PROPERTIES{};
529 check(real && std::memcmp(&pc_form, &pc_want, sizeof(pc_want)) == 0 && rt::d3d12_xs::device_slot_hits(26) == 4,
530 "slot 26 PC form still forwards GetCustomHeapProperties");
531
209 // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI. 532 // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI.
210 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; 533 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{};
211 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; 534 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
@@ -348,15 +671,20 @@ int main(int argc, char** argv) {
348 check(hr == S_OK && token2 != 0 && token2 != token, "slot 80 returns a fresh token on the next wait"); 671 check(hr == S_OK && token2 != 0 && token2 != token, "slot 80 returns a fresh token on the next wait");
349 hr = reinterpret_cast<WaitFrameEventFn>(proxy_vtbl[80])(device.Get(), 0, 0, nullptr, 0, nullptr); 672 hr = reinterpret_cast<WaitFrameEventFn>(proxy_vtbl[80])(device.Get(), 0, 0, nullptr, 0, nullptr);
350 check(hr == E_POINTER, "slot 80 refuses a null token with E_POINTER"); 673 check(hr == E_POINTER, "slot 80 refuses a null token with E_POINTER");
674 const auto tokens = rt::d3d12_xs::device_frame_tokens(device.Get());
675 check(tokens && tokens->issued() == token2 && token2 == token + 1,
676 "slot 80 tokens come from the device's frame token source");
677 check(!rt::d3d12_xs::device_frame_tokens(nullptr), "a non-proxy has no frame token source");
351 check(rt::d3d12_xs::device_slot_hits(78) == 1 && rt::d3d12_xs::device_slot_hits(79) == 1 && 678 check(rt::d3d12_xs::device_slot_hits(78) == 1 && rt::d3d12_xs::device_slot_hits(79) == 1 &&
352 rt::d3d12_xs::device_slot_hits(80) == 3, 679 rt::d3d12_xs::device_slot_hits(80) == 3,
353 "slots 78/79/80 hit counters are 1/1/3"); 680 "slots 78/79/80 hit counters are 1/1/3");
354 681
355 D3D12_COMMAND_QUEUE_DESC xbox_queue{}; 682 // The console description is 32 bytes: the PC prefix, then four Xbox words (the proxy logs them).
356 xbox_queue.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; 683 struct { D3D12_COMMAND_QUEUE_DESC pc; std::uint32_t extra[4]; } xbox_queue{};
684 xbox_queue.pc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
357 const IID iid_queue = __uuidof(ID3D12CommandQueue); 685 const IID iid_queue = __uuidof(ID3D12CommandQueue);
358 ComPtr<ID3D12CommandQueue> xbox_queue_proxy; 686 ComPtr<ID3D12CommandQueue> xbox_queue_proxy;
359 hr = reinterpret_cast<CreateQueueXFn>(proxy_vtbl[48])(device.Get(), &xbox_queue, &iid_queue, 687 hr = reinterpret_cast<CreateQueueXFn>(proxy_vtbl[48])(device.Get(), reinterpret_cast<const D3D12_COMMAND_QUEUE_DESC*>(&xbox_queue), &iid_queue,
360 reinterpret_cast<void**>(xbox_queue_proxy.GetAddressOf())); 688 reinterpret_cast<void**>(xbox_queue_proxy.GetAddressOf()));
361 check(hr == S_OK && rt::d3d12_xs::is_queue_proxy(xbox_queue_proxy.Get()), 689 check(hr == S_OK && rt::d3d12_xs::is_queue_proxy(xbox_queue_proxy.Get()),
362 "slot 48 CreateCommandQueueX returns a queue proxy"); 690 "slot 48 CreateCommandQueueX returns a queue proxy");
@@ -436,6 +764,102 @@ int main(int argc, char** argv) {
436 check(SUCCEEDED(hr) && pso67 != nullptr, "slot 67 creates a compute PSO via CreateComputePipelineState"); 764 check(SUCCEEDED(hr) && pso67 != nullptr, "slot 67 creates a compute PSO via CreateComputePipelineState");
437 check(rt::d3d12_xs::device_slot_hits(67) == 1, "slot 67 hit counter is 1"); 765 check(rt::d3d12_xs::device_slot_hits(67) == 1, "slot 67 hit counter is 1");
438 check(rt::d3d12_xs::device_slot_first_call_seen(67), "slot 67 first-call flag is set"); 766 check(rt::d3d12_xs::device_slot_first_call_seen(67), "slot 67 first-call flag is set");
767
768 // Slot 86: CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**), forwarded to PC
769 // ID3D12Device2::CreatePipelineState (PC slot 47).
770 if (slots > 47) {
771 struct alignas(void*) ComputeStream {
772 alignas(void*) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE root_type =
773 D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE;
774 ID3D12RootSignature* root_sig = nullptr;
775 alignas(void*) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE cs_type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS;
776 D3D12_SHADER_BYTECODE cs{};
777 } stream;
778 stream.root_sig = root_signature.Get();
779 stream.cs.pShaderBytecode = bytecode->GetBufferPointer();
780 stream.cs.BytecodeLength = bytecode->GetBufferSize();
781 D3D12_PIPELINE_STATE_STREAM_DESC stream_desc{sizeof(stream), &stream};
782 using XboxCreatePipelineStateFn =
783 HRESULT(WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, const IID*, void**);
784 auto create_stream_pso = reinterpret_cast<XboxCreatePipelineStateFn>(proxy_vtbl[86]);
785 ComPtr<ID3D12PipelineState> pso86;
786 hr = create_stream_pso(device.Get(), &stream_desc, &iid_pso,
787 reinterpret_cast<void**>(pso86.GetAddressOf()));
788 check(SUCCEEDED(hr) && pso86 != nullptr,
789 "slot 86 creates a PSO via PC ID3D12Device2::CreatePipelineState (slot 47)");
790 check(rt::d3d12_xs::device_slot_hits(86) == 1, "slot 86 hit counter is 1");
791 check(rt::d3d12_xs::device_slot_first_call_seen(86), "slot 86 first-call flag is set");
792 check_derived_states(device.Get(), proxy_vtbl, root_signature.Get(), pso86.Get(), pso67.Get());
793 }
794 }
795
796 // Slot 101: CreateStateObject(const D3D12_STATE_OBJECT_DESC*, REFIID, void**), forwarded to PC
797 // ID3D12Device5::CreateStateObject (PC slot 62).
798 if (slots > 62) {
799 using XboxCreateStateObjectFn = HRESULT(WINAPI*)(void*, const D3D12_STATE_OBJECT_DESC*, const IID*, void**);
800 auto create_state_object = reinterpret_cast<XboxCreateStateObjectFn>(proxy_vtbl[101]);
801 D3D12_STATE_OBJECT_DESC empty_so{};
802 empty_so.Type = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE;
803 void* so_out = reinterpret_cast<void*>(0x1111);
804 hr = create_state_object(device.Get(), &empty_so, nullptr, &so_out);
805 check(hr == E_POINTER && so_out == nullptr, "slot 101 nulls its output for a null IID");
806 check(rt::d3d12_xs::device_slot_hits(101) == 1, "slot 101 hit counter is 1");
807 }
808
809 // Slot 108: GetResourceAllocationInfo2(ret, this, visible_mask, count, descs, info1) with C-ABI struct return,
810 // 56-byte D3D12_RESOURCE_DESC entries, and Xbox layout/flag words, compared against direct PC
811 // ID3D12Device8::GetResourceAllocationInfo2 (PC slot 68).
812 if (slots > 68) {
813 ComPtr<ID3D12Device8> real_device8;
814 if (real && SUCCEEDED(real->QueryInterface(IID_PPV_ARGS(real_device8.GetAddressOf()))) && real_device8) {
815 D3D12_RESOURCE_DESC xbox_descs[2]{};
816 xbox_descs[0].Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
817 xbox_descs[0].Width = 64;
818 xbox_descs[0].Height = 64;
819 xbox_descs[0].DepthOrArraySize = 1;
820 xbox_descs[0].MipLevels = 1;
821 xbox_descs[0].Format = DXGI_FORMAT_R8G8B8A8_UNORM;
822 xbox_descs[0].SampleDesc.Count = 1;
823 xbox_descs[0].Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x105);
824 xbox_descs[0].Flags = static_cast<D3D12_RESOURCE_FLAGS>(
825 D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | 0x300000u);
826 xbox_descs[1].Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
827 xbox_descs[1].Width = 4096;
828 xbox_descs[1].Height = 1;
829 xbox_descs[1].DepthOrArraySize = 1;
830 xbox_descs[1].MipLevels = 1;
831 xbox_descs[1].SampleDesc.Count = 1;
832 xbox_descs[1].Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);
833 xbox_descs[1].Flags = static_cast<D3D12_RESOURCE_FLAGS>(0x200000u);
834
835 D3D12_RESOURCE_DESC1 pc_descs[2]{};
836 std::memcpy(&pc_descs[0], &xbox_descs[0], sizeof(D3D12_RESOURCE_DESC));
837 pc_descs[0].SamplerFeedbackMipRegion = {};
838 pc_descs[0].Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
839 pc_descs[0].Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
840 std::memcpy(&pc_descs[1], &xbox_descs[1], sizeof(D3D12_RESOURCE_DESC));
841 pc_descs[1].SamplerFeedbackMipRegion = {};
842 pc_descs[1].Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
843 pc_descs[1].Flags = D3D12_RESOURCE_FLAG_NONE;
844
845 D3D12_RESOURCE_ALLOCATION_INFO1 pc_info1[2]{};
846 const D3D12_RESOURCE_ALLOCATION_INFO pc_info =
847 real_device8->GetResourceAllocationInfo2(1, 2, pc_descs, pc_info1);
848
849 using XboxGetAllocInfo2CAbiFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(
850 D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, const D3D12_RESOURCE_DESC*,
851 D3D12_RESOURCE_ALLOCATION_INFO1*);
852 auto get_alloc_info2 = reinterpret_cast<XboxGetAllocInfo2CAbiFn>(proxy_vtbl[108]);
853 D3D12_RESOURCE_ALLOCATION_INFO xbox_info{};
854 D3D12_RESOURCE_ALLOCATION_INFO1 xbox_info1[2]{};
855 D3D12_RESOURCE_ALLOCATION_INFO* ret_ptr =
856 get_alloc_info2(&xbox_info, device.Get(), 1, 2, xbox_descs, xbox_info1);
857 check(ret_ptr == &xbox_info && xbox_info.SizeInBytes == pc_info.SizeInBytes &&
858 xbox_info.Alignment == pc_info.Alignment && xbox_info1[0].SizeInBytes == pc_info1[0].SizeInBytes &&
859 xbox_info1[1].SizeInBytes == pc_info1[1].SizeInBytes,
860 "slot 108 C-ABI GetResourceAllocationInfo2 with 56-byte Xbox descs matches PC Device8");
861 check(rt::d3d12_xs::device_slot_hits(108) == 1, "slot 108 hit counter is 1");
862 }
439 } 863 }
440 864
441 // _COM_Outptr_ (d3d12.h): a failed create leaves NULL in the output. WARP accepts invalid heap descriptions, 865 // _COM_Outptr_ (d3d12.h): a failed create leaves NULL in the output. WARP accepts invalid heap descriptions,
@@ -497,7 +921,397 @@ int main(int argc, char** argv) {
497 } 921 }
498 } 922 }
499 923
924 // Title-exported __XMemAllocationHooks__ backing for CreateDescriptorHeap (slot 14) + CPU handle translation
925 // against the real WARP D3D12 runtime.
926 {
927 struct HookState {
928 alignas(64) std::uint8_t backing[4096]{};
929 std::size_t alloc_size = 0;
930 std::uint64_t alloc_attr = 0;
931 void* freed_ptr = nullptr;
932 std::uint64_t freed_attr = 0;
933 int alloc_count = 0;
934 int free_count = 0;
935 };
936 static HookState hook_state;
937 hook_state = {};
938 struct HookCallbacks {
939 static void* __stdcall alloc(std::size_t size, std::uint64_t attr) {
940 ++hook_state.alloc_count;
941 hook_state.alloc_size = size;
942 hook_state.alloc_attr = attr;
943 if ((attr & 0x3FFFull) == 4 && size <= sizeof(hook_state.backing)) return hook_state.backing;
944 return nullptr;
945 }
946 static void __stdcall free(void* ptr, std::uint64_t attr) {
947 ++hook_state.free_count;
948 hook_state.freed_ptr = ptr;
949 hook_state.freed_attr = attr;
950 }
951 };
952 const rt::shims::XMemAllocationHooks title_hooks{&HookCallbacks::alloc, &HookCallbacks::free};
953 rt::shims::add_xmem_allocation_hooks(&title_hooks, &title_hooks);
954
955 D3D12_DESCRIPTOR_HEAP_DESC hooked_desc{};
956 hooked_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
957 hooked_desc.NumDescriptors = 4;
958 hooked_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
959 const UINT inc = device->GetDescriptorHandleIncrementSize(hooked_desc.Type);
960 ComPtr<ID3D12DescriptorHeap> hooked_heap;
961 hr = device->CreateDescriptorHeap(&hooked_desc, IID_PPV_ARGS(hooked_heap.GetAddressOf()));
962 check(SUCCEEDED(hr) && hooked_heap != nullptr, "hooked slot 14 creates a descriptor heap");
963 check(hook_state.alloc_count == 1 && hook_state.alloc_size == hooked_desc.NumDescriptors * inc &&
964 hook_state.alloc_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes,
965 "slot 14 invokes __XMemAllocationHooks__ with heap byte size and D3D descriptor-heap attributes");
966 if (hooked_heap) {
967 void** hooked_vtbl = *reinterpret_cast<void***>(hooked_heap.Get());
968 const auto hooked_cpu = reinterpret_cast<GetCpuHandleFn>(hooked_vtbl[9])(hooked_heap.Get());
969 const auto hooked_gpu = reinterpret_cast<GetGpuHandleFn>(hooked_vtbl[10])(hooked_heap.Get());
970 const auto expected_base = reinterpret_cast<SIZE_T>(hook_state.backing);
971 check(hooked_cpu.ptr == expected_base,
972 "hooked heap slot 9 returns the title-supplied CPU descriptor base");
973 check(hooked_gpu.ptr != 0, "hooked heap slot 10 returns a valid GPU descriptor start");
974
975 // Create a CBV at slot 1 of the title-backed heap; WARP validates the translated real handle.
976 D3D12_CONSTANT_BUFFER_VIEW_DESC cbv{};
977 cbv.BufferLocation = 0;
978 cbv.SizeInBytes = 256;
979 device->CreateConstantBufferView(&cbv, D3D12_CPU_DESCRIPTOR_HANDLE{expected_base + inc});
980 check(true, "CreateConstantBufferView translates a title-backed CPU descriptor handle on WARP");
981 }
982 hooked_heap.Reset();
983 check(hook_state.free_count == 1 && hook_state.freed_ptr == hook_state.backing &&
984 hook_state.freed_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes,
985 "releasing the hooked heap frees its backing through __XMemAllocationHooks__");
986
987 // End-to-end console command list clear + readback with title-backed RTV and DSV heaps:
988 // verifies CPU handle translation on console slots 50/51/52 and FLOAT Depth (XMM3) on slot 51.
989 {
990 struct DualHeapState {
991 alignas(64) std::uint8_t rtv_backing[1024]{};
992 alignas(64) std::uint8_t dsv_backing[1024]{};
993 int next_slice = 0;
994 };
995 static DualHeapState dual_state;
996 dual_state = {};
997 struct DualHooks {
998 static void* __stdcall alloc(std::size_t size, std::uint64_t attr) {
999 if ((attr & 0x3FFFull) != 4 || size > 1024) return nullptr;
1000 return dual_state.next_slice++ == 0 ? dual_state.rtv_backing : dual_state.dsv_backing;
1001 }
1002 static void __stdcall free(void*, std::uint64_t) {}
1003 };
1004 const rt::shims::XMemAllocationHooks dual_hooks{&DualHooks::alloc, &DualHooks::free};
1005 rt::shims::remove_xmem_allocation_hooks(&title_hooks);
1006 rt::shims::add_xmem_allocation_hooks(&dual_hooks, &dual_hooks);
1007
1008 D3D12_DESCRIPTOR_HEAP_DESC rtv_hd{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 2, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0};
1009 D3D12_DESCRIPTOR_HEAP_DESC dsv_hd{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 2, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0};
1010 ComPtr<ID3D12DescriptorHeap> rtv_heap, dsv_heap;
1011 hr = device->CreateDescriptorHeap(&rtv_hd, IID_PPV_ARGS(rtv_heap.GetAddressOf()));
1012 HRESULT hr_dsv = device->CreateDescriptorHeap(&dsv_hd, IID_PPV_ARGS(dsv_heap.GetAddressOf()));
1013 check(SUCCEEDED(hr) && SUCCEEDED(hr_dsv) && rtv_heap && dsv_heap,
1014 "hooked RTV and DSV heaps create through slot 14");
1015
1016 const D3D12_HEAP_PROPERTIES default_hp = default_heap();
1017 D3D12_HEAP_PROPERTIES readback_hp = default_heap();
1018 readback_hp.Type = D3D12_HEAP_TYPE_READBACK;
1019 D3D12_RESOURCE_DESC rt_desc{};
1020 rt_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
1021 rt_desc.Width = 4;
1022 rt_desc.Height = 4;
1023 rt_desc.DepthOrArraySize = 1;
1024 rt_desc.MipLevels = 1;
1025 rt_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1026 rt_desc.SampleDesc = {1, 0};
1027 rt_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
1028
1029 D3D12_RESOURCE_DESC ds_desc = rt_desc;
1030 ds_desc.Format = DXGI_FORMAT_D32_FLOAT;
1031 ds_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
1032
1033 D3D12_RESOURCE_DESC rb_desc = buffer_desc();
1034 rb_desc.Width = 4096;
1035 rb_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
1036
1037 ComPtr<ID3D12Resource> rt_tex, ds_tex, rb_buf;
1038 hr = device->CreateCommittedResource(&default_hp, D3D12_HEAP_FLAG_NONE, &rt_desc,
1039 D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr,
1040 IID_PPV_ARGS(rt_tex.GetAddressOf()));
1041 HRESULT hr2 = device->CreateCommittedResource(&default_hp, D3D12_HEAP_FLAG_NONE, &ds_desc,
1042 D3D12_RESOURCE_STATE_DEPTH_WRITE, nullptr,
1043 IID_PPV_ARGS(ds_tex.GetAddressOf()));
1044 HRESULT hr3 = device->CreateCommittedResource(&readback_hp, D3D12_HEAP_FLAG_NONE, &rb_desc,
1045 D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
1046 IID_PPV_ARGS(rb_buf.GetAddressOf()));
1047 check(SUCCEEDED(hr) && SUCCEEDED(hr2) && SUCCEEDED(hr3),
1048 "RT, DS and readback resources create for console list clear test");
1049
1050 if (rtv_heap && dsv_heap && rt_tex && ds_tex && rb_buf) {
1051 const auto rtv_cpu = reinterpret_cast<GetCpuHandleFn>(
1052 (*reinterpret_cast<void***>(rtv_heap.Get()))[9])(rtv_heap.Get());
1053 const auto dsv_cpu = reinterpret_cast<GetCpuHandleFn>(
1054 (*reinterpret_cast<void***>(dsv_heap.Get()))[9])(dsv_heap.Get());
1055 const UINT rtv_inc = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
1056 const UINT dsv_inc = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
1057 const D3D12_CPU_DESCRIPTOR_HANDLE rtv_h{rtv_cpu.ptr + rtv_inc};
1058 const D3D12_CPU_DESCRIPTOR_HANDLE dsv_h{dsv_cpu.ptr + dsv_inc};
1059 check(rtv_cpu.ptr == reinterpret_cast<SIZE_T>(dual_state.rtv_backing) &&
1060 dsv_cpu.ptr == reinterpret_cast<SIZE_T>(dual_state.dsv_backing),
1061 "RTV and DSV heaps report their title-backed CPU descriptor bases");
1062
1063 device->CreateRenderTargetView(rt_tex.Get(), nullptr, rtv_h);
1064 device->CreateDepthStencilView(ds_tex.Get(), nullptr, dsv_h);
1065
1066 using CreateQueueXFn = HRESULT(WINAPI*)(void*, const D3D12_COMMAND_QUEUE_DESC*, const IID*, void**);
1067 using CreateListXFn = HRESULT(WINAPI*)(void*, const void*, ID3D12CommandAllocator*,
1068 ID3D12PipelineState*, const IID*, void**);
1069 using CloseFn = HRESULT(WINAPI*)(void*);
1070 using BarrierFn = void(WINAPI*)(void*, UINT, const D3D12_RESOURCE_BARRIER*);
1071 using CopyTexFn = void(WINAPI*)(void*, const D3D12_TEXTURE_COPY_LOCATION*, UINT, UINT, UINT,
1072 const D3D12_TEXTURE_COPY_LOCATION*, const D3D12_BOX*);
1073 using OmSetRtFn = void(WINAPI*)(void*, UINT, const D3D12_CPU_DESCRIPTOR_HANDLE*, BOOL,
1074 const D3D12_CPU_DESCRIPTOR_HANDLE*);
1075 using ClearDsvFn = void(WINAPI*)(void*, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_CLEAR_FLAGS, FLOAT, UINT8,
1076 UINT, const D3D12_RECT*);
1077 using ClearRtvFn = void(WINAPI*)(void*, D3D12_CPU_DESCRIPTOR_HANDLE, const FLOAT[4], UINT,
1078 const D3D12_RECT*);
1079
1080 const D3D12_COMMAND_QUEUE_DESC qd{};
1081 const IID iid_q = __uuidof(ID3D12CommandQueue);
1082 const IID iid_l = __uuidof(ID3D12GraphicsCommandList);
1083 ComPtr<ID3D12CommandQueue> clear_q;
1084 ComPtr<ID3D12CommandAllocator> clear_alloc;
1085 ComPtr<ID3D12GraphicsCommandList> clear_list;
1086 ComPtr<ID3D12Fence> clear_fence;
1087 hr = reinterpret_cast<CreateQueueXFn>(proxy_vtbl[48])(
1088 device.Get(), &qd, &iid_q, reinterpret_cast<void**>(clear_q.GetAddressOf()));
1089 HRESULT hra = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
1090 IID_PPV_ARGS(clear_alloc.GetAddressOf()));
1091 struct {
1092 UINT Type;
1093 UINT NodeMask;
1094 } ld{D3D12_COMMAND_LIST_TYPE_DIRECT, 0};
1095 HRESULT hrl = SUCCEEDED(hra) ? reinterpret_cast<CreateListXFn>(proxy_vtbl[73])(
1096 device.Get(), &ld, clear_alloc.Get(), nullptr, &iid_l,
1097 reinterpret_cast<void**>(clear_list.GetAddressOf()))
1098 : hra;
1099 HRESULT hrf = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(clear_fence.GetAddressOf()));
1100 check(SUCCEEDED(hr) && SUCCEEDED(hra) && SUCCEEDED(hrl) && SUCCEEDED(hrf) &&
1101 rt::d3d12_xs::is_list_proxy(clear_list.Get()),
1102 "console list proxy created for hooked RTV/DSV clear");
1103
1104 if (clear_q && clear_list && clear_fence) {
1105 void** lv = *reinterpret_cast<void***>(clear_list.Get());
1106 const FLOAT rgba[4] = {1.0f, 0.0f, 0.5f, 1.0f};
1107 reinterpret_cast<OmSetRtFn>(lv[50])(clear_list.Get(), 1, &rtv_h, FALSE, &dsv_h);
1108 reinterpret_cast<ClearRtvFn>(lv[52])(clear_list.Get(), rtv_h, rgba, 0, nullptr);
1109 reinterpret_cast<ClearDsvFn>(lv[51])(clear_list.Get(), dsv_h, D3D12_CLEAR_FLAG_DEPTH, 0.25f, 0, 0,
1110 nullptr);
1111
1112 D3D12_RESOURCE_BARRIER b[2]{};
1113 b[0].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
1114 b[0].Transition = {rt_tex.Get(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
1115 D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE};
1116 b[1].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
1117 b[1].Transition = {ds_tex.Get(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
1118 D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE};
1119 reinterpret_cast<BarrierFn>(lv[26])(clear_list.Get(), 2, b);
1120
1121 D3D12_TEXTURE_COPY_LOCATION dst_rt{}, src_rt{}, dst_ds{}, src_ds{};
1122 dst_rt.pResource = rb_buf.Get();
1123 dst_rt.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
1124 dst_rt.PlacedFootprint = {0, {DXGI_FORMAT_R8G8B8A8_UNORM, 4, 4, 1, 256}};
1125 src_rt.pResource = rt_tex.Get();
1126 src_rt.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
1127 dst_ds.pResource = rb_buf.Get();
1128 dst_ds.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
1129 dst_ds.PlacedFootprint = {1536, {DXGI_FORMAT_R32_TYPELESS, 4, 4, 1, 256}};
1130 src_ds.pResource = ds_tex.Get();
1131 src_ds.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
1132 reinterpret_cast<CopyTexFn>(lv[16])(clear_list.Get(), &dst_rt, 0, 0, 0, &src_rt, nullptr);
1133 reinterpret_cast<CopyTexFn>(lv[16])(clear_list.Get(), &dst_ds, 0, 0, 0, &src_ds, nullptr);
1134
1135 const HRESULT hr_close = reinterpret_cast<CloseFn>(lv[9])(clear_list.Get());
1136 check(hr_close == S_OK, "console list Close succeeds after title-backed RTV/DSV clears");
1137
1138 ID3D12CommandList* lists[] = {clear_list.Get()};
1139 clear_q->ExecuteCommandLists(1, lists);
1140 HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr);
1141 const bool done = ev && SUCCEEDED(clear_q->Signal(clear_fence.Get(), 1)) &&
1142 SUCCEEDED(clear_fence->SetEventOnCompletion(1, ev)) &&
1143 WaitForSingleObject(ev, 5000) == 0;
1144 if (ev) CloseHandle(ev);
1145 check(done, "console list clear commands complete on the GPU");
1146
1147 void* mapped = nullptr;
1148 const D3D12_RANGE range{0, 4096};
1149 if (done && SUCCEEDED(rb_buf->Map(0, &range, &mapped)) && mapped) {
1150 const auto* bytes = static_cast<const std::uint8_t*>(mapped);
1151 const bool rt_ok = bytes[0] == 255 && bytes[1] == 0 && (bytes[2] == 127 || bytes[2] == 128) &&
1152 bytes[3] == 255;
1153 float depth_got = -1.0f;
1154 std::memcpy(&depth_got, bytes + 1536, sizeof(depth_got));
1155 const bool ds_ok = std::fabs(depth_got - 0.25f) < 1e-6f;
1156 check(rt_ok, "console slot 52 ClearRenderTargetView writes expected RGBA texel via hooked heap");
1157 check(ds_ok, "console slot 51 ClearDepthStencilView preserves FLOAT depth 0.25 via XMM3");
1158 const D3D12_RANGE empty{0, 0};
1159 rb_buf->Unmap(0, &empty);
1160 }
1161 }
1162 }
1163 rtv_heap.Reset();
1164 dsv_heap.Reset();
1165 rt::shims::remove_xmem_allocation_hooks(&dual_hooks);
1166 }
1167 }
1168
500 // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own. 1169 // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own.
1170 // Slot 57 (DeserializeGraphicsPipelineStateX):
1171 // 1. Guard-page test on the measured 188-byte (0xbc) pipeline blob from PSO #1 (record 8916), whose third element
1172 // ("TEXCOORD" at 0x9b, fields at 0xa4) has its 28-byte block truncated by 4 bytes at 0xbc. Placing the 188-byte
1173 // blob at the very end of a committed page right before a PAGE_NOACCESS guard page proves the parser decodes all
1174 // 3 elements (POSITION R32G32B32_FLOAT @0, COLOR R8G8B8A8_UNORM @12, TEXCOORD R32G32_FLOAT @16) without reading
1175 // past `blob_size`.
1176 // 2. ShaderLibrary `fspx_gfx/index.json` loading and separate `fspx_size()`, `fspx_gfx_size()`, `bvh_size()` counters.
1177 {
1178 auto put_u32 = [](std::uint8_t* dst, std::size_t off, std::uint32_t v) {
1179 std::memcpy(dst + off, &v, 4);
1180 };
1181 std::uint8_t blob188[0xbc]{};
1182 put_u32(blob188, 0x00, 0xea6f6e56u); // PSO 1 magic/checksum
1183 put_u32(blob188, 0x04, 0x00001000u); // constant
1184 put_u32(blob188, 0x08, 0u);
1185 put_u32(blob188, 0x0c, 1u);
1186 put_u32(blob188, 0x10, 0x0000001cu); // 28 bytes (7 u32) per element
1187 put_u32(blob188, 0x1c, 0xffffffffu);
1188 put_u32(blob188, 0x24, 0x00130100u);
1189 put_u32(blob188, 0x28, 1u);
1190 put_u32(blob188, 0x38, 0x00000070u); // 4 + 3*28 + (9+6+9) = 112
1191 put_u32(blob188, 0x3c, 0x0000000cu);
1192 put_u32(blob188, 0x4c, 3u); // 3 input elements
1193 put_u32(blob188, 0x50, 9u); // max name stride including NUL
1194
1195 // Element 0 @ 0x54: "POSITION\0" (9 B) + 28 B fields @ 0x5d..0x79
1196 std::memcpy(blob188 + 0x54, "POSITION", 9);
1197 put_u32(blob188, 0x5d + 0x00, 0u); // InputSlot 0
1198 put_u32(blob188, 0x5d + 0x04, static_cast<std::uint32_t>(DXGI_FORMAT_R32G32B32_FLOAT)); // 6
1199 put_u32(blob188, 0x5d + 0x08, 0u); // SemanticIndex 0
1200 put_u32(blob188, 0x5d + 0x0c, 0u); // AlignedByteOffset 0
1201 put_u32(blob188, 0x5d + 0x18, 6u);
1202
1203 // Element 1 @ 0x79: "COLOR\0" (6 B) + 28 B fields @ 0x7f..0x9b
1204 std::memcpy(blob188 + 0x79, "COLOR", 6);
1205 put_u32(blob188, 0x7f + 0x00, 0u);
1206 put_u32(blob188, 0x7f + 0x04, static_cast<std::uint32_t>(DXGI_FORMAT_R8G8B8A8_UNORM)); // 28
1207 put_u32(blob188, 0x7f + 0x08, 0u);
1208 put_u32(blob188, 0x7f + 0x0c, 12u);
1209 put_u32(blob188, 0x7f + 0x18, 9u);
1210
1211 // Element 2 @ 0x9b: "TEXCOORD\0" (9 B) + 24 B fields @ 0xa4..0xbc (truncated by 4 B at 0xbc!)
1212 std::memcpy(blob188 + 0x9b, "TEXCOORD", 9);
1213 put_u32(blob188, 0xa4 + 0x00, 0u);
1214 put_u32(blob188, 0xa4 + 0x04, static_cast<std::uint32_t>(DXGI_FORMAT_R32G32_FLOAT)); // 16
1215 put_u32(blob188, 0xa4 + 0x08, 0u);
1216 put_u32(blob188, 0xa4 + 0x0c, 16u);
1217
1218 SYSTEM_INFO si{};
1219 GetSystemInfo(&si);
1220 const std::size_t page = si.dwPageSize ? si.dwPageSize : 4096;
1221 auto* pages = static_cast<std::uint8_t*>(
1222 VirtualAlloc(nullptr, page * 2, MEM_RESERVE, PAGE_NOACCESS));
1223 check(pages != nullptr, "slot 57 pipeline blob guard pages reserved");
1224 if (pages) {
1225 void* committed = VirtualAlloc(pages, page, MEM_COMMIT, PAGE_READWRITE);
1226 check(committed == pages, "slot 57 pipeline blob first page committed before guard page");
1227 std::uint8_t* guarded_blob = pages + page - sizeof(blob188);
1228 std::memcpy(guarded_blob, blob188, sizeof(blob188));
1229 std::vector<rt::d3d12_xs::XboxPipelineInputElement> elems;
1230 const bool ok = rt::d3d12_xs::parse_xbox_pipeline_blob_input_layout(
1231 guarded_blob, sizeof(blob188), elems);
1232 check(ok && elems.size() == 3,
1233 "slot 57 pipeline blob parser decodes 3 elements from truncated 188-byte blob adjacent to PAGE_NOACCESS");
1234 if (elems.size() == 3) {
1235 check(elems[0].semantic_name == "POSITION" && elems[0].format == DXGI_FORMAT_R32G32B32_FLOAT &&
1236 elems[0].aligned_byte_offset == 0 && elems[0].input_slot == 0,
1237 "slot 57 pipeline blob element 0 is POSITION R32G32B32_FLOAT @0");
1238 check(elems[1].semantic_name == "COLOR" && elems[1].format == DXGI_FORMAT_R8G8B8A8_UNORM &&
1239 elems[1].aligned_byte_offset == 12 && elems[1].input_slot == 0,
1240 "slot 57 pipeline blob element 1 is COLOR R8G8B8A8_UNORM @12");
1241 check(elems[2].semantic_name == "TEXCOORD" && elems[2].format == DXGI_FORMAT_R32G32_FLOAT &&
1242 elems[2].aligned_byte_offset == 16 && elems[2].input_slot == 0,
1243 "slot 57 pipeline blob element 2 is TEXCOORD R32G32_FLOAT @16");
1244 }
1245 VirtualFree(pages, 0, MEM_RELEASE);
1246 }
1247
1248 // Slot 57 null-argument checks on the device proxy.
1249 void** vtable = *reinterpret_cast<void***>(device.Get());
1250 using Slot57Fn = HRESULT(WINAPI*)(void*, const void*, const IID*, void**);
1251 const IID iid_pso = __uuidof(ID3D12PipelineState);
1252 void* pso_out = reinterpret_cast<void*>(0x1111);
1253 hr = reinterpret_cast<Slot57Fn>(vtable[57])(device.Get(), nullptr, &iid_pso, &pso_out);
1254 check(FAILED(hr) && pso_out == nullptr, "slot 57 nulls its output for a null description");
1255
1256 // Synthetic test for ShaderLibrary loading `fspx_gfx/index.json` alongside `fspx/index.json` and `bvh/index.json`
1257 // while keeping `fspx_size()`, `fspx_gfx_size()`, and `bvh_size()` independent.
1258 wchar_t temp_root[MAX_PATH]{};
1259 if (GetTempPathW(MAX_PATH, temp_root)) {
1260 const std::filesystem::path tmp_dir =
1261 std::filesystem::path(temp_root) / ("leonida_fspx_gfx_test_" + std::to_string(GetCurrentProcessId()));
1262 std::error_code ec;
1263 std::filesystem::create_directories(tmp_dir / "fspx", ec);
1264 std::filesystem::create_directories(tmp_dir / "fspx_gfx", ec);
1265 std::filesystem::create_directories(tmp_dir / "bvh", ec);
1266 {
1267 std::ofstream(tmp_dir / "index.json") << "{\n}\n";
1268 std::ofstream(tmp_dir / "fspx" / "index.json")
1269 << "{\n"
1270 << " \"libcs_00001\": {\n"
1271 << " \"stage\": \"cs\",\n"
1272 << " \"fspx_code_sha256\": \"1111111111111111111111111111111111111111111111111111111111111111\"\n"
1273 << " }\n"
1274 << "}\n";
1275 std::ofstream(tmp_dir / "fspx_gfx" / "index.json")
1276 << "{\n"
1277 << " \"9e5ffd2c6c521c037cf57582a23f8ff7ba494a71ca63bb899357caee8baab850\": {\n"
1278 << " \"stage\": \"ps\",\n"
1279 << " \"spv\": \"9e5ffd2c6c521c03_libps_00842.spv\",\n"
1280 << " \"fspx_code_sha256\": \"9e5ffd2c6c521c037cf57582a23f8ff7ba494a71ca63bb899357caee8baab850\"\n"
1281 << " },\n"
1282 << " \"160fbe4368fb1a6349a2683bf72817f183d780c42a35cf25c86560917228061a\": {\n"
1283 << " \"stage\": \"vs\",\n"
1284 << " \"spv\": \"160fbe4368fb1a63_libvs_00843.spv\",\n"
1285 << " \"fspx_code_sha256\": \"160fbe4368fb1a6349a2683bf72817f183d780c42a35cf25c86560917228061a\"\n"
1286 << " }\n"
1287 << "}\n";
1288 std::ofstream(tmp_dir / "bvh" / "index.json")
1289 << "{\n"
1290 << " \"bvh_00001\": {\n"
1291 << " \"stage\": \"cs\",\n"
1292 << " \"fspx_code_sha256\": \"2222222222222222222222222222222222222222222222222222222222222222\"\n"
1293 << " }\n"
1294 << "}\n";
1295 }
1296 leonida::ShaderLibrary lib;
1297 std::string err;
1298 const bool loaded = lib.load(tmp_dir, &err);
1299 check(loaded, "ShaderLibrary::load loads index.json + fspx + fspx_gfx + bvh");
1300 check(lib.fspx_size() == 1, "ShaderLibrary::fspx_size() counts only fspx/ entries");
1301 check(lib.fspx_gfx_size() == 2, "ShaderLibrary::fspx_gfx_size() counts only fspx_gfx/ entries");
1302 check(lib.bvh_size() == 1, "ShaderLibrary::bvh_size() counts only bvh/ entries");
1303 const auto* ps_entry =
1304 lib.find_fspx_by_code("9e5ffd2c6c521c037cf57582a23f8ff7ba494a71ca63bb899357caee8baab850");
1305 const auto* vs_entry =
1306 lib.find_fspx_by_code("160fbe4368fb1a6349a2683bf72817f183d780c42a35cf25c86560917228061a");
1307 check(ps_entry && ps_entry->stage == "ps" && ps_entry->spv_file == "fspx_gfx/9e5ffd2c6c521c03_libps_00842.spv",
1308 "fspx_gfx PS entry preserves stage and its spv filename, under the folder prefix");
1309 check(vs_entry && vs_entry->stage == "vs" && vs_entry->spv_file == "fspx_gfx/160fbe4368fb1a63_libvs_00843.spv",
1310 "fspx_gfx VS entry preserves stage and its spv filename, under the folder prefix");
1311 std::filesystem::remove_all(tmp_dir, ec);
1312 }
1313 }
1314
501 if (real) real->AddRef(); 1315 if (real) real->AddRef();
502 // Drop every device child before the proxy so the PC device is not released first. 1316 // Drop every device child before the proxy so the PC device is not released first.
503 root_signature.Reset(); 1317 root_signature.Reset();