| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750 |
- // 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/Gr/GrObject.h>
- #include <AnKi/Gr/Enums.h>
- #include <AnKi/Gr/TextureView.h>
- #include <AnKi/Gr/Buffer.h>
- #include <AnKi/Gr/GrManager.h>
- #include <AnKi/Gr/Framebuffer.h>
- #include <AnKi/Gr/TimestampQuery.h>
- #include <AnKi/Gr/CommandBuffer.h>
- #include <AnKi/Gr/AccelerationStructure.h>
- #include <AnKi/Util/HashMap.h>
- #include <AnKi/Util/BitSet.h>
- #include <AnKi/Util/WeakArray.h>
- #include <AnKi/Util/Function.h>
- namespace anki
- {
- // Forward
- class RenderGraph;
- class RenderGraphDescription;
- /// @addtogroup graphics
- /// @{
- /// @name RenderGraph constants
- /// @{
- constexpr U32 MAX_RENDER_GRAPH_PASSES = 128;
- constexpr U32 MAX_RENDER_GRAPH_RENDER_TARGETS = 64; ///< Max imported or not render targets in RenderGraph.
- constexpr U32 MAX_RENDER_GRAPH_BUFFERS = 64;
- constexpr U32 MAX_RENDER_GRAPH_ACCELERATION_STRUCTURES = 32;
- /// @}
- /// Render target handle used in the RenderGraph.
- /// @memberof RenderGraphDescription
- class RenderGraphGrObjectHandle
- {
- friend class RenderPassDependency;
- friend class RenderGraphDescription;
- friend class RenderGraph;
- friend class RenderPassDescriptionBase;
- public:
- Bool operator==(const RenderGraphGrObjectHandle& b) const
- {
- return m_idx == b.m_idx;
- }
- Bool operator!=(const RenderGraphGrObjectHandle& b) const
- {
- return m_idx != b.m_idx;
- }
- Bool isValid() const
- {
- return m_idx != MAX_U32;
- }
- private:
- U32 m_idx = MAX_U32;
- };
- /// Render target (TexturePtr) handle.
- /// @memberof RenderGraphDescription
- class RenderTargetHandle : public RenderGraphGrObjectHandle
- {
- };
- /// BufferPtr handle.
- /// @memberof RenderGraphDescription
- class BufferHandle : public RenderGraphGrObjectHandle
- {
- };
- /// AccelerationStructurePtr handle.
- /// @memberof RenderGraphDescription
- class AccelerationStructureHandle : public RenderGraphGrObjectHandle
- {
- };
- /// Describes the render target.
- /// @memberof RenderGraphDescription
- class RenderTargetDescription : public TextureInitInfo
- {
- friend class RenderGraphDescription;
- public:
- RenderTargetDescription()
- {
- }
- RenderTargetDescription(CString name)
- : TextureInitInfo(name)
- {
- }
- /// Create an internal hash.
- void bake()
- {
- ANKI_ASSERT(m_hash == 0);
- ANKI_ASSERT(m_usage == TextureUsageBit::NONE && "No need to supply the usage. RenderGraph will find out");
- m_hash = computeHash();
- }
- private:
- U64 m_hash = 0;
- };
- /// The only parameter of RenderPassWorkCallback.
- /// @memberof RenderGraph
- class RenderPassWorkContext
- {
- friend class RenderGraph;
- public:
- CommandBufferPtr m_commandBuffer;
- U32 m_currentSecondLevelCommandBufferIndex ANKI_DEBUG_CODE(= 0);
- U32 m_secondLevelCommandBufferCount ANKI_DEBUG_CODE(= 0);
- void getBufferState(BufferHandle handle, BufferPtr& buff) const;
- void getRenderTargetState(RenderTargetHandle handle, const TextureSubresourceInfo& subresource,
- TexturePtr& tex) const;
- /// Convenience method.
- void bindTextureAndSampler(U32 set, U32 binding, RenderTargetHandle handle,
- const TextureSubresourceInfo& subresource, const SamplerPtr& sampler)
- {
- TexturePtr tex;
- getRenderTargetState(handle, subresource, tex);
- TextureViewInitInfo viewInit(tex, subresource, "TmpRenderGraph");
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindTextureAndSampler(set, binding, view, sampler);
- }
- /// Convenience method.
- void bindTexture(U32 set, U32 binding, RenderTargetHandle handle, const TextureSubresourceInfo& subresource)
- {
- TexturePtr tex;
- getRenderTargetState(handle, subresource, tex);
- TextureViewInitInfo viewInit(tex, subresource, "TmpRenderGraph");
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindTexture(set, binding, view);
- }
- /// Convenience method to bind the whole texture as color.
- void bindColorTextureAndSampler(U32 set, U32 binding, RenderTargetHandle handle, const SamplerPtr& sampler)
- {
- TexturePtr tex = getTexture(handle);
- TextureViewInitInfo viewInit(tex); // Use the whole texture
- getRenderTargetState(handle, viewInit, tex);
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindTextureAndSampler(set, binding, view, sampler);
- }
- /// Convenience method to bind the whole texture as color.
- void bindColorTexture(U32 set, U32 binding, RenderTargetHandle handle, U32 arrayIdx = 0)
- {
- TexturePtr tex = getTexture(handle);
- TextureViewInitInfo viewInit(tex); // Use the whole texture
- getRenderTargetState(handle, viewInit, tex);
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindTexture(set, binding, view, arrayIdx);
- }
- /// Convenience method.
- void bindImage(U32 set, U32 binding, RenderTargetHandle handle, const TextureSubresourceInfo& subresource,
- U32 arrayIdx = 0)
- {
- TexturePtr tex;
- getRenderTargetState(handle, subresource, tex);
- TextureViewInitInfo viewInit(tex, subresource, "TmpRenderGraph");
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindImage(set, binding, view, arrayIdx);
- }
- /// Convenience method to bind the whole image.
- void bindImage(U32 set, U32 binding, RenderTargetHandle handle, U32 arrayIdx = 0)
- {
- TexturePtr tex;
- #if ANKI_ENABLE_ASSERTIONS
- tex = getTexture(handle);
- ANKI_ASSERT(tex->getLayerCount() == 1 && tex->getMipmapCount() == 1
- && tex->getDepthStencilAspect() == DepthStencilAspectBit::NONE);
- #endif
- const TextureSubresourceInfo subresource;
- getRenderTargetState(handle, subresource, tex);
- TextureViewInitInfo viewInit(tex, subresource, "TmpRenderGraph");
- TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
- m_commandBuffer->bindImage(set, binding, view, arrayIdx);
- }
- /// Convenience method.
- void bindStorageBuffer(U32 set, U32 binding, BufferHandle handle)
- {
- BufferPtr buff;
- getBufferState(handle, buff);
- m_commandBuffer->bindStorageBuffer(set, binding, buff, 0, MAX_PTR_SIZE);
- }
- /// Convenience method.
- void bindUniformBuffer(U32 set, U32 binding, BufferHandle handle)
- {
- BufferPtr buff;
- getBufferState(handle, buff);
- m_commandBuffer->bindUniformBuffer(set, binding, buff, 0, MAX_PTR_SIZE);
- }
- /// Convenience method.
- void bindAccelerationStructure(U32 set, U32 binding, AccelerationStructureHandle handle);
- private:
- const RenderGraph* m_rgraph ANKI_DEBUG_CODE(= nullptr);
- U32 m_passIdx ANKI_DEBUG_CODE(= MAX_U32);
- U32 m_batchIdx ANKI_DEBUG_CODE(= MAX_U32);
- TexturePtr getTexture(RenderTargetHandle handle) const;
- };
- /// RenderGraph pass dependency.
- /// @memberof RenderGraphDescription
- class RenderPassDependency
- {
- friend class RenderGraph;
- friend class RenderPassDescriptionBase;
- public:
- /// Dependency to a texture subresource.
- RenderPassDependency(RenderTargetHandle handle, TextureUsageBit usage, const TextureSubresourceInfo& subresource)
- : m_texture({handle, usage, subresource})
- , m_type(Type::TEXTURE)
- {
- ANKI_ASSERT(handle.isValid());
- }
- /// Dependency to the whole texture.
- RenderPassDependency(RenderTargetHandle handle, TextureUsageBit usage,
- DepthStencilAspectBit aspect = DepthStencilAspectBit::NONE)
- : m_texture({handle, usage, TextureSubresourceInfo()})
- , m_type(Type::TEXTURE)
- {
- ANKI_ASSERT(handle.isValid());
- m_texture.m_subresource.m_mipmapCount = MAX_U32; // Mark it as "whole texture"
- m_texture.m_subresource.m_depthStencilAspect = aspect;
- }
- RenderPassDependency(BufferHandle handle, BufferUsageBit usage)
- : m_buffer({handle, usage})
- , m_type(Type::BUFFER)
- {
- ANKI_ASSERT(handle.isValid());
- }
- RenderPassDependency(AccelerationStructureHandle handle, AccelerationStructureUsageBit usage)
- : m_as({handle, usage})
- , m_type(Type::ACCELERATION_STRUCTURE)
- {
- ANKI_ASSERT(handle.isValid());
- }
- private:
- class TextureInfo
- {
- public:
- RenderTargetHandle m_handle;
- TextureUsageBit m_usage;
- TextureSubresourceInfo m_subresource;
- };
- class BufferInfo
- {
- public:
- BufferHandle m_handle;
- BufferUsageBit m_usage;
- };
- class ASInfo
- {
- public:
- AccelerationStructureHandle m_handle;
- AccelerationStructureUsageBit m_usage;
- };
- union
- {
- TextureInfo m_texture;
- BufferInfo m_buffer;
- ASInfo m_as;
- };
- enum class Type : U8
- {
- BUFFER,
- TEXTURE,
- ACCELERATION_STRUCTURE
- };
- Type m_type;
- };
- /// The base of compute/transfer and graphics renderpasses for RenderGraph.
- /// @memberof RenderGraphDescription
- class RenderPassDescriptionBase
- {
- friend class RenderGraph;
- friend class RenderGraphDescription;
- public:
- virtual ~RenderPassDescriptionBase()
- {
- m_name.destroy(m_alloc); // To avoid the assertion
- m_rtDeps.destroy(m_alloc);
- m_buffDeps.destroy(m_alloc);
- m_asDeps.destroy(m_alloc);
- m_callback.destroy(m_alloc);
- }
- template<typename TFunc>
- void setWork(U32 secondLeveCmdbCount, TFunc func)
- {
- ANKI_ASSERT(m_type == Type::GRAPHICS || secondLeveCmdbCount == 0);
- m_callback.init(m_alloc, func);
- m_secondLevelCmdbsCount = secondLeveCmdbCount;
- }
- template<typename TFunc>
- void setWork(TFunc func)
- {
- setWork(0, func);
- }
- /// Add a new consumer or producer dependency.
- void newDependency(const RenderPassDependency& dep);
- protected:
- enum class Type : U8
- {
- GRAPHICS,
- NO_GRAPHICS
- };
- Type m_type;
- StackAllocator<U8> m_alloc;
- RenderGraphDescription* m_descr;
- Function<void(RenderPassWorkContext&)> m_callback;
- U32 m_secondLevelCmdbsCount = 0;
- DynamicArray<RenderPassDependency> m_rtDeps;
- DynamicArray<RenderPassDependency> m_buffDeps;
- DynamicArray<RenderPassDependency> m_asDeps;
- BitSet<MAX_RENDER_GRAPH_RENDER_TARGETS, U64> m_readRtMask{false};
- BitSet<MAX_RENDER_GRAPH_RENDER_TARGETS, U64> m_writeRtMask{false};
- BitSet<MAX_RENDER_GRAPH_BUFFERS, U64> m_readBuffMask{false};
- BitSet<MAX_RENDER_GRAPH_BUFFERS, U64> m_writeBuffMask{false};
- BitSet<MAX_RENDER_GRAPH_ACCELERATION_STRUCTURES, U32> m_readAsMask{false};
- BitSet<MAX_RENDER_GRAPH_ACCELERATION_STRUCTURES, U32> m_writeAsMask{false};
- String m_name;
- RenderPassDescriptionBase(Type t, RenderGraphDescription* descr)
- : m_type(t)
- , m_descr(descr)
- {
- ANKI_ASSERT(descr);
- }
- void setName(CString name)
- {
- m_name.create(m_alloc, (name.isEmpty()) ? "N/A" : name);
- }
- void fixSubresource(RenderPassDependency& dep) const;
- void validateDep(const RenderPassDependency& dep);
- };
- /// Framebuffer attachment info.
- class FramebufferDescriptionAttachment
- {
- public:
- TextureSurfaceInfo m_surface;
- AttachmentLoadOperation m_loadOperation = AttachmentLoadOperation::CLEAR;
- AttachmentStoreOperation m_storeOperation = AttachmentStoreOperation::STORE;
- ClearValue m_clearValue;
- AttachmentLoadOperation m_stencilLoadOperation = AttachmentLoadOperation::CLEAR;
- AttachmentStoreOperation m_stencilStoreOperation = AttachmentStoreOperation::STORE;
- DepthStencilAspectBit m_aspect = DepthStencilAspectBit::NONE; ///< Relevant only for depth stencil textures.
- };
- /// Describes a framebuffer.
- /// @memberof RenderGraphDescription
- class FramebufferDescription
- {
- friend class GraphicsRenderPassDescription;
- friend class RenderGraph;
- public:
- Array<FramebufferDescriptionAttachment, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
- U32 m_colorAttachmentCount = 0;
- FramebufferDescriptionAttachment m_depthStencilAttachment;
- /// Calculate the hash for the framebuffer.
- void bake();
- Bool isBacked() const
- {
- return m_hash != 0;
- }
- private:
- U64 m_hash = 0;
- };
- /// A graphics render pass for RenderGraph.
- /// @memberof RenderGraphDescription
- class GraphicsRenderPassDescription : public RenderPassDescriptionBase
- {
- friend class RenderGraphDescription;
- friend class RenderGraph;
- template<typename, typename>
- friend class GenericPoolAllocator;
- public:
- void setFramebufferInfo(const FramebufferDescription& fbInfo,
- ConstWeakArray<RenderTargetHandle> colorRenderTargetHandles,
- RenderTargetHandle depthStencilRenderTargetHandle, U32 minx = 0, U32 miny = 0,
- U32 maxx = MAX_U32, U32 maxy = MAX_U32);
- void setFramebufferInfo(const FramebufferDescription& fbInfo,
- std::initializer_list<RenderTargetHandle> colorRenderTargetHandles,
- RenderTargetHandle depthStencilRenderTargetHandle, U32 minx = 0, U32 miny = 0,
- U32 maxx = MAX_U32, U32 maxy = MAX_U32);
- private:
- Array<RenderTargetHandle, MAX_COLOR_ATTACHMENTS + 1> m_rtHandles;
- FramebufferDescription m_fbDescr;
- Array<U32, 4> m_fbRenderArea = {};
- GraphicsRenderPassDescription(RenderGraphDescription* descr)
- : RenderPassDescriptionBase(Type::GRAPHICS, descr)
- {
- memset(&m_rtHandles[0], 0xFF, sizeof(m_rtHandles));
- }
- Bool hasFramebuffer() const
- {
- return m_fbDescr.m_hash != 0;
- }
- };
- /// A compute render pass for RenderGraph.
- /// @memberof RenderGraphDescription
- class ComputeRenderPassDescription : public RenderPassDescriptionBase
- {
- friend class RenderGraphDescription;
- template<typename, typename>
- friend class GenericPoolAllocator;
- private:
- ComputeRenderPassDescription(RenderGraphDescription* descr)
- : RenderPassDescriptionBase(Type::NO_GRAPHICS, descr)
- {
- }
- };
- /// Builds the description of the frame's render passes and their interactions.
- /// @memberof RenderGraph
- class RenderGraphDescription
- {
- friend class RenderGraph;
- friend class RenderPassDescriptionBase;
- public:
- RenderGraphDescription(const StackAllocator<U8>& alloc)
- : m_alloc(alloc)
- {
- }
- ~RenderGraphDescription();
- /// Create a new graphics render pass.
- GraphicsRenderPassDescription& newGraphicsRenderPass(CString name);
- /// Create a new compute render pass.
- ComputeRenderPassDescription& newComputeRenderPass(CString name);
- /// Import an existing render target and let the render graph know about it's up-to-date usage.
- RenderTargetHandle importRenderTarget(TexturePtr tex, TextureUsageBit usage);
- /// Import an existing render target and let the render graph find it's current usage by looking at the previous
- /// frame.
- RenderTargetHandle importRenderTarget(TexturePtr tex);
- /// Get or create a new render target.
- RenderTargetHandle newRenderTarget(const RenderTargetDescription& initInf);
- /// Import a buffer.
- BufferHandle importBuffer(BufferPtr buff, BufferUsageBit usage, PtrSize offset = 0, PtrSize range = MAX_PTR_SIZE);
- /// Import an AS.
- AccelerationStructureHandle importAccelerationStructure(AccelerationStructurePtr as,
- AccelerationStructureUsageBit usage);
- /// Gather statistics.
- void setStatisticsEnabled(Bool gather)
- {
- m_gatherStatistics = gather;
- }
- private:
- class Resource
- {
- public:
- Array<char, MAX_GR_OBJECT_NAME_LENGTH + 1> m_name;
- void setName(CString name)
- {
- const U len = name.getLength();
- ANKI_ASSERT(len <= MAX_GR_OBJECT_NAME_LENGTH);
- strcpy(&m_name[0], (len) ? &name[0] : "unnamed");
- }
- };
- class RT : public Resource
- {
- public:
- TextureInitInfo m_initInfo;
- U64 m_hash = 0;
- TexturePtr m_importedTex;
- TextureUsageBit m_importedLastKnownUsage = TextureUsageBit::NONE;
- /// Derived by the deps of this RT and will be used to set its usage.
- TextureUsageBit m_usageDerivedByDeps = TextureUsageBit::NONE;
- Bool m_importedAndUndefinedUsage = false;
- };
- class Buffer : public Resource
- {
- public:
- BufferUsageBit m_usage;
- BufferPtr m_importedBuff;
- PtrSize m_offset;
- PtrSize m_range;
- };
- class AS : public Resource
- {
- public:
- AccelerationStructurePtr m_importedAs;
- AccelerationStructureUsageBit m_usage;
- };
- StackAllocator<U8> m_alloc;
- DynamicArray<RenderPassDescriptionBase*> m_passes;
- DynamicArray<RT> m_renderTargets;
- DynamicArray<Buffer> m_buffers;
- DynamicArray<AS> m_as;
- Bool m_gatherStatistics = false;
- /// Return true if 2 buffer ranges overlap.
- static Bool bufferRangeOverlaps(PtrSize offsetA, PtrSize rangeA, PtrSize offsetB, PtrSize rangeB)
- {
- ANKI_ASSERT(rangeA > 0 && rangeB > 0);
- if(rangeA == MAX_PTR_SIZE || rangeB == MAX_PTR_SIZE)
- {
- return true;
- }
- else if(offsetA <= offsetB)
- {
- return offsetA + rangeA >= offsetB;
- }
- else
- {
- return offsetB + rangeB >= offsetA;
- }
- }
- };
- /// Statistics.
- /// @memberof RenderGraph
- class RenderGraphStatistics
- {
- public:
- Second m_gpuTime; ///< Time spent in the GPU.
- Second m_cpuStartTime; ///< Time the work was submited from the CPU (almost)
- };
- /// Accepts a descriptor of the frame's render passes and sets the dependencies between them.
- ///
- /// The idea for the RenderGraph is to automate:
- /// - Synchronization (barriers, events etc) between passes.
- /// - Command buffer creation for primary and secondary command buffers.
- /// - Framebuffer creation.
- /// - Render target creation (optional since textures can be imported as well).
- ///
- /// It accepts a description of the frame's render passes (compute and graphics), compiles that description to calculate
- /// dependencies and then populates command buffers with the help of multiple RenderPassWorkCallback.
- class RenderGraph final : public GrObject
- {
- ANKI_GR_OBJECT
- friend class RenderPassWorkContext;
- public:
- static const GrObjectType CLASS_TYPE = GrObjectType::RENDER_GRAPH;
- /// @name 1st step methods
- /// @{
- void compileNewGraph(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
- /// @}
- /// @name 2nd step methods
- /// @{
- /// Will call a number of RenderPassWorkCallback that populate 2nd level command buffers.
- void runSecondLevel(U32 threadIdx);
- /// @}
- /// @name 3rd step methods
- /// @{
- /// Will call a number of RenderPassWorkCallback that populate 1st level command buffers.
- void run() const;
- /// @}
- /// @name 3rd step methods
- /// @{
- void flush();
- /// @}
- /// @name 4th step methods
- /// @{
- /// Reset the graph for a new frame. All previously created RenderGraphHandle are invalid after that call.
- void reset();
- /// @}
- /// @name 5th step methods [OPTIONAL]
- /// @{
- /// Get some statistics.
- void getStatistics(RenderGraphStatistics& statistics) const;
- /// @}
- private:
- static constexpr U PERIODIC_CLEANUP_EVERY = 60; ///< How many frames between cleanups.
- // Forward declarations of internal classes.
- class BakeContext;
- class Pass;
- class Batch;
- class RT;
- class Buffer;
- class AS;
- class TextureBarrier;
- class BufferBarrier;
- class ASBarrier;
- /// Render targets of the same type+size+format.
- class RenderTargetCacheEntry
- {
- public:
- DynamicArray<TexturePtr> m_textures;
- U32 m_texturesInUse = 0;
- };
- /// Info on imported render targets that are kept between runs.
- class ImportedRenderTargetInfo
- {
- public:
- DynamicArray<TextureUsageBit> m_surfOrVolLastUsages; ///< Last TextureUsageBit of the imported RT.
- };
- HashMap<U64, RenderTargetCacheEntry> m_renderTargetCache; ///< Non-imported render targets.
- HashMap<U64, FramebufferPtr> m_fbCache; ///< Framebuffer cache.
- HashMap<U64, ImportedRenderTargetInfo> m_importedRenderTargets;
- BakeContext* m_ctx = nullptr;
- U64 m_version = 0;
- static constexpr U MAX_TIMESTAMPS_BUFFERED = MAX_FRAMES_IN_FLIGHT + 1;
- class
- {
- public:
- Array<TimestampQueryPtr, MAX_TIMESTAMPS_BUFFERED * 2> m_timestamps;
- Array<Second, MAX_TIMESTAMPS_BUFFERED> m_cpuStartTimes;
- U8 m_nextTimestamp = 0;
- } m_statistics;
- RenderGraph(GrManager* manager, CString name);
- ~RenderGraph();
- static ANKI_USE_RESULT RenderGraph* newInstance(GrManager* manager);
- BakeContext* newContext(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
- void initRenderPassesAndSetDeps(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
- void initBatches();
- void initGraphicsPasses(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
- void setBatchBarriers(const RenderGraphDescription& descr);
- TexturePtr getOrCreateRenderTarget(const TextureInitInfo& initInf, U64 hash);
- FramebufferPtr getOrCreateFramebuffer(const FramebufferDescription& fbDescr, const RenderTargetHandle* rtHandles,
- CString name, Bool& drawsToPresentableTex);
- /// Every N number of frames clean unused cached items.
- void periodicCleanup();
- ANKI_HOT static Bool passADependsOnB(const RenderPassDescriptionBase& a, const RenderPassDescriptionBase& b);
- static Bool overlappingTextureSubresource(const TextureSubresourceInfo& suba, const TextureSubresourceInfo& subb);
- static Bool passHasUnmetDependencies(const BakeContext& ctx, U32 passIdx);
- void setTextureBarrier(Batch& batch, const RenderPassDependency& consumer);
- template<typename TFunc>
- static void iterateSurfsOrVolumes(const TexturePtr& tex, const TextureSubresourceInfo& subresource, TFunc func);
- void getCrntUsage(RenderTargetHandle handle, U32 batchIdx, const TextureSubresourceInfo& subresource,
- TextureUsageBit& usage) const;
- /// @name Dump the dependency graph into a file.
- /// @{
- ANKI_USE_RESULT Error dumpDependencyDotFile(const RenderGraphDescription& descr, const BakeContext& ctx,
- CString path) const;
- static StringAuto textureUsageToStr(StackAllocator<U8>& alloc, TextureUsageBit usage);
- static StringAuto bufferUsageToStr(StackAllocator<U8>& alloc, BufferUsageBit usage);
- static StringAuto asUsageToStr(StackAllocator<U8>& alloc, AccelerationStructureUsageBit usage);
- /// @}
- TexturePtr getTexture(RenderTargetHandle handle) const;
- BufferPtr getBuffer(BufferHandle handle) const;
- AccelerationStructurePtr getAs(AccelerationStructureHandle handle) const;
- };
- /// @}
- } // end namespace anki
- #include <AnKi/Gr/RenderGraph.inl.h>
|