Merge pull request #6851 from unknownbrackets/d3d9

Use PS 2.0 and VS 2.0 on Direct3D 9
This commit is contained in:
Henrik Rydgård
2014-09-07 10:00:12 +02:00
5 changed files with 33 additions and 14 deletions
+2 -1
View File
@@ -127,6 +127,7 @@ namespace DX9 {
// And an initial clear. We don't clear per frame as the games are supposed to handle that
// by themselves.
ClearBuffer();
// TODO: Check / use D3DCAPS2_DYNAMICTEXTURES?
pD3Ddevice->CreateTexture(512, 272, 1, 0, D3DFMT(D3DFMT_A8R8G8B8), D3DPOOL_MANAGED, &drawPixelsTex_, NULL);
useBufferedRendering_ = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
}
@@ -156,7 +157,7 @@ namespace DX9 {
u8 * convBuf = NULL;
D3DLOCKED_RECT rect;
drawPixelsTex_->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE);
drawPixelsTex_->LockRect(0, &rect, NULL, 0);
convBuf = (u8*)rect.pBits;
+2 -2
View File
@@ -232,7 +232,7 @@ void GenerateFragmentShaderDX9(char *buffer) {
WRITE(p, " float3 v_color1: COLOR1; \n");
}
if (enableFog) {
WRITE(p, "float v_fogdepth:FOG;\n");
WRITE(p, "float2 v_fogdepth: TEXCOORD1;\n");
}
WRITE(p, " }; \n");
WRITE(p, " \n");
@@ -328,7 +328,7 @@ void GenerateFragmentShaderDX9(char *buffer) {
}
if (enableFog) {
WRITE(p, " float fogCoef = clamp(In.v_fogdepth, 0.0, 1.0);\n");
WRITE(p, " float fogCoef = clamp(In.v_fogdepth.x, 0.0, 1.0);\n");
WRITE(p, " return lerp(float4(u_fogcolor, v.a), v, fogCoef);\n");
} else {
WRITE(p, " return v;\n");
+24 -9
View File
@@ -56,6 +56,7 @@ void ComputeVertexShaderIDDX9(VertexShaderIDDX9 *id, u32 vertType, int prim, boo
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
bool hasNormal = (vertType & GE_VTYPE_NRM_MASK) != 0;
bool hasTexcoord = (vertType & GE_VTYPE_TC_MASK) != 0;
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
@@ -105,6 +106,7 @@ void ComputeVertexShaderIDDX9(VertexShaderIDDX9 *id, u32 vertType, int prim, boo
id->d[1] |= gstate.isLightingEnabled() << 24;
id->d[1] |= (vertTypeGetWeightMask(vertType) >> GE_VTYPE_WEIGHT_SHIFT) << 25;
id->d[1] |= gstate.areNormalsReversed() << 26;
id->d[1] |= (hasTexcoord & 1) << 27;
}
}
@@ -137,6 +139,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0 || !useHWTransform;
bool hasNormal = (vertType & GE_VTYPE_NRM_MASK) != 0 && useHWTransform;
bool hasTexcoord = (vertType & GE_VTYPE_TC_MASK) != 0 || !useHWTransform;
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
bool throughmode = (vertType & GE_VTYPE_THROUGH_MASK) != 0;
bool flipV = gstate_c.flipTexture;
@@ -228,7 +231,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
if (vertTypeGetWeightMask(vertType) != GE_VTYPE_WEIGHT_NONE) {
WRITE(p, "%s", boneWeightAttrDecl[TranslateNumBonesDX9(vertTypeGetNumBoneWeights(vertType))]);
}
if (doTexture) {
if (doTexture && hasTexcoord) {
if (doTextureProjection)
WRITE(p, " float2 texcoord: TEXCOORD0; \n");
else
@@ -270,7 +273,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
WRITE(p, " float3 v_color1 : COLOR1; \n");
if (enableFog) {
WRITE(p, "float v_fogdepth:FOG;\n");
WRITE(p, "float2 v_fogdepth: TEXCOORD1;\n");
}
WRITE(p, " }; \n");
WRITE(p, " \n");
@@ -292,7 +295,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
WRITE(p, " Out.v_color1 = In.vec3(0.0);\n");
}
if (enableFog) {
WRITE(p, " Out.v_fogdepth = In.position.w;\n");
WRITE(p, " Out.v_fogdepth.x = In.position.w;\n");
}
if (gstate.isModeThrough()) {
WRITE(p, " Out.gl_Position = mul(float4(In.position.xyz, 1.0), u_proj_through);\n");
@@ -521,9 +524,17 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
case GE_TEXMAP_TEXTURE_COORDS: // Scale-offset. Easy.
case GE_TEXMAP_UNKNOWN: // Not sure what this is, but Riviera uses it. Treating as coords works.
if (prescale) {
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
if (hasTexcoord) {
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
} else {
WRITE(p, " Out.v_texcoord = float2(0.0);\n");
}
} else {
WRITE(p, " Out.v_texcoord = In.texcoord * u_uvscaleoffset.xy + u_uvscaleoffset.zw;\n");
if (hasTexcoord) {
WRITE(p, " Out.v_texcoord = In.texcoord * u_uvscaleoffset.xy + u_uvscaleoffset.zw;\n");
} else {
WRITE(p, " Out.v_texcoord = u_uvscaleoffset.zw;\n");
}
}
break;
@@ -536,9 +547,13 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
break;
case GE_PROJMAP_UV: // Use unscaled UV as source
{
static const char *rescaleuv[4] = {"", " * 1.9921875", " * 1.999969482421875", ""}; // 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f};
const char *factor = rescaleuv[(vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT];
temp_tc = StringFromFormat("float4(In.texcoord.xy %s, 0.0, 1.0)", factor);
if (hasTexcoord) {
static const char *rescaleuv[4] = {"", " * 1.9921875", " * 1.999969482421875", ""}; // 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f};
const char *factor = rescaleuv[(vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT];
temp_tc = StringFromFormat("float4(In.texcoord.xy %s, 0.0, 1.0)", factor);
} else {
temp_tc = "float4(0.0, 0.0, 0.0, 1.0)";
}
}
break;
case GE_PROJMAP_NORMALIZED_NORMAL: // Use normalized transformed normal as source
@@ -574,7 +589,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
// Compute fogdepth
if (enableFog)
WRITE(p, " Out.v_fogdepth = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n");
WRITE(p, " Out.v_fogdepth.x = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n");
}
+3
View File
@@ -323,6 +323,9 @@ private:
class CullMode {
DWORD cull;
public:
CullMode() : cull (D3DCULL_NONE) {
}
inline void set(int wantcull, int cullmode) {
DWORD newcull;
if (!wantcull) {
+2 -2
View File
@@ -79,7 +79,7 @@ bool CompilePixelShader(const char * code, LPDIRECT3DPIXELSHADER9 * pShader, LPD
NULL,
NULL,
"main",
"ps_3_0",
"ps_2_0",
0,
&pShaderCode,
&pErrorMsg,
@@ -115,7 +115,7 @@ bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, L
NULL,
NULL,
"main",
"vs_3_0",
"vs_2_0",
0,
&pShaderCode,
&pErrorMsg,