| 1 |
/* |
| 2 |
* Copyright 2020 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h" |
| 9 |
#include "src/gpu/ganesh/d3d/GrD3DGpu.h" |
| 10 |
|
| 11 |
std::unique_ptr<GrD3DDescriptorHeap> GrD3DDescriptorHeap::Make(GrD3DGpu* gpu, |
| 12 |
D3D12_DESCRIPTOR_HEAP_TYPE type, |
| 13 |
unsigned int numDescriptors, |
| 14 |
D3D12_DESCRIPTOR_HEAP_FLAGS flags) { |
| 15 |
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {}; |
| 16 |
heapDesc.Type = type; |
| 17 |
heapDesc.NumDescriptors = numDescriptors; |
| 18 |
heapDesc.Flags = flags; |
| 19 |
|
| 20 |
ID3D12DescriptorHeap* heap; |
| 21 |
gpu->device()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&heap)); |
| 22 |
|
| 23 |
return std::unique_ptr<GrD3DDescriptorHeap>( |
| 24 |
new GrD3DDescriptorHeap(std::move(gr_cp<ID3D12DescriptorHeap>(heap)), |
| 25 |
gpu->device()->GetDescriptorHandleIncrementSize(type))); |
| 26 |
} |
| 27 |
|
| 28 |
GrD3DDescriptorHeap::GrD3DDescriptorHeap(const gr_cp<ID3D12DescriptorHeap>& heap, |
| 29 |
unsigned int handleIncrementSize) |
| 30 |
: fHeap(heap) |
| 31 |
, fHandleIncrementSize(handleIncrementSize) |
| 32 |
, fUniqueID(GenID()) { |
| 33 |
fCPUHeapStart = fHeap->GetCPUDescriptorHandleForHeapStart(); |
| 34 |
fGPUHeapStart = fHeap->GetGPUDescriptorHandleForHeapStart(); |
| 35 |
} |
| 36 |
|
| 37 |
GrD3DDescriptorHeap::CPUHandle GrD3DDescriptorHeap::getCPUHandle(unsigned int index) { |
| 38 |
SkASSERT(index < fHeap->GetDesc().NumDescriptors); |
| 39 |
D3D12_CPU_DESCRIPTOR_HANDLE handle = fCPUHeapStart; |
| 40 |
handle.ptr += index * fHandleIncrementSize; |
| 41 |
return {handle, fUniqueID}; |
| 42 |
} |
| 43 |
|
| 44 |
GrD3DDescriptorHeap::GPUHandle GrD3DDescriptorHeap::getGPUHandle(unsigned int index) { |
| 45 |
SkASSERT(index < fHeap->GetDesc().NumDescriptors); |
| 46 |
D3D12_GPU_DESCRIPTOR_HANDLE handle = fGPUHeapStart; |
| 47 |
handle.ptr += index * fHandleIncrementSize; |
| 48 |
return {handle, fUniqueID}; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|