BsVulkanGpuPipelineState.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /**
  48. * Returns a pipeline layout object for the specified device index. If the device index doesn't match a bit in the
  49. * device mask provided on pipeline creation, null is returned.
  50. */
  51. VkPipelineLayout getPipelineLayout(UINT32 deviceIdx) const;
  52. protected:
  53. friend class VulkanRenderStateCoreManager;
  54. VulkanGraphicsPipelineStateCore(const PIPELINE_STATE_CORE_DESC& desc, GpuDeviceFlags deviceMask);
  55. /** @copydoc GraphicsPipelineStateCore::initialize */
  56. void initialize() override;
  57. /**
  58. * Create a new Vulkan graphics pipeline.
  59. *
  60. * @param[in] deviceIdx Index of the device to create the pipeline for.
  61. * @param[in] framebuffer Framebuffer object that defines the surfaces this pipeline will render to.
  62. * @param[in] readOnlyDepth True if the pipeline is only allowed to read the depth buffer, without writes.
  63. * @param[in] drawOp Type of geometry that will be drawn using the pipeline.
  64. * @param[in] vertexInputState State describing inputs to the vertex program.
  65. * @return Vulkan graphics pipeline object.
  66. *
  67. * @note Thread safe.
  68. */
  69. VulkanPipeline* createPipeline(UINT32 deviceIdx, VulkanFramebuffer* framebuffer, bool readOnlyDepth,
  70. DrawOperationType drawOp, VkPipelineVertexInputStateCreateInfo* vertexInputState);
  71. /** Contains pipeline data specific to a single Vulkan device. */
  72. struct PerDeviceData
  73. {
  74. VulkanDevice* device;
  75. VkPipelineLayout pipelineLayout;
  76. };
  77. VkPipelineShaderStageCreateInfo mShaderStageInfos[5];
  78. VkPipelineInputAssemblyStateCreateInfo mInputAssemblyInfo;
  79. VkPipelineTessellationStateCreateInfo mTesselationInfo;
  80. VkPipelineViewportStateCreateInfo mViewportInfo;
  81. VkPipelineRasterizationStateCreateInfo mRasterizationInfo;
  82. VkPipelineMultisampleStateCreateInfo mMultiSampleInfo;
  83. VkPipelineDepthStencilStateCreateInfo mDepthStencilInfo;
  84. VkPipelineColorBlendAttachmentState mAttachmentBlendStates[BS_MAX_MULTIPLE_RENDER_TARGETS];
  85. VkPipelineColorBlendStateCreateInfo mColorBlendStateInfo;
  86. VkPipelineDynamicStateCreateInfo mDynamicStateInfo;
  87. VkDynamicState mDynamicStates[3];
  88. VkGraphicsPipelineCreateInfo mPipelineInfo;
  89. bool mScissorEnabled;
  90. SPtr<VertexDeclarationCore> mVertexDecl;
  91. GpuDeviceFlags mDeviceMask;
  92. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  93. Mutex mMutex;
  94. };
  95. /** Vulkan implementation of a compute pipeline state. */
  96. class VulkanComputePipelineStateCore : public ComputePipelineStateCore
  97. {
  98. public:
  99. ~VulkanComputePipelineStateCore();
  100. /**
  101. * Returns a pipeline object for the specified device index. If the device index doesn't match a bit in the
  102. * device mask provided on pipeline creation, null is returned.
  103. */
  104. VulkanPipeline* getPipeline(UINT32 deviceIdx) const;
  105. /**
  106. * Returns a pipeline layout object for the specified device index. If the device index doesn't match a bit in the
  107. * device mask provided on pipeline creation, null is returned.
  108. */
  109. VkPipelineLayout getPipelineLayout(UINT32 deviceIdx) const;
  110. protected:
  111. friend class VulkanRenderStateCoreManager;
  112. VulkanComputePipelineStateCore(const SPtr<GpuProgramCore>& program, GpuDeviceFlags deviceMask);
  113. /** @copydoc ComputePipelineStateCore::initialize */
  114. void initialize() override;
  115. /** Contains pipeline data specific to a single Vulkan device. */
  116. struct PerDeviceData
  117. {
  118. VulkanDevice* device;
  119. VulkanPipeline* pipeline;
  120. VkPipelineLayout pipelineLayout;
  121. };
  122. GpuDeviceFlags mDeviceMask;
  123. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  124. };
  125. /** @} */
  126. }