Added nvgfx.

This commit is contained in:
yellows8 2017-11-12 23:57:30 -05:00
parent 0c19c1738c
commit 619a9a378c
4 changed files with 47 additions and 0 deletions

View File

@ -41,6 +41,7 @@ extern "C" {
#include <switch/gfx/gfxproducer.h>
#include <switch/gfx/ioctl.h>
#include <switch/gfx/nvioctl.h>
#include <switch/gfx/nvgfx.h>
#include <switch/devices/usb_comms.h>
#include <switch/devices/fs_dev.h>

View File

@ -0,0 +1,2 @@
Result nvgfxInitialize(void);
void nvgfxExit(void);

View File

@ -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);

40
nx/source/gfx/nvgfx.c Normal file
View File

@ -0,0 +1,40 @@
#include <string.h>
#include <switch.h>
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;
}