diff options
| author | ASTROWwwW <astrxwledev@gmail.com> | 2026-11-23 19:38:48 +0100 |
|---|---|---|
| committer | ASTROWwwW <astrxwledev@gmail.com> | 2026-11-23 19:38:48 +0100 |
| commit | 5caef48a194d1a39d0568427cdbb4da22a482817 (patch) | |
| tree | e11ac7fe306d4247a3cb432fbeddafe3896bca88 /runtime/shims/d3d12_com.cpp | |
| parent | 8644ce10dc3ef16e18d07cb59c50edcf6d65a827 (diff) | |
| parent | 39b757a6d283fedd32715f84107356b2250d7db9 (diff) | |
Merge branch 'pr7111' into ladder-frame
# Conflicts:
# docs/runtime_imports.md
# runtime/CMakeLists.txt
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 356f8b0c8..e1408d281 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -370,10 +370,12 @@ public: | |||
| 370 | record_dispatch(x, y, z); | 370 | record_dispatch(x, y, z); |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | // ClearState returns every piece of list state to its default, as Reset does (stencil references included). | 373 | // ClearState returns every piece of list state to its default, as Reset does (stencil references and predication |
| 374 | // included). | ||
| 374 | void STDMETHODCALLTYPE ClearState(ID3D12PipelineState* state) override { | 375 | void STDMETHODCALLTYPE ClearState(ID3D12PipelineState* state) override { |
| 375 | if (list_.closed()) return; | 376 | if (list_.closed()) return; |
| 376 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | 377 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); |
| 378 | if (!list_.closed()) check(list_.set_predication({0, 0, 0})); | ||
| 377 | reset_state(state); | 379 | reset_state(state); |
| 378 | } | 380 | } |
| 379 | 381 | ||
| @@ -670,10 +672,24 @@ public: | |||
| 670 | check(list_.resolve_subresource({resource_id(dst), dst_subresource, resource_id(src), src_subresource, region})); | 672 | check(list_.resolve_subresource({resource_id(dst), dst_subresource, resource_id(src), src_subresource, region})); |
| 671 | } | 673 | } |
| 672 | 674 | ||
| 673 | // A null buffer turns predication off (docs/d3d12_vulkan.md section 4.7). Bundles may not set it. | 675 | // A null buffer turns predication off (docs/d3d12_vulkan.md section 4.7). Bundles and copy lists may not set it. |
| 676 | // Recording-time checks match live Windows 11 WARP and RTX 5090 D3D12: null buffer requires offset 0 and | ||
| 677 | // EQUAL_ZERO; a non-null resource must be a non-READBACK buffer with an 8-byte aligned in-bounds range. | ||
| 674 | void STDMETHODCALLTYPE SetPredication(ID3D12Resource* buffer, UINT64 offset, D3D12_PREDICATION_OP op) override { | 678 | void STDMETHODCALLTYPE SetPredication(ID3D12Resource* buffer, UINT64 offset, D3D12_PREDICATION_OP op) override { |
| 675 | d3d12_trace::record("ID3D12GraphicsCommandList::SetPredication"); | 679 | d3d12_trace::record("ID3D12GraphicsCommandList::SetPredication"); |
| 676 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || type_ == D3D12_COMMAND_LIST_TYPE_COPY) return check(false); | 680 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || type_ == D3D12_COMMAND_LIST_TYPE_COPY) return check(false); |
| 681 | if (!buffer) { | ||
| 682 | if (offset != 0 || op != D3D12_PREDICATION_OP_EQUAL_ZERO) return check(false); | ||
| 683 | return check(list_.set_predication({0, 0, 0})); | ||
| 684 | } | ||
| 685 | const auto desc = buffer->GetDesc(); | ||
| 686 | if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return check(false); | ||
| 687 | if (offset % leonida::predication_alignment != 0 || offset > desc.Width || | ||
| 688 | desc.Width - offset < leonida::predication_alignment) | ||
| 689 | return check(false); | ||
| 690 | D3D12_HEAP_PROPERTIES heap{}; | ||
| 691 | if (SUCCEEDED(buffer->GetHeapProperties(&heap, nullptr)) && heap.Type == D3D12_HEAP_TYPE_READBACK) | ||
| 692 | return check(false); | ||
| 677 | check(list_.set_predication({resource_id(buffer), offset, u(op)})); | 693 | check(list_.set_predication({resource_id(buffer), offset, u(op)})); |
| 678 | } | 694 | } |
| 679 | 695 | ||
| @@ -1019,14 +1035,67 @@ private: | |||
| 1019 | allocator_ = nullptr; | 1035 | allocator_ = nullptr; |
| 1020 | } | 1036 | } |
| 1021 | 1037 | ||
| 1038 | static UINT subresource_count(const D3D12_RESOURCE_DESC& desc) { | ||
| 1039 | if (desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return 1; | ||
| 1040 | const UINT mips = desc.MipLevels ? desc.MipLevels : 1u; | ||
| 1041 | const UINT layers = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D | ||
| 1042 | ? 1u | ||
| 1043 | : (desc.DepthOrArraySize ? desc.DepthOrArraySize : 1u); | ||
| 1044 | UINT planes = 1; | ||
| 1045 | switch (desc.Format) { | ||
| 1046 | case DXGI_FORMAT_D24_UNORM_S8_UINT: | ||
| 1047 | case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: | ||
| 1048 | case DXGI_FORMAT_R24G8_TYPELESS: | ||
| 1049 | case DXGI_FORMAT_R32G8X24_TYPELESS: | ||
| 1050 | case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: | ||
| 1051 | case DXGI_FORMAT_X24_TYPELESS_G8_UINT: | ||
| 1052 | case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: | ||
| 1053 | case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: | ||
| 1054 | case DXGI_FORMAT_NV12: | ||
| 1055 | case DXGI_FORMAT_P010: | ||
| 1056 | case DXGI_FORMAT_P016: | ||
| 1057 | planes = 2; | ||
| 1058 | break; | ||
| 1059 | default: | ||
| 1060 | break; | ||
| 1061 | } | ||
| 1062 | return mips * layers * planes; | ||
| 1063 | } | ||
| 1064 | |||
| 1022 | void atomic_copy(std::uint32_t bytes, ID3D12Resource* dst, UINT64 dst_offset, ID3D12Resource* src, | 1065 | void atomic_copy(std::uint32_t bytes, ID3D12Resource* dst, UINT64 dst_offset, ID3D12Resource* src, |
| 1023 | UINT64 src_offset, UINT count, ID3D12Resource* const* resources, | 1066 | UINT64 src_offset, UINT count, ID3D12Resource* const* resources, |
| 1024 | const D3D12_SUBRESOURCE_RANGE_UINT64* ranges) { | 1067 | const D3D12_SUBRESOURCE_RANGE_UINT64* ranges) { |
| 1025 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || (count && (!resources || !ranges))) return check(false); | 1068 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !dst || !src || (count && (!resources || !ranges))) |
| 1069 | return check(false); | ||
| 1070 | const auto dst_desc = dst->GetDesc(); | ||
| 1071 | const auto src_desc = src->GetDesc(); | ||
| 1072 | if (dst_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || | ||
| 1073 | src_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) | ||
| 1074 | return check(false); | ||
| 1075 | if (dst_offset % bytes != 0 || src_offset % bytes != 0 || dst_offset > dst_desc.Width || | ||
| 1076 | dst_desc.Width - dst_offset < bytes || src_offset > src_desc.Width || src_desc.Width - src_offset < bytes) | ||
| 1077 | return check(false); | ||
| 1026 | leonida::AtomicCopyBuffer copy{resource_id(dst), dst_offset, resource_id(src), src_offset, bytes, {}}; | 1078 | leonida::AtomicCopyBuffer copy{resource_id(dst), dst_offset, resource_id(src), src_offset, bytes, {}}; |
| 1027 | for (UINT i = 0; i < count; ++i) | 1079 | copy.dependencies.reserve(count); |
| 1028 | copy.dependencies.push_back( | 1080 | for (UINT i = 0; i < count; ++i) { |
| 1029 | {resource_id(resources[i]), ranges[i].Subresource, ranges[i].Range.Begin, ranges[i].Range.End}); | 1081 | ID3D12Resource* dep = resources[i]; |
| 1082 | if (!dep) return check(false); | ||
| 1083 | const auto dep_desc = dep->GetDesc(); | ||
| 1084 | const auto& r = ranges[i]; | ||
| 1085 | UINT64 begin = r.Range.Begin; | ||
| 1086 | UINT64 end = r.Range.End; | ||
| 1087 | if (dep_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { | ||
| 1088 | if (r.Subresource != 0) return check(false); | ||
| 1089 | if (begin >= end || (end != UINT64_MAX && end > dep_desc.Width)) | ||
| 1090 | return check(false); | ||
| 1091 | } else { | ||
| 1092 | const UINT total_subresources = subresource_count(dep_desc); | ||
| 1093 | if (r.Subresource != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && r.Subresource >= total_subresources) | ||
| 1094 | return check(false); | ||
| 1095 | if (begin != 0 || end != UINT64_MAX) return check(false); | ||
| 1096 | } | ||
| 1097 | copy.dependencies.push_back({resource_id(dep), r.Subresource, begin, end}); | ||
| 1098 | } | ||
| 1030 | check(list_.atomic_copy(copy)); | 1099 | check(list_.atomic_copy(copy)); |
| 1031 | } | 1100 | } |
| 1032 | 1101 | ||