| 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 |
#ifndef GrD3DAMDMemoryAllocator_DEFINED |
| 9 |
#define GrD3DAMDMemoryAllocator_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/gpu/ganesh/d3d/GrD3DTypes.h" |
| 13 |
|
| 14 |
#if defined(__clang__) |
| 15 |
#pragma clang diagnostic push |
| 16 |
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" |
| 17 |
#endif |
| 18 |
#include "D3D12MemAlloc.h" // NO_G3_REWRITE |
| 19 |
#if defined(__clang__) |
| 20 |
#pragma clang diagnostic pop |
| 21 |
#endif |
| 22 |
|
| 23 |
class GrD3DAMDMemoryAllocator : public GrD3DMemoryAllocator { |
| 24 |
public: |
| 25 |
static sk_sp<GrD3DMemoryAllocator> Make(IDXGIAdapter* adapter, ID3D12Device* device); |
| 26 |
|
| 27 |
~GrD3DAMDMemoryAllocator() override { fAllocator->Release(); } |
| 28 |
|
| 29 |
gr_cp<ID3D12Resource> createResource(D3D12_HEAP_TYPE, const D3D12_RESOURCE_DESC*, |
| 30 |
D3D12_RESOURCE_STATES initialResourceState, |
| 31 |
sk_sp<GrD3DAlloc>* allocation, |
| 32 |
const D3D12_CLEAR_VALUE*) override; |
| 33 |
|
| 34 |
gr_cp<ID3D12Resource> createAliasingResource(sk_sp<GrD3DAlloc>& allocation, |
| 35 |
uint64_t localOffset, |
| 36 |
const D3D12_RESOURCE_DESC*, |
| 37 |
D3D12_RESOURCE_STATES initialResourceState, |
| 38 |
const D3D12_CLEAR_VALUE*) override; |
| 39 |
|
| 40 |
class Alloc : public GrD3DAlloc { |
| 41 |
public: |
| 42 |
Alloc(D3D12MA::Allocation* allocation) : fAllocation(allocation) {} |
| 43 |
~Alloc() override { |
| 44 |
fAllocation->Release(); |
| 45 |
} |
| 46 |
private: |
| 47 |
friend class GrD3DAMDMemoryAllocator; |
| 48 |
D3D12MA::Allocation* fAllocation; |
| 49 |
}; |
| 50 |
|
| 51 |
private: |
| 52 |
GrD3DAMDMemoryAllocator(D3D12MA::Allocator* allocator) : fAllocator(allocator) {} |
| 53 |
|
| 54 |
D3D12MA::Allocator* fAllocator; |
| 55 |
}; |
| 56 |
|
| 57 |
#endif |