BsGpuPipelineParamInfo.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "CoreThread/BsCoreObject.h"
  6. #include "Allocators/BsGroupAlloc.h"
  7. namespace bs
  8. {
  9. /** @addtogroup RenderAPI-Internal
  10. * @{
  11. */
  12. /** Helper structure used for initializing GpuPipelineParamInfo. */
  13. struct GPU_PIPELINE_PARAMS_DESC
  14. {
  15. SPtr<GpuParamDesc> fragmentParams;
  16. SPtr<GpuParamDesc> vertexParams;
  17. SPtr<GpuParamDesc> geometryParams;
  18. SPtr<GpuParamDesc> hullParams;
  19. SPtr<GpuParamDesc> domainParams;
  20. SPtr<GpuParamDesc> computeParams;
  21. };
  22. /** Binding location for a single GPU program parameter. */
  23. struct GpuParamBinding
  24. {
  25. UINT32 set = (UINT32)-1;
  26. UINT32 slot = (UINT32)-1;
  27. };
  28. /** Contains code common to both sim and core thread implementations of GpuPipelineParamInfo. */
  29. class BS_CORE_EXPORT GpuPipelineParamInfoBase
  30. {
  31. public:
  32. /** Types of GPU parameters. */
  33. enum class ParamType
  34. {
  35. ParamBlock, Texture, LoadStoreTexture, Buffer, SamplerState, Count
  36. };
  37. /** Constructs the object using the provided GPU parameter descriptors. */
  38. GpuPipelineParamInfoBase(const GPU_PIPELINE_PARAMS_DESC& desc);
  39. virtual ~GpuPipelineParamInfoBase();
  40. /** Gets the total number of sets. */
  41. UINT32 getNumSets() const { return mNumSets; }
  42. /** Returns the total number of elements across all sets. */
  43. UINT32 getNumElements() const { return mNumElements; }
  44. /** Returns the number of elements in all sets for the specified parameter type. */
  45. UINT32 getNumElements(ParamType type) { return mNumElementsPerType[(int)type]; }
  46. /**
  47. * Converts a set/slot combination into a sequential index that maps to the parameter in that parameter type's
  48. * array.
  49. *
  50. * If the set or slot is out of valid range, the method logs an error and returns -1. Only performs range checking
  51. * in debug mode.
  52. */
  53. UINT32 getSequentialSlot(ParamType type, UINT32 set, UINT32 slot) const;
  54. /** Converts a sequential slot index into a set/slot combination. */
  55. void getBinding(ParamType type, UINT32 sequentialSlot, UINT32& set, UINT32& slot) const;
  56. /**
  57. * Finds set/slot indices of a parameter with the specified name for every GPU program stage. Set/slot indices are
  58. * set to -1 if a stage doesn't have a block with the specified name.
  59. */
  60. void getBindings(ParamType type, const String& name, GpuParamBinding(&bindings)[GPT_COUNT]);
  61. /** Returns descriptions of individual parameters for the specified GPU program type. */
  62. const SPtr<GpuParamDesc>& getParamDesc(GpuProgramType type) const { return mParamDescs[(int)type]; }
  63. protected:
  64. /** Information about a single set in the param info object. */
  65. struct SetInfo
  66. {
  67. UINT32* slotIndices;
  68. ParamType* slotTypes;
  69. UINT32* slotSamplers;
  70. UINT32 numSlots;
  71. };
  72. /** Information how a resource maps to a certain set/slot. */
  73. struct ResourceInfo
  74. {
  75. UINT32 set;
  76. UINT32 slot;
  77. };
  78. std::array<SPtr<GpuParamDesc>, 6> mParamDescs;
  79. UINT32 mNumSets;
  80. UINT32 mNumElements;
  81. SetInfo* mSetInfos;
  82. UINT32 mNumElementsPerType[(int)ParamType::Count];
  83. ResourceInfo* mResourceInfos[(int)ParamType::Count];
  84. GroupAlloc mAlloc;
  85. };
  86. /** Holds meta-data about a set of GPU parameters used by a single pipeline state. */
  87. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  88. {
  89. public:
  90. virtual ~GpuPipelineParamInfo() { }
  91. /**
  92. * Retrieves a core implementation of this object usable only from the core thread.
  93. *
  94. * @note Core thread only.
  95. */
  96. SPtr<ct::GpuPipelineParamInfo> getCore() const;
  97. /**
  98. * Constructs the object using the provided GPU parameter descriptors.
  99. *
  100. * @param[in] desc Object containing parameter descriptions for individual GPU program stages.
  101. */
  102. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc);
  103. private:
  104. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc);
  105. /** @copydoc CoreObject::createCore */
  106. SPtr<ct::CoreObject> createCore() const override;
  107. };
  108. namespace ct
  109. {
  110. /** Core thread version of a bs::GpuPipelineParamInfo. */
  111. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  112. {
  113. public:
  114. virtual ~GpuPipelineParamInfo() { }
  115. /**
  116. * @copydoc bs::GpuPipelineParamInfo::create
  117. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  118. */
  119. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc,
  120. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  121. protected:
  122. friend class RenderStateManager;
  123. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc, GpuDeviceFlags deviceMask);
  124. };
  125. }
  126. /** @} */
  127. }