BsVulkanGpuParams.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 bs
  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. };
  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. };
  66. friend class VulkanHardwareBufferCoreManager;
  67. VulkanGpuParams(const SPtr<GpuPipelineParamInfoCore>& paramInfo, GpuDeviceFlags deviceMask);
  68. /** @copydoc GpuParamsCore::initialize */
  69. void initialize() override;
  70. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  71. GpuDeviceFlags mDeviceMask;
  72. UINT8* mData;
  73. bool* mSetsDirty;
  74. Mutex mMutex;
  75. };
  76. /** @} */
  77. }