Skip to content

Commit

Permalink
Merge branch 'd3d9-removal'.
Browse files Browse the repository at this point in the history
If you're looking for a reason for the removal, issue 6167 lists more than enough of things that are not supported by D3D9.
  • Loading branch information
neobrain committed Oct 6, 2013
2 parents 7dba383 + ed88cf6 commit a25a0a2
Show file tree
Hide file tree
Showing 50 changed files with 81 additions and 7,412 deletions.
5 changes: 1 addition & 4 deletions Source/Core/DolphinWX/Dolphin.vcxproj
Expand Up @@ -374,9 +374,6 @@ xcopy "$(SolutionDir)..\Externals\msvcrt\$(PlatformName)\*.dll" "$(TargetDir)" /
<ProjectReference Include="..\..\Plugins\Plugin_VideoDX11\Plugin_VideoDX11.vcxproj">
<Project>{9a4c733c-bade-4ac6-b58a-6e274395e90e}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Plugins\Plugin_VideoDX9\Plugin_VideoDX9.vcxproj">
<Project>{dc7d7af4-ce47-49e8-8b63-265cb6233a49}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Plugins\Plugin_VideoOGL\Plugin_VideoOGL.vcxproj">
<Project>{1909cd2d-1707-456f-86ca-0df42a727c99}</Project>
</ProjectReference>
Expand Down Expand Up @@ -408,4 +405,4 @@ xcopy "$(SolutionDir)..\Externals\msvcrt\$(PlatformName)\*.dll" "$(TargetDir)" /
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions Source/Core/DolphinWX/Src/VideoConfigDiag.cpp
Expand Up @@ -67,9 +67,9 @@ void VideoConfigDiag::Event_Close(wxCloseEvent& ev)
}

#if defined(_WIN32)
wxString backend_desc = wxTRANSLATE("Selects what graphics API to use internally.\nDirect3D 9 usually is the fastest one. OpenGL is more accurate though. Direct3D 11 is somewhere between the two.\nNote that the Direct3D backends are only available on Windows.\n\nIf unsure, use Direct3D 11.");
wxString backend_desc = wxTRANSLATE("Selects what graphics API to use internally.\nThe software renderer is only used for debugging, so you'll want to use either Direct3D or OpenGL. Different games will behave differently on each backend, so for best emulation experience it's recommended to try both and chose the one that fits your requirements best.\nNote that the Direct3D backend is not available on old Windows versions.\n\nIf unsure, use Direct3D.");
#else
wxString backend_desc = wxTRANSLATE("Selects what graphics API to use internally.\nDirect3D 9 usually is the fastest one. OpenGL is more accurate though. Direct3D 11 is somewhere between the two.\nNote that the Direct3D backends are only available on Windows.\n\nIf unsure, use OpenGL.");
wxString backend_desc = wxTRANSLATE("Selects what graphics API to use internally.\nThe software renderer is only used for debugging, so unless you have a reason to use it you'll want to select OpenGL here.\n\nIf unsure, use OpenGL.");
#endif
wxString adapter_desc = wxTRANSLATE("Select a hardware adapter to use.\n\nIf unsure, use the first one.");
wxString display_res_desc = wxTRANSLATE("Selects the display resolution used in fullscreen mode.\nThis should always be bigger than or equal to the internal resolution. Performance impact is negligible.\n\nIf unsure, use your desktop resolution.\nIf still unsure, use the highest resolution which works for you.");
Expand Down
71 changes: 24 additions & 47 deletions Source/Core/VideoCommon/Src/PixelShaderGen.cpp
Expand Up @@ -271,20 +271,15 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
for (int i = 0; i < 8; ++i)
out.Write("uniform sampler2D samp%d;\n", i);
}
else
else // D3D
{
// Declare samplers
for (int i = 0; i < 8; ++i)
out.Write("%s samp%d : register(s%d);\n", (ApiType == API_D3D11) ? "sampler" : "uniform sampler2D", i, i);
out.Write("sampler samp%d : register(s%d);\n", i, i);

if (ApiType == API_D3D11)
{
out.Write("\n");
for (int i = 0; i < 8; ++i)
{
out.Write("Texture2D Tex%d : register(t%d);\n", i, i);
}
}
out.Write("\n");
for (int i = 0; i < 8; ++i)
out.Write("Texture2D Tex%d : register(t%d);\n", i, i);
}
out.Write("\n");

