GrManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/Common.h>
  7. #include <AnKi/Gr/GrObject.h>
  8. #include <AnKi/Util/String.h>
  9. namespace anki {
  10. // Forward
  11. class ConfigSet;
  12. class NativeWindow;
  13. /// @addtogroup graphics
  14. /// @{
  15. /// Manager initializer.
  16. class GrManagerInitInfo
  17. {
  18. public:
  19. AllocAlignedCallback m_allocCallback = nullptr;
  20. void* m_allocCallbackUserData = nullptr;
  21. CString m_cacheDirectory;
  22. const ConfigSet* m_config = nullptr;
  23. NativeWindow* m_window = nullptr;
  24. };
  25. /// Graphics statistics.
  26. class GrManagerStats
  27. {
  28. public:
  29. PtrSize m_cpuMemory = 0;
  30. PtrSize m_gpuMemory = 0;
  31. U32 m_commandBufferCount = 0;
  32. };
  33. /// The graphics manager, owner of all graphics objects.
  34. class GrManager
  35. {
  36. public:
  37. /// Create.
  38. static ANKI_USE_RESULT Error newInstance(GrManagerInitInfo& init, GrManager*& gr);
  39. /// Destroy.
  40. static void deleteInstance(GrManager* gr);
  41. const GpuDeviceCapabilities& getDeviceCapabilities() const
  42. {
  43. return m_capabilities;
  44. }
  45. const BindlessLimits& getBindlessLimits() const
  46. {
  47. return m_bindlessLimits;
  48. }
  49. /// Get next presentable image. The returned Texture is valid until the following swapBuffers. After that it might
  50. /// dissapear even if you hold the reference.
  51. TexturePtr acquireNextPresentableTexture();
  52. /// Swap buffers
  53. void swapBuffers();
  54. /// Wait for all work to finish.
  55. void finish();
  56. /// @name Object creation methods. They are thread-safe.
  57. /// @{
  58. ANKI_USE_RESULT BufferPtr newBuffer(const BufferInitInfo& init);
  59. ANKI_USE_RESULT TexturePtr newTexture(const TextureInitInfo& init);
  60. ANKI_USE_RESULT TextureViewPtr newTextureView(const TextureViewInitInfo& init);
  61. ANKI_USE_RESULT SamplerPtr newSampler(const SamplerInitInfo& init);
  62. ANKI_USE_RESULT ShaderPtr newShader(const ShaderInitInfo& init);
  63. ANKI_USE_RESULT ShaderProgramPtr newShaderProgram(const ShaderProgramInitInfo& init);
  64. ANKI_USE_RESULT CommandBufferPtr newCommandBuffer(const CommandBufferInitInfo& init);
  65. ANKI_USE_RESULT FramebufferPtr newFramebuffer(const FramebufferInitInfo& init);
  66. ANKI_USE_RESULT OcclusionQueryPtr newOcclusionQuery();
  67. ANKI_USE_RESULT TimestampQueryPtr newTimestampQuery();
  68. ANKI_USE_RESULT RenderGraphPtr newRenderGraph();
  69. ANKI_USE_RESULT AccelerationStructurePtr newAccelerationStructure(const AccelerationStructureInitInfo& init);
  70. /// @}
  71. GrManagerStats getStats() const;
  72. ANKI_INTERNAL GrAllocator<U8>& getAllocator()
  73. {
  74. return m_alloc;
  75. }
  76. ANKI_INTERNAL GrAllocator<U8> getAllocator() const
  77. {
  78. return m_alloc;
  79. }
  80. ANKI_INTERNAL CString getCacheDirectory() const
  81. {
  82. return m_cacheDir.toCString();
  83. }
  84. ANKI_INTERNAL U64 getNewUuid()
  85. {
  86. return m_uuidIndex.fetchAdd(1);
  87. }
  88. protected:
  89. GrAllocator<U8> m_alloc; ///< Keep it first to get deleted last
  90. String m_cacheDir;
  91. Atomic<U64> m_uuidIndex = {1};
  92. GpuDeviceCapabilities m_capabilities;
  93. BindlessLimits m_bindlessLimits;
  94. GrManager();
  95. virtual ~GrManager();
  96. };
  97. /// @}
  98. } // end namespace anki