mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Moved framebuf width/height/size fields from nvgfx into gfx + code used with those. Moved g_gfxprod_BufferInitData into gfx + renamed it. Moved code for using bufferProducerGraphicBufferInit() / struct init code into gfx. Removed commented out code for g_nvgfx_totalframebufs init. Replaced hard-coded width/height constants in gfx with the width/height fields.
This commit is contained in:
parent
e128fd58f1
commit
f00bc78569
@ -23,10 +23,13 @@ static bufferProducerQueueBufferOutput g_gfx_QueueBuffer_QueueBufferOutput;
|
||||
|
||||
static bool g_gfxDoubleBuf = 1;
|
||||
|
||||
static size_t g_gfx_framebuf_width=0, g_gfx_framebuf_aligned_width=0;
|
||||
static size_t g_gfx_framebuf_height=0, g_gfx_framebuf_aligned_height=0;
|
||||
size_t g_gfx_singleframebuf_size=0;
|
||||
|
||||
extern u32 __nx_applet_type;
|
||||
|
||||
extern u32 g_nvgfx_totalframebufs;
|
||||
extern size_t g_nvgfx_singleframebuf_size;
|
||||
extern nvioctl_fence g_nvgfx_nvhostgpu_gpfifo_fence;
|
||||
|
||||
//static Result _gfxGetDisplayResolution(u64 *width, u64 *height);
|
||||
@ -55,6 +58,38 @@ static bufferProducerQueueBufferInput g_gfxQueueBufferData = {
|
||||
}
|
||||
};
|
||||
|
||||
//Some of this struct is based on tegra_dc_ext_flip_windowattr.
|
||||
//TODO: How much of this struct do official apps really set? Most of it seems to be used as-is from the bufferProducerRequestBuffer() output.
|
||||
static bufferProducerGraphicBuffer g_gfx_BufferInitData = {
|
||||
.magic = 0x47424652,//"RFBG"/'GBFR'
|
||||
.format = 0x1,
|
||||
.usage = 0xb00,
|
||||
|
||||
.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()".
|
||||
|
||||
.numFds = 0x0,
|
||||
.numInts = sizeof(g_gfx_BufferInitData.data)>>2,//0x51
|
||||
|
||||
.data = {
|
||||
.unk_x0 = 0xffffffff,
|
||||
.unk_x8 = 0x0,
|
||||
.unk_xc = 0xdaffcaff,
|
||||
.unk_x10 = 0x2a,
|
||||
.unk_x14 = 0x0,
|
||||
.unk_x18 = 0xb00,
|
||||
.unk_x1c = 0x1,
|
||||
.unk_x20 = 0x1,
|
||||
.unk_x2c = 0x1,
|
||||
.unk_x30 = 0x0,
|
||||
.flags = 0x532120,
|
||||
.unk_x40 = 0x1,
|
||||
.unk_x44 = 0x3,
|
||||
.unk_x54 = 0xfe,
|
||||
.unk_x58 = 0x4,
|
||||
}
|
||||
};
|
||||
|
||||
static Result _gfxGetNativeWindowID(u8 *buf, u64 size, s32 *out_ID) {
|
||||
u32 *bufptr = (u32*)buf;
|
||||
|
||||
@ -82,7 +117,7 @@ static Result _gfxDequeueBuffer(void) {
|
||||
|
||||
memcpy(&tmp_fence, fence, sizeof(bufferProducerFence));//Offical sw waits on the fence from the previous DequeueBuffer call. Using the fence from the current DequeueBuffer call results in nvgfxEventWait() failing.
|
||||
|
||||
rc = bufferProducerDequeueBuffer(async, 1280, 720, 0, 0x300, &g_gfxCurrentProducerBuffer, fence);
|
||||
rc = bufferProducerDequeueBuffer(async, g_gfx_framebuf_width, g_gfx_framebuf_height, 0, 0x300, &g_gfxCurrentProducerBuffer, fence);
|
||||
|
||||
if (R_SUCCEEDED(rc) && tmp_fence.is_valid) rc = nvgfxEventWait(tmp_fence.nv_fences[0].id, tmp_fence.nv_fences[0].value, -1);
|
||||
|
||||
@ -127,6 +162,29 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L
|
||||
memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested));
|
||||
memset(&g_gfx_DequeueBuffer_fence, 0, sizeof(g_gfx_DequeueBuffer_fence));
|
||||
|
||||
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_singleframebuf_size = g_gfx_framebuf_aligned_width*g_gfx_framebuf_aligned_height*4;
|
||||
|
||||
g_gfx_BufferInitData.width = g_gfx_framebuf_width;
|
||||
g_gfx_BufferInitData.height = g_gfx_framebuf_height;
|
||||
g_gfx_BufferInitData.stride = g_gfx_framebuf_aligned_width;
|
||||
|
||||
g_gfx_BufferInitData.data.width_unk0 = g_gfx_framebuf_width;
|
||||
g_gfx_BufferInitData.data.width_unk1 = g_gfx_framebuf_width;
|
||||
g_gfx_BufferInitData.data.height_unk = g_gfx_framebuf_height;
|
||||
|
||||
g_gfx_BufferInitData.data.byte_stride = g_gfx_framebuf_aligned_width*4;
|
||||
|
||||
g_gfx_BufferInitData.data.buffer_size0 = g_gfx_singleframebuf_size;
|
||||
g_gfx_BufferInitData.data.buffer_size1 = g_gfx_singleframebuf_size;
|
||||
|
||||
rc = viInitialize(servicetype);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
@ -218,6 +276,9 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L
|
||||
g_gfxFramebuf = NULL;
|
||||
g_gfxFramebufSize = 0;
|
||||
|
||||
g_gfx_framebuf_width = 0;
|
||||
g_gfx_framebuf_height = 0;
|
||||
|
||||
memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested));
|
||||
}
|
||||
|
||||
@ -285,9 +346,22 @@ void gfxExit(void) {
|
||||
g_gfxFramebuf = NULL;
|
||||
g_gfxFramebufSize = 0;
|
||||
|
||||
g_gfx_framebuf_width = 0;
|
||||
g_gfx_framebuf_height = 0;
|
||||
|
||||
memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested));
|
||||
}
|
||||
|
||||
Result _gfxGraphicBufferInit(s32 buf, u32 nvmap_handle) {
|
||||
g_gfx_BufferInitData.refcount = buf;
|
||||
g_gfx_BufferInitData.data.nvmap_handle0 = nvmap_handle;
|
||||
g_gfx_BufferInitData.data.nvmap_handle1 = nvmap_handle;
|
||||
g_gfx_BufferInitData.data.buffer_offset = g_gfx_singleframebuf_size*buf;
|
||||
g_gfx_BufferInitData.data.timestamp = svcGetSystemTick();
|
||||
|
||||
return bufferProducerGraphicBufferInit(buf, &g_gfx_BufferInitData);
|
||||
}
|
||||
|
||||
static void _waitevent(Handle *handle) {
|
||||
s32 tmpindex=0;
|
||||
Result rc=0, rc2=0;
|
||||
@ -316,14 +390,14 @@ void gfxSwapBuffers() {
|
||||
}
|
||||
|
||||
u8* gfxGetFramebuffer(u32* width, u32* height) {
|
||||
if(width) *width = 1280;
|
||||
if(height) *height = 720;
|
||||
if(width) *width = g_gfx_framebuf_width;
|
||||
if(height) *height = g_gfx_framebuf_height;
|
||||
|
||||
return &g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size];
|
||||
return &g_gfxFramebuf[g_gfxCurrentBuffer*g_gfx_singleframebuf_size];
|
||||
}
|
||||
|
||||
size_t gfxGetFramebufferSize(void) {
|
||||
return g_nvgfx_singleframebuf_size;
|
||||
return g_gfx_singleframebuf_size;
|
||||
}
|
||||
|
||||
void gfxSetDoubleBuffering(bool doubleBuffering) {
|
||||
@ -331,7 +405,7 @@ void gfxSetDoubleBuffering(bool doubleBuffering) {
|
||||
}
|
||||
|
||||
void gfxFlushBuffers(void) {
|
||||
armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size], g_nvgfx_singleframebuf_size);
|
||||
armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_gfx_singleframebuf_size], g_gfx_singleframebuf_size);
|
||||
}
|
||||
|
||||
/*static Result _gfxGetDisplayResolution(u64 *width, u64 *height) {
|
||||
|
@ -36,9 +36,6 @@ static size_t g_nvgfx_nvhost_userdata_size;
|
||||
static u32 g_nvgfx_nvhostctrl_eventres;
|
||||
|
||||
u32 g_nvgfx_totalframebufs = 0;
|
||||
size_t g_nvgfx_framebuf_width=0, g_nvgfx_framebuf_aligned_width=0;
|
||||
size_t g_nvgfx_framebuf_height=0, g_nvgfx_framebuf_aligned_height=0;
|
||||
size_t g_nvgfx_singleframebuf_size=0;
|
||||
|
||||
static nvmapobj nvmap_objs[18];
|
||||
|
||||
@ -48,37 +45,9 @@ static u64 nvmap_obj6_mapbuffer_xdb_offset;
|
||||
|
||||
static u64 g_nvgfx_gpfifo_pos = 0;
|
||||
|
||||
//Some of this struct is based on tegra_dc_ext_flip_windowattr.
|
||||
//TODO: How much of this struct do official apps really set? Most of it seems to be used as-is from the bufferProducerRequestBuffer() output.
|
||||
static bufferProducerGraphicBuffer g_gfxprod_BufferInitData = {
|
||||
.magic = 0x47424652,//"RFBG"/'GBFR'
|
||||
.format = 0x1,
|
||||
.usage = 0xb00,
|
||||
extern size_t g_gfx_singleframebuf_size;
|
||||
|
||||
.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()".
|
||||
|
||||
.numFds = 0x0,
|
||||
.numInts = sizeof(g_gfxprod_BufferInitData.data)>>2,//0x51
|
||||
|
||||
.data = {
|
||||
.unk_x0 = 0xffffffff,
|
||||
.unk_x8 = 0x0,
|
||||
.unk_xc = 0xdaffcaff,
|
||||
.unk_x10 = 0x2a,
|
||||
.unk_x14 = 0x0,
|
||||
.unk_x18 = 0xb00,
|
||||
.unk_x1c = 0x1,
|
||||
.unk_x20 = 0x1,
|
||||
.unk_x2c = 0x1,
|
||||
.unk_x30 = 0x0,
|
||||
.flags = 0x532120,
|
||||
.unk_x40 = 0x1,
|
||||
.unk_x44 = 0x3,
|
||||
.unk_x54 = 0xfe,
|
||||
.unk_x58 = 0x4,
|
||||
}
|
||||
};
|
||||
Result _gfxGraphicBufferInit(s32 buf, u32 nvmap_handle);
|
||||
|
||||
Result nvmapobjInitialize(nvmapobj *obj, size_t size) {
|
||||
Result rc=0;
|
||||
@ -143,7 +112,7 @@ Result nvgfxInitialize(void) {
|
||||
|
||||
g_nvgfx_nvhostctrl_eventhandle = INVALID_HANDLE;
|
||||
|
||||
g_nvgfx_totalframebufs = 2;//4;
|
||||
g_nvgfx_totalframebufs = 2;
|
||||
|
||||
memset(nvmap_objs, 0, sizeof(nvmap_objs));
|
||||
|
||||
@ -163,16 +132,6 @@ Result nvgfxInitialize(void) {
|
||||
|
||||
g_nvgfx_gpfifo_pos = 0;
|
||||
|
||||
if (g_nvgfx_framebuf_width==0 || g_nvgfx_framebuf_height==0) {
|
||||
g_nvgfx_framebuf_width = 1280;
|
||||
g_nvgfx_framebuf_aligned_width = (g_nvgfx_framebuf_width+15) & ~15;//Align to 16.
|
||||
|
||||
g_nvgfx_framebuf_height = 720;
|
||||
g_nvgfx_framebuf_aligned_height = (g_nvgfx_framebuf_height+127) & ~127;//Align to 128.
|
||||
}
|
||||
|
||||
g_nvgfx_singleframebuf_size = g_nvgfx_framebuf_aligned_width*g_nvgfx_framebuf_aligned_height*4;
|
||||
|
||||
//All of the below sizes for nvmapobjInitialize are from certain official sw.
|
||||
//if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[0], 0x1000);
|
||||
if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[1], 0x10000);
|
||||
@ -180,7 +139,7 @@ Result nvgfxInitialize(void) {
|
||||
if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[3], 0x10000);
|
||||
if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[4], 0x59000);
|
||||
//if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[5], 0x1000000);
|
||||
if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[6], g_nvgfx_totalframebufs*g_nvgfx_singleframebuf_size);
|
||||
if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[6], g_nvgfx_totalframebufs*g_gfx_singleframebuf_size);
|
||||
//if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[7], 0x1000000);
|
||||
//if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[8], 0x800000);
|
||||
//if (R_SUCCEEDED(rc)) rc = nvmapobjInitialize(&nvmap_objs[9], 0x100000);
|
||||
@ -296,25 +255,12 @@ Result nvgfxInitialize(void) {
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
for(pos=0; pos<g_nvgfx_totalframebufs; pos++) {
|
||||
rc = nvioctlNvhostAsGpu_MapBufferEx(g_nvgfx_fd_nvhostasgpu, 0x100, 0xdb, framebuf_nvmap_handle, 0, pos*g_nvgfx_singleframebuf_size, g_nvgfx_singleframebuf_size, nvmap_obj6_mapbuffer_xdb_offset, NULL);
|
||||
rc = nvioctlNvhostAsGpu_MapBufferEx(g_nvgfx_fd_nvhostasgpu, 0x100, 0xdb, framebuf_nvmap_handle, 0, pos*g_gfx_singleframebuf_size, g_gfx_singleframebuf_size, nvmap_obj6_mapbuffer_xdb_offset, NULL);
|
||||
if (R_FAILED(rc)) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
g_gfxprod_BufferInitData.width = g_nvgfx_framebuf_width;
|
||||
g_gfxprod_BufferInitData.height = g_nvgfx_framebuf_height;
|
||||
g_gfxprod_BufferInitData.stride = g_nvgfx_framebuf_aligned_width;
|
||||
|
||||
g_gfxprod_BufferInitData.data.width_unk0 = g_nvgfx_framebuf_width;
|
||||
g_gfxprod_BufferInitData.data.width_unk1 = g_nvgfx_framebuf_width;
|
||||
g_gfxprod_BufferInitData.data.height_unk = g_nvgfx_framebuf_height;
|
||||
|
||||
g_gfxprod_BufferInitData.data.byte_stride = g_nvgfx_framebuf_aligned_width*4;
|
||||
|
||||
g_gfxprod_BufferInitData.data.buffer_size0 = g_nvgfx_singleframebuf_size;
|
||||
g_gfxprod_BufferInitData.data.buffer_size1 = g_nvgfx_singleframebuf_size;
|
||||
|
||||
rc = bufferProducerQuery(NATIVE_WINDOW_FORMAT, &tmp);//TODO: What does official sw use the output from this for?
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
@ -333,13 +279,7 @@ Result nvgfxInitialize(void) {
|
||||
|
||||
//The above gets a nvmap_handle, but normally it's the same value passed to nvioctlNvmap_GetId().
|
||||
|
||||
g_gfxprod_BufferInitData.refcount = i;
|
||||
g_gfxprod_BufferInitData.data.nvmap_handle0 = tmpval;
|
||||
g_gfxprod_BufferInitData.data.nvmap_handle1 = tmpval;
|
||||
g_gfxprod_BufferInitData.data.buffer_offset = g_nvgfx_singleframebuf_size*i;
|
||||
g_gfxprod_BufferInitData.data.timestamp = svcGetSystemTick();
|
||||
|
||||
rc = bufferProducerGraphicBufferInit(i, &g_gfxprod_BufferInitData);
|
||||
rc = _gfxGraphicBufferInit(i, tmpval);
|
||||
if (R_FAILED(rc)) break;
|
||||
}
|
||||
}
|
||||
@ -418,9 +358,6 @@ Result nvgfxInitialize(void) {
|
||||
g_nvgfx_fd_nvhostasgpu = 0;
|
||||
g_nvgfx_fd_nvhostctrlgpu = 0;
|
||||
|
||||
g_nvgfx_framebuf_width = 0;
|
||||
g_nvgfx_framebuf_height = 0;
|
||||
|
||||
nvmapobjCloseAll();
|
||||
|
||||
if(g_nvgfx_nvhost_userdata) {
|
||||
@ -463,9 +400,6 @@ void nvgfxExit(void) {
|
||||
g_nvgfx_fd_nvhostasgpu = 0;
|
||||
g_nvgfx_fd_nvhostctrlgpu = 0;
|
||||
|
||||
g_nvgfx_framebuf_width = 0;
|
||||
g_nvgfx_framebuf_height = 0;
|
||||
|
||||
nvmapobjCloseAll();
|
||||
|
||||
if(g_nvgfx_nvhost_userdata) {
|
||||
|
Loading…
Reference in New Issue
Block a user