diff --git a/nx/include/switch.h b/nx/include/switch.h index 9f7fcaff..0bddfc20 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -41,6 +41,7 @@ extern "C" { #include #include #include +#include #include #include diff --git a/nx/include/switch/gfx/nvgfx.h b/nx/include/switch/gfx/nvgfx.h new file mode 100644 index 00000000..f70b0549 --- /dev/null +++ b/nx/include/switch/gfx/nvgfx.h @@ -0,0 +1,2 @@ +Result nvgfxInitialize(void); +void nvgfxExit(void); diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 868722f3..b4a2dcfd 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -124,6 +124,8 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L if (R_SUCCEEDED(rc)) rc = nvInitialize(nv_servicetype, nv_transfermem_size); + if (R_SUCCEEDED(rc)) rc = nvgfxInitialize(); + if (R_SUCCEEDED(rc)) rc = gfxproducerInitialize(&g_gfxBinderSession); if (R_SUCCEEDED(rc)) rc = gfxproducerConnect(2, 0); @@ -157,6 +159,7 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L if (R_FAILED(rc)) { gfxproducerExit(); + nvgfxExit(); nvExit(); binderExitSession(&g_gfxBinderSession); viCloseLayer(&g_gfxLayer); @@ -196,6 +199,7 @@ void gfxExit(void) { gfxproducerExit(); + nvgfxExit(); nvExit(); binderExitSession(&g_gfxBinderSession); diff --git a/nx/source/gfx/nvgfx.c b/nx/source/gfx/nvgfx.c new file mode 100644 index 00000000..5ca015b8 --- /dev/null +++ b/nx/source/gfx/nvgfx.c @@ -0,0 +1,40 @@ +#include +#include + +static bool g_nvgfxInitialized = 0; +static u32 g_nvgfx_fd_nvhostctrlgpu; + +static gpu_characteristics g_nvgfx_gpu_characteristics; + +Result nvgfxInitialize(void) { + Result rc=0; + if(g_nvgfxInitialized)return 0; + + g_nvgfx_fd_nvhostctrlgpu = 0; + + memset(&g_nvgfx_gpu_characteristics, 0, sizeof(gpu_characteristics)); + + //Officially NVHOST_IOCTL_CTRL_GET_CONFIG is used a lot (here and later), skip that. + + rc = nvOpen(&g_nvgfx_fd_nvhostctrlgpu, "/dev/nvhost-ctrl-gpu"); + if (R_SUCCEEDED(rc)) { + rc = nvioctlNvhostCtrlGpu_GetCharacteristics(g_nvgfx_fd_nvhostctrlgpu, &g_nvgfx_gpu_characteristics); + //TODO: What is the above output officially used for? + } + + if (R_FAILED(rc)) nvClose(g_nvgfx_fd_nvhostctrlgpu); + + if (R_SUCCEEDED(rc)) g_nvgfxInitialized = 1; + + return rc; +} + +void nvgfxExit(void) { + if(!g_nvgfxInitialized)return; + + nvClose(g_nvgfx_fd_nvhostctrlgpu); + g_nvgfx_fd_nvhostctrlgpu = 0; + + g_nvgfxInitialized = 0; +} +