diff options
| author | NeoBrainX <NeoBrainX@googlemail.com> | 2010-06-12 15:49:21 +0000 |
|---|---|---|
| committer | NeoBrainX <NeoBrainX@googlemail.com> | 2010-06-12 15:49:21 +0000 |
| commit | a6ebc8234f4e5aef62fb0ccf55dcf83211168896 (patch) | |
| tree | 1ca68e54a11a005eb7f064c3f4a2147366367ad8 /Source/Core/VideoCommon/Src/VertexShaderGen.cpp | |
| parent | f0d178122ed33972360ba9c268b0f814e45e0536 (diff) | |
Preparing stuff for DX11:
- be more strict with the input signature of generated pixel shaders
- replace the D3D parameter with an API_TYPE one, so that we can further distinguish between DX9 and DX11
- for what it's worth dx11 (using vs_4_0) doesn't support D3DCOLORtoUBYTE4; added a workaround for this
- add a "dx9-" prefix to the shader cache files to avoid conflicts with dx11 shaders
Apart from that we're calling CommandProcessor::Shutdown() in main.cpp,Shutdown() now.
Delete all files in User/ShaderCache if you want to save a few KB disk space :P
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5659 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/VideoCommon/Src/VertexShaderGen.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexShaderGen.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index a2a096d0dd..7562c26ced 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -80,7 +80,7 @@ static char text[16384]; char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char *dest, int coloralpha); -const char *GenerateVertexShaderCode(u32 components, bool D3D) +const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) { setlocale(LC_NUMERIC, "C"); // Reset locale for compilation text[sizeof(text) - 1] = 0x7C; // canary @@ -89,6 +89,7 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) _assert_(bpmem.genMode.numtexgens == xfregs.numTexGens); _assert_(bpmem.genMode.numcolchans == xfregs.nNumChans); + bool is_d3d = (api_type == API_D3D9 || api_type == API_D3D11); u32 lightMask = 0; if (xfregs.nNumChans > 0) lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask(); @@ -107,7 +108,7 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) "typedef struct { Light lights[8]; } s_"I_LIGHTS";\n" "typedef struct { float4 C0,C1,C2,C3; } s_"I_MATERIALS";\n" "typedef struct { float4 T0,T1,T2,T3; } s_"I_PROJECTION";\n" - "typedef struct { float4 params; } s_"I_FOGPARAMS";\n"); // a, b, c, b_shift + ); WRITE(p, "struct VS_OUTPUT {\n"); WRITE(p, " float4 pos : POSITION;\n"); @@ -134,7 +135,6 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, "uniform s_"I_LIGHTS" "I_LIGHTS" : register(c%d);\n", C_LIGHTS); WRITE(p, "uniform s_"I_MATERIALS" "I_MATERIALS" : register(c%d);\n", C_MATERIALS); WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION); - WRITE(p, "uniform s_"I_FOGPARAMS" "I_FOGPARAMS" : register(c%d);\n", C_FOGPARAMS); WRITE(p, "VS_OUTPUT main(\n"); @@ -142,13 +142,13 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) if (components & VB_HAS_NRM0) WRITE(p, " float3 rawnorm0 : NORMAL0,\n"); if (components & VB_HAS_NRM1) { - if (D3D) + if (is_d3d) WRITE(p, " float3 rawnorm1 : NORMAL1,\n"); else WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB); } if (components & VB_HAS_NRM2) { - if (D3D) + if (is_d3d) WRITE(p, " float3 rawnorm2 : NORMAL2,\n"); else WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB); @@ -163,7 +163,7 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i); } if (components & VB_HAS_POSMTXIDX) { - if (D3D) + if (is_d3d) { WRITE(p, " float4 blend_indices : BLENDINDICES,\n"); } @@ -175,10 +175,14 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) // transforms if (components & VB_HAS_POSMTXIDX) { - if (D3D) + if (api_type == API_D3D9) { - WRITE(p, "int4 indices = D3DCOLORtoUBYTE4(blend_indices);\n" - "int posmtx = indices.x;\n"); + WRITE(p, "int4 indices = D3DCOLORtoUBYTE4(blend_indices);\n"); + WRITE(p, "int posmtx = indices.x;\n"); + } + else if (api_type == API_D3D11) + { + WRITE(p, "int posmtx = blend_indices.x * 255.0f;\n"); } else { @@ -208,7 +212,6 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, "float3 _norm1 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n"); if (components & VB_HAS_NRM2) WRITE(p, "float3 _norm2 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n"); - } if (!(components & VB_HAS_NRM0)) @@ -326,6 +329,7 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, "}\n"); } + // zero left over channels for (int i = xfregs.nNumChans; i < 2; ++i) WRITE(p, "o.colors[%d] = float4(0.0f,0.0f,0.0f,0.0f);\n", i); @@ -452,11 +456,11 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, "o.tex3.w = o.pos.w;\n"); } - if (D3D) + if (is_d3d) { - WRITE(p, "o.pos.z = o.pos.z + o.pos.w;\n"); - } - else + WRITE(p, "o.pos.z = o.pos.z + o.pos.w;\n"); + } + else { // scale to gl clip space - which is -o.pos.w to o.pos.w, hence the addition. WRITE(p, "o.pos.z = (o.pos.z * 2.0f) + o.pos.w;\n"); @@ -464,6 +468,7 @@ const char *GenerateVertexShaderCode(u32 components, bool D3D) WRITE(p, "return o;\n}\n"); + if (text[sizeof(text) - 1] != 0x7C) PanicAlert("VertexShader generator - buffer too small, canary has been eaten!"); return text; |
