BsVulkanFramebuffer.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. namespace bs
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. /** Represents a single attachment in a Vulkan frame-buffer. */
  12. struct VULKAN_ATTACHMENT_DESC
  13. {
  14. /** Image to attach or null if none. */
  15. VulkanImage* image;
  16. /** View of the image to attach or VK_NULL_HANDLE if none. */
  17. VkImageView view;
  18. /** Format of the attached image. */
  19. VkFormat format;
  20. /** Initial layer of the surface as pointed to by the provided image view. */
  21. UINT32 baseLayer;
  22. };
  23. /** Contains parameters used for initializing VulkanFrameBuffer object. */
  24. struct VULKAN_FRAMEBUFFER_DESC
  25. {
  26. /** Images describing the color attachments. */
  27. VULKAN_ATTACHMENT_DESC color[BS_MAX_MULTIPLE_RENDER_TARGETS];
  28. /** Image describing the depth attachment. */
  29. VULKAN_ATTACHMENT_DESC depth;
  30. /** Width of the images, in pixels. All images must be the same size. */
  31. UINT32 width;
  32. /** Height of the images, in pixels. All images must be the same size. */
  33. UINT32 height;
  34. /** Number of image layers to render to. This value is used for all provided surfaces. */
  35. UINT32 layers;
  36. /** Number of samples in the attached images. All attachments must have the same number of samples. */
  37. UINT32 numSamples;
  38. /** Set to true if framebuffer represents an offscreen surface that will not be presented. */
  39. bool offscreen;
  40. };
  41. /** Vulkan frame buffer containing one or multiple color surfaces, and an optional depth surface. */
  42. class VulkanFramebuffer : public VulkanResource
  43. {
  44. public:
  45. /** Creates a new frame buffer with the specified image views attached.
  46. *
  47. * @param[in] owner Resource manager that allocated this resource.
  48. * @param[in] desc Description of the frame buffer.
  49. */
  50. VulkanFramebuffer(VulkanResourceManager* owner, const VULKAN_FRAMEBUFFER_DESC& desc);
  51. ~VulkanFramebuffer();
  52. /** Returns a unique ID of this framebuffer. */
  53. UINT32 getId() const { return mId; }
  54. /**
  55. * Gets internal Vulkan render pass object.
  56. *
  57. * @param[in] preserveContents If true, returns render pass that preserves existing framebuffer attachment
  58. * contents on load. Otherwise returns render pass that discards them (more
  59. * efficient).
  60. */
  61. VkRenderPass getRenderPass(bool preserveContents) const;
  62. /**
  63. * Gets internal Vulkan framebuffer object.
  64. *
  65. * @param[in] preserveContents If true, returns render pass that preserves existing framebuffer attachment
  66. * contents on load. Otherwise returns render pass that discards them (more
  67. * efficient).
  68. */
  69. VkFramebuffer getFramebuffer(bool preserveContents) const;
  70. /**
  71. * Gets the number of layers in each framebuffer surface. A layer is an element in a texture array, or a depth
  72. * slice in a 3D texture).
  73. */
  74. UINT32 getNumLayers() const { return mNumLayers; }
  75. /** Returns the image representing the color attachment at the provided index. */
  76. VulkanImage* getColorImage(UINT32 colorIdx) const { return mColorImages[colorIdx]; }
  77. /** Returns the image representing the depth/stencil attachment, if one exists. */
  78. VulkanImage* getDepthStencilImage() const { return mDepthStencilImage; }
  79. /** Returns the initial layer of the color texture surface in which to start rendering. */
  80. UINT32 getColorBaseLayer(UINT32 colorIdx) const { return mColorBaseLayers[colorIdx]; }
  81. /** Returns the initial layer of the depth-stencil texture surface in which to start rendering. */
  82. UINT32 getDepthStencilBaseLayer() const { return mDepthBaseLayer; }
  83. /** Gets the total number of frame-buffer attachments, including both color and depth. */
  84. UINT32 getNumAttachments() const { return mNumAttachments; }
  85. /** Gets the number of color frame-buffer attachments. */
  86. UINT32 getNumColorAttachments() const { return mNumColorAttachments; }
  87. /** Returns true if the framebuffer has a depth attachment. */
  88. bool hasDepthAttachment() const { return mHasDepth; }
  89. /** Returns sample flags that determine if the framebuffer supports multi-sampling, and for how many samples. */
  90. VkSampleCountFlagBits getSampleFlags() const { return mSampleFlags; }
  91. private:
  92. UINT32 mId;
  93. VkRenderPass mRenderPassDiscard;
  94. VkFramebuffer mFramebufferDiscard;
  95. VkRenderPass mRenderPassPreserve;
  96. VkFramebuffer mFramebufferPreserve;
  97. UINT32 mNumAttachments;
  98. UINT32 mNumColorAttachments;
  99. UINT32 mNumLayers;
  100. VulkanImage* mColorImages[BS_MAX_MULTIPLE_RENDER_TARGETS];
  101. VulkanImage* mDepthStencilImage;
  102. UINT32 mColorBaseLayers[BS_MAX_MULTIPLE_RENDER_TARGETS];
  103. UINT32 mDepthBaseLayer;
  104. bool mHasDepth;
  105. VkSampleCountFlagBits mSampleFlags;
  106. static UINT32 sNextValidId;
  107. };
  108. /** @} */
  109. }