| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- // Copyright (C) 2009-2021, 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/StagingGpuMemoryManager.h>
- #include <AnKi/Collision/Forward.h>
- namespace anki
- {
- // Forward
- class ConfigSet;
- class ResourceManager;
- class StagingGpuMemoryManager;
- class UiManager;
- /// @addtogroup renderer
- /// @{
- /// Renderer statistics.
- class RendererPrecreatedSamplers
- {
- public:
- SamplerPtr m_nearestNearestClamp;
- SamplerPtr m_trilinearClamp;
- SamplerPtr m_trilinearRepeat;
- SamplerPtr m_trilinearRepeatAniso;
- };
- /// Offscreen renderer.
- class Renderer
- {
- public:
- Renderer();
- ~Renderer();
- ProbeReflections& getProbeReflections()
- {
- return *m_probeReflections;
- }
- VolumetricLightingAccumulation& getVolumetricLightingAccumulation()
- {
- return *m_volLighting;
- }
- ShadowMapping& getShadowMapping()
- {
- return *m_shadowMapping;
- }
- GBuffer& getGBuffer()
- {
- return *m_gbuffer;
- }
- LightShading& getLightShading()
- {
- return *m_lightShading;
- }
- DepthDownscale& getDepthDownscale()
- {
- return *m_depth;
- }
- ForwardShading& getForwardShading()
- {
- return *m_forwardShading;
- }
- VolumetricFog& getVolumetricFog()
- {
- return *m_volFog;
- }
- Tonemapping& getTonemapping()
- {
- return *m_tonemapping;
- }
- Ssao& getSsao()
- {
- return *m_ssao;
- }
- Bloom& getBloom()
- {
- return *m_bloom;
- }
- FinalComposite& getFinalComposite()
- {
- return *m_finalComposite;
- }
- Dbg& getDbg()
- {
- return *m_dbg;
- }
- TemporalAA& getTemporalAA()
- {
- return *m_temporalAA;
- }
- DownscaleBlur& getDownscaleBlur()
- {
- return *m_downscale;
- }
- LensFlare& getLensFlare()
- {
- return *m_lensFlare;
- }
- const LensFlare& getLensFlare() const
- {
- return *m_lensFlare;
- }
- const GlobalIllumination& getGlobalIllumination() const
- {
- return *m_gi;
- }
- UiStage& getUiStage()
- {
- return *m_uiStage;
- }
- ShadowmapsResolve& getShadowmapsResolve()
- {
- return *m_smResolve;
- }
- AccelerationStructureBuilder& getAccelerationStructureBuilder()
- {
- return *m_accelerationStructureBuilder;
- }
- RtShadows& getRtShadows()
- {
- return *m_rtShadows;
- }
- MotionVectors& getMotionVectors()
- {
- return *m_motionVectors;
- }
- Bool getRtShadowsEnabled() const
- {
- return m_rtShadows.isCreated();
- }
- Ssr& getSsr()
- {
- return *m_ssr;
- }
- Ssgi& getSsgi()
- {
- return *m_ssgi;
- }
- U32 getWidth() const
- {
- return m_width;
- }
- U32 getHeight() const
- {
- return m_height;
- }
- F32 getAspectRatio() const
- {
- return F32(m_width) / F32(m_height);
- }
- /// Init the renderer.
- ANKI_USE_RESULT Error init(ThreadHive* hive, ResourceManager* resources, GrManager* gr,
- StagingGpuMemoryManager* stagingMem, UiManager* ui, HeapAllocator<U8> alloc,
- const ConfigSet& config, Timestamp* globTimestamp);
- /// This function does all the rendering stages and produces a final result.
- ANKI_USE_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.
- ANKI_USE_RESULT 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.
- ANKI_USE_RESULT RenderTargetDescription create2DRenderTargetDescription(U32 w, U32 h, Format format,
- CString name = {});
- ANKI_USE_RESULT TexturePtr createAndClearRenderTarget(const TextureInitInfo& inf,
- const ClearValue& clearVal = ClearValue());
- GrManager& getGrManager()
- {
- return *m_gr;
- }
- HeapAllocator<U8> getAllocator() const
- {
- return m_alloc;
- }
- ResourceManager& getResourceManager()
- {
- return *m_resources;
- }
- 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;
- }
- StagingGpuMemoryManager& getStagingGpuMemoryManager()
- {
- 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;
- }
- /// @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;
- StagingGpuMemoryManager* m_stagingMem = nullptr;
- GrManager* m_gr = nullptr;
- UiManager* m_ui = nullptr;
- Timestamp* m_globTimestamp;
- HeapAllocator<U8> m_alloc;
- /// @name Rendering stages
- /// @{
- UniquePtr<VolumetricLightingAccumulation> m_volLighting;
- UniquePtr<GlobalIllumination> m_gi;
- UniquePtr<ProbeReflections> m_probeReflections;
- UniquePtr<ShadowMapping> m_shadowMapping; ///< Shadow mapping.
- UniquePtr<GBuffer> m_gbuffer; ///< Material rendering stage
- UniquePtr<GBufferPost> m_gbufferPost;
- UniquePtr<Ssr> m_ssr;
- UniquePtr<Ssgi> m_ssgi;
- UniquePtr<LightShading> m_lightShading; ///< Illumination rendering stage
- UniquePtr<DepthDownscale> m_depth;
- UniquePtr<ForwardShading> m_forwardShading; ///< Forward shading.
- UniquePtr<VolumetricFog> m_volFog; ///< Volumetric fog.
- UniquePtr<LensFlare> m_lensFlare; ///< Forward shading lens flares.
- UniquePtr<DownscaleBlur> m_downscale;
- UniquePtr<TemporalAA> m_temporalAA;
- UniquePtr<Tonemapping> m_tonemapping;
- UniquePtr<Ssao> m_ssao;
- UniquePtr<Bloom> m_bloom;
- UniquePtr<FinalComposite> m_finalComposite; ///< Postprocessing rendering stage
- UniquePtr<Dbg> m_dbg; ///< Debug stage.
- UniquePtr<UiStage> m_uiStage;
- UniquePtr<GenericCompute> m_genericCompute;
- UniquePtr<ShadowmapsResolve> m_smResolve;
- UniquePtr<AccelerationStructureBuilder> m_accelerationStructureBuilder;
- UniquePtr<RtShadows> m_rtShadows;
- UniquePtr<MotionVectors> m_motionVectors;
- UniquePtr<ClusterBinning> m_clusterBinning;
- /// @}
- U32 m_tileSize = 0;
- UVec2 m_tileCounts = UVec2(0u);
- U32 m_zSplitCount = 0;
- U32 m_width;
- U32 m_height;
- RenderableDrawer m_sceneDrawer;
- U64 m_frameCount; ///< Frame number
- U64 m_prevLoadRequestCount = 0;
- U64 m_prevAsyncTasksCompleted = 0;
- Bool m_resourcesDirty = true;
- CommonMatrices m_prevMatrices;
- Array<Mat4, 16> m_jitteredMats16x;
- Array<Mat4, 8> m_jitteredMats8x;
- 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;
- ANKI_USE_RESULT Error initInternal(const ConfigSet& initializer);
- void initJitteredMats();
- };
- /// @}
- } // end namespace anki
|