HUGE commit :)

in general cleanup and bugfix disable pierre  patch for the moment as it causes problem in some games and hopefully fix the remaining missing textures for nvidia users in opengl.
make the code in pixelshadergen looks nice and readable.
D3D: this is a ultra experimental commit please check for regressions or error.
make the efb Scale / super sampling level customizable to improve the output quality and let the user configure quality according to his hardware.
is everyone likes this change will translate it to opengl
please test


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5612 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2010-06-05 00:01:18 +00:00
parent 63dbcf4f97
commit c98f8a96d2
25 changed files with 291 additions and 434 deletions

View File

@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'};
// Update this to the current SVN revision every time you change shader generation code. // Update this to the current SVN revision every time you change shader generation code.
// We don't automatically get this from SVN_REV because that would mean regenerating the // We don't automatically get this from SVN_REV because that would mean regenerating the
// shader cache for every revision, graphics-related or not, which is simply annoying. // shader cache for every revision, graphics-related or not, which is simply annoying.
const int version = 5520; const int version = 5597;
LinearDiskCache::LinearDiskCache() LinearDiskCache::LinearDiskCache()
: file_(NULL), num_entries_(0) { : file_(NULL), num_entries_(0) {

View File

@ -108,6 +108,15 @@
// Tev/combiner things // Tev/combiner things
#define TEVSCALE_1 0
#define TEVSCALE_2 1
#define TEVSCALE_4 2
#define TEVDIVIDE_2 3
#define TEVCMP_R8 0
#define TEVCMP_GR16 1
#define TEVCMP_BGR24 2
#define TEVCMP_RGB8 3
#define TEVOP_ADD 0 #define TEVOP_ADD 0
#define TEVOP_SUB 1 #define TEVOP_SUB 1
@ -173,13 +182,10 @@ enum Compare
#define ZTEXTURE_ADD 1 #define ZTEXTURE_ADD 1
#define ZTEXTURE_REPLACE 2 #define ZTEXTURE_REPLACE 2
enum TevBias #define TevBias_ZERO 0
{ #define TevBias_ADDHALF 1
TB_ZERO = 0, #define TevBias_SUBHALF 2
TB_ADDHALF = 1, #define TevBias_COMPARE 3
TB_SUBHALF = 2,
TB_COMPARE = 3,
};
enum AlphaOp enum AlphaOp
{ {

View File

@ -157,13 +157,13 @@ const float epsilon8bit = 1.0f / 255.0f;
static const char *tevKSelTableC[] = // KCSEL static const char *tevKSelTableC[] = // KCSEL
{ {
"1.0f,1.0f,1.0f", // 1 = 0x00 "1.0f,1.0f,1.0f", // 1 = 0x00
"0.8745098f,0.8745098f,0.8745098f", // 7_8 = 0x01 "(223.0f/255.0f),(223.0f/255.0f),(223.0f/255.0f)", // 7_8 = 0x01
"0.7490196f,0.7490196f,0.7490196f", // 3_4 = 0x02 "(191.0f/255.0f),(191.0f/255.0f),(191.0f/255.0f)", // 3_4 = 0x02
"0.6235294f,0.6235294f,0.6235294f", // 5_8 = 0x03 "(159.0f/255.0f),(159.0f/255.0f),(159.0f/255.0f)", // 5_8 = 0x03
"0.4980392f,0.4980392f,0.4980392f", // 1_2 = 0x04 "(127.0f/255.0f),(127.0f/255.0f),(127.0f/255.0f)", // 1_2 = 0x04
"0.372549f,0.372549f,0.372549f", // 3_8 = 0x05 "(95.0f/255.0f),(95.0f/255.0f),(95.0f/255.0f)", // 3_8 = 0x05
"0.2470588f,0.2470588f,0.2470588f", // 1_4 = 0x06 "(63.0f/255.0f),(63.0f/255.0f),(63.0f/255.0f)", // 1_4 = 0x06
"0.1215686f,0.1215686f,0.1215686f", // 1_8 = 0x07 "(31.0f/255.0f),(31.0f/255.0f),(31.0f/255.0f)", // 1_8 = 0x07
"ERROR", // 0x08 "ERROR", // 0x08
"ERROR", // 0x09 "ERROR", // 0x09
"ERROR", // 0x0a "ERROR", // 0x0a
@ -193,13 +193,13 @@ static const char *tevKSelTableC[] = // KCSEL
static const char *tevKSelTableA[] = // KASEL static const char *tevKSelTableA[] = // KASEL
{ {
"1.0f", // 1 = 0x00 "1.0f", // 1 = 0x00
"0.8745098f",// 7_8 = 0x01 "(223.0f/255.0f)",// 7_8 = 0x01
"0.7490196f", // 3_4 = 0x02 "(191.0f/255.0f)", // 3_4 = 0x02
"0.6235294f",// 5_8 = 0x03 "(159.0f/255.0f)",// 5_8 = 0x03
"0.4980392f", // 1_2 = 0x04 "(127.0f/255.0f)", // 1_2 = 0x04
"0.372549f",// 3_8 = 0x05 "(95.0f/255.0f)",// 3_8 = 0x05
"0.2470588f", // 1_4 = 0x06 "(63.0f/255.0f)", // 1_4 = 0x06
"0.1215686f",// 1_8 = 0x07 "(31.0f/255.0f)",// 1_8 = 0x07
"ERROR", // 0x08 "ERROR", // 0x08
"ERROR", // 0x09 "ERROR", // 0x09
"ERROR", // 0x0a "ERROR", // 0x0a
@ -237,8 +237,8 @@ static const char *tevScaleTable[] = // CS
static const char *tevBiasTable[] = // TB static const char *tevBiasTable[] = // TB
{ {
"", // ZERO, "", // ZERO,
"+0.4980392f", // ADDHALF, "+(127.0f/255.0f)", // ADDHALF,
"-0.4980392f", // SUBHALF, "-(127.0f/255.0f)", // SUBHALF,
"", "",
}; };
@ -247,13 +247,6 @@ static const char *tevOpTable[] = { // TEV
"-", // TEVOP_SUB = 1, "-", // TEVOP_SUB = 1,
}; };
//static const char *tevCompOpTable[] = { ">", "==" };
#define TEVCMP_R8 0
#define TEVCMP_GR16 1
#define TEVCMP_BGR24 2
#define TEVCMP_RGB8 3
static const char *tevCInputTable[] = // CC static const char *tevCInputTable[] = // CC
{ {
"(prev.rgb)", // CPREV, "(prev.rgb)", // CPREV,
@ -269,7 +262,7 @@ static const char *tevCInputTable[] = // CC
"(rastemp.rgb)", // RASC, "(rastemp.rgb)", // RASC,
"(rastemp.aaa)", // RASA, "(rastemp.aaa)", // RASA,
"float3(1.0f,1.0f,1.0f)", // ONE "float3(1.0f,1.0f,1.0f)", // ONE
"float3(0.4980392f,0.4980392f,0.4980392f)", // HALF "float3((127.0f/255.0f),(127.0f/255.0f),(127.0f/255.0f))", // HALF
"(konsttemp.rgb)", //"konsttemp.rgb", // KONST "(konsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.0f,0.0f,0.0f)", // ZERO "float3(0.0f,0.0f,0.0f)", // ZERO
///aded extra values to map clamped values ///aded extra values to map clamped values
@ -286,7 +279,7 @@ static const char *tevCInputTable[] = // CC
"(rastemp.rgb)", // RASC, "(rastemp.rgb)", // RASC,
"(rastemp.aaa)", // RASA, "(rastemp.aaa)", // RASA,
"float3(1.0f,1.0f,1.0f)", // ONE "float3(1.0f,1.0f,1.0f)", // ONE
"float3(0.4980392f,0.4980392f,0.4980392f)", // HALF "float3((127.0f/255.0f),(127.0f/255.0f),(127.0f/255.0f))", // HALF
"(konsttemp.rgb)", //"konsttemp.rgb", // KONST "(konsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.0f,0.0f,0.0f)", // ZERO "float3(0.0f,0.0f,0.0f)", // ZERO
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
@ -510,7 +503,7 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, u32 H
} }
// emulation of unisgned 8 overflow when casting // emulation of unisgned 8 overflow when casting
WRITE(p, "prev = frac(4.0f + prev * 0.99609375f) * 1.00392157f;\n");//fmod(fmod(prev * 255.0f,256.0f) + 256.0f,256.0f) * 0.0039215686f;\n"); WRITE(p, "prev = frac(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n");
if (!WriteAlphaTest(p, HLSL)) if (!WriteAlphaTest(p, HLSL))
{ {
@ -719,14 +712,49 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL)
if (bCKonst || bAKonst ) if (bCKonst || bAKonst )
WRITE(p, "konsttemp=float4(%s,%s);\n",tevKSelTableC[kc],tevKSelTableA[ka]); WRITE(p, "konsttemp=float4(%s,%s);\n",tevKSelTableC[kc],tevKSelTableA[ka]);
if(cc.a == 0 || cc.a == 1 || cc.b == 0 || cc.b == 1 || cc.c == 0 || cc.c == 1 || ac.a == 0 || ac.b == 0 || ac.c == 0) if(cc.a == TEVCOLORARG_CPREV
WRITE(p, "cprev = frac(4.0f + prev * 0.99609375f) * 1.00392157f;\n"); || cc.a == TEVCOLORARG_APREV
if(cc.a == 2 || cc.a == 3 || cc.b == 2 || cc.b == 3 || cc.c == 2 || cc.c == 3 || ac.a == 1 || ac.b == 1 || ac.c == 1) || cc.b == TEVCOLORARG_CPREV
WRITE(p, "cc0 = frac(4.0f + c0 * 0.99609375f) * 1.00392157f;\n"); || cc.b == TEVCOLORARG_APREV
if(cc.a == 4 || cc.a == 5 || cc.b == 4 || cc.b == 5 || cc.c == 4 || cc.c == 5 || ac.a == 2 || ac.b == 2 || ac.c == 2) || cc.c == TEVCOLORARG_CPREV
WRITE(p, "cc1 = frac(4.0f + c1 * 0.99609375f) * 1.00392157f;\n"); || cc.c == TEVCOLORARG_APREV
if(cc.a == 6 || cc.a == 7 || cc.b == 6 || cc.b == 7 || cc.c == 6 || cc.c == 7 || ac.a == 3 || ac.b == 3 || ac.c == 3) || ac.a == TEVALPHAARG_APREV
WRITE(p, "cc2 = frac(4.0f + c2 * 0.99609375f) * 1.00392157f;\n"); || ac.b == TEVALPHAARG_APREV
|| ac.c == TEVALPHAARG_APREV)
WRITE(p, "cprev = frac(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n");
if(cc.a == TEVCOLORARG_C0
|| cc.a == TEVCOLORARG_A0
|| cc.b == TEVCOLORARG_C0
|| cc.b == TEVCOLORARG_A0
|| cc.c == TEVCOLORARG_C0
|| cc.c == TEVCOLORARG_A0
|| ac.a == TEVALPHAARG_A0
|| ac.b == TEVALPHAARG_A0
|| ac.c == TEVALPHAARG_A0)
WRITE(p, "cc0 = frac(4.0f + c0 * (255.0f/256.0f)) * (256.0f/255.0f);\n");
if(cc.a == TEVCOLORARG_C1
|| cc.a == TEVCOLORARG_A1
|| cc.b == TEVCOLORARG_C1
|| cc.b == TEVCOLORARG_A1
|| cc.c == TEVCOLORARG_C1
|| cc.c == TEVCOLORARG_A1
|| ac.a == TEVALPHAARG_A1
|| ac.b == TEVALPHAARG_A1
|| ac.c == TEVALPHAARG_A1)
WRITE(p, "cc1 = frac(4.0f + c1 * (255.0f/256.0f)) * (256.0f/255.0f);\n");
if(cc.a == TEVCOLORARG_C2
|| cc.a == TEVCOLORARG_A2
|| cc.b == TEVCOLORARG_C2
|| cc.b == TEVCOLORARG_A2
|| cc.c == TEVCOLORARG_C2
|| cc.c == TEVCOLORARG_A2
|| ac.a == TEVALPHAARG_A2
|| ac.b == TEVALPHAARG_A2
|| ac.c == TEVALPHAARG_A2)
WRITE(p, "cc2 = frac(4.0f + c2 * (255.0f/256.0f)) * (256.0f/255.0f);\n");
if (cc.clamp) if (cc.clamp)
WRITE(p, "%s=saturate(", tevCOutputTable[cc.dest]); WRITE(p, "%s=saturate(", tevCOutputTable[cc.dest]);
@ -734,13 +762,13 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL)
WRITE(p, "%s=", tevCOutputTable[cc.dest]); WRITE(p, "%s=", tevCOutputTable[cc.dest]);
// combine the color channel // combine the color channel
if (cc.bias != 3) // if not compare if (cc.bias != TevBias_COMPARE) // if not compare
{ {
//normal color combiner goes here //normal color combiner goes here
if (cc.shift>0) if (cc.shift > TEVSCALE_1)
WRITE(p, "%s*(",tevScaleTable[cc.shift]); WRITE(p, "%s*(",tevScaleTable[cc.shift]);
if(!(cc.d == TEVCOLORARG_ZERO && cc.op == 0)) if(!(cc.d == TEVCOLORARG_ZERO && cc.op == TEVOP_ADD))
WRITE(p, "%s%s",tevCInputTable[cc.d],tevOpTable[cc.op]); WRITE(p, "%s%s",tevCInputTable[cc.d],tevOpTable[cc.op]);
if (cc.a == cc.b) if (cc.a == cc.b)
@ -750,11 +778,11 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL)
else if (cc.c == TEVCOLORARG_ONE) else if (cc.c == TEVCOLORARG_ONE)
WRITE(p,"%s",tevCInputTable[cc.b + 16]); WRITE(p,"%s",tevCInputTable[cc.b + 16]);
else if (cc.a == TEVCOLORARG_ZERO) else if (cc.a == TEVCOLORARG_ZERO)
WRITE(p,"%s*(trunc(%s * 256.9921875f)*0.00390625f)",tevCInputTable[cc.b + 16],tevCInputTable[cc.c + 16]); WRITE(p,"%s*%s",tevCInputTable[cc.b + 16],tevCInputTable[cc.c + 16]);
else if (cc.b == TEVCOLORARG_ZERO) else if (cc.b == TEVCOLORARG_ZERO)
WRITE(p,"%s*(float3(1.0f,1.0f,1.0f)-(trunc(%s * 256.9921875f)*0.00390625f))",tevCInputTable[cc.a + 16],tevCInputTable[cc.c + 16]); WRITE(p,"%s*(float3(1.0f,1.0f,1.0f)-%s)",tevCInputTable[cc.a + 16],tevCInputTable[cc.c + 16]);
else else
WRITE(p, "lerp(%s,%s,(trunc(%s * 256.9921875f)*0.00390625f))",tevCInputTable[cc.a + 16], tevCInputTable[cc.b + 16],tevCInputTable[cc.c + 16]); WRITE(p, "lerp(%s,%s,%s)",tevCInputTable[cc.a + 16], tevCInputTable[cc.b + 16],tevCInputTable[cc.c + 16]);
WRITE(p, "%s",tevBiasTable[cc.bias]); WRITE(p, "%s",tevBiasTable[cc.bias]);
@ -780,13 +808,13 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL)
else else
WRITE(p, "%s=", tevAOutputTable[ac.dest]); WRITE(p, "%s=", tevAOutputTable[ac.dest]);
if (ac.bias != 3) // if not compare if (ac.bias != TevBias_COMPARE) // if not compare
{ {
//normal alpha combiner goes here //normal alpha combiner goes here
if (ac.shift>0) if (ac.shift > TEVSCALE_1)
WRITE(p, "%s*(",tevScaleTable[ac.shift]); WRITE(p, "%s*(",tevScaleTable[ac.shift]);
if(!(ac.d == TEVALPHAARG_ZERO && ac.op == 0)) if(!(ac.d == TEVALPHAARG_ZERO && ac.op == TEVOP_ADD))
WRITE(p, "%s.a%s",tevAInputTable[ac.d],tevOpTable[ac.op]); WRITE(p, "%s.a%s",tevAInputTable[ac.d],tevOpTable[ac.op]);
if (ac.a == ac.b) if (ac.a == ac.b)
@ -794,11 +822,11 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL)
else if (ac.c == TEVALPHAARG_ZERO) else if (ac.c == TEVALPHAARG_ZERO)
WRITE(p,"%s.a",tevAInputTable[ac.a + 8]); WRITE(p,"%s.a",tevAInputTable[ac.a + 8]);
else if (ac.a == TEVALPHAARG_ZERO) else if (ac.a == TEVALPHAARG_ZERO)
WRITE(p,"%s.a*(trunc(%s.a * 256.9921875f)*0.00390625f)",tevAInputTable[ac.b + 8],tevAInputTable[ac.c + 8]); WRITE(p,"%s.a*%s.a",tevAInputTable[ac.b + 8],tevAInputTable[ac.c + 8]);
else if (ac.b == TEVALPHAARG_ZERO) else if (ac.b == TEVALPHAARG_ZERO)
WRITE(p,"%s.a*(1.0f-(trunc(%s.a * 256.9921875f)*0.00390625f))",tevAInputTable[ac.a + 8],tevAInputTable[ac.c + 8]); WRITE(p,"%s.a*(1.0f-%s.a)",tevAInputTable[ac.a + 8],tevAInputTable[ac.c + 8]);
else else
WRITE(p, "lerp(%s.a,%s.a,(trunc(%s.a * 256.9921875f)*0.00390625f))",tevAInputTable[ac.a + 8],tevAInputTable[ac.b + 8],tevAInputTable[ac.c + 8]); WRITE(p, "lerp(%s.a,%s.a,%s.a)",tevAInputTable[ac.a + 8],tevAInputTable[ac.b + 8],tevAInputTable[ac.c + 8]);
WRITE(p, "%s",tevBiasTable[ac.bias]); WRITE(p, "%s",tevBiasTable[ac.bias]);

View File

@ -111,6 +111,7 @@ void WriteSwizzler(char*& p, u32 format,bool HLSL)
if(HLSL) if(HLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n"); WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
} }
} }
@ -163,6 +164,7 @@ void Write32BitSwizzler(char*& p, u32 format, bool HLSL)
if(HLSL) if(HLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n"); WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
} }
} }

View File

@ -598,12 +598,12 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int count)
int startv = 0, extraverts = 0; int startv = 0, extraverts = 0;
int v = 0; int v = 0;
int remainingVerts2 = VertexManager::GetRemainingVertices(primitive); //int remainingVerts2 = VertexManager::GetRemainingVertices(primitive);
while (v < count) while (v < count)
{ {
int remainingVerts = VertexManager::GetRemainingSize() / native_stride; int remainingVerts = VertexManager::GetRemainingSize() / native_stride;
if (remainingVerts2 - v + startv < remainingVerts) //if (remainingVerts2 - v + startv < remainingVerts)
remainingVerts = remainingVerts2 - v + startv; //remainingVerts = remainingVerts2 - v + startv;
if (remainingVerts < granularity) { if (remainingVerts < granularity) {
INCSTAT(stats.thisFrame.numBufferSplits); INCSTAT(stats.thisFrame.numBufferSplits);
// This buffer full - break current primitive and flush, to switch to the next buffer. // This buffer full - break current primitive and flush, to switch to the next buffer.
@ -611,7 +611,7 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int count)
if (v - startv > 0) if (v - startv > 0)
VertexManager::AddVertices(primitive, v - startv + extraverts); VertexManager::AddVertices(primitive, v - startv + extraverts);
VertexManager::Flush(); VertexManager::Flush();
remainingVerts2 = VertexManager::GetRemainingVertices(primitive); //remainingVerts2 = VertexManager::GetRemainingVertices(primitive);
// Why does this need to be so complicated? // Why does this need to be so complicated?
switch (primitive) { switch (primitive) {
case 3: // triangle strip, copy last two vertices case 3: // triangle strip, copy last two vertices

View File

@ -148,10 +148,15 @@ void Enumerate()
bool isNvidia = a.ident.VendorId == VENDOR_NVIDIA; bool isNvidia = a.ident.VendorId == VENDOR_NVIDIA;
// Add SuperSamples modes // Add SuperSamples modes
a.aa_levels.push_back(AALevel("None", D3DMULTISAMPLE_NONE, 0)); a.aa_levels.push_back(AALevel("1x EFB - SSAA NONE", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("2.25x SSAA", D3DMULTISAMPLE_NONE, 0)); a.aa_levels.push_back(AALevel("1x EFB - 4x SSAA", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("4x SSAA", D3DMULTISAMPLE_NONE, 0)); a.aa_levels.push_back(AALevel("1x EFB - 9x SSAA", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("9x SSAA", D3DMULTISAMPLE_NONE, 0)); a.aa_levels.push_back(AALevel("2x EFB - SSAA NONE", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("2x EFB - 4x SSAA", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("2x EFB - 9x SSAA", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("3x EFB - SSAA NONE", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("3x EFB - 4x SSAA", D3DMULTISAMPLE_NONE, 0));
a.aa_levels.push_back(AALevel("3x EFB - 9x SSAA", D3DMULTISAMPLE_NONE, 0));
//Add multisample modes //Add multisample modes
//disable them will they are not implemnted //disable them will they are not implemnted
/* /*

View File

@ -325,31 +325,12 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
float SuperSampleCompensation = 1.0f; float SuperSampleCompensation = 1.0f;
float scaleX = Renderer::GetXFBScaleX(); float scaleX = Renderer::GetXFBScaleX();
float scaleY = Renderer::GetXFBScaleY(); float scaleY = Renderer::GetXFBScaleY();
if(g_ActiveConfig.iMultisampleMode > 0 && g_ActiveConfig.iMultisampleMode < 4)
{
switch (g_ActiveConfig.iMultisampleMode)
{
case 1:
break;
case 2:
SuperSampleCompensation = 0.5f;
break;
case 3:
SuperSampleCompensation = 1.0f/3.0f;
break;
default:
break;
};
}
scaleX *= SuperSampleCompensation ;
scaleY *= SuperSampleCompensation;
TargetRectangle targetSource,efbSource; TargetRectangle targetSource,efbSource;
efbSource = Renderer::ConvertEFBRectangle(sourceRc); efbSource = Renderer::ConvertEFBRectangle(sourceRc);
targetSource.top = (sourceRc.top *scaleY); targetSource.top = (int)(sourceRc.top *scaleY);
targetSource.bottom = (sourceRc.bottom *scaleY); targetSource.bottom = (int)(sourceRc.bottom *scaleY);
targetSource.left = (sourceRc.left *scaleX); targetSource.left = (int)(sourceRc.left *scaleX);
targetSource.right = (sourceRc.right * scaleX); targetSource.right = (int)(sourceRc.right * scaleX);
int target_width = targetSource.right - targetSource.left; int target_width = targetSource.right - targetSource.left;
int target_height = targetSource.bottom - targetSource.top; int target_height = targetSource.bottom - targetSource.top;
if (it != m_virtualXFBList.end()) if (it != m_virtualXFBList.end())
@ -445,7 +426,6 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
int SSAAMode = ( g_ActiveConfig.iMultisampleMode > 3 )? 0 : g_ActiveConfig.iMultisampleMode;
D3D::drawShadedTexQuad( D3D::drawShadedTexQuad(
read_texture, read_texture,
&sourcerect, &sourcerect,
@ -453,8 +433,8 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
Renderer::GetFullTargetHeight(), Renderer::GetFullTargetHeight(),
target_width, target_width,
target_height, target_height,
PixelShaderCache::GetColorCopyProgram(SSAAMode), PixelShaderCache::GetColorCopyProgram( g_ActiveConfig.iMultisampleMode),
(SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader( g_ActiveConfig.iMultisampleMode));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);

View File

@ -42,26 +42,26 @@ LinearDiskCache g_ps_disk_cache;
static float lastPSconstants[C_COLORMATRIX+16][4]; static float lastPSconstants[C_COLORMATRIX+16][4];
static LPDIRECT3DPIXELSHADER9 s_ColorMatrixProgram[4]; static LPDIRECT3DPIXELSHADER9 s_ColorMatrixProgram[3];
static LPDIRECT3DPIXELSHADER9 s_ColorCopyProgram[4]; static LPDIRECT3DPIXELSHADER9 s_ColorCopyProgram[3];
static LPDIRECT3DPIXELSHADER9 s_DepthMatrixProgram[4]; static LPDIRECT3DPIXELSHADER9 s_DepthMatrixProgram[3];
static LPDIRECT3DPIXELSHADER9 s_ClearProgram = 0; static LPDIRECT3DPIXELSHADER9 s_ClearProgram = 0;
LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetColorMatrixProgram(int SSAAMode) LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetColorMatrixProgram(int SSAAMode)
{ {
return s_ColorMatrixProgram[SSAAMode]; return s_ColorMatrixProgram[SSAAMode % 3];
} }
LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetDepthMatrixProgram(int SSAAMode) LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetDepthMatrixProgram(int SSAAMode)
{ {
return s_DepthMatrixProgram[SSAAMode]; return s_DepthMatrixProgram[SSAAMode % 3];
} }
LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetColorCopyProgram(int SSAAMode) LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetColorCopyProgram(int SSAAMode)
{ {
return s_ColorCopyProgram[SSAAMode]; return s_ColorCopyProgram[SSAAMode % 3];
} }
LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetClearProgram() LPDIRECT3DPIXELSHADER9 PixelShaderCache::GetClearProgram()
@ -132,18 +132,7 @@ void PixelShaderCache::Init()
"in float2 uv0 : TEXCOORD0){\n" "in float2 uv0 : TEXCOORD0){\n"
"ocol0 = tex2D(samp0,uv0);\n" "ocol0 = tex2D(samp0,uv0);\n"
"}\n"); "}\n");
s_ColorCopyProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorCopyProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//2 samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
"void main(\n"
"out float4 ocol0 : COLOR0,\n"
"in float4 uv0 : TEXCOORD0,\n"
"in float4 uv1 : TEXCOORD1,\n"
"in float4 uv2 : TEXCOORD2){\n"
"ocol0 = (tex2D(samp0,uv1.xy) + tex2D(samp0,uv2.xy))*0.5f;\n"
"}\n");
s_ColorCopyProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//4 Samples //4 Samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
@ -156,7 +145,7 @@ void PixelShaderCache::Init()
"in float4 uv4 : TEXCOORD4){\n" "in float4 uv4 : TEXCOORD4){\n"
"ocol0 = (tex2D(samp0,uv1.xy) + tex2D(samp0,uv2.xy) + tex2D(samp0,uv3.xy) + tex2D(samp0,uv4.xy))*0.25f;\n" "ocol0 = (tex2D(samp0,uv1.xy) + tex2D(samp0,uv2.xy) + tex2D(samp0,uv3.xy) + tex2D(samp0,uv4.xy))*0.25f;\n"
"}\n"); "}\n");
s_ColorCopyProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorCopyProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//9 Samples //9 Samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
@ -169,7 +158,7 @@ void PixelShaderCache::Init()
"in float4 uv4 : TEXCOORD4){\n" "in float4 uv4 : TEXCOORD4){\n"
"ocol0 = (tex2D(samp0,uv1.xy) + tex2D(samp0,uv1.wz) + tex2D(samp0,uv2.xy) + tex2D(samp0,uv2.wz) + tex2D(samp0,uv3.xy) + tex2D(samp0,uv3.wz) + tex2D(samp0,uv4.xy) + tex2D(samp0,uv4.wz) + tex2D(samp0,uv0.xy))/9.0f;\n" "ocol0 = (tex2D(samp0,uv1.xy) + tex2D(samp0,uv1.wz) + tex2D(samp0,uv2.xy) + tex2D(samp0,uv2.wz) + tex2D(samp0,uv3.xy) + tex2D(samp0,uv3.wz) + tex2D(samp0,uv4.xy) + tex2D(samp0,uv4.wz) + tex2D(samp0,uv0.xy))/9.0f;\n"
"}\n"); "}\n");
s_ColorCopyProgram[3] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorCopyProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//Color conversion Programs //Color conversion Programs
//1 sample //1 sample
@ -181,24 +170,8 @@ void PixelShaderCache::Init()
"float4 texcol = tex2D(samp0,uv0);\n" "float4 texcol = tex2D(samp0,uv0);\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_ColorMatrixProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorMatrixProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//2 samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
"uniform float4 cColMatrix[5] : register(c%d);\n"
"void main(\n"
"out float4 ocol0 : COLOR0,\n"
"in float4 uv0 : TEXCOORD0,\n"
"in float4 uv1 : TEXCOORD1,\n"
"in float4 uv2 : TEXCOORD2,\n"
"in float4 uv3 : TEXCOORD3,\n"
"in float4 uv4 : TEXCOORD4,\n"
"in float4 uv5 : TEXCOORD5){\n"
"float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w)))) * 0.5f;\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX);
s_ColorMatrixProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//4 samples //4 samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
"uniform float4 cColMatrix[5] : register(c%d);\n" "uniform float4 cColMatrix[5] : register(c%d);\n"
@ -213,7 +186,7 @@ void PixelShaderCache::Init()
"float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.x,uv5.x,uv5.z),clamp(uv3.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.x,uv5.x,uv5.z),clamp(uv4.y,uv5.y,uv5.w))))*0.25f;\n" "float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.x,uv5.x,uv5.z),clamp(uv3.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.x,uv5.x,uv5.z),clamp(uv4.y,uv5.y,uv5.w))))*0.25f;\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_ColorMatrixProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorMatrixProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//9 samples //9 samples
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
@ -229,7 +202,7 @@ void PixelShaderCache::Init()
"float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv1.w,uv5.x,uv5.z),clamp(uv1.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.w,uv5.x,uv5.z),clamp(uv2.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.x,uv5.x,uv5.z),clamp(uv3.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.w,uv5.x,uv5.z),clamp(uv3.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.x,uv5.x,uv5.z),clamp(uv4.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.w,uv5.x,uv5.z),clamp(uv4.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv0.x,uv5.x,uv5.z),clamp(uv0.y,uv5.y,uv5.w))))/9;\n" "float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv1.w,uv5.x,uv5.z),clamp(uv1.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.w,uv5.x,uv5.z),clamp(uv2.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.x,uv5.x,uv5.z),clamp(uv3.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv3.w,uv5.x,uv5.z),clamp(uv3.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.x,uv5.x,uv5.z),clamp(uv4.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv4.w,uv5.x,uv5.z),clamp(uv4.z,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv0.x,uv5.x,uv5.z),clamp(uv0.y,uv5.y,uv5.w))))/9;\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_ColorMatrixProgram[3] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_ColorMatrixProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//Depth copy programs //Depth copy programs
//1 sample //1 sample
@ -243,26 +216,8 @@ void PixelShaderCache::Init()
"texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n" "texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_DepthMatrixProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_DepthMatrixProgram[0] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//2 sample
sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
"uniform float4 cColMatrix[5] : register(c%d);\n"
"void main(\n"
"out float4 ocol0 : COLOR0,\n"
"in float4 uv0 : TEXCOORD0,\n"
"in float4 uv1 : TEXCOORD1,\n"
"in float4 uv2 : TEXCOORD2,\n"
"in float4 uv3 : TEXCOORD3,\n"
"in float4 uv4 : TEXCOORD4,\n"
"in float4 uv5 : TEXCOORD5){\n"
"float4 texcol = (tex2D(samp0,float2(clamp(uv1.x,uv5.x,uv5.z),clamp(uv1.y,uv5.y,uv5.w))) + tex2D(samp0,float2(clamp(uv2.x,uv5.x,uv5.z),clamp(uv2.y,uv5.y,uv5.w)))) * 0.5f;\n"
"float4 EncodedDepth = frac((texcol.r * (16777215.0f/16777216.0f)) * float4(1.0f,255.0f,255.0f*255.0f,255.0f*255.0f*255.0f));\n"
"texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX);
s_DepthMatrixProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//4 sample //4 sample
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
"uniform float4 cColMatrix[5] : register(c%d);\n" "uniform float4 cColMatrix[5] : register(c%d);\n"
@ -279,7 +234,7 @@ void PixelShaderCache::Init()
"texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n" "texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_DepthMatrixProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_DepthMatrixProgram[1] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
//9 sample //9 sample
sprintf(pprog, "uniform sampler samp0 : register(s0);\n" sprintf(pprog, "uniform sampler samp0 : register(s0);\n"
@ -297,7 +252,7 @@ void PixelShaderCache::Init()
"texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n" "texcol = float4((EncodedDepth.rgb * (16777216.0f/16777215.0f)),1.0f);\n"
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
"}\n",C_COLORMATRIX); "}\n",C_COLORMATRIX);
s_DepthMatrixProgram[3] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); s_DepthMatrixProgram[2] = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog));
Clear(); Clear();
@ -325,7 +280,7 @@ void PixelShaderCache::Clear()
void PixelShaderCache::Shutdown() void PixelShaderCache::Shutdown()
{ {
for(int i = 0;i<4;i++) for(int i = 0;i<3;i++)
{ {
if (s_ColorMatrixProgram[i]) s_ColorMatrixProgram[i]->Release(); if (s_ColorMatrixProgram[i]) s_ColorMatrixProgram[i]->Release();
s_ColorMatrixProgram[i] = NULL; s_ColorMatrixProgram[i] = NULL;

View File

@ -116,85 +116,67 @@ static const D3DBLEND d3dDestFactors[8] =
D3DBLEND_INVDESTALPHA D3DBLEND_INVDESTALPHA
}; };
// 0 0x00
// 1 Source & destination
// 2 Source & ~destination
// 3 Source
// 4 ~Source & destination
// 5 Destination
// 6 Source ^ destination = Source & ~destination | ~Source & destination
// 7 Source | destination
// 8 ~(Source | destination)
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
// 10 ~Destination
// 11 Source | ~destination
// 12 ~Source
// 13 ~Source | destination
// 14 ~(Source & destination)
// 15 0xff
static const D3DBLENDOP d3dLogincOPop[16] = static const D3DBLENDOP d3dLogincOPop[16] =
{ {
D3DBLENDOP_ADD,//0 D3DBLENDOP_ADD,
D3DBLENDOP_ADD,//1 D3DBLENDOP_ADD,
D3DBLENDOP_SUBTRACT,//2 D3DBLENDOP_SUBTRACT,
D3DBLENDOP_ADD,//3 D3DBLENDOP_ADD,
D3DBLENDOP_REVSUBTRACT,//4 D3DBLENDOP_REVSUBTRACT,
D3DBLENDOP_ADD,//5 D3DBLENDOP_ADD,
D3DBLENDOP_MAX,//6 D3DBLENDOP_MAX,
D3DBLENDOP_ADD,//7 D3DBLENDOP_ADD,
D3DBLENDOP_MAX,//8 D3DBLENDOP_MAX,
D3DBLENDOP_MAX,//9 D3DBLENDOP_MAX,
D3DBLENDOP_ADD,//10 D3DBLENDOP_ADD,
D3DBLENDOP_ADD,//11 D3DBLENDOP_ADD,
D3DBLENDOP_ADD,//12 D3DBLENDOP_ADD,
D3DBLENDOP_ADD,//13 D3DBLENDOP_ADD,
D3DBLENDOP_ADD,//14 D3DBLENDOP_ADD,
D3DBLENDOP_ADD//15 D3DBLENDOP_ADD
}; };
static const D3DBLEND d3dLogicOpSrcFactors[16] = static const D3DBLEND d3dLogicOpSrcFactors[16] =
{ {
D3DBLEND_ZERO,//0 D3DBLEND_ZERO,
D3DBLEND_DESTCOLOR,//1 D3DBLEND_DESTCOLOR,
D3DBLEND_ONE,//2 D3DBLEND_ONE,
D3DBLEND_ONE,//3 D3DBLEND_ONE,
D3DBLEND_DESTCOLOR,//4 D3DBLEND_DESTCOLOR,
D3DBLEND_ZERO,//5 D3DBLEND_ZERO,
D3DBLEND_INVDESTCOLOR,//6 D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVDESTCOLOR,//7 D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVSRCCOLOR,//8 D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVSRCCOLOR,//9 D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVDESTCOLOR,//10 D3DBLEND_INVDESTCOLOR,
D3DBLEND_ONE,//11 D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,//12 D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVSRCCOLOR,//13 D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVDESTCOLOR,//14 D3DBLEND_INVDESTCOLOR,
D3DBLEND_ONE//15 D3DBLEND_ONE
}; };
static const D3DBLEND d3dLogicOpDestFactors[16] = static const D3DBLEND d3dLogicOpDestFactors[16] =
{ {
D3DBLEND_ZERO,//0 D3DBLEND_ZERO,
D3DBLEND_ZERO,//1 D3DBLEND_ZERO,
D3DBLEND_INVSRCCOLOR,//2 D3DBLEND_INVSRCCOLOR,
D3DBLEND_ZERO,//3 D3DBLEND_ZERO,
D3DBLEND_ONE,//4 D3DBLEND_ONE,
D3DBLEND_ONE,//5 D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,//6 D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE,//7 D3DBLEND_ONE,
D3DBLEND_INVDESTCOLOR,//8 D3DBLEND_INVDESTCOLOR,
D3DBLEND_SRCCOLOR,//9 D3DBLEND_SRCCOLOR,
D3DBLEND_INVDESTCOLOR,//10 D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVDESTCOLOR,//11 D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVSRCCOLOR,//12 D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE,//13 D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,//14 D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE//15 D3DBLEND_ONE
}; };
static const D3DCULL d3dCullModes[4] = static const D3DCULL d3dCullModes[4] =
@ -269,8 +251,8 @@ bool Renderer::Init()
UpdateActiveConfig(); UpdateActiveConfig();
int fullScreenRes, x, y, w_temp, h_temp; int fullScreenRes, x, y, w_temp, h_temp;
s_blendMode = 0; s_blendMode = 0;
// Multisample Anti-aliasing hasn't been implemented yet // Multisample Anti-aliasing hasn't been implemented yet use supersamling instead
int backbuffer_ms_mode = 0; // g_ActiveConfig.iMultisampleMode; int backbuffer_ms_mode = 0;
g_VideoInitialize.pRequestWindowSize(x, y, w_temp, h_temp); g_VideoInitialize.pRequestWindowSize(x, y, w_temp, h_temp);
@ -308,26 +290,9 @@ bool Renderer::Init()
s_LastAA = (g_ActiveConfig.iMultisampleMode > 3)?0:g_ActiveConfig.iMultisampleMode; s_LastAA = (g_ActiveConfig.iMultisampleMode > 3)?0:g_ActiveConfig.iMultisampleMode;
float SupersampleCoeficient = 1.0f; float SupersampleCoeficient = (s_LastAA % 3) + 1;
switch (s_LastAA) EFBxScale = (s_LastAA / 3) + 1 * SupersampleCoeficient;
{ EFByScale = EFBxScale;
case 1:
break;
case 2:
SupersampleCoeficient = 2.0f;
break;
case 3:
SupersampleCoeficient = 3.0f;
break;
default:
break;
};
xScale *= SupersampleCoeficient;
yScale *= SupersampleCoeficient;
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
s_target_width = EFB_WIDTH * EFBxScale; s_target_width = EFB_WIDTH * EFBxScale;
s_target_height = EFB_HEIGHT * EFByScale; s_target_height = EFB_HEIGHT * EFByScale;
@ -423,16 +388,6 @@ void Renderer::DrawDebugText()
std::string T1 = "", T2 = ""; std::string T1 = "", T2 = "";
std::vector<std::string> T0; std::vector<std::string> T0;
/*
int W, H;
sscanf(g_ActiveConfig.cInternalRes, "%dx%d", &W, &H);
std::string OSDM1 =
g_ActiveConfig.bNativeResolution || g_ActiveConfig.b2xResolution ?
(g_ActiveConfig.bNativeResolution ?
StringFromFormat("%i x %i (native)", OSDInternalW, OSDInternalH)
: StringFromFormat("%i x %i (2x)", OSDInternalW, OSDInternalH))
: StringFromFormat("%i x %i (custom)", W, H);
*/
std::string OSDM1 = StringFromFormat("%i x %i", OSDInternalW, OSDInternalH); std::string OSDM1 = StringFromFormat("%i x %i", OSDInternalW, OSDInternalH);
std::string OSDM21; std::string OSDM21;
switch(g_ActiveConfig.iAspectRatio) switch(g_ActiveConfig.iAspectRatio)
@ -494,16 +449,6 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color)
D3D::font.DrawTextScaled((float)left, (float)top, 20, 20, 0.0f, color, text, false); D3D::font.DrawTextScaled((float)left, (float)top, 20, 20, 0.0f, color, text, false);
} }
void dumpMatrix(D3DXMATRIX &mtx)
{
for (int y = 0; y < 4; y++)
{
char temp[256];
sprintf(temp,"%4.4f %4.4f %4.4f %4.4f", mtx.m[y][0], mtx.m[y][1], mtx.m[y][2], mtx.m[y][3]);
g_VideoInitialize.pLog(temp, FALSE);
}
}
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc) TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
{ {
int Xstride = (s_Fulltarget_width - s_target_width) / 2; int Xstride = (s_Fulltarget_width - s_target_width) / 2;
@ -597,27 +542,14 @@ bool Renderer::SetScissorRect()
rc.right = (int)((float)bpmem.scissorBR.x - xoff - 341); rc.right = (int)((float)bpmem.scissorBR.x - xoff - 341);
rc.bottom = (int)((float)bpmem.scissorBR.y - yoff - 341); rc.bottom = (int)((float)bpmem.scissorBR.y - yoff - 341);
int Xstride = (s_Fulltarget_width - s_target_width) / 2;
int Ystride = (s_Fulltarget_height - s_target_height) / 2;
rc.left = (int)(rc.left * EFBxScale);
rc.top = (int)(rc.top * EFByScale);
rc.right = (int)(rc.right * EFBxScale);
rc.bottom = (int)(rc.bottom * EFByScale);
if (rc.left < 0) rc.left = 0; if (rc.left < 0) rc.left = 0;
if (rc.right < 0) rc.right = 0; if (rc.right < 0) rc.right = 0;
if (rc.left > s_target_width) rc.left = s_target_width; if (rc.left > EFB_WIDTH) rc.left = EFB_WIDTH;
if (rc.right > s_target_width) rc.right = s_target_width; if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
if (rc.top < 0) rc.top = 0; if (rc.top < 0) rc.top = 0;
if (rc.bottom < 0) rc.bottom = 0; if (rc.bottom < 0) rc.bottom = 0;
if (rc.top > s_target_height) rc.top = s_target_height; if (rc.top > EFB_HEIGHT) rc.top = EFB_HEIGHT;
if (rc.bottom > s_target_height) rc.bottom = s_target_height; if (rc.bottom > EFB_HEIGHT) rc.bottom = EFB_HEIGHT;
rc.left += Xstride;
rc.top += Ystride;
rc.right += Xstride;
rc.bottom += Ystride;
if (rc.left > rc.right) if (rc.left > rc.right)
{ {
@ -631,8 +563,16 @@ bool Renderer::SetScissorRect()
rc.bottom = rc.top; rc.bottom = rc.top;
rc.top = temp; rc.top = temp;
} }
if (rc.right >= rc.left && rc.bottom >= rc.top) int Xstride = (s_Fulltarget_width - s_target_width) / 2;
int Ystride = (s_Fulltarget_height - s_target_height) / 2;
rc.left = (int)(rc.left * EFBxScale) + Xstride;
rc.top = (int)(rc.top * EFByScale) + Ystride;
rc.right = (int)(rc.right * EFBxScale) + Xstride;
rc.bottom = (int)(rc.bottom * EFByScale) + Ystride;
if (rc.right != rc.left && rc.bottom != rc.top)
{ {
D3D::dev->SetScissorRect(&rc); D3D::dev->SetScissorRect(&rc);
return true; return true;
@ -761,7 +701,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
Renderer::GetFullTargetHeight(), Renderer::GetFullTargetHeight(),
4,4, 4,4,
(BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram(0):PixelShaderCache::GetDepthMatrixProgram(0), (BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram(0):PixelShaderCache::GetDepthMatrixProgram(0),
VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader(0));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
@ -959,8 +899,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
D3D::ChangeRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); D3D::ChangeRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
D3D::drawClearQuad(color ,(z & 0xFFFFFF) / float(0xFFFFFF),PixelShaderCache::GetClearProgram(),VertexShaderCache::GetClearVertexShader()); D3D::drawClearQuad(color ,(z & 0xFFFFFF) / float(0xFFFFFF),PixelShaderCache::GetClearProgram(),VertexShaderCache::GetClearVertexShader());
if (zEnable) if (zEnable)
D3D::RefreshRenderState(D3DRS_ZFUNC); D3D::RefreshRenderState(D3DRS_ZFUNC);
//D3D::dev->Clear(0, NULL, (colorEnable ? D3DCLEAR_TARGET : 0)| ( zEnable ? D3DCLEAR_ZBUFFER : 0), color | ((alphaEnable)?0:0xFF000000),(z & 0xFFFFFF) / float(0xFFFFFF), 0);
UpdateViewport(); UpdateViewport();
SetScissorRect(); SetScissorRect();
} }
@ -1118,7 +1057,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
drawRc.right = 1; drawRc.right = 1;
} }
D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,Width,Height,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader()); D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,Width,Height,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader(0));
} }
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
@ -1133,7 +1072,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
if(s_bScreenshot) if(s_bScreenshot)
{ {
s_criticalScreenshot.Enter(); s_criticalScreenshot.Enter();
// create a R8G8B8 surface for the screenshot (no alpha channel) // create a R8G8B8 surface for the screenshot (no alpha channel)
// otherwise funky screenshots get saved // otherwise funky screenshots get saved
LPDIRECT3DSURFACE9 screenshot_surface; LPDIRECT3DSURFACE9 screenshot_surface;
@ -1145,7 +1083,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
} }
else else
PanicAlert("Failed to create surface for screenshot!"); PanicAlert("Failed to create surface for screenshot!");
s_bScreenshot = false; s_bScreenshot = false;
s_criticalScreenshot.Leave(); s_criticalScreenshot.Leave();
} }
@ -1256,29 +1194,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
yScale = (float)(dst_rect.bottom - dst_rect.top) / (float)s_XFB_height; yScale = (float)(dst_rect.bottom - dst_rect.top) / (float)s_XFB_height;
} }
float SupersampleCoeficient = 1.0f; float SupersampleCoeficient = (s_LastAA % 3) + 1;
switch (s_LastAA) EFBxScale = (s_LastAA / 3) + 1 * SupersampleCoeficient;
{ EFByScale = EFBxScale;
case 1: s_target_width = EFB_WIDTH * EFBxScale;
break; s_target_height = EFB_HEIGHT * EFByScale;
case 2:
SupersampleCoeficient = 2.0f;
break;
case 3:
SupersampleCoeficient = 3.0f;
break;
default:
break;
};
xScale *= SupersampleCoeficient;
yScale *= SupersampleCoeficient;
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
s_target_width = EFB_WIDTH * ceilf(EFBxScale);
s_target_height = EFB_HEIGHT * ceilf(EFByScale);
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface()); D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
if(WindowResized) if(WindowResized)
@ -1413,7 +1333,7 @@ void Renderer::SetSamplerState(int stage, int texindex)
min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT; min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT; mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
mip = (tm0.min_filter == 8)?D3DTEXF_NONE:d3dMipFilters[tm0.min_filter & 3]; mip = (tm0.min_filter == 8)?D3DTEXF_NONE:d3dMipFilters[tm0.min_filter & 3];
if((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 4) == 0)) mip = D3DTEXF_NONE; if((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 5) == 0)) mip = D3DTEXF_NONE;
} }
if (texindex) if (texindex)
stage += 4; stage += 4;
@ -1429,7 +1349,6 @@ void Renderer::SetSamplerState(int stage, int texindex)
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]); D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]); D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
//just a test but it seems to work
float lodbias = tm0.lod_bias / 32.0f; float lodbias = tm0.lod_bias / 32.0f;
D3D::SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,*(DWORD*)&lodbias); D3D::SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,*(DWORD*)&lodbias);
D3D::SetSamplerState(stage,D3DSAMP_MAXMIPLEVEL,tm1.min_lod>>5); D3D::SetSamplerState(stage,D3DSAMP_MAXMIPLEVEL,tm1.min_lod>>5);

