| 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 | |
| 18 | #include "VkObject.hpp" |
| 19 | #include "VkFormat.h" |
| 20 | #include "VkImageView.hpp" |
| 21 | |
| 22 | namespace vk |
| 23 | { |
| 24 | |
| 25 | class Buffer; |
| 26 | |
| 27 | class BufferView : public Object<BufferView, VkBufferView> |
| 28 | { |
| 29 | public: |
| 30 | BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem); |
| 31 | |
| 32 | static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo* pCreateInfo) |
| 33 | { |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | void *getPointer() const; |
| 38 | uint32_t getElementCount() const { return static_cast<uint32_t>(range / Format(format).bytes()); } |
| 39 | uint32_t getRangeInBytes() const { return static_cast<uint32_t>(range); } |
| 40 | VkFormat getFormat() const { return format; } |
| 41 | |
| 42 | const uint32_t id = ImageView::nextID++; // ID space for sampling function cache, shared with imageviews |
| 43 | private: |
| 44 | Buffer *buffer; |
| 45 | VkFormat format; |
| 46 | VkDeviceSize offset; |
| 47 | VkDeviceSize range; |
| 48 | }; |
| 49 | |
| 50 | static inline BufferView* Cast(VkBufferView object) |
| 51 | { |
| 52 | return BufferView::Cast(object); |
| 53 | } |
| 54 | |
| 55 | } // namespace vk |
| 56 | |
| 57 | #endif // VK_BUFFER_VIEW_HPP_ |
| 58 | |