BsVulkanGpuParams.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "Renderapi/BsGpuParams.h"
  6. #include "Allocators/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. VkBufferView bufferView;
  52. };
  53. /** All GPU param data related to a single descriptor set. */
  54. struct PerSetData
  55. {
  56. VulkanDescriptorSet* latestSet;
  57. Vector<VulkanDescriptorSet*> sets;
  58. VkWriteDescriptorSet* writeSetInfos;
  59. WriteInfo* writeInfos;
  60. UINT32 numElements;
  61. };
  62. /** All GPU param data beloning to a single device. */
  63. struct PerDeviceData
  64. {
  65. PerSetData* perSetData;
  66. VkImage* sampledImages;
  67. VkImage* storageImages;
  68. VkBuffer* uniformBuffers;
  69. VkBuffer* buffers;
  70. VkSampler* samplers;
  71. };
  72. friend class VulkanHardwareBufferManager;
  73. VulkanGpuParams(const SPtr<GpuPipelineParamInfo>& paramInfo, GpuDeviceFlags deviceMask);
  74. /** @copydoc GpuParams::initialize */
  75. void initialize() override;
  76. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  77. GpuDeviceFlags mDeviceMask;
  78. bool* mSetsDirty;
  79. GroupAlloc mAlloc;
  80. Mutex mMutex;
  81. };
  82. /** @} */
  83. }}