mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-07 22:34:43 -04:00
Simplify Draw command
This commit is contained in:
parent
243af150a8
commit
b73d03b199
@ -1,7 +1,7 @@
|
|||||||
#ifndef __GL_CONSTANTS
|
#ifndef __GL_CONSTANTS
|
||||||
#define __GL_CONSTANTS
|
#define __GL_CONSTANTS
|
||||||
|
|
||||||
#define VERTEX_CACHE_SIZE 16
|
#define VERTEX_CACHE_SIZE 4
|
||||||
|
|
||||||
#define MATRIX_SIZE 64
|
#define MATRIX_SIZE 64
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ enum {
|
|||||||
GPU_CMD_SET_WORD = 0x2,
|
GPU_CMD_SET_WORD = 0x2,
|
||||||
GPU_CMD_SET_LONG = 0x3,
|
GPU_CMD_SET_LONG = 0x3,
|
||||||
|
|
||||||
GPU_CMD_DRAW_TRI = 0x4,
|
GPU_CMD_DRAW_QUAD = 0x4,
|
||||||
GPU_CMD_UPLOAD_VTX = 0x5,
|
GPU_CMD_UPLOAD_VTX = 0x5,
|
||||||
GPU_CMD_MATRIX_LOAD = 0x6,
|
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);
|
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_SYNC_PIPE 0xE7000000
|
||||||
#define RDP_CMD_SET_BLEND_COLOR 0xF9000000
|
#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++)
|
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);
|
upload_vertex(first + i, cache_index);
|
||||||
|
|
||||||
// Last vertex of quad?
|
// Last vertex of quad?
|
||||||
if ((i & 3) != 3) continue;
|
if ((i & 3) != 3) continue;
|
||||||
|
|
||||||
// Add two triangles
|
// We pass -1 because the triangle can be clipped and split into multiple
|
||||||
uint8_t idx = cache_index - 3;
|
// triangles.
|
||||||
gpu_draw_triangle(idx + 0, idx + 1, idx + 2);
|
rdpq_write(-1, gpup_id, GPU_CMD_DRAW_QUAD);
|
||||||
gpu_draw_triangle(idx + 0, idx + 2, idx + 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
RSPQ_DefineCommand GPUCmd_SetWord, 8 # 0x2
|
RSPQ_DefineCommand GPUCmd_SetWord, 8 # 0x2
|
||||||
RSPQ_DefineCommand GPUCmd_SetLong, 12 # 0x3
|
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_UploadVertex, 20 # 0x5
|
||||||
RSPQ_DefineCommand GPUCmd_MatrixLoad, 68 # 0x6
|
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
|
CACHE_OFFSETS: .half 2,4,6,8,10,12,14,16,18
|
||||||
|
|
||||||
CLIP_CODE_FACTORS: .half 1, 1, GUARD_BAND_FACTOR, GUARD_BAND_FACTOR
|
CLIP_CODE_FACTORS: .half 1, 1, GUARD_BAND_FACTOR, GUARD_BAND_FACTOR
|
||||||
|
DRAW_TRI_RA: .word 0
|
||||||
|
|
||||||
#define CLIPPING_PLANE_COUNT 6
|
#define CLIPPING_PLANE_COUNT 6
|
||||||
#define CLIPPING_CACHE_SIZE 9
|
#define CLIPPING_CACHE_SIZE 9
|
||||||
@ -97,6 +98,39 @@ GPUCmd_PushRDP:
|
|||||||
.endfunc
|
.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
|
# GPUCmd_UploadVertex
|
||||||
#
|
#
|
||||||
@ -401,16 +435,6 @@ GL_TnL:
|
|||||||
.endfunc
|
.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
|
.func GPUCmd_DrawTriangle
|
||||||
GPUCmd_DrawTriangle:
|
GPUCmd_DrawTriangle:
|
||||||
#define vtx1 a1
|
#define vtx1 a1
|
||||||
@ -419,11 +443,7 @@ GPUCmd_DrawTriangle:
|
|||||||
#define trcode1 t6
|
#define trcode1 t6
|
||||||
#define trcode2 t7
|
#define trcode2 t7
|
||||||
#define trcode3 t8
|
#define trcode3 t8
|
||||||
|
sw ra, %lo(DRAW_TRI_RA) # TODO find a register for this
|
||||||
addi vtx3, a1, %lo(VERTEX_CACHE)
|
|
||||||
srl vtx2, a1, 16
|
|
||||||
addi vtx2, %lo(VERTEX_CACHE)
|
|
||||||
addi vtx1, a0, %lo(VERTEX_CACHE)
|
|
||||||
|
|
||||||
# Trivial reject: if all the vertices are out of the same plane (at least one),
|
# Trivial reject: if all the vertices are out of the same plane (at least one),
|
||||||
# the triangle is out of the viewport.
|
# the triangle is out of the viewport.
|
||||||
@ -487,43 +507,31 @@ gl_draw_single_triangle:
|
|||||||
addi s1, 2
|
addi s1, 2
|
||||||
|
|
||||||
gl_draw_triangle_end:
|
gl_draw_triangle_end:
|
||||||
j RSPQ_Loop
|
lw ra, %lo(DRAW_TRI_RA)
|
||||||
|
jr ra
|
||||||
nop
|
nop
|
||||||
|
|
||||||
#undef vtx1
|
#undef vtx1
|
||||||
#undef vtx2
|
#undef vtx2
|
||||||
#undef vtx3
|
#undef vtx3
|
||||||
|
|
||||||
.endfunc
|
.endfunc
|
||||||
|
|
||||||
|
|
||||||
GPUCmd_MatrixLoad:
|
.func GPUCmd_DrawQuad
|
||||||
#define src s6
|
GPUCmd_DrawQuad:
|
||||||
#define dst s7
|
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
|
li a1, %lo(VERTEX_CACHE) + 0*PRIM_VTX_SIZE
|
||||||
#define vrhs01_f $v03
|
li a2, %lo(VERTEX_CACHE) + 2*PRIM_VTX_SIZE
|
||||||
#define vrhs23_i $v04
|
jal GPUCmd_DrawTriangle
|
||||||
#define vrhs23_f $v05
|
li a3, %lo(VERTEX_CACHE) + 3*PRIM_VTX_SIZE
|
||||||
|
|
||||||
addi src, rspq_dmem_buf_ptr, %lo(RSPQ_DMEM_BUFFER) - 64
|
j RSPQ_Loop
|
||||||
addi dst, zero, %lo(GL_MATRIX_MVP)
|
nop
|
||||||
|
.endfunc
|
||||||
# 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
|
|
||||||
|
|
||||||
#include "rsp_gpu_clipping.inc"
|
#include "rsp_gpu_clipping.inc"
|
||||||
#include <rsp_rdpq.inc>
|
#include <rsp_rdpq.inc>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user