View File

@ -188,7 +188,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
if (!g_ActiveConfig.bSafeTextureCache) if (!g_ActiveConfig.bSafeTextureCache)
hash_value = ((u32 *)ptr)[0]; hash_value = ((u32 *)ptr)[0];
if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash) && FullFormat == entry.fmt)) if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash) && FullFormat == entry.fmt && entry.MipLevels <= maxlevel))
{ {
entry.frameCount = frameCount; entry.frameCount = frameCount;
D3D::SetTexture(stage, entry.texture); D3D::SetTexture(stage, entry.texture);
@ -200,7 +200,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
// instead of destroying it and having to create a new one. // instead of destroying it and having to create a new one.
// Might speed up movie playback very, very slightly. // Might speed up movie playback very, very slightly.
if (width == entry.w && height==entry.h && FullFormat == entry.fmt) if (width == entry.w && height==entry.h && FullFormat == entry.fmt && entry.MipLevels == maxlevel)
{ {
skip_texture_create = true; skip_texture_create = true;
} }
@ -286,6 +286,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
TexLevels = (isPow2 && UseNativeMips && (maxlevel > 0)) ? (int)(log((double)TexLevels)/log((double)2)) + 1 : ((isPow2)? 0 : 1); TexLevels = (isPow2 && UseNativeMips && (maxlevel > 0)) ? (int)(log((double)TexLevels)/log((double)2)) + 1 : ((isPow2)? 0 : 1);
if(TexLevels > maxlevel && maxlevel > 0) if(TexLevels > maxlevel && maxlevel > 0)
TexLevels = maxlevel; TexLevels = maxlevel;
entry.MipLevels = maxlevel;
if (!skip_texture_create) if (!skip_texture_create)
{ {
entry.texture = D3D::CreateTexture2D((BYTE*)temp, width, height, expandedWidth, d3d_fmt, swap_r_b, TexLevels); entry.texture = D3D::CreateTexture2D((BYTE*)temp, width, height, expandedWidth, d3d_fmt, swap_r_b, TexLevels);
@ -361,25 +362,11 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
int tex_w = (abs(source_rect.GetWidth()) >> bScaleByHalf); int tex_w = (abs(source_rect.GetWidth()) >> bScaleByHalf);
int tex_h = (abs(source_rect.GetHeight()) >> bScaleByHalf); int tex_h = (abs(source_rect.GetHeight()) >> bScaleByHalf);
//compensate the texture grow if supersampling is enabled to conserve memory usage //compensate the texture grow if supersampling is enabled to conserve memory usage
float SuperSampleCompensation = 1.0f; float SuperSampleCompensation = (g_ActiveConfig.iMultisampleMode % 3) + 1;
SuperSampleCompensation = 1.0f / SuperSampleCompensation;
float xScale = Renderer::GetTargetScaleX(); float xScale = Renderer::GetTargetScaleX();
float yScale = Renderer::GetTargetScaleY(); float yScale = Renderer::GetTargetScaleY();
if(g_ActiveConfig.iMultisampleMode > 0 && g_ActiveConfig.iMultisampleMode < 4)
{
switch (g_ActiveConfig.iMultisampleMode)
{
case 1:
break;
case 2:
SuperSampleCompensation = 0.5f;
break;
case 3:
SuperSampleCompensation = 1.0f/3.0f;
break;
default:
break;
};
}
int Scaledtex_w = (g_ActiveConfig.bCopyEFBScaled)?((int)(xScale * SuperSampleCompensation * tex_w)):tex_w; int Scaledtex_w = (g_ActiveConfig.bCopyEFBScaled)?((int)(xScale * SuperSampleCompensation * tex_w)):tex_w;
int Scaledtex_h = (g_ActiveConfig.bCopyEFBScaled)?((int)(yScale * SuperSampleCompensation * tex_h)):tex_h; int Scaledtex_h = (g_ActiveConfig.bCopyEFBScaled)?((int)(yScale * SuperSampleCompensation * tex_h)):tex_h;
@ -585,7 +572,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
Scaledtex_w, Scaledtex_w,
Scaledtex_h, Scaledtex_h,
((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(SSAAMode): PixelShaderCache::GetColorMatrixProgram(SSAAMode), ((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(SSAAMode): PixelShaderCache::GetColorMatrixProgram(SSAAMode),
(SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader(SSAAMode));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);

View File

@ -39,7 +39,7 @@ public:
u32 oldpixel; u32 oldpixel;
int frameCount; int frameCount;
int w, h, fmt; int w, h, fmt,MipLevels;
int Scaledw, Scaledh; int Scaledw, Scaledh;
float scaleX, scaleY; // Hires texutres need this float scaleX, scaleY; // Hires texutres need this

View File

@ -271,7 +271,7 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
// Draw... // Draw...
D3D::drawShadedTexQuad(srcTexture,&SrcRect,1,1,dstWidth,dstHeight,shader,VertexShaderCache::GetSimpleVertexShader()); D3D::drawShadedTexQuad(srcTexture,&SrcRect,1,1,dstWidth,dstHeight,shader,VertexShaderCache::GetSimpleVertexShader(0));
hr = D3D::dev->SetRenderTarget(0, FBManager.GetEFBColorRTSurface()); hr = D3D::dev->SetRenderTarget(0, FBManager.GetEFBColorRTSurface());
hr = D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface()); hr = D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface());
Renderer::RestoreAPIState(); Renderer::RestoreAPIState();
@ -414,8 +414,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
return; return;
} }
float srcFormatFactor = 0.5f; int srcFmtWidth = srcWidth / 2;
float srcFmtWidth = srcWidth * srcFormatFactor;
Renderer::ResetAPIState(); // reset any game specific settings Renderer::ResetAPIState(); // reset any game specific settings
LPDIRECT3DTEXTURE9 s_srcTexture = D3D::CreateTexture2D(srcAddr, srcFmtWidth, srcHeight, srcFmtWidth, D3DFMT_A8R8G8B8, false); LPDIRECT3DTEXTURE9 s_srcTexture = D3D::CreateTexture2D(srcAddr, srcFmtWidth, srcHeight, srcFmtWidth, D3DFMT_A8R8G8B8, false);
@ -466,7 +465,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
srcWidth, srcWidth,
srcHeight, srcHeight,
s_yuyvToRgbProgram, s_yuyvToRgbProgram,
VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader(0));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);

View File

@ -269,7 +269,7 @@ void Flush()
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
tex.texTlut[i&3].tlut_format, tex.texTlut[i&3].tlut_format,
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8) && g_ActiveConfig.bUseNativeMips, (tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8) && g_ActiveConfig.bUseNativeMips,
(tex.texMode1[i&3].max_lod >> 4)); (tex.texMode1[i&3].max_lod >> 5));
if (tentry) { if (tentry) {
PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0); PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0);

