• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2019 Google Inc.
6  * Copyright (c) 2019 The Khronos Group Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Memory management utilities.
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vkMemUtil.hpp"
26 #include "deDefs.h"
27 #include "vkStrUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkRef.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "deInt32.h"
33 
34 #include <sstream>
35 
36 namespace vk
37 {
38 
39 using de::UniquePtr;
40 using de::MovePtr;
41 using std::vector;
42 
43 typedef de::SharedPtr<Allocation> AllocationSp;
44 
45 namespace
46 {
47 
48 class HostPtr
49 {
50 public:
51 								HostPtr		(const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags);
52 								~HostPtr	(void);
53 
get(void) const54 	void*						get			(void) const { return m_ptr; }
55 
56 private:
57 	const DeviceInterface&		m_vkd;
58 	const VkDevice				m_device;
59 	const VkDeviceMemory		m_memory;
60 	void* const					m_ptr;
61 };
62 
HostPtr(const DeviceInterface & vkd,VkDevice device,VkDeviceMemory memory,VkDeviceSize offset,VkDeviceSize size,VkMemoryMapFlags flags)63 HostPtr::HostPtr (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
64 	: m_vkd		(vkd)
65 	, m_device	(device)
66 	, m_memory	(memory)
67 	, m_ptr		(mapMemory(vkd, device, memory, offset, size, flags))
68 {
69 }
70 
~HostPtr(void)71 HostPtr::~HostPtr (void)
72 {
73 	m_vkd.unmapMemory(m_device, m_memory);
74 }
75 
isHostVisibleMemory(const VkPhysicalDeviceMemoryProperties & deviceMemProps,deUint32 memoryTypeNdx)76 bool isHostVisibleMemory (const VkPhysicalDeviceMemoryProperties& deviceMemProps, deUint32 memoryTypeNdx)
77 {
78 	DE_ASSERT(memoryTypeNdx < deviceMemProps.memoryTypeCount);
79 	return (deviceMemProps.memoryTypes[memoryTypeNdx].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0u;
80 }
81 
82 } // anonymous
83 
84 // Allocation
85 
Allocation(VkDeviceMemory memory,VkDeviceSize offset,void * hostPtr)86 Allocation::Allocation (VkDeviceMemory memory, VkDeviceSize offset, void* hostPtr)
87 	: m_memory	(memory)
88 	, m_offset	(offset)
89 	, m_hostPtr	(hostPtr)
90 {
91 }
92 
~Allocation(void)93 Allocation::~Allocation (void)
94 {
95 }
96 
flushAlloc(const DeviceInterface & vkd,VkDevice device,const Allocation & alloc)97 void flushAlloc (const DeviceInterface& vkd, VkDevice device, const Allocation& alloc)
98 {
99 	flushMappedMemoryRange(vkd, device, alloc.getMemory(), alloc.getOffset(), VK_WHOLE_SIZE);
100 }
101 
invalidateAlloc(const DeviceInterface & vkd,VkDevice device,const Allocation & alloc)102 void invalidateAlloc (const DeviceInterface& vkd, VkDevice device, const Allocation& alloc)
103 {
104 	invalidateMappedMemoryRange(vkd, device, alloc.getMemory(), alloc.getOffset(), VK_WHOLE_SIZE);
105 }
106 
107 // MemoryRequirement
108 
109 const MemoryRequirement MemoryRequirement::Any							= MemoryRequirement(0x0u);
110 const MemoryRequirement MemoryRequirement::HostVisible					= MemoryRequirement(MemoryRequirement::FLAG_HOST_VISIBLE);
111 const MemoryRequirement MemoryRequirement::Coherent						= MemoryRequirement(MemoryRequirement::FLAG_COHERENT);
112 const MemoryRequirement MemoryRequirement::LazilyAllocated				= MemoryRequirement(MemoryRequirement::FLAG_LAZY_ALLOCATION);
113 const MemoryRequirement MemoryRequirement::Protected					= MemoryRequirement(MemoryRequirement::FLAG_PROTECTED);
114 const MemoryRequirement MemoryRequirement::Local						= MemoryRequirement(MemoryRequirement::FLAG_LOCAL);
115 const MemoryRequirement MemoryRequirement::Cached						= MemoryRequirement(MemoryRequirement::FLAG_CACHED);
116 const MemoryRequirement MemoryRequirement::NonLocal						= MemoryRequirement(MemoryRequirement::FLAG_NON_LOCAL);
117 const MemoryRequirement MemoryRequirement::DeviceAddress				= MemoryRequirement(MemoryRequirement::FLAG_DEVICE_ADDRESS);
118 const MemoryRequirement MemoryRequirement::DeviceAddressCaptureReplay	= MemoryRequirement(MemoryRequirement::FLAG_DEVICE_ADDRESS_CAPTURE_REPLAY);
119 
matchesHeap(VkMemoryPropertyFlags heapFlags) const120 bool MemoryRequirement::matchesHeap (VkMemoryPropertyFlags heapFlags) const
121 {
122 	// sanity check
123 	if ((m_flags & FLAG_COHERENT) && !(m_flags & FLAG_HOST_VISIBLE))
124 		DE_FATAL("Coherent memory must be host-visible");
125 	if ((m_flags & FLAG_HOST_VISIBLE) && (m_flags & FLAG_LAZY_ALLOCATION))
126 		DE_FATAL("Lazily allocated memory cannot be mappable");
127 	if ((m_flags & FLAG_PROTECTED) && (m_flags & FLAG_HOST_VISIBLE))
128 		DE_FATAL("Protected memory cannot be mappable");
129 
130 	// host-visible
131 	if ((m_flags & FLAG_HOST_VISIBLE) && !(heapFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
132 		return false;
133 
134 	// coherent
135 	if ((m_flags & FLAG_COHERENT) && !(heapFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
136 		return false;
137 
138 	// lazy
139 	if ((m_flags & FLAG_LAZY_ALLOCATION) && !(heapFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT))
140 		return false;
141 
142 	// protected
143 	if ((m_flags & FLAG_PROTECTED) && !(heapFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT))
144 		return false;
145 
146 	// local
147 	if ((m_flags & FLAG_LOCAL) && !(heapFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
148 		return false;
149 
150 	// cached
151 	if ((m_flags & FLAG_CACHED) && !(heapFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT))
152 		return false;
153 
154 	// non-local
155 	if ((m_flags & FLAG_NON_LOCAL) && (heapFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
156 		return false;
157 
158 	return true;
159 }
160 
MemoryRequirement(deUint32 flags)161 MemoryRequirement::MemoryRequirement (deUint32 flags)
162 	: m_flags(flags)
163 {
164 }
165 
166 // SimpleAllocator
167 
168 class SimpleAllocation : public Allocation
169 {
170 public:
171 									SimpleAllocation	(Move<VkDeviceMemory> mem, MovePtr<HostPtr> hostPtr, size_t offset);
172 	virtual							~SimpleAllocation	(void);
173 
174 private:
175 	const Unique<VkDeviceMemory>	m_memHolder;
176 	const UniquePtr<HostPtr>		m_hostPtr;
177 };
178 
SimpleAllocation(Move<VkDeviceMemory> mem,MovePtr<HostPtr> hostPtr,size_t offset)179 SimpleAllocation::SimpleAllocation (Move<VkDeviceMemory> mem, MovePtr<HostPtr> hostPtr, size_t offset)
180 	: Allocation	(*mem, offset, hostPtr ? hostPtr->get() : DE_NULL)
181 	, m_memHolder	(mem)
182 	, m_hostPtr		(hostPtr)
183 {
184 }
185 
~SimpleAllocation(void)186 SimpleAllocation::~SimpleAllocation (void)
187 {
188 }
189 
SimpleAllocator(const DeviceInterface & vk,VkDevice device,const VkPhysicalDeviceMemoryProperties & deviceMemProps,size_t offset)190 SimpleAllocator::SimpleAllocator (const DeviceInterface& vk, VkDevice device, const VkPhysicalDeviceMemoryProperties& deviceMemProps, size_t offset)
191 	: m_vk		(vk)
192 	, m_device	(device)
193 	, m_memProps(deviceMemProps)
194 	, m_offset	(offset)
195 {
196 }
197 
allocate(const VkMemoryAllocateInfo & allocInfo,VkDeviceSize alignment)198 MovePtr<Allocation> SimpleAllocator::allocate (const VkMemoryAllocateInfo& allocInfo, VkDeviceSize alignment)
199 {
200 	// Align the offset to the requirements.
201 	size_t offset = deAlignSize(m_offset, static_cast<size_t>(alignment));
202 	VkMemoryAllocateInfo info = allocInfo;
203 	info.allocationSize += offset;
204 	Move<VkDeviceMemory>	mem		= allocateMemory(m_vk, m_device, &info);
205 	MovePtr<HostPtr>		hostPtr;
206 
207 	if (isHostVisibleMemory(m_memProps, info.memoryTypeIndex))
208 		hostPtr = MovePtr<HostPtr>(new HostPtr(m_vk, m_device, *mem, offset, info.allocationSize, 0u));
209 
210 	return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr, offset));
211 }
212 
allocate(const VkMemoryRequirements & memReqs,MemoryRequirement requirement)213 MovePtr<Allocation> SimpleAllocator::allocate (const VkMemoryRequirements& memReqs, MemoryRequirement requirement)
214 {
215 	const deUint32				memoryTypeNdx	= selectMatchingMemoryType(m_memProps, memReqs.memoryTypeBits, requirement);
216 	// Align the offset to the requirements.
217 	size_t offset = deAlignSize(m_offset, static_cast<size_t>(memReqs.alignment));
218 
219 	VkMemoryAllocateInfo		allocInfo		=
220 	{
221 		VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,	//	VkStructureType			sType;
222 		DE_NULL,								//	const void*				pNext;
223 		memReqs.size + offset,					//	VkDeviceSize			allocationSize;
224 		memoryTypeNdx,							//	deUint32				memoryTypeIndex;
225 	};
226 
227 	VkMemoryAllocateFlagsInfo	allocFlagsInfo =
228 	{
229 		VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,	//	VkStructureType	sType
230 		DE_NULL,										//	const void*		pNext
231 		0,												//	VkMemoryAllocateFlags    flags
232 		0,												//	uint32_t                 deviceMask
233 	};
234 
235 	if (requirement & MemoryRequirement::DeviceAddress)
236 		allocFlagsInfo.flags |= VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT;
237 
238 	if (requirement & MemoryRequirement::DeviceAddressCaptureReplay)
239 		allocFlagsInfo.flags |= VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT;
240 
241 	if (allocFlagsInfo.flags)
242 		allocInfo.pNext = &allocFlagsInfo;
243 
244 	Move<VkDeviceMemory>		mem				= allocateMemory(m_vk, m_device, &allocInfo);
245 	MovePtr<HostPtr>			hostPtr;
246 
247 	if (requirement & MemoryRequirement::HostVisible)
248 	{
249 		DE_ASSERT(isHostVisibleMemory(m_memProps, allocInfo.memoryTypeIndex));
250 		hostPtr = MovePtr<HostPtr>(new HostPtr(m_vk, m_device, *mem, offset, memReqs.size, 0u));
251 	}
252 
253 	return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr, offset));
254 }
255 
allocateExtended(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkMemoryRequirements & memReqs,const MemoryRequirement requirement,const void * pNext)256 MovePtr<Allocation> allocateExtended (const InstanceInterface&		vki,
257 									  const DeviceInterface&		vkd,
258 									  const VkPhysicalDevice&		physDevice,
259 									  const VkDevice				device,
260 									  const VkMemoryRequirements&	memReqs,
261 									  const MemoryRequirement		requirement,
262 									  const void*					pNext)
263 {
264 	const VkPhysicalDeviceMemoryProperties	memoryProperties	= getPhysicalDeviceMemoryProperties(vki, physDevice);
265 	const deUint32							memoryTypeNdx		= selectMatchingMemoryType(memoryProperties, memReqs.memoryTypeBits, requirement);
266 	const VkMemoryAllocateInfo				allocInfo			=
267 	{
268 		VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,	//	VkStructureType	sType
269 		pNext,									//	const void*		pNext
270 		memReqs.size,							//	VkDeviceSize	allocationSize
271 		memoryTypeNdx,							//	deUint32		memoryTypeIndex
272 	};
273 	Move<VkDeviceMemory>					mem					= allocateMemory(vkd, device, &allocInfo);
274 	MovePtr<HostPtr>						hostPtr;
275 
276 	if (requirement & MemoryRequirement::HostVisible)
277 	{
278 		DE_ASSERT(isHostVisibleMemory(memoryProperties, allocInfo.memoryTypeIndex));
279 		hostPtr = MovePtr<HostPtr>(new HostPtr(vkd, device, *mem, 0u, allocInfo.allocationSize, 0u));
280 	}
281 
282 	return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr, 0u));
283 }
284 
allocateDedicated(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkBuffer buffer,MemoryRequirement requirement)285 de::MovePtr<Allocation> allocateDedicated (const InstanceInterface&	vki,
286 										   const DeviceInterface&	vkd,
287 										   const VkPhysicalDevice&	physDevice,
288 										   const VkDevice			device,
289 										   const VkBuffer			buffer,
290 										   MemoryRequirement		requirement)
291 {
292 	const VkMemoryRequirements				memoryRequirements		= getBufferMemoryRequirements(vkd, device, buffer);
293 	const VkMemoryDedicatedAllocateInfo		dedicatedAllocationInfo	=
294 	{
295 		VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,					// VkStructureType		sType
296 		DE_NULL,															// const void*			pNext
297 		DE_NULL,															// VkImage				image
298 		buffer																// VkBuffer				buffer
299 	};
300 
301 	return allocateExtended(vki, vkd, physDevice, device, memoryRequirements, requirement, &dedicatedAllocationInfo);
302 }
303 
allocateDedicated(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkImage image,MemoryRequirement requirement)304 de::MovePtr<Allocation> allocateDedicated (const InstanceInterface&	vki,
305 										   const DeviceInterface&	vkd,
306 										   const VkPhysicalDevice&	physDevice,
307 										   const VkDevice			device,
308 										   const VkImage			image,
309 										   MemoryRequirement		requirement)
310 {
311 	const VkMemoryRequirements				memoryRequirements		= getImageMemoryRequirements(vkd, device, image);
312 	const VkMemoryDedicatedAllocateInfo		dedicatedAllocationInfo	=
313 	{
314 		VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,				// VkStructureType		sType
315 		DE_NULL,														// const void*			pNext
316 		image,															// VkImage				image
317 		DE_NULL															// VkBuffer				buffer
318 	};
319 
320 	return allocateExtended(vki, vkd, physDevice, device, memoryRequirements, requirement, &dedicatedAllocationInfo);
321 }
322 
mapMemory(const DeviceInterface & vkd,VkDevice device,VkDeviceMemory mem,VkDeviceSize offset,VkDeviceSize size,VkMemoryMapFlags flags)323 void* mapMemory (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
324 {
325 	void* hostPtr = DE_NULL;
326 	VK_CHECK(vkd.mapMemory(device, mem, offset, size, flags, &hostPtr));
327 	TCU_CHECK(hostPtr);
328 	return hostPtr;
329 }
330 
flushMappedMemoryRange(const DeviceInterface & vkd,VkDevice device,VkDeviceMemory memory,VkDeviceSize offset,VkDeviceSize size)331 void flushMappedMemoryRange (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size)
332 {
333 	const VkMappedMemoryRange	range	=
334 	{
335 		VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
336 		DE_NULL,
337 		memory,
338 		offset,
339 		size
340 	};
341 
342 	VK_CHECK(vkd.flushMappedMemoryRanges(device, 1u, &range));
343 }
344 
invalidateMappedMemoryRange(const DeviceInterface & vkd,VkDevice device,VkDeviceMemory memory,VkDeviceSize offset,VkDeviceSize size)345 void invalidateMappedMemoryRange (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size)
346 {
347 	const VkMappedMemoryRange	range	=
348 	{
349 		VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
350 		DE_NULL,
351 		memory,
352 		offset,
353 		size
354 	};
355 
356 	VK_CHECK(vkd.invalidateMappedMemoryRanges(device, 1u, &range));
357 }
358 
selectMatchingMemoryType(const VkPhysicalDeviceMemoryProperties & deviceMemProps,deUint32 allowedMemTypeBits,MemoryRequirement requirement)359 deUint32 selectMatchingMemoryType (const VkPhysicalDeviceMemoryProperties& deviceMemProps, deUint32 allowedMemTypeBits, MemoryRequirement requirement)
360 {
361 	const deUint32	compatibleTypes		= getCompatibleMemoryTypes(deviceMemProps, requirement);
362 	deUint32		candidates			= allowedMemTypeBits & compatibleTypes;
363 #ifdef CTS_USES_VULKANSC
364 	// in case of Vulkan SC: prefer memory types from SEU-safe heaps ( SEU = single event upsets )
365 	const deUint32	seuSafeTypes		= getSEUSafeMemoryTypes(deviceMemProps);
366 	deUint32		seuSafeCandidates	= candidates & seuSafeTypes;
367 	if (seuSafeCandidates != 0u)
368 		candidates						= seuSafeCandidates;
369 #endif // CTS_USES_VULKANSC
370 
371 	if (candidates == 0u)
372 		TCU_THROW(NotSupportedError, "No compatible memory type found");
373 
374 	return (deUint32)deCtz32(candidates);
375 }
376 
getCompatibleMemoryTypes(const VkPhysicalDeviceMemoryProperties & deviceMemProps,MemoryRequirement requirement)377 deUint32 getCompatibleMemoryTypes (const VkPhysicalDeviceMemoryProperties& deviceMemProps, MemoryRequirement requirement)
378 {
379 	deUint32	compatibleTypes	= 0u;
380 
381 	for (deUint32 memoryTypeNdx = 0; memoryTypeNdx < deviceMemProps.memoryTypeCount; memoryTypeNdx++)
382 	{
383 		if (requirement.matchesHeap(deviceMemProps.memoryTypes[memoryTypeNdx].propertyFlags))
384 			compatibleTypes |= (1u << memoryTypeNdx);
385 	}
386 
387 	return compatibleTypes;
388 }
389 
390 #ifdef CTS_USES_VULKANSC
391 
getSEUSafeMemoryTypes(const VkPhysicalDeviceMemoryProperties & deviceMemProps)392 deUint32 getSEUSafeMemoryTypes (const VkPhysicalDeviceMemoryProperties& deviceMemProps)
393 {
394 	deUint32	seuSafeTypes	= 0u;
395 
396 	for (deUint32 memoryTypeNdx = 0; memoryTypeNdx < deviceMemProps.memoryTypeCount; memoryTypeNdx++)
397 	{
398 		if( ( deviceMemProps.memoryHeaps[deviceMemProps.memoryTypes[memoryTypeNdx].heapIndex].flags & VK_MEMORY_HEAP_SEU_SAFE_BIT ) != 0u )
399 			seuSafeTypes |= (1u << memoryTypeNdx);
400 	}
401 	return seuSafeTypes;
402 }
403 
404 #endif // CTS_USES_VULKANSC
405 
bindImagePlanesMemory(const DeviceInterface & vkd,const VkDevice device,const VkImage image,const deUint32 numPlanes,vector<AllocationSp> & allocations,vk::Allocator & allocator,const vk::MemoryRequirement requirement)406 void bindImagePlanesMemory (const DeviceInterface&		vkd,
407 							const VkDevice				device,
408 							const VkImage				image,
409 							const deUint32				numPlanes,
410 							vector<AllocationSp>&		allocations,
411 							vk::Allocator&				allocator,
412 							const vk::MemoryRequirement	requirement)
413 {
414 	vector<VkBindImageMemoryInfo>		coreInfos;
415 	vector<VkBindImagePlaneMemoryInfo>	planeInfos;
416 	coreInfos.reserve(numPlanes);
417 	planeInfos.reserve(numPlanes);
418 
419 	for (deUint32 planeNdx = 0; planeNdx < numPlanes; ++planeNdx)
420 	{
421 		const VkImageAspectFlagBits	planeAspect	= getPlaneAspect(planeNdx);
422 		const VkMemoryRequirements	reqs		= getImagePlaneMemoryRequirements(vkd, device, image, planeAspect);
423 
424 		allocations.push_back(AllocationSp(allocator.allocate(reqs, requirement).release()));
425 
426 		VkBindImagePlaneMemoryInfo	planeInfo	=
427 		{
428 			VK_STRUCTURE_TYPE_BIND_IMAGE_PLANE_MEMORY_INFO,
429 			DE_NULL,
430 			planeAspect
431 		};
432 		planeInfos.push_back(planeInfo);
433 
434 		VkBindImageMemoryInfo		coreInfo	=
435 		{
436 			VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
437 			&planeInfos.back(),
438 			image,
439 			allocations.back()->getMemory(),
440 			allocations.back()->getOffset(),
441 		};
442 		coreInfos.push_back(coreInfo);
443 	}
444 
445 	VK_CHECK(vkd.bindImageMemory2(device, numPlanes, coreInfos.data()));
446 }
447 
bindImage(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkImage image,const MemoryRequirement requirement)448 MovePtr<Allocation> bindImage (const DeviceInterface&	vk,
449 							   const VkDevice			device,
450 							   Allocator&				allocator,
451 							   const VkImage			image,
452 							   const MemoryRequirement	requirement)
453 {
454 	MovePtr<Allocation> alloc = allocator.allocate(getImageMemoryRequirements(vk, device, image), requirement);
455 	VK_CHECK(vk.bindImageMemory(device, image, alloc->getMemory(), alloc->getOffset()));
456 	return alloc;
457 }
458 
bindBuffer(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkBuffer buffer,const MemoryRequirement requirement)459 MovePtr<Allocation> bindBuffer (const DeviceInterface&	vk,
460 								const VkDevice			device,
461 								Allocator&				allocator,
462 								const VkBuffer			buffer,
463 								const MemoryRequirement	requirement)
464 {
465 	MovePtr<Allocation> alloc(allocator.allocate(getBufferMemoryRequirements(vk, device, buffer), requirement));
466 	VK_CHECK(vk.bindBufferMemory(device, buffer, alloc->getMemory(), alloc->getOffset()));
467 	return alloc;
468 }
469 
zeroBuffer(const DeviceInterface & vk,const VkDevice device,const Allocation & alloc,const VkDeviceSize size)470 void zeroBuffer (const DeviceInterface&	vk,
471 				 const VkDevice			device,
472 				 const Allocation&		alloc,
473 				 const VkDeviceSize		size)
474 {
475 	deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(size));
476 	flushAlloc(vk, device, alloc);
477 }
478 
479 } // vk
480