| 1 |
/* |
| 2 |
* Copyright 2018 Google Inc. |
| 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 skgpu_VulkanAMDMemoryAllocator_DEFINED |
| 9 |
#define skgpu_VulkanAMDMemoryAllocator_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/gpu/vk/VulkanMemoryAllocator.h" |
| 13 |
#include "include/gpu/vk/VulkanTypes.h" |
| 14 |
#include "include/private/gpu/vk/SkiaVulkan.h" |
| 15 |
#include "src/gpu/vk/vulkanmemoryallocator/VulkanMemoryAllocatorWrapper.h" |
| 16 |
|
| 17 |
#include <cstdint> |
| 18 |
#include <optional> |
| 19 |
#include <utility> |
| 20 |
|
| 21 |
namespace skgpu { |
| 22 |
|
| 23 |
class VulkanExtensions; |
| 24 |
enum class ThreadSafe : bool; |
| 25 |
struct VulkanInterface; |
| 26 |
|
| 27 |
class VulkanAMDMemoryAllocator : public VulkanMemoryAllocator { |
| 28 |
public: |
| 29 |
static sk_sp<VulkanMemoryAllocator> Make(VkInstance instance, |
| 30 |
VkPhysicalDevice physicalDevice, |
| 31 |
VkDevice device, |
| 32 |
uint32_t physicalDeviceVersion, |
| 33 |
const VulkanExtensions* extensions, |
| 34 |
const VulkanInterface* interface, |
| 35 |
ThreadSafe); |
| 36 |
|
| 37 |
~VulkanAMDMemoryAllocator() override; |
| 38 |
|
| 39 |
VkResult allocateImageMemory(VkImage image, |
| 40 |
uint32_t allocationPropertyFlags, |
| 41 |
skgpu::VulkanBackendMemory*) override; |
| 42 |
|
| 43 |
VkResult allocateBufferMemory(VkBuffer buffer, |
| 44 |
BufferUsage usage, |
| 45 |
uint32_t allocationPropertyFlags, |
| 46 |
skgpu::VulkanBackendMemory*) override; |
| 47 |
|
| 48 |
void freeMemory(const VulkanBackendMemory&) override; |
| 49 |
|
| 50 |
void getAllocInfo(const VulkanBackendMemory&, VulkanAlloc*) const override; |
| 51 |
|
| 52 |
VkResult mapMemory(const VulkanBackendMemory&, void** data) override; |
| 53 |
void unmapMemory(const VulkanBackendMemory&) override; |
| 54 |
|
| 55 |
VkResult flushMemory(const VulkanBackendMemory&, |
| 56 |
VkDeviceSize offset, |
| 57 |
VkDeviceSize size) override; |
| 58 |
VkResult invalidateMemory(const VulkanBackendMemory&, |
| 59 |
VkDeviceSize offset, |
| 60 |
VkDeviceSize size) override; |
| 61 |
|
| 62 |
std::pair<uint64_t, uint64_t> totalAllocatedAndUsedMemory() const override; |
| 63 |
|
| 64 |
private: |
| 65 |
VulkanAMDMemoryAllocator(VmaAllocator allocator); |
| 66 |
|
| 67 |
VmaAllocator fAllocator; |
| 68 |
}; |
| 69 |
|
| 70 |
} // namespace skgpu |
| 71 |
|
| 72 |
#endif // skgpu_VulkanAMDMemoryAllocator_DEFINED |