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.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 670719dca..e9b19b7a8 100644
--- a/runtime/test/device_proxy_test.cpp
+++ b/runtime/test/device_proxy_test.cpp
@@ -161,6 +161,9 @@ int main(int argc, char** argv) {
161 check(rt::d3d12_xs::device_slot_overridden(14), "device slot 14 is the descriptor-heap override"); 161 check(rt::d3d12_xs::device_slot_overridden(14), "device slot 14 is the descriptor-heap override");
162 check(rt::d3d12_xs::device_slot_overridden(62), "device slot 62 is the compute-PSO override"); 162 check(rt::d3d12_xs::device_slot_overridden(62), "device slot 62 is the compute-PSO override");
163 check(rt::d3d12_xs::device_slot_overridden(76), "device slot 76 is the resource override"); 163 check(rt::d3d12_xs::device_slot_overridden(76), "device slot 76 is the resource override");
164 check(rt::d3d12_xs::device_slot_overridden(86), "device slot 86 is the CreatePipelineState override");
165 check(rt::d3d12_xs::device_slot_overridden(101), "device slot 101 is the CreateStateObject override");
166 check(rt::d3d12_xs::device_slot_overridden(108), "device slot 108 is the GetResourceAllocationInfo2 override");
164 check(rt::d3d12_xs::device_slot_overridden(67), 167 check(rt::d3d12_xs::device_slot_overridden(67),
165 "device slot 67 is the DeserializeComputePipelineStateX override (console native-code compute pipeline, not PC CreateProtectedResourceSession1)"); 168 "device slot 67 is the DeserializeComputePipelineStateX override (console native-code compute pipeline, not PC CreateProtectedResourceSession1)");
166 169
@@ -540,6 +543,101 @@ int main(int argc, char** argv) {
540 check(SUCCEEDED(hr) && pso67 != nullptr, "slot 67 creates a compute PSO via CreateComputePipelineState"); 543 check(SUCCEEDED(hr) && pso67 != nullptr, "slot 67 creates a compute PSO via CreateComputePipelineState");
541 check(rt::d3d12_xs::device_slot_hits(67) == 1, "slot 67 hit counter is 1"); 544 check(rt::d3d12_xs::device_slot_hits(67) == 1, "slot 67 hit counter is 1");
542 check(rt::d3d12_xs::device_slot_first_call_seen(67), "slot 67 first-call flag is set"); 545 check(rt::d3d12_xs::device_slot_first_call_seen(67), "slot 67 first-call flag is set");
546
547 // Slot 86: CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**), forwarded to PC
548 // ID3D12Device2::CreatePipelineState (PC slot 47).
549 if (slots > 47) {
550 struct alignas(void*) ComputeStream {
551 alignas(void*) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE root_type =
552 D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE;
553 ID3D12RootSignature* root_sig = nullptr;
554 alignas(void*) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE cs_type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS;
555 D3D12_SHADER_BYTECODE cs{};
556 } stream;
557 stream.root_sig = root_signature.Get();
558 stream.cs.pShaderBytecode = bytecode->GetBufferPointer();
559 stream.cs.BytecodeLength = bytecode->GetBufferSize();
560 D3D12_PIPELINE_STATE_STREAM_DESC stream_desc{sizeof(stream), &stream};
561 using XboxCreatePipelineStateFn =
562 HRESULT(WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, const IID*, void**);
563 auto create_stream_pso = reinterpret_cast<XboxCreatePipelineStateFn>(proxy_vtbl[86]);
564 ComPtr<ID3D12PipelineState> pso86;
565 hr = create_stream_pso(device.Get(), &stream_desc, &iid_pso,
566 reinterpret_cast<void**>(pso86.GetAddressOf()));
567 check(SUCCEEDED(hr) && pso86 != nullptr,
568 "slot 86 creates a PSO via PC ID3D12Device2::CreatePipelineState (slot 47)");
569 check(rt::d3d12_xs::device_slot_hits(86) == 1, "slot 86 hit counter is 1");
570 check(rt::d3d12_xs::device_slot_first_call_seen(86), "slot 86 first-call flag is set");
571 }
572 }
573
574 // Slot 101: CreateStateObject(const D3D12_STATE_OBJECT_DESC*, REFIID, void**), forwarded to PC
575 // ID3D12Device5::CreateStateObject (PC slot 62).
576 if (slots > 62) {
577 using XboxCreateStateObjectFn = HRESULT(WINAPI*)(void*, const D3D12_STATE_OBJECT_DESC*, const IID*, void**);
578 auto create_state_object = reinterpret_cast<XboxCreateStateObjectFn>(proxy_vtbl[101]);
579 D3D12_STATE_OBJECT_DESC empty_so{};
580 empty_so.Type = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE;
581 void* so_out = reinterpret_cast<void*>(0x1111);
582 hr = create_state_object(device.Get(), &empty_so, nullptr, &so_out);
583 check(hr == E_POINTER && so_out == nullptr, "slot 101 nulls its output for a null IID");
584 check(rt::d3d12_xs::device_slot_hits(101) == 1, "slot 101 hit counter is 1");
585 }
586
587 // Slot 108: GetResourceAllocationInfo2(ret, this, visible_mask, count, descs, info1) with C-ABI struct return,
588 // 56-byte D3D12_RESOURCE_DESC entries, and Xbox layout/flag words, compared against direct PC
589 // ID3D12Device8::GetResourceAllocationInfo2 (PC slot 68).
590 if (slots > 68) {
591 ComPtr<ID3D12Device8> real_device8;
592 if (real && SUCCEEDED(real->QueryInterface(IID_PPV_ARGS(real_device8.GetAddressOf()))) && real_device8) {
593 D3D12_RESOURCE_DESC xbox_descs[2]{};
594 xbox_descs[0].Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
595 xbox_descs[0].Width = 64;
596 xbox_descs[0].Height = 64;
597 xbox_descs[0].DepthOrArraySize = 1;
598 xbox_descs[0].MipLevels = 1;
599 xbox_descs[0].Format = DXGI_FORMAT_R8G8B8A8_UNORM;
600 xbox_descs[0].SampleDesc.Count = 1;
601 xbox_descs[0].Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x105);
602 xbox_descs[0].Flags = static_cast<D3D12_RESOURCE_FLAGS>(
603 D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | 0x300000u);
604 xbox_descs[1].Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
605 xbox_descs[1].Width = 4096;
606 xbox_descs[1].Height = 1;
607 xbox_descs[1].DepthOrArraySize = 1;
608 xbox_descs[1].MipLevels = 1;
609 xbox_descs[1].SampleDesc.Count = 1;
610 xbox_descs[1].Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);
611 xbox_descs[1].Flags = static_cast<D3D12_RESOURCE_FLAGS>(0x200000u);
612
613 D3D12_RESOURCE_DESC1 pc_descs[2]{};
614 std::memcpy(&pc_descs[0], &xbox_descs[0], sizeof(D3D12_RESOURCE_DESC));
615 pc_descs[0].SamplerFeedbackMipRegion = {};
616 pc_descs[0].Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
617 pc_descs[0].Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
618 std::memcpy(&pc_descs[1], &xbox_descs[1], sizeof(D3D12_RESOURCE_DESC));
619 pc_descs[1].SamplerFeedbackMipRegion = {};
620 pc_descs[1].Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
621 pc_descs[1].Flags = D3D12_RESOURCE_FLAG_NONE;
622
623 D3D12_RESOURCE_ALLOCATION_INFO1 pc_info1[2]{};
624 const D3D12_RESOURCE_ALLOCATION_INFO pc_info =
625 real_device8->GetResourceAllocationInfo2(1, 2, pc_descs, pc_info1);
626
627 using XboxGetAllocInfo2CAbiFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(
628 D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, const D3D12_RESOURCE_DESC*,
629 D3D12_RESOURCE_ALLOCATION_INFO1*);
630 auto get_alloc_info2 = reinterpret_cast<XboxGetAllocInfo2CAbiFn>(proxy_vtbl[108]);
631 D3D12_RESOURCE_ALLOCATION_INFO xbox_info{};
632 D3D12_RESOURCE_ALLOCATION_INFO1 xbox_info1[2]{};
633 D3D12_RESOURCE_ALLOCATION_INFO* ret_ptr =
634 get_alloc_info2(&xbox_info, device.Get(), 1, 2, xbox_descs, xbox_info1);
635 check(ret_ptr == &xbox_info && xbox_info.SizeInBytes == pc_info.SizeInBytes &&
636 xbox_info.Alignment == pc_info.Alignment && xbox_info1[0].SizeInBytes == pc_info1[0].SizeInBytes &&
637 xbox_info1[1].SizeInBytes == pc_info1[1].SizeInBytes,
638 "slot 108 C-ABI GetResourceAllocationInfo2 with 56-byte Xbox descs matches PC Device8");
639 check(rt::d3d12_xs::device_slot_hits(108) == 1, "slot 108 hit counter is 1");
640 }
543 } 641 }
544 642
545 // _COM_Outptr_ (d3d12.h): a failed create leaves NULL in the output. WARP accepts invalid heap descriptions, 643 // _COM_Outptr_ (d3d12.h): a failed create leaves NULL in the output. WARP accepts invalid heap descriptions,