1cb93a386Sopenharmony_ci// Copyright 2018 The SwiftShader Authors. All Rights Reserved. 2cb93a386Sopenharmony_ci// 3cb93a386Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4cb93a386Sopenharmony_ci// you may not use this file except in compliance with the License. 5cb93a386Sopenharmony_ci// You may obtain a copy of the License at 6cb93a386Sopenharmony_ci// 7cb93a386Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8cb93a386Sopenharmony_ci// 9cb93a386Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10cb93a386Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11cb93a386Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb93a386Sopenharmony_ci// See the License for the specific language governing permissions and 13cb93a386Sopenharmony_ci// limitations under the License. 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci#ifndef VK_BUFFER_HPP_ 16cb93a386Sopenharmony_ci#define VK_BUFFER_HPP_ 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ci#include "VkObject.hpp" 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_cinamespace vk { 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ciclass DeviceMemory; 23cb93a386Sopenharmony_ci 24cb93a386Sopenharmony_ciclass Buffer : public Object<Buffer, VkBuffer> 25cb93a386Sopenharmony_ci{ 26cb93a386Sopenharmony_cipublic: 27cb93a386Sopenharmony_ci Buffer(const VkBufferCreateInfo *pCreateInfo, void *mem); 28cb93a386Sopenharmony_ci void destroy(const VkAllocationCallbacks *pAllocator); 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo *pCreateInfo); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci const VkMemoryRequirements getMemoryRequirements() const; 33cb93a386Sopenharmony_ci void bind(DeviceMemory *pDeviceMemory, VkDeviceSize pMemoryOffset); 34cb93a386Sopenharmony_ci void copyFrom(const void *srcMemory, VkDeviceSize size, VkDeviceSize offset); 35cb93a386Sopenharmony_ci void copyTo(void *dstMemory, VkDeviceSize size, VkDeviceSize offset) const; 36cb93a386Sopenharmony_ci void copyTo(Buffer *dstBuffer, const VkBufferCopy2KHR &pRegion) const; 37cb93a386Sopenharmony_ci void fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data); 38cb93a386Sopenharmony_ci void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData); 39cb93a386Sopenharmony_ci void *getOffsetPointer(VkDeviceSize offset) const; 40cb93a386Sopenharmony_ci inline VkDeviceSize getSize() const { return size; } 41cb93a386Sopenharmony_ci uint8_t *end() const; 42cb93a386Sopenharmony_ci bool canBindToMemory(DeviceMemory *pDeviceMemory) const; 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci VkBufferUsageFlags getUsage() const { return usage; } 45cb93a386Sopenharmony_ci VkBufferCreateFlags getFlags() const { return flags; } 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ciprivate: 48cb93a386Sopenharmony_ci void *memory = nullptr; 49cb93a386Sopenharmony_ci VkBufferCreateFlags flags = 0; 50cb93a386Sopenharmony_ci VkDeviceSize size = 0; 51cb93a386Sopenharmony_ci VkBufferUsageFlags usage = 0; 52cb93a386Sopenharmony_ci VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE; 53cb93a386Sopenharmony_ci uint32_t queueFamilyIndexCount = 0; 54cb93a386Sopenharmony_ci uint32_t *queueFamilyIndices = nullptr; 55cb93a386Sopenharmony_ci 56cb93a386Sopenharmony_ci VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleTypes = (VkExternalMemoryHandleTypeFlags)0; 57cb93a386Sopenharmony_ci}; 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_cistatic inline Buffer *Cast(VkBuffer object) 60cb93a386Sopenharmony_ci{ 61cb93a386Sopenharmony_ci return Buffer::Cast(object); 62cb93a386Sopenharmony_ci} 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ci} // namespace vk 65cb93a386Sopenharmony_ci 66cb93a386Sopenharmony_ci#endif // VK_BUFFER_HPP_ 67