Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PixelShaderGen: Don't disable depth texture emulation if z writing is…
… disabled (this is what VideoSoftware is doing).
  • Loading branch information
neobrain committed Jan 8, 2013
1 parent e979b2d commit 876eee5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Common/Src/LinearDiskCache.h
Expand Up @@ -24,7 +24,7 @@
// Increment this every time you change shader generation code.
enum
{
LINEAR_DISKCACHE_VER = 6975
LINEAR_DISKCACHE_VER = 6977
};

// On disk format:
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/BPMemory.h
Expand Up @@ -793,7 +793,7 @@ union PE_CONTROL
{
u32 pixel_format : 3; // PIXELFMT_X
u32 zformat : 3; // Z Compression for 16bit Z format
u32 zcomploc : 1; // 1: before tex stage
u32 early_ztest : 1; // 1: before tex stage
u32 unused : 17;
u32 rid : 8;
};
Expand Down
17 changes: 8 additions & 9 deletions Source/Core/VideoCommon/Src/PixelShaderGen.cpp
Expand Up @@ -109,7 +109,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo
uid->values[0] |= bpmem.genMode.numtexgens << 4; // 4
uid->values[0] |= dstAlphaMode << 8; // 2

bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth;
bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.early_ztest && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth;

uid->values[0] |= DepthTextureEnable << 10; // 1

Expand Down Expand Up @@ -170,7 +170,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo
if (DepthTextureEnable)
{
ptr[0] |= bpmem.ztex2.op << 11; // 2
ptr[0] |= bpmem.zcontrol.zcomploc << 13; // 1
ptr[0] |= bpmem.zcontrol.early_ztest << 13; // 1
ptr[0] |= bpmem.zmode.testenable << 14; // 1
ptr[0] |= bpmem.zmode.updateenable << 15; // 1
}
Expand Down Expand Up @@ -528,7 +528,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
nIndirectStagesUsed |= 1 << bpmem.tevind[i].bt;
}
}
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.early_ztest && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
// Declare samplers

if(ApiType != API_D3D11)
Expand Down Expand Up @@ -769,12 +769,11 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (DepthTextureEnable)
{
// use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format...
if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable)
// Note: depth textures are disabled if early depth test is enabled
if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.early_ztest && bpmem.zmode.testenable)
{
if (bpmem.ztex2.op == ZTEXTURE_ADD)
WRITE(p, "zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w + zCoord;\n");
else
WRITE(p, "zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w;\n");
WRITE(p, "zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w %s;\n",
(bpmem.ztex2.op == ZTEXTURE_ADD) ? "+ zCoord" : "");

// scale to make result from frac correct
WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n");
Expand Down Expand Up @@ -1264,7 +1263,7 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
// depth channel.
// 2 - in the next pass disable depth chanel update, but proccess the color data normally
// this way is the only CORRECT way to emulate perfectly the zcomplock behaviour
if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable))
if (!(bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable))
{
WRITE(p, "discard;\n");
if (ApiType != API_D3D11)
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp
Expand Up @@ -125,7 +125,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi)
if (z < 0 || z > 0x00ffffff)
return;

if (bpmem.zcontrol.zcomploc && bpmem.zmode.testenable)
if (bpmem.zcontrol.early_ztest && bpmem.zmode.testenable)
{
// early z
if (!EfbInterface::ZCompare(x, y, z))
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp
Expand Up @@ -784,7 +784,7 @@ void Tev::Draw()
output[BLU_C] = (output[BLU_C] * invFog + fogInt * bpmem.fog.color.b) >> 8;
}

if (!bpmem.zcontrol.zcomploc && bpmem.zmode.testenable)
if (!bpmem.zcontrol.early_ztest && bpmem.zmode.testenable)
{
if (!EfbInterface::ZCompare(Position[0], Position[1], Position[2]))
return;
Expand Down

0 comments on commit 876eee5

Please sign in to comment.