| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- // Copyright (C) 2009-2023, 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/Utils/Drawer.h>
- #include <AnKi/Renderer/Utils/GpuVisibility.h>
- #include <AnKi/Renderer/Utils/HzbGenerator.h>
- #include <AnKi/Math.h>
- #include <AnKi/Gr.h>
- #include <AnKi/Resource/Forward.h>
- #include <AnKi/Collision/Forward.h>
- #include <AnKi/Renderer/Utils/Readback.h>
- namespace anki {
- // Forward
- extern BoolCVar g_vrsCVar;
- extern BoolCVar g_vrsLimitTo2x2CVar;
- extern BoolCVar g_preferComputeCVar;
- extern NumericCVar<F32> g_renderScalingCVar;
- extern BoolCVar g_rayTracedShadowsCVar;
- /// @addtogroup renderer
- /// @{
- /// Renderer statistics.
- class RendererPrecreatedSamplers
- {
- public:
- SamplerPtr m_nearestNearestClamp;
- SamplerPtr m_trilinearClamp;
- SamplerPtr m_trilinearRepeat;
- SamplerPtr m_trilinearRepeatAniso;
- SamplerPtr m_trilinearRepeatAnisoResolutionScalingBias;
- SamplerPtr m_trilinearClampShadow;
- };
- /// Offscreen renderer.
- class Renderer
- {
- public:
- Renderer();
- ~Renderer();
- #define ANKI_RENDERER_OBJECT_DEF(a, b) \
- a& get##a() \
- { \
- return *m_##b; \
- }
- #include <AnKi/Renderer/RendererObject.def.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(UVec2 swapchainSize, StackMemoryPool* framePool);
- /// This function does all the rendering stages and produces a final result.
- Error populateRenderGraph(RenderingContext& ctx);
- void finalize(const RenderingContext& ctx, Fence* fence);
- U64 getFrameCount() const
- {
- return m_frameCount;
- }
- const RenderableDrawer& getSceneDrawer() const
- {
- return m_sceneDrawer;
- }
- RenderableDrawer& getSceneDrawer()
- {
- return m_sceneDrawer;
- }
- GpuVisibility& getGpuVisibility()
- {
- return m_visibility;
- }
- GpuVisibilityNonRenderables& getGpuVisibilityNonRenderables()
- {
- return m_nonRenderablesVisibility;
- }
- GpuVisibilityAccelerationStructures& getGpuVisibilityAccelerationStructures()
- {
- return m_asVisibility;
- }
- const HzbGenerator& getHzbGenerator() const
- {
- return m_hzbGenerator;
- }
- ReadbackManager& getReadbackManager()
- {
- return m_readbaks;
- }
- /// 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());
- TextureView& getDummyTextureView2d() const
- {
- return *m_dummyTexView2d;
- }
- TextureView& getDummyTextureView3d() const
- {
- return *m_dummyTexView3d;
- }
- Buffer& getDummyBuffer() const
- {
- return *m_dummyBuff;
- }
- const RendererPrecreatedSamplers& getSamplers() const
- {
- return m_samplers;
- }
- 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;
- BufferHandle getGpuSceneBufferHandle() const
- {
- return m_runCtx.m_gpuSceneHandle;
- }
- /// @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.
- Bool getCurrentDebugRenderTarget(Array<RenderTargetHandle, kMaxDebugRenderTargets>& handles, ShaderProgramPtr& optionalShaderProgram);
- /// @}
- StackMemoryPool& getFrameMemoryPool() const
- {
- ANKI_ASSERT(m_framePool);
- return *m_framePool;
- }
- private:
- /// @name Rendering stages
- /// @{
- #define ANKI_RENDERER_OBJECT_DEF(a, b) UniquePtr<a, SingletonMemoryPoolDeleter<RendererMemoryPool>> m_##b;
- #include <AnKi/Renderer/RendererObject.def.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;
- GpuVisibility m_visibility;
- GpuVisibilityNonRenderables m_nonRenderablesVisibility;
- GpuVisibilityAccelerationStructures m_asVisibility;
- HzbGenerator m_hzbGenerator;
- ReadbackManager m_readbaks;
- U64 m_frameCount; ///< Frame number
- CommonMatrices m_prevMatrices;
- Array<Vec2, 64> m_jitterOffsets;
- TextureViewPtr m_dummyTexView2d;
- TextureViewPtr m_dummyTexView3d;
- BufferPtr m_dummyBuff;
- RendererPrecreatedSamplers m_samplers;
- ShaderProgramResourcePtr m_clearTexComputeProg;
- StackMemoryPool* m_framePool = nullptr;
- class DebugRtInfo
- {
- public:
- RendererObject* m_obj;
- RendererString m_rtName;
- };
- RendererDynamicArray<DebugRtInfo> m_debugRts;
- RendererString m_currentDebugRtName;
- class
- {
- public:
- BufferHandle m_gpuSceneHandle;
- } m_runCtx;
- Error initInternal(UVec2 swapchainSize);
- void gpuSceneCopy(RenderingContext& ctx);
- };
- /// @}
- } // end namespace anki
|