UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
MemoryUtils.h
1#pragma once
2#include <UnCompute/Backend/IBuffer.h>
3#include <UnCompute/Backend/IComputeDevice.h>
4#include <UnCompute/Backend/IDeviceMemory.h>
5#include <algorithm>
6#include <numeric>
7
8namespace UN::Utility
9{
18 inline ResultCode AllocateMemoryFor(const ArraySlice<IDeviceObject*>& objects, MemoryKindFlags flags,
19 const char* memoryDebugName, IDeviceMemory** ppMemory)
20 {
21 auto* pDevice = objects[0]->GetDevice();
22 if (auto result = pDevice->CreateMemory(ppMemory); Failed(result))
23 {
24 return result;
25 }
26
27 DeviceMemoryDesc desc(memoryDebugName, flags, 0, objects);
28 return (*ppMemory)->Init(desc);
29 }
30
38 inline ResultCode AllocateMemoryFor(IDeviceObject* pObject, MemoryKindFlags flags, IDeviceMemory** ppMemory)
39 {
40 auto name = fmt::format("Memory for \"{}\"", pObject->GetDebugName());
41 IDeviceObject* objects[] = { pObject };
42 return AllocateMemoryFor(objects, flags, name.c_str(), ppMemory);
43 }
44} // namespace UN::Utility