Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 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 VK_BUFFER_HPP_ |
| 16 | #define VK_BUFFER_HPP_ |
| 17 | |
| 18 | #include "VkObject.hpp" |
| 19 | |
| 20 | namespace vk |
| 21 | { |
| 22 | |
| 23 | class Buffer : public Object<Buffer, VkBuffer> |
| 24 | { |
| 25 | public: |
| 26 | Buffer(const VkBufferCreateInfo* pCreateInfo, void* mem); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 27 | void destroy(const VkAllocationCallbacks* pAllocator); |
| 28 | |
| 29 | static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo* pCreateInfo); |
| 30 | |
| 31 | const VkMemoryRequirements getMemoryRequirements() const; |
| 32 | void bind(VkDeviceMemory pDeviceMemory, VkDeviceSize pMemoryOffset); |
Alexis Hetu | 2661e84 | 2018-12-07 11:36:34 -0500 | [diff] [blame] | 33 | void copyFrom(const void* srcMemory, VkDeviceSize size, VkDeviceSize offset); |
| 34 | void copyTo(void* dstMemory, VkDeviceSize size, VkDeviceSize offset) const; |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 35 | void copyTo(Buffer* dstBuffer, const VkBufferCopy& pRegion) const; |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 36 | void fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data); |
| 37 | void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData); |
Alexis Hetu | e0b5a4b | 2018-12-14 12:11:02 -0500 | [diff] [blame] | 38 | void* getOffsetPointer(VkDeviceSize offset) const; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 39 | inline VkDeviceSize getSize() const { return size; } |
Alexis Hetu | 377077a | 2019-03-14 15:10:51 -0400 | [diff] [blame] | 40 | uint8_t* end() const; |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 41 | |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 42 | private: |
| 43 | void* memory = nullptr; |
| 44 | VkBufferCreateFlags flags = 0; |
| 45 | VkDeviceSize size = 0; |
| 46 | VkBufferUsageFlags usage = 0; |
| 47 | VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 48 | uint32_t queueFamilyIndexCount = 0; |
| 49 | uint32_t* queueFamilyIndices = nullptr; |
| 50 | }; |
| 51 | |
| 52 | static inline Buffer* Cast(VkBuffer object) |
| 53 | { |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 54 | return reinterpret_cast<Buffer*>(object.get()); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace vk |
| 58 | |
| 59 | #endif // VK_BUFFER_HPP_ |