2017-09-08 09:42:56 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-09-08 09:42:56 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include "VideoBackends/D3D/DXPipeline.h"
|
|
|
|
|
2017-09-08 09:42:56 +00:00
|
|
|
#include "Common/Assert.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
2023-01-29 10:58:32 +00:00
|
|
|
#include "VideoBackends/D3D/D3DGfx.h"
|
2017-09-08 09:42:56 +00:00
|
|
|
#include "VideoBackends/D3D/D3DState.h"
|
2020-09-15 12:50:34 +00:00
|
|
|
#include "VideoBackends/D3D/D3DVertexManager.h"
|
2017-09-08 09:42:56 +00:00
|
|
|
#include "VideoBackends/D3D/DXShader.h"
|
|
|
|
#include "VideoBackends/D3D/DXTexture.h"
|
2019-12-22 18:40:40 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2017-09-08 09:42:56 +00:00
|
|
|
|
|
|
|
namespace DX11
|
|
|
|
{
|
2023-01-28 00:28:52 +00:00
|
|
|
DXPipeline::DXPipeline(const AbstractPipelineConfig& config, ID3D11InputLayout* input_layout,
|
|
|
|
ID3D11VertexShader* vertex_shader, ID3D11GeometryShader* geometry_shader,
|
|
|
|
ID3D11PixelShader* pixel_shader, ID3D11RasterizerState* rasterizer_state,
|
2017-09-08 09:42:56 +00:00
|
|
|
ID3D11DepthStencilState* depth_state, ID3D11BlendState* blend_state,
|
2019-02-15 01:59:50 +00:00
|
|
|
D3D11_PRIMITIVE_TOPOLOGY primitive_topology, bool use_logic_op)
|
2023-01-28 00:28:52 +00:00
|
|
|
: AbstractPipeline(config), m_input_layout(input_layout), m_vertex_shader(vertex_shader),
|
2017-09-08 09:42:56 +00:00
|
|
|
m_geometry_shader(geometry_shader), m_pixel_shader(pixel_shader),
|
|
|
|
m_rasterizer_state(rasterizer_state), m_depth_state(depth_state), m_blend_state(blend_state),
|
2019-02-15 01:59:50 +00:00
|
|
|
m_primitive_topology(primitive_topology), m_use_logic_op(use_logic_op)
|
2017-09-08 09:42:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
DXPipeline::~DXPipeline() = default;
|
2017-09-08 09:42:56 +00:00
|
|
|
|
|
|
|
std::unique_ptr<DXPipeline> DXPipeline::Create(const AbstractPipelineConfig& config)
|
|
|
|
{
|
2023-01-29 10:58:32 +00:00
|
|
|
StateCache& state_cache = static_cast<Gfx*>(g_gfx.get())->GetStateCache();
|
2017-09-08 09:42:56 +00:00
|
|
|
ID3D11RasterizerState* rasterizer_state = state_cache.Get(config.rasterization_state);
|
|
|
|
ID3D11DepthStencilState* depth_state = state_cache.Get(config.depth_state);
|
|
|
|
ID3D11BlendState* blend_state = state_cache.Get(config.blending_state);
|
|
|
|
D3D11_PRIMITIVE_TOPOLOGY primitive_topology =
|
|
|
|
StateCache::GetPrimitiveTopology(config.rasterization_state.primitive);
|
|
|
|
if (!rasterizer_state || !depth_state || !blend_state)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const DXShader* vertex_shader = static_cast<const DXShader*>(config.vertex_shader);
|
|
|
|
const DXShader* geometry_shader = static_cast<const DXShader*>(config.geometry_shader);
|
|
|
|
const DXShader* pixel_shader = static_cast<const DXShader*>(config.pixel_shader);
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(vertex_shader != nullptr && pixel_shader != nullptr);
|
2017-09-08 09:42:56 +00:00
|
|
|
|
|
|
|
ID3D11InputLayout* input_layout =
|
2019-02-15 01:59:50 +00:00
|
|
|
config.vertex_format ?
|
|
|
|
const_cast<D3DVertexFormat*>(static_cast<const D3DVertexFormat*>(config.vertex_format))
|
|
|
|
->GetInputLayout(vertex_shader->GetByteCode().data(),
|
|
|
|
vertex_shader->GetByteCode().size()) :
|
|
|
|
nullptr;
|
2017-09-08 09:42:56 +00:00
|
|
|
|
2019-08-02 08:43:28 +00:00
|
|
|
// Only use the integer RTV if logic op is supported, and enabled.
|
|
|
|
const bool use_logic_op =
|
|
|
|
config.blending_state.logicopenable && g_ActiveConfig.backend_info.bSupportsLogicOp;
|
|
|
|
|
2023-01-28 00:28:52 +00:00
|
|
|
return std::make_unique<DXPipeline>(config, input_layout, vertex_shader->GetD3DVertexShader(),
|
2019-08-02 08:43:28 +00:00
|
|
|
geometry_shader ? geometry_shader->GetD3DGeometryShader() :
|
|
|
|
nullptr,
|
|
|
|
pixel_shader->GetD3DPixelShader(), rasterizer_state,
|
|
|
|
depth_state, blend_state, primitive_topology, use_logic_op);
|
2017-09-08 09:42:56 +00:00
|
|
|
}
|
|
|
|
} // namespace DX11
|