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:
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
-rw-r--r--runtime/test/device_proxy_test.cpp71
1 files changed, 69 insertions, 2 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 70cae9a89..46a853e7c 100644
--- a/runtime/test/device_proxy_test.cpp
+++ b/runtime/test/device_proxy_test.cpp
@@ -21,6 +21,7 @@
21 21
22#include <wrl/client.h> 22#include <wrl/client.h>
23 23
24#include "d3d12_trace.h"
24#include "d3d12_xs_device.h" 25#include "d3d12_xs_device.h"
25#include "shims.h" 26#include "shims.h"
26 27
@@ -107,7 +108,9 @@ bool load_compute_shader(ComPtr<ID3DBlob>& bytecode) {
107 108
108} // namespace 109} // namespace
109 110
110int main() { 111int main(int argc, char** argv) {
112 // --trace-d3d12, as gta6rt takes it: device_proxy_trace checks that the parameter words still print then.
113 if (argc == 2 && std::strcmp(argv[1], "--trace-d3d12") == 0) rt::d3d12_trace::set_enabled(true);
111 std::setvbuf(stdout, nullptr, _IONBF, 0); 114 std::setvbuf(stdout, nullptr, _IONBF, 0);
112 std::printf("device_proxy_test: Xbox-ABI device proxy over WARP\n"); 115 std::printf("device_proxy_test: Xbox-ABI device proxy over WARP\n");
113 116
@@ -132,7 +135,7 @@ int main() {
132 check(create_device != nullptr, "shim registry exposes d3d12_xs!D3D12XboxCreateDevice"); 135 check(create_device != nullptr, "shim registry exposes d3d12_xs!D3D12XboxCreateDevice");
133 if (!create_device) return 1; 136 if (!create_device) return 1;
134 137
135 std::uint32_t params[24] = {}; // logged only; the measured layout is not decoded 138 std::uint32_t params[24] = {0x1234abcd}; // logged only, not decoded; word 0 is device_proxy_trace's marker
136 const IID iid_device = __uuidof(ID3D12Device); 139 const IID iid_device = __uuidof(ID3D12Device);
137 void* created = nullptr; 140 void* created = nullptr;
138 hr = create_device(warp.Get(), params, &iid_device, &created); 141 hr = create_device(warp.Get(), params, &iid_device, &created);
@@ -166,6 +169,15 @@ int main() {
166 if (slots > 67) check(proxy_vtbl[67] != real_vtbl[67], "slot 67 thunk differs from PC CreateProtectedResourceSession1"); 169 if (slots > 67) check(proxy_vtbl[67] != real_vtbl[67], "slot 67 thunk differs from PC CreateProtectedResourceSession1");
167 if (slots > 76) check(proxy_vtbl[76] != real_vtbl[76], "slot 76 thunk differs from PC CreateCommittedResource3"); 170 if (slots > 76) check(proxy_vtbl[76] != real_vtbl[76], "slot 76 thunk differs from PC CreateCommittedResource3");
168 171
172 // The hit counters are for tests and count from the first read or reset, so that a title's calls write no
173 // shared counter. The QueryInterface of the creation above was before that: its flag is set, its hit is not.
174 check(rt::d3d12_xs::device_slot_first_call_seen(0), "slot 0 first-call flag is set by the creation");
175 check(rt::d3d12_xs::device_slot_hits(0) == 0, "slot 0 has no hit before the first read of a counter");
176 device->AddRef();
177 device->Release();
178 check(rt::d3d12_xs::device_slot_hits(1) == 1 && rt::d3d12_xs::device_slot_hits(2) == 1,
179 "slots 1 and 2 count the calls after the first read");
180
169 rt::d3d12_xs::reset_device_proxy_stats(); 181 rt::d3d12_xs::reset_device_proxy_stats();
170 182
171 // QI/refcount behaviour: device interfaces resolve to the same proxy, non-device IIDs do not. 183 // QI/refcount behaviour: device interfaces resolve to the same proxy, non-device IIDs do not.
@@ -312,6 +324,61 @@ int main() {
312 check(rt::d3d12_xs::device_slot_hits(76) == 2, "slot 76 hit counter is 2"); 324 check(rt::d3d12_xs::device_slot_hits(76) == 2, "slot 76 hit counter is 2");
313 check(rt::d3d12_xs::device_slot_first_call_seen(76), "slot 76 first-call flag is set"); 325 check(rt::d3d12_xs::device_slot_first_call_seen(76), "slot 76 first-call flag is set");
314 326
327 // Xbox device slots from the public HLE. On the Vulkan device the PC entries at 78/79 are
328 // CreateReservedResource2/CreateSampler2 and 80 is past the 80-slot table, so success here can only come from
329 // the routes: frame events return S_OK and a fresh token, CreateCommandQueueX returns a queue proxy and
330 // CreateCommandListX (desc, allocator, initialState, riid, out; no node mask) reaches PC CreateCommandList.
331 {
332 using SetFrameIntervalFn = HRESULT(WINAPI*)(void*, void*, UINT, UINT, UINT);
333 using ScheduleFrameEventFn = HRESULT(WINAPI*)(void*, UINT, UINT, void*, UINT);
334 using WaitFrameEventFn = HRESULT(WINAPI*)(void*, UINT, UINT, void*, UINT, UINT64*);
335 using CreateQueueXFn = HRESULT(WINAPI*)(void*, const D3D12_COMMAND_QUEUE_DESC*, const IID*, void**);
336 using CreateListXFn = HRESULT(WINAPI*)(void*, const void*, ID3D12CommandAllocator*, ID3D12PipelineState*,
337 const IID*, void**);
338
339 hr = reinterpret_cast<SetFrameIntervalFn>(proxy_vtbl[78])(device.Get(), nullptr, 16667, 1, 0);
340 check(hr == S_OK, "slot 78 SetFrameIntervalX returns S_OK");
341 hr = reinterpret_cast<ScheduleFrameEventFn>(proxy_vtbl[79])(device.Get(), 0, 0, nullptr, 0);
342 check(hr == S_OK, "slot 79 ScheduleFrameEventX returns S_OK");
343
344 std::uint64_t token = 0, token2 = 0;
345 hr = reinterpret_cast<WaitFrameEventFn>(proxy_vtbl[80])(device.Get(), 0, INFINITE, nullptr, 0, &token);
346 check(hr == S_OK && token != 0, "slot 80 WaitFrameEventX returns a non-zero token");
347 hr = reinterpret_cast<WaitFrameEventFn>(proxy_vtbl[80])(device.Get(), 0, 0, nullptr, 0, &token2);
348 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);
350 check(hr == E_POINTER, "slot 80 refuses a null token with E_POINTER");
351 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,
353 "slots 78/79/80 hit counters are 1/1/3");
354
355 D3D12_COMMAND_QUEUE_DESC xbox_queue{};
356 xbox_queue.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
357 const IID iid_queue = __uuidof(ID3D12CommandQueue);
358 ComPtr<ID3D12CommandQueue> xbox_queue_proxy;
359 hr = reinterpret_cast<CreateQueueXFn>(proxy_vtbl[48])(device.Get(), &xbox_queue, &iid_queue,
360 reinterpret_cast<void**>(xbox_queue_proxy.GetAddressOf()));
361 check(hr == S_OK && rt::d3d12_xs::is_queue_proxy(xbox_queue_proxy.Get()),
362 "slot 48 CreateCommandQueueX returns a queue proxy");
363 check(rt::d3d12_xs::device_slot_hits(48) == 1, "slot 48 hit counter is 1");
364
365 ComPtr<ID3D12CommandAllocator> xbox_allocator;
366 hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
367 IID_PPV_ARGS(xbox_allocator.GetAddressOf()));
368 struct XboxCommandListDesc {
369 UINT Type;
370 UINT NodeMask;
371 } list_desc{D3D12_COMMAND_LIST_TYPE_DIRECT, 7}; // the node mask is ignored by the console call
372 const IID iid_list = __uuidof(ID3D12GraphicsCommandList);
373 ComPtr<ID3D12GraphicsCommandList> xbox_list;
374 hr = SUCCEEDED(hr) ? reinterpret_cast<CreateListXFn>(proxy_vtbl[73])(
375 device.Get(), &list_desc, xbox_allocator.Get(), nullptr, &iid_list,
376 reinterpret_cast<void**>(xbox_list.GetAddressOf()))
377 : hr;
378 check(hr == S_OK && xbox_list != nullptr, "slot 73 CreateCommandListX returns a command list");
379 check(rt::d3d12_xs::device_slot_hits(73) == 1, "slot 73 hit counter is 1");
380 }
381
315 // Slot 62: an empty root signature and a trivial compute shader through the Xbox signature. The PC entry at 382 // Slot 62: an empty root signature and a trivial compute shader through the Xbox signature. The PC entry at
316 // slot 62 is CreateStateObject, so success here proves the override reached CreateComputePipelineState. 383 // slot 62 is CreateStateObject, so success here proves the override reached CreateComputePipelineState.
317 D3D12_ROOT_SIGNATURE_DESC root_desc{}; 384 D3D12_ROOT_SIGNATURE_DESC root_desc{};