1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "VkDeviceMemory.hpp"
22 DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo* pCreateInfo, void* mem) :
23 size(pCreateInfo->allocationSize), memoryTypeIndex(pCreateInfo->memoryTypeIndex)
28 void DeviceMemory::destroy(const VkAllocationCallbacks* pAllocator)
30 vk::deallocate(buffer, DEVICE_MEMORY);
33 size_t DeviceMemory::ComputeRequiredAllocationSize(const VkMemoryAllocateInfo* pCreateInfo)
35 // buffer is "GPU memory", so we use device memory for it
39 VkResult DeviceMemory::allocate()
43 buffer = vk::allocate(size, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
48 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
54 VkResult DeviceMemory::map(VkDeviceSize pOffset, VkDeviceSize pSize, void** ppData)
56 *ppData = getOffsetPointer(pOffset);
61 VkDeviceSize DeviceMemory::getCommittedMemoryInBytes() const
66 void* DeviceMemory::getOffsetPointer(VkDeviceSize pOffset)
70 return reinterpret_cast<char*>(buffer) + pOffset;