Skip to content

Commit

Permalink
attempt at hw texture copy
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanr13 committed Jan 7, 2025
1 parent 7a54c2d commit 6e09f03
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ extern bool g_infologs;
: (void) 0)

#define lwarn(format, ...) \
printf("\e[43;30m[WARNING](%s) " format "\e[0m\n", \
printf("\e[33;30m[WARNING](%s) " format "\e[0m\n", \
__func__ __VA_OPT__(, ) __VA_ARGS__)
#define lerror(format, ...) \
printf("\e[41m[ERROR](%s) " format "\e[0m\n", \
printf("\e[31m[ERROR](%s) " format "\e[0m\n", \
__func__ __VA_OPT__(, ) __VA_ARGS__)

#define print_fvec(v) printf("[%f,%f,%f,%f] ", (v)[0], (v)[1], (v)[2], (v)[3])
Expand Down
51 changes: 46 additions & 5 deletions src/pica/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ FBInfo* fbcache_find_within(GPU* gpu, u32 color_paddr) {
for (int i = 0; i < FB_MAX; i++) {
if (gpu->fbs.d[i].color_paddr <= color_paddr &&
color_paddr < gpu->fbs.d[i].color_paddr +
gpu->fbs.d[i].width * gpu->fbs.d[i].height *
gpu->fbs.d[i].color_Bpp) {
gpu->fbs.d[i].width * gpu->fbs.d[i].height *
gpu->fbs.d[i].color_Bpp) {
newfb = &gpu->fbs.d[i];
break;
}
Expand Down Expand Up @@ -346,6 +346,18 @@ TexInfo* texcache_load(GPU* gpu, u32 paddr) {
return tex;
}

TexInfo* texcache_find_within(GPU* gpu, u32 paddr) {
TexInfo* tex = NULL;
for (int i = 0; i < TEX_MAX; i++) {
if (gpu->textures.d[i].paddr <= paddr &&
paddr < gpu->textures.d[i].paddr + gpu->textures.d[i].size) {
tex = &gpu->textures.d[i];
break;
}
}
return tex;
}

void gpu_update_cur_fb(GPU* gpu) {
if (gpu->cur_fb &&
gpu->cur_fb->color_paddr == (gpu->io.fb.colorbuf_loc << 3))
Expand Down Expand Up @@ -392,9 +404,9 @@ void gpu_update_cur_fb(GPU* gpu) {

void gpu_display_transfer(GPU* gpu, u32 paddr, int yoff, bool scalex,
bool scaley, bool top) {
// the source can be offset into or before an existing framebuffer, so we need to
// account for this

// the source can be offset into or before an existing framebuffer, so we
// need to account for this
FBInfo* fb = NULL;
int yoffsrc;
for (int i = 0; i < FB_MAX; i++) {
Expand Down Expand Up @@ -424,6 +436,35 @@ void gpu_display_transfer(GPU* gpu, u32 paddr, int yoff, bool scalex,

void gpu_texture_copy(GPU* gpu, u32 srcpaddr, u32 dstpaddr, u32 size,
u32 srcpitch, u32 srcgap, u32 dstpitch, u32 dstgap) {

FBInfo* srcfb = fbcache_find_within(gpu, srcpaddr);
TexInfo* dsttex = texcache_find_within(gpu, dstpaddr);

linfo("texture copy from %x to %x size=%d", srcpaddr, dstpaddr, size);

if (srcfb && dsttex) {
// do a hardware copy

linfo("copying from fb at %x to texture at %x", srcfb->color_paddr,
dsttex->paddr);

// need to handle more general cases at some point

if (srcgap == 0 && dstgap == 0) {
int yoff = (srcpaddr - srcfb->color_paddr) /
(srcfb->width * srcfb->color_Bpp);
int height = size / srcfb->width;
// this feels wrong but it works ... :/
glBindFramebuffer(GL_READ_FRAMEBUFFER, srcfb->fbo);
glBindTexture(GL_TEXTURE_2D, dsttex->tex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0,
srcfb->width * ctremu.videoscale,
srcfb->height * ctremu.videoscale, 0);
}

return;
}

u8* src = PTR(srcpaddr);
u8* dst = PTR(dstpaddr);

Expand Down

0 comments on commit 6e09f03

Please sign in to comment.