From 40227bbdf14cd89d83256381fdea83b7092849ba Mon Sep 17 00:00:00 2001 From: misson20000 Date: Tue, 6 Mar 2018 20:53:39 -0800 Subject: [PATCH] use 3 graphic buffers instead of 2 to make it harder to run out of buffers or accidentally tear one --- include/libtransistor/display/surface.h | 2 +- lib/display/surface.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/libtransistor/display/surface.h b/include/libtransistor/display/surface.h index 1d776d0b..f6c52872 100644 --- a/include/libtransistor/display/surface.h +++ b/include/libtransistor/display/surface.h @@ -34,7 +34,7 @@ typedef struct { uint32_t *gpu_buffer_memory; uint32_t *gpu_buffer_memory_alloc; - graphic_buffer_t graphic_buffers[2]; + graphic_buffer_t graphic_buffers[3]; } surface_t; /** diff --git a/lib/display/surface.c b/lib/display/surface.c index 0b512f6e..c9f404ac 100644 --- a/lib/display/surface.c +++ b/lib/display/surface.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -29,12 +30,15 @@ result_t surface_create(surface_t *surface, uint64_t layer_id, igbp_t igbp) { goto fail_connect; } - surface->gpu_buffer_memory = alloc_pages(0x780000, 0x780000, NULL); + const uint64_t num_buffers = ARRAY_LENGTH(surface->graphic_buffers); + size_t buffer_size = num_buffers * 0x3c0000; + + surface->gpu_buffer_memory = alloc_pages(buffer_size, buffer_size, NULL); if(surface->gpu_buffer_memory == NULL) { return LIBTRANSISTOR_ERR_OUT_OF_MEMORY; } - if((r = svcSetMemoryAttribute(surface->gpu_buffer_memory, 0x780000, 0x8, 0x8)) != RESULT_OK) { + if((r = svcSetMemoryAttribute(surface->gpu_buffer_memory, buffer_size, 0x8, 0x8)) != RESULT_OK) { printf("failed svcsma\n"); goto fail_memory; } @@ -44,7 +48,7 @@ result_t surface_create(surface_t *surface, uint64_t layer_id, igbp_t igbp) { if((r = gpu_buffer_initialize( &surface->gpu_buffer, surface->gpu_buffer_memory, - 0x780000, 0, 0, 0x1000, 0)) != RESULT_OK) { + buffer_size, 0, 0, 0x1000, 0)) != RESULT_OK) { goto fail_memory_attribute; } @@ -56,12 +60,12 @@ result_t surface_create(surface_t *surface, uint64_t layer_id, igbp_t igbp) { gb_common.usage = 0xb00; gb_common.gpu_buffer = &surface->gpu_buffer; - for(int i = 0; i < 2; i++) { + for(int i = 0; i < ARRAY_LENGTH(surface->graphic_buffers); i++) { surface->graphic_buffers[i] = gb_common; surface->graphic_buffers[i].unknown = 0x3c0000 * i; // TODO: this isn't unknown; this is the offset within the gpu_buffer where the pixel data lives } - for(int i = 0; i < 2; i++) { + for(int i = 0; i < ARRAY_LENGTH(surface->graphic_buffers); i++) { if((r = igbp_set_preallocated_buffer(&surface->igbp, i, &surface->graphic_buffers[i])) != RESULT_OK) { goto fail_memory_attribute; } @@ -92,7 +96,7 @@ void surface_destroy(surface_t *surface) { gpu_buffer_destroy(&surface->gpu_buffer, NULL, NULL); - svcSetMemoryAttribute(surface->gpu_buffer_memory, 0x780000, 0x0, 0x0); + svcSetMemoryAttribute(surface->gpu_buffer_memory, 0x3c0000 * ARRAY_LENGTH(surface->graphic_buffers), 0x0, 0x0); free_pages(surface->gpu_buffer_memory); }