Skip to content

Commit

Permalink
store softbuf as RGBA4
Browse files Browse the repository at this point in the history
this is faster for some reason???
  • Loading branch information
skyfloogle committed Jan 6, 2024
1 parent a2c1844 commit 19cf78a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
2 changes: 2 additions & 0 deletions include/vb_dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ extern shaderProgram_s sFinal;

extern bool tileVisible[2048];

extern u8 brightness[4];

// video_hard
extern C3D_Tex screenTexHard;
extern C3D_RenderTarget *screenTarget;
Expand Down
22 changes: 16 additions & 6 deletions source/3ds/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ shaderProgram_s sFinal;
DVLB_s *sSoft_dvlb;
shaderProgram_s sSoft;

u8 brightness[4];

bool tileVisible[2048];

void processColumnTable() {
Expand Down Expand Up @@ -169,6 +171,19 @@ void video_init() {
void video_render(int alt_buf) {
C3D_FrameBegin(0);

#ifdef COLTABLESCALE
int col_scale = maxRepeat >= 4 ? maxRepeat / 4 : 1;
#else
int col_scale = maxRepeat;
#endif
brightness[0] = 0;
brightness[1] = tVIPREG.BRTA * col_scale;
if (brightness[1] > 127) brightness[1] = 127;
brightness[2] = tVIPREG.BRTB * col_scale;
if (brightness[2] > 127) brightness[2] = 127;
brightness[3] = (tVIPREG.BRTA + tVIPREG.BRTB + tVIPREG.BRTC) * col_scale;
if (brightness[3] > 127) brightness[3] = 127;

C3D_AttrInfo *attrInfo = C3D_GetAttrInfo();
AttrInfo_Init(attrInfo);
AttrInfo_AddLoader(attrInfo, 0, GPU_SHORT, 4);
Expand Down Expand Up @@ -202,15 +217,10 @@ void video_render(int alt_buf) {
C3D_FrameDrawOn(screenTarget);
C3D_BindProgram(&sFinal);

// It seems very difficult to get the softbuf colours to match
// those of the hard render for some reason.
// The closest I got was trying to emulate the same dot product.
// Note that it's dotted with 0xff8080ff: 0xffffffff was too bright.
C3D_TexEnv *env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_CONSTANT, 0);
C3D_TexEnvOpAlpha(env, GPU_TEVOP_A_SRC_R, 0, 0);
C3D_TexEnvColor(env, 0xff8080ff);
C3D_TexEnvColor(env, (brightness[1] << 16) | (brightness[2] << 8) | (brightness[3]) | 0xff808080);
C3D_TexEnvFunc(env, C3D_RGB, GPU_DOT3_RGB);

C3D_ImmDrawBegin(GPU_GEOMETRY_PRIM);
Expand Down
25 changes: 8 additions & 17 deletions source/3ds/video_hard.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,17 @@ void setRegularDrawing() {
}

void video_hard_render() {
#ifdef COLTABLESCALE
int col_scale = maxRepeat >= 4 ? maxRepeat / 4 : 1;
#else
int col_scale = maxRepeat;
#endif
float cols[4] = {0,
(tVIPREG.BRTA * col_scale + 0x80) / 256.0,
(tVIPREG.BRTB * col_scale + 0x80) / 256.0,
((tVIPREG.BRTA + tVIPREG.BRTB + tVIPREG.BRTC) * col_scale + 0x80) / 256.0};
u32 clearcol = (cols[tVIPREG.BKCOL] - 0.5) * 510;
C3D_RenderTargetClear(screenTarget, C3D_CLEAR_ALL, clearcol | (clearcol << 8) | (clearcol << 16) | 0xff000000, 0);
u8 clearcol = brightness[tVIPREG.BKCOL];
C3D_RenderTargetClear(screenTarget, C3D_CLEAR_ALL, ((clearcol | (clearcol << 8) | (clearcol << 16)) << 2) | 0xff000000, 0);
for (int i = 0; i < 4; i++) {
HWORD pal = tVIPREG.GPLT[i];
palettes[i].x = cols[(pal >> 6) & 3];
palettes[i].y = cols[(pal >> 4) & 3];
palettes[i].z = cols[(pal >> 2) & 3];
palettes[i].x = brightness[(pal >> 6) & 3] / 256.0 + 0.5;
palettes[i].y = brightness[(pal >> 4) & 3] / 256.0 + 0.5;
palettes[i].z = brightness[(pal >> 2) & 3] / 256.0 + 0.5;
pal = tVIPREG.JPLT[i];
palettes[i + 4].x = cols[(pal >> 6) & 3];
palettes[i + 4].y = cols[(pal >> 4) & 3];
palettes[i + 4].z = cols[(pal >> 2) & 3];
palettes[i + 4].x = brightness[(pal >> 6) & 3] / 256.0 + 0.5;
palettes[i + 4].y = brightness[(pal >> 4) & 3] / 256.0 + 0.5;
palettes[i + 4].z = brightness[(pal >> 2) & 3] / 256.0 + 0.5;
}

vcur = vbuf;
Expand Down
21 changes: 6 additions & 15 deletions source/3ds/video_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void video_soft_init() {
C3D_TexInitParams params;
params.width = 512;
params.height = 512;
params.format = GPU_L8;
params.format = GPU_RGBA4;
params.type = GPU_TEX_2D;
params.onVram = false;
params.maxLevel = 0;
Expand Down Expand Up @@ -74,19 +74,10 @@ void update_texture_cache_soft() {
void video_soft_render(int alt_buf) {
// copy framebuffer
uint32_t *out_fb = C3D_Tex2DGetImagePtr(&screenTexSoft, 0, NULL);
#ifdef COLTABLESCALE
int col_scale = maxRepeat >= 4 ? maxRepeat / 4 : 1;
#else
int col_scale = maxRepeat;
#endif
int16_t colors[4] = {0, tVIPREG.BRTA * col_scale + 0x80, tVIPREG.BRTB * col_scale + 0x80, (tVIPREG.BRTA + tVIPREG.BRTB + tVIPREG.BRTC) * col_scale + 0x80};
if (colors[1] > 255) colors[1] = 255;
if (colors[2] > 255) colors[2] = 255;
if (colors[3] > 255) colors[3] = 255;
for (int eye = 0; eye < eye_count; eye++) {
for (int tx = 0; tx < 384 / 8; tx++) {
for (int ty = 0; ty < 224 / 8; ty++) {
uint32_t *out_tile = &out_fb[8 * 8 / 4 * (1 + eye * 256 / 8 + 512 / 8 * (512 / 8 - 1 - tx) + ty)];
uint32_t *out_tile = &out_fb[8 * 8 / 4 * 2 * (1 + eye * 256 / 8 + 512 / 8 * (512 / 8 - 1 - tx) + ty)];
uint16_t *in_fb_ptr = (uint16_t*)(V810_DISPLAY_RAM.pmemory + 0x10000 * eye + 0x8000 * alt_buf + tx * (256 / 4 * 8) + ty * 2);

for (int i = 0; i <= 2; i += 2) {
Expand All @@ -99,14 +90,14 @@ void video_soft_render(int alt_buf) {
in_fb_ptr += 256 / 4 / 2;
slice1 |= (*in_fb_ptr << 16);
in_fb_ptr += 256 / 4 / 2;

const static uint16_t colors[4] = {0, 0x88ff, 0x8f8f, 0xf88f};

#define SQUARE(x, i) { \
uint32_t left = x >> (0 + 4*i) & 0x00030003; \
uint32_t right = x >> (2 + 4*i) & 0x00030003; \
*--out_tile = (colors[left >> 16]) | \
(colors[right >> 16] << 8) | \
(colors[(uint16_t)left] << 16) | \
(colors[(uint16_t)right] << 24); \
*--out_tile = colors[(uint16_t)left] | (colors[(uint16_t)right] << 16); \
*--out_tile = colors[left >> 16] | (colors[right >> 16] << 16); \
}

SQUARE(slice2, 3);
Expand Down

0 comments on commit 19cf78a

Please sign in to comment.