DXPipeline.cpp 3.2 KB

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