BsGpuPipelineParamInfo.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "BsCoreObject.h"
  6. #include "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 numSlots;
  59. };
  60. /** Information how a resource maps to a certain set/slot. */
  61. struct ResourceInfo
  62. {
  63. UINT32 set;
  64. UINT32 slot;
  65. };
  66. std::array<SPtr<GpuParamDesc>, 6> mParamDescs;
  67. UINT32 mNumSets;
  68. UINT32 mNumElements;
  69. SetInfo* mSetInfos;
  70. UINT32 mNumElementsPerType[(int)ParamType::Count];
  71. ResourceInfo* mResourceInfos[(int)ParamType::Count];
  72. GroupAlloc mAlloc;
  73. };
  74. /** Core thread version of a GpuPipelineParamInfo. */
  75. class BS_CORE_EXPORT GpuPipelineParamInfoCore : public CoreObjectCore, public GpuPipelineParamInfoBase
  76. {
  77. public:
  78. virtual ~GpuPipelineParamInfoCore() { }
  79. /**
  80. * @copydoc GpuPipelineParamInfo::create
  81. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  82. */
  83. static SPtr<GpuPipelineParamInfoCore> create(const GPU_PIPELINE_PARAMS_DESC& desc,
  84. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  85. protected:
  86. friend class RenderStateCoreManager;
  87. GpuPipelineParamInfoCore(const GPU_PIPELINE_PARAMS_DESC& desc, GpuDeviceFlags deviceMask);
  88. };
  89. /** Holds meta-data about a set of GPU parameters used by a single pipeline state. */
  90. class BS_CORE_EXPORT GpuPipelineParamInfo : public CoreObject, public GpuPipelineParamInfoBase
  91. {
  92. public:
  93. virtual ~GpuPipelineParamInfo() { }
  94. /**
  95. * Retrieves a core implementation of this object usable only from the core thread.
  96. *
  97. * @note Core thread only.
  98. */
  99. SPtr<GpuPipelineParamInfoCore> getCore() const;
  100. /**
  101. * Constructs the object using the provided GPU parameter descriptors.
  102. *
  103. * @param[in] desc Object containing parameter descriptions for individual GPU program stages.
  104. */
  105. static SPtr<GpuPipelineParamInfo> create(const GPU_PIPELINE_PARAMS_DESC& desc);
  106. private:
  107. GpuPipelineParamInfo(const GPU_PIPELINE_PARAMS_DESC& desc);
  108. /** @copydoc CoreObject::createCore */
  109. SPtr<CoreObjectCore> createCore() const override;
  110. };
  111. /** @} */
  112. }