From 4f2fb10347a52be612fb79a32f954168451e99da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 12 Feb 2017 16:14:14 +0100 Subject: [PATCH] Further D3D11 fixes --- GPU/Common/ShaderUniforms.h | 2 +- GPU/Common/SoftwareTransformCommon.cpp | 2 +- GPU/D3D11/DrawEngineD3D11.cpp | 23 +++++++++++------------ GPU/Directx9/PixelShaderGeneratorDX9.cpp | 2 +- GPU/Directx9/VertexShaderGeneratorDX9.cpp | 9 +++++++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/GPU/Common/ShaderUniforms.h b/GPU/Common/ShaderUniforms.h index 17ec2955bb..df3d0e495e 100644 --- a/GPU/Common/ShaderUniforms.h +++ b/GPU/Common/ShaderUniforms.h @@ -69,7 +69,7 @@ R"( float4x4 u_proj; float4x4 u_tex; float4 u_uvscaleoffset; float4 u_depthRange; - float3 u_fogcoef; + float3 u_fogcoef_stencilreplace; float4 u_matambientalpha; float3 u_fogcolor; float3 u_texenv; diff --git a/GPU/Common/SoftwareTransformCommon.cpp b/GPU/Common/SoftwareTransformCommon.cpp index 5d9c2cf4c7..bab715e13f 100644 --- a/GPU/Common/SoftwareTransformCommon.cpp +++ b/GPU/Common/SoftwareTransformCommon.cpp @@ -502,7 +502,7 @@ void SoftwareTransform( const u16 *indsIn = (const u16 *)inds; u16 *newInds = inds + vertexCount; u16 *indsOut = newInds; - maxIndex = 4 * vertexCount; + maxIndex = 4 * (vertexCount / 2); for (int i = 0; i < vertexCount; i += 2) { const TransformedVertex &transVtxTL = transformed[indsIn[i + 0]]; const TransformedVertex &transVtxBR = transformed[indsIn[i + 1]]; diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index a85241956b..4b994a6c61 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -40,13 +40,13 @@ #include "GPU/D3D11/ShaderManagerD3D11.h" #include "GPU/D3D11/GPU_D3D11.h" -const D3D11_PRIMITIVE_TOPOLOGY glprim[8] = { +const D3D11_PRIMITIVE_TOPOLOGY d3d11prim[8] = { D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, D3D11_PRIMITIVE_TOPOLOGY_LINELIST, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, - D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, // Fans not supported + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Fans not supported D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Need expansion - though we could do it with geom shaders in most cases }; @@ -104,7 +104,9 @@ DrawEngineD3D11::DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, tessDataTransfer = new TessellationDataTransferD3D11(); - // Vertex pushing buffers. + // Vertex pushing buffers. For uniforms we use short DISCARD buffers, but we could use + // this kind of buffer there as well with D3D11.1. We might be able to use the same buffer + // for both vertices and indices, and possibly all three data types. pushVerts_ = new PushBufferD3D11(device, VERTEX_PUSH_SIZE, D3D11_BIND_VERTEX_BUFFER); pushInds_ = new PushBufferD3D11(device, INDEX_PUSH_SIZE, D3D11_BIND_INDEX_BUFFER); } @@ -113,10 +115,8 @@ DrawEngineD3D11::~DrawEngineD3D11() { delete pushVerts_; delete pushInds_; - for (auto decl = inputLayoutMap_.begin(); decl != inputLayoutMap_.end(); ++decl) { - if (decl->second) { - decl->second->Release(); - } + for (auto &decl : inputLayoutMap_) { + decl.second->Release(); } for (auto &depth : depthStencilCache_) { depth.second->Release(); @@ -559,12 +559,10 @@ void DrawEngineD3D11::BeginFrame() { } VertexArrayInfoD3D11::~VertexArrayInfoD3D11() { - if (vbo) { + if (vbo) vbo->Release(); - } - if (ebo) { + if (ebo) ebo->Release(); - } } static uint32_t SwapRB(uint32_t c) { @@ -775,7 +773,7 @@ rotateVBO: context_->IASetInputLayout(inputLayout); UINT stride = dec_->GetDecVtxFmt().stride; - context_->IASetPrimitiveTopology(glprim[prim]); + context_->IASetPrimitiveTopology(d3d11prim[prim]); if (!vb_) { // Push! UINT vOffset; @@ -869,6 +867,7 @@ rotateVBO: layout = iter->second; } context_->IASetInputLayout(layout); + context_->IASetPrimitiveTopology(d3d11prim[prim]); UINT stride = sizeof(TransformedVertex); UINT vOffset = 0; diff --git a/GPU/Directx9/PixelShaderGeneratorDX9.cpp b/GPU/Directx9/PixelShaderGeneratorDX9.cpp index 382bf440c1..b099d7a0e7 100644 --- a/GPU/Directx9/PixelShaderGeneratorDX9.cpp +++ b/GPU/Directx9/PixelShaderGeneratorDX9.cpp @@ -341,7 +341,7 @@ bool GenerateFragmentShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage if (stencilToAlpha != REPLACE_ALPHA_NO) { switch (replaceAlphaWithStencilType) { case STENCIL_VALUE_UNIFORM: - replacedAlpha = "u_stencilReplaceValue"; + replacedAlpha = lang == HLSL_D3D11 ? "u_fogcoef_stencilreplace.z" : "u_stencilReplaceValue"; break; case STENCIL_VALUE_ZERO: diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.cpp b/GPU/Directx9/VertexShaderGeneratorDX9.cpp index b9ff0f0dd1..37b2c47645 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.cpp +++ b/GPU/Directx9/VertexShaderGeneratorDX9.cpp @@ -604,8 +604,13 @@ void GenerateVertexShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage l } // Compute fogdepth - if (enableFog) - WRITE(p, " Out.v_fogdepth.x = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n"); + if (enableFog) { + if (lang == HLSL_D3D11) { + WRITE(p, " Out.v_fogdepth.x = (viewPos.z + u_fogcoef_stencilreplace.x) * u_fogcoef_stencilreplace.y;\n"); + } else { + WRITE(p, " Out.v_fogdepth.x = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n"); + } + } } WRITE(p, " return Out;\n");