From fbce1e80295e2208bb11826b07563efef2ec3e57 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 18 Nov 2017 17:35:06 -0500 Subject: [PATCH] Use the output buffer value from gfxproducerDequeueBuffer() with gfxproducer calls. Set g_gfxCurrentBuffer in _gfxDequeueBuffer() with the output buffer value. Removed a comment. --- nx/include/switch/gfx/gfxproducer.h | 2 +- nx/source/gfx/gfx.c | 21 +++++++++++++++------ nx/source/gfx/gfxproducer.c | 4 +++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/nx/include/switch/gfx/gfxproducer.h b/nx/include/switch/gfx/gfxproducer.h index 5c2c1f09..72ef5466 100644 --- a/nx/include/switch/gfx/gfxproducer.h +++ b/nx/include/switch/gfx/gfxproducer.h @@ -2,7 +2,7 @@ Result gfxproducerInitialize(binderSession *session); void gfxproducerExit(); Result gfxproducerRequestBuffer(s32 bufferIdx); -Result gfxproducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u32 usage); +Result gfxproducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u32 usage, s32 *buf); Result gfxproducerQueueBuffer(s32 buf, u8 input[0x5c]); Result gfxproducerQuery(s32 what, s32* value); Result gfxproducerConnect(s32 api, bool producerControlledByApp); diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 73175d24..35bb1133 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -10,6 +10,7 @@ static u64 g_gfxNativeWindow_Size; static s32 g_gfxNativeWindow_ID; static binderSession g_gfxBinderSession; static s32 g_gfxCurrentBuffer = 0; +static s32 g_gfxCurrentProducerBuffer = 0; static u8 *g_gfxFramebuf; static size_t g_gfxFramebufSize; static size_t g_gfxFramebufSingleSize = 0x3c0000; @@ -23,7 +24,7 @@ static u32 g_gfxQueueBufferData[0x5c>>2] = { 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x1, 0x1, 0x42, -0x13f4, //Increased by 6/7 each time. +0x13f4, 0xffffffff, 0x0, 0xffffffff, 0x0, 0xffffffff, 0x0}; @@ -43,7 +44,13 @@ static Result _gfxGetNativeWindowID(u8 *buf, u64 size, s32 *out_ID) { } static Result _gfxDequeueBuffer() { - return gfxproducerDequeueBuffer(1, 1280, 720, 0, 0x300); + Result rc=0; + + rc = gfxproducerDequeueBuffer(1, 1280, 720, 0, 0x300, &g_gfxCurrentProducerBuffer); + + if (R_SUCCEEDED(rc)) g_gfxCurrentBuffer = g_gfxCurrentProducerBuffer & 1; + + return rc; } static Result _gfxQueueBuffer(s32 buf) { @@ -72,6 +79,7 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L g_gfxNativeWindow_ID = 0; g_gfxDisplayVsyncEvent = INVALID_HANDLE; g_gfxCurrentBuffer = 0; + g_gfxCurrentProducerBuffer = 0; g_gfxFramebuf = NULL; g_gfxFramebufSize = 0; @@ -106,12 +114,12 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L rc = _gfxDequeueBuffer(); if (R_FAILED(rc)) break; - rc = gfxproducerRequestBuffer(i); + rc = gfxproducerRequestBuffer(g_gfxCurrentProducerBuffer); if (R_FAILED(rc)) break; //Officially, nvioctlNvmap_FromID() and nvioctlChannel_SubmitGPFIFO() are used here. - rc = _gfxQueueBuffer(i); + rc = _gfxQueueBuffer(g_gfxCurrentProducerBuffer); if (R_FAILED(rc)) break; } } @@ -140,6 +148,7 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L g_gfxNativeWindow_ID = 0; g_gfxCurrentBuffer = 0; + g_gfxCurrentProducerBuffer = 0; g_gfxFramebuf = NULL; g_gfxFramebufSize = 0; } @@ -197,6 +206,7 @@ void gfxExit(void) { g_gfxNativeWindow_ID = 0; g_gfxCurrentBuffer = 0; + g_gfxCurrentProducerBuffer = 0; g_gfxFramebuf = NULL; g_gfxFramebufSize = 0; } @@ -210,8 +220,7 @@ void gfxWaitForVsync() { void gfxSwapBuffers() { Result rc=0; - rc = _gfxQueueBuffer(g_gfxCurrentBuffer); - g_gfxCurrentBuffer ^= 1; + rc = _gfxQueueBuffer(g_gfxCurrentProducerBuffer); if (R_SUCCEEDED(rc)) rc = _gfxDequeueBuffer(); diff --git a/nx/source/gfx/gfxproducer.c b/nx/source/gfx/gfxproducer.c index b8c68b1a..b3aba070 100644 --- a/nx/source/gfx/gfxproducer.c +++ b/nx/source/gfx/gfxproducer.c @@ -55,7 +55,7 @@ Result gfxproducerRequestBuffer(s32 bufferIdx) { return 0; } -Result gfxproducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u32 usage) { +Result gfxproducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u32 usage, s32 *buf) { Result rc; parcelContext parcel, parcel_reply; @@ -77,6 +77,8 @@ Result gfxproducerDequeueBuffer(bool async, u32 width, u32 height, s32 format, u //TODO: parse reply + *buf = parcelReadInt32(&parcel_reply); + return 0; }