Expand Down Expand Up @@ -361,13 +356,13 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
{
static bool warn_once = true;
if (warn_once)
WARN_LOG(VIDEO, "Early z test enabled but not possible to emulate with current configuration. Make sure to use the D3D11 or OpenGL backend and enable fast depth calculations. If this message still shows up your hardware isn't able to emulate the feature properly (a GPU which supports D3D 11.0 / OGL 4.2 is required).");
WARN_LOG(VIDEO, "Early z test enabled but not possible to emulate with current configuration. Make sure to enable fast depth calculations. If this message still shows up your hardware isn't able to emulate the feature properly (a GPU with D3D 11.0 / OGL 4.2 support is required).");
warn_once = false;
}

out.Write("void main()\n{\n");
}
else
else // D3D
{
if (forced_early_z)
{
Expand All @@ -377,27 +372,17 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
{
static bool warn_once = true;
if (warn_once)
WARN_LOG(VIDEO, "Early z test enabled but not possible to emulate with current configuration. Make sure to use the D3D11 or OpenGL backend and enable fast depth calculations. If this message still shows up your hardware isn't able to emulate the feature properly (a GPU which supports D3D 11.0 / OGL 4.2 is required).");
WARN_LOG(VIDEO, "Early z test enabled but not possible to emulate with current configuration. Make sure to enable fast depth calculations. If this message still shows up your hardware isn't able to emulate the feature properly (a GPU with D3D 11.0 / OGL 4.2 support is required).");
warn_once = false;
}

out.Write("void main(\n");
if(ApiType != API_D3D11)
{
out.Write(" out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
per_pixel_depth ? "\n out float depth : DEPTH," : "",
ApiType & API_D3D9_SM20 ? "POSITION" : "VPOS");
}
else
{
out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "",
per_pixel_depth ? "\n out float depth : SV_Depth," : "");
}
out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "",
per_pixel_depth ? "\n out float depth : SV_Depth," : "");

// "centroid" attribute is only supported by D3D11
const char* optCentroid = (ApiType == API_D3D11 ? "centroid" : "");
// Use centroid sampling to make MSAA work properly
const char* optCentroid = "centroid";

out.Write(" in %s float4 colors_0 : COLOR0,\n", optCentroid);
out.Write(" in %s float4 colors_1 : COLOR1", optCentroid);
Expand Down Expand Up @@ -623,10 +608,11 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
WriteAlphaTest<T>(out, uid_data, ApiType, dstAlphaMode, per_pixel_depth);


