diff --git a/misc/n64/gl_constants.h b/misc/n64/gl_constants.h index 054ffaca7..a2ca68e8f 100644 --- a/misc/n64/gl_constants.h +++ b/misc/n64/gl_constants.h @@ -1,7 +1,7 @@ #ifndef __GL_CONSTANTS #define __GL_CONSTANTS -#define VERTEX_CACHE_SIZE 16 +#define VERTEX_CACHE_SIZE 4 #define MATRIX_SIZE 64 diff --git a/misc/n64/gpu.c b/misc/n64/gpu.c index 793878818..b3d4399af 100644 --- a/misc/n64/gpu.c +++ b/misc/n64/gpu.c @@ -33,7 +33,7 @@ enum { GPU_CMD_SET_WORD = 0x2, GPU_CMD_SET_LONG = 0x3, - GPU_CMD_DRAW_TRI = 0x4, + GPU_CMD_DRAW_QUAD = 0x4, GPU_CMD_UPLOAD_VTX = 0x5, GPU_CMD_MATRIX_LOAD = 0x6, @@ -80,16 +80,6 @@ static inline void gpu_set_long(uint32_t offset, uint64_t value) rspq_write(gpup_id, GPU_CMD_SET_LONG, offset, value >> 32, value & 0xFFFFFFFF); } -static inline void gpu_draw_triangle(int i0, int i1, int i2) -{ - // We pass -1 because the triangle can be clipped and split into multiple - // triangles. - rdpq_write(-1, gpup_id, GPU_CMD_DRAW_TRI, - (i0*PRIM_VTX_SIZE), - ((i1*PRIM_VTX_SIZE)<<16) | (i2*PRIM_VTX_SIZE) - ); -} - #define RDP_CMD_SYNC_PIPE 0xE7000000 #define RDP_CMD_SET_BLEND_COLOR 0xF9000000 @@ -196,16 +186,15 @@ static void gpuDrawArrays(uint32_t first, uint32_t count) { for (uint32_t i = 0; i < count; i++) { - uint8_t cache_index = i % VERTEX_CACHE_SIZE; + uint8_t cache_index = i & 3; upload_vertex(first + i, cache_index); // Last vertex of quad? if ((i & 3) != 3) continue; - // Add two triangles - uint8_t idx = cache_index - 3; - gpu_draw_triangle(idx + 0, idx + 1, idx + 2); - gpu_draw_triangle(idx + 0, idx + 2, idx + 3); + // We pass -1 because the triangle can be clipped and split into multiple + // triangles. + rdpq_write(-1, gpup_id, GPU_CMD_DRAW_QUAD); } } diff --git a/misc/n64/rsp_gpu.S b/misc/n64/rsp_gpu.S index 87033509d..9b3a57739 100644 --- a/misc/n64/rsp_gpu.S +++ b/misc/n64/rsp_gpu.S @@ -9,7 +9,7 @@ RSPQ_DefineCommand GPUCmd_SetWord, 8 # 0x2 RSPQ_DefineCommand GPUCmd_SetLong, 12 # 0x3 - RSPQ_DefineCommand GPUCmd_DrawTriangle, 8 # 0x4 + RSPQ_DefineCommand GPUCmd_DrawQuad, 4 # 0x4 RSPQ_DefineCommand GPUCmd_UploadVertex, 20 # 0x5 RSPQ_DefineCommand GPUCmd_MatrixLoad, 68 # 0x6 @@ -41,6 +41,7 @@ VERTEX_CACHE: .dcb.b PRIM_VTX_SIZE * VERTEX_CACHE_SIZE CACHE_OFFSETS: .half 2,4,6,8,10,12,14,16,18 CLIP_CODE_FACTORS: .half 1, 1, GUARD_BAND_FACTOR, GUARD_BAND_FACTOR +DRAW_TRI_RA: .word 0 #define CLIPPING_PLANE_COUNT 6 #define CLIPPING_CACHE_SIZE 9 @@ -97,6 +98,39 @@ GPUCmd_PushRDP: .endfunc + .func GPUCmd_MatrixLoad +GPUCmd_MatrixLoad: + #define src s6 + #define dst s7 + + #define vrhs01_i $v02 + #define vrhs01_f $v03 + #define vrhs23_i $v04 + #define vrhs23_f $v05 + + addi src, rspq_dmem_buf_ptr, %lo(RSPQ_DMEM_BUFFER) - 64 + addi dst, zero, %lo(GL_MATRIX_MVP) + + # Load the matrix from command parameters (misaligned) + lqv vrhs01_i, 0x00,src + lrv vrhs01_i, 0x10,src + lqv vrhs23_i, 0x10,src + lrv vrhs23_i, 0x20,src + lqv vrhs01_f, 0x20,src + lrv vrhs01_f, 0x30,src + lqv vrhs23_f, 0x30,src + lrv vrhs23_f, 0x40,src + + sqv vrhs01_i, 0x00,dst + sqv vrhs23_i, 0x10,dst + sqv vrhs01_f, 0x20,dst + jr ra + sqv vrhs23_f, 0x30,dst + +#undef src +#undef dst + .endfunc + ######################################## # GPUCmd_UploadVertex # @@ -401,16 +435,6 @@ GL_TnL: .endfunc - ################################################################ - # GPUCmd_DrawTriangle - # - # Arguments: - # a0: Bit 31..24: Command id - # Bit 11..0: Offset into vertex cache of vtx1 - # a1: Bit 27..16: Offset into vertex cache of vtx2 - # Bit 11..0: Offset into vertex cache of vtx3 - # - ################################################################ .func GPUCmd_DrawTriangle GPUCmd_DrawTriangle: #define vtx1 a1 @@ -419,11 +443,7 @@ GPUCmd_DrawTriangle: #define trcode1 t6 #define trcode2 t7 #define trcode3 t8 - - addi vtx3, a1, %lo(VERTEX_CACHE) - srl vtx2, a1, 16 - addi vtx2, %lo(VERTEX_CACHE) - addi vtx1, a0, %lo(VERTEX_CACHE) + sw ra, %lo(DRAW_TRI_RA) # TODO find a register for this # Trivial reject: if all the vertices are out of the same plane (at least one), # the triangle is out of the viewport. @@ -487,43 +507,31 @@ gl_draw_single_triangle: addi s1, 2 gl_draw_triangle_end: - j RSPQ_Loop + lw ra, %lo(DRAW_TRI_RA) + jr ra nop #undef vtx1 #undef vtx2 #undef vtx3 - .endfunc -GPUCmd_MatrixLoad: - #define src s6 - #define dst s7 + .func GPUCmd_DrawQuad +GPUCmd_DrawQuad: + li a1, %lo(VERTEX_CACHE) + 0*PRIM_VTX_SIZE + li a2, %lo(VERTEX_CACHE) + 1*PRIM_VTX_SIZE + jal GPUCmd_DrawTriangle + li a3, %lo(VERTEX_CACHE) + 2*PRIM_VTX_SIZE - #define vrhs01_i $v02 - #define vrhs01_f $v03 - #define vrhs23_i $v04 - #define vrhs23_f $v05 + li a1, %lo(VERTEX_CACHE) + 0*PRIM_VTX_SIZE + li a2, %lo(VERTEX_CACHE) + 2*PRIM_VTX_SIZE + jal GPUCmd_DrawTriangle + li a3, %lo(VERTEX_CACHE) + 3*PRIM_VTX_SIZE - addi src, rspq_dmem_buf_ptr, %lo(RSPQ_DMEM_BUFFER) - 64 - addi dst, zero, %lo(GL_MATRIX_MVP) - - # Load the matrix from command parameters (misaligned) - lqv vrhs01_i, 0x00,src - lrv vrhs01_i, 0x10,src - lqv vrhs23_i, 0x10,src - lrv vrhs23_i, 0x20,src - lqv vrhs01_f, 0x20,src - lrv vrhs01_f, 0x30,src - lqv vrhs23_f, 0x30,src - lrv vrhs23_f, 0x40,src - - sqv vrhs01_i, 0x00,dst - sqv vrhs23_i, 0x10,dst - sqv vrhs01_f, 0x20,dst - jr ra - sqv vrhs23_f, 0x30,dst + j RSPQ_Loop + nop + .endfunc #include "rsp_gpu_clipping.inc" #include