A little housekeeping on Vertex Shader in DX9. Pending more work but my shader code is still too buggy to commit.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@330 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2008-08-26 23:11:15 +00:00
parent 59974dfb5b
commit 60a5a592f9
8 changed files with 62 additions and 86 deletions

View File

@ -227,6 +227,7 @@ void Renderer::SwapBuffers(void)
//clean out old stuff from caches
frameCount++;
PShaderCache::Cleanup();
VShaderCache::Cleanup();
TextureCache::Cleanup();
//DListCache::Cleanup();

View File

@ -2,6 +2,7 @@
#include "Utils.h"
#include "Globals.h"
#include "ShaderManager.h"
#include "VertexLoader.h"
#include "BPMemory.h"
#include "XFMemory.h"
@ -40,7 +41,6 @@ VShaderCache::VSCache VShaderCache::vshaders;
void PShaderCache::Init()
{
}
@ -49,7 +49,7 @@ void PShaderCache::Shutdown()
PSCache::iterator iter = pshaders.begin();
for (;iter!=pshaders.end();iter++)
iter->second.Destroy();
pshaders.clear();
pshaders.clear();
}
@ -79,7 +79,7 @@ void PShaderCache::SetShader()
}
const char *code = GeneratePixelShader();
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePShader(code, strlen(code));
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePShader(code, int(strlen(code)));
if (shader)
{
//Make an entry in the table
@ -135,8 +135,13 @@ void VShaderCache::Shutdown()
void VShaderCache::SetShader()
{
if (D3D::GetShaderVersion() < 2)
return; // we are screwed
static LPDIRECT3DVERTEXSHADER9 lastShader = 0;
xformhash currentHash = GetCurrentXForm();
DVSTARTPROFILE();
tevhash currentHash = GetCurrentTEV();
VSCache::iterator iter;
iter = vshaders.find(currentHash);
@ -153,8 +158,8 @@ void VShaderCache::SetShader()
return;
}
LPDIRECT3DVERTEXSHADER9 shader = GenerateVertexShader();
const char *code = GenerateVertexShader();
LPDIRECT3DVERTEXSHADER9 shader = D3D::CompileVShader(code, int(strlen(code)));
if (shader)
{
//Make an entry in the table
@ -180,5 +185,5 @@ void VShaderCache::Cleanup()
iter = vshaders.erase(iter);
}
}
SETSTAT(stats.numPixelShadersAlive, (int)vshaders.size());
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
}

View File

@ -64,7 +64,7 @@ class VShaderCache
}
};
typedef std::map<xformhash,VSCacheEntry> VSCache;
typedef std::map<tevhash,VSCacheEntry> VSCache;
static VSCache vshaders;

View File

