From 4645ef7004d4693f69b40d46074e6ee3eabb1672 Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 16 Sep 2018 16:37:31 +0200 Subject: [PATCH] gfx: Add gfxAppendFence. Remove obsolete comments related to double buffering. --- nx/include/switch/display/gfx.h | 8 ++++++-- nx/source/display/gfx.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/nx/include/switch/display/gfx.h b/nx/include/switch/display/gfx.h index af6ee6c8..fbb7b8b2 100644 --- a/nx/include/switch/display/gfx.h +++ b/nx/include/switch/display/gfx.h @@ -7,6 +7,7 @@ */ #pragma once #include "../types.h" +#include "../nvidia/fence.h" /// Converts red, green, blue, and alpha components to packed RGBA8. #define RGBA8(r,g,b,a) (((r)&0xff)|(((g)&0xff)<<8)|(((b)&0xff)<<16)|(((a)&0xff)<<24)) @@ -53,7 +54,7 @@ void gfxInitResolutionDefault(void); /// When the input is invalid this returns without changing the crop data, this includes the input values being larger than the framebuf width/height. /// This will update the display width/height returned by \ref gfxGetFramebuffer, with that width/height being reset to the default when required. /// \ref gfxGetFramebufferDisplayOffset uses absolute x/y, it will not adjust for non-zero crop left/top. -/// The new crop config will not take affect with double-buffering disabled. When used during frame-drawing, this should be called before \ref gfxGetFramebuffer. +/// When used during frame-drawing, this should be called before \ref gfxGetFramebuffer. /// The right and bottom params are aligned to 4. void gfxConfigureCrop(s32 left, s32 top, s32 right, s32 bottom); @@ -69,7 +70,10 @@ void gfxConfigureAutoResolutionDefault(bool enable); /// Waits for vertical sync. void gfxWaitForVsync(void); -/// Swaps the framebuffers (for double-buffering). +/// Appends one or more fences that the display service will wait on before rendering the current framebuffer. Note that only up to 4 fences can be submitted. +void gfxAppendFence(NvMultiFence* mf); + +/// Swaps the framebuffers. void gfxSwapBuffers(void); /// Get the specified framebuffer nvmap handle where index specifies the buffer number beginning with the back buffer, with optional output ptr for the offset in the buffer. diff --git a/nx/source/display/gfx.c b/nx/source/display/gfx.c index efd0894b..44e51bcd 100644 --- a/nx/source/display/gfx.c +++ b/nx/source/display/gfx.c @@ -69,7 +69,7 @@ static BqQueueBufferInput g_gfxQueueBufferData = { static BqGraphicBuffer g_gfx_BufferInitData = { .magic = 0x47424652,//"RFBG"/'GBFR' .format = 0x1, - .usage = 0xb00, + .usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, .pid = 0x2a, //Official sw sets this to the output of "getpid()", which calls a func which is hard-coded for returning 0x2a. .refcount = 0x0, //Official sw sets this to the output of "android_atomic_inc()". @@ -137,11 +137,20 @@ static Result _gfxDequeueBuffer(void) { return rc; } +void gfxAppendFence(NvMultiFence* mf) { + u32 max_fences = 4 - g_gfxQueueBufferData.fence.num_fences; + u32 num_fences = max_fences < mf->num_fences ? max_fences : mf->num_fences; + + for (u32 i = 0; i < num_fences; i ++) + g_gfxQueueBufferData.fence.fences[g_gfxQueueBufferData.fence.num_fences++] = mf->fences[i]; +} + static Result _gfxQueueBuffer(void) { Result rc=0; if (g_gfxCurrentProducerBuffer >= 0) { rc = bqQueueBuffer(&g_gfxBinderSession, g_gfxCurrentProducerBuffer, &g_gfxQueueBufferData, &g_gfx_QueueBuffer_QueueBufferOutput); + g_gfxQueueBufferData.fence.num_fences = 0; g_gfxCurrentProducerBuffer = -1; } @@ -153,6 +162,7 @@ static Result _gfxCancelBuffer(void) { if (g_gfxCurrentProducerBuffer >= 0) { rc = bqCancelBuffer(&g_gfxBinderSession, g_gfxCurrentProducerBuffer, &g_gfxQueueBufferData.fence); + g_gfxQueueBufferData.fence.num_fences = 0; g_gfxCurrentProducerBuffer = -1; }