AbstractPipeline.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <cstddef>
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include "Common/CommonTypes.h"
  9. #include "VideoCommon/RenderState.h"
  10. #include "VideoCommon/TextureConfig.h"
  11. class AbstractShader;
  12. class NativeVertexFormat;
  13. // We use three pipeline usages:
  14. // - GX
  15. // - Per-stage UBO (VS/GS/PS, VS constants accessible from PS)
  16. // - 8 combined image samplers (accessible from PS)
  17. // - 1 SSBO, accessible from PS if bounding box is enabled
  18. // - GX Uber
  19. // - Same as GX, plus one VS SSBO for vertices if dynamic vertex loading is enabled
  20. // - Utility
  21. // - Single UBO, accessible from all stages [set=0, binding=1]
  22. // - 8 combined image samplers (accessible from PS) [set=1, binding=0-7]
  23. // - 1 texel buffer, accessible from PS [set=2, binding=0]
  24. // - Compute
  25. // - 1 uniform buffer [set=0, binding=1]
  26. // - 8 combined image samplers [set=1, binding=0-7]
  27. // - 1 texel buffer [set=2, binding=0]
  28. // - 1 storage image [set=3, binding=0]
  29. enum class AbstractPipelineUsage
  30. {
  31. GX,
  32. GXUber,
  33. Utility
  34. };
  35. struct AbstractPipelineConfig
  36. {
  37. const NativeVertexFormat* vertex_format = nullptr;
  38. const AbstractShader* vertex_shader = nullptr;
  39. const AbstractShader* geometry_shader = nullptr;
  40. const AbstractShader* pixel_shader = nullptr;
  41. RasterizationState rasterization_state;
  42. DepthState depth_state;
  43. BlendingState blending_state;
  44. FramebufferState framebuffer_state;
  45. AbstractPipelineUsage usage = AbstractPipelineUsage::GX;
  46. bool operator==(const AbstractPipelineConfig& rhs) const
  47. {
  48. return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
  49. rasterization_state.hex, depth_state.hex, blending_state.hex,
  50. framebuffer_state.hex, usage) ==
  51. std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
  52. rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
  53. rhs.framebuffer_state.hex, rhs.usage);
  54. }
  55. bool operator<(const AbstractPipelineConfig& rhs) const
  56. {
  57. return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
  58. rasterization_state.hex, depth_state.hex, blending_state.hex,
  59. framebuffer_state.hex, usage) <
  60. std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
  61. rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
  62. rhs.framebuffer_state.hex, rhs.usage);
  63. }
  64. };
  65. class AbstractPipeline
  66. {
  67. public:
  68. AbstractPipeline() = default;
  69. explicit AbstractPipeline(const AbstractPipelineConfig& config) : m_config(config) {}
  70. virtual ~AbstractPipeline() = default;
  71. AbstractPipelineConfig m_config;
  72. // "Cache data" can be used to assist a driver with creating pipelines by using previously
  73. // compiled shader ISA. The abstract shaders and creation struct are still required to create
  74. // pipeline objects, the cache is optionally used by the driver to speed up compilation.
  75. using CacheData = std::vector<u8>;
  76. virtual CacheData GetCacheData() const { return {}; }
  77. };