ShaderProgram.h 2.2 KB

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