blob: 3312f23ae6dd5b86394d85d9f00b7d4ad331822d [file] [log] [blame]
Chris Forbes58228822019-04-17 12:51:29 -07001// Copyright 2019 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#include "VkBufferView.hpp"
16#include "VkBuffer.hpp"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040017#include "VkFormat.hpp"
Chris Forbes58228822019-04-17 12:51:29 -070018
Nicolas Capens157ba262019-12-10 17:49:14 -050019namespace vk {
Chris Forbes58228822019-04-17 12:51:29 -070020
Ben Clayton2ed93ab2019-12-17 20:38:03 +000021BufferView::BufferView(const VkBufferViewCreateInfo *pCreateInfo, void *mem)
Nicolas Capens77090262020-03-19 00:26:21 -040022 : id(pCreateInfo->format)
23 , buffer(vk::Cast(pCreateInfo->buffer))
Ben Clayton2ed93ab2019-12-17 20:38:03 +000024 , format(pCreateInfo->format)
25 , offset(pCreateInfo->offset)
Chris Forbes58228822019-04-17 12:51:29 -070026{
Ben Clayton2ed93ab2019-12-17 20:38:03 +000027 if(pCreateInfo->range == VK_WHOLE_SIZE)
28 {
29 range = buffer->getSize() - offset;
30 }
31 else
32 {
33 range = pCreateInfo->range;
34 }
Chris Forbes58228822019-04-17 12:51:29 -070035}
36
Ben Clayton2ed93ab2019-12-17 20:38:03 +000037void *BufferView::getPointer() const
Chris Forbes58228822019-04-17 12:51:29 -070038{
Ben Clayton2ed93ab2019-12-17 20:38:03 +000039 return buffer->getOffsetPointer(offset);
Chris Forbes58228822019-04-17 12:51:29 -070040}
41
Nicolas Capens77090262020-03-19 00:26:21 -040042} // namespace vk