Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
use 3 graphic buffers instead of 2 to make it harder to run out of bu…
Browse files Browse the repository at this point in the history
…ffers or accidentally tear one
  • Loading branch information
misson20000 committed Mar 7, 2018
1 parent d3f6118 commit 40227bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/libtransistor/display/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
16 changes: 10 additions & 6 deletions lib/display/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include<libtransistor/display/graphic_buffer_queue.h>
#include<libtransistor/display/surface.h>
#include<libtransistor/alloc_pages.h>
#include<libtransistor/util.h>

#include<stdio.h>

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 40227bb

Please sign in to comment.