From 82b494203de76816eb5f9d2e32ddc46e71b9efe2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 8 May 2025 21:36:38 +1000 Subject: [PATCH] PS2: Slightly optimise drawing by using aligned data where possible --- misc/ps2/DrawColoured.S | 28 ++++------------------------ misc/ps2/DrawTextured.S | 17 +++++------------ src/Graphics_PS2.c | 5 ++++- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/misc/ps2/DrawColoured.S b/misc/ps2/DrawColoured.S index e716a495b..d5235bec6 100644 --- a/misc/ps2/DrawColoured.S +++ b/misc/ps2/DrawColoured.S @@ -95,12 +95,7 @@ FUNC DrawColouredQuad ### VERTEX 1 ### - # LOAD VERTEX 1 - ld $t0,0x00(SRC) # t0 = src[0].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x08(SRC) # t0 = src[0].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_1, 0x00(TMP) # V1 = tmp + lqc2 POS_1, 0x00(SRC) TransformVertex POS_1 lwc1 COL1, 0x0C(SRC) @@ -108,12 +103,7 @@ FUNC DrawColouredQuad BeginClip POS_1 ### VERTEX 2 ### - # LOAD VERTEX 2 - ld $t0,0x10(SRC) # t0 = src[1].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x18(SRC) # t0 = src[1].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_2, 0x00(TMP) # V2 = tmp + lqc2 POS_2, 0x10(SRC) TransformVertex POS_2 lwc1 COL2, 0x1C(SRC) @@ -122,12 +112,7 @@ FUNC DrawColouredQuad BeginClip POS_2 ### VERTEX 3 ### - # LOAD VERTEX 3 - ld $t0,0x20(SRC) # t0 = src[2].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x28(SRC) # t0 = src[2].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_3, 0x00(TMP) # V3 = tmp + lqc2 POS_3, 0x20(SRC) TransformVertex POS_3 lwc1 COL3, 0x2C(SRC) @@ -136,12 +121,7 @@ FUNC DrawColouredQuad BeginClip POS_3 ### VERTEX 4 ### - # LOAD VERTEX 4 - ld $t0,0x30(SRC) # t0 = src[3].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x38(SRC) # t0 = src[3].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_4, 0x00(TMP) # V4 = tmp + lqc2 POS_4, 0x30(SRC) TransformVertex POS_4 lwc1 COL4, 0x3C(SRC) diff --git a/misc/ps2/DrawTextured.S b/misc/ps2/DrawTextured.S index ee214a415..926184c1d 100644 --- a/misc/ps2/DrawTextured.S +++ b/misc/ps2/DrawTextured.S @@ -105,12 +105,7 @@ FUNC DrawTexturedQuad ### VERTEX 1 ### - # LOAD VERTEX 1 - ld $t0,0x00(SRC) # t0 = src[0].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x08(SRC) # t0 = src[0].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_1, 0x00(TMP) # V1 = tmp + lqc2 POS_1, 0x00(SRC) TransformVertex POS_1 lwc1 COL1, 0x0C(SRC) @@ -131,22 +126,19 @@ FUNC DrawTexturedQuad lwc1 COL2, 0x24(SRC) lwc1 U_2, 0x28(SRC) lwc1 V_2, 0x2C(SRC) + vmulq.w POS_1, V0001, $Q vdiv $Q, _one, POS2w BeginClip POS_2 ### VERTEX 3 ### - # LOAD VERTEX 3 - ld $t0,0x30(SRC) # t0 = src[2].x,y - sd $t0,0x00(TMP) # tmp.x,y = t0 - lw $t0,0x38(SRC) # t0 = src[2].z - sw $t0,0x08(TMP) # tmp.z = t0 - lqc2 POS_3, 0x00(TMP) # V3 = tmp + lqc2 POS_3, 0x30(SRC) TransformVertex POS_3 lwc1 COL3, 0x3C(SRC) lwc1 U_3, 0x40(SRC) lwc1 V_3, 0x44(SRC) + vmulq.w POS_2, V0001, $Q vdiv $Q, _one, POS3w BeginClip POS_3 @@ -163,6 +155,7 @@ FUNC DrawTexturedQuad lwc1 COL4, 0x54(SRC) lwc1 U_4, 0x58(SRC) lwc1 V_4, 0x5C(SRC) + vmulq.w POS_3, V0001, $Q vdiv $Q, _one, POS4w BeginClip POS_4 diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 0f49f5779..c56870e98 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -397,7 +397,10 @@ static void PreprocessColouredVertices(void) { } static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) { - return Mem_TryAlloc(count, strideSizes[fmt]); + //return Mem_TryAlloc(count, strideSizes[fmt]); + return memalign(16,count * strideSizes[fmt]); + // align to 16 bytes, so DrawTexturedQuad/DrawColouredQuad can + // load vertices using the "load quad (16 bytes)" instruction } void Gfx_BindVb(GfxResourceID vb) { gfx_vertices = vb; }