// ID3D12GraphicsCommandList8 on the Vulkan-backed COM surface: QueryInterface for the public IID, its one method // with two UINT parameters, the values the layer records, and the reference count. Creating an allocator and a // command list needs neither a GPU nor the Vulkan loader, so this runs as a plain CPU test. // // The method is recorded but not applied: the backend has no pipeline or draw path that could consume per-face // stencil references yet (docs/d3d12_vulkan.md section 3.2). #include "../shims/d3d12_com.h" #include #include #define EXPECT(condition) do { \ if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ } while (0) namespace { template struct Ref { T* p = nullptr; ~Ref() { if (p) p->Release(); } }; } // namespace int main() { using namespace rt::d3d12; Ref allocator; Ref list7; EXPECT(SUCCEEDED(create_command_allocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator.p)))); EXPECT(SUCCEEDED(create_command_list(D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.p, IID_PPV_ARGS(&list7.p)))); // AddRef through the GCL7 pointer gives the count this test expects while the QueryInterface reference is held. const ULONG held = list7.p->AddRef(); list7.p->Release(); { Ref list8; EXPECT(SUCCEEDED(list7.p->QueryInterface(IID_PPV_ARGS(&list8.p)))); EXPECT(list8.p != nullptr); EXPECT(static_cast(list8.p) == static_cast(list7.p)); EXPECT(list7.p->AddRef() == held + 1); // QueryInterface holds one reference list7.p->Release(); list8.p->OMSetFrontAndBackStencilRef(1, 2); UINT front = 0, back = 0; EXPECT(front_back_stencil_ref(list8.p, front, back)); EXPECT(front == 1 && back == 2); // Both parameters are UINTs, not bytes. list8.p->OMSetFrontAndBackStencilRef(0xffffffffu, 0x80000000u); EXPECT(front_back_stencil_ref(list8.p, front, back)); EXPECT(front == 0xffffffffu && back == 0x80000000u); // The method really is at the SDK's GCL8 slot: IUnknown 0-2, ID3D12Object 3-6, ID3D12DeviceChild 7, // ID3D12CommandList 8, GCL 9-59, GCL1 60-65, GCL2 66, GCL3 67, GCL4 68-76, GCL5 77-78, GCL6 79, // GCL7 80 (Barrier), GCL8 81 (byte offset 0x288) in d3d12.h 10.0.26100.0. constexpr std::size_t kStencilRefSlot = 81; using StencilRefFn = void (STDMETHODCALLTYPE*)(ID3D12GraphicsCommandList8*, UINT, UINT); void** vtable = *reinterpret_cast(list8.p); reinterpret_cast(vtable[kStencilRefSlot])(list8.p, 3, 4); EXPECT(front_back_stencil_ref(list8.p, front, back)); EXPECT(front == 3 && back == 4); EXPECT(list8.p->Close() == S_OK); EXPECT(SUCCEEDED(list7.p->Reset(allocator.p, nullptr))); EXPECT(front_back_stencil_ref(list8.p, front, back)); EXPECT(front == 0 && back == 0); // Reset returns list state to its default } EXPECT(list7.p->AddRef() == held); // QueryInterface released its reference list7.p->Release(); UINT ignored_front = 0, ignored_back = 0; EXPECT(!front_back_stencil_ref(nullptr, ignored_front, ignored_back)); std::printf("GCL8: QueryInterface, OMSetFrontAndBackStencilRef(1, 2), refcount balanced\n"); return 0; }