// TODO: Make more sense out of this comment
// D3D9 doesn't support readback of depth in pixel shader, so we always have to calculate it again.
// This shouldn't be a performance issue as the written depth is usually still from perspective division
// but this isn't true for z-textures, so there will be depth issues between enabled and disabled z-textures fragments
if ((ApiType == API_OPENGL || ApiType == API_D3D11) && g_ActiveConfig.bFastDepthCalc)
if (g_ActiveConfig.bFastDepthCalc)
out.Write("float zCoord = rawpos.z;\n");
else
{
Expand Down Expand Up @@ -682,18 +668,10 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{
out.SetConstantsUsed(C_ALPHA, C_ALPHA);
if(ApiType & API_D3D9)
{
// alpha component must be 0 or the shader will not compile (Direct3D 9Ex restriction)
// Colors will be blended against the color from ocol1 in D3D 9...
out.Write("\tocol1 = float4(prev.a, prev.a, prev.a, 0.0);\n");
}
else
{
// Colors will be blended against the alpha from ocol1...
out.Write("\tocol1 = prev;\n");
}
// ...and the alpha from ocol0 will be written to the framebuffer.

// Colors will be blended against the alpha from ocol1 and
// the alpha from ocol0 will be written to the framebuffer.
out.Write("\tocol1 = prev;\n");
out.Write("\tocol0.a = " I_ALPHA"[0].a;\n");
}

Expand Down Expand Up @@ -1127,10 +1105,10 @@ void SampleTexture(T& out, const char *texcoords, const char *texswap, int texma
{
out.SetConstantsUsed(C_TEXDIMS+texmap,C_TEXDIMS+texmap);

if (ApiType == API_D3D11)
if (ApiType == API_D3D)
out.Write("Tex%d.Sample(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", texmap,texmap, texcoords, texmap, texswap);
else
out.Write("%s(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", ApiType == API_OPENGL ? "texture" : "tex2D", texmap, texcoords, texmap, texswap);
else // OGL
out.Write("texture(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", texmap, texcoords, texmap, texswap);
}

static const char *tevAlphaFuncsTable[] =
Expand Down Expand Up @@ -1164,7 +1142,6 @@ static inline void WriteAlphaTest(T& out, pixel_shader_uid_data& uid_data, API_T

out.SetConstantsUsed(C_ALPHA, C_ALPHA);

// using discard then return works the same in cg and dx9 but not in dx11
out.Write("\tif(!( ");

uid_data.alpha_test_comp0 = bpmem.alpha_test.comp0;
Expand Down Expand Up @@ -1198,14 +1175,14 @@ static inline void WriteAlphaTest(T& out, pixel_shader_uid_data& uid_data, API_T
// It seems to be less buggy than not to update the depth buffer if alpha test fails,
// but both ways wouldn't be accurate.

// OpenGL 4.2 has a flag which allows the driver to still update the depth buffer
// OpenGL 4.2 has a flag which allows the driver to still update the depth buffer
// if alpha test fails. The driver doesn't have to, but I assume they all do because
// it's the much faster code path for the GPU.
uid_data.alpha_test_use_zcomploc_hack = bpmem.UseEarlyDepthTest() && bpmem.zmode.updateenable && !g_ActiveConfig.backend_info.bSupportsEarlyZ;
if (!uid_data.alpha_test_use_zcomploc_hack)
{
out.Write("\t\tdiscard;\n");
if (ApiType != API_D3D11)
if (ApiType != API_D3D)
out.Write("\t\treturn;\n");
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Core/VideoCommon/Src/TextureCacheBase.cpp
Expand Up @@ -481,8 +481,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
// Sometimes, we can get around recreating a texture if only the number of mip levels changes
// e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
// Thus, we don't update this member for every Load, but just whenever the texture gets recreated
// TODO: D3D9 doesn't support min_lod. We should add a workaround for that here!


// TODO: This is the wrong value. We should be storing the number of levels our actual texture has.
// But that will currently make the above "existing entry" tests fail as "texLevels" is not calculated until after.
// Currently, we might try to reuse a texture which appears to have more levels than actual, maybe..
Expand Down
78 changes: 22 additions & 56 deletions Source/Core/VideoCommon/Src/TextureConversionShader.cpp
Expand Up @@ -83,38 +83,22 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
{
WRITE(p, "#define samp0 samp9\n");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
{
WRITE(p,"uniform sampler samp0 : register(s0);\n");
}
else
{
WRITE(p,"sampler samp0 : register(s0);\n");
WRITE(p, "Texture2D Tex0 : register(t0);\n");
}

if (ApiType == API_OPENGL)
{
WRITE(p, " out vec4 ocol0;\n");
WRITE(p, " VARYIN float2 uv0;\n");
WRITE(p, "void main()\n");
}
else
else // D3D
{
WRITE(p,"sampler samp0 : register(s0);\n");
WRITE(p, "Texture2D Tex0 : register(t0);\n");

WRITE(p,"void main(\n");
if (ApiType != API_D3D11)
{
WRITE(p," out float4 ocol0 : COLOR0,\n");
}
else
{
WRITE(p," out float4 ocol0 : SV_Target,\n");
}
WRITE(p," out float4 ocol0 : SV_Target,\n");
WRITE(p," in float2 uv0 : TEXCOORD0)\n");
}

WRITE(p, "{\n"
WRITE(p, "{\n"
" float2 sampleUv;\n"
" float2 uv1 = floor(uv0);\n");

Expand Down Expand Up @@ -142,15 +126,15 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)

if (ApiType != API_OPENGL)
{
WRITE(p, " sampleUv = sampleUv + float2(0.0,1.0);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv + float2(0.0,1.0);\n"); // still need to determine the reason for this
WRITE(p, " sampleUv = sampleUv / " I_COLORS"[0].zw;\n");
}
}

// block dimensions : widthStride, heightStride
// block dimensions : widthStride, heightStride
// texture dims : width, height, x offset, y offset
void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
{
{
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
Expand All @@ -164,39 +148,23 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
{
WRITE(p, "#define samp0 samp9\n");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
{
WRITE(p,"uniform sampler samp0 : register(s0);\n");
}
else
{
WRITE(p,"sampler samp0 : register(s0);\n");
WRITE(p, "Texture2D Tex0 : register(t0);\n");
}

if (ApiType == API_OPENGL)
{
WRITE(p, " out float4 ocol0;\n");
WRITE(p, " VARYIN float2 uv0;\n");
WRITE(p, "void main()\n");
}
else
{
WRITE(p,"sampler samp0 : register(s0);\n");
WRITE(p, "Texture2D Tex0 : register(t0);\n");

WRITE(p,"void main(\n");
if(ApiType != API_D3D11)
{
WRITE(p," out float4 ocol0 : COLOR0,\n");
}
else
{
WRITE(p," out float4 ocol0 : SV_Target,\n");
}
WRITE(p," out float4 ocol0 : SV_Target,\n");
WRITE(p," in float2 uv0 : TEXCOORD0)\n");
}


WRITE(p, "{\n"
WRITE(p, "{\n"
" float2 sampleUv;\n"
" float2 uv1 = floor(uv0);\n");

Expand Down Expand Up @@ -232,18 +200,16 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYPE ApiType)
{
const char* texSampleOpName;
if (ApiType & API_D3D9)
texSampleOpName = "tex2D";
else if (ApiType == API_D3D11)
if (ApiType == API_D3D)
texSampleOpName = "tex0.Sample";
else
else // OGL
texSampleOpName = "texture2DRect";

// the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX.
const char* texSampleIncrementUnit;
if (ApiType != API_OPENGL)
if (ApiType == API_D3D)
texSampleIncrementUnit = I_COLORS"[0].x / " I_COLORS"[0].z";
else
else // OGL
texSampleIncrementUnit = I_COLORS"[0].x";

WRITE(p, " %s = %s(samp0, sampleUv + float2(%d.0 * (%s), 0.0)).%s;\n",
Expand Down Expand Up @@ -296,7 +262,7 @@ void WriteEncoderEnd(char* p, API_TYPE ApiType)
void WriteI8Encoder(char* p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_I8, ApiType);
WRITE(p, " float3 texSample;\n");
WRITE(p, " float3 texSample;\n");

WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.b");
Expand Down Expand Up @@ -430,7 +396,7 @@ void WriteRGB565Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n");
WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\n");
WRITE(p, " float2 texBs = float2(texSample0.b, texSample1.b);\n");

WriteToBitDepth(p, 6, "texGs", "float2 gInt");
WRITE(p, " float2 gUpper = floor(gInt / 8.0);\n");
WRITE(p, " float2 gLower = gInt - gUpper * 8.0;\n");
Expand Down Expand Up @@ -888,12 +854,12 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
break;
default:
PanicAlert("Unknown texture copy format: 0x%x\n", format);
break;
break;
}

if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!");

#ifndef ANDROID
uselocale(old_locale); // restore locale
freelocale(locale);
Expand Down

0 comments on commit a25a0a2

Please sign in to comment.