BsVulkanGpuParams.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /**
  30. * Binds the internal descriptor sets to the provided command buffer. Caller must perform external locking if
  31. * some other thread could write to this object while it is being bound. The same applies to any resources
  32. * held by this object.
  33. *
  34. * @note Thread safe.
  35. */
  36. void bind(VulkanCommandBuffer& buffer);
  37. protected:
  38. /** Contains data about writing to either buffer or a texture descriptor. */
  39. union WriteInfo
  40. {
  41. VkDescriptorImageInfo image;
  42. VkDescriptorBufferInfo buffer;
  43. VkBufferView bufferView;
  44. };
  45. /** All GPU param data related to a single descriptor set. */
  46. struct PerSetData
  47. {
  48. VulkanDescriptorLayout* layout;
  49. VulkanDescriptorSet* latestSet;
  50. Vector<VulkanDescriptorSet*> sets;
  51. VkWriteDescriptorSet* writeSetInfos;
  52. WriteInfo* writeInfos;
  53. UINT32 numElements;
  54. };
  55. /** All GPU param data beloning to a single device. */
  56. struct PerDeviceData
  57. {
  58. PerSetData* perSetData;
  59. UINT32 numSets;
  60. VkPipelineLayout pipelineLayout;
  61. };
  62. friend class VulkanHardwareBufferCoreManager;
  63. VulkanGpuParams(const SPtr<GpuPipelineParamInfo>& paramInfo, GpuDeviceFlags deviceMask);
  64. PerDeviceData mPerDeviceData[BS_MAX_DEVICES];
  65. GpuDeviceFlags mDeviceMask;
  66. UINT8* mData;
  67. bool* mSetsDirty;
  68. Mutex mMutex;
  69. };
  70. /** @} */
  71. }