mirror of
https://gitee.com/openharmony/third_party_vulkan-loader
synced 2024-12-18 12:58:10 +00:00
device_class: Add helper function to alloc and bind memory
This commit is contained in:
parent
ce1b179198
commit
eb3d370cbc
@ -1,3 +1,4 @@
|
||||
#include "gtest-1.7.0/include/gtest/gtest.h"
|
||||
#include "xgldevice.h"
|
||||
|
||||
XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) :
|
||||
@ -83,3 +84,34 @@ void XglDevice::get_device_queue(XGL_QUEUE_TYPE queue_type, XGL_UINT queue_idx)
|
||||
err = xglGetDeviceQueue(this->device(), queue_type, queue_idx, &this->m_queue);
|
||||
ASSERT_XGL_SUCCESS(err) << "xglGetDeviceQueue failed";
|
||||
}
|
||||
|
||||
XGL_RESULT XglDevice::AllocAndBindGpuMemory(XGL_OBJECT obj, const std::string &objName, XGL_GPU_MEMORY *pMem)
|
||||
{
|
||||
XGL_RESULT err;
|
||||
XGL_MEMORY_REQUIREMENTS mem_req;
|
||||
XGL_UINT data_size;
|
||||
err = xglGetObjectInfo(obj, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, &data_size, &mem_req);
|
||||
if (err != XGL_SUCCESS) return err;
|
||||
|
||||
if (mem_req.size > 0) {
|
||||
XGL_MEMORY_ALLOC_INFO mem_info = {
|
||||
XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
|
||||
XGL_NULL_HANDLE,
|
||||
mem_req.size, // allocationSize
|
||||
mem_req.alignment, // alignment
|
||||
XGL_MEMORY_ALLOC_SHAREABLE_BIT, // XGL_MEMORY_ALLOC_FLAGS
|
||||
mem_req.heapCount, // heapCount
|
||||
{0}, // heaps
|
||||
XGL_MEMORY_PRIORITY_NORMAL // XGL_MEMORY_PRIORITY
|
||||
};
|
||||
memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS);
|
||||
|
||||
err = xglAllocMemory(device(), &mem_info, pMem);
|
||||
if (err != XGL_SUCCESS) return err;
|
||||
|
||||
err = xglBindObjectMemory(obj, *pMem, 0);
|
||||
if (err != XGL_SUCCESS) return err;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public:
|
||||
void get_device_queue(XGL_QUEUE_TYPE queue_type,
|
||||
XGL_UINT queue_idx);
|
||||
void get_device_queue() {get_device_queue(XGL_QUEUE_TYPE_GRAPHICS, 0);}
|
||||
XGL_RESULT AllocAndBindGpuMemory(XGL_OBJECT obj, const std::string &objName, XGL_GPU_MEMORY *pMem);
|
||||
|
||||
private:
|
||||
XGL_DEVICE m_xgl_device_object;
|
||||
|
Loading…
Reference in New Issue
Block a user