BsVulkanTexture.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "BsTexture.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Wrapper around a Vulkan image object that manages its usage and lifetime. */
  13. class VulkanImage : public VulkanResource
  14. {
  15. public:
  16. VulkanImage(VulkanResourceManager* owner, VkImage image, VkDeviceMemory memory, VkImageLayout layout,
  17. const TextureProperties& props);
  18. ~VulkanImage();
  19. /** Returns the internal handle to the Vulkan object. */
  20. VkImage getHandle() const { return mImage; }
  21. /** Returns the layout the image is currently in. */
  22. VkImageLayout getLayout() const { return mLayout; }
  23. /** Notifies the resource that the current image layout has changed. */
  24. void setLayout(VkImageLayout layout) { mLayout = layout; }
  25. /** Returns an image view that covers all faces and mip maps of the texture. */
  26. VkImageView getView() const { return mMainView; };
  27. /** Returns an image view that covers the specified faces and mip maps of the texture. */
  28. VkImageView getView(const TextureSurface& surface) const;
  29. private:
  30. /** Creates a new view of the provided part (or entirety) of surface. */
  31. VkImageView createView(const TextureSurface& surface) const;
  32. /** Contains information about view for a specific surface(s) of this image. */
  33. struct ImageViewInfo
  34. {
  35. TextureSurface surface;
  36. VkImageView view;
  37. };
  38. VkImage mImage;
  39. VkDeviceMemory mMemory;
  40. VkImageLayout mLayout;
  41. VkImageView mMainView;
  42. mutable VkImageViewCreateInfo mImageViewCI;
  43. mutable Vector<ImageViewInfo> mImageInfos;
  44. };
  45. /** Vulkan implementation of a texture. */
  46. class VulkanTextureCore : public TextureCore
  47. {
  48. public:
  49. ~VulkanTextureCore();
  50. /**
  51. * Gets the resource wrapping the Vulkan image object, on the specified device. If texture device mask doesn't
  52. * include the provided device, null is returned.
  53. */
  54. VulkanImage* getResource(UINT32 deviceIdx) const { return mImages[deviceIdx]; }
  55. /**
  56. * Returns an image view that covers all faces and mip maps of the texture. Usable only on the specified device.
  57. * If texture device mask doesn't include the provided device, null is returned.
  58. */
  59. VkImageView getView(UINT32 deviceIdx) const;
  60. /**
  61. * Returns an image view that covers the specified faces and mip maps of the texture. Usable only on the specified
  62. * device. If texture device mask doesn't include the provided device, null is returned.
  63. */
  64. VkImageView getView(UINT32 deviceIdx, const TextureSurface& surface) const;
  65. protected:
  66. friend class VulkanTextureCoreManager;
  67. VulkanTextureCore(const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData, GpuDeviceFlags deviceMask);
  68. /** @copydoc CoreObjectCore::initialize() */
  69. void initialize() override;
  70. /** @copydoc TextureCore::lockImpl */
  71. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  72. UINT32 queueIdx = 0) override;
  73. /** @copydoc TextureCore::unlockImpl */
  74. void unlockImpl() override;
  75. /** @copydoc TextureCore::copyImpl */
  76. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel,
  77. const SPtr<TextureCore>& target, UINT32 queueIdx = 0) override;
  78. /** @copydoc TextureCore::readData */
  79. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  80. UINT32 queueIdx = 0) override;
  81. /** @copydoc TextureCore::writeData */
  82. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false,
  83. UINT32 queueIdx = 0) override;
  84. private:
  85. /** Creates a new image for the specified device, matching the current properties. */
  86. VulkanImage* createImage(VulkanDevice& device, bool staging, bool readable);
  87. VulkanImage* mImages[BS_MAX_DEVICES];
  88. GpuDeviceFlags mDeviceMask;
  89. VkImageCreateInfo mImageCI;
  90. };
  91. /** @} */
  92. }