upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/d3d12_com.cpp
diff options
context:
space:
mode:
authorDennis Schöneberg <schoenebergde@gmail.com>2026-11-23 16:49:28 +0100
committerGitHub <noreply@github.com>2026-11-23 09:49:28 -0600
commit2c72b0d28147d336a106f35d0ee76cd6635652dd (patch)
tree9f0d750ec845b00604b4a620d12f76d72ed14922 /runtime/shims/d3d12_com.cpp
parent0805d30d5411ca0df33eeede637442518b3f6169 (diff)
d3d12: validate DXR acceleration-structure prebuild and recording inputs (#6825)
Squash-merged after diff review of PR #6825 - d3d12: validate DXR acceleration-structure prebuild and recording inputs
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
-rw-r--r--runtime/shims/d3d12_com.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index 987dd2d64..d66e6803c 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -784,7 +784,17 @@ public:
784 const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT postbuild_count, 784 const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc, UINT postbuild_count,
785 const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* postbuild) override { 785 const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* postbuild) override {
786 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false); 786 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc) return check(false);
787 if (postbuild_count && !postbuild) return check(false);
788 for (UINT i = 0; i < postbuild_count; ++i) {
789 if (!valid_postbuild_info_type(postbuild[i].InfoType)) return check(false);
790 }
787 const auto& in = desc->Inputs; 791 const auto& in = desc->Inputs;
792 if (in.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL &&
793 in.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL)
794 return check(false);
795 if (in.DescsLayout != D3D12_ELEMENTS_LAYOUT_ARRAY &&
796 in.DescsLayout != D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS)
797 return check(false);
788 leonida::BuildAccelerationStructure cmd{}; 798 leonida::BuildAccelerationStructure cmd{};
789 cmd.is_tlas = (in.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL); 799 cmd.is_tlas = (in.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL);
790 cmd.update = (in.Flags & D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE) != 0; 800 cmd.update = (in.Flags & D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE) != 0;
@@ -859,6 +869,7 @@ public:
859 const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* desc, UINT count, 869 const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC* desc, UINT count,
860 const D3D12_GPU_VIRTUAL_ADDRESS* sources) override { 870 const D3D12_GPU_VIRTUAL_ADDRESS* sources) override {
861 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc || !count || !sources) return check(false); 871 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !desc || !count || !sources) return check(false);
872 if (!valid_postbuild_info_type(desc->InfoType)) return check(false);
862 leonida::AccelerationStructurePostbuild info{}; 873 leonida::AccelerationStructurePostbuild info{};
863 info.dest_va = desc->DestBuffer; 874 info.dest_va = desc->DestBuffer;
864 info.type = static_cast<std::uint32_t>(desc->InfoType); 875 info.type = static_cast<std::uint32_t>(desc->InfoType);
@@ -870,12 +881,37 @@ public:
870 D3D12_GPU_VIRTUAL_ADDRESS source, 881 D3D12_GPU_VIRTUAL_ADDRESS source,
871 D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) override { 882 D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) override {
872 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); 883 if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false);
884 if (!valid_copy_mode(mode)) return check(false);
873 check(list_.copy_acceleration_structure({dest, source, static_cast<std::uint32_t>(mode)})); 885 check(list_.copy_acceleration_structure({dest, source, static_cast<std::uint32_t>(mode)}));
874 } 886 }
875 887
876 static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); } 888 static GraphicsCommandList* from(IUnknown* object) { return Child::from<GraphicsCommandList>(object); }
877 889
878private: 890private:
891 static bool valid_postbuild_info_type(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_TYPE type) {
892 switch (type) {
893 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE:
894 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_TOOLS_VISUALIZATION:
895 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION:
896 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_CURRENT_SIZE:
897 return true;
898 default:
899 return false;
900 }
901 }
902
903 static bool valid_copy_mode(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) {
904 switch (mode) {
905 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_CLONE:
906 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_COMPACT:
907 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_VISUALIZATION_DECODE_FOR_TOOLS:
908 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_SERIALIZE:
909 case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_DESERIALIZE:
910 return true;
911 default:
912 return false;
913 }
914 }
879 template<class E> 915 template<class E>
880 static std::uint32_t u(E value) { 916 static std::uint32_t u(E value) {
881 return static_cast<std::uint32_t>(value); 917 return static_cast<std::uint32_t>(value);