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/CPUDescriptorHeapAllocationD3D12.h" 16 #include "dawn_native/Error.h" 17 18 namespace dawn_native { namespace d3d12 { 19 CPUDescriptorHeapAllocation(D3D12_CPU_DESCRIPTOR_HANDLE baseDescriptor,uint32_t heapIndex)20 CPUDescriptorHeapAllocation::CPUDescriptorHeapAllocation( 21 D3D12_CPU_DESCRIPTOR_HANDLE baseDescriptor, 22 uint32_t heapIndex) 23 : mBaseDescriptor(baseDescriptor), mHeapIndex(heapIndex) { 24 } 25 GetBaseDescriptor() const26 D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHeapAllocation::GetBaseDescriptor() const { 27 ASSERT(IsValid()); 28 return mBaseDescriptor; 29 } 30 OffsetFrom(uint32_t sizeIncrementInBytes,uint32_t offsetInDescriptorCount) const31 D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHeapAllocation::OffsetFrom( 32 uint32_t sizeIncrementInBytes, 33 uint32_t offsetInDescriptorCount) const { 34 ASSERT(IsValid()); 35 D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = mBaseDescriptor; 36 cpuHandle.ptr += sizeIncrementInBytes * offsetInDescriptorCount; 37 return cpuHandle; 38 } 39 GetHeapIndex() const40 uint32_t CPUDescriptorHeapAllocation::GetHeapIndex() const { 41 ASSERT(mHeapIndex >= 0); 42 return mHeapIndex; 43 } 44 IsValid() const45 bool CPUDescriptorHeapAllocation::IsValid() const { 46 return mBaseDescriptor.ptr != 0; 47 } 48 Invalidate()49 void CPUDescriptorHeapAllocation::Invalidate() { 50 mBaseDescriptor = {0}; 51 } 52 53 }} // namespace dawn_native::d3d12 54