1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef GrD3DAMDMemoryAllocator_DEFINED 9cb93a386Sopenharmony_ci#define GrD3DAMDMemoryAllocator_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 12cb93a386Sopenharmony_ci#include "include/gpu/d3d/GrD3DTypes.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ci#if defined(__clang__) 15cb93a386Sopenharmony_ci#pragma clang diagnostic push 16cb93a386Sopenharmony_ci#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" 17cb93a386Sopenharmony_ci#endif 18cb93a386Sopenharmony_ci#include "D3D12MemAlloc.h" 19cb93a386Sopenharmony_ci#if defined(__clang__) 20cb93a386Sopenharmony_ci#pragma clang diagnostic pop 21cb93a386Sopenharmony_ci#endif 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ciclass GrD3DAMDMemoryAllocator : public GrD3DMemoryAllocator { 24cb93a386Sopenharmony_cipublic: 25cb93a386Sopenharmony_ci static sk_sp<GrD3DMemoryAllocator> Make(IDXGIAdapter* adapter, ID3D12Device* device); 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci ~GrD3DAMDMemoryAllocator() override { fAllocator->Release(); } 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ci gr_cp<ID3D12Resource> createResource(D3D12_HEAP_TYPE, const D3D12_RESOURCE_DESC*, 30cb93a386Sopenharmony_ci D3D12_RESOURCE_STATES initialResourceState, 31cb93a386Sopenharmony_ci sk_sp<GrD3DAlloc>* allocation, 32cb93a386Sopenharmony_ci const D3D12_CLEAR_VALUE*) override; 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci gr_cp<ID3D12Resource> createAliasingResource(sk_sp<GrD3DAlloc>& allocation, 35cb93a386Sopenharmony_ci uint64_t localOffset, 36cb93a386Sopenharmony_ci const D3D12_RESOURCE_DESC*, 37cb93a386Sopenharmony_ci D3D12_RESOURCE_STATES initialResourceState, 38cb93a386Sopenharmony_ci const D3D12_CLEAR_VALUE*) override; 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci class Alloc : public GrD3DAlloc { 41cb93a386Sopenharmony_ci public: 42cb93a386Sopenharmony_ci Alloc(D3D12MA::Allocation* allocation) : fAllocation(allocation) {} 43cb93a386Sopenharmony_ci ~Alloc() override { 44cb93a386Sopenharmony_ci fAllocation->Release(); 45cb93a386Sopenharmony_ci } 46cb93a386Sopenharmony_ci private: 47cb93a386Sopenharmony_ci friend class GrD3DAMDMemoryAllocator; 48cb93a386Sopenharmony_ci D3D12MA::Allocation* fAllocation; 49cb93a386Sopenharmony_ci }; 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ciprivate: 52cb93a386Sopenharmony_ci GrD3DAMDMemoryAllocator(D3D12MA::Allocator* allocator) : fAllocator(allocator) {} 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci D3D12MA::Allocator* fAllocator; 55cb93a386Sopenharmony_ci}; 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ci#endif 58