GrManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2009-present, 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/Common.h>
  7. #include <AnKi/Gr/GrObject.h>
  8. #include <AnKi/Util/String.h>
  9. #include <AnKi/Util/WeakArray.h>
  10. #include <AnKi/Util/CVarSet.h>
  11. namespace anki {
  12. // Forward
  13. class NativeWindow;
  14. /// @addtogroup graphics
  15. /// @{
  16. /// Manager initializer.
  17. class GrManagerInitInfo
  18. {
  19. public:
  20. AllocAlignedCallback m_allocCallback = nullptr;
  21. void* m_allocCallbackUserData = nullptr;
  22. CString m_cacheDirectory;
  23. };
  24. /// The graphics manager, owner of all graphics objects.
  25. class GrManager : public MakeSingletonPtr<GrManager>
  26. {
  27. template<typename>
  28. friend class MakeSingletonPtr;
  29. public:
  30. Error init(GrManagerInitInfo& init);
  31. const GpuDeviceCapabilities& getDeviceCapabilities() const
  32. {
  33. return m_capabilities;
  34. }
  35. /// First call in the frame. Do that before everything else.
  36. void beginFrame();
  37. /// Get next presentable image. The returned Texture is valid until the following swapBuffers. After that it might dissapear even if you hold the
  38. /// reference.
  39. TexturePtr acquireNextPresentableTexture();
  40. /// End this frame.
  41. void endFrame();
  42. /// Submit command buffers. Can be called outside beginFrame() endFrame().
  43. /// @param[in] waitFences Optionally wait for some fences.
  44. /// @param[out] signalFence Optionaly create fence that will be signaled when the submission is done.
  45. void submit(WeakArray<CommandBuffer*> cmdbs, WeakArray<Fence*> waitFences = {}, FencePtr* signalFence = nullptr);
  46. void submit(CommandBuffer* cmdb, WeakArray<Fence*> waitFences = {}, FencePtr* signalFence = nullptr)
  47. {
  48. submit(WeakArray<CommandBuffer*>(&cmdb, 1), waitFences, signalFence);
  49. }
  50. /// Wait for all GPU work to finish.
  51. void finish();
  52. /// @name Object creation methods. They are thread-safe.
  53. /// @{
  54. [[nodiscard]] BufferPtr newBuffer(const BufferInitInfo& init);
  55. [[nodiscard]] TexturePtr newTexture(const TextureInitInfo& init);
  56. [[nodiscard]] SamplerPtr newSampler(const SamplerInitInfo& init);
  57. [[nodiscard]] ShaderPtr newShader(const ShaderInitInfo& init);
  58. [[nodiscard]] ShaderProgramPtr newShaderProgram(const ShaderProgramInitInfo& init);
  59. [[nodiscard]] CommandBufferPtr newCommandBuffer(const CommandBufferInitInfo& init);
  60. [[nodiscard]] OcclusionQueryPtr newOcclusionQuery();
  61. [[nodiscard]] TimestampQueryPtr newTimestampQuery();
  62. [[nodiscard]] PipelineQueryPtr newPipelineQuery(const PipelineQueryInitInfo& inf);
  63. [[nodiscard]] RenderGraphPtr newRenderGraph();
  64. [[nodiscard]] GrUpscalerPtr newGrUpscaler(const GrUpscalerInitInfo& init);
  65. [[nodiscard]] AccelerationStructurePtr newAccelerationStructure(const AccelerationStructureInitInfo& init);
  66. /// @}
  67. /// Get the size of the acceleration structure if you are planning to supply a custom buffer.
  68. PtrSize getAccelerationStructureMemoryRequirement(const AccelerationStructureInitInfo& init) const;
  69. ANKI_INTERNAL CString getCacheDirectory() const
  70. {
  71. return m_cacheDir.toCString();
  72. }
  73. ANKI_INTERNAL U32 getNewUuid()
  74. {
  75. return m_uuidIndex.fetchAdd(1);
  76. }
  77. protected:
  78. GrString m_cacheDir;
  79. Atomic<U32> m_uuidIndex = {1};
  80. GpuDeviceCapabilities m_capabilities;
  81. GrManager();
  82. virtual ~GrManager();
  83. };
  84. template<>
  85. template<>
  86. GrManager& MakeSingletonPtr<GrManager>::allocateSingleton<>();
  87. template<>
  88. void MakeSingletonPtr<GrManager>::freeSingleton();
  89. /// @}
  90. } // end namespace anki