• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "VkDeviceMemory.hpp"
16 
17 #include "VkConfig.h"
18 
19 namespace vk
20 {
21 
DeviceMemory(const VkMemoryAllocateInfo * pCreateInfo,void * mem)22 DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo* pCreateInfo, void* mem) :
23 	size(pCreateInfo->allocationSize), memoryTypeIndex(pCreateInfo->memoryTypeIndex)
24 {
25 	ASSERT(size);
26 }
27 
destroy(const VkAllocationCallbacks * pAllocator)28 void DeviceMemory::destroy(const VkAllocationCallbacks* pAllocator)
29 {
30 	vk::deallocate(buffer, DEVICE_MEMORY);
31 }
32 
ComputeRequiredAllocationSize(const VkMemoryAllocateInfo * pCreateInfo)33 size_t DeviceMemory::ComputeRequiredAllocationSize(const VkMemoryAllocateInfo* pCreateInfo)
34 {
35 	// buffer is "GPU memory", so we use device memory for it
36 	return 0;
37 }
38 
allocate()39 VkResult DeviceMemory::allocate()
40 {
41 	if(!buffer)
42 	{
43 		buffer = vk::allocate(size, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
44 	}
45 
46 	if(!buffer)
47 	{
48 		return VK_ERROR_OUT_OF_DEVICE_MEMORY;
49 	}
50 
51 	return VK_SUCCESS;
52 }
53 
map(VkDeviceSize pOffset,VkDeviceSize pSize,void ** ppData)54 VkResult DeviceMemory::map(VkDeviceSize pOffset, VkDeviceSize pSize, void** ppData)
55 {
56 	*ppData = getOffsetPointer(pOffset);
57 
58 	return VK_SUCCESS;
59 }
60 
getCommittedMemoryInBytes() const61 VkDeviceSize DeviceMemory::getCommittedMemoryInBytes() const
62 {
63 	return size;
64 }
65 
getOffsetPointer(VkDeviceSize pOffset)66 void* DeviceMemory::getOffsetPointer(VkDeviceSize pOffset)
67 {
68 	ASSERT(buffer);
69 
70 	return reinterpret_cast<char*>(buffer) + pOffset;
71 }
72 
73 } // namespace vk
74