1 // Copyright 2018 The Amber Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_VULKAN_TRANSFER_BUFFER_H_ 16 #define SRC_VULKAN_TRANSFER_BUFFER_H_ 17 18 #include <vector> 19 20 #include "amber/result.h" 21 #include "amber/vulkan_header.h" 22 #include "src/format.h" 23 #include "src/vulkan/resource.h" 24 25 namespace amber { 26 namespace vulkan { 27 28 class CommandBuffer; 29 class Device; 30 31 /// Wrapper around a Vulkan VkBuffer object. 32 class TransferBuffer : public Resource { 33 public: 34 TransferBuffer(Device* device, uint32_t size_in_bytes, Format* format); 35 ~TransferBuffer() override; 36 37 Result Initialize(const VkBufferUsageFlags usage); GetVkBufferView()38 const VkBufferView* GetVkBufferView() const { return &view_; } 39 GetVkBuffer()40 VkBuffer GetVkBuffer() const { return buffer_; } 41 42 /// Records a command on |command_buffer| to copy the buffer contents from the 43 /// host to the device. 44 void CopyToDevice(CommandBuffer* command_buffer) override; 45 /// Records a command on |command_buffer| to copy the buffer contents from the 46 /// device to the host. 47 void CopyToHost(CommandBuffer* command_buffer) override; 48 49 private: 50 VkBuffer buffer_ = VK_NULL_HANDLE; 51 VkDeviceMemory memory_ = VK_NULL_HANDLE; 52 VkBufferView view_ = VK_NULL_HANDLE; 53 VkFormat format_ = VK_FORMAT_UNDEFINED; 54 }; 55 56 } // namespace vulkan 57 } // namespace amber 58 59 #endif // SRC_VULKAN_TRANSFER_BUFFER_H_ 60