1 // Copyright 2020 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "dawn_native/d3d12/QuerySetD3D12.h" 16 17 #include "dawn_native/d3d12/D3D12Error.h" 18 #include "dawn_native/d3d12/DeviceD3D12.h" 19 #include "dawn_native/d3d12/UtilsD3D12.h" 20 21 namespace dawn_native { namespace d3d12 { 22 23 namespace { D3D12QueryHeapType(wgpu::QueryType type)24 D3D12_QUERY_HEAP_TYPE D3D12QueryHeapType(wgpu::QueryType type) { 25 switch (type) { 26 case wgpu::QueryType::Occlusion: 27 return D3D12_QUERY_HEAP_TYPE_OCCLUSION; 28 case wgpu::QueryType::PipelineStatistics: 29 return D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS; 30 case wgpu::QueryType::Timestamp: 31 return D3D12_QUERY_HEAP_TYPE_TIMESTAMP; 32 } 33 } 34 } // anonymous namespace 35 36 // static Create(Device * device,const QuerySetDescriptor * descriptor)37 ResultOrError<Ref<QuerySet>> QuerySet::Create(Device* device, 38 const QuerySetDescriptor* descriptor) { 39 Ref<QuerySet> querySet = AcquireRef(new QuerySet(device, descriptor)); 40 DAWN_TRY(querySet->Initialize()); 41 return querySet; 42 } 43 Initialize()44 MaybeError QuerySet::Initialize() { 45 D3D12_QUERY_HEAP_DESC queryHeapDesc = {}; 46 queryHeapDesc.Type = D3D12QueryHeapType(GetQueryType()); 47 queryHeapDesc.Count = std::max(GetQueryCount(), uint32_t(1u)); 48 49 ID3D12Device* d3d12Device = ToBackend(GetDevice())->GetD3D12Device(); 50 DAWN_TRY(CheckOutOfMemoryHRESULT( 51 d3d12Device->CreateQueryHeap(&queryHeapDesc, IID_PPV_ARGS(&mQueryHeap)), 52 "ID3D12Device::CreateQueryHeap")); 53 54 SetLabelImpl(); 55 56 return {}; 57 } 58 GetQueryHeap() const59 ID3D12QueryHeap* QuerySet::GetQueryHeap() const { 60 return mQueryHeap.Get(); 61 } 62 63 QuerySet::~QuerySet() = default; 64 DestroyImpl()65 void QuerySet::DestroyImpl() { 66 QuerySetBase::DestroyImpl(); 67 ToBackend(GetDevice())->ReferenceUntilUnused(mQueryHeap); 68 mQueryHeap = nullptr; 69 } 70 SetLabelImpl()71 void QuerySet::SetLabelImpl() { 72 SetDebugName(ToBackend(GetDevice()), mQueryHeap.Get(), "Dawn_QuerySet", GetLabel()); 73 } 74 75 }} // namespace dawn_native::d3d12 76