diff options
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 7e428735d..55c6f86a8 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -113,8 +113,9 @@ class CommandAllocator final | |||
| 113 | : public Child<CommandAllocator, ID3D12CommandAllocatorStubs, ID3D12Object, ID3D12DeviceChild, ID3D12Pageable, | 113 | : public Child<CommandAllocator, ID3D12CommandAllocatorStubs, ID3D12Object, ID3D12DeviceChild, ID3D12Pageable, |
| 114 | ID3D12CommandAllocator> { | 114 | ID3D12CommandAllocator> { |
| 115 | public: | 115 | public: |
| 116 | // {7d0e6b51-34a2-4f0c-9a61-0c5b2e8f4a10} | 116 | // {7d0e6b51-34a2-4f0c-9a61-0c5b2e8f4a10}, public in d3d12_xs_device.h: the device proxy's slot 9 wraps an allocator |
| 117 | static constexpr GUID kTag{0x7d0e6b51, 0x34a2, 0x4f0c, {0x9a, 0x61, 0x0c, 0x5b, 0x2e, 0x8f, 0x4a, 0x10}}; | 117 | // in an Xbox-ABI allocator proxy only when it answers this tag, because from() below resolves such a proxy. |
| 118 | static constexpr GUID kTag = d3d12_xs::kLeonidaCommandAllocatorTag; | ||
| 118 | explicit CommandAllocator(D3D12_COMMAND_LIST_TYPE type) : type_(type) {} | 119 | explicit CommandAllocator(D3D12_COMMAND_LIST_TYPE type) : type_(type) {} |
| 119 | // Lists own their recorded commands, so there is nothing to free. As on the PC runtime (D3D-51, measured by | 120 | // Lists own their recorded commands, so there is nothing to free. As on the PC runtime (D3D-51, measured by |
| 120 | // d3d12_vulkan_device_test): E_FAIL while a list is recording into this allocator, and S_OK while its lists are | 121 | // d3d12_vulkan_device_test): E_FAIL while a list is recording into this allocator, and S_OK while its lists are |
| @@ -124,7 +125,12 @@ public: | |||
| 124 | // The one list that is recording into this allocator, or null. D3D12 allows one at a time. | 125 | // The one list that is recording into this allocator, or null. D3D12 allows one at a time. |
| 125 | const void* recording() const { return recording_; } | 126 | const void* recording() const { return recording_; } |
| 126 | void set_recording(const void* list) { recording_ = list; } | 127 | void set_recording(const void* list) { recording_ = list; } |
| 127 | static CommandAllocator* from(IUnknown* object) { return Child::from<CommandAllocator>(object); } | 128 | // An allocator proxy (the title's allocator from device slot 9) stands for the allocator behind it, so every |
| 129 | // list method that takes an allocator (CreateCommandList, Reset) resolves it here. | ||
| 130 | static CommandAllocator* from(IUnknown* object) { | ||
| 131 | if (ID3D12CommandAllocator* real = d3d12_xs::allocator_proxy_real_allocator(object)) object = real; | ||
| 132 | return Child::from<CommandAllocator>(object); | ||
| 133 | } | ||
| 128 | 134 | ||
| 129 | private: | 135 | private: |
| 130 | D3D12_COMMAND_LIST_TYPE type_; | 136 | D3D12_COMMAND_LIST_TYPE type_; |
| @@ -214,10 +220,14 @@ public: | |||
| 214 | bind_root(compute_, signature); | 220 | bind_root(compute_, signature); |
| 215 | } | 221 | } |
| 216 | void STDMETHODCALLTYPE SetGraphicsRootSignature(ID3D12RootSignature* signature) override { | 222 | void STDMETHODCALLTYPE SetGraphicsRootSignature(ID3D12RootSignature* signature) override { |
| 223 | d3d12_trace::record("ID3D12GraphicsCommandList::SetGraphicsRootSignature"); | ||
| 217 | bind_root(graphics_, signature); | 224 | bind_root(graphics_, signature); |
| 218 | } | 225 | } |
| 219 | 226 | ||
| 220 | void STDMETHODCALLTYPE SetPipelineState(ID3D12PipelineState* state) override { set_pipeline(state); } | 227 | void STDMETHODCALLTYPE SetPipelineState(ID3D12PipelineState* state) override { |
| 228 | d3d12_trace::record("ID3D12GraphicsCommandList::SetPipelineState"); | ||
| 229 | set_pipeline(state); | ||
| 230 | } | ||
| 221 | 231 | ||
| 222 | // The bound heaps matter to direct heap indexing, which is still open (section 3.4); tables carry their VAs. | 232 | // The bound heaps matter to direct heap indexing, which is still open (section 3.4); tables carry their VAs. |
| 223 | void STDMETHODCALLTYPE SetDescriptorHeaps(UINT, ID3D12DescriptorHeap* const*) override {} | 233 | void STDMETHODCALLTYPE SetDescriptorHeaps(UINT, ID3D12DescriptorHeap* const*) override {} |
| @@ -591,12 +601,17 @@ public: | |||
| 591 | cmd.argument_offset = argument_buffer_offset; | 601 | cmd.argument_offset = argument_buffer_offset; |
| 592 | cmd.count_buffer = count_buffer ? resource_id(count_buffer) : 0; | 602 | cmd.count_buffer = count_buffer ? resource_id(count_buffer) : 0; |
| 593 | cmd.count_offset = count_buffer ? count_buffer_offset : 0; | 603 | cmd.count_offset = count_buffer ? count_buffer_offset : 0; |
| 604 | if (kind == leonida::IndirectKind::dispatch && max_command_count) { // the pipeline and root arguments a Dispatch would record | ||
| 605 | if (!compute_pipeline_ || !compute_.layout) return check(false); | ||
| 606 | cmd.pipeline = compute_pipeline_; | ||
| 607 | cmd.user_data = compute_.data; | ||
| 608 | } | ||
| 594 | check(list_.execute_indirect(cmd)); | 609 | check(list_.execute_indirect(cmd)); |
| 595 | } | 610 | } |
| 596 | 611 | ||
| 597 | void STDMETHODCALLTYPE BuildRaytracingAccelerationStructure( | 612 | void STDMETHODCALLTYPE BuildRaytracingAccelerationStructure( |
| 598 | const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT, | 613 | const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT postbuild_count, |
| 599 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC*) override { | 614 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* postbuild) override { |
| 600 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false); | 615 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false); |
| 601 | const auto& in = desc->Inputs; | 616 | const auto& in = desc->Inputs; |
| 602 | leonida::BuildAccelerationStructure cmd{}; | 617 | leonida::BuildAccelerationStructure cmd{}; |
| @@ -650,7 +665,38 @@ public: | |||
| 650 | cmd.triangles.push_back(t); | 665 | cmd.triangles.push_back(t); |
| 651 | } | 666 | } |
| 652 | } | 667 | } |
| 653 | check(list_.build_acceleration_structure(cmd)); | 668 | const std::uint64_t built = cmd.dst_va; |
| 669 | const bool recorded = list_.build_acceleration_structure(std::move(cmd)); | ||
| 670 | check(recorded); | ||
| 671 | if (!recorded) return; | ||
| 672 | // The postbuild values of the structure just built, after it (D3D12 orders them after the build). | ||
| 673 | for (UINT i = 0; postbuild && i < postbuild_count; ++i) { | ||
| 674 | leonida::AccelerationStructurePostbuild info{}; | ||
| 675 | info.dest_va = postbuild[i].DestBuffer; | ||
| 676 | info.type = static_cast<std::uint32_t>(postbuild[i].InfoType); | ||
| 677 | info.sources = {built}; | ||
| 678 | const bool ok = list_.acceleration_structure_postbuild(std::move(info)); | ||
| 679 | check(ok); | ||
| 680 | if (!ok) return; | ||
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 | void STDMETHODCALLTYPE EmitRaytracingAccelerationStructurePostbuildInfo( | ||
| 685 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* desc, UINT count, | ||
| 686 | const D3D12_GPU_VIRTUAL_ADDRESS* sources) override { | ||
| 687 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc || !count || !sources) return check(false); | ||
| 688 | leonida::AccelerationStructurePostbuild info{}; | ||
| 689 | info.dest_va = desc->DestBuffer; | ||
| 690 | info.type = static_cast<std::uint32_t>(desc->InfoType); | ||
| 691 | info.sources.assign(sources, sources + count); | ||
| 692 | check(list_.acceleration_structure_postbuild(std::move(info))); | ||
| 693 | } | ||
| 694 | |||
| 695 | void STDMETHODCALLTYPE CopyRaytracingAccelerationStructure(D3D12_GPU_VIRTUAL_ADDRESS dest, | ||
| 696 | D3D12_GPU_VIRTUAL_ADDRESS source, | ||
| 697 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) override { | ||
| 698 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | ||
| 699 | check(list_.copy_acceleration_structure({dest, source, static_cast<std::uint32_t>(mode)})); | ||
| 654 | } | 700 | } |
| 655 | 701 | ||
| 656 | static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); } | 702 | static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); } |
| @@ -1251,7 +1297,8 @@ HRESULT create_command_list(D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator | |||
| 1251 | if (!command_allocator || command_allocator->type() != type) return E_INVALIDARG; | 1297 | if (!command_allocator || command_allocator->type() != type) return E_INVALIDARG; |
| 1252 | // A list is created open, so the allocator must be free: E_INVALIDARG as on the PC runtime (D3D-51). | 1298 | // A list is created open, so the allocator must be free: E_INVALIDARG as on the PC runtime (D3D-51). |
| 1253 | if (command_allocator->recording()) return E_INVALIDARG; | 1299 | if (command_allocator->recording()) return E_INVALIDARG; |
| 1254 | if (type != D3D12_COMMAND_LIST_TYPE_DIRECT && type != D3D12_COMMAND_LIST_TYPE_BUNDLE) | 1300 | if (type != D3D12_COMMAND_LIST_TYPE_DIRECT && type != D3D12_COMMAND_LIST_TYPE_BUNDLE && |
| 1301 | type != D3D12_COMMAND_LIST_TYPE_COMPUTE && type != D3D12_COMMAND_LIST_TYPE_COPY) | ||
| 1255 | stub("create_command_list(non-direct type)"); | 1302 | stub("create_command_list(non-direct type)"); |
| 1256 | auto* object = new GraphicsCommandList(type); // created open, as D3D12 does | 1303 | auto* object = new GraphicsCommandList(type); // created open, as D3D12 does |
| 1257 | object->record_into(command_allocator); | 1304 | object->record_into(command_allocator); |