2
0

ShaderProgram.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/GrObject.h>
  7. #include <AnKi/Gr/Shader.h>
  8. namespace anki
  9. {
  10. /// @addtogroup graphics
  11. /// @{
  12. /// @memberof RayTracingShaders
  13. class RayTracingHitGroup
  14. {
  15. public:
  16. ShaderPtr m_closestHitShader;
  17. ShaderPtr m_anyHitShader;
  18. };
  19. /// @memberof ShaderProgramInitInfo
  20. class RayTracingShaders
  21. {
  22. public:
  23. WeakArray<ShaderPtr> m_rayGenShaders;
  24. WeakArray<ShaderPtr> m_missShaders;
  25. WeakArray<RayTracingHitGroup> m_hitGroups;
  26. U32 m_maxRecursionDepth = 1;
  27. };
  28. /// ShaderProgram init info.
  29. class ShaderProgramInitInfo : public GrBaseInitInfo
  30. {
  31. public:
  32. /// Option 1
  33. Array<ShaderPtr, U32(ShaderType::LAST_GRAPHICS + 1)> m_graphicsShaders;
  34. /// Option 2
  35. ShaderPtr m_computeShader;
  36. /// Option 3
  37. RayTracingShaders m_rayTracingShaders;
  38. ShaderProgramInitInfo(CString name = {})
  39. : GrBaseInitInfo(name)
  40. {
  41. }
  42. Bool isValid() const;
  43. };
  44. /// GPU program.
  45. class ShaderProgram : public GrObject
  46. {
  47. ANKI_GR_OBJECT
  48. public:
  49. static const GrObjectType CLASS_TYPE = GrObjectType::SHADER_PROGRAM;
  50. /// Get the shader group handles that will be used in the SBTs. The size of each handle is
  51. /// GpuDeviceCapabilities::m_shaderGroupHandleSize. To access a handle use:
  52. /// @code
  53. /// const U8* handleBegin = &getShaderGroupHandles()[handleIdx * devCapabilities.m_shaderGroupHandleSize];
  54. /// const U8* handleEnd = &getShaderGroupHandles()[(handleIdx + 1) * devCapabilities.m_shaderGroupHandleSize];
  55. /// @endcode
  56. /// The handleIdx is defined via a convention. The ray gen shaders appear first where handleIdx is in the same order
  57. /// as the shader in RayTracingShaders::m_rayGenShaders. Then miss shaders follow with a similar rule. Then hit
  58. /// groups follow.
  59. ConstWeakArray<U8> getShaderGroupHandles() const;
  60. protected:
  61. /// Construct.
  62. ShaderProgram(GrManager* manager, CString name)
  63. : GrObject(manager, CLASS_TYPE, name)
  64. {
  65. }
  66. /// Destroy.
  67. ~ShaderProgram()
  68. {
  69. }
  70. private:
  71. /// Allocate and initialize a new instance.
  72. static ANKI_USE_RESULT ShaderProgram* newInstance(GrManager* manager, const ShaderProgramInitInfo& init);
  73. };
  74. /// @}
  75. } // end namespace anki