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_VIEW_HPP_ |
| 16 | #define VK_BUFFER_VIEW_HPP_ |
| 17 | |
Chris Forbes | 5822882 | 2019-04-17 12:51:29 -0700 | [diff] [blame] | 18 | #include "VkFormat.h" |
Chris Forbes | 246cc50 | 2019-05-09 09:25:09 -0700 | [diff] [blame] | 19 | #include "VkImageView.hpp" |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 20 | #include "VkObject.hpp" |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 21 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 22 | namespace vk { |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 23 | |
Alexis Hetu | 7d96f51 | 2019-06-13 18:23:56 -0400 | [diff] [blame] | 24 | class Buffer; |
| 25 | |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 26 | class BufferView : public Object<BufferView, VkBufferView> |
| 27 | { |
| 28 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 29 | BufferView(const VkBufferViewCreateInfo *pCreateInfo, void *mem); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 30 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 31 | static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo *pCreateInfo) |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
Chris Forbes | 5822882 | 2019-04-17 12:51:29 -0700 | [diff] [blame] | 36 | void *getPointer() const; |
Alexis Hetu | 126bd7a | 2019-05-10 17:07:42 -0400 | [diff] [blame] | 37 | 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 Forbes | 3e6a971 | 2019-05-08 14:05:56 -0700 | [diff] [blame] | 39 | VkFormat getFormat() const { return format; } |
Chris Forbes | 5822882 | 2019-04-17 12:51:29 -0700 | [diff] [blame] | 40 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 41 | const uint32_t id = ImageView::nextID++; // ID space for sampling function cache, shared with imageviews |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 42 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 43 | Buffer *buffer; |
| 44 | VkFormat format; |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 45 | VkDeviceSize offset; |
| 46 | VkDeviceSize range; |
| 47 | }; |
| 48 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 49 | static inline BufferView *Cast(VkBufferView object) |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 50 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 51 | return BufferView::Cast(object); |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 54 | } // namespace vk |
Alexis Hetu | 38ff830 | 2018-10-18 15:08:13 -0400 | [diff] [blame] | 55 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 56 | #endif // VK_BUFFER_VIEW_HPP_ |