BsVulkanGpuPipelineState.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "BsVulkanResource.h"
  6. #include "BsGpuPipelineState.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Wrapper around a Vulkan graphics pipeline that manages its usage and lifetime. */
  13. class VulkanPipeline : public VulkanResource
  14. {
  15. public:
  16. VulkanPipeline(VulkanResourceManager* owner, VkPipeline pipeline);
  17. ~VulkanPipeline();
  18. /** Returns the internal handle to the Vulkan object. */
  19. VkPipeline getHandle() const { return mPipeline; }
  20. private:
  21. VkPipeline mPipeline;
  22. };
  23. /** Vulkan implementation of a graphics pipeline state. */
  24. class VulkanGraphicsPipelineStateCore : public GraphicsPipelineStateCore
  25. {
  26. public:
  27. ~VulkanGraphicsPipelineStateCore();
  28. /** Checks does the pipeline enable scissor tests. */
  29. bool isScissorEnabled() const { return mScissorEnabled; }
  30. /** Returns the vertex input declaration from the vertex GPU program bound on the pipeline. */
  31. SPtr<VertexDeclarationCore> getInputDeclaration() const { return mVertexDecl; }
  32. /**
  33. * Attempts to find an existing pipeline matching the provided parameters, or creates a new one if one cannot be
  34. * found.
  35. *
  36. * @param[in] deviceIdx Index of the device to retrieve the pipeline for.
  37. * @param[in] framebuffer Framebuffer object that defines the surfaces this pipeline will render to.
  38. * @param[in] readOnlyDepth True if the pipeline is only allowed to read the depth buffer, without writes.
  39. * @param[in] drawOp Type of geometry that will be drawn using the pipeline.
  40. * @param[in] vertexInputState State describing inputs to the vertex program.
  41. * @return Vulkan graphics pipeline object.
  42. *
  43. * @note Thread safe.
  44. */
  45. VulkanPipeline* getPipeline(UINT32 deviceIdx, VulkanFramebuffer* framebuffer, bool readOnlyDepth,
  46. DrawOperationType drawOp, VkPipelineVertexInputStateCreateInfo* vertexInputState);
  47. protected:
  48. friend class VulkanRenderStateCoreManager;
  49. VulkanGraphicsPipelineStateCore(const PIPELINE_STATE_CORE_DESC& desc, GpuDeviceFlags deviceMask);
  50. /** @copydoc GraphicsPipelineStateCore::initialize */
  51. void initialize() override;
  52. /**
  53. * Create a new Vulkan graphics pipeline.
  54. *
  55. * @param[in] deviceIdx Index of the device to create the pipeline for.
  56. * @param[in] framebuffer Framebuffer object that defines the surfaces this pipeline will render to.
  57. * @param[in] readOnlyDepth True if the pipeline is only allowed to read the depth buffer, without writes.
  58. * @param[in] drawOp Type of geometry that will be drawn using the pipeline.
  59. * @param[in] vertexInputState State describing inputs to the vertex program.
  60. * @return Vulkan graphics pipeline object.
  61. *
  62. * @note Thread safe.
  63. */
  64. VulkanPipeline* createPipeline(UINT32 deviceIdx, VulkanFramebuffer* framebuffer, bool readOnlyDepth,
  65. DrawOperationType drawOp, VkPipelineVertexInputStateCreateInfo* vertexInputState);
  66. /** Contains pipeline data specific to a single Vulkan device. */
  67. struct PerDeviceData
  68. {
  69. VulkanDevice* device;
  70. VkPipelineLayout pipelineLayout;
  71. };
  72. VkPipelineShaderStageCreateInfo mShaderStageInfos[5];
  73. VkPipelineInputAssemblyStateCreateInfo mInputAssemblyInfo;
  74. VkPipelineTessellationStateCreateInfo mTesselationInfo;
  75. VkPipelineViewportStateCreateInfo mViewportInfo;
  76. VkPipelineRasterizationStateCreateInfo mRasterizationInfo;
  77. VkPipelineMultisampleStateCreateInfo mMultiSampleInfo;
  78. VkPipelineDepthStencilStateCreateInfo mDepthStencilInfo;
  79. VkPipelineColorBlendAttachmentState mAttachmentBlendStates[BS_MAX_MULTIPLE_RENDER_TARGETS];
  80. VkPipelineColorBlendStateCreateInfo mColorBlendStateInfo;
  81. VkPipelineDynamicStateCreateInfo mDynamicStateInfo;
  82. VkDynamicState mDynamicStates[3];
  83. VkGraphicsPipelineCreateInfo mPipelineInfo;
  84. bool mScissorEnabled;
  85. SPtr<VertexDeclarationCore> mVertexDecl;
  86. GpuDeviceFlags mDeviceMask;
  87. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  88. Mutex mMutex;
  89. };
  90. /** Vulkan implementation of a compute pipeline state. */
  91. class VulkanComputePipelineStateCore : public ComputePipelineStateCore
  92. {
  93. public:
  94. ~VulkanComputePipelineStateCore();
  95. /**
  96. * Returns a pipeline object for the specified device index. If the device index doesn't match a bit in the
  97. * device mask provided on pipeline creation, null is returned.
  98. */
  99. VulkanPipeline* getPipeline(UINT32 deviceIdx) const;
  100. protected:
  101. friend class VulkanRenderStateCoreManager;
  102. VulkanComputePipelineStateCore(const SPtr<GpuProgramCore>& program, GpuDeviceFlags deviceMask);
  103. /** @copydoc ComputePipelineStateCore::initialize */
  104. void initialize() override;
  105. /** Contains pipeline data specific to a single Vulkan device. */
  106. struct PerDeviceData
  107. {
  108. VulkanDevice* device;
  109. VulkanPipeline* pipeline;
  110. };
  111. GpuDeviceFlags mDeviceMask;
  112. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  113. };
  114. /** @} */
  115. }