From fc12291806c5f6eb6ba06f0f533d8723808bd129 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Mon, 14 Jun 2010 14:36:01 +0000 Subject: [PATCH] some fixes to my last commit and .... modify shader generator to produce native sm 4.0 code. eliminate compatibility mode in dx11 so now all shader must work much better. please test. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5691 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Common.h | 7 -- Source/Core/Common/Src/LinearDiskCache.cpp | 2 +- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 91 ++++++++++++++++--- Source/Core/VideoCommon/Src/PixelShaderGen.h | 2 +- Source/Core/VideoCommon/Src/VertexShaderGen.h | 2 +- Source/Core/VideoCommon/Src/VideoCommon.h | 7 ++ .../Plugin_VideoDX11/Src/D3DShader.cpp | 2 +- .../Plugin_VideoDX11/Src/PixelShaderCache.cpp | 61 ++++++++----- .../Src/VertexShaderCache.cpp | 33 +++++-- 9 files changed, 149 insertions(+), 58 deletions(-) diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index aba142aefe..80bd3d75e8 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -129,13 +129,6 @@ #endif // WIN32 -typedef enum -{ - API_OPENGL, - API_D3D9, - API_D3D11 -} API_TYPE; - // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index 41bc5ba555..372628d4da 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -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. // 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. -const int version = 5659; +const int version = 5691; LinearDiskCache::LinearDiskCache() : file_(NULL), num_entries_(0) { diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index ae2758c84f..afc1400c3a 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -385,10 +385,18 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_ // Declare samplers if (texture_mask) { - if (ApiType != API_OPENGL) + if (ApiType == API_D3D11) + { + WRITE(p, "sampler "); + } + else if (ApiType == API_D3D9) + { WRITE(p, "uniform sampler "); + } else + { WRITE(p, "uniform samplerRECT "); + } bool bfirst = true; for (int i = 0; i < 8; ++i) { @@ -398,19 +406,57 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_ bfirst = false; } } - WRITE(p, ";\n"); + WRITE(p, ";\n"); + if(ApiType == API_D3D11) + { + bfirst = true; + WRITE(p, "Texture2D "); + for (int i = 0; i < 8; ++i) + { + if (texture_mask & (1< bool IsD3D(); +typedef enum +{ + API_OPENGL, + API_D3D9, + API_D3D11 +} API_TYPE; + #endif // _VIDEOCOMMON_H diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp index 73fdfd83c6..699cdbe982 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp @@ -90,7 +90,7 @@ bool CompilePixelShader(const char* code, unsigned int len, ID3D10Blob** blob) #if defined(_DEBUG) || defined(DEBUGFAST) UINT flags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY|D3D10_SHADER_DEBUG|D3D10_SHADER_WARNINGS_ARE_ERRORS; #else - UINT flags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY|D3D10_SHADER_OPTIMIZATION_LEVEL3|D3D10_SHADER_SKIP_VALIDATION; + UINT flags = D3D10_SHADER_OPTIMIZATION_LEVEL3; #endif HRESULT hr = D3DCompile(code, len, NULL, NULL, NULL, "main", D3D::PixelShaderVersionString(), flags, 0, &shaderBuffer, &errorBuffer); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp index 1dbbb946ca..0b5c9adc83 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp @@ -47,43 +47,46 @@ ID3D11PixelShader* s_ClearProgram = NULL; const char clear_program_code[] = { "void main(\n" - "out float4 ocol0 : COLOR0,\n" - "in float4 pos : POSITION,\n" + "out float4 ocol0 : SV_Target,\n" + "in float4 pos : SV_Position,\n" "in float4 incol0 : COLOR0){\n" "ocol0 = incol0;\n" "}\n" }; const char color_copy_program_code[] = { - "uniform sampler samp0 : register(s0);\n" + "sampler samp0 : register(s0);\n" + "Texture2D Tex0 : register(t0);\n" "void main(\n" - "out float4 ocol0 : COLOR0,\n" - "in float4 pos : POSITION,\n" + "out float4 ocol0 : SV_Target,\n" + "in float4 pos : SV_Position,\n" "in float2 uv0 : TEXCOORD0){\n" - "ocol0 = tex2D(samp0,uv0);\n" + "ocol0 = Tex0.Sample(samp0,uv0);\n" "}\n" }; const char color_matrix_program_code[] = { - "uniform sampler samp0 : register(s0);\n" + "sampler samp0 : register(s0);\n" + "Texture2D Tex0 : register(t0);\n" "uniform float4 cColMatrix[5] : register(c0);\n" "void main(\n" - "out float4 ocol0 : COLOR0,\n" - "in float4 pos : POSITION,\n" + "out float4 ocol0 : SV_Target,\n" + "in float4 pos : SV_Position,\n" " in float2 uv0 : TEXCOORD0){\n" - "float4 texcol = tex2D(samp0,uv0);\n" + "float4 texcol = Tex0.Sample(samp0,uv0);\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "}\n" }; const char depth_matrix_program[] = { - "uniform sampler samp0 : register(s0);\n" + "sampler samp0 : register(s0);\n" + "Texture2D Tex0 : register(t0);\n" "uniform float4 cColMatrix[5] : register(c0);\n" "void main(\n" - "out float4 ocol0 : COLOR0,\n" - " in float4 pos : POSITION,\n" + "out float4 ocol0 : SV_Target,\n" + " in float4 pos : SV_Position,\n" " in float2 uv0 : TEXCOORD0){\n" - "float4 texcol = tex2D(samp0,uv0);\n" + "float4 texcol = Tex0.Sample(samp0,uv0);\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" @@ -125,23 +128,35 @@ unsigned int ps_constant_offset_table[] = { }; void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - D3D::gfxstate->psconstants[ps_constant_offset_table[const_number] ] = f1; - D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+1] = f2; - D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+2] = f3; - D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+3] = f4; - D3D::gfxstate->pscbufchanged = true; + if(D3D::gfxstate->psconstants[ps_constant_offset_table[const_number] ] != f1 + || D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+1] != f2 + || D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+2] != f3 + || D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+3] != f4) + { + D3D::gfxstate->psconstants[ps_constant_offset_table[const_number] ] = f1; + D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+1] = f2; + D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+2] = f3; + D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]+3] = f4; + D3D::gfxstate->pscbufchanged = true; + } } void SetPSConstant4fv(unsigned int const_number, const float* f) { - memcpy(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4); - D3D::gfxstate->pscbufchanged = true; + if(memcmp(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4)) + { + memcpy(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4); + D3D::gfxstate->pscbufchanged = true; + } } void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f) { - memcpy(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count); - D3D::gfxstate->pscbufchanged = true; + if(memcmp(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count)) + { + memcpy(&D3D::gfxstate->psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count); + D3D::gfxstate->pscbufchanged = true; + } } // this class will load the precompiled shaders into our cache diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp index 4f0286b1a5..9de7bb6939 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp @@ -51,17 +51,26 @@ ID3D11InputLayout* VertexShaderCache::GetClearInputLayout() { return ClearLayout unsigned int vs_constant_offset_table[238]; void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number] ] = f1; - D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+1] = f2; - D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+2] = f3; - D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+3] = f4; - D3D::gfxstate->vscbufchanged = true; + if(D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number] ] != f1 + || D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+1] != f2 + || D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+2] != f3 + || D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+3] != f4) + { + D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number] ] = f1; + D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+1] = f2; + D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+2] = f3; + D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]+3] = f4; + D3D::gfxstate->vscbufchanged = true; + } } void SetVSConstant4fv(unsigned int const_number, const float* f) { - memcpy(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4); - D3D::gfxstate->vscbufchanged = true; + if(memcmp(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4)) + { + memcpy(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4); + D3D::gfxstate->vscbufchanged = true; + } } void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float* f) @@ -69,14 +78,18 @@ void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const for (unsigned int i = 0; i < count; i++) { memcpy(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number+i]], f+3*i, sizeof(float)*3); - D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f; + D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f; } + D3D::gfxstate->vscbufchanged = true; } void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f) { - memcpy(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count); - D3D::gfxstate->vscbufchanged = true; + if(memcmp(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count)) + { + memcpy(&D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count); + D3D::gfxstate->vscbufchanged = true; + } } // this class will load the precompiled shaders into our cache