aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkAMDMemoryAllocator.h
blob: 297b0adaf758e7de24d61ad502c6e31f886684e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrVkAMDMemoryAllocator_DEFINED
#define GrVkAMDMemoryAllocator_DEFINED

#include "vk/GrVkMemoryAllocator.h"

#include "GrVulkanMemoryAllocator.h"

struct GrVkInterface;

class GrVkAMDMemoryAllocator : public GrVkMemoryAllocator {
public:
    GrVkAMDMemoryAllocator(VkPhysicalDevice physicalDevice, VkDevice device,
                           sk_sp<const GrVkInterface> interface);

    ~GrVkAMDMemoryAllocator() override;

    bool allocateMemoryForImage(VkImage image, AllocationPropertyFlags flags, GrVkBackendMemory*) override;

    bool allocateMemoryForBuffer(VkBuffer buffer, BufferUsage usage,
                                 AllocationPropertyFlags flags, GrVkBackendMemory*) override;

    void freeMemory(const GrVkBackendMemory&) override;

    void getAllocInfo(const GrVkBackendMemory&, GrVkAlloc*) const override;

    void* mapMemory(const GrVkBackendMemory&) override;
    void unmapMemory(const GrVkBackendMemory&) override;

    void flushMappedMemory(const GrVkBackendMemory&, VkDeviceSize offset,
                           VkDeviceSize size) override;
    void invalidateMappedMemory(const GrVkBackendMemory&, VkDeviceSize offset,
                                VkDeviceSize size) override;

    uint64_t totalUsedMemory() const override;
    uint64_t totalAllocatedMemory() const override;

private:
    VmaAllocator fAllocator;

    // If a future version of the AMD allocator has helper functions for flushing and invalidating
    // memory, then we won't need to save the GrVkInterface here since we won't need to make direct
    // vulkan calls.
    sk_sp<const GrVkInterface> fInterface;
    VkDevice fDevice;

    typedef GrVkMemoryAllocator INHERITED;
};

#endif