GrManager.h 3.0 KB

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