@ -126,7 +126,7 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
Vec3 OrigPos = varray->GetPos(i);
if (varray->GetComponents() & VB_HAS_POSMTXIDX)
if (varray->GetComponents() & VertexLoader::VB_HAS_POSMTXIDX)
{
int index = varray->GetPosMtxInd(i);
SetPosNormalMatrix(
@ -136,7 +136,7 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
for (int j = 0; j < 8; j++)
{
if (varray->GetComponents() & (VB_HAS_TEXMTXIDX0<<j))
if (varray->GetComponents() & (VertexLoader::VB_HAS_TEXMTXIDX0<<j))
{
float *flipmem = (float *)xfmem;
int index = varray->GetTexMtxInd(j, i);
@ -151,7 +151,7 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
Vec3 TempNormal;
Vec3 OrigNormal;
if (varray->GetComponents() & VB_HAS_NRM0)
if (varray->GetComponents() & VertexLoader::VB_HAS_NRM0)
{
OrigNormal = varray->GetNormal(0, i);
VtxMulMtx33(TempNormal, OrigNormal, m_pNormalMatrix);
@ -180,7 +180,7 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
RGBAFloat material;
RGBAFloat lightSum(0,0,0,0);
bool hasColorJ = (varray->GetComponents() & (VB_HAS_COL0 << j)) != 0;
bool hasColorJ = (varray->GetComponents() & (VertexLoader::VB_HAS_COL0 << j)) != 0;
//get basic material color from appropriate sources (this would compile nicely!:)
if (xfregs.colChans[j].color.matsource == GX_SRC_REG)
@ -295,7 +295,7 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
default:
{
int c = xfregs.texcoords[n].texmtxinfo.sourcerow - XF_SRCTEX0_INROW;
bool hasTCC = (varray->GetComponents() & (VB_HAS_UV0 << c)) != 0;
bool hasTCC = (varray->GetComponents() & (VertexLoader::VB_HAS_UV0 << c)) != 0;
if (c >= 0 && c <= 7 && hasTCC)
{
const DecUV &uv = varray->GetUV(c, i);

View File

@ -27,22 +27,22 @@ DecodedVArray *varray;
int ComputeVertexSize(u32 comp)
{
int size = 0;
if (comp & VB_HAS_POSMTXIDX)
if (comp & VertexLoader::VB_HAS_POSMTXIDX)
size += 4;
if (comp & (VB_HAS_TEXMTXIDX0 | VB_HAS_TEXMTXIDX1 | VB_HAS_TEXMTXIDX2 | VB_HAS_TEXMTXIDX3))
if (comp & (VertexLoader::VB_HAS_TEXMTXIDX0 | VertexLoader::VB_HAS_TEXMTXIDX1 | VertexLoader::VB_HAS_TEXMTXIDX2 | VertexLoader::VB_HAS_TEXMTXIDX3))
size += 4;
if (comp & (VB_HAS_TEXMTXIDX4 | VB_HAS_TEXMTXIDX5 | VB_HAS_TEXMTXIDX6 | VB_HAS_TEXMTXIDX7))
if (comp & (VertexLoader::VB_HAS_TEXMTXIDX4 | VertexLoader::VB_HAS_TEXMTXIDX5 | VertexLoader::VB_HAS_TEXMTXIDX6 | VertexLoader::VB_HAS_TEXMTXIDX7))
size += 4;
if (comp & VB_HAS_NRM0)
if (comp & VertexLoader::VB_HAS_NRM0)
size += 4;
if (comp & (VB_HAS_NRM1 | VB_HAS_NRM2)) //combine into single check for speed
if (comp & (VertexLoader::VB_HAS_NRM1 | VertexLoader::VB_HAS_NRM2)) //combine into single check for speed
size += 8;
if (comp & VB_HAS_COL0)
if (comp & VertexLoader::VB_HAS_COL0)
size += 4;
if (comp & VB_HAS_COL1)
if (comp & VertexLoader::VB_HAS_COL1)
size += 4;
for (int i = 0; i < 8; i++)
if (comp & (VB_HAS_UV0 << i))
if (comp & (VertexLoader::VB_HAS_UV0 << i))
size += 8;
return size;
}

View File

@ -24,34 +24,6 @@ The decision will be how granular to be with the number of shaders and lighting
*/
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_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_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),
};
int ComputeVertexSize(u32 components);
#include "CPStructs.h"
@ -70,6 +42,38 @@ public:
NRM_THREE = 3
};
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,
};
private:
TPipelineFunction m_PipelineStates[32];
int m_numPipelineStates;

View File

@ -3,43 +3,12 @@
#include "VertexShader.h"
#include "BPStructs.h"
//I hope we don't get too many hash collisions :p
//all these magic numbers are primes, it should help a bit
xformhash GetCurrentXForm()
{
//return 0;
xformhash hash = bpmem.genMode.numtexgens*8*17;
/*
for (int i=0; i<bpmem.genMode.numtevstages+1; i++)
{
hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13);
hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3);
}
for (int i=0; i<bpmem.genMode.numtevstages/2+1; i++)
{
hash = _rotl(hash,13) ^ (bpmem.tevorders[i].hex*7);
}
for (int i=0; i<8; i++)
{
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap1;
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap2;
}*/
// to hash: bpmem.tevorders[j/2].getTexCoord(j&1);
// also texcoords array
return hash;
}
char text2[65536];
#define WRITE p+=sprintf
void WriteTexgen(char *&p, int n);
LPDIRECT3DVERTEXSHADER9 GenerateVertexShader()
const char *GenerateVertexShader()
{
int numColors = 2;
int numUV = 8;
@ -97,7 +66,7 @@ LPDIRECT3DVERTEXSHADER9 GenerateVertexShader()
WRITE(p,"\0");
// MessageBox(0,text2,0,0);
return D3D::CompileVShader(text2,(int)(p-text2));
return text2;
}

View File

@ -3,10 +3,7 @@
#include "Common.h"
typedef u32 xformhash;
xformhash GetCurrentXForm();
LPDIRECT3DVERTEXSHADER9 GenerateVertexShader();
const char *GenerateVertexShader();
#define PS_CONST_COLORS 0
#define PS_CONST_KCOLORS 4