View File

@ -40,15 +40,14 @@ const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
static float GC_ALIGNED16(lastVSconstants[C_FOGPARAMS + 8][4]); static float GC_ALIGNED16(lastVSconstants[C_FOGPARAMS + 8][4]);
static LPDIRECT3DVERTEXSHADER9 SimpleVertexShader; static LPDIRECT3DVERTEXSHADER9 SimpleVertexShader[3];
static LPDIRECT3DVERTEXSHADER9 ClearVertexShader; static LPDIRECT3DVERTEXSHADER9 ClearVertexShader;
static LPDIRECT3DVERTEXSHADER9 FSAAVertexShader;
LinearDiskCache g_vs_disk_cache; LinearDiskCache g_vs_disk_cache;
LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetSimpleVertexShader() LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetSimpleVertexShader(int level)
{ {
return SimpleVertexShader; return SimpleVertexShader[level % 3];
} }
LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetClearVertexShader() LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetClearVertexShader()
@ -56,10 +55,6 @@ LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetClearVertexShader()
return ClearVertexShader; return ClearVertexShader;
} }
LPDIRECT3DVERTEXSHADER9 VertexShaderCache::GetFSAAVertexShader()
{
return FSAAVertexShader;
}
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4) void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
{ {
@ -148,7 +143,7 @@ void VertexShaderCache::Init()
"return OUT;\n" "return OUT;\n"
"}\n"); "}\n");
SimpleVertexShader = D3D::CompileAndCreateVertexShader(vProg, (int)strlen(vProg)); SimpleVertexShader[0] = D3D::CompileAndCreateVertexShader(vProg, (int)strlen(vProg));
sprintf(vProg,"struct VSOUTPUT\n" sprintf(vProg,"struct VSOUTPUT\n"
"{\n" "{\n"
@ -180,14 +175,38 @@ void VertexShaderCache::Init()
"VSOUTPUT OUT;" "VSOUTPUT OUT;"
"OUT.vPosition = inPosition;\n" "OUT.vPosition = inPosition;\n"
"OUT.vTexCoord = inTEX0.xyyx;\n" "OUT.vTexCoord = inTEX0.xyyx;\n"
"OUT.vTexCoord1 = inTEX0.xyyx + (float4(-0.1830127f,-0.6830127f,-0.7071068f,-1.2247449f) * inTEX1.xyyx);\n" "OUT.vTexCoord1 = inTEX0.xyyx + (float4(-0.5f,-0.5f,-0.5f,-0.5f) * inTEX1.xyyx);\n"
"OUT.vTexCoord2 = inTEX0.xyyx + (float4(-0.6830127f, 0.1830127f, 0.7071068f, 1.2247449f) * inTEX1.xyyx);\n" "OUT.vTexCoord2 = inTEX0.xyyx + (float4(-0.5f, 0.5f, 0.5f,-0.5f) * inTEX1.xyyx);\n"
"OUT.vTexCoord3 = inTEX0.xyyx + (float4( 0.6830127f,-0.1830127f,-1.2247449f, 0.7071068f) * inTEX1.xyyx);\n" "OUT.vTexCoord3 = inTEX0.xyyx + (float4( 0.5f,-0.5f,-0.5f, 0.5f) * inTEX1.xyyx);\n"
"OUT.vTexCoord4 = inTEX0.xyyx + (float4( 0.1830127f, 0.6830127f, 1.2247449f,-0.7071068f) * inTEX1.xyyx);\n" "OUT.vTexCoord4 = inTEX0.xyyx + (float4( 0.5f, 0.5f, 0.5f, 0.5f) * inTEX1.xyyx);\n"
"OUT.vTexCoord5 = inTEX2;\n" "OUT.vTexCoord5 = inTEX2;\n"
"return OUT;\n" "return OUT;\n"
"}\n"); "}\n");
FSAAVertexShader = D3D::CompileAndCreateVertexShader(vProg, (int)strlen(vProg)); SimpleVertexShader[1] = D3D::CompileAndCreateVertexShader(vProg, (int)strlen(vProg));
sprintf(vProg, "struct VSOUTPUT\n"
"{\n"
"float4 vPosition : POSITION;\n"
"float4 vTexCoord : TEXCOORD0;\n"
"float4 vTexCoord1 : TEXCOORD1;\n"
"float4 vTexCoord2 : TEXCOORD2;\n"
"float4 vTexCoord3 : TEXCOORD3;\n"
"float4 vTexCoord4 : TEXCOORD4;\n"
"float4 vTexCoord5 : TEXCOORD5;\n"
"};\n"
"VSOUTPUT main(float4 inPosition : POSITION,float2 inTEX0 : TEXCOORD0,float2 inTEX1 : TEXCOORD1,float4 inTEX2 : TEXCOORD2)\n"
"{\n"
"VSOUTPUT OUT;"
"OUT.vPosition = inPosition;\n"
"OUT.vTexCoord = inTEX0.xyyx;\n"
"OUT.vTexCoord1 = inTEX0.xyyx + (float4(-1.0f,-1.0f,-1.0f, 1.0f) * inTEX1.xyyx);\n"
"OUT.vTexCoord2 = inTEX0.xyyx + (float4(-1.0f, 0.0f, 0.0f, 1.0f) * inTEX1.xyyx);\n"
"OUT.vTexCoord3 = inTEX0.xyyx + (float4(-1.0f, 1.0f, 1.0f, 1.0f) * inTEX1.xyyx);\n"
"OUT.vTexCoord4 = inTEX0.xyyx + (float4( 0.0f, 1.0f,-1.0f, 0.0f) * inTEX1.xyyx);\n"
"OUT.vTexCoord5 = inTEX2;\n"
"return OUT;\n"
"}\n");
SimpleVertexShader[2] = D3D::CompileAndCreateVertexShader(vProg, (int)strlen(vProg));
Clear(); Clear();
delete [] vProg; delete [] vProg;
@ -215,17 +234,17 @@ void VertexShaderCache::Clear()
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
{ {
if (SimpleVertexShader) for (int i = 0; i<3;i++)
SimpleVertexShader->Release(); {
SimpleVertexShader = NULL; if (SimpleVertexShader[i])
SimpleVertexShader[i]->Release();
SimpleVertexShader[i] = NULL;
}
if (ClearVertexShader) if (ClearVertexShader)
ClearVertexShader->Release(); ClearVertexShader->Release();
ClearVertexShader = NULL; ClearVertexShader = NULL;
if (FSAAVertexShader)
FSAAVertexShader->Release();
FSAAVertexShader = NULL;
Clear(); Clear();
g_vs_disk_cache.Sync(); g_vs_disk_cache.Sync();

View File

@ -55,9 +55,8 @@ public:
static void Clear(); static void Clear();
static void Shutdown(); static void Shutdown();
static bool SetShader(u32 components); static bool SetShader(u32 components);
static LPDIRECT3DVERTEXSHADER9 GetSimpleVertexShader(); static LPDIRECT3DVERTEXSHADER9 GetSimpleVertexShader(int level);
static LPDIRECT3DVERTEXSHADER9 GetClearVertexShader(); static LPDIRECT3DVERTEXSHADER9 GetClearVertexShader();
static LPDIRECT3DVERTEXSHADER9 GetFSAAVertexShader();
static bool InsertByteCode(const VERTEXSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate); static bool InsertByteCode(const VERTEXSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
static std::string GetCurrentShaderCode(); static std::string GetCurrentShaderCode();

View File

@ -12,11 +12,13 @@
#undef APSTUDIO_READONLY_SYMBOLS #undef APSTUDIO_READONLY_SYMBOLS
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// English (United States) resources // English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252) #pragma code_page(1252)
#endif //_WIN32
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
@ -44,7 +46,7 @@ BEGIN
CONTROL "&Widescreen Hack",IDC_WIDESCREEN_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,25,67,10 CONTROL "&Widescreen Hack",IDC_WIDESCREEN_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,25,67,10
LTEXT "&Aspect Ratio:",IDC_STATIC,9,40,48,8 LTEXT "&Aspect Ratio:",IDC_STATIC,9,40,48,8
COMBOBOX IDC_ASPECTRATIO,68,39,89,57,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_ASPECTRATIO,68,39,89,57,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "&Anti-alias mode:",IDC_STATIC,9,59,51,8 LTEXT "&Scale - AA mode:",IDC_STATIC,9,59,59,8
COMBOBOX IDC_ANTIALIASMODE,68,59,162,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_ANTIALIASMODE,68,59,162,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "&Enable CPU->EFB access ",IDC_EFB_ACCESS_ENABLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,7,80,94,11 CONTROL "&Enable CPU->EFB access ",IDC_EFB_ACCESS_ENABLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,7,80,94,11
GROUPBOX "Safe Texture Cache Mode",IDC_STATIC,109,94,125,27 GROUPBOX "Safe Texture Cache Mode",IDC_STATIC,109,94,125,27
@ -103,7 +105,7 @@ END
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO GUIDELINES DESIGNINFO
BEGIN BEGIN
IDD_ABOUT, DIALOG IDD_ABOUT, DIALOG
BEGIN BEGIN
@ -177,7 +179,7 @@ END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
#endif // English (United States) resources #endif // English (U.S.) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -111,7 +111,7 @@ void PixelShaderCache::Init()
"ADD result.color, R1, program.env[%d];\n" "ADD result.color, R1, program.env[%d];\n"
"END\n", C_COLORMATRIX+3, C_COLORMATRIX+2, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+4); "END\n", C_COLORMATRIX+3, C_COLORMATRIX+2, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+4);
glGenProgramsARB(1, &s_ColorMatrixProgram); glGenProgramsARB(1, &s_ColorMatrixProgram);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, s_ColorMatrixProgram); SetCurrentShader(s_ColorMatrixProgram);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog); glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
GLenum err = GL_REPORT_ERROR(); GLenum err = GL_REPORT_ERROR();
@ -139,7 +139,7 @@ void PixelShaderCache::Init()
"ADD result.color, R1, program.env[%d];\n" "ADD result.color, R1, program.env[%d];\n"
"END\n", C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4); "END\n", C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4);
glGenProgramsARB(1, &s_DepthMatrixProgram); glGenProgramsARB(1, &s_DepthMatrixProgram);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, s_DepthMatrixProgram); SetCurrentShader(s_DepthMatrixProgram);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog); glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
err = GL_REPORT_ERROR(); err = GL_REPORT_ERROR();
@ -148,9 +148,7 @@ void PixelShaderCache::Init()
glDeleteProgramsARB(1, &s_DepthMatrixProgram); glDeleteProgramsARB(1, &s_DepthMatrixProgram);
s_DepthMatrixProgram = 0; s_DepthMatrixProgram = 0;
} }
CurrentShader=0;
ShaderEnabled = false;
EnableShader(s_DepthMatrixProgram);
} }
void PixelShaderCache::Shutdown() void PixelShaderCache::Shutdown()
@ -160,7 +158,7 @@ void PixelShaderCache::Shutdown()
glDeleteProgramsARB(1, &s_DepthMatrixProgram); glDeleteProgramsARB(1, &s_DepthMatrixProgram);
s_DepthMatrixProgram = 0; s_DepthMatrixProgram = 0;
PSCache::iterator iter = pshaders.begin(); PSCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); ++iter) for (; iter != pshaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
pshaders.clear(); pshaders.clear();
} }
@ -272,7 +270,7 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr
} }
glGenProgramsARB(1, &ps.glprogid); glGenProgramsARB(1, &ps.glprogid);
EnableShader(ps.glprogid); SetCurrentShader(ps.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog); glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR(); err = GL_REPORT_ERROR();
@ -311,7 +309,6 @@ void PixelShaderCache::DisableShader()
CurrentShader = 0; CurrentShader = 0;
if(ShaderEnabled) if(ShaderEnabled)
{ {
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
glDisable(GL_FRAGMENT_PROGRAM_ARB); glDisable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = false; ShaderEnabled = false;
} }
@ -320,17 +317,6 @@ void PixelShaderCache::DisableShader()
//bind a program if is diferent from the binded oone //bind a program if is diferent from the binded oone
void PixelShaderCache::SetCurrentShader(GLuint Shader) void PixelShaderCache::SetCurrentShader(GLuint Shader)
{
//The caching here breakes Super Mario Sunshine i'm still trying to figure out wy
if(ShaderEnabled /*&& CurrentShader != Shader*/)
{
CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
}
}
//Enable Fragment program and bind initial program
void PixelShaderCache::EnableShader(GLuint Shader)
{ {
if(!ShaderEnabled) if(!ShaderEnabled)
{ {
@ -343,4 +329,4 @@ void PixelShaderCache::EnableShader(GLuint Shader)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
} }
} }

