| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Renderer/Common.h>
- #include <AnKi/Renderer/Drawer.h>
- #include <AnKi/Math.h>
- #include <AnKi/Gr.h>
- #include <AnKi/Resource/Forward.h>
- #include <AnKi/Core/GpuMemoryPools.h>
- #include <AnKi/Collision/Forward.h>
- namespace anki {
- // Forward
- class ConfigSet;
- class ResourceManager;
- class StagingGpuMemoryPool;
- class UiManager;
- /// @addtogroup renderer
- /// @{
- /// Renderer statistics.
- class RendererPrecreatedSamplers
- {
- public:
- SamplerPtr m_nearestNearestClamp;
- SamplerPtr m_trilinearClamp;
- SamplerPtr m_trilinearRepeat;
- SamplerPtr m_trilinearRepeatAniso;
- SamplerPtr m_trilinearRepeatAnisoResolutionScalingBias;
- };
- /// Offscreen renderer.
- class Renderer
- {
- public:
- Renderer();
- ~Renderer();
- #define ANKI_RENDERER_OBJECT_DEF(a, b) \
- a& get##a() \
- { \
- return *m_##b; \
- }
- #include <AnKi/Renderer/RendererObject.defs.h>
- #undef ANKI_RENDERER_OBJECT_DEF
- Bool getRtShadowsEnabled() const
- {
- return m_rtShadows.isCreated();
- }
- const UVec2& getInternalResolution() const
- {
- return m_internalResolution;
- }
- const UVec2& getPostProcessResolution() const
- {
- return m_postProcessResolution;
- }
- F32 getAspectRatio() const
- {
- return F32(m_internalResolution.x()) / F32(m_internalResolution.y());
- }
- /// Init the renderer.
- Error init(ThreadHive* hive, ResourceManager* resources, GrManager* gr, StagingGpuMemoryPool* stagingMem,
- UiManager* ui, HeapAllocator<U8> alloc, ConfigSet* config, Timestamp* globTimestamp,
- UVec2 swapchainSize);
- /// This function does all the rendering stages and produces a final result.
- Error populateRenderGraph(RenderingContext& ctx);
- void finalize(const RenderingContext& ctx);
- U64 getFrameCount() const
- {
- return m_frameCount;
- }
- const RenderableDrawer& getSceneDrawer() const
- {
- return m_sceneDrawer;
- }
- RenderableDrawer& getSceneDrawer()
- {
- return m_sceneDrawer;
- }
- UiManager& getUiManager()
- {
- ANKI_ASSERT(m_ui);
- return *m_ui;
- }
- /// Create the init info for a 2D texture that will be used as a render target.
- [[nodiscard]] TextureInitInfo create2DRenderTargetInitInfo(U32 w, U32 h, Format format, TextureUsageBit usage,
- CString name = {});
- /// Create the init info for a 2D texture that will be used as a render target.
- [[nodiscard]] RenderTargetDescription create2DRenderTargetDescription(U32 w, U32 h, Format format,
- CString name = {});
- [[nodiscard]] TexturePtr createAndClearRenderTarget(const TextureInitInfo& inf, TextureUsageBit initialUsage,
- const ClearValue& clearVal = ClearValue());
- GrManager& getGrManager()
- {
- return *m_gr;
- }
- HeapAllocator<U8> getAllocator() const
- {
- return m_alloc;
- }
- ResourceManager& getResourceManager()
- {
- return *m_resources;
- }
- const ConfigSet& getConfig() const
- {
- ANKI_ASSERT(m_config);
- return *m_config;
- }
- Timestamp getGlobalTimestamp() const
- {
- return *m_globTimestamp;
- }
- Timestamp* getGlobalTimestampPtr()
- {
- return m_globTimestamp;
- }
- /// Returns true if there were resources loaded or loading async tasks that got completed.
- Bool resourcesLoaded() const
- {
- return m_resourcesDirty;
- }
- TextureViewPtr getDummyTextureView2d() const
- {
- return m_dummyTexView2d;
- }
- TextureViewPtr getDummyTextureView3d() const
- {
- return m_dummyTexView3d;
- }
- BufferPtr getDummyBuffer() const
- {
- return m_dummyBuff;
- }
- const RendererPrecreatedSamplers& getSamplers() const
- {
- return m_samplers;
- }
- StagingGpuMemoryPool& getStagingGpuMemory()
- {
- ANKI_ASSERT(m_stagingMem);
- return *m_stagingMem;
- }
- ThreadHive& getThreadHive()
- {
- ANKI_ASSERT(m_threadHive);
- return *m_threadHive;
- }
- const ThreadHive& getThreadHive() const
- {
- ANKI_ASSERT(m_threadHive);
- return *m_threadHive;
- }
- U32 getTileSize() const
- {
- return m_tileSize;
- }
- const UVec2& getTileCounts() const
- {
- return m_tileCounts;
- }
- U32 getZSplitCount() const
- {
- return m_zSplitCount;
- }
- Format getHdrFormat() const;
- Format getDepthNoStencilFormat() const;
- /// @name Debug render targets
- /// @{
- /// Register a debug render target.
- void registerDebugRenderTarget(RendererObject* obj, CString rtName);
- /// Set the render target you want to show.
- void setCurrentDebugRenderTarget(CString rtName);
- /// Get the render target currently showing.
- CString getCurrentDebugRenderTarget() const
- {
- return m_currentDebugRtName;
- }
- // Need to call it after the handle is set by the RenderGraph.
- void getCurrentDebugRenderTarget(RenderTargetHandle& handle, Bool& handleValid,
- ShaderProgramPtr& optionalShaderProgram);
- /// @}
- private:
- ResourceManager* m_resources = nullptr;
- ThreadHive* m_threadHive = nullptr;
- StagingGpuMemoryPool* m_stagingMem = nullptr;
- GrManager* m_gr = nullptr;
- UiManager* m_ui = nullptr;
- Timestamp* m_globTimestamp = nullptr;
- ConfigSet* m_config = nullptr;
- HeapAllocator<U8> m_alloc;
- /// @name Rendering stages
- /// @{
- #define ANKI_RENDERER_OBJECT_DEF(a, b) UniquePtr<a> m_##b;
- #include <AnKi/Renderer/RendererObject.defs.h>
- #undef ANKI_RENDERER_OBJECT_DEF
- /// @}
- U32 m_tileSize = 0;
- UVec2 m_tileCounts = UVec2(0u);
- U32 m_zSplitCount = 0;
- UVec2 m_internalResolution = UVec2(0u); ///< The resolution of all passes up until TAA.
- UVec2 m_postProcessResolution = UVec2(0u); ///< The resolution of post processing and following passes.
- RenderableDrawer m_sceneDrawer;
- U64 m_frameCount; ///< Frame number
- U64 m_prevLoadRequestCount = 0;
- U64 m_prevAsyncTasksCompleted = 0;
- Bool m_resourcesDirty = true;
- CommonMatrices m_prevMatrices;
- Array<Vec2, 64> m_jitterOffsets;
- TextureViewPtr m_dummyTexView2d;
- TextureViewPtr m_dummyTexView3d;
- BufferPtr m_dummyBuff;
- RendererPrecreatedSamplers m_samplers;
- ShaderProgramResourcePtr m_clearTexComputeProg;
- class DebugRtInfo
- {
- public:
- RendererObject* m_obj;
- String m_rtName;
- };
- DynamicArray<DebugRtInfo> m_debugRts;
- String m_currentDebugRtName;
- Error initInternal(UVec2 swapchainSize);
- };
- /// @}
- } // end namespace anki
|