Update d3d implementation and add some debugging code

This commit is contained in:
kaetemi 2013-09-11 01:12:37 +02:00
parent 9a75f11c78
commit c11ad45d91
11 changed files with 112 additions and 28 deletions

View file

@ -2542,8 +2542,8 @@ private:
// The last vertex buffer needs vertex color // The last vertex buffer needs vertex color
bool _FogEnabled; bool _FogEnabled;
bool _VertexProgramUser; NLMISC::CRefPtr<CVertexProgram> _VertexProgramUser;
bool _PixelProgramUser; NLMISC::CRefPtr<CPixelProgram> _PixelProgramUser;
// *** Internal resources // *** Internal resources

View file

@ -328,7 +328,7 @@ bool CDriverD3D::setupMaterial(CMaterial &mat)
pShader = static_cast<CMaterialDrvInfosD3D*>((IMaterialDrvInfos*)(mat._MatDrvInfo)); pShader = static_cast<CMaterialDrvInfosD3D*>((IMaterialDrvInfos*)(mat._MatDrvInfo));
// Now we can get the supported shader from the cache. // Now we can get the supported shader from the cache.
CMaterial::TShader matShader = mat.getShader(); CMaterial::TShader matShader = _PixelProgramUser ? CMaterial::Program : mat.getShader();
if (_CurrentMaterialSupportedShader != CMaterial::Normal) if (_CurrentMaterialSupportedShader != CMaterial::Normal)
{ {
@ -648,7 +648,9 @@ bool CDriverD3D::setupMaterial(CMaterial &mat)
// Must separate texture setup and texture activation in 2 "for"... // Must separate texture setup and texture activation in 2 "for"...
// because setupTexture() may disable all stage. // because setupTexture() may disable all stage.
if (matShader == CMaterial::Normal || matShader == CMaterial::PostProcessing) if (matShader == CMaterial::Normal
|| ((matShader == CMaterial::Program) && (_PixelProgramUser->features().MaterialFlags & CGPUProgramFeatures::TextureStages))
)
{ {
uint stage; uint stage;
for(stage=0 ; stage<maxTexture; ++stage) for(stage=0 ; stage<maxTexture; ++stage)
@ -668,7 +670,9 @@ bool CDriverD3D::setupMaterial(CMaterial &mat)
// Don't do it also for Specular because the EnvFunction and the TexGen may be special. // Don't do it also for Specular because the EnvFunction and the TexGen may be special.
{ {
H_AUTO_D3D(CDriverD3D_setupMaterial_normalShaderActivateTextures) H_AUTO_D3D(CDriverD3D_setupMaterial_normalShaderActivateTextures)
if (matShader == CMaterial::Normal || matShader == CMaterial::PostProcessing) if (matShader == CMaterial::Normal
|| ((matShader == CMaterial::Program) && (_PixelProgramUser->features().MaterialFlags & CGPUProgramFeatures::TextureStages))
)
{ {
uint stage; uint stage;
for(stage=0 ; stage<maxTexture; ++stage) for(stage=0 ; stage<maxTexture; ++stage)

View file

@ -129,13 +129,13 @@ bool CDriverD3D::activePixelProgram(CPixelProgram *program)
if (!CDriverD3D::compilePixelProgram(program)) return false; if (!CDriverD3D::compilePixelProgram(program)) return false;
CPixelProgramDrvInfosD3D *info = static_cast<CPixelProgramDrvInfosD3D *>((IGPUProgramDrvInfos*)program->m_DrvInfo); CPixelProgramDrvInfosD3D *info = static_cast<CPixelProgramDrvInfosD3D *>((IGPUProgramDrvInfos*)program->m_DrvInfo);
_PixelProgramUser = true; _PixelProgramUser = program;
setPixelShader(info->Shader); setPixelShader(info->Shader);
} }
else else
{ {
setPixelShader(NULL); setPixelShader(NULL);
_PixelProgramUser = false; _PixelProgramUser = NULL;
} }
return true; return true;

View file

@ -379,7 +379,7 @@ bool CDriverD3D::activeVertexProgram (CVertexProgram *program)
if (!CDriverD3D::compileVertexProgram(program)) return false; if (!CDriverD3D::compileVertexProgram(program)) return false;
CVertexProgamDrvInfosD3D *info = NLMISC::safe_cast<CVertexProgamDrvInfosD3D *>((IGPUProgramDrvInfos*)program->m_DrvInfo); CVertexProgamDrvInfosD3D *info = NLMISC::safe_cast<CVertexProgamDrvInfosD3D *>((IGPUProgramDrvInfos*)program->m_DrvInfo);
_VertexProgramUser = true; _VertexProgramUser = program;
setVertexProgram (info->Shader, program); setVertexProgram (info->Shader, program);
/* D3DRS_FOGSTART and D3DRS_FOGEND must be set with [1, 0] else the fog doesn't work properly on VertexShader and non-VertexShader objects /* D3DRS_FOGSTART and D3DRS_FOGEND must be set with [1, 0] else the fog doesn't work properly on VertexShader and non-VertexShader objects
@ -395,7 +395,7 @@ bool CDriverD3D::activeVertexProgram (CVertexProgram *program)
else else
{ {
setVertexProgram (NULL, NULL); setVertexProgram (NULL, NULL);
_VertexProgramUser = false; _VertexProgramUser = NULL;
// Set the old fog range // Set the old fog range
setRenderState (D3DRS_FOGSTART, *((DWORD*) (&_FogStart))); setRenderState (D3DRS_FOGSTART, *((DWORD*) (&_FogStart)));

View file

@ -1204,7 +1204,7 @@ void CLandscape::render(const CVector &refineCenter, const CVector &frontVecto
{ {
// activate the program to set the uniforms in the program state for all programs // activate the program to set the uniforms in the program state for all programs
// note: when uniforms are driver state, the indices must be the same across programs // note: when uniforms are driver state, the indices must be the same across programs
if (uprogstate) _TileVB.activateVP(i); _TileVB.activateVP(i);
// c[0..3] take the ModelViewProjection Matrix. // c[0..3] take the ModelViewProjection Matrix.
driver->setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity); driver->setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity);

View file

@ -659,9 +659,13 @@ CVertexProgramLandscape::CVertexProgramLandscape(CLandscapeVBAllocator::TType ty
void CVertexProgramLandscape::buildInfo() void CVertexProgramLandscape::buildInfo()
{ {
m_Idx.ProgramConstants0 = getUniformIndex("programConstants0"); m_Idx.ProgramConstants0 = getUniformIndex("programConstants0");
nlassert(m_Idx.ProgramConstants0 != ~0);
m_Idx.RefineCenter = getUniformIndex("refineCenter"); m_Idx.RefineCenter = getUniformIndex("refineCenter");
nlassert(m_Idx.RefineCenter != ~0);
m_Idx.TileDist = getUniformIndex("tileDist"); m_Idx.TileDist = getUniformIndex("tileDist");
nlassert(m_Idx.TileDist != ~0);
m_Idx.PZBModelPosition = getUniformIndex("pzbModelPosition"); m_Idx.PZBModelPosition = getUniformIndex("pzbModelPosition");
nlassert(m_Idx.PZBModelPosition != ~0);
} }
} // NL3D } // NL3D

View file

@ -78,6 +78,48 @@ const char *a_arbfp1 =
"MOV result.color.yzw, R0;\n" "MOV result.color.yzw, R0;\n"
"END\n"; "END\n";
const char *a_ps_2_0 =
"ps_2_0\n"
// cgc version 3.1.0013, build date Apr 18 2012
// command line args: -profile ps_2_0
// source file: pp_stereo_debug.cg
//vendor NVIDIA Corporation
//version 3.1.0.13
//profile ps_2_0
//program pp_stereo_debug
//semantic pp_stereo_debug.cTex0 : TEX0
//semantic pp_stereo_debug.cTex1 : TEX1
//var float2 texCoord : $vin.TEXCOORD0 : TEX0 : 0 : 1
//var sampler2D cTex0 : TEX0 : texunit 0 : 1 : 1
//var sampler2D cTex1 : TEX1 : texunit 1 : 2 : 1
//var float4 oCol : $vout.COLOR : COL : 3 : 1
//const c[0] = 0 1 0.5
"dcl_2d s0\n"
"dcl_2d s1\n"
"def c0, 0.00000000, 1.00000000, 0.50000000, 0\n"
"dcl t0.xy\n"
"texld r1, t0, s1\n"
"texld r2, t0, s0\n"
"add r0, r2, -r1\n"
"add r1, r2, r1\n"
"mul r1, r1, c0.z\n"
"abs r0, r0\n"
"cmp r0, -r0, c0.x, c0.y\n"
"add_pp_sat r0.x, r0, r0.y\n"
"add_pp_sat r0.x, r0, r0.z\n"
"add_pp_sat r0.x, r0, r0.w\n"
"abs_pp r0.x, r0\n"
"cmp_pp r0.x, -r0, c0.y, c0\n"
"abs_pp r0.x, r0\n"
"mov r2.xzw, r1\n"
"mad r2.y, r1, c0.z, c0.z\n"
"cmp r2, -r0.x, r1, r2\n"
"mad r1.x, r2, c0.z, c0.z\n"
"mov r0.yzw, r2\n"
"cmp r0.x, -r0, r1, r2\n"
"mov oC0, r0\n";
;
class CStereoDebuggerFactory : public IStereoDeviceFactory class CStereoDebuggerFactory : public IStereoDeviceFactory
{ {
public: public:
@ -116,27 +158,31 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver(); NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver();
IGPUProgram::CSource *source = new IGPUProgram::CSource(); if (drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
source->Features.MaterialFlags = CGPUProgramFeatures::TextureStages;
/*if (drvInternal->supportPixelProgram(CPixelProgram::fp40) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{ {
nldebug("VR: fp40");
m_PixelProgram = new CPixelProgram(a_fp40);
}
else*/ if (drvInternal->supportPixelProgram(CPixelProgram::arbfp1) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{
nldebug("VR: arbfp1");
source->Profile = IGPUProgram::arbfp1;
source->setSourcePtr(a_arbfp1);
m_PixelProgram = new CPixelProgram(); m_PixelProgram = new CPixelProgram();
m_PixelProgram->addSource(source); // arbfp1
{
IGPUProgram::CSource *source = new IGPUProgram::CSource();
source->Features.MaterialFlags = CGPUProgramFeatures::TextureStages;
source->Profile = IGPUProgram::arbfp1;
source->setSourcePtr(a_arbfp1);
m_PixelProgram->addSource(source);
}
// ps_2_0
{
IGPUProgram::CSource *source = new IGPUProgram::CSource();
source->Features.MaterialFlags = CGPUProgramFeatures::TextureStages;
source->Profile = IGPUProgram::ps_2_0;
source->setSourcePtr(a_ps_2_0);
m_PixelProgram->addSource(source);
}
if (!drvInternal->compilePixelProgram(m_PixelProgram))
{
delete m_PixelProgram;
m_PixelProgram = NULL;
}
} }
/*else if (drvInternal->supportPixelProgram(CPixelProgram::ps_2_0))
{
nldebug("VR: ps_2_0");
m_PixelProgram = new CPixelProgram(a_ps_2_0);
}*/
if (m_PixelProgram) if (m_PixelProgram)
{ {

View file

@ -642,6 +642,8 @@ public:
source->setSource(vpgram); source->setSource(vpgram);
source->ParamIndices["modelViewProjection"] = 0;
source->ParamIndices["fog"] = 6;
source->ParamIndices["programConstants0"] = 8; source->ParamIndices["programConstants0"] = 8;
source->ParamIndices["directionalLight"] = 9; source->ParamIndices["directionalLight"] = 9;
source->ParamIndices["viewCenter"] = 10; source->ParamIndices["viewCenter"] = 10;
@ -670,20 +672,33 @@ public:
virtual void buildInfo() virtual void buildInfo()
{ {
m_Idx.ProgramConstants0 = getUniformIndex("programConstants0"); m_Idx.ProgramConstants0 = getUniformIndex("programConstants0");
nlassert(m_Idx.ProgramConstants0 != ~0);
m_Idx.DirectionalLight = getUniformIndex("directionalLight"); m_Idx.DirectionalLight = getUniformIndex("directionalLight");
nlassert(m_Idx.DirectionalLight != ~0);
m_Idx.ViewCenter = getUniformIndex("viewCenter"); m_Idx.ViewCenter = getUniformIndex("viewCenter");
nlassert(m_Idx.ViewCenter != ~0);
m_Idx.NegInvTransDist = getUniformIndex("negInvTransDist"); m_Idx.NegInvTransDist = getUniformIndex("negInvTransDist");
nlassert(m_Idx.NegInvTransDist != ~0);
m_Idx.AngleAxis = getUniformIndex("angleAxis"); m_Idx.AngleAxis = getUniformIndex("angleAxis");
nlassert(m_Idx.AngleAxis != ~0);
m_Idx.Wind = getUniformIndex("wind"); m_Idx.Wind = getUniformIndex("wind");
nlassert(m_Idx.Wind != ~0);
m_Idx.CosCoeff0 = getUniformIndex("cosCoeff0"); m_Idx.CosCoeff0 = getUniformIndex("cosCoeff0");
nlassert(m_Idx.CosCoeff0 != ~0);
m_Idx.CosCoeff1 = getUniformIndex("cosCoeff1"); m_Idx.CosCoeff1 = getUniformIndex("cosCoeff1");
nlassert(m_Idx.CosCoeff1 != ~0);
m_Idx.CosCoeff2 = getUniformIndex("cosCoeff2"); m_Idx.CosCoeff2 = getUniformIndex("cosCoeff2");
nlassert(m_Idx.CosCoeff2 != ~0);
m_Idx.QuatConstants = getUniformIndex("quatConstants"); m_Idx.QuatConstants = getUniformIndex("quatConstants");
nlassert(m_Idx.QuatConstants != ~0);
m_Idx.PiConstants = getUniformIndex("piConstants"); m_Idx.PiConstants = getUniformIndex("piConstants");
nlassert(m_Idx.PiConstants != ~0);
m_Idx.LUTSize = getUniformIndex("lutSize"); m_Idx.LUTSize = getUniformIndex("lutSize");
nlassert(m_Idx.LUTSize != ~0);
for (uint i = 0; i < NL3D_VEGETABLE_VP_LUT_SIZE; ++i) for (uint i = 0; i < NL3D_VEGETABLE_VP_LUT_SIZE; ++i)
{ {
m_Idx.LUT[i] = getUniformIndex(NLMISC::toString("lut[%i]", i)); m_Idx.LUT[i] = getUniformIndex(NLMISC::toString("lut[%i]", i));
nlassert(m_Idx.LUT[i] != ~0);
} }
} }
const CIdx &idx() const { return m_Idx; } const CIdx &idx() const { return m_Idx; }

View file

@ -266,6 +266,7 @@ public:
virtual void buildInfo() virtual void buildInfo()
{ {
m_Idx.ProgramConstant0 = getUniformIndex("programConstant0"); m_Idx.ProgramConstant0 = getUniformIndex("programConstant0");
nlassert(m_Idx.ProgramConstant0 != ~0);
} }
inline const CIdx &idx() { return m_Idx; } inline const CIdx &idx() { return m_Idx; }
private: private:

View file

@ -125,15 +125,23 @@ CVertexProgramWaterVPNoWave::CVertexProgramWaterVPNoWave(bool diffuse)
void CVertexProgramWaterVPNoWave::buildInfo() void CVertexProgramWaterVPNoWave::buildInfo()
{ {
m_Idx.BumpMap0Scale = getUniformIndex("bumpMap0Scale"); m_Idx.BumpMap0Scale = getUniformIndex("bumpMap0Scale");
nlassert(m_Idx.BumpMap0Scale != ~0);
m_Idx.BumpMap0Offset = getUniformIndex("bumpMap0Offset"); m_Idx.BumpMap0Offset = getUniformIndex("bumpMap0Offset");
nlassert(m_Idx.BumpMap0Offset != ~0);
m_Idx.BumpMap1Scale = getUniformIndex("bumpMap1Scale"); m_Idx.BumpMap1Scale = getUniformIndex("bumpMap1Scale");
nlassert(m_Idx.BumpMap1Scale != ~0);
m_Idx.BumpMap1Offset = getUniformIndex("bumpMap1Offset"); m_Idx.BumpMap1Offset = getUniformIndex("bumpMap1Offset");
nlassert(m_Idx.BumpMap1Offset != ~0);
m_Idx.ObserverHeight = getUniformIndex("observerHeight"); m_Idx.ObserverHeight = getUniformIndex("observerHeight");
nlassert(m_Idx.ObserverHeight != ~0);
m_Idx.ScaleReflectedRay = getUniformIndex("scaleReflectedRay"); m_Idx.ScaleReflectedRay = getUniformIndex("scaleReflectedRay");
nlassert(m_Idx.ScaleReflectedRay != ~0);
if (m_Diffuse) if (m_Diffuse)
{ {
m_Idx.DiffuseMapVector0 = getUniformIndex("diffuseMapVector0"); m_Idx.DiffuseMapVector0 = getUniformIndex("diffuseMapVector0");
nlassert(m_Idx.DiffuseMapVector0 != ~0);
m_Idx.DiffuseMapVector1 = getUniformIndex("diffuseMapVector1"); m_Idx.DiffuseMapVector1 = getUniformIndex("diffuseMapVector1");
nlassert(m_Idx.DiffuseMapVector1 != ~0);
} }
} }

View file

@ -125,11 +125,17 @@ public:
virtual void buildInfo() virtual void buildInfo()
{ {
m_Idx.WorldToUV0 = getUniformIndex("worldToUV0"); m_Idx.WorldToUV0 = getUniformIndex("worldToUV0");
nlassert(m_Idx.WorldToUV0 != ~0);
m_Idx.WorldToUV1 = getUniformIndex("worldToUV1"); m_Idx.WorldToUV1 = getUniformIndex("worldToUV1");
nlassert(m_Idx.WorldToUV1 != ~0);
m_Idx.RefCamDist = getUniformIndex("refCamDist"); m_Idx.RefCamDist = getUniformIndex("refCamDist");
nlassert(m_Idx.RefCamDist != ~0);
m_Idx.DistScaleBias = getUniformIndex("distScaleBias"); m_Idx.DistScaleBias = getUniformIndex("distScaleBias");
nlassert(m_Idx.DistScaleBias != ~0);
m_Idx.Diffuse = getUniformIndex("diffuse"); m_Idx.Diffuse = getUniformIndex("diffuse");
nlassert(m_Idx.Diffuse != ~0);
m_Idx.BlendScale = getUniformIndex("blendScale"); m_Idx.BlendScale = getUniformIndex("blendScale");
nlassert(m_Idx.BlendScale != ~0);
} }
inline const CIdx &idx() const { return m_Idx; } inline const CIdx &idx() const { return m_Idx; }
private: private: