diff options
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 e33769c58..f25168a2a 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 | ||
| @@ -1010,14 +1026,67 @@ private: | |||
| 1010 | allocator_ = nullptr; | 1026 | allocator_ = nullptr; |
| 1011 | } | 1027 | } |
| 1012 | 1028 | ||
| 1029 | static UINT subresource_count(const D3D12_RESOURCE_DESC& desc) { | ||
| 1030 | if (desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return 1; | ||
| 1031 | const UINT mips = desc.MipLevels ? desc.MipLevels : 1u; | ||
| 1032 | const UINT layers = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D | ||
| 1033 | ? 1u | ||
| 1034 | : (desc.DepthOrArraySize ? desc.DepthOrArraySize : 1u); | ||
| 1035 | UINT planes = 1; | ||
| 1036 | switch (desc.Format) { | ||
| 1037 | case DXGI_FORMAT_D24_UNORM_S8_UINT: | ||
| 1038 | case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: | ||
| 1039 | case DXGI_FORMAT_R24G8_TYPELESS: | ||
| 1040 | case DXGI_FORMAT_R32G8X24_TYPELESS: | ||
| 1041 | case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: | ||
| 1042 | case DXGI_FORMAT_X24_TYPELESS_G8_UINT: | ||
| 1043 | case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: | ||
| 1044 | case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: | ||
| 1045 | case DXGI_FORMAT_NV12: | ||
| 1046 | case DXGI_FORMAT_P010: | ||
| 1047 | case DXGI_FORMAT_P016: | ||
| 1048 | planes = 2; | ||
| 1049 | break; | ||
| 1050 | default: | ||
| 1051 | break; | ||
| 1052 | } | ||
| 1053 | return mips * layers * planes; | ||
| 1054 | } | ||
| 1055 | |||
| 1013 | void atomic_copy(std::uint32_t bytes, ID3D12Resource* dst, UINT64 dst_offset, ID3D12Resource* src, | 1056 | void atomic_copy(std::uint32_t bytes, ID3D12Resource* dst, UINT64 dst_offset, ID3D12Resource* src, |
| 1014 | UINT64 src_offset, UINT count, ID3D12Resource* const* resources, | 1057 | UINT64 src_offset, UINT count, ID3D12Resource* const* resources, |
| 1015 | const D3D12_SUBRESOURCE_RANGE_UINT64* ranges) { | 1058 | const D3D12_SUBRESOURCE_RANGE_UINT64* ranges) { |
| 1016 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || (count && (!resources || !ranges))) return check(false); | 1059 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE || !dst || !src || (count && (!resources || !ranges))) |
| 1060 | return check(false); | ||
| 1061 | const auto dst_desc = dst->GetDesc(); | ||
| 1062 | const auto src_desc = src->GetDesc(); | ||
| 1063 | if (dst_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || | ||
| 1064 | src_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) | ||
| 1065 | return check(false); | ||
| 1066 | if (dst_offset % bytes != 0 || src_offset % bytes != 0 || dst_offset > dst_desc.Width || | ||
| 1067 | dst_desc.Width - dst_offset < bytes || src_offset > src_desc.Width || src_desc.Width - src_offset < bytes) | ||
| 1068 | return check(false); | ||
| 1017 | leonida::AtomicCopyBuffer copy{resource_id(dst), dst_offset, resource_id(src), src_offset, bytes, {}}; | 1069 | leonida::AtomicCopyBuffer copy{resource_id(dst), dst_offset, resource_id(src), src_offset, bytes, {}}; |
| 1018 | for (UINT i = 0; i < count; ++i) | 1070 | copy.dependencies.reserve(count); |
| 1019 | copy.dependencies.push_back( | 1071 | for (UINT i = 0; i < count; ++i) { |
| 1020 | {resource_id(resources[i]), ranges[i].Subresource, ranges[i].Range.Begin, ranges[i].Range.End}); | 1072 | ID3D12Resource* dep = resources[i]; |
| 1073 | if (!dep) return check(false); | ||
| 1074 | const auto dep_desc = dep->GetDesc(); | ||
| 1075 | const auto& r = ranges[i]; | ||
| 1076 | UINT64 begin = r.Range.Begin; | ||
| 1077 | UINT64 end = r.Range.End; | ||
| 1078 | if (dep_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { | ||
| 1079 | if (r.Subresource != 0) return check(false); | ||
| 1080 | if (begin >= end || (end != UINT64_MAX && end > dep_desc.Width)) | ||
| 1081 | return check(false); | ||
| 1082 | } else { | ||
| 1083 | const UINT total_subresources = subresource_count(dep_desc); | ||
| 1084 | if (r.Subresource != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && r.Subresource >= total_subresources) | ||
| 1085 | return check(false); | ||
| 1086 | if (begin != 0 || end != UINT64_MAX) return check(false); | ||
| 1087 | } | ||
| 1088 | copy.dependencies.push_back({resource_id(dep), r.Subresource, begin, end}); | ||
| 1089 | } | ||
| 1021 | check(list_.atomic_copy(copy)); | 1090 | check(list_.atomic_copy(copy)); |
| 1022 | } | 1091 | } |
| 1023 | 1092 | ||