From 72d8c3344bddf45a1b4e4767b3535a9e2173f7d8 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Fri, 24 Oct 2008 23:08:46 +0000 Subject: [PATCH] Code movin' and cleanup again, in the GL plugin. Planning to turn NativeVertexFormat into something cachable, instead of locked to each VertexLoader. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@948 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/NativeVertexFormat.h | 88 ++++++ Source/Core/VideoCommon/Src/Profiler.h | 2 +- Source/Core/VideoCommon/Src/VertexShader.cpp | 4 +- Source/Core/VideoCommon/Src/VertexShader.h | 33 --- Source/Core/VideoCommon/VideoCommon.vcproj | 4 + .../Plugin_VideoDX9/Src/VertexLoader.cpp | 4 +- .../Plugin_VideoDX9/Src/VertexLoader.h | 4 +- .../Plugin_VideoDX9/Src/VertexLoader_Color.h | 36 +-- .../Src/VertexLoader_MtxIndex.h | 4 +- .../Src/VertexLoader_Normal.cpp | 36 +-- .../Plugin_VideoDX9/Src/VertexLoader_Normal.h | 36 +-- .../Src/VertexLoader_Position.h | 30 +- .../Src/VertexLoader_TextCoord.h | 30 +- .../Plugin_VideoOGL/Plugin_VideoOGL.vcproj | 4 + .../Plugins/Plugin_VideoOGL/Src/BPStructs.cpp | 16 +- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 4 +- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h | 2 + .../Src/NativeVertexFormat.cpp | 196 +++++++++++++ .../Plugin_VideoOGL/Src/PixelShaderManager.h | 2 +- Source/Plugins/Plugin_VideoOGL/Src/SConscript | 1 + .../Plugin_VideoOGL/Src/VertexLoader.cpp | 274 +++++------------- .../Plugin_VideoOGL/Src/VertexLoader.h | 34 +-- .../Plugin_VideoOGL/Src/VertexLoader_Color.h | 36 +-- .../Src/VertexLoader_Normal.cpp | 36 +-- .../Plugin_VideoOGL/Src/VertexLoader_Normal.h | 36 +-- .../Src/VertexLoader_Position.h | 30 +- .../Src/VertexLoader_TextCoord.h | 62 ++-- .../Plugin_VideoOGL/Src/VertexManager.cpp | 17 +- .../Src/VertexShaderManager.cpp | 2 +- .../Plugin_VideoOGL/Src/VertexShaderManager.h | 2 +- 30 files changed, 591 insertions(+), 474 deletions(-) create mode 100644 Source/Core/VideoCommon/Src/NativeVertexFormat.h create mode 100644 Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp diff --git a/Source/Core/VideoCommon/Src/NativeVertexFormat.h b/Source/Core/VideoCommon/Src/NativeVertexFormat.h new file mode 100644 index 0000000000..817b5ded1f --- /dev/null +++ b/Source/Core/VideoCommon/Src/NativeVertexFormat.h @@ -0,0 +1,88 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _NATIVEVERTEXFORMAT_H +#define _NATIVEVERTEXFORMAT_H + +#include "CPMemory.h" + +// m_components +enum { + VB_HAS_POSMTXIDX =(1<<1), + VB_HAS_TEXMTXIDX0=(1<<2), + VB_HAS_TEXMTXIDX1=(1<<3), + VB_HAS_TEXMTXIDX2=(1<<4), + VB_HAS_TEXMTXIDX3=(1<<5), + VB_HAS_TEXMTXIDX4=(1<<6), + VB_HAS_TEXMTXIDX5=(1<<7), + VB_HAS_TEXMTXIDX6=(1<<8), + VB_HAS_TEXMTXIDX7=(1<<9), + VB_HAS_TEXMTXIDXALL=(0xff<<2), + + //VB_HAS_POS=0, // Implied, it always has pos! don't bother testing + VB_HAS_NRM0=(1<<10), + VB_HAS_NRM1=(1<<11), + VB_HAS_NRM2=(1<<12), + VB_HAS_NRMALL=(7<<10), + + VB_HAS_COL0=(1<<13), + VB_HAS_COL1=(1<<14), + + VB_HAS_UV0=(1<<15), + VB_HAS_UV1=(1<<16), + VB_HAS_UV2=(1<<17), + VB_HAS_UV3=(1<<18), + VB_HAS_UV4=(1<<19), + VB_HAS_UV5=(1<<20), + VB_HAS_UV6=(1<<21), + VB_HAS_UV7=(1<<22), + VB_HAS_UVALL=(0xff<<15), + VB_HAS_UVTEXMTXSHIFT=13, +}; + + +#define LOADERDECL __cdecl +typedef void (LOADERDECL *TPipelineFunction)(const void *); + +// This will soon be used in a cache of vertex formats, rather than used in-place. +// The implementation of this class is specific for GL/DX, so NativeVertexFormat.cpp +// is in the respective plugin, not here in VideoCommon. + +// Note that this class can't just invent arbitrary vertex formats out of its input - +// all the data loading code must always be made compatible. +class NativeVertexFormat +{ + void SetupColor(int num, int _iMode, int _iFormat, int _iElements); + void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac); + +public: + NativeVertexFormat(); + ~NativeVertexFormat(); + + void Initialize(const TVtxDesc &vtx_desc, const TVtxAttr &vtx_attr); + void RunPipelineOnce(const TVtxAttr &vtx_attr) const; + + // TODO: move these in under private: + int m_VBVertexStride; // PC-side vertex stride + int m_VBStridePad; + u32 m_components; // VB_HAS_X. Bitmask telling what vertex components are present. + TPipelineFunction m_PipelineStages[32]; + int m_numPipelineStages; + u8* m_compiledCode; +}; + +#endif // _NATIVEVERTEXFORMAT_H diff --git a/Source/Core/VideoCommon/Src/Profiler.h b/Source/Core/VideoCommon/Src/Profiler.h index 62808c3e07..db7524bca6 100644 --- a/Source/Core/VideoCommon/Src/Profiler.h +++ b/Source/Core/VideoCommon/Src/Profiler.h @@ -61,7 +61,7 @@ public: #else -#define DVSTARTPROFILE(name) +#define DVSTARTPROFILE() #define DVSTARTSUBPROFILE(name) class DVProfileFunc diff --git a/Source/Core/VideoCommon/Src/VertexShader.cpp b/Source/Core/VideoCommon/Src/VertexShader.cpp index 556aefb153..97b7f9b426 100644 --- a/Source/Core/VideoCommon/Src/VertexShader.cpp +++ b/Source/Core/VideoCommon/Src/VertexShader.cpp @@ -15,9 +15,11 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ -#include "Profiler.h" #include +#include "Profiler.h" +#include "NativeVertexFormat.h" + #include "BPMemory.h" #include "VertexShader.h" diff --git a/Source/Core/VideoCommon/Src/VertexShader.h b/Source/Core/VideoCommon/Src/VertexShader.h index 4845241d56..1c89374132 100644 --- a/Source/Core/VideoCommon/Src/VertexShader.h +++ b/Source/Core/VideoCommon/Src/VertexShader.h @@ -24,39 +24,6 @@ #define SHADER_NORM1_ATTRIB 6 #define SHADER_NORM2_ATTRIB 7 -// m_components -enum { - VB_HAS_POSMTXIDX =(1<<1), - VB_HAS_TEXMTXIDX0=(1<<2), - VB_HAS_TEXMTXIDX1=(1<<3), - VB_HAS_TEXMTXIDX2=(1<<4), - VB_HAS_TEXMTXIDX3=(1<<5), - VB_HAS_TEXMTXIDX4=(1<<6), - VB_HAS_TEXMTXIDX5=(1<<7), - VB_HAS_TEXMTXIDX6=(1<<8), - VB_HAS_TEXMTXIDX7=(1<<9), - VB_HAS_TEXMTXIDXALL=(0xff<<2), - - //VB_HAS_POS=0, // Implied, it always has pos! don't bother testing - VB_HAS_NRM0=(1<<10), - VB_HAS_NRM1=(1<<11), - VB_HAS_NRM2=(1<<12), - VB_HAS_NRMALL=(7<<10), - - VB_HAS_COL0=(1<<13), - VB_HAS_COL1=(1<<14), - - VB_HAS_UV0=(1<<15), - VB_HAS_UV1=(1<<16), - VB_HAS_UV2=(1<<17), - VB_HAS_UV3=(1<<18), - VB_HAS_UV4=(1<<19), - VB_HAS_UV5=(1<<20), - VB_HAS_UV6=(1<<21), - VB_HAS_UV7=(1<<22), - VB_HAS_UVALL=(0xff<<15), - VB_HAS_UVTEXMTXSHIFT=13, -}; // shader variables #define I_POSNORMALMATRIX "cpnmtx" diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index e2795fde9b..35e29e4e42 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -479,6 +479,10 @@ RelativePath=".\Src\LookUpTables.h" > + + diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.cpp index 0e0f4f21d6..7f935b10cc 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.cpp @@ -317,9 +317,9 @@ void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, in } } -void VertexLoader::WriteCall(void (LOADERDECL *func)(void *)) +void VertexLoader::WriteCall(TPipelineFunction func) { - m_PipelineStates[m_numPipelineStates++] = func;; + m_PipelineStates[m_numPipelineStates++] = func; } using namespace Gen; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.h index a001ace901..097410da65 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader.h @@ -48,7 +48,7 @@ int ComputeVertexSize(u32 components); #include "DataReader.h" #define LOADERDECL __cdecl -typedef void (LOADERDECL *TPipelineFunction)(void*); +typedef void (LOADERDECL *TPipelineFunction)(const void*); class VertexLoader { @@ -127,7 +127,7 @@ public: void Compile(); void PrepareRun(); void RunVertices(int count); - void WriteCall(void (LOADERDECL *func)(void *)); + void WriteCall(TPipelineFunction func); int GetVertexSize(){return m_VertexSize;} //VtxDesc - global diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Color.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Color.h index 52df1ba8e0..fbabd4a1bc 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Color.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Color.h @@ -82,7 +82,7 @@ inline u32 _Read32(u32 iAddress) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -void LOADERDECL Color_ReadDirect_24b_888(void* _p) +void LOADERDECL Color_ReadDirect_24b_888(const void *_p) { u32 col = DataReadU8()<SetNormalX(0, ((float)(signed char)DataReadU8()+0.5f) / 127.5f); varray->SetNormalY(0, ((float)(signed char)DataReadU8()+0.5f) / 127.5f); @@ -139,7 +139,7 @@ VertexLoader_Normal::Normal_DirectByte(void* _p) // Normal_DirectShort // void LOADERDECL -VertexLoader_Normal::Normal_DirectShort(void* _p) +VertexLoader_Normal::Normal_DirectShort(const void* _p) { varray->SetNormalX(0, ((float)(signed short)DataReadU16()+0.5f) / 32767.5f); varray->SetNormalY(0, ((float)(signed short)DataReadU16()+0.5f) / 32767.5f); @@ -150,7 +150,7 @@ VertexLoader_Normal::Normal_DirectShort(void* _p) // Normal_DirectFloat // void LOADERDECL -VertexLoader_Normal::Normal_DirectFloat(void* _p) +VertexLoader_Normal::Normal_DirectFloat(const void* _p) { varray->SetNormalX(0, DataReadF32()); varray->SetNormalY(0, DataReadF32()); @@ -161,7 +161,7 @@ VertexLoader_Normal::Normal_DirectFloat(void* _p) // Normal_DirectByte3 // void LOADERDECL -VertexLoader_Normal::Normal_DirectByte3(void* _p) +VertexLoader_Normal::Normal_DirectByte3(const void* _p) { for (int i=0; i<3; i++) { @@ -175,7 +175,7 @@ VertexLoader_Normal::Normal_DirectByte3(void* _p) // Normal_DirectShort3 // void LOADERDECL -VertexLoader_Normal::Normal_DirectShort3(void* _p) +VertexLoader_Normal::Normal_DirectShort3(const void* _p) { for (int i=0; i<3; i++) { @@ -189,7 +189,7 @@ VertexLoader_Normal::Normal_DirectShort3(void* _p) // Normal_DirectFloat3 // void LOADERDECL -VertexLoader_Normal::Normal_DirectFloat3(void* _p) +VertexLoader_Normal::Normal_DirectFloat3(const void* _p) { for (int i=0; i<3; i++) { @@ -209,7 +209,7 @@ VertexLoader_Normal::Normal_DirectFloat3(void* _p) // Normal_Index8_Byte // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Byte(void* _p) +VertexLoader_Normal::Normal_Index8_Byte(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -223,7 +223,7 @@ VertexLoader_Normal::Normal_Index8_Byte(void* _p) // Normal_Index8_Short // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Short(void* _p) +VertexLoader_Normal::Normal_Index8_Short(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -237,7 +237,7 @@ VertexLoader_Normal::Normal_Index8_Short(void* _p) // Normal_Index8_Float // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Float(void* _p) +VertexLoader_Normal::Normal_Index8_Float(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -251,7 +251,7 @@ VertexLoader_Normal::Normal_Index8_Float(void* _p) // Normal_Index8_Byte3 // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Byte3(void* _p) +VertexLoader_Normal::Normal_Index8_Byte3(const void* _p) { if (index3) { @@ -283,7 +283,7 @@ VertexLoader_Normal::Normal_Index8_Byte3(void* _p) // Normal_Index8_Short3 // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Short3(void* _p) +VertexLoader_Normal::Normal_Index8_Short3(const void* _p) { if (index3) { @@ -315,7 +315,7 @@ VertexLoader_Normal::Normal_Index8_Short3(void* _p) // Normal_Index8_Float3 // void LOADERDECL -VertexLoader_Normal::Normal_Index8_Float3(void* _p) +VertexLoader_Normal::Normal_Index8_Float3(const void* _p) { if (index3) { @@ -353,7 +353,7 @@ VertexLoader_Normal::Normal_Index8_Float3(void* _p) // Normal_Index16_Byte // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Byte(void* _p) +VertexLoader_Normal::Normal_Index16_Byte(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -367,7 +367,7 @@ VertexLoader_Normal::Normal_Index16_Byte(void* _p) // Normal_Index16_Short // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Short(void* _p) +VertexLoader_Normal::Normal_Index16_Short(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -381,7 +381,7 @@ VertexLoader_Normal::Normal_Index16_Short(void* _p) // Normal_Index8_Float // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Float(void* _p) +VertexLoader_Normal::Normal_Index16_Float(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_NORMAL] + (Index * arraystrides[ARRAY_NORMAL]); @@ -395,7 +395,7 @@ VertexLoader_Normal::Normal_Index16_Float(void* _p) // Normal_Index16_Byte3 // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Byte3(void* _p) +VertexLoader_Normal::Normal_Index16_Byte3(const void* _p) { if (index3) { @@ -427,7 +427,7 @@ VertexLoader_Normal::Normal_Index16_Byte3(void* _p) // Normal_Index16_Short3 // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Short3(void* _p) +VertexLoader_Normal::Normal_Index16_Short3(const void* _p) { if (index3) { @@ -459,7 +459,7 @@ VertexLoader_Normal::Normal_Index16_Short3(void* _p) // Normal_Index16_Float3 // void LOADERDECL -VertexLoader_Normal::Normal_Index16_Float3(void* _p) +VertexLoader_Normal::Normal_Index16_Float3(const void* _p) { if (index3) { diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Normal.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Normal.h index 30f8a3c188..2f74ad59a9 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Normal.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Normal.h @@ -65,26 +65,26 @@ private: static TPipelineFunction m_funcTable[NUM_NRM_TYPE][NUM_NRM_FORMAT][NUM_NRM_ELEMENTS]; // direct - static void LOADERDECL Normal_DirectByte(void* _p); - static void LOADERDECL Normal_DirectShort(void* _p); - static void LOADERDECL Normal_DirectFloat(void* _p); - static void LOADERDECL Normal_DirectByte3(void* _p); - static void LOADERDECL Normal_DirectShort3(void* _p); - static void LOADERDECL Normal_DirectFloat3(void* _p); + static void LOADERDECL Normal_DirectByte(const void* _p); + static void LOADERDECL Normal_DirectShort(const void* _p); + static void LOADERDECL Normal_DirectFloat(const void* _p); + static void LOADERDECL Normal_DirectByte3(const void* _p); + static void LOADERDECL Normal_DirectShort3(const void* _p); + static void LOADERDECL Normal_DirectFloat3(const void* _p); // index8 - static void LOADERDECL Normal_Index8_Byte(void* _p); - static void LOADERDECL Normal_Index8_Short(void* _p); - static void LOADERDECL Normal_Index8_Float(void* _p); - static void LOADERDECL Normal_Index8_Byte3(void* _p); - static void LOADERDECL Normal_Index8_Short3(void* _p); - static void LOADERDECL Normal_Index8_Float3(void* _p); + static void LOADERDECL Normal_Index8_Byte(const void* _p); + static void LOADERDECL Normal_Index8_Short(const void* _p); + static void LOADERDECL Normal_Index8_Float(const void* _p); + static void LOADERDECL Normal_Index8_Byte3(const void* _p); + static void LOADERDECL Normal_Index8_Short3(const void* _p); + static void LOADERDECL Normal_Index8_Float3(const void* _p); // index16 - static void LOADERDECL Normal_Index16_Byte(void* _p); - static void LOADERDECL Normal_Index16_Short(void* _p); - static void LOADERDECL Normal_Index16_Float(void* _p); - static void LOADERDECL Normal_Index16_Byte3(void* _p); - static void LOADERDECL Normal_Index16_Short3(void* _p); - static void LOADERDECL Normal_Index16_Float3(void* _p); + static void LOADERDECL Normal_Index16_Byte(const void* _p); + static void LOADERDECL Normal_Index16_Short(const void* _p); + static void LOADERDECL Normal_Index16_Float(const void* _p); + static void LOADERDECL Normal_Index16_Byte3(const void* _p); + static void LOADERDECL Normal_Index16_Short3(const void* _p); + static void LOADERDECL Normal_Index16_Float3(const void* _p); }; \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Position.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Position.h index 508e5f4dac..a664a00861 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Position.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_Position.h @@ -63,7 +63,7 @@ void LOADERDECL _ReadPosFloatMem(int iAddress, TVtxAttr* pVtxAttr) varray->SetPosZ(1.0); } -void LOADERDECL Pos_ReadDirect_UByte(void* _p) +void LOADERDECL Pos_ReadDirect_UByte(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; varray->SetPosX((float)DataReadU8() * posScale); @@ -75,7 +75,7 @@ void LOADERDECL Pos_ReadDirect_UByte(void* _p) varray->SetPosZ(1.0); } -void LOADERDECL Pos_ReadDirect_Byte(void* _p) +void LOADERDECL Pos_ReadDirect_Byte(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; varray->SetPosX((float)(s8)DataReadU8() * posScale); @@ -87,7 +87,7 @@ void LOADERDECL Pos_ReadDirect_Byte(void* _p) varray->SetPosZ(1.0); } -void LOADERDECL Pos_ReadDirect_UShort(void* _p) +void LOADERDECL Pos_ReadDirect_UShort(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; @@ -100,7 +100,7 @@ void LOADERDECL Pos_ReadDirect_UShort(void* _p) varray->SetPosZ(1.0); } -void LOADERDECL Pos_ReadDirect_Short(void* _p) +void LOADERDECL Pos_ReadDirect_Short(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; @@ -113,7 +113,7 @@ void LOADERDECL Pos_ReadDirect_Short(void* _p) varray->SetPosZ(1.0); } -void LOADERDECL Pos_ReadDirect_Float(void* _p) +void LOADERDECL Pos_ReadDirect_Float(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; @@ -130,14 +130,14 @@ void LOADERDECL Pos_ReadDirect_Float(void* _p) // Index 8 // ============================================================================== -void LOADERDECL Pos_ReadIndex8_UByte(void* _p) +void LOADERDECL Pos_ReadIndex8_UByte(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_POSITION] + (Index * arraystrides[ARRAY_POSITION]); _ReadPos8Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex8_Byte(void* _p) +void LOADERDECL Pos_ReadIndex8_Byte(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u8 Index = DataReadU8(); @@ -145,7 +145,7 @@ void LOADERDECL Pos_ReadIndex8_Byte(void* _p) _ReadPos8Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex8_UShort(void* _p) +void LOADERDECL Pos_ReadIndex8_UShort(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u8 Index = DataReadU8(); @@ -153,7 +153,7 @@ void LOADERDECL Pos_ReadIndex8_UShort(void* _p) _ReadPos16Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex8_Short(void* _p) +void LOADERDECL Pos_ReadIndex8_Short(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u8 Index = DataReadU8(); @@ -161,7 +161,7 @@ void LOADERDECL Pos_ReadIndex8_Short(void* _p) _ReadPos16Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex8_Float(void* _p) +void LOADERDECL Pos_ReadIndex8_Float(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u8 Index = DataReadU8(); @@ -173,28 +173,28 @@ void LOADERDECL Pos_ReadIndex8_Float(void* _p) // Index 16 // ============================================================================== -void LOADERDECL Pos_ReadIndex16_UByte(void* _p){ +void LOADERDECL Pos_ReadIndex16_UByte(const void* _p){ TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_POSITION] + (Index * arraystrides[ARRAY_POSITION]); _ReadPos8Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex16_Byte(void* _p){ +void LOADERDECL Pos_ReadIndex16_Byte(const void* _p){ TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_POSITION] + (Index * arraystrides[ARRAY_POSITION]); _ReadPos8Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex16_UShort(void* _p){ +void LOADERDECL Pos_ReadIndex16_UShort(const void* _p){ TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_POSITION] + (Index * arraystrides[ARRAY_POSITION]); _ReadPos16Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex16_Short(void* _p) +void LOADERDECL Pos_ReadIndex16_Short(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); @@ -202,7 +202,7 @@ void LOADERDECL Pos_ReadIndex16_Short(void* _p) _ReadPos16Mem(iAddress, pVtxAttr); } -void LOADERDECL Pos_ReadIndex16_Float(void* _p) +void LOADERDECL Pos_ReadIndex16_Float(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_TextCoord.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_TextCoord.h index 36c8ed008f..90f1ca1625 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_TextCoord.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexLoader_TextCoord.h @@ -20,7 +20,7 @@ extern int tcIndex; -void LOADERDECL TexCoord_ReadDirect_UByte(void* _p) +void LOADERDECL TexCoord_ReadDirect_UByte(const void* _p) { varray->SetU(tcIndex, DataReadU8() * tcScaleU[tcIndex]); if (tcElements[tcIndex]) @@ -28,7 +28,7 @@ void LOADERDECL TexCoord_ReadDirect_UByte(void* _p) tcIndex++; } -void LOADERDECL TexCoord_ReadDirect_Byte(void* _p) +void LOADERDECL TexCoord_ReadDirect_Byte(const void* _p) { varray->SetU(tcIndex, (s8)DataReadU8() * tcScaleU[tcIndex]); if (tcElements[tcIndex]) @@ -36,7 +36,7 @@ void LOADERDECL TexCoord_ReadDirect_Byte(void* _p) tcIndex++; } -void LOADERDECL TexCoord_ReadDirect_UShort(void* _p) +void LOADERDECL TexCoord_ReadDirect_UShort(const void* _p) { varray->SetU(tcIndex, DataReadU16() * tcScaleU[tcIndex]); if (tcElements[tcIndex]) @@ -44,14 +44,14 @@ void LOADERDECL TexCoord_ReadDirect_UShort(void* _p) tcIndex++; } -void LOADERDECL TexCoord_ReadDirect_Short(void* _p) +void LOADERDECL TexCoord_ReadDirect_Short(const void* _p) { varray->SetU(tcIndex, (s16)DataReadU16() * tcScaleU[tcIndex]); if (tcElements[tcIndex]) varray->SetV(tcIndex, (s16)DataReadU16() * tcScaleV[tcIndex]); tcIndex++; } -void LOADERDECL TexCoord_ReadDirect_Float(void* _p) +void LOADERDECL TexCoord_ReadDirect_Float(const void* _p) { varray->SetU(tcIndex, DataReadF32() * tcScaleU[tcIndex]); if (tcElements[tcIndex]) @@ -60,7 +60,7 @@ void LOADERDECL TexCoord_ReadDirect_Float(void* _p) } // ================================================================================== -void LOADERDECL TexCoord_ReadIndex8_UByte(void* _p) +void LOADERDECL TexCoord_ReadIndex8_UByte(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -70,7 +70,7 @@ void LOADERDECL TexCoord_ReadIndex8_UByte(void* _p) varray->SetV(tcIndex, (float)(u8)Memory_Read_U8(iAddress+1) * tcScaleV[tcIndex]); tcIndex++; } -void LOADERDECL TexCoord_ReadIndex8_Byte(void* _p) +void LOADERDECL TexCoord_ReadIndex8_Byte(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -81,7 +81,7 @@ void LOADERDECL TexCoord_ReadIndex8_Byte(void* _p) tcIndex++; } -void LOADERDECL TexCoord_ReadIndex8_UShort(void* _p) +void LOADERDECL TexCoord_ReadIndex8_UShort(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -91,7 +91,7 @@ void LOADERDECL TexCoord_ReadIndex8_UShort(void* _p) varray->SetV(tcIndex, (float)(u16)Memory_Read_U16(iAddress+2) * tcScaleV[tcIndex]); tcIndex++; } -void LOADERDECL TexCoord_ReadIndex8_Short(void* _p) +void LOADERDECL TexCoord_ReadIndex8_Short(const void* _p) { u8 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -101,7 +101,7 @@ void LOADERDECL TexCoord_ReadIndex8_Short(void* _p) varray->SetV(tcIndex, (float)(s16)Memory_Read_U16(iAddress+2) * tcScaleV[tcIndex]); tcIndex++; } -void LOADERDECL TexCoord_ReadIndex8_Float(void* _p) +void LOADERDECL TexCoord_ReadIndex8_Float(const void* _p) { u16 Index = DataReadU8(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -118,7 +118,7 @@ void LOADERDECL TexCoord_ReadIndex8_Float(void* _p) // ================================================================================== -void LOADERDECL TexCoord_ReadIndex16_UByte(void* _p) +void LOADERDECL TexCoord_ReadIndex16_UByte(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -134,7 +134,7 @@ void LOADERDECL TexCoord_ReadIndex16_UByte(void* _p) } tcIndex++; } -void LOADERDECL TexCoord_ReadIndex16_Byte(void* _p) +void LOADERDECL TexCoord_ReadIndex16_Byte(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -151,7 +151,7 @@ void LOADERDECL TexCoord_ReadIndex16_Byte(void* _p) tcIndex++; } -void LOADERDECL TexCoord_ReadIndex16_UShort(void* _p) +void LOADERDECL TexCoord_ReadIndex16_UShort(const void* _p) { TVtxAttr* pVtxAttr = (TVtxAttr*)_p; u16 Index = DataReadU16(); @@ -168,7 +168,7 @@ void LOADERDECL TexCoord_ReadIndex16_UShort(void* _p) } tcIndex++; } -void LOADERDECL TexCoord_ReadIndex16_Short(void* _p) +void LOADERDECL TexCoord_ReadIndex16_Short(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); @@ -184,7 +184,7 @@ void LOADERDECL TexCoord_ReadIndex16_Short(void* _p) } tcIndex++; } -void LOADERDECL TexCoord_ReadIndex16_Float(void* _p) +void LOADERDECL TexCoord_ReadIndex16_Float(const void* _p) { u16 Index = DataReadU16(); u32 iAddress = arraybases[ARRAY_TEXCOORD0+tcIndex] + (Index * arraystrides[ARRAY_TEXCOORD0+tcIndex]); diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj index 8149d16770..c3ae08140c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj +++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj @@ -728,6 +728,10 @@ RelativePath=".\Src\BPStructs.h" > + + diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp index a3eb7e569b..165d53e8c5 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp @@ -736,19 +736,19 @@ bool SetScissorRect() int xoff = bpmem.scissorOffset.x * 2 - 342; int yoff = bpmem.scissorOffset.y * 2 - 342; - int rc_left = bpmem.scissorTL.x - xoff - 342; // left = 0 + float rc_left = bpmem.scissorTL.x - xoff - 342; // left = 0 rc_left *= MValueX; if (rc_left < 0) rc_left = 0; - int rc_top = bpmem.scissorTL.y - yoff - 342; // right = 0 + float rc_top = bpmem.scissorTL.y - yoff - 342; // right = 0 rc_top *= MValueY; if (rc_top < 0) rc_top = 0; - int rc_right = bpmem.scissorBR.x - xoff - 342; // right = 640 + float rc_right = bpmem.scissorBR.x - xoff - 342; // right = 640 rc_right *= MValueX; if (rc_right > 640 * MValueX) rc_right = 640 * MValueX; - int rc_bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480 + float rc_bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480 rc_bottom *= MValueY; if (rc_bottom > 480 * MValueY) rc_bottom = 480 * MValueY; @@ -761,10 +761,10 @@ bool SetScissorRect() if (rc_right >= rc_left && rc_bottom >= rc_top ) { glScissor( - rc_left, // x = 0 - Renderer::GetTargetHeight()-(rc_bottom), // y = 0 - (rc_right-rc_left), // y = 0 - (rc_bottom-rc_top) // y = 0 + (int)rc_left, // x = 0 + Renderer::GetTargetHeight()-(int)(rc_bottom), // y = 0 + (int)(rc_right-rc_left), // y = 0 + (int)(rc_bottom-rc_top) // y = 0 ); return true; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 068d3325f2..2923f37ae2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -178,8 +178,8 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight { MValueX = 1.0f / Max; MValueY = 1.0f / Max; - nXoff = (nBackbufferWidth - (640 * MValueX)) / 2; - nYoff = (nBackbufferHeight - (480 * MValueY)) / 2; + nXoff = (int)((nBackbufferWidth - (640 * MValueX)) / 2); + nYoff = (int)((nBackbufferHeight - (480 * MValueY)) / 2); } g_VideoInitialize.pPeekMessages = &Callback_PeekMessages; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index d52e2b636e..c5522dbe59 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -18,6 +18,8 @@ #ifndef _GLINIT_H #define _GLINIT_H +#include "pluginspecs_video.h" + #ifdef _WIN32 #define GLEW_STATIC diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp new file mode 100644 index 0000000000..43a2040952 --- /dev/null +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -0,0 +1,196 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "GLUtil.h" +#include "Profiler.h" +#include "x64Emitter.h" +#include "ABI.h" +#include "MemoryUtil.h" +#include "VertexShader.h" + +#include "CPMemory.h" +#include "NativeVertexFormat.h" + +#define COMPILED_CODE_SIZE 4096 + +// Note the use of CallCdeclFunction3I etc. +// This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit +// address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we +// want to grab the function pointers from the import table instead. + +// This problem does not apply to glew functions, only core opengl32 functions. + +// Here's some global state. We only use this to keep track of what we've sent to the OpenGL state +// machine. + + + + + +DECLARE_IMPORT(glNormalPointer); +DECLARE_IMPORT(glVertexPointer); +DECLARE_IMPORT(glColorPointer); +DECLARE_IMPORT(glTexCoordPointer); + +NativeVertexFormat::NativeVertexFormat() +{ + m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false); + m_numPipelineStages = 0; + if (m_compiledCode) { + memset(m_compiledCode, 0, COMPILED_CODE_SIZE); + } +} + +NativeVertexFormat::~NativeVertexFormat() +{ + FreeMemoryPages(m_compiledCode, COMPILED_CODE_SIZE); + m_compiledCode = 0; +} + +void NativeVertexFormat::Initialize(const TVtxDesc &vtx_desc, const TVtxAttr &vtx_attr) +{ + using namespace Gen; + const int col[2] = {vtx_desc.Color0, vtx_desc.Color1}; + // TextureCoord + const int tc[8] = { + vtx_desc.Tex0Coord, vtx_desc.Tex1Coord, vtx_desc.Tex2Coord, vtx_desc.Tex3Coord, + vtx_desc.Tex4Coord, vtx_desc.Tex5Coord, vtx_desc.Tex6Coord, vtx_desc.Tex7Coord, + }; + + DVSTARTPROFILE(); + + if (m_VBVertexStride & 3) { + // make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost) + m_VBStridePad = 4 - (m_VBVertexStride & 3); + m_VBVertexStride += m_VBStridePad; + } + + // compile the pointer set function - why? + u8 *old_code_ptr = GetWritableCodePtr(); + SetCodePtr(m_compiledCode); + Util::EmitPrologue(6); + int offset = 0; + + // Position + if (vtx_desc.Position != NOT_PRESENT) { // TODO: Why the check? Always present, AFAIK! + CallCdeclFunction4_I(glVertexPointer, 3, GL_FLOAT, m_VBVertexStride, offset); + offset += 12; + } + + // Normals + if (vtx_desc.Normal != NOT_PRESENT) { + switch (vtx_attr.NormalFormat) { + case FORMAT_UBYTE: + case FORMAT_BYTE: + CallCdeclFunction3_I(glNormalPointer, GL_BYTE, m_VBVertexStride, offset); offset += 3; + if (vtx_attr.NormalElements) { + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; + } + break; + case FORMAT_USHORT: + case FORMAT_SHORT: + CallCdeclFunction3_I(glNormalPointer, GL_SHORT, m_VBVertexStride, offset); offset += 6; + if (vtx_attr.NormalElements) { + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; + } + break; + case FORMAT_FLOAT: + CallCdeclFunction3_I(glNormalPointer, GL_FLOAT, m_VBVertexStride, offset); offset += 12; + if (vtx_attr.NormalElements) { + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12; + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12; + } + break; + default: _assert_(0); break; + } + } + + // TODO : With byte or short normals above, offset will be misaligned (not 4byte aligned)! Ugh! + + for (int i = 0; i < 2; i++) { + if (col[i] != NOT_PRESENT) { + if (i) + CallCdeclFunction4((void *)glSecondaryColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset); + else + CallCdeclFunction4_I(glColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset); + offset += 4; + } + } + + // TextureCoord + for (int i = 0; i < 8; i++) { + if (tc[i] != NOT_PRESENT || (m_components & (VB_HAS_TEXMTXIDX0 << i))) { + int id = GL_TEXTURE0 + i; +#ifdef _M_X64 +#ifdef _MSC_VER + MOV(32, R(RCX), Imm32(id)); +#else + MOV(32, R(RDI), Imm32(id)); +#endif +#else + ABI_AlignStack(1 * 4); + PUSH(32, Imm32(id)); +#endif + CALL((void *)glClientActiveTexture); +#ifndef _M_X64 +#ifdef _WIN32 + // don't inc stack on windows, stdcall +#else + ABI_RestoreStack(1 * 4); +#endif +#endif + // TODO : More potential disalignment! + if (m_components & (VB_HAS_TEXMTXIDX0 << i)) { + if (tc[i] != NOT_PRESENT) { + CallCdeclFunction4_I(glTexCoordPointer, 3, GL_FLOAT, m_VBVertexStride, offset); + offset += 12; + } + else { + CallCdeclFunction4_I(glTexCoordPointer, 3, GL_SHORT, m_VBVertexStride, offset); + offset += 6; + } + } + else { + CallCdeclFunction4_I(glTexCoordPointer, vtx_attr.texCoord[i].Elements ? 2 : 1, GL_FLOAT, m_VBVertexStride, offset); + offset += 4 * (vtx_attr.texCoord[i].Elements?2:1); + } + } + } + + if (vtx_desc.PosMatIdx) { + CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_POSMTX_ATTRIB, 1, GL_UNSIGNED_BYTE, GL_FALSE, m_VBVertexStride, offset); + offset += 1; + } + + _assert_(offset+m_VBStridePad == m_VBVertexStride); + + Util::EmitEpilogue(6); + if (Gen::GetCodePtr() - (u8*)m_compiledCode > COMPILED_CODE_SIZE) + { + Crash(); + } + + SetCodePtr(old_code_ptr); +} + +void NativeVertexFormat::RunPipelineOnce(const TVtxAttr &vtx_attr) const +{ + for (int i = 0; i < m_numPipelineStages; i++) + m_PipelineStages[i](&vtx_attr); +} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderManager.h b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderManager.h index f041130154..89bf875759 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderManager.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderManager.h @@ -117,7 +117,7 @@ public: static FRAGMENTSHADER* GetShader(); static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram); - static void SetConstants(FRAGMENTSHADER& ps); // 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/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index 93e82d2e0a..39af336521 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -19,6 +19,7 @@ files = [ 'Render.cpp', 'TextureMngr.cpp', 'ImageWrite.cpp', + 'NativeVertexFormat.cpp', 'VertexManager.cpp', 'VertexLoader.cpp', 'VertexLoader_Normal.cpp', diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp index 380e31d926..1f4ee98bd4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp @@ -23,8 +23,6 @@ #include "Common.h" #include "Config.h" #include "ImageWrite.h" -#include "x64Emitter.h" -#include "ABI.h" #include "Profiler.h" #include "StringUtil.h" @@ -39,8 +37,6 @@ #include "PixelShaderManager.h" #include "TextureMngr.h" -#include "MemoryUtil.h" - #include extern void (*fnSetupVertexPointers)(); @@ -66,13 +62,13 @@ static u8 s_curtexmtx[8]; static int s_texmtxwrite = 0; static int s_texmtxread = 0; -void LOADERDECL PosMtx_ReadDirect_UByte(void* _p) +void LOADERDECL PosMtx_ReadDirect_UByte(const void *_p) { s_curposmtx = DataReadU8()&0x3f; PRIM_LOG("posmtx: %d, ", s_curposmtx); } -void LOADERDECL PosMtx_Write(void* _p) +void LOADERDECL PosMtx_Write(const void *_p) { *VertexManager::s_pCurBufferPointer++ = s_curposmtx; //*VertexManager::s_pCurBufferPointer++ = 0; @@ -80,27 +76,27 @@ void LOADERDECL PosMtx_Write(void* _p) //*VertexManager::s_pCurBufferPointer++ = 0; } -void LOADERDECL TexMtx_ReadDirect_UByte(void* _p) +void LOADERDECL TexMtx_ReadDirect_UByte(const void *_p) { s_curtexmtx[s_texmtxread] = DataReadU8()&0x3f; PRIM_LOG("texmtx%d: %d, ", s_texmtxread, s_curtexmtx[s_texmtxread]); s_texmtxread++; } -void LOADERDECL TexMtx_Write_Float(void* _p) +void LOADERDECL TexMtx_Write_Float(const void *_p) { *(float*)VertexManager::s_pCurBufferPointer = (float)s_curtexmtx[s_texmtxwrite++]; VertexManager::s_pCurBufferPointer += 4; } -void LOADERDECL TexMtx_Write_Float2(void* _p) +void LOADERDECL TexMtx_Write_Float2(const void *_p) { ((float*)VertexManager::s_pCurBufferPointer)[0] = 0; ((float*)VertexManager::s_pCurBufferPointer)[1] = (float)s_curtexmtx[s_texmtxwrite++]; VertexManager::s_pCurBufferPointer += 8; } -void LOADERDECL TexMtx_Write_Short3(void* _p) +void LOADERDECL TexMtx_Write_Short3(const void *_p) { ((s16*)VertexManager::s_pCurBufferPointer)[0] = 0; ((s16*)VertexManager::s_pCurBufferPointer)[1] = 0; @@ -115,24 +111,15 @@ void LOADERDECL TexMtx_Write_Short3(void* _p) VertexLoader g_VertexLoaders[8]; -#define COMPILED_CODE_SIZE 4096 - VertexLoader::VertexLoader() { - m_numPipelineStages = 0; m_VertexSize = 0; m_AttrDirty = AD_DIRTY; VertexLoader_Normal::Init(); - - m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false); - if (m_compiledCode) { - memset(m_compiledCode, 0, COMPILED_CODE_SIZE); - } } VertexLoader::~VertexLoader() { - FreeMemoryPages(m_compiledCode, COMPILED_CODE_SIZE); } int VertexLoader::ComputeVertexSize() @@ -150,7 +137,7 @@ int VertexLoader::ComputeVertexSize() m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex; } - if (fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_compiledCode) + if (fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_NativeFmt.m_compiledCode) VertexManager::Flush(); m_AttrDirty = AD_DIRTY; @@ -259,24 +246,8 @@ int VertexLoader::ComputeVertexSize() } -// Note the use of CallCdeclFunction3I etc. -// This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit -// address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we -// want to grab the function pointers from the import table instead. - -// This problem does not apply to glew functions, only core opengl32 functions. - -DECLARE_IMPORT(glNormalPointer); -DECLARE_IMPORT(glVertexPointer); -DECLARE_IMPORT(glColorPointer); -DECLARE_IMPORT(glTexCoordPointer); - void VertexLoader::PrepareForVertexFormat() { - using namespace Gen; - - //_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer ); - if (m_AttrDirty == AD_CLEAN) { // Check if local cached desc (in this VL) matches global desc @@ -289,36 +260,35 @@ void VertexLoader::PrepareForVertexFormat() { m_AttrDirty = AD_CLEAN; } - + m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex; - DVSTARTPROFILE(); // Reset pipeline - m_VBStridePad = 0; - m_VBVertexStride = 0; - m_numPipelineStages = 0; - m_components = 0; + m_NativeFmt.m_VBStridePad = 0; + m_NativeFmt.m_VBVertexStride = 0; + m_NativeFmt.m_numPipelineStages = 0; + m_NativeFmt.m_components = 0; // m_VBVertexStride for texmtx and posmtx is computed later when writing. // Position Matrix Index if (m_VtxDesc.PosMatIdx) { - m_PipelineStages[m_numPipelineStages++] = PosMtx_ReadDirect_UByte; - m_components |= VB_HAS_POSMTXIDX; + m_NativeFmt.m_PipelineStages[m_NativeFmt.m_numPipelineStages++] = PosMtx_ReadDirect_UByte; + m_NativeFmt.m_components |= VB_HAS_POSMTXIDX; } - if (m_VtxDesc.Tex0MatIdx) {m_components|=VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex1MatIdx) {m_components|=VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex2MatIdx) {m_components|=VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex3MatIdx) {m_components|=VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex4MatIdx) {m_components|=VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex5MatIdx) {m_components|=VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex6MatIdx) {m_components|=VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex7MatIdx) {m_components|=VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex0MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex1MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex2MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex3MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex4MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex5MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex6MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); } + if (m_VtxDesc.Tex7MatIdx) {m_NativeFmt.m_components |= VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); } // Position if (m_VtxDesc.Position != NOT_PRESENT) - m_VBVertexStride += 12; + m_NativeFmt.m_VBVertexStride += 12; switch (m_VtxDesc.Position) { case NOT_PRESENT: {_assert_msg_(0, "Vertex descriptor without position!", "WTF?");} break; @@ -378,12 +348,12 @@ void VertexLoader::PrepareForVertexFormat() case FORMAT_FLOAT: sizePro=4; break; default: _assert_(0); break; } - m_VBVertexStride += sizePro * 3 * (m_VtxAttr.NormalElements?3:1); + m_NativeFmt.m_VBVertexStride += sizePro * 3 * (m_VtxAttr.NormalElements?3:1); - int m_numNormals = (m_VtxAttr.NormalElements==1) ? NRM_THREE : NRM_ONE; - m_components |= VB_HAS_NRM0; - if (m_numNormals == NRM_THREE) - m_components |= VB_HAS_NRM1 | VB_HAS_NRM2; + int numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE; + m_NativeFmt.m_components |= VB_HAS_NRM0; + if (numNormals == NRM_THREE) + m_NativeFmt.m_components |= VB_HAS_NRM1 | VB_HAS_NRM2; } // Colors @@ -392,7 +362,7 @@ void VertexLoader::PrepareForVertexFormat() SetupColor(i, col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements); if (col[i] != NOT_PRESENT) - m_VBVertexStride+=4; + m_NativeFmt.m_VBVertexStride += 4; } // TextureCoord @@ -404,21 +374,21 @@ void VertexLoader::PrepareForVertexFormat() // Texture matrix indices (remove if corresponding texture coordinate isn't enabled) for (int i = 0; i < 8; i++) { SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac); - if (m_components & (VB_HAS_TEXMTXIDX0 << i)) { + if (m_NativeFmt.m_components & (VB_HAS_TEXMTXIDX0 << i)) { if (tc[i] != NOT_PRESENT) { // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2); - m_VBVertexStride += 12; + m_NativeFmt.m_VBVertexStride += 12; } else { WriteCall(TexMtx_Write_Short3); - m_VBVertexStride += 6; // still include the texture coordinate, but this time as 6 bytes - m_components |= VB_HAS_UV0 << i; // have to include since using now + m_NativeFmt.m_VBVertexStride += 6; // still include the texture coordinate, but this time as 6 bytes + m_NativeFmt.m_components |= VB_HAS_UV0 << i; // have to include since using now } } else { if (tc[i] != NOT_PRESENT) - m_VBVertexStride += 4 * (m_VtxAttr.texCoord[i].Elements ? 2 : 1); + m_NativeFmt.m_VBVertexStride += 4 * (m_VtxAttr.texCoord[i].Elements ? 2 : 1); } if (tc[i] == NOT_PRESENT) { @@ -430,144 +400,30 @@ void VertexLoader::PrepareForVertexFormat() break; } } - if (j == 8 && !((m_components&VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL<<(i+1)))) // no more tex coords and tex matrices, so exit loop + if (j == 8 && !((m_NativeFmt.m_components&VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL<<(i+1)))) // no more tex coords and tex matrices, so exit loop break; } } if (m_VtxDesc.PosMatIdx) { WriteCall(PosMtx_Write); - m_VBVertexStride += 1; + m_NativeFmt.m_VBVertexStride += 1; } - if (m_VBVertexStride & 3) { - // make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost) - m_VBStridePad = 4 - (m_VBVertexStride & 3); - m_VBVertexStride += m_VBStridePad; - } - - // compile the pointer set function - why? - u8 *old_code_ptr = GetWritableCodePtr(); - SetCodePtr(m_compiledCode); - Util::EmitPrologue(6); - int offset = 0; - - // Position - if (m_VtxDesc.Position != NOT_PRESENT) { // TODO: Why the check? Always present, AFAIK! - CallCdeclFunction4_I(glVertexPointer, 3, GL_FLOAT, m_VBVertexStride, offset); - offset += 12; - } - - // Normals - if (m_VtxDesc.Normal != NOT_PRESENT) { - switch (m_VtxAttr.NormalFormat) { - case FORMAT_UBYTE: - case FORMAT_BYTE: - CallCdeclFunction3_I(glNormalPointer, GL_BYTE, m_VBVertexStride, offset); offset += 3; - if (m_VtxAttr.NormalElements) { - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; - } - break; - case FORMAT_USHORT: - case FORMAT_SHORT: - CallCdeclFunction3_I(glNormalPointer, GL_SHORT, m_VBVertexStride, offset); offset += 6; - if (m_VtxAttr.NormalElements) { - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; - } - break; - case FORMAT_FLOAT: - CallCdeclFunction3_I(glNormalPointer, GL_FLOAT, m_VBVertexStride, offset); offset += 12; - if (m_VtxAttr.NormalElements) { - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12; - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12; - } - break; - default: _assert_(0); break; - } - } - - // TODO : With byte or short normals above, offset will be misaligned (not 4byte aligned)! Ugh! - - for (int i = 0; i < 2; i++) { - if (col[i] != NOT_PRESENT) { - if (i) - CallCdeclFunction4((void *)glSecondaryColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset); - else - CallCdeclFunction4_I(glColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset); - offset += 4; - } - } - - // TextureCoord - for (int i = 0; i < 8; i++) { - if (tc[i] != NOT_PRESENT || (m_components & (VB_HAS_TEXMTXIDX0 << i))) { - int id = GL_TEXTURE0 + i; -#ifdef _M_X64 -#ifdef _MSC_VER - MOV(32, R(RCX), Imm32(id)); -#else - MOV(32, R(RDI), Imm32(id)); -#endif -#else - ABI_AlignStack(1 * 4); - PUSH(32, Imm32(id)); -#endif - CALL((void *)glClientActiveTexture); -#ifndef _M_X64 -#ifdef _WIN32 - // don't inc stack on windows, stdcall -#else - ABI_RestoreStack(1 * 4); -#endif -#endif - // TODO : More potential disalignment! - if (m_components & (VB_HAS_TEXMTXIDX0 << i)) { - if (tc[i] != NOT_PRESENT) { - CallCdeclFunction4_I(glTexCoordPointer, 3, GL_FLOAT, m_VBVertexStride, offset); - offset += 12; - } - else { - CallCdeclFunction4_I(glTexCoordPointer, 3, GL_SHORT, m_VBVertexStride, offset); - offset += 6; - } - } - else { - CallCdeclFunction4_I(glTexCoordPointer, m_VtxAttr.texCoord[i].Elements ? 2 : 1, GL_FLOAT, m_VBVertexStride, offset); - offset += 4 * (m_VtxAttr.texCoord[i].Elements?2:1); - } - } - } - - if (m_VtxDesc.PosMatIdx) { - CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_POSMTX_ATTRIB, 1, GL_UNSIGNED_BYTE, GL_FALSE, m_VBVertexStride, offset); - offset += 1; - } - - _assert_(offset+m_VBStridePad == m_VBVertexStride); - - Util::EmitEpilogue(6); - if (Gen::GetCodePtr() - (u8*)m_compiledCode > COMPILED_CODE_SIZE) - { - assert(0); - Crash(); - } - - SetCodePtr(old_code_ptr); + m_NativeFmt.Initialize(m_VtxDesc, m_VtxAttr); } void VertexLoader::SetupColor(int num, int mode, int format, int elements) { // if COL0 not present, then embed COL1 into COL0 - if (num == 1 && !(m_components & VB_HAS_COL0)) + if (num == 1 && !(m_NativeFmt.m_components & VB_HAS_COL0)) num = 0; - m_components |= VB_HAS_COL0 << num; + m_NativeFmt.m_components |= VB_HAS_COL0 << num; switch (mode) { case NOT_PRESENT: - m_components &= ~(VB_HAS_COL0 << num); + m_NativeFmt.m_components &= ~(VB_HAS_COL0 << num); break; case DIRECT: switch (format) @@ -610,12 +466,12 @@ void VertexLoader::SetupColor(int num, int mode, int format, int elements) void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, int _iFrac) { - m_components |= VB_HAS_UV0 << num; + m_NativeFmt.m_components |= VB_HAS_UV0 << num; switch (mode) { case NOT_PRESENT: - m_components &= ~(VB_HAS_UV0 << num); + m_NativeFmt.m_components &= ~(VB_HAS_UV0 << num); break; case DIRECT: switch (format) @@ -653,9 +509,9 @@ void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, in } } -void VertexLoader::WriteCall(void (LOADERDECL *func)(void *)) +void VertexLoader::WriteCall(TPipelineFunction func) { - m_PipelineStages[m_numPipelineStages++] = func; + m_NativeFmt.m_PipelineStages[m_NativeFmt.m_numPipelineStages++] = func; } void VertexLoader::RunVertices(int primitive, int count) @@ -666,7 +522,7 @@ void VertexLoader::RunVertices(int primitive, int count) ComputeVertexSize(); // Figure out a better check. Also, jitting fnSetupVertexPointers seems pretty silly - not likely to be a bottleneck. - if (fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode) + if (fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_NativeFmt.m_compiledCode) VertexManager::Flush(); if (bpmem.genMode.cullmode == 3 && primitive < 5) @@ -679,14 +535,14 @@ void VertexLoader::RunVertices(int primitive, int count) // This has dirty handling - won't actually recompute unless necessary. PrepareForVertexFormat(); - fnSetupVertexPointers = (void (*)())(void*)m_compiledCode; + fnSetupVertexPointers = (void (*)())(void*)m_NativeFmt.m_compiledCode; - VertexManager::EnableComponents(m_components); + VertexManager::EnableComponents(m_NativeFmt.m_components); // Load position and texcoord scale factors. // Hm, this could be done when the VtxAttr is set, instead. posScale = shiftLookup[m_VtxAttr.PosFrac]; - if (m_components & VB_HAS_UVALL) { + if (m_NativeFmt.m_components & VB_HAS_UVALL) { for (int i = 0; i < 8; i++) { tcScaleU[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac]; tcScaleV[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac]; @@ -700,11 +556,11 @@ void VertexLoader::RunVertices(int primitive, int count) switch (primitive) { case 3: // strip case 4: // fan - if (VertexManager::GetRemainingSize() < 3 * m_VBVertexStride ) + if (VertexManager::GetRemainingSize() < 3 * m_NativeFmt.m_VBVertexStride ) VertexManager::Flush(); break; case 6: // line strip - if (VertexManager::GetRemainingSize() < 2 * m_VBVertexStride ) + if (VertexManager::GetRemainingSize() < 2 * m_NativeFmt.m_VBVertexStride ) VertexManager::Flush(); break; case 0: // quads @@ -723,7 +579,7 @@ void VertexLoader::RunVertices(int primitive, int count) { if ((v % granularity) == 0) { - if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) { + if (VertexManager::GetRemainingSize() < granularity*m_NativeFmt.m_VBVertexStride) { // This buffer full - break current primitive and flush, to switch to the next buffer. u8* plastptr = VertexManager::s_pCurBufferPointer; if (v - startv > 0) @@ -734,27 +590,27 @@ void VertexLoader::RunVertices(int primitive, int count) case 3: // triangle strip, copy last two vertices // a little trick since we have to keep track of signs if (v & 1) { - memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_VBVertexStride, m_VBVertexStride); - memcpy_gc(VertexManager::s_pCurBufferPointer+m_VBVertexStride, plastptr-m_VBVertexStride*2, 2*m_VBVertexStride); - VertexManager::s_pCurBufferPointer += m_VBVertexStride*3; + memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_NativeFmt.m_VBVertexStride, m_NativeFmt.m_VBVertexStride); + memcpy_gc(VertexManager::s_pCurBufferPointer+m_NativeFmt.m_VBVertexStride, plastptr-m_NativeFmt.m_VBVertexStride*2, 2*m_NativeFmt.m_VBVertexStride); + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBVertexStride*3; extraverts = 3; } else { - memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*2, m_VBVertexStride*2); - VertexManager::s_pCurBufferPointer += m_VBVertexStride*2; + memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_NativeFmt.m_VBVertexStride*2, m_NativeFmt.m_VBVertexStride*2); + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBVertexStride*2; extraverts = 2; } break; case 4: // tri fan, copy first and last vert - memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*(v-startv+extraverts), m_VBVertexStride); - VertexManager::s_pCurBufferPointer += m_VBVertexStride; - memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride); - VertexManager::s_pCurBufferPointer += m_VBVertexStride; + memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_NativeFmt.m_VBVertexStride*(v-startv+extraverts), m_NativeFmt.m_VBVertexStride); + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBVertexStride; + memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_NativeFmt.m_VBVertexStride, m_NativeFmt.m_VBVertexStride); + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBVertexStride; extraverts = 2; break; case 6: // line strip - memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride); - VertexManager::s_pCurBufferPointer += m_VBVertexStride; + memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_NativeFmt.m_VBVertexStride, m_NativeFmt.m_VBVertexStride); + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBVertexStride; extraverts = 1; break; default: @@ -767,10 +623,10 @@ void VertexLoader::RunVertices(int primitive, int count) tcIndex = 0; colIndex = 0; s_texmtxwrite = s_texmtxread = 0; - for (int i = 0; i < m_numPipelineStages; i++) - m_PipelineStages[i](&m_VtxAttr); - VertexManager::s_pCurBufferPointer += m_VBStridePad; + m_NativeFmt.RunPipelineOnce(m_VtxAttr); + + VertexManager::s_pCurBufferPointer += m_NativeFmt.m_VBStridePad; PRIM_LOG("\n"); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h index 4cd0a3f936..65a63c10f2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h @@ -21,8 +21,7 @@ #include "CPMemory.h" #include "DataReader.h" -#define LOADERDECL __cdecl -typedef void (LOADERDECL *TPipelineFunction)(void*); +#include "NativeVertexFormat.h" // There are 8 of these. Most games only use the first, and just reconfigure it all the time // as needed, unfortunately. @@ -37,15 +36,16 @@ public: NRM_THREE = 3 }; -private: - TPipelineFunction m_PipelineStages[32]; - int m_numPipelineStages; +private: + // The 3 possible values (0, 1, 2) should be documented here. + enum { + AD_CLEAN = 0, + AD_DIRTY = 1, + AD_VAT_DIRTY = 2, + } m_AttrDirty; + // Flipper vertex format ============= int m_VertexSize; // number of bytes of a raw GC vertex - int m_VBVertexStride; // PC-side vertex stride - int m_VBStridePad; - - u32 m_components; // VB_HAS_X. Bitmask telling what vertex components are present. // Raw VAttr UVAT_group0 m_group0; @@ -53,21 +53,15 @@ private: UVAT_group2 m_group2; TVtxAttr m_VtxAttr; // Decoded into easy format - u8* m_compiledCode; - // Common for all loaders (? then why is it here?) TVtxDesc m_VtxDesc; + // PC vertex format, + converter ====== + NativeVertexFormat m_NativeFmt; + void SetupColor(int num, int _iMode, int _iFormat, int _iElements); void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac); - // The 3 possible values (0, 1, 2) should be documented here. - enum { - AD_CLEAN = 0, - AD_DIRTY = 1, - AD_VAT_DIRTY = 2, - } m_AttrDirty; - public: // constructor VertexLoader(); @@ -76,10 +70,10 @@ public: // run the pipeline void PrepareForVertexFormat(); void RunVertices(int primitive, int count); - void WriteCall(void (LOADERDECL *func)(void *)); + void WriteCall(TPipelineFunction); int GetGCVertexSize() const { _assert_( !m_AttrDirty ); return m_VertexSize; } - int GetVBVertexStride() const { _assert_( !m_AttrDirty); return m_VBVertexStride; } + int GetVBVertexStride() const { _assert_( !m_AttrDirty); return m_NativeFmt.m_VBVertexStride; } int ComputeVertexSize(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader_Color.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader_Color.h index d6cfa52709..dc91765dbb 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader_Color.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader_Color.h @@ -81,7 +81,7 @@ inline u32 _Read32(u32 iAddress) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -void LOADERDECL Color_ReadDirect_24b_888(void* _p) +void LOADERDECL Color_ReadDirect_24b_888(const void *_p) { u32 col = DataReadU8()<glprogid); - glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid); + if (vs) glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid); + if (ps) glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid); // Lego Star Wars crashes here. #ifdef _DEBUG PRIM_LOG("\n"); @@ -327,10 +328,12 @@ void VertexManager::LoadCPReg(u32 sub_cmd, u32 value) } } +// This should move into NativeVertexFormat void VertexManager::EnableComponents(u32 components) { if (s_prevcomponents != components) { - VertexManager::Flush(); + if (s_vStoredPrimitives.size() != 0) + PanicAlert("EnableComponents - report this bug"); // matrices if ((components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp index c5538afadd..d5eba1cef0 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp @@ -224,7 +224,7 @@ const u16 s_mtrltable[16][2] = {{0, 0}, {0, 1}, {1, 1}, {0, 2}, // ======================================================================================= // Syncs the shader constant buffers with xfmem // ---------------- -void VertexShaderMngr::SetConstants(VERTEXSHADER& vs) +void VertexShaderMngr::SetConstants() { //nTransformMatricesChanged[0] = 0; nTransformMatricesChanged[1] = 256; //nNormalMatricesChanged[0] = 0; nNormalMatricesChanged[1] = 96; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h index 1d08ace835..7b31581531 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h @@ -112,7 +112,7 @@ public: static bool CompileVertexShader(VERTEXSHADER& ps, const char* pstrprogram); // constant management - static void SetConstants(VERTEXSHADER& vs); + static void SetConstants(); static void SetViewport(float* _Viewport); static void SetViewportChanged();