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 "include/gpu/vk/GrVkMemoryAllocator.h" 12 #include "include/gpu/vk/GrVkTypes.h" 13 #include "include/private/GrTypesPriv.h" 14 #include "include/private/SkTArray.h" 15 16 class GrVkGpu; 17 18 namespace GrVkMemory { 19 /** 20 * Allocates vulkan device memory and binds it to the gpu's device for the given object. 21 * Returns true if allocation succeeded. 22 */ 23 bool AllocAndBindBufferMemory(GrVkGpu* gpu, 24 VkBuffer buffer, 25 GrVkMemoryAllocator::BufferUsage, 26 GrVkAlloc* alloc); 27 void FreeBufferMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc); 28 29 bool AllocAndBindImageMemory(GrVkGpu* gpu, 30 VkImage image, 31 GrMemoryless, 32 GrVkAlloc* alloc); 33 void FreeImageMemory(const GrVkGpu* gpu, 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(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(GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset, 46 VkDeviceSize size); 47 void InvalidateMappedAlloc(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 } // namespace GrVkMemory 55 56 #endif 57