blob: 8488a84dfd0c99e9012fa1aa4489a24c8c0b97ab [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_VIEW_HPP_
16#define VK_BUFFER_VIEW_HPP_
17
Antonio Maiorano42fd1592020-04-27 11:30:40 -040018#include "VkFormat.hpp"
Chris Forbes246cc502019-05-09 09:25:09 -070019#include "VkImageView.hpp"
Ben Clayton2ed93ab2019-12-17 20:38:03 +000020#include "VkObject.hpp"
Alexis Hetu38ff8302018-10-18 15:08:13 -040021
Nicolas Capens157ba262019-12-10 17:49:14 -050022namespace vk {
Alexis Hetu38ff8302018-10-18 15:08:13 -040023
Alexis Hetu7d96f512019-06-13 18:23:56 -040024class Buffer;
25
Alexis Hetu38ff8302018-10-18 15:08:13 -040026class BufferView : public Object<BufferView, VkBufferView>
27{
28public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000029 BufferView(const VkBufferViewCreateInfo *pCreateInfo, void *mem);
Alexis Hetu38ff8302018-10-18 15:08:13 -040030
Ben Clayton2ed93ab2019-12-17 20:38:03 +000031 static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo *pCreateInfo)
Alexis Hetu38ff8302018-10-18 15:08:13 -040032 {
33 return 0;
34 }
35
Chris Forbes58228822019-04-17 12:51:29 -070036 void *getPointer() const;
Alexis Hetu126bd7a2019-05-10 17:07:42 -040037 uint32_t getElementCount() const { return static_cast<uint32_t>(range / Format(format).bytes()); }
38 uint32_t getRangeInBytes() const { return static_cast<uint32_t>(range); }
Chris Forbes3e6a9712019-05-08 14:05:56 -070039 VkFormat getFormat() const { return format; }
Chris Forbes58228822019-04-17 12:51:29 -070040
Nicolas Capens77090262020-03-19 00:26:21 -040041 const Identifier id;
42
Alexis Hetu38ff8302018-10-18 15:08:13 -040043private:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000044 Buffer *buffer;
45 VkFormat format;
Alexis Hetu38ff8302018-10-18 15:08:13 -040046 VkDeviceSize offset;
47 VkDeviceSize range;
48};
49
Ben Clayton2ed93ab2019-12-17 20:38:03 +000050static inline BufferView *Cast(VkBufferView object)
Alexis Hetu38ff8302018-10-18 15:08:13 -040051{
Alexis Hetubd4cf812019-06-14 15:14:07 -040052 return BufferView::Cast(object);
Alexis Hetu38ff8302018-10-18 15:08:13 -040053}
54
Nicolas Capens157ba262019-12-10 17:49:14 -050055} // namespace vk
Alexis Hetu38ff8302018-10-18 15:08:13 -040056
Ben Clayton2ed93ab2019-12-17 20:38:03 +000057#endif // VK_BUFFER_VIEW_HPP_