BsGpuPipelineParamInfo.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 the specified GPU program stage. Set/slot
  58. * indices are set to -1 if a stage doesn't have a block with the specified name.
  59. */
  60. void getBinding(GpuProgramType progType, ParamType type, const String& name, GpuParamBinding &binding);
  61. /**
  62. * Finds set/slot indices of a parameter with the specified name for every GPU program stage. Set/slot indices are
  63. * set to -1 if a stage doesn't have a block with the specified name.
  64. */
  65. void getBindings(ParamType type, const String& name, GpuParamBinding(&bindings)[GPT_COUNT]);
  66. /** Returns descriptions of individual parameters for the specified GPU program type. */
  67. const SPtr<GpuParamDesc>& getParamDesc(GpuProgramType type) const { return mParamDescs[(int)type]; }
  68. protected:
  69. /** Information about a single set in the param info object. */
  70. struct SetInfo
  71. {
  72. UINT32* slotIndices;
  73. ParamType* slotTypes;
  74. UINT32* slotSamplers;
  75. UINT32 numSlots;
  76. };
  77. /** Information how a resource maps to a certain set/slot. */
  78. struct ResourceInfo
  79. {
  80. UINT32 set;
  81. UINT32 slot;
  82. };
  83. std::array<SPtr<GpuParamDesc>, 6> mParamDescs;
  84. UINT32 mNumSets;
  85. UINT32 mNumElements;
  86. SetInfo* mSetInfos;
  87. UINT32 mNumElementsPerType[(int)ParamType::Count];
  88. ResourceInfo* mResourceInfos[(int)ParamType::Count];
  89. GroupAlloc mAlloc;
  90. };
  91. /** Holds meta-data about a set of GPU parameters used by a single pipeline state. */
  92. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  93. {
  94. public:
  95. virtual ~GpuPipelineParamInfo() { }
  96. /**
  97. * Retrieves a core implementation of this object usable only from the core thread.
  98. *
  99. * @note Core thread only.
  100. */
  101. SPtr<ct::GpuPipelineParamInfo> getCore() const;
  102. /**
  103. * Constructs the object using the provided GPU parameter descriptors.
  104. *
  105. * @param[in] desc Object containing parameter descriptions for individual GPU program stages.
  106. */
  107. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc);
  108. private:
  109. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc);
  110. /** @copydoc CoreObject::createCore */
  111. SPtr<ct::CoreObject> createCore() const override;
  112. };
  113. namespace ct
  114. {
  115. /** Core thread version of a bs::GpuPipelineParamInfo. */
  116. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  117. {
  118. public:
  119. virtual ~GpuPipelineParamInfo() { }
  120. /**
  121. * @copydoc bs::GpuPipelineParamInfo::create
  122. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  123. */
  124. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc,
  125. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  126. protected:
  127. friend class RenderStateManager;
  128. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc, GpuDeviceFlags deviceMask);
  129. };
  130. }
  131. /** @} */
  132. }