mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <switch.h>
|
|
|
|
Result nvGpuCreate(NvGpu* g)
|
|
{
|
|
Result rc;
|
|
|
|
if (R_FAILED(nvInfoInit()))
|
|
return MAKERESULT(Module_Libnx, LibnxError_NvinfoFailedToInitialize);
|
|
|
|
if (R_FAILED(nvBufferInit())) {
|
|
nvInfoExit();
|
|
return MAKERESULT(Module_Libnx, LibnxError_NvbufFailedToInitialize);
|
|
}
|
|
|
|
rc = nvChannelCreate(&g->gpu_channel, "/dev/nvhost-gpu");
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvAddressSpaceCreate(&g->addr_space);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvAddressSpaceReserveFull(&g->addr_space);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvAddressSpaceBindToChannel(&g->addr_space, &g->gpu_channel);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvChannelSetNvmapFd(&g->gpu_channel);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvGpfifoCreate(&g->gpfifo, &g->gpu_channel);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nv3DContextCreate(&g->_3d_ctx, g);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvErrorNotifierCreate(&g->error_notifier, g);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvChannelSetPriority(&g->gpu_channel, NvChannelPriority_Medium);
|
|
|
|
if (R_SUCCEEDED(rc))
|
|
rc = nvZcullContextCreate(&g->zcull_ctx, g);
|
|
|
|
if (R_FAILED(rc))
|
|
nvGpuClose(g);
|
|
|
|
return rc;
|
|
}
|
|
|
|
void nvGpuClose(NvGpu* g)
|
|
{
|
|
nvBufferExit();
|
|
nvInfoExit();
|
|
|
|
nvErrorNotifierClose(&g->error_notifier);
|
|
nvZcullContextClose(&g->zcull_ctx);
|
|
nv3DContextClose(&g->_3d_ctx);
|
|
nvGpfifoClose(&g->gpfifo);
|
|
nvAddressSpaceClose(&g->addr_space);
|
|
nvChannelClose(&g->gpu_channel);
|
|
}
|