BsVulkanGpuParams.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. namespace BansheeEngine
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. /** Vulkan implementation of GpuParams, containing resource descriptors for all shader stages. */
  12. class VulkanGpuParams : public GpuParamsCore
  13. {
  14. public:
  15. ~VulkanGpuParams();
  16. /** @copydoc GpuParamsCore::setParamBlockBuffer(UINT32, UINT32, const ParamsBufferType&) */
  17. void setParamBlockBuffer(UINT32 set, UINT32 slot, const SPtr<GpuParamBlockBufferCore>& paramBlockBuffer) override;
  18. /** @copydoc GpuParamsCore::setTexture */
  19. void setTexture(UINT32 set, UINT32 slot, const SPtr<TextureCore>& texture) override;
  20. /** @copydoc GpuParamsCore::setLoadStoreTexture */
  21. void setLoadStoreTexture(UINT32 set, UINT32 slot, const SPtr<TextureCore>& texture,
  22. const TextureSurface& surface) override;
  23. /** @copydoc GpuParamsCore::setBuffer */
  24. void setBuffer(UINT32 set, UINT32 slot, const SPtr<GpuBufferCore>& buffer) override;
  25. /** @copydoc GpuParamsCore::setSamplerState */
  26. void setSamplerState(UINT32 set, UINT32 slot, const SPtr<SamplerStateCore>& sampler) override;
  27. /** @copydoc GpuParamsCore::setLoadStoreSurface */
  28. void setLoadStoreSurface(UINT32 set, UINT32 slot, const TextureSurface& surface) 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. };
  67. friend class VulkanHardwareBufferCoreManager;
  68. VulkanGpuParams(const SPtr<GpuPipelineParamInfoCore>& paramInfo, GpuDeviceFlags deviceMask);
  69. /** @copydoc GpuParamsCore::initialize */
  70. void initialize() override;
  71. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  72. GpuDeviceFlags mDeviceMask;
  73. UINT8* mData;
  74. bool* mSetsDirty;
  75. Mutex mMutex;
  76. };
  77. /** @} */
  78. }