BsGpuPipelineParamInfo.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /** Contains code common to both sim and core thread implementations of GpuPipelineParamInfo. */
  23. class BS_CORE_EXPORT GpuPipelineParamInfoBase
  24. {
  25. public:
  26. /** Types of GPU parameters. */
  27. enum class ParamType
  28. {
  29. ParamBlock, Texture, LoadStoreTexture, Buffer, SamplerState, Count
  30. };
  31. /** Constructs the object using the provided GPU parameter descriptors. */
  32. GpuPipelineParamInfoBase(const GPU_PIPELINE_PARAMS_DESC& desc);
  33. virtual ~GpuPipelineParamInfoBase();
  34. /** Gets the total number of sets. */
  35. UINT32 getNumSets() const { return mNumSets; }
  36. /** Returns the total number of elements across all sets. */
  37. UINT32 getNumElements() const { return mNumElements; }
  38. /** Returns the number of elements in all sets for the specified parameter type. */
  39. UINT32 getNumElements(ParamType type) { return mNumElementsPerType[(int)type]; }
  40. /**
  41. * Converts a set/slot combination into a sequential index that maps to the parameter in that parameter type's
  42. * array.
  43. *
  44. * If the set or slot is out of valid range, the method logs an error and returns -1. Only performs range checking
  45. * in debug mode.
  46. */
  47. UINT32 getSequentialSlot(ParamType type, UINT32 set, UINT32 slot) const;
  48. /** Converts a sequential slot index into a set/slot combination. */
  49. void getSetSlot(ParamType type, UINT32 sequentialSlot, UINT32& set, UINT32& slot) const;
  50. /** Returns descriptions of individual parameters for the specified GPU program type. */
  51. const SPtr<GpuParamDesc>& getParamDesc(GpuProgramType type) const { return mParamDescs[(int)type]; }
  52. protected:
  53. /** Information about a single set in the param info object. */
  54. struct SetInfo
  55. {
  56. UINT32* slotIndices;
  57. ParamType* slotTypes;
  58. UINT32* slotSamplers;
  59. UINT32 numSlots;
  60. };
  61. /** Information how a resource maps to a certain set/slot. */
  62. struct ResourceInfo
  63. {
  64. UINT32 set;
  65. UINT32 slot;
  66. };
  67. std::array<SPtr<GpuParamDesc>, 6> mParamDescs;
  68. UINT32 mNumSets;
  69. UINT32 mNumElements;
  70. SetInfo* mSetInfos;
  71. UINT32 mNumElementsPerType[(int)ParamType::Count];
  72. ResourceInfo* mResourceInfos[(int)ParamType::Count];
  73. GroupAlloc mAlloc;
  74. };
  75. /** Holds meta-data about a set of GPU parameters used by a single pipeline state. */
  76. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  77. {
  78. public:
  79. virtual ~GpuPipelineParamInfo() { }
  80. /**
  81. * Retrieves a core implementation of this object usable only from the core thread.
  82. *
  83. * @note Core thread only.
  84. */
  85. SPtr<ct::GpuPipelineParamInfo> getCore() const;
  86. /**
  87. * Constructs the object using the provided GPU parameter descriptors.
  88. *
  89. * @param[in] desc Object containing parameter descriptions for individual GPU program stages.
  90. */
  91. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc);
  92. private:
  93. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc);
  94. /** @copydoc CoreObject::createCore */
  95. SPtr<ct::CoreObject> createCore() const override;
  96. };
  97. namespace ct
  98. {
  99. /** Core thread version of a bs::GpuPipelineParamInfo. */
  100. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  101. {
  102. public:
  103. virtual ~GpuPipelineParamInfo() { }
  104. /**
  105. * @copydoc bs::GpuPipelineParamInfo::create
  106. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  107. */
  108. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc,
  109. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  110. protected:
  111. friend class RenderStateManager;
  112. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc, GpuDeviceFlags deviceMask);
  113. };
  114. }
  115. /** @} */
  116. }