diff --git a/nx/include/switch/gfx/gfx.h b/nx/include/switch/gfx/gfx.h index 763c4405..4f83befa 100644 --- a/nx/include/switch/gfx/gfx.h +++ b/nx/include/switch/gfx/gfx.h @@ -10,6 +10,11 @@ void gfxExit(void); /// Note that "framebuffer" here is technically windowbuffer. +/// The default resolution is 720p, however you should use gfxGetFramebuffer() to get the current width/height. + +/// This can only be used before calling gfxInitDefault(), this will use fatalSimple() otherwise. If the input is 0, the default resolution will be used during gfxInitDefault(). This sets the maximum resolution for the framebuffer, used during gfxInitDefault(). This is also used as the current resolution. The width/height are reset to the default when gfxExit() is used. +void gfxInitResolution(u32 width, u32 height); + void gfxWaitForVsync(); void gfxSwapBuffers(); u8* gfxGetFramebuffer(u32* width, u32* height); @@ -25,8 +30,7 @@ static inline u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) { gfxGetFramebuffer(&width, &height); - if (x >= width) x = width-1; - if (y >= height) y = height-1; + if (x >= width || y >= height) return (gfxGetFramebufferSize()-4)/4;//Return the last pixel-offset in the buffer, the data located here is not displayed due to alignment. y = height-1-y; diff --git a/nx/include/switch/gfx/nvioctl.h b/nx/include/switch/gfx/nvioctl.h index 735b622c..10874458 100644 --- a/nx/include/switch/gfx/nvioctl.h +++ b/nx/include/switch/gfx/nvioctl.h @@ -91,7 +91,7 @@ Result nvioctlNvhostAsGpu_BindChannel(u32 fd, u32 channel_fd); Result nvioctlNvhostAsGpu_AllocSpace(u32 fd, u32 pages, u32 page_size, u32 flags, u64 align, u64 *offset); Result nvioctlNvhostAsGpu_MapBufferEx(u32 fd, u32 flags, u32 kind, u32 nvmap_handle, u32 page_size, u64 buffer_offset, u64 mapping_size, u64 input_offset, u64 *offset); Result nvioctlNvhostAsGpu_GetVARegions(u32 fd, nvioctl_va_region regions[2]); -Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size); +Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size, u32 flags); Result nvioctlNvmap_Create(u32 fd, u32 size, u32 *nvmap_handle); Result nvioctlNvmap_FromId(u32 fd, u32 id, u32 *nvmap_handle); diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index f20e7b0b..a61eb231 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -164,12 +164,12 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L if (g_gfx_framebuf_width==0 || g_gfx_framebuf_height==0) { g_gfx_framebuf_width = 1280; - g_gfx_framebuf_aligned_width = (g_gfx_framebuf_width+15) & ~15;//Align to 16. - g_gfx_framebuf_height = 720; - g_gfx_framebuf_aligned_height = (g_gfx_framebuf_height+127) & ~127;//Align to 128. } + g_gfx_framebuf_aligned_width = (g_gfx_framebuf_width+15) & ~15;//Align to 16. + g_gfx_framebuf_aligned_height = (g_gfx_framebuf_height+127) & ~127;//Align to 128. + g_gfx_singleframebuf_size = g_gfx_framebuf_aligned_width*g_gfx_framebuf_aligned_height*4; g_gfx_BufferInitData.width = g_gfx_framebuf_width; @@ -352,6 +352,13 @@ void gfxExit(void) { memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested)); } +void gfxInitResolution(u32 width, u32 height) { + if (g_gfxInitialized) fatalSimple(MAKERESULT(MODULE_LIBNX, LIBNX_ALREADYINITIALIZED)); + + g_gfx_framebuf_width = width; + g_gfx_framebuf_height = height; +} + Result _gfxGraphicBufferInit(s32 buf, u32 nvmap_handle) { g_gfx_BufferInitData.refcount = buf; g_gfx_BufferInitData.data.nvmap_handle0 = nvmap_handle; diff --git a/nx/source/gfx/ioctl/nvhost-as-gpu.c b/nx/source/gfx/ioctl/nvhost-as-gpu.c index 6027f37c..378879b5 100644 --- a/nx/source/gfx/ioctl/nvhost-as-gpu.c +++ b/nx/source/gfx/ioctl/nvhost-as-gpu.c @@ -96,7 +96,7 @@ Result nvioctlNvhostAsGpu_GetVARegions(u32 fd, nvioctl_va_region regions[2]) { return rc; } -Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size) { +Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size, u32 flags) { struct { __in u32 big_page_size; // depends on GPU's available_big_page_sizes; 0=default __in s32 as_fd; // ignored; passes 0 @@ -109,6 +109,7 @@ Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size) { memset(&data, 0, sizeof(data)); data.big_page_size = big_page_size; + data.flags = flags; return nvIoctl(fd, _IOW(0x41, 0x09, data), &data); } diff --git a/nx/source/gfx/nvgfx.c b/nx/source/gfx/nvgfx.c index 92542fa3..0314741a 100644 --- a/nx/source/gfx/nvgfx.c +++ b/nx/source/gfx/nvgfx.c @@ -173,12 +173,12 @@ Result nvgfxInitialize(void) { if (R_SUCCEEDED(rc)) rc = nvOpen(&g_nvgfx_fd_nvhostasgpu, "/dev/nvhost-as-gpu"); - if (R_SUCCEEDED(rc)) rc = nvioctlNvhostAsGpu_InitializeEx(g_nvgfx_fd_nvhostasgpu, 1); + if (R_SUCCEEDED(rc)) rc = nvioctlNvhostAsGpu_InitializeEx(g_nvgfx_fd_nvhostasgpu, 1, /*0*/0x10000); //Officially this is used twice here - only use it once here. if (R_SUCCEEDED(rc)) rc = nvioctlNvhostAsGpu_GetVARegions(g_nvgfx_fd_nvhostasgpu, g_nvgfx_nvhostasgpu_varegions); - if (R_SUCCEEDED(rc)) rc = nvioctlNvhostAsGpu_AllocSpace(g_nvgfx_fd_nvhostasgpu, 0x10000, 0x20000, 0, 0x10000, &g_nvgfx_nvhostasgpu_allocspace_offset); + if (R_SUCCEEDED(rc)) rc = nvioctlNvhostAsGpu_AllocSpace(g_nvgfx_fd_nvhostasgpu, 0x10000, /*0x20000*/0x10000, 0, 0x10000, &g_nvgfx_nvhostasgpu_allocspace_offset); if (R_SUCCEEDED(rc)) rc = nvOpen(&g_nvgfx_fd_nvmap, "/dev/nvmap"); /*if (R_SUCCEEDED(rc)) rc = nvmapobjSetup(&nvmap_objs[0], 0, 0, 0x20000, 0);