GrManagerImpl.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/gl/GrManagerImpl.h>
  6. #include <AnKi/Gr/GrManager.h>
  7. #include <AnKi/Gr/gl/RenderingThread.h>
  8. #include <AnKi/Gr/gl/GlState.h>
  9. #include <AnKi/Core/Config.h>
  10. #include <AnKi/Core/NativeWindow.h>
  11. namespace anki {
  12. GrManagerImpl::GrManagerImpl()
  13. {
  14. }
  15. GrManagerImpl::~GrManagerImpl()
  16. {
  17. m_fakeDefaultFb.reset(nullptr);
  18. m_fakeFbTex.reset(nullptr);
  19. if(m_thread)
  20. {
  21. m_thread->stop();
  22. m_alloc.deleteInstance(m_thread);
  23. m_thread = nullptr;
  24. }
  25. if(m_state)
  26. {
  27. m_alloc.deleteInstance(m_state);
  28. }
  29. destroyBackend();
  30. }
  31. Error GrManagerImpl::init(GrManagerInitInfo& init, GrAllocator<U8> alloc)
  32. {
  33. m_alloc = alloc;
  34. m_cacheDir.create(m_alloc, init.m_cacheDirectory);
  35. m_debugMarkers = init.m_config->getNumber("gr_debugMarkers");
  36. // Init the backend of the backend
  37. ANKI_CHECK(createBackend(init));
  38. // First create the state
  39. m_state = m_alloc.newInstance<GlState>(this);
  40. m_state->initMainThread(*init.m_config);
  41. // Create thread
  42. m_thread = m_alloc.newInstance<RenderingThread>(this);
  43. // Start it
  44. m_thread->start();
  45. m_thread->syncClientServer();
  46. // Misc
  47. m_capabilities.m_gpuVendor = m_state->m_gpu;
  48. m_capabilities.m_uniformBufferBindOffsetAlignment = m_state->m_uboAlignment;
  49. m_capabilities.m_uniformBufferMaxRange = m_state->m_uniBlockMaxSize;
  50. m_capabilities.m_storageBufferBindOffsetAlignment = m_state->m_ssboAlignment;
  51. m_capabilities.m_storageBufferMaxRange = m_state->m_storageBlockMaxSize;
  52. m_capabilities.m_textureBufferBindOffsetAlignment = m_state->m_tboAlignment;
  53. m_capabilities.m_textureBufferMaxRange = m_state->m_tboMaxRange;
  54. m_capabilities.m_majorApiVersion = U(init.m_config->getNumber("gr.glmajor"));
  55. m_capabilities.m_minorApiVersion = U(init.m_config->getNumber("gr.glmajor"));
  56. initFakeDefaultFb(init);
  57. return Error::kNone;
  58. }
  59. void GrManagerImpl::initFakeDefaultFb(GrManagerInitInfo& init)
  60. {
  61. U32 defaultFbWidth = init.m_window->getWidth();
  62. U32 defaultFbHeight = init.m_window->getHeight();
  63. TextureInitInfo texinit("FB Tex");
  64. texinit.m_width = defaultFbWidth;
  65. texinit.m_height = defaultFbHeight;
  66. texinit.m_format = Format::kR8G8B8A8_Unorm;
  67. texinit.m_usage =
  68. TextureUsageBit::kFramebufferWrite | TextureUsageBit::kImageComputeWrite | TextureUsageBit::kPresent;
  69. m_fakeFbTex = newTexture(texinit);
  70. TextureViewPtr view = newTextureView(TextureViewInitInfo(m_fakeFbTex, "FB view"));
  71. FramebufferInitInfo fbinit("Dflt FB");
  72. fbinit.m_colorAttachmentCount = 1;
  73. fbinit.m_colorAttachments[0].m_textureView = view;
  74. m_fakeDefaultFb = newFramebuffer(fbinit);
  75. }
  76. } // end namespace anki