Chromium Code Reviews| Index: src/gpu/vk/GrVkMemory.h |
| diff --git a/src/gpu/vk/GrVkMemory.h b/src/gpu/vk/GrVkMemory.h |
| index 279dd58dd5b4a5489115fec2b47de04de9051eeb..7f520ab06f04b3a012775d4822fa083f926d689e 100644 |
| --- a/src/gpu/vk/GrVkMemory.h |
| +++ b/src/gpu/vk/GrVkMemory.h |
| @@ -8,6 +8,9 @@ |
| #ifndef GrVkMemory_DEFINED |
| #define GrVkMemory_DEFINED |
| +#include "GrVkBuffer.h" |
| +#include "SkTArray.h" |
| +#include "SkTLList.h" |
| #include "vk/GrVkDefines.h" |
| #include "vk/GrVkTypes.h" |
| @@ -16,23 +19,98 @@ class GrVkGpu; |
| namespace GrVkMemory { |
| /** |
| * Allocates vulkan device memory and binds it to the gpu's device for the given object. |
| - * Returns true of allocation succeeded. |
| + * Returns true if allocation succeeded. |
| */ |
| bool AllocAndBindBufferMemory(const GrVkGpu* gpu, |
| VkBuffer buffer, |
| - const VkMemoryPropertyFlags flags, |
| + GrVkBuffer::Type type, |
| GrVkAlloc* alloc); |
| - void FreeBufferMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc); |
| + void FreeBufferMemory(const GrVkGpu* gpu, GrVkBuffer::Type type, const GrVkAlloc& alloc); |
| bool AllocAndBindImageMemory(const GrVkGpu* gpu, |
| VkImage image, |
| - const VkMemoryPropertyFlags flags, |
| + bool linearTiling, |
| GrVkAlloc* alloc); |
| - void FreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc); |
| + void FreeImageMemory(const GrVkGpu* gpu, bool linearTiling, const GrVkAlloc& alloc); |
| VkPipelineStageFlags LayoutToPipelineStageFlags(const VkImageLayout layout); |
| VkAccessFlags LayoutToSrcAccessMask(const VkImageLayout layout); |
| } |
| +class GrVkSubHeap { |
| +public: |
| + GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex, VkDeviceSize size); |
| + ~GrVkSubHeap(); |
| + |
| + uint32_t memoryTypeIndex() { return fMemoryTypeIndex; } |
| + VkDeviceSize size() { return fSize; } |
| + VkDeviceSize freeSize() { return fFreeSize; } |
| + VkDeviceSize largestBlockSize() { return fLargestBlockSize; } |
| + VkDeviceMemory memory() { return fAlloc; } |
| + |
| + bool unallocated() { return fSize == fFreeSize; } |
| + |
| + bool alloc(VkDeviceSize size, VkDeviceSize alignment, GrVkAlloc* alloc); |
| + void free(const GrVkAlloc& alloc); |
| + |
| +private: |
| + struct Block { |
| + VkDeviceSize fOffset; |
| + VkDeviceSize fSize; |
| + }; |
| + typedef SkTLList<Block, 16> FreeList; |
| + |
| + const GrVkGpu* fGpu; |
| + uint32_t fMemoryTypeIndex; |
| + VkDeviceSize fSize; |
| + VkDeviceSize fFreeSize; |
| + VkDeviceSize fLargestBlockSize; |
| + VkDeviceSize fLargestBlockOffset; |
| + VkDeviceMemory fAlloc; |
| + FreeList fFreeList; |
| +}; |
| + |
| +class GrVkHeap { |
| +public: |
| + enum Strategy { |
| + kSubAlloc_Strategy, // alloc large subheaps and suballoc within them |
| + kSingleAlloc_Strategy // alloc/recycle an individual subheap per object |
| + }; |
| + |
| + GrVkHeap(const GrVkGpu* gpu, Strategy strategy, VkDeviceSize subHeapSize) |
| + : fGpu(gpu) |
| + , fSubHeapSize(subHeapSize) |
| + , fAllocSize(0) |
| + , fUsedSize(0) { |
| + if (strategy == kSubAlloc_Strategy) { |
| + fAllocFunc = &GrVkHeap::subAlloc; |
| + } else { |
| + fAllocFunc = &GrVkHeap::singleAlloc; |
| + } |
| + } |
| + |
| + ~GrVkHeap(); |
| + |
| + bool alloc(VkDeviceSize size, VkDeviceSize alignment, uint32_t memoryTypeIndex, GrVkAlloc* alloc) { |
|
egdaniel
2016/06/13 16:44:44
100 chars
jvanverth1
2016/06/13 19:59:23
Done.
|
| + return (*this.*fAllocFunc)(size, alignment, memoryTypeIndex, alloc); |
| + } |
| + bool free(const GrVkAlloc& alloc); |
| + |
| +private: |
| + typedef bool (GrVkHeap::*AllocFunc)(VkDeviceSize size, VkDeviceSize alignment, |
| + uint32_t memoryTypeIndex, GrVkAlloc* alloc); |
| + |
| + bool subAlloc(VkDeviceSize size, VkDeviceSize alignment, |
| + uint32_t memoryTypeIndex, GrVkAlloc* alloc); |
| + bool singleAlloc(VkDeviceSize size, VkDeviceSize alignment, |
| + uint32_t memoryTypeIndex, GrVkAlloc* alloc); |
| + |
| + const GrVkGpu* fGpu; |
| + VkDeviceSize fSubHeapSize; |
| + VkDeviceSize fAllocSize; |
| + VkDeviceSize fUsedSize; |
| + AllocFunc fAllocFunc; |
| + SkTArray<GrVkSubHeap*> fSubHeaps; |
| +}; |
| #endif |