1 /* 2 * Copyright 2015 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 GrVkMemory_DEFINED 9 #define GrVkMemory_DEFINED 10 11 #include "GrVkBuffer.h" 12 #include "SkTArray.h" 13 #include "vk/GrVkTypes.h" 14 15 class GrVkGpu; 16 17 namespace GrVkMemory { 18 /** 19 * Allocates vulkan device memory and binds it to the gpu's device for the given object. 20 * Returns true if allocation succeeded. 21 */ 22 bool AllocAndBindBufferMemory(const GrVkGpu* gpu, 23 VkBuffer buffer, 24 GrVkBuffer::Type type, 25 bool dynamic, 26 GrVkAlloc* alloc); 27 void FreeBufferMemory(const GrVkGpu* gpu, GrVkBuffer::Type type, const GrVkAlloc& alloc); 28 29 bool AllocAndBindImageMemory(const GrVkGpu* gpu, 30 VkImage image, 31 bool linearTiling, 32 GrVkAlloc* alloc); 33 void FreeImageMemory(const GrVkGpu* gpu, bool linearTiling, const GrVkAlloc& alloc); 34 35 // Maps the entire GrVkAlloc and returns a pointer to the start of the allocation. Underneath 36 // the hood, we may map more than the range of the GrVkAlloc (e.g. the entire VkDeviceMemory), 37 // but the pointer returned will always be to the start of the GrVkAlloc. The caller should also 38 // never assume more than the GrVkAlloc block has been mapped. 39 void* MapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc); 40 void UnmapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc); 41 42 // For the Flush and Invalidate calls, the offset should be relative to the GrVkAlloc. Thus this 43 // will often be 0. The client does not need to make sure the offset and size are aligned to the 44 // nonCoherentAtomSize, the internal calls will handle that. 45 void FlushMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset, 46 VkDeviceSize size); 47 void InvalidateMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset, 48 VkDeviceSize size); 49 50 // Helper for aligning and setting VkMappedMemoryRange for flushing/invalidating noncoherent 51 // memory. 52 void GetNonCoherentMappedMemoryRange(const GrVkAlloc&, VkDeviceSize offset, VkDeviceSize size, 53 VkDeviceSize alignment, VkMappedMemoryRange*); 54 } 55 56 #endif 57