Skip to content

Commit ac78131

Browse files
committed
Fix on real hardware!
Aside from a silly mistake, the main issue why this was crashing on real hardware before was because the 3DS GPU apparently does not like rendering using one shader program with a geo component and one without on the same frame. Making a dummy geoshader for the normal sprite case appears to fix it (not sure what performance cost this may entail).
1 parent 18d7991 commit ac78131

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed

source/base.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// citro2d's base.c, altered slightly to work with the geometry shader.
2-
// Look for to see meaningful changes: !! Changed for geo shader
32

43
#include "internal.h"
54
#include "render2d_shbin.h"
@@ -34,8 +33,10 @@ bool C2D_Init(size_t maxObjects)
3433
switch (shaderId) {
3534
case C2D_Normal:
3635
vertsPerSprite = 6;
36+
break;
3737
case C2D_ScanlineOffset:
3838
vertsPerSprite = 2;
39+
break;
3940
}
4041

4142
ctx->vtxBufSize = vertsPerSprite*maxObjects;
@@ -45,7 +46,7 @@ bool C2D_Init(size_t maxObjects)
4546

4647
switch (shaderId) {
4748
case C2D_Normal:
48-
ctx->shader = DVLB_ParseFile((u32*)render2g_shbin, render2d_shbin_size);
49+
ctx->shader = DVLB_ParseFile((u32*)render2d_shbin, render2d_shbin_size);
4950
break;
5051
case C2D_ScanlineOffset:
5152
ctx->shader = DVLB_ParseFile((u32*)render2g_shbin, render2g_shbin_size);
@@ -61,8 +62,13 @@ bool C2D_Init(size_t maxObjects)
6162
shaderProgramInit(&ctx->program);
6263
shaderProgramSetVsh(&ctx->program, &ctx->shader->DVLE[0]);
6364

64-
if (shaderId == C2D_ScanlineOffset) {
65-
shaderProgramSetGsh(&ctx->program, &ctx->shader->DVLE[1], 4*vertsPerSprite); //!! Changed for geo shader
65+
switch (shaderId) {
66+
case C2D_Normal:
67+
shaderProgramSetGsh(&ctx->program, &ctx->shader->DVLE[1], 4*vertsPerSprite/2);
68+
break;
69+
case C2D_ScanlineOffset:
70+
shaderProgramSetGsh(&ctx->program, &ctx->shader->DVLE[1], 4*vertsPerSprite);
71+
break;
6672
}
6773

6874
AttrInfo_Init(&ctx->attrInfo);
@@ -557,14 +563,9 @@ void C2Di_FlushVtxBuf(void)
557563

558564
GPU_Primitive_t primitive;
559565

560-
if (__C2Di_CurrentShader == C2D_ScanlineOffset) {
561-
primitive = GPU_GEOMETRY_PRIM;
562-
}
563-
else {
564-
primitive = GPU_TRIANGLES;
565-
}
566+
primitive = GPU_GEOMETRY_PRIM;
566567

567-
C3D_DrawArrays(primitive, ctx->vtxBufLastPos, len); //!! Changed for geo shader
568+
C3D_DrawArrays(primitive, ctx->vtxBufLastPos, len);
568569
ctx->vtxBufLastPos = ctx->vtxBufPos;
569570
}
570571

source/render2d.g.pica

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; Example PICA200 geometry shader
2+
.gsh point c0
3+
4+
; Uniforms
5+
.fvec projection[4]
6+
7+
; Constants
8+
9+
; Outputs - this time the type *is* used
10+
.out oPosition position
11+
.out oTexCoord0 texcoord0
12+
.out oTexCoord1 texcoord1
13+
.out oColor color
14+
15+
; Inputs: we will receive the following inputs:
16+
; v0-v3: data of the first vertex
17+
; v4-v7: data of the second vertex
18+
; v8-v11: data of the third vertex
19+
20+
; Inputs
21+
.in iPosition_1 v0
22+
.in iTexCoord_1 v1
23+
.in iProcTexCoord_1 v2
24+
.in iColor_1 v3
25+
.in iPosition_2 v4
26+
.in iTexCoord_2 v5
27+
.in iProcTexCoord_2 v6
28+
.in iColor_2 v7
29+
.in iPosition_3 v8
30+
.in iTexCoord_3 v9
31+
.in iProcTexCoord_3 v10
32+
.in iColor_3 v11
33+
34+
.entry render2d_gmain
35+
.proc render2d_gmain
36+
setemit 0
37+
mov oPosition, iPosition_1
38+
mov oTexCoord0, iTexCoord_1
39+
mov oTexCoord1, iProcTexCoord_1
40+
mov oColor, iColor_1
41+
emit
42+
43+
; Emit the second vertex
44+
setemit 1
45+
mov oPosition, iPosition_2
46+
mov oTexCoord0, iTexCoord_2
47+
mov oTexCoord1, iProcTexCoord_2
48+
mov oColor, iColor_2
49+
emit
50+
51+
; Emit the third vertex and finish the primitive
52+
setemit 2, prim
53+
mov oPosition, iPosition_3
54+
mov oTexCoord0, iTexCoord_3
55+
mov oTexCoord1, iProcTexCoord_3
56+
mov oColor, iColor_3
57+
emit
58+
59+
end
60+
.end

0 commit comments

Comments
 (0)