• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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 GrVkBuffer_DEFINED
9 #define GrVkBuffer_DEFINED
10 
11 #include "include/gpu/vk/GrVkTypes.h"
12 #include "src/gpu/GrGpuBuffer.h"
13 
14 class GrVkDescriptorSet;
15 class GrVkGpu;
16 
17 class GrVkBuffer : public GrGpuBuffer {
18 public:
19     static sk_sp<GrVkBuffer> Make(GrVkGpu* gpu,
20                                    size_t size,
21                                    GrGpuBufferType bufferType,
22                                    GrAccessPattern accessPattern);
23 
vkBuffer()24     VkBuffer vkBuffer() const { return fBuffer; }
25 
26     void addMemoryBarrier(VkAccessFlags srcAccessMask,
27                           VkAccessFlags dstAccesMask,
28                           VkPipelineStageFlags srcStageMask,
29                           VkPipelineStageFlags dstStageMask,
30                           bool byRegion) const;
31 
32     // If the buffer is a uniform buffer, return the descriptor set for that buffer. It is not valid
33     // to call this on non uniform buffers.
34     const VkDescriptorSet* uniformDescriptorSet() const;
35 
36 private:
37     GrVkBuffer(GrVkGpu* gpu,
38                 size_t sizeInBytes,
39                 GrGpuBufferType bufferType,
40                 GrAccessPattern accessPattern,
41                 VkBuffer buffer,
42                 const GrVkAlloc& alloc,
43                 const GrVkDescriptorSet* uniformDescriptorSet);
44 
isVkMappable()45     bool isVkMappable() const { return fAlloc.fFlags & GrVkAlloc::kMappable_Flag; }
46 
vkIsMapped()47     bool vkIsMapped() const { return SkToBool(fMapPtr); }
48     void vkMap(size_t size);
49     void vkUnmap(size_t size);
50     void copyCpuDataToGpuBuffer(const void* srcData, size_t size);
51 
52 
53     void onMap() override;
54     void onUnmap() override;
55     bool onUpdateData(const void* src, size_t srcSizeInBytes) override;
56 
57     void vkRelease();
58 
59     void onAbandon() override;
60     void onRelease() override;
61 
62     GrVkGpu* getVkGpu() const;
63 
64     VkBuffer fBuffer;
65     GrVkAlloc fAlloc;
66 
67     const GrVkDescriptorSet* fUniformDescriptorSet;
68 
69     using INHERITED = GrGpuBuffer;
70 };
71 
72 #endif
73