blob: 2aa59fc3a377856a3b17a3c5940b8b49dfd133b8 [file] [log] [blame]
Alexis Hetu38ff8302018-10-18 15:08:13 -04001// 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 Capens157ba262019-12-10 17:49:14 -050020namespace vk {
Alexis Hetu38ff8302018-10-18 15:08:13 -040021
Alexis Hetu7d96f512019-06-13 18:23:56 -040022class DeviceMemory;
23
Alexis Hetu38ff8302018-10-18 15:08:13 -040024class Buffer : public Object<Buffer, VkBuffer>
25{
26public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000027 Buffer(const VkBufferCreateInfo *pCreateInfo, void *mem);
28 void destroy(const VkAllocationCallbacks *pAllocator);
Alexis Hetu38ff8302018-10-18 15:08:13 -040029
Ben Clayton2ed93ab2019-12-17 20:38:03 +000030 static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo *pCreateInfo);
Alexis Hetu38ff8302018-10-18 15:08:13 -040031
32 const VkMemoryRequirements getMemoryRequirements() const;
Ben Clayton2ed93ab2019-12-17 20:38:03 +000033 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 Hetu7fb0b732019-02-07 13:50:10 -050037 void fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data);
Ben Clayton2ed93ab2019-12-17 20:38:03 +000038 void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData);
39 void *getOffsetPointer(VkDeviceSize offset) const;
Alexis Hetuf0aa9d52019-04-01 17:06:47 -040040 inline VkDeviceSize getSize() const { return size; }
Ben Clayton2ed93ab2019-12-17 20:38:03 +000041 uint8_t *end() const;
42 bool canBindToMemory(DeviceMemory *pDeviceMemory) const;
Alexis Hetu38ff8302018-10-18 15:08:13 -040043
Alexis Hetu38ff8302018-10-18 15:08:13 -040044private:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000045 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' Turner359bc802019-08-14 17:46:07 +020052
53 VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleTypes = (VkExternalMemoryHandleTypeFlags)0;
Alexis Hetu38ff8302018-10-18 15:08:13 -040054};
55
Ben Clayton2ed93ab2019-12-17 20:38:03 +000056static inline Buffer *Cast(VkBuffer object)
Alexis Hetu38ff8302018-10-18 15:08:13 -040057{
Alexis Hetubd4cf812019-06-14 15:14:07 -040058 return Buffer::Cast(object);
Alexis Hetu38ff8302018-10-18 15:08:13 -040059}
60
Nicolas Capens157ba262019-12-10 17:49:14 -050061} // namespace vk
Alexis Hetu38ff8302018-10-18 15:08:13 -040062
Ben Clayton2ed93ab2019-12-17 20:38:03 +000063#endif // VK_BUFFER_HPP_