From ef73487fcaeb5b767980d9587869dcb9b2034bce Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Dec 2014 10:35:16 -0800 Subject: [PATCH 1/3] Fix Vec4::SetZero() not clearing all lanes. --- GPU/Math3D.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/Math3D.h b/GPU/Math3D.h index 7c9f540476..8adb449e8d 100644 --- a/GPU/Math3D.h +++ b/GPU/Math3D.h @@ -636,7 +636,7 @@ public: void SetZero() { - x=0; y=0; z=0; + x=0; y=0; z=0; w=0; } // Common alias: RGBA (colors) From e130c1648d4aa2032fd34ff2c8e0b667118793da Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Dec 2014 10:35:47 -0800 Subject: [PATCH 2/3] Clean up some conversion warnings. --- GPU/Common/SplineCommon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index a251153820..9823b37872 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -139,8 +139,8 @@ void _SplinePatchLowQuality(u8 *&dest, u16 *indices, int &count, const SplinePat const int tile_max_u = (spatch.type_u & END_OPEN) ? spatch.count_u - 1 : spatch.count_u - 2; const int tile_max_v = (spatch.type_v & END_OPEN) ? spatch.count_v - 1 : spatch.count_v - 2; - float tu_width = spatch.count_u - 3; - float tv_height = spatch.count_v - 3; + float tu_width = (float)spatch.count_u - 3.0f; + float tv_height = (float)spatch.count_v - 3.0f; tu_width /= (float)(tile_max_u - tile_min_u); tv_height /= (float)(tile_max_v - tile_min_v); @@ -224,8 +224,8 @@ void _SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const SplineP // First compute all the vertices and put them in an array SimpleVertex *&vertices = (SimpleVertex*&)dest; - float tu_width = spatch.count_u - 3; - float tv_height = spatch.count_v - 3; + float tu_width = (float)spatch.count_u - 3.0f; + float tv_height = (float)spatch.count_v - 3.0f; bool computeNormals = gstate.isLightingEnabled(); for (int tile_v = 0; tile_v < patch_div_t + 1; tile_v++) { From 7ed67ad06612759401767462be23ea3bd8714a44 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Dec 2014 10:36:09 -0800 Subject: [PATCH 3/3] Use floats and SSE for spline colors. --- GPU/Common/SplineCommon.cpp | 31 +++++++++++++++++++------------ GPU/Common/SplineCommon.h | 5 ++++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 9823b37872..1b2d3a064b 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -18,12 +18,17 @@ #include #include +#if defined(_M_SSE) +#include +#endif + #include "Core/Config.h" #include "GPU/Common/SplineCommon.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" + #define START_OPEN 1 #define END_OPEN 2 @@ -237,25 +242,23 @@ void _SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const SplineP if (u < 0.0f) u = 0.0f; SimpleVertex *vert = &vertices[tile_v * (patch_div_s + 1) + tile_u]; + Vec4f vert_color; vert->pos.SetZero(); if (origVertType & GE_VTYPE_NRM_MASK) { vert->nrm.SetZero(); - } - else { + } else { vert->nrm.SetZero(); vert->nrm.z = 1.0f; } if (origVertType & GE_VTYPE_COL_MASK) { - memset(vert->color, 0, 4); - } - else { + vert_color.SetZero(); + } else { memcpy(vert->color, spatch.points[0]->color, 4); } if (origVertType & GE_VTYPE_TC_MASK) { vert->uv[0] = 0.0f; vert->uv[1] = 0.0f; - } - else { + } else { vert->uv[0] = tu_width * ((float)tile_u / (float)patch_div_s); vert->uv[1] = tv_height * ((float)tile_v / (float)patch_div_t); } @@ -288,11 +291,12 @@ void _SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const SplineP vert->uv[1] += a->uv[1] * f; } if (origVertType & GE_VTYPE_COL_MASK) { - // TODO: Accumulating values in u8s is crazy. We need floats or something. - vert->color[0] += a->color[0] * f; - vert->color[1] += a->color[1] * f; - vert->color[2] += a->color[2] * f; - vert->color[3] += a->color[3] * f; + Vec4f a_color = Vec4f::FromRGBA(a->color_32); +#ifdef _M_SSE + vert_color.vec = _mm_add_ps(vert_color.vec, _mm_mul_ps(a_color.vec, _mm_set_ps1(f))); +#else + vert_color += a_color * f; +#endif } if (origVertType & GE_VTYPE_NRM_MASK) { vert->nrm += a->nrm * f; @@ -303,6 +307,9 @@ void _SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const SplineP if (origVertType & GE_VTYPE_NRM_MASK) { vert->nrm.Normalize(); } + if (origVertType & GE_VTYPE_COL_MASK) { + vert->color_32 = vert_color.ToRGBA(); + } } } diff --git a/GPU/Common/SplineCommon.h b/GPU/Common/SplineCommon.h index 8ab61bc10d..7e7624ca0e 100644 --- a/GPU/Common/SplineCommon.h +++ b/GPU/Common/SplineCommon.h @@ -23,7 +23,10 @@ // PSP compatible format so we can use the end of the pipeline in beziers etc struct SimpleVertex { float uv[2]; - u8 color[4]; + union { + u8 color[4]; + u32_le color_32; + }; Vec3Packedf nrm; Vec3Packedf pos; };