From 3d9dfad6a229f03948620b97f7e3b48e80784b3c Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 17 Dec 2014 03:05:23 +0100 Subject: [PATCH] D3D: Set the geometry shader before every draw call. And refactor the VertexManager draw call. --- Source/Core/VideoBackends/D3D/D3DUtil.cpp | 1 + .../VideoBackends/D3D/PSTextureEncoder.cpp | 1 + Source/Core/VideoBackends/D3D/Render.cpp | 5 +- .../Core/VideoBackends/D3D/VertexManager.cpp | 53 ++++++------------- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 1 + 5 files changed, 22 insertions(+), 39 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DUtil.cpp b/Source/Core/VideoBackends/D3D/D3DUtil.cpp index 50eac8665b..ad9acc809f 100644 --- a/Source/Core/VideoBackends/D3D/D3DUtil.cpp +++ b/Source/Core/VideoBackends/D3D/D3DUtil.cpp @@ -350,6 +350,7 @@ int CD3DFont::DrawTextScaled(float x, float y, float size, float spacing, u32 dw D3D::stateman->SetPixelShader(m_pshader); D3D::stateman->SetVertexShader(m_vshader); + D3D::stateman->SetGeometryShader(nullptr); D3D::stateman->SetInputLayout(m_InputLayout); D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp index fcc40cc9e5..0ca9ee2211 100644 --- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp @@ -1084,6 +1084,7 @@ size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat, #endif { D3D::stateman->SetVertexShader(m_vShader); + D3D::stateman->SetGeometryShader(nullptr); D3D::stateman->PushBlendState(m_efbEncodeBlendState); D3D::stateman->PushDepthState(m_efbEncodeDepthState); diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 840725fb53..3c2712fbf7 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -1105,13 +1105,14 @@ void Renderer::ApplyState(bool bUseDstAlpha) } ID3D11Buffer* vertexConstants = VertexShaderCache::GetConstantBuffer(); - ID3D11Buffer* pixelConstants = PixelShaderCache::GetConstantBuffer(); - D3D::stateman->SetPixelConstants(pixelConstants, g_ActiveConfig.bEnablePixelLighting ? vertexConstants : nullptr); + D3D::stateman->SetPixelConstants(PixelShaderCache::GetConstantBuffer(), g_ActiveConfig.bEnablePixelLighting ? vertexConstants : nullptr); D3D::stateman->SetVertexConstants(vertexConstants); + D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer()); D3D::stateman->SetPixelShader(PixelShaderCache::GetActiveShader()); D3D::stateman->SetVertexShader(VertexShaderCache::GetActiveShader()); + D3D::stateman->SetGeometryShader(GeometryShaderCache::GetActiveShader()); } void Renderer::RestoreState() diff --git a/Source/Core/VideoBackends/D3D/VertexManager.cpp b/Source/Core/VideoBackends/D3D/VertexManager.cpp index f51319bb73..5a15ca2a0b 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/VertexManager.cpp @@ -126,49 +126,28 @@ void VertexManager::Draw(u32 stride) u32 baseVertex = m_vertexDrawOffset / stride; u32 startIndex = m_indexDrawOffset / sizeof(u16); - if (current_primitive_type == PRIMITIVE_TRIANGLES) + switch (current_primitive_type) { - D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); - D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer()); - D3D::stateman->SetGeometryShader(GeometryShaderCache::GetActiveShader()); - - D3D::stateman->Apply(); - D3D::context->DrawIndexed(indices, startIndex, baseVertex); - - INCSTAT(stats.thisFrame.numDrawCalls); - - D3D::stateman->SetGeometryShader(nullptr); + case PRIMITIVE_POINTS: + D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); + ((DX11::Renderer*)g_renderer)->ApplyCullDisable(); + break; + case PRIMITIVE_LINES: + D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); + ((DX11::Renderer*)g_renderer)->ApplyCullDisable(); + break; + case PRIMITIVE_TRIANGLES: + D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + break; } - else if (current_primitive_type == PRIMITIVE_LINES) - { - ((DX11::Renderer*)g_renderer)->ApplyCullDisable(); - D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); - D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer()); - D3D::stateman->SetGeometryShader(GeometryShaderCache::GetActiveShader()); - D3D::stateman->Apply(); - D3D::context->DrawIndexed(indices, startIndex, baseVertex); + D3D::stateman->Apply(); + D3D::context->DrawIndexed(indices, startIndex, baseVertex); - INCSTAT(stats.thisFrame.numDrawCalls); + INCSTAT(stats.thisFrame.numDrawCalls); - D3D::stateman->SetGeometryShader(nullptr); + if (current_primitive_type != PRIMITIVE_TRIANGLES) ((DX11::Renderer*)g_renderer)->RestoreCull(); - } - else //if (current_primitive_type == PRIMITIVE_POINTS) - { - ((DX11::Renderer*)g_renderer)->ApplyCullDisable(); - D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); - D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer()); - D3D::stateman->SetGeometryShader(GeometryShaderCache::GetActiveShader()); - - D3D::stateman->Apply(); - D3D::context->DrawIndexed(indices, startIndex, baseVertex); - - INCSTAT(stats.thisFrame.numDrawCalls); - - D3D::stateman->SetGeometryShader(nullptr); - ((DX11::Renderer*)g_renderer)->RestoreCull(); - } } void VertexManager::vFlush(bool useDstAlpha) diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index fb56363e31..955fb38bc8 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -282,6 +282,7 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::stateman->SetPixelShader(m_pShader); D3D::stateman->SetVertexShader(m_vShader); + D3D::stateman->SetGeometryShader(nullptr); D3D::stateman->PushBlendState(m_xfbEncodeBlendState); D3D::stateman->PushDepthState(m_xfbEncodeDepthState);