View File

@ -81,8 +81,6 @@ public:
static void SetCurrentShader(GLuint Shader); static void SetCurrentShader(GLuint Shader);
static void DisableShader(); static void DisableShader();
static void EnableShader(GLuint Shader);
}; };
#endif // _PIXELSHADERCACHE_H_ #endif // _PIXELSHADERCACHE_H_

View File

@ -74,7 +74,7 @@ bool ApplyShader()
if (s_shader.glprogid != 0) if (s_shader.glprogid != 0)
{ {
PixelShaderCache::EnableShader(s_shader.glprogid); PixelShaderCache::SetCurrentShader(s_shader.glprogid);
return true; return true;
} }
else else

View File

@ -591,8 +591,8 @@ void Renderer::RestoreAPIState()
SetColorMask(); SetColorMask();
SetBlendMode(true); SetBlendMode(true);
VertexShaderCache::EnableShader(0); VertexShaderCache::SetCurrentShader(0);
PixelShaderCache::EnableShader(0); PixelShaderCache::SetCurrentShader(0);
} }
void Renderer::SetColorMask() void Renderer::SetColorMask()

View File

@ -203,7 +203,7 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar
glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight); glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);
PixelShaderCache::EnableShader(shader.glprogid); PixelShaderCache::SetCurrentShader(shader.glprogid);
// Draw... // Draw...
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -340,8 +340,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
Renderer::ResetAPIState(); Renderer::ResetAPIState();
float srcFormatFactor = 0.5f; int srcFmtWidth = srcWidth / 2;
float srcFmtWidth = srcWidth * srcFormatFactor;
// swich to texture converter frame buffer // swich to texture converter frame buffer
// attach destTexture as color destination // attach destTexture as color destination
@ -374,7 +373,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
glViewport(0, 0, srcWidth, srcHeight); glViewport(0, 0, srcWidth, srcHeight);
PixelShaderCache::EnableShader(s_yuyvToRgbProgram.glprogid); PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();

