blob: 98b68cce1b907b5501cc85b1cbfa7b3acfcc9909 [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
Chris Forbes58228822019-04-17 12:51:29 -070018#include "VkFormat.h"
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
Ben Clayton2ed93ab2019-12-17 20:38:03 +000041 const uint32_t id = ImageView::nextID++; // ID space for sampling function cache, shared with imageviews
Alexis Hetu38ff8302018-10-18 15:08:13 -040042private:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000043 Buffer *buffer;
44 VkFormat format;
Alexis Hetu38ff8302018-10-18 15:08:13 -040045 VkDeviceSize offset;
46 VkDeviceSize range;
47};
48
Ben Clayton2ed93ab2019-12-17 20:38:03 +000049static inline BufferView *Cast(VkBufferView object)
Alexis Hetu38ff8302018-10-18 15:08:13 -040050{
Alexis Hetubd4cf812019-06-14 15:14:07 -040051 return BufferView::Cast(object);
Alexis Hetu38ff8302018-10-18 15:08:13 -040052}
53
Nicolas Capens157ba262019-12-10 17:49:14 -050054} // namespace vk
Alexis Hetu38ff8302018-10-18 15:08:13 -040055
Ben Clayton2ed93ab2019-12-17 20:38:03 +000056#endif // VK_BUFFER_VIEW_HPP_