// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include #include #include namespace anki { // Forward class NativeWindow; /// @addtogroup graphics /// @{ /// Manager initializer. class GrManagerInitInfo { public: AllocAlignedCallback m_allocCallback = nullptr; void* m_allocCallbackUserData = nullptr; CString m_cacheDirectory; }; /// The graphics manager, owner of all graphics objects. class GrManager : public MakeSingletonPtr { template friend class MakeSingletonPtr; public: Error init(GrManagerInitInfo& init); const GpuDeviceCapabilities& getDeviceCapabilities() const { return m_capabilities; } /// First call in the frame. Do that before everything else. void beginFrame(); /// Get next presentable image. The returned Texture is valid until the following swapBuffers. After that it might dissapear even if you hold the /// reference. TexturePtr acquireNextPresentableTexture(); /// End this frame. void endFrame(); /// Submit command buffers. Can be called outside beginFrame() endFrame(). /// @param[in] waitFences Optionally wait for some fences. /// @param[out] signalFence Optionaly create fence that will be signaled when the submission is done. void submit(WeakArray cmdbs, WeakArray waitFences = {}, FencePtr* signalFence = nullptr); void submit(CommandBuffer* cmdb, WeakArray waitFences = {}, FencePtr* signalFence = nullptr) { submit(WeakArray(&cmdb, 1), waitFences, signalFence); } /// Wait for all GPU work to finish. void finish(); /// @name Object creation methods. They are thread-safe. /// @{ [[nodiscard]] BufferPtr newBuffer(const BufferInitInfo& init); [[nodiscard]] TexturePtr newTexture(const TextureInitInfo& init); [[nodiscard]] SamplerPtr newSampler(const SamplerInitInfo& init); [[nodiscard]] ShaderPtr newShader(const ShaderInitInfo& init); [[nodiscard]] ShaderProgramPtr newShaderProgram(const ShaderProgramInitInfo& init); [[nodiscard]] CommandBufferPtr newCommandBuffer(const CommandBufferInitInfo& init); [[nodiscard]] OcclusionQueryPtr newOcclusionQuery(); [[nodiscard]] TimestampQueryPtr newTimestampQuery(); [[nodiscard]] PipelineQueryPtr newPipelineQuery(const PipelineQueryInitInfo& inf); [[nodiscard]] RenderGraphPtr newRenderGraph(); [[nodiscard]] GrUpscalerPtr newGrUpscaler(const GrUpscalerInitInfo& init); [[nodiscard]] AccelerationStructurePtr newAccelerationStructure(const AccelerationStructureInitInfo& init); /// @} /// Get the size of the acceleration structure if you are planning to supply a custom buffer. PtrSize getAccelerationStructureMemoryRequirement(const AccelerationStructureInitInfo& init) const; ANKI_INTERNAL CString getCacheDirectory() const { return m_cacheDir.toCString(); } ANKI_INTERNAL U32 getNewUuid() { return m_uuidIndex.fetchAdd(1); } protected: GrString m_cacheDir; Atomic m_uuidIndex = {1}; GpuDeviceCapabilities m_capabilities; GrManager(); virtual ~GrManager(); }; template<> template<> GrManager& MakeSingletonPtr::allocateSingleton<>(); template<> void MakeSingletonPtr::freeSingleton(); /// @} } // end namespace anki