View File

@ -132,7 +132,7 @@ void TextureMngr::TCacheEntry::SetTextureParameters(TexMode0 &newmode,TexMode1 &
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4) if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
mode.min_filter += 4; // take equivalent forced linear mode.min_filter += 4; // take equivalent forced linear
int filt = newmode.min_filter; int filt = newmode.min_filter;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & (((newmode1.max_lod >> 4) > 0)?7:4)]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & (((newmode1.max_lod >> 5) > 0)?7:4)]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod >> 5); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod >> 5);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod >> 5); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod >> 5);
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (newmode.lod_bias/32.0f)); glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (newmode.lod_bias/32.0f));
@ -261,7 +261,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
TexMode1 &tm1 = bpmem.tex[texstage >> 2].texMode1[texstage & 3]; TexMode1 &tm1 = bpmem.tex[texstage >> 2].texMode1[texstage & 3];
bool UseNativeMips = (tm0.min_filter & 3) && (tm0.min_filter != 8) && g_ActiveConfig.bUseNativeMips; bool UseNativeMips = (tm0.min_filter & 3) && (tm0.min_filter != 8) && g_ActiveConfig.bUseNativeMips;
int maxlevel = ((tm1.max_lod >> 4)); int maxlevel = tm1.max_lod >> 4;//this ir realy strange should be 5 but that breaks some textures
u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address); u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address);
int bsw = TexDecoder_GetBlockWidthInTexels(tex_format) - 1; int bsw = TexDecoder_GetBlockWidthInTexels(tex_format) - 1;
@ -309,7 +309,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
if (!g_ActiveConfig.bSafeTextureCache) if (!g_ActiveConfig.bSafeTextureCache)
hash_value = ((u32 *)ptr)[0]; hash_value = ((u32 *)ptr)[0];
if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash) && (int) FullFormat == entry.fmt)) if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash) && ((int) FullFormat == entry.fmt) && maxlevel <= entry.MipLevels ))
{ {
entry.frameCount = frameCount; entry.frameCount = frameCount;
glEnable(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D); glEnable(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D);
@ -327,7 +327,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
// Let's reload the new texture data into the same texture, // Let's reload the new texture data into the same texture,
// instead of destroying it and having to create a new one. // instead of destroying it and having to create a new one.
// Might speed up movie playback very, very slightly. // Might speed up movie playback very, very slightly.
if (width == entry.w && height == entry.h && (int) FullFormat == entry.fmt) if (width == entry.w && height == entry.h && (int) FullFormat == entry.fmt && maxlevel <= entry.MipLevels )
{ {
glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture); glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
@ -398,6 +398,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
TexLevels = (isPow2 && UseNativeMips && (maxlevel > 0)) ? (int)(log((double)TexLevels)/log((double)2)) + 1 : (isPow2? 0 : 1); TexLevels = (isPow2 && UseNativeMips && (maxlevel > 0)) ? (int)(log((double)TexLevels)/log((double)2)) + 1 : (isPow2? 0 : 1);
if(TexLevels > maxlevel && maxlevel > 0) if(TexLevels > maxlevel && maxlevel > 0)
TexLevels = maxlevel; TexLevels = maxlevel;
entry.MipLevels = maxlevel;
bool GenerateMipmaps = TexLevels > 1 || TexLevels == 0; bool GenerateMipmaps = TexLevels > 1 || TexLevels == 0;
entry.bHaveMipMaps = GenerateMipmaps; entry.bHaveMipMaps = GenerateMipmaps;
int gl_format = 0; int gl_format = 0;
@ -509,27 +510,13 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
{ {
if (expandedWidth != (int)currentWidth) if (expandedWidth != (int)currentWidth)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expandedWidth); glPixelStorei(GL_UNPACK_ROW_LENGTH, expandedWidth);
if(skip_texture_create) glTexImage2D(target, level, gl_iformat, currentWidth, currentHeight, 0, gl_format, gl_type, temp);
{
glTexSubImage2D(target, level,0,0,currentWidth, currentWidth, gl_format, gl_type, temp);
}
else
{
glTexImage2D(target, level, gl_iformat, currentWidth, currentHeight, 0, gl_format, gl_type, temp);
}
if (expandedWidth != (int)currentWidth) if (expandedWidth != (int)currentWidth)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
} }
else else
{ {
if(skip_texture_create) glCompressedTexImage2D(target, level, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, currentWidth, currentHeight, 0, expandedWidth*expandedHeight/2, temp);
{
glCompressedTexSubImage2D(target, level,0,0,currentWidth, currentHeight, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,expandedWidth*expandedHeight/2, temp);
}
else
{
glCompressedTexImage2D(target, level, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, currentWidth, currentHeight, 0, expandedWidth*expandedHeight/2, temp);
}
} }
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
u32 size = (max(mipWidth, bsw) * max(mipHeight, bsh) * bsdepth) >> 1; u32 size = (max(mipWidth, bsw) * max(mipHeight, bsh) * bsdepth) >> 1;
@ -778,7 +765,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
PixelShaderCache::EnableShader(bFromZBuffer ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram()); PixelShaderCache::SetCurrentShader(bFromZBuffer ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
PixelShaderManager::SetColorMatrix(colmat, fConstAdd); // set transformation PixelShaderManager::SetColorMatrix(colmat, fConstAdd); // set transformation
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();

View File

@ -29,7 +29,7 @@ class TextureMngr
public: public:
struct TCacheEntry struct TCacheEntry
{ {
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; } TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0),MipLevels(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
GLuint texture; GLuint texture;
u32 addr; u32 addr;
@ -41,7 +41,7 @@ public:
TexMode1 mode1; // current filter and clamp modes that texture is set to TexMode1 mode1; // current filter and clamp modes that texture is set to
int frameCount; int frameCount;
int w, h, fmt; int w, h, fmt,MipLevels;
float scaleX, scaleY; // Hires texutres need this float scaleX, scaleY; // Hires texutres need this

View File

@ -108,15 +108,13 @@ void VertexShaderCache::Init()
s_displayCompileAlert = true; s_displayCompileAlert = true;
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions); glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
ShaderEnabled = false; SetCurrentShader(0);
CurrentShader = 0;
EnableShader(0);
} }
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
{ {
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter) for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
vshaders.clear(); vshaders.clear();
} }
@ -213,7 +211,7 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
plocal = strstr(plocal + 13, "program.local"); plocal = strstr(plocal + 13, "program.local");
} }
glGenProgramsARB(1, &vs.glprogid); glGenProgramsARB(1, &vs.glprogid);
EnableShader(vs.glprogid); SetCurrentShader(vs.glprogid);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog); glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR(); err = GL_REPORT_ERROR();
@ -233,10 +231,9 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
void VertexShaderCache::DisableShader() void VertexShaderCache::DisableShader()
{ {
CurrentShader = 0;
if (ShaderEnabled) if (ShaderEnabled)
{ {
CurrentShader = 0;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
glDisable(GL_VERTEX_PROGRAM_ARB); glDisable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = false; ShaderEnabled = false;
} }
@ -244,15 +241,6 @@ void VertexShaderCache::DisableShader()
void VertexShaderCache::SetCurrentShader(GLuint Shader) void VertexShaderCache::SetCurrentShader(GLuint Shader)
{
if (ShaderEnabled && CurrentShader != Shader)
{
CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
}
}
void VertexShaderCache::EnableShader(GLuint Shader)
{ {
if (!ShaderEnabled) if (!ShaderEnabled)
{ {
@ -265,5 +253,4 @@ void VertexShaderCache::EnableShader(GLuint Shader)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
} }
} }

View File

@ -65,9 +65,8 @@ public:
static bool CompileVertexShader(VERTEXSHADER& ps, const char* pstrprogram); static bool CompileVertexShader(VERTEXSHADER& ps, const char* pstrprogram);
static void SetCurrentShader(GLuint Shader); static void SetCurrentShader(GLuint Shader);
static void DisableShader(); static void DisableShader();
static void EnableShader(GLuint Shader);
}; };
#endif // _VERTEXSHADERCACHE_H_ #endif // _VERTEXSHADERCACHE_H_