| 1 | // Copyright 2017 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "VideoBackends/D3D/DXPipeline.h" |
| 5 | |
| 6 | #include "Common/Assert.h" |
| 7 | #include "Common/Logging/Log.h" |
| 8 | |
| 9 | #include "VideoBackends/D3D/D3DBase.h" |
| 10 | #include "VideoBackends/D3D/D3DGfx.h" |
| 11 | #include "VideoBackends/D3D/D3DState.h" |
| 12 | #include "VideoBackends/D3D/D3DVertexManager.h" |
| 13 | #include "VideoBackends/D3D/DXShader.h" |
| 14 | #include "VideoBackends/D3D/DXTexture.h" |
| 15 | #include "VideoCommon/VideoConfig.h" |
| 16 | |
| 17 | namespace DX11 |
| 18 | { |
| 19 | DXPipeline::DXPipeline(const AbstractPipelineConfig& config, ID3D11InputLayout* input_layout, |
| 20 | ID3D11VertexShader* vertex_shader, ID3D11GeometryShader* geometry_shader, |
| 21 | ID3D11PixelShader* pixel_shader, ID3D11RasterizerState* rasterizer_state, |
| 22 | ID3D11DepthStencilState* depth_state, ID3D11BlendState* blend_state, |
| 23 | D3D11_PRIMITIVE_TOPOLOGY primitive_topology, bool use_logic_op) |
| 24 | : AbstractPipeline(config), m_input_layout(input_layout), m_vertex_shader(vertex_shader), |
| 25 | m_geometry_shader(geometry_shader), m_pixel_shader(pixel_shader), |
| 26 | m_rasterizer_state(rasterizer_state), m_depth_state(depth_state), m_blend_state(blend_state), |
| 27 | m_primitive_topology(primitive_topology), m_use_logic_op(use_logic_op) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | DXPipeline::~DXPipeline() = default; |
| 32 | |
| 33 | std::unique_ptr<DXPipeline> DXPipeline::Create(const AbstractPipelineConfig& config) |
| 34 | { |
| 35 | StateCache& state_cache = static_cast<Gfx*>(g_gfx.get())->GetStateCache(); |
| 36 | ID3D11RasterizerState* rasterizer_state = state_cache.Get(config.rasterization_state); |
| 37 | ID3D11DepthStencilState* depth_state = state_cache.Get(config.depth_state); |
| 38 | ID3D11BlendState* blend_state = state_cache.Get(config.blending_state); |
| 39 | D3D11_PRIMITIVE_TOPOLOGY primitive_topology = |
| 40 | StateCache::GetPrimitiveTopology(config.rasterization_state.primitive); |
| 41 | if (!rasterizer_state || !depth_state || !blend_state) |
| 42 | return nullptr; |
| 43 | |
| 44 | const DXShader* vertex_shader = static_cast<const DXShader*>(config.vertex_shader); |
| 45 | const DXShader* geometry_shader = static_cast<const DXShader*>(config.geometry_shader); |
| 46 | const DXShader* pixel_shader = static_cast<const DXShader*>(config.pixel_shader); |
| 47 | ASSERT(vertex_shader != nullptr && pixel_shader != nullptr); |
| 48 | |
| 49 | ID3D11InputLayout* input_layout = |
| 50 | config.vertex_format ? |
| 51 | const_cast<D3DVertexFormat*>(static_cast<const D3DVertexFormat*>(config.vertex_format)) |
| 52 | ->GetInputLayout(vertex_shader->GetByteCode().data(), |
| 53 | vertex_shader->GetByteCode().size()) : |
| 54 | nullptr; |
| 55 | |
| 56 | // Only use the integer RTV if logic op is supported, and enabled. |
| 57 | const bool use_logic_op = |
| 58 | config.blending_state.logic_op_enable && g_backend_info.bSupportsLogicOp; |
| 59 | |
| 60 | return std::make_unique<DXPipeline>(config, input_layout, vertex_shader->GetD3DVertexShader(), |
| 61 | geometry_shader ? geometry_shader->GetD3DGeometryShader() : |
| 62 | nullptr, |
| 63 | pixel_shader->GetD3DPixelShader(), rasterizer_state, |
| 64 | depth_state, blend_state, primitive_topology, use_logic_op); |
| 65 | } |
| 66 | } // namespace DX11 |