blob: fe91703c6014e6192fd8894e62908d32be68ac5d [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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
jvanverth6b6ffc42016-06-13 14:28:07 -070011#include "GrVkBuffer.h"
12#include "SkTArray.h"
jvanverthe50f3e72016-03-28 07:03:06 -070013#include "vk/GrVkDefines.h"
jvanverth1e305ba2016-06-01 09:39:15 -070014#include "vk/GrVkTypes.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050015
16class GrVkGpu;
17
18namespace GrVkMemory {
19 /**
20 * Allocates vulkan device memory and binds it to the gpu's device for the given object.
jvanverth6b6ffc42016-06-13 14:28:07 -070021 * Returns true if allocation succeeded.
Greg Daniel164a9f02016-02-22 09:56:40 -050022 */
23 bool AllocAndBindBufferMemory(const GrVkGpu* gpu,
24 VkBuffer buffer,
jvanverth6b6ffc42016-06-13 14:28:07 -070025 GrVkBuffer::Type type,
jvanvertha584de92016-06-30 09:10:52 -070026 bool dynamic,
jvanverth1e305ba2016-06-01 09:39:15 -070027 GrVkAlloc* alloc);
jvanverth6b6ffc42016-06-13 14:28:07 -070028 void FreeBufferMemory(const GrVkGpu* gpu, GrVkBuffer::Type type, const GrVkAlloc& alloc);
Greg Daniel164a9f02016-02-22 09:56:40 -050029
30 bool AllocAndBindImageMemory(const GrVkGpu* gpu,
31 VkImage image,
jvanverth6b6ffc42016-06-13 14:28:07 -070032 bool linearTiling,
jvanverth1e305ba2016-06-01 09:39:15 -070033 GrVkAlloc* alloc);
jvanverth6b6ffc42016-06-13 14:28:07 -070034 void FreeImageMemory(const GrVkGpu* gpu, bool linearTiling, const GrVkAlloc& alloc);
Greg Daniel164a9f02016-02-22 09:56:40 -050035
Greg Daniel81df0412018-05-31 13:13:33 -040036 // Maps the entire GrVkAlloc and returns a pointer to the start of the allocation. Underneath
37 // the hood, we may map more than the range of the GrVkAlloc (e.g. the entire VkDeviceMemory),
38 // but the pointer returned will always be to the start of the GrVkAlloc. The caller should also
39 // never assume more than the GrVkAlloc block has been mapped.
40 void* MapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc);
41 void UnmapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc);
42
43 // For the Flush and Invalidate calls, the offset should be relative to the GrVkAlloc. Thus this
44 // will often be 0. The client does not need to make sure the offset and size are aligned to the
45 // nonCoherentAtomSize, the internal calls will handle that.
Greg Daniele35a99e2018-03-02 11:44:22 -050046 void FlushMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset,
47 VkDeviceSize size);
48 void InvalidateMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset,
49 VkDeviceSize size);
Greg Daniel81df0412018-05-31 13:13:33 -040050
51 // Helper for aligning and setting VkMappedMemoryRange for flushing/invalidating noncoherent
52 // memory.
53 void GetNonCoherentMappedMemoryRange(const GrVkAlloc&, VkDeviceSize offset, VkDeviceSize size,
54 VkDeviceSize alignment, VkMappedMemoryRange*);
Greg Daniel164a9f02016-02-22 09:56:40 -050055}
56
jvanverthe50f3e72016-03-28 07:03:06 -070057#endif