diff options
| author | Senne Cools <113857183+sennecools@users.noreply.github.com> | 2026-11-23 16:59:58 +0100 |
|---|---|---|
| committer | Senne Cools <113857183+sennecools@users.noreply.github.com> | 2026-11-23 16:59:58 +0100 |
| commit | 0d73e8b95d9af460227efbce4b7ec182764abe2d (patch) | |
| tree | f4a648ed50de144ce45ae3c16926ef9ec2a91dab /runtime/shims/d3d12_com.cpp | |
| parent | 23e9c9535dce7fe32049c99205c0629893bef932 (diff) | |
| parent | 4da521de3ec672d69216302d29dc291614b8e6b9 (diff) | |
Merge origin/main: slot 26 next to the Xbox slot routes
AI-assisted.
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 55b523d96..4dd766b31 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -90,6 +90,7 @@ const char* name(leonida::ReplayResult result) { | |||
| 90 | case leonida::ReplayResult::invalid_copy: return "invalid copy or resolve"; | 90 | case leonida::ReplayResult::invalid_copy: return "invalid copy or resolve"; |
| 91 | case leonida::ReplayResult::invalid_query: return "invalid query"; | 91 | case leonida::ReplayResult::invalid_query: return "invalid query"; |
| 92 | case leonida::ReplayResult::invalid_indirect_arguments: return "invalid indirect argument or count buffer range"; | 92 | case leonida::ReplayResult::invalid_indirect_arguments: return "invalid indirect argument or count buffer range"; |
| 93 | case leonida::ReplayResult::invalid_draw: return "draw kind does not match the pipeline (mesh or vertex)"; | ||
| 93 | case leonida::ReplayResult::unsupported: return "unsupported"; | 94 | case leonida::ReplayResult::unsupported: return "unsupported"; |
| 94 | } | 95 | } |
| 95 | return "?"; | 96 | return "?"; |
| @@ -433,6 +434,20 @@ public: | |||
| 433 | record_draw(true, indices, instances, first_index, base_vertex, first_instance); | 434 | record_draw(true, indices, instances, first_index, base_vertex, first_instance); |
| 434 | } | 435 | } |
| 435 | 436 | ||
| 437 | // ID3D12GraphicsCommandList6: a mesh draw. The bound graphics pipeline must have a mesh shader (checked at | ||
| 438 | // execution, where the pipeline is resolved). D3D12 caps each count at 65535 and their product at 2^22 | ||
| 439 | // (D3D12_MS_DISPATCH_MAX_THREAD_GROUPS_PER_GRID); a larger grid is a recording error. | ||
| 440 | void STDMETHODCALLTYPE DispatchMesh(UINT x, UINT y, UINT z) override { | ||
| 441 | d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh"); | ||
| 442 | if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false); | ||
| 443 | if (!graphics_pipeline_ || !graphics_.layout) return check(false); | ||
| 444 | if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized | ||
| 445 | leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_, | ||
| 446 | scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; | ||
| 447 | draw.mesh = true; | ||
| 448 | check(list_.draw(std::move(draw))); | ||
| 449 | } | ||
| 450 | |||
| 436 | void STDMETHODCALLTYPE ResourceBarrier(UINT count, const D3D12_RESOURCE_BARRIER* barriers) override { | 451 | void STDMETHODCALLTYPE ResourceBarrier(UINT count, const D3D12_RESOURCE_BARRIER* barriers) override { |
| 437 | d3d12_trace::record("ID3D12GraphicsCommandList::ResourceBarrier"); | 452 | d3d12_trace::record("ID3D12GraphicsCommandList::ResourceBarrier"); |
| 438 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | 453 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); |
| @@ -749,6 +764,29 @@ public: | |||
| 749 | UINT stride = 0; | 764 | UINT stride = 0; |
| 750 | if (!command_signature_info(signature, kind, stride) || !argument_buffer) | 765 | if (!command_signature_info(signature, kind, stride) || !argument_buffer) |
| 751 | return check(false); | 766 | return check(false); |
| 767 | const auto arg_desc = argument_buffer->GetDesc(); | ||
| 768 | if (arg_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || argument_buffer_offset % 4 != 0) | ||
| 769 | return check(false); | ||
| 770 | if (count_buffer) { | ||
| 771 | const auto count_desc = count_buffer->GetDesc(); | ||
| 772 | if (count_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || count_buffer_offset % 4 != 0 || | ||
| 773 | count_desc.Width < sizeof(UINT) || count_buffer_offset > count_desc.Width - sizeof(UINT)) | ||
| 774 | return check(false); | ||
| 775 | } else if (count_buffer_offset != 0) { | ||
| 776 | return check(false); | ||
| 777 | } | ||
| 778 | if (max_command_count) { | ||
| 779 | const UINT64 record_size = | ||
| 780 | kind == leonida::IndirectKind::draw ? sizeof(D3D12_DRAW_ARGUMENTS) | ||
| 781 | : kind == leonida::IndirectKind::draw_indexed ? sizeof(D3D12_DRAW_INDEXED_ARGUMENTS) | ||
| 782 | : kind == leonida::IndirectKind::dispatch ? sizeof(D3D12_DISPATCH_ARGUMENTS) | ||
| 783 | : 0; | ||
| 784 | if (!record_size || stride < record_size || stride % 4 != 0) | ||
| 785 | return check(false); | ||
| 786 | const UINT64 required = UINT64(max_command_count - 1) * stride + record_size; | ||
| 787 | if (argument_buffer_offset > arg_desc.Width || arg_desc.Width - argument_buffer_offset < required) | ||
| 788 | return check(false); | ||
| 789 | } | ||
| 752 | leonida::ExecuteIndirect cmd{}; | 790 | leonida::ExecuteIndirect cmd{}; |
| 753 | cmd.kind = kind; | 791 | cmd.kind = kind; |
| 754 | cmd.stride = stride; | 792 | cmd.stride = stride; |
| @@ -769,7 +807,17 @@ public: | |||
| 769 | const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT postbuild_count, | 807 | const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT postbuild_count, |
| 770 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* postbuild) override { | 808 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* postbuild) override { |
| 771 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false); | 809 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false); |
| 810 | if (postbuild_count && !postbuild) return check(false); | ||
| 811 | for (UINT i = 0; i < postbuild_count; ++i) { | ||
| 812 | if (!valid_postbuild_info_type(postbuild[i].InfoType)) return check(false); | ||
| 813 | } | ||
| 772 | const auto& in = desc->Inputs; | 814 | const auto& in = desc->Inputs; |
| 815 | if (in.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL && | ||
| 816 | in.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL) | ||
| 817 | return check(false); | ||
| 818 | if (in.DescsLayout != D3D12_ELEMENTS_LAYOUT_ARRAY && | ||
| 819 | in.DescsLayout != D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS) | ||
| 820 | return check(false); | ||
| 773 | leonida::BuildAccelerationStructure cmd{}; | 821 | leonida::BuildAccelerationStructure cmd{}; |
| 774 | cmd.is_tlas = (in.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL); | 822 | cmd.is_tlas = (in.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL); |
| 775 | cmd.update = (in.Flags & D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE) != 0; | 823 | cmd.update = (in.Flags & D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE) != 0; |
| @@ -844,6 +892,7 @@ public: | |||
| 844 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* desc, UINT count, | 892 | const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* desc, UINT count, |
| 845 | const D3D12_GPU_VIRTUAL_ADDRESS* sources) override { | 893 | const D3D12_GPU_VIRTUAL_ADDRESS* sources) override { |
| 846 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc || !count || !sources) return check(false); | 894 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc || !count || !sources) return check(false); |
| 895 | if (!valid_postbuild_info_type(desc->InfoType)) return check(false); | ||
| 847 | leonida::AccelerationStructurePostbuild info{}; | 896 | leonida::AccelerationStructurePostbuild info{}; |
| 848 | info.dest_va = desc->DestBuffer; | 897 | info.dest_va = desc->DestBuffer; |
| 849 | info.type = static_cast<std::uint32_t>(desc->InfoType); | 898 | info.type = static_cast<std::uint32_t>(desc->InfoType); |
| @@ -855,12 +904,37 @@ public: | |||
| 855 | D3D12_GPU_VIRTUAL_ADDRESS source, | 904 | D3D12_GPU_VIRTUAL_ADDRESS source, |
| 856 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) override { | 905 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) override { |
| 857 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | 906 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); |
| 907 | if (!valid_copy_mode(mode)) return check(false); | ||
| 858 | check(list_.copy_acceleration_structure({dest, source, static_cast<std::uint32_t>(mode)})); | 908 | check(list_.copy_acceleration_structure({dest, source, static_cast<std::uint32_t>(mode)})); |
| 859 | } | 909 | } |
| 860 | 910 | ||
| 861 | static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); } | 911 | static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); } |
| 862 | 912 | ||
| 863 | private: | 913 | private: |
| 914 | static bool valid_postbuild_info_type(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_TYPE type) { | ||
| 915 | switch (type) { | ||
| 916 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE: | ||
| 917 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_TOOLS_VISUALIZATION: | ||
| 918 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION: | ||
| 919 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_CURRENT_SIZE: | ||
| 920 | return true; | ||
| 921 | default: | ||
| 922 | return false; | ||
| 923 | } | ||
| 924 | } | ||
| 925 | |||
| 926 | static bool valid_copy_mode(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) { | ||
| 927 | switch (mode) { | ||
| 928 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_CLONE: | ||
| 929 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_COMPACT: | ||
| 930 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_VISUALIZATION_DECODE_FOR_TOOLS: | ||
| 931 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_SERIALIZE: | ||
| 932 | case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_DESERIALIZE: | ||
| 933 | return true; | ||
| 934 | default: | ||
| 935 | return false; | ||
| 936 | } | ||
| 937 | } | ||
| 864 | template<class E> | 938 | template<class E> |
| 865 | static std::uint32_t u(E value) { | 939 | static std::uint32_t u(E value) { |
| 866 | return static_cast<std::uint32_t>(value); | 940 | return static_cast<std::uint32_t>(value); |