BsVulkanGpuParams.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "BsGpuParams.h"
  6. #include "BsGroupAlloc.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Vulkan implementation of GpuParams, containing resource descriptors for all shader stages. */
  13. class VulkanGpuParams : public GpuParams
  14. {
  15. public:
  16. ~VulkanGpuParams();
  17. /** @copydoc GpuParams::setParamBlockBuffer(UINT32, UINT32, const ParamsBufferType&) */
  18. void setParamBlockBuffer(UINT32 set, UINT32 slot, const SPtr<GpuParamBlockBuffer>& paramBlockBuffer) override;
  19. /** @copydoc GpuParams::setTexture */
  20. void setTexture(UINT32 set, UINT32 slot, const SPtr<Texture>& texture,
  21. const TextureSurface& surface = TextureSurface::COMPLETE) override;
  22. /** @copydoc GpuParams::setLoadStoreTexture */
  23. void setLoadStoreTexture(UINT32 set, UINT32 slot, const SPtr<Texture>& texture,
  24. const TextureSurface& surface) override;
  25. /** @copydoc GpuParams::setBuffer */
  26. void setBuffer(UINT32 set, UINT32 slot, const SPtr<GpuBuffer>& buffer) override;
  27. /** @copydoc GpuParams::setSamplerState */
  28. void setSamplerState(UINT32 set, UINT32 slot, const SPtr<SamplerState>& sampler) override;
  29. /** Returns the total number of descriptor sets used by this object. */
  30. UINT32 getNumSets() const;
  31. /**
  32. * Prepares the internal descriptor sets for a bind operation on the provided command buffer. It generates and/or
  33. * updates and descriptor sets, and registers the relevant resources with the command buffer.
  34. *
  35. * Caller must perform external locking if some other thread could write to this object while it is being bound.
  36. * The same applies to any resources held by this object.
  37. *
  38. * @param[in] buffer Buffer on which the parameters will be bound to.
  39. * @param[out] sets Pre-allocated buffer in which the descriptor set handled will be written. Must be of
  40. * getNumSets() size.
  41. *
  42. * @note Thread safe.
  43. */
  44. void prepareForBind(VulkanCmdBuffer& buffer, VkDescriptorSet* sets);
  45. protected:
  46. /** Contains data about writing to either buffer or a texture descriptor. */
  47. union WriteInfo
  48. {
  49. VkDescriptorImageInfo image;
  50. VkDescriptorBufferInfo buffer;
  51. };
  52. /** All GPU param data related to a single descriptor set. */
  53. struct PerSetData
  54. {
  55. VulkanDescriptorSet* latestSet;
  56. Vector<VulkanDescriptorSet*> sets;
  57. VkWriteDescriptorSet* writeSetInfos;
  58. WriteInfo* writeInfos;
  59. UINT32 numElements;
  60. };
  61. /** All GPU param data beloning to a single device. */
  62. struct PerDeviceData
  63. {
  64. PerSetData* perSetData;
  65. VkImage* sampledImages;
  66. VkImage* storageImages;
  67. VkBuffer* uniformBuffers;
  68. VkBuffer* buffers;
  69. VkSampler* samplers;
  70. };
  71. friend class VulkanHardwareBufferManager;
  72. VulkanGpuParams(const SPtr<GpuPipelineParamInfo>& paramInfo, GpuDeviceFlags deviceMask);
  73. /** @copydoc GpuParams::initialize */
  74. void initialize() override;
  75. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  76. GpuDeviceFlags mDeviceMask;
  77. bool* mSetsDirty;
  78. GroupAlloc mAlloc;
  79. Mutex mMutex;
  80. };
  81. /** @} */
  82. }}