blob: a1cdf1cb60834811a3901e3517b13103d4c108a5 [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"
jvanverth1e305ba2016-06-01 09:39:15 -070013#include "vk/GrVkTypes.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
15class GrVkGpu;
16
17namespace GrVkMemory {
18 /**
19 * Allocates vulkan device memory and binds it to the gpu's device for the given object.
jvanverth6b6ffc42016-06-13 14:28:07 -070020 * Returns true if allocation succeeded.
Greg Daniel164a9f02016-02-22 09:56:40 -050021 */
22 bool AllocAndBindBufferMemory(const GrVkGpu* gpu,
23 VkBuffer buffer,
jvanverth6b6ffc42016-06-13 14:28:07 -070024 GrVkBuffer::Type type,
jvanvertha584de92016-06-30 09:10:52 -070025 bool dynamic,
jvanverth1e305ba2016-06-01 09:39:15 -070026 GrVkAlloc* alloc);
jvanverth6b6ffc42016-06-13 14:28:07 -070027 void FreeBufferMemory(const GrVkGpu* gpu, GrVkBuffer::Type type, const GrVkAlloc& alloc);
Greg Daniel164a9f02016-02-22 09:56:40 -050028
29 bool AllocAndBindImageMemory(const GrVkGpu* gpu,
30 VkImage image,
jvanverth6b6ffc42016-06-13 14:28:07 -070031 bool linearTiling,
jvanverth1e305ba2016-06-01 09:39:15 -070032 GrVkAlloc* alloc);
jvanverth6b6ffc42016-06-13 14:28:07 -070033 void FreeImageMemory(const GrVkGpu* gpu, bool linearTiling, const GrVkAlloc& alloc);
Greg Daniel164a9f02016-02-22 09:56:40 -050034
Greg Daniel81df0412018-05-31 13:13:33 -040035 // 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.
Greg Daniele35a99e2018-03-02 11:44:22 -050045 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);
Greg Daniel81df0412018-05-31 13:13:33 -040049
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*);
Greg Daniel164a9f02016-02-22 09:56:40 -050054}
55
jvanverthe50f3e72016-03-28 07:03:06 -070056#endif