From d4ff7cc92823e418ec11182da9001bfaa0fd28c7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 19 Mar 2017 19:51:44 -0700 Subject: [PATCH] Spline: Simplify uniforms/dirty to one check. This makes backends more consistent in which values they use, and reduces the (relatively uncommon compared to other drawcalls) dirty checks for splines. --- GPU/Common/ShaderCommon.h | 6 +----- GPU/Common/ShaderUniforms.cpp | 17 +++++------------ GPU/Common/ShaderUniforms.h | 2 +- GPU/D3D11/GPU_D3D11.cpp | 17 +++++------------ GPU/GLES/GPU_GLES.cpp | 21 +++++++-------------- GPU/GLES/ShaderManagerGLES.cpp | 23 +++++++++-------------- GPU/GPUState.h | 1 - GPU/Vulkan/GPU_Vulkan.cpp | 17 +++++------------ 8 files changed, 33 insertions(+), 71 deletions(-) diff --git a/GPU/Common/ShaderCommon.h b/GPU/Common/ShaderCommon.h index 460316557f..45b40d63a5 100644 --- a/GPU/Common/ShaderCommon.h +++ b/GPU/Common/ShaderCommon.h @@ -88,11 +88,7 @@ enum : uint64_t { DIRTY_BONEMATRIX7 = 1ULL << 31, // These are for hardware tessellation - DIRTY_BEZIERCOUNTU = 1ULL << 32, - DIRTY_SPLINECOUNTU = 1ULL << 33, - DIRTY_SPLINECOUNTV = 1ULL << 34, - DIRTY_SPLINETYPEU = 1ULL << 35, - DIRTY_SPLINETYPEV = 1ULL << 36, + DIRTY_BEZIERSPLINE = 1ULL << 32, DIRTY_BONE_UNIFORMS = 0xFF000000ULL, diff --git a/GPU/Common/ShaderUniforms.cpp b/GPU/Common/ShaderUniforms.cpp index a804be5023..e92448c7ed 100644 --- a/GPU/Common/ShaderUniforms.cpp +++ b/GPU/Common/ShaderUniforms.cpp @@ -197,18 +197,11 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView ub->depthRange[3] = viewZInvScale; } - if (gstate_c.bezier) { - if (dirtyUniforms & DIRTY_BEZIERCOUNTU) - ub->spline_count_u = gstate_c.spline_count_u; - } else if (gstate_c.spline) { - if (dirtyUniforms & DIRTY_SPLINECOUNTU) - ub->spline_count_u = gstate_c.spline_count_u; - if (dirtyUniforms & DIRTY_SPLINECOUNTV) - ub->spline_count_v = gstate_c.spline_count_v; - if (dirtyUniforms & DIRTY_SPLINETYPEU) - ub->spline_type_u = gstate_c.spline_type_u; - if (dirtyUniforms & DIRTY_SPLINETYPEV) - ub->spline_type_v = gstate_c.spline_type_v; + if (dirtyUniforms & DIRTY_BEZIERSPLINE) { + ub->spline_count_u = gstate_c.spline_count_u; + ub->spline_count_v = gstate_c.spline_count_v; + ub->spline_type_u = gstate_c.spline_type_u; + ub->spline_type_v = gstate_c.spline_type_v; } } diff --git a/GPU/Common/ShaderUniforms.h b/GPU/Common/ShaderUniforms.h index 3189c31d12..55f08f7658 100644 --- a/GPU/Common/ShaderUniforms.h +++ b/GPU/Common/ShaderUniforms.h @@ -12,7 +12,7 @@ enum : uint64_t { DIRTY_WORLDMATRIX | DIRTY_PROJTHROUGHMATRIX | DIRTY_VIEWMATRIX | DIRTY_TEXMATRIX | DIRTY_ALPHACOLORREF | DIRTY_PROJMATRIX | DIRTY_FOGCOLOR | DIRTY_FOGCOEF | DIRTY_TEXENV | DIRTY_STENCILREPLACEVALUE | DIRTY_ALPHACOLORMASK | DIRTY_SHADERBLEND | DIRTY_UVSCALEOFFSET | DIRTY_TEXCLAMP | DIRTY_DEPTHRANGE | DIRTY_MATAMBIENTALPHA | - DIRTY_BEZIERCOUNTU | DIRTY_SPLINECOUNTU | DIRTY_SPLINECOUNTV | DIRTY_SPLINETYPEU | DIRTY_SPLINETYPEV, + DIRTY_BEZIERSPLINE, DIRTY_LIGHT_UNIFORMS = DIRTY_LIGHT0 | DIRTY_LIGHT1 | DIRTY_LIGHT2 | DIRTY_LIGHT3 | DIRTY_MATDIFFUSE | DIRTY_MATSPECULAR | DIRTY_MATEMISSIVE | DIRTY_AMBIENT, diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 2a6018dfcf..ddd7016279 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -596,7 +596,7 @@ void GPU_D3D11::Execute_Bezier(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.bezier = true; if (gstate_c.spline_count_u != bz_ucount) { - gstate_c.Dirty(DIRTY_BEZIERCOUNTU); + gstate_c.Dirty(DIRTY_BEZIERSPLINE); gstate_c.spline_count_u = bz_ucount; } } @@ -657,20 +657,13 @@ void GPU_D3D11::Execute_Spline(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.spline = true; - if (gstate_c.spline_count_u != sp_ucount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTU); + bool countsChanged = gstate_c.spline_count_u != sp_ucount || gstate_c.spline_count_v != sp_vcount; + bool typesChanged = gstate_c.spline_type_u != sp_utype || gstate_c.spline_type_v != sp_vtype; + if (countsChanged || typesChanged) { + gstate_c.Dirty(DIRTY_BEZIERSPLINE); gstate_c.spline_count_u = sp_ucount; - } - if (gstate_c.spline_count_v != sp_vcount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTV); gstate_c.spline_count_v = sp_vcount; - } - if (gstate_c.spline_type_u != sp_utype) { - gstate_c.Dirty(DIRTY_SPLINETYPEU); gstate_c.spline_type_u = sp_utype; - } - if (gstate_c.spline_type_v != sp_vtype) { - gstate_c.Dirty(DIRTY_SPLINETYPEV); gstate_c.spline_type_v = sp_vtype; } } diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 9a49212f6a..5b7e2c4fb0 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -769,9 +769,9 @@ void GPU_GLES::Execute_Bezier(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.bezier = true; - if (gstate_c.bezier_count_u != bz_ucount) { - gstate_c.Dirty(DIRTY_BEZIERCOUNTU); - gstate_c.bezier_count_u = bz_ucount; + if (gstate_c.spline_count_u != bz_ucount) { + gstate_c.Dirty(DIRTY_BEZIERSPLINE); + gstate_c.spline_count_u = bz_ucount; } } @@ -831,20 +831,13 @@ void GPU_GLES::Execute_Spline(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.spline = true; - if (gstate_c.spline_count_u != sp_ucount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTU); + bool countsChanged = gstate_c.spline_count_u != sp_ucount || gstate_c.spline_count_v != sp_vcount; + bool typesChanged = gstate_c.spline_type_u != sp_utype || gstate_c.spline_type_v != sp_vtype; + if (countsChanged || typesChanged) { + gstate_c.Dirty(DIRTY_BEZIERSPLINE); gstate_c.spline_count_u = sp_ucount; - } - if (gstate_c.spline_count_v != sp_vcount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTV); gstate_c.spline_count_v = sp_vcount; - } - if (gstate_c.spline_type_u != sp_utype) { - gstate_c.Dirty(DIRTY_SPLINETYPEU); gstate_c.spline_type_u = sp_utype; - } - if (gstate_c.spline_type_v != sp_vtype) { - gstate_c.Dirty(DIRTY_SPLINETYPEV); gstate_c.spline_type_v = sp_vtype; } } diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 482cc3ddd0..48847ed8f5 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -292,11 +292,10 @@ LinkedShader::LinkedShader(ShaderID VSID, Shader *vs, ShaderID FSID, Shader *fs, u_lightpos[i] != -1) availableUniforms |= DIRTY_LIGHT0 << i; } - if (u_spline_count_u != -1) availableUniforms |= DIRTY_BEZIERCOUNTU; - if (u_spline_count_u != -1) availableUniforms |= DIRTY_SPLINECOUNTU; - if (u_spline_count_v != -1) availableUniforms |= DIRTY_SPLINECOUNTV; - if (u_spline_type_u != -1) availableUniforms |= DIRTY_SPLINETYPEU; - if (u_spline_type_v != -1) availableUniforms |= DIRTY_SPLINETYPEV; + if (u_spline_count_u != -1) availableUniforms |= DIRTY_BEZIERSPLINE; + if (u_spline_count_v != -1) availableUniforms |= DIRTY_BEZIERSPLINE; + if (u_spline_type_u != -1) availableUniforms |= DIRTY_BEZIERSPLINE; + if (u_spline_type_v != -1) availableUniforms |= DIRTY_BEZIERSPLINE; glUseProgram(program); @@ -735,17 +734,13 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid) { } } - if (gstate_c.bezier) { - if (dirty & DIRTY_BEZIERCOUNTU) - glUniform1i(u_spline_count_u, gstate_c.bezier_count_u); - } else if (gstate_c.spline) { - if (dirty & DIRTY_SPLINECOUNTU) - glUniform1i(u_spline_count_u, gstate_c.spline_count_u); - if (dirty & DIRTY_SPLINECOUNTV) + if (dirty & DIRTY_BEZIERSPLINE) { + glUniform1i(u_spline_count_u, gstate_c.spline_count_u); + if (u_spline_count_v != -1) glUniform1i(u_spline_count_v, gstate_c.spline_count_v); - if (dirty & DIRTY_SPLINETYPEU) + if (u_spline_type_u != -1) glUniform1i(u_spline_type_u, gstate_c.spline_type_u); - if (dirty & DIRTY_SPLINETYPEV) + if (u_spline_type_v != -1) glUniform1i(u_spline_type_v, gstate_c.spline_type_v); } CHECK_GL_ERROR_IF_DEBUG(); diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 9c5fe43811..d695bb99dc 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -553,7 +553,6 @@ struct GPUStateCache { bool bezier; bool spline; - int bezier_count_u; int spline_count_u; int spline_count_v; int spline_type_u; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index a635a268c5..7232ca0864 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -584,7 +584,7 @@ void GPU_Vulkan::Execute_Bezier(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.bezier = true; if (gstate_c.spline_count_u != bz_ucount) { - gstate_c.Dirty(DIRTY_BEZIERCOUNTU); + gstate_c.Dirty(DIRTY_BEZIERSPLINE); gstate_c.spline_count_u = bz_ucount; } } @@ -644,20 +644,13 @@ void GPU_Vulkan::Execute_Spline(u32 op, u32 diff) { if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) { gstate_c.spline = true; - if (gstate_c.spline_count_u != sp_ucount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTU); + bool countsChanged = gstate_c.spline_count_u != sp_ucount || gstate_c.spline_count_v != sp_vcount; + bool typesChanged = gstate_c.spline_type_u != sp_utype || gstate_c.spline_type_v != sp_vtype; + if (countsChanged || typesChanged) { + gstate_c.Dirty(DIRTY_BEZIERSPLINE); gstate_c.spline_count_u = sp_ucount; - } - if (gstate_c.spline_count_v != sp_vcount) { - gstate_c.Dirty(DIRTY_SPLINECOUNTV); gstate_c.spline_count_v = sp_vcount; - } - if (gstate_c.spline_type_u != sp_utype) { - gstate_c.Dirty(DIRTY_SPLINETYPEU); gstate_c.spline_type_u = sp_utype; - } - if (gstate_c.spline_type_v != sp_vtype) { - gstate_c.Dirty(DIRTY_SPLINETYPEV); gstate_c.spline_type_v = sp_vtype; } }