1 /* 2 * Copyright 2022 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 skgpu_graphite_VulkanBuffer_DEFINED 9 #define skgpu_graphite_VulkanBuffer_DEFINED 10 11 #include "include/gpu/vk/VulkanMemoryAllocator.h" 12 #include "src/gpu/graphite/Buffer.h" 13 #include "src/gpu/graphite/vk/VulkanSharedContext.h" 14 15 namespace skgpu::graphite { 16 17 class VulkanBuffer final : public Buffer { 18 public: 19 static sk_sp<Buffer> Make(const VulkanSharedContext*, size_t, BufferType, PrioritizeGpuReads); 20 void freeGpuData() override; vkBuffer()21 VkBuffer vkBuffer() const { return fBuffer; } 22 23 private: 24 VulkanBuffer(const VulkanSharedContext*, size_t, BufferType, PrioritizeGpuReads, VkBuffer, 25 const skgpu::VulkanAlloc&); 26 27 void onMap() override; 28 void onUnmap() override; 29 30 void internalMap(size_t readOffset, size_t readSize); 31 void internalUnmap(size_t flushOffset, size_t flushSize); 32 isMappable()33 bool isMappable() const { return fAlloc.fFlags & skgpu::VulkanAlloc::kMappable_Flag; } 34 vulkanSharedContext()35 const VulkanSharedContext* vulkanSharedContext() const { 36 return static_cast<const VulkanSharedContext*>(this->sharedContext()); 37 } 38 39 VkBuffer fBuffer; 40 skgpu::VulkanAlloc fAlloc; 41 /** 42 * Buffers can either be mapped for: 43 * 1) Reading from the CPU (The effect of writing would be undefined) 44 * 2) Writing from the CPU (The existing contents are discarded. Even in the case where the 45 * initial contents are overwritten, CPU reads should be avoided for performance reasons as 46 * the memory may not be cached). 47 */ 48 bool fBufferUsedForCPURead = false; 49 }; 50 51 } // namespace skgpu::graphite 52 53 #endif // skgpu_graphite_VulkanBuffer_DEFINED 54 55