Added gfxInitResolution() + added gfx.h comments. Updated gfxGetFramebufferDisplayOffset() so that the returned pixel-offset is in a region that's not displayed when the x/y is out-of-bounds. Fixed g_gfx_framebuf_aligned_{width/height} init when the initial width/height is not the default 0. Updated nvioctlNvhostAsGpu_InitializeEx/nvioctlNvhostAsGpu_AllocSpace usage etc, required for using non-720p framebufs.

This commit is contained in:
yellows8 2017-12-20 20:18:16 -05:00
parent f00bc78569
commit d62709adc7
5 changed files with 21 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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