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 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 20 | namespace vk { |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 21 | |
Alexis Hetu | 7d96f51 | 2019-06-13 18:23:56 -0400 | [diff] [blame] | 22 | class DeviceMemory; |
| 23 | |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 24 | class Buffer : public Object<Buffer, VkBuffer> |
| 25 | { |
| 26 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 27 | Buffer(const VkBufferCreateInfo *pCreateInfo, void *mem); |
| 28 | void destroy(const VkAllocationCallbacks *pAllocator); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 29 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 30 | static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo *pCreateInfo); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 31 | |
| 32 | const VkMemoryRequirements getMemoryRequirements() const; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 33 | void bind(DeviceMemory *pDeviceMemory, VkDeviceSize pMemoryOffset); |
| 34 | void copyFrom(const void *srcMemory, VkDeviceSize size, VkDeviceSize offset); |
| 35 | void copyTo(void *dstMemory, VkDeviceSize size, VkDeviceSize offset) const; |
| 36 | void copyTo(Buffer *dstBuffer, const VkBufferCopy &pRegion) const; |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 37 | void fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data); |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 38 | void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData); |
| 39 | void *getOffsetPointer(VkDeviceSize offset) const; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 40 | inline VkDeviceSize getSize() const { return size; } |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 41 | uint8_t *end() const; |
| 42 | bool canBindToMemory(DeviceMemory *pDeviceMemory) const; |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 43 | |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 44 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 45 | void *memory = nullptr; |
| 46 | VkBufferCreateFlags flags = 0; |
| 47 | VkDeviceSize size = 0; |
| 48 | VkBufferUsageFlags usage = 0; |
| 49 | VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 50 | uint32_t queueFamilyIndexCount = 0; |
| 51 | uint32_t *queueFamilyIndices = nullptr; |
David 'Digit' Turner | 359bc80 | 2019-08-14 17:46:07 +0200 | [diff] [blame] | 52 | |
| 53 | VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleTypes = (VkExternalMemoryHandleTypeFlags)0; |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 54 | }; |
| 55 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 56 | static inline Buffer *Cast(VkBuffer object) |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 57 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 58 | return Buffer::Cast(object); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 61 | } // namespace vk |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 62 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 63 | #endif // VK_BUFFER_HPP_ |