From 5e5db9fbc67595dccb0f47088a0482f0f798379f Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 15 Jan 2014 16:58:36 +0100 Subject: [PATCH] VideoCommon: cleanup of "components" usage This "u32 components" is a list of flags which attributes of the vertex loader are present. We are used to append this variable to lots of vertex generation functions, but some of them don't need it at all. --- .../VideoBackends/D3D/LineGeometryShader.cpp | 2 +- .../VideoBackends/D3D/PointGeometryShader.cpp | 2 +- .../Core/VideoBackends/D3D/VertexManager.cpp | 2 +- .../Core/VideoBackends/OGL/VertexManager.cpp | 4 +- Source/Core/VideoCommon/NativeVertexFormat.h | 1 - .../Core/VideoCommon/PixelShaderManager.cpp | 2 +- Source/Core/VideoCommon/PixelShaderManager.h | 2 +- Source/Core/VideoCommon/VertexLoader.cpp | 46 +++++++++---------- Source/Core/VideoCommon/VertexShaderGen.cpp | 8 ++-- Source/Core/VideoCommon/VertexShaderGen.h | 2 +- 10 files changed, 34 insertions(+), 37 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/LineGeometryShader.cpp b/Source/Core/VideoBackends/D3D/LineGeometryShader.cpp index a68dadaabb..944dca38f2 100644 --- a/Source/Core/VideoBackends/D3D/LineGeometryShader.cpp +++ b/Source/Core/VideoBackends/D3D/LineGeometryShader.cpp @@ -172,7 +172,7 @@ bool LineGeometryShader::SetShader(u32 components, float lineWidth, static char buffer[16384]; ShaderCode code; code.SetBuffer(buffer); - GenerateVSOutputStructForGS(code, components, API_D3D); + GenerateVSOutputStructForGS(code, API_D3D); code.Write("\n%s", LINE_GS_COMMON); std::stringstream numTexCoordsStream; diff --git a/Source/Core/VideoBackends/D3D/PointGeometryShader.cpp b/Source/Core/VideoBackends/D3D/PointGeometryShader.cpp index 30e4434521..34d87efb0f 100644 --- a/Source/Core/VideoBackends/D3D/PointGeometryShader.cpp +++ b/Source/Core/VideoBackends/D3D/PointGeometryShader.cpp @@ -166,7 +166,7 @@ bool PointGeometryShader::SetShader(u32 components, float pointSize, static char buffer[16384]; ShaderCode code; code.SetBuffer(buffer); - GenerateVSOutputStructForGS(code, components, API_D3D); + GenerateVSOutputStructForGS(code, API_D3D); code.Write("\n%s", POINT_GS_COMMON); std::stringstream numTexCoordsStream; diff --git a/Source/Core/VideoBackends/D3D/VertexManager.cpp b/Source/Core/VideoBackends/D3D/VertexManager.cpp index b951a7464f..45638dfbf1 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/VertexManager.cpp @@ -238,7 +238,7 @@ void VertexManager::vFlush() // set global constants VertexShaderManager::SetConstants(); - PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components); + PixelShaderManager::SetConstants(); bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index 64e8f92313..f10618e7f3 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -259,7 +259,7 @@ void VertexManager::vFlush() // set global constants VertexShaderManager::SetConstants(); - PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components); + PixelShaderManager::SetConstants(); ProgramShaderCache::UploadConstants(); // setup the pointers @@ -280,7 +280,7 @@ void VertexManager::vFlush() { // Need to set these again, if we don't support UBO VertexShaderManager::SetConstants(); - PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components); + PixelShaderManager::SetConstants(); } // only update alpha diff --git a/Source/Core/VideoCommon/NativeVertexFormat.h b/Source/Core/VideoCommon/NativeVertexFormat.h index f4f060e7bb..b4e83ed8a6 100644 --- a/Source/Core/VideoCommon/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/NativeVertexFormat.h @@ -101,7 +101,6 @@ public: virtual void Initialize(const PortableVertexDeclaration &vtx_decl) = 0; virtual void SetupVertexPointers() = 0; - virtual void EnableComponents(u32 components) {} u32 GetVertexStride() const { return vertex_stride; } diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index 270bc7d087..0c35bb44e4 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -65,7 +65,7 @@ void PixelShaderManager::Shutdown() } -void PixelShaderManager::SetConstants(u32 components) +void PixelShaderManager::SetConstants() { if (s_bFogRangeAdjustChanged) { diff --git a/Source/Core/VideoCommon/PixelShaderManager.h b/Source/Core/VideoCommon/PixelShaderManager.h index d0c3509baa..c4d193e516 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.h +++ b/Source/Core/VideoCommon/PixelShaderManager.h @@ -23,7 +23,7 @@ public: static void Shutdown(); static void DoState(PointerWrap &p); - static void SetConstants(u32 components); // sets pixel shader constants + static void SetConstants(); // sets pixel shader constants // constant management, should be called after memory is committed static void SetColorChanged(int type, int index); diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index d5cf003e76..4a389bc636 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -178,7 +178,7 @@ VertexLoader::VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr) m_numLoadedVertices = 0; m_VertexSize = 0; m_numPipelineStages = 0; - m_NativeFmt = g_vertex_manager->CreateNativeVertexFormat(); + m_NativeFmt = 0; loop_counter = 0; VertexLoader_Normal::Init(); VertexLoader_Position::Init(); @@ -251,9 +251,7 @@ void VertexLoader::CompileVertexTranslator() // Reset pipeline m_numPipelineStages = 0; - - // It's a bit ugly that we poke inside m_NativeFmt in this function. Planning to fix this. - m_NativeFmt->m_components = 0; + u32 components = 0; // Position in pc vertex format. int nat_offset = 0; @@ -270,18 +268,18 @@ void VertexLoader::CompileVertexTranslator() if (m_VtxDesc.PosMatIdx) { WriteCall(PosMtx_ReadDirect_UByte); - m_NativeFmt->m_components |= VB_HAS_POSMTXIDX; + components |= VB_HAS_POSMTXIDX; m_VertexSize += 1; } - if (m_VtxDesc.Tex0MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex1MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex2MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex3MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex4MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex5MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex6MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex7MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex0MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex1MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex2MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex3MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex4MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex5MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex6MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex7MatIdx) {m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); } // Write vertex position loader if(g_ActiveConfig.bUseBBox) @@ -333,10 +331,10 @@ void VertexLoader::CompileVertexTranslator() } int numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE; - m_NativeFmt->m_components |= VB_HAS_NRM0; + components |= VB_HAS_NRM0; if (numNormals == NRM_THREE) - m_NativeFmt->m_components |= VB_HAS_NRM1 | VB_HAS_NRM2; + components |= VB_HAS_NRM1 | VB_HAS_NRM2; } vtx_decl.color_gl_type = VAR_UNSIGNED_BYTE; @@ -344,11 +342,11 @@ void VertexLoader::CompileVertexTranslator() vtx_decl.color_offset[1] = -1; for (int i = 0; i < 2; i++) { - m_NativeFmt->m_components |= VB_HAS_COL0 << i; + components |= VB_HAS_COL0 << i; switch (col[i]) { case NOT_PRESENT: - m_NativeFmt->m_components &= ~(VB_HAS_COL0 << i); + components &= ~(VB_HAS_COL0 << i); vtx_decl.color_offset[i] = -1; break; case DIRECT: @@ -407,7 +405,7 @@ void VertexLoader::CompileVertexTranslator() if (tc[i] == NOT_PRESENT) { - m_NativeFmt->m_components &= ~(VB_HAS_UV0 << i); + components &= ~(VB_HAS_UV0 << i); } else { @@ -415,12 +413,12 @@ void VertexLoader::CompileVertexTranslator() _assert_msg_(VIDEO, FORMAT_UBYTE <= format && format <= FORMAT_FLOAT, "Invalid texture coordinates format!\n(format = %d)", format); _assert_msg_(VIDEO, 0 <= elements && elements <= 1, "Invalid number of texture coordinates elements!\n(elements = %d)", elements); - m_NativeFmt->m_components |= VB_HAS_UV0 << i; + components |= VB_HAS_UV0 << i; WriteCall(VertexLoader_TextCoord::GetFunction(tc[i], format, elements)); m_VertexSize += VertexLoader_TextCoord::GetSize(tc[i], format, elements); } - if (m_NativeFmt->m_components & (VB_HAS_TEXMTXIDX0 << i)) + if (components & (VB_HAS_TEXMTXIDX0 << i)) { if (tc[i] != NOT_PRESENT) { @@ -433,7 +431,7 @@ void VertexLoader::CompileVertexTranslator() } else { - m_NativeFmt->m_components |= VB_HAS_UV0 << i; // have to include since using now + components |= VB_HAS_UV0 << i; // have to include since using now vtx_decl.texcoord_offset[i] = nat_offset; vtx_decl.texcoord_gl_type[i] = VAR_FLOAT; vtx_decl.texcoord_size[i] = 4; @@ -465,7 +463,7 @@ void VertexLoader::CompileVertexTranslator() } } // tricky! - if (j == 8 && !((m_NativeFmt->m_components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1)))) + if (j == 8 && !((components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1)))) { // no more tex coords and tex matrices, so exit loop break; @@ -500,6 +498,8 @@ void VertexLoader::CompileVertexTranslator() ABI_PopAllCalleeSavedRegsAndAdjustStack(); RET(); #endif + m_NativeFmt = g_vertex_manager->CreateNativeVertexFormat(); + m_NativeFmt->m_components = components; m_NativeFmt->Initialize(vtx_decl); } @@ -565,8 +565,6 @@ int VertexLoader::SetupRunVertices(int vtx_attr_group, int primitive, int const return 0; } - m_NativeFmt->EnableComponents(m_NativeFmt->m_components); - // Load position and texcoord scale factors. m_VtxAttr.PosFrac = g_VtxAttr[vtx_attr_group].g0.PosFrac; m_VtxAttr.texCoord[0].Frac = g_VtxAttr[vtx_attr_group].g0.Tex0Frac; diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 9ff8617976..78d54492ac 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -38,7 +38,7 @@ static void DefineVSOutputStructMember(T& object, API_TYPE api_type, const char* } template -static inline void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type) +static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type) { object.Write("struct VS_OUTPUT {\n"); DefineVSOutputStructMember(object, api_type, "float4", "pos", -1, "POSITION"); @@ -99,7 +99,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) out.Write("};\n"); - GenerateVSOutputStruct(out, components, api_type); + GenerateVSOutputStruct(out, api_type); uid_data.numTexGens = xfregs.numTexGen.numTexGens; uid_data.components = components; @@ -467,7 +467,7 @@ void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE GenerateVertexShader(object, components, api_type); } -void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type) +void GenerateVSOutputStructForGS(ShaderCode& object, API_TYPE api_type) { - GenerateVSOutputStruct(object, components, api_type); + GenerateVSOutputStruct(object, api_type); } diff --git a/Source/Core/VideoCommon/VertexShaderGen.h b/Source/Core/VideoCommon/VertexShaderGen.h index 378f2cd77d..0bc4d8d832 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.h +++ b/Source/Core/VideoCommon/VertexShaderGen.h @@ -90,6 +90,6 @@ typedef ShaderCode VertexShaderCode; // TODO: Obsolete.. void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type); void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type); -void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type); +void GenerateVSOutputStructForGS(ShaderCode& object, API_TYPE api_type); #endif // GCOGL_VERTEXSHADER_H