Foundation
Loading...
Searching...
No Matches
Renderer.hpp
Go to the documentation of this file.
1#pragma once
3#include <Core/Logging.hpp>
4#include <Core/ThreadPool.hpp>
5#include "RenderPass.hpp"
6#include "RenderResource.hpp"
7#include "Shader.hpp"
12{
17 {
32 bool asyncCompute{true};
39 bool present{true};
44 uint32_t threadCount{std::max(1u, std::thread::hardware_concurrency() - 1)};
59 bool profilePasses{true};
60 };
61 /* -- Constants -- */
62 // Maximum number of render passes per frame
63 // NOTE: The limit here is mostly arbitrary - and is only used
64 // for the default priority heuristic when determining pass order.
65 constexpr size_t kMaxRenderPasses = 1024;
66 // Maximum number of command lists per frame
68 // Maximum size of the per-frame transient arena (16MB)
69 constexpr size_t kExecuteArenaSize = 16 * (1 << 20);
70 const RHIPipelineStage kComputeStagesMask = RHIPipelineStageBits::FragmentShader |
71 RHIPipelineStageBits::VertexShader | RHIPipelineStageBits::MeshShader | RHIPipelineStageBits::RayTracingShader |
72 RHIPipelineStageBits::AllGraphics;
73 const RHIResourceAccessBits kAllShaderWrites = RHIResourceAccessBits::ShaderWrite |
74 RHIResourceAccessBits::RenderTargetWrite | RHIResourceAccessBits::DepthStencilWrite |
75 RHIResourceAccessBits::TransferWrite | RHIResourceAccessBits::HostWrite;
76 const RHIResourceAccessBits kAllShaderReads = RHIResourceAccessBits::ShaderRead |
77 RHIResourceAccessBits::RenderTargetRead | RHIResourceAccessBits::UniformRead |
78 RHIResourceAccessBits::TransferRead | RHIResourceAccessBits::HostRead;
89 {
94 {
99 // Backbuffer specializations
101 // [resource, view desc]
104 // [resource, ord range]
106 // Passes ordered by pass.ord
110 // Execution grouped by queue type
112 {
113 const int groupIndex{}; // Index in executionGroups
114 int graphicsGroupIndex{-1}; // Index of all unique graphics groups before this one
115 int computeGroupIndex{-1}; // Index of all unique compute groups before this one
118 // Resources used in this group
120 bool isLastGraphics = false;
121 bool isLastCompute = false;
122
127 };
132 {
134 while (u >= graph.size())
135 graph.emplace_back(graph.get_allocator());
136 graph[u].emplace_back(v, hdl);
137 while (v >= in.size())
138 in.push_back(0);
139 in[v]++;
140 }
147 };
148
149 public:
150 enum class State
151 {
152 Undefined, // Initialized
153 Setup, // During BeginSetup(), EndSetup(). No work on the GPU yet.
154 PostSetup, // Safe state (with a device wait), after EndSetup(), EndExecute()
155 Execute // During BeginExecute(), EndExecute()
156 };
157
158 private:
161
163
164 uint64_t mFrameSwapped{0}; // Frame rendered in the current Swapchain
165
166 uint32_t mFrameSwaps{1}; // Max frames in flight
169
173 // Per swap primitives
198
200 // Semaphore for async compute
205
207 // Setup
209 RHITextureViewDesc const& desc) const;
210 // PostSetup
211 void CullPasses(PassHandle epilogue) const;
214 void FinalizeResources();
215 void FinalizePasses();
216 // Temporary memory arena for execution
218 // Temporary allocator for execution
219 // This is reset every frame, and only guaranteed to be valid during Execute state.
221 // Temporary storage for submits calls
222 // This is reset every frame, and only guaranteed to be valid during Execute state.
224 // Thread pool for concurrent command list recording
237 // [current sync][thread id]
250 {
251 switch (queue)
252 {
253 case RHIDeviceQueueType::Undefined:
255 case RHIDeviceQueueType::Graphics:
257 case RHIDeviceQueueType::Compute:
259 default:
260 throw std::runtime_error("Unhandled queue type");
261 }
262 }
292 void SetFrameSyncObjects();
302 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead) const;
312 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead,
313 RHITextureLayout layout = RHITextureLayout::ShaderReadOnly) const;
314 RHIDeviceIdleGuard mWaitIdle; // Ensure device is idle on destruction
315 public:
316 Renderer() = delete;
319
320#pragma region Render Graph Setup
326 void BeginSetup();
337 template <typename T, typename... Args>
338 requires std::is_base_of_v<RenderPass, T>
340 {
342 CHECK_MSG(queue == RHIDeviceQueueType::Graphics || queue == RHIDeviceQueueType::Compute,
343 "Invalid queue type. Only Graphics and Compute queues are supported.");
344 PassHandle handle = mSetup->trackedPasses.size();
345 CHECK_MSG(handle < kMaxRenderPasses, "Exceeded maximum number of render passes ({})", kMaxRenderPasses);
346 if (!mDesc.asyncCompute)
347 queue = RHIDeviceQueueType::Graphics; // Force graphics queue if async compute is disabled
348 mSetup->trackedPasses.emplace_back(
349 mAllocator, handle, name, queue,
350 ConstructUniqueBase<RenderPass, T>(mAllocator, std::forward<Args>(args)...), priority);
351 mSetup->epilogue = handle;
352 return handle;
353 }
369 template <typename FSetup, typename FRecord>
371 FRecord&& record)
372 {
373 return CreatePassImpl<LambdaPass<FSetup, FRecord>>(name, queue, priority, std::forward<FSetup>(setup),
374 std::forward<FRecord>(record));
375 }
394 template <typename T>
396 {
397
399
400 ResourceHandle index = mSetup->trackedResources.size();
401 mSetup->trackedResources.emplace_back(index, name, desc, mAllocator);
402 return mSetup->trackedResources.size() - 1;
403 }
413#pragma region Resource Binding
420 void BindPass(PassHandle pass, PassHandle other);
433 Span<const char> specializationData = {}, uint32_t rtHitGroupIndex = 0) const;
442 void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const;
456 void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const& info) const;
470 StringView bind_point) const;
484 StringView bind_point) const;
498 StringView bind_point) const;
507 void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const;
513 void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const;
519 void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const;
535 void BindDescriptorSet(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout* layout);
547 RHIPipelineStage stage, RHITextureViewDesc const& desc) const;
562 RHIPipelineStage stage, RHITextureViewDesc const& desc) const;
573 void
574 BindTextureRTV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
575 RHIPipelineState::PipelineStateDesc::Attachment::Blending const& blending = {}) const;
584 void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc) const;
592 RHIPipelineState::PipelineStateDesc::Attachment::Blending const& blending = {}) const;
597 void BindBackbufferUAV(PassHandle pass, int set_index) const;
605 RHITextureSubresourceRange const& range = {}) const;
613 RHITextureSubresourceRange const& range = {}) const;
625 StringView bind_point) const;
626
627#pragma endregion
628#pragma region PSO Flags
636 RHIPipelineState::PipelineStateDesc::Rasterizer const& rasterizer = {},
637 RHIPipelineState::PipelineStateDesc::DepthStencil const& depth_stencil = {}) const;
638#pragma endregion
647 void EndSetup();
648#pragma endregion
649#pragma region Swapchain
654 {
655 CHECK(mSwapchain && "Swapchain not initialized");
656 return mSwapchain->mDesc.extents;
657 }
662 {
663 CHECK(mSwapchain && "Swapchain not initialized");
664 auto xy = mSwapchain->mDesc.extents;
665 return {xy.x, xy.y, 1};
666 }
667#pragma endregion
668#pragma region Render Graph Runtime
681 DerefResource(const ResourceHandle handle) const
682 {
683 CHECK(mResources && handle < mResources->resources.size());
685 auto& res = mResources->resources[handle];
686 CHECK_MSG(!res.valueless_by_exception(), "Resource handle {} is valueless", handle);
687 auto ptr = res.Visit([](auto* ptr) -> Tv { return ptr; }, [](auto& hdl) -> Tv { return hdl.Get(); });
688 CHECK_MSG(!ptr.valueless_by_exception(), "Resource handle {} is null", handle);
689 return ptr;
690 }
697 {
698 CHECK(mResources && handle < mResources->views.size());
699 using Tv = RHITextureView*;
700 auto& view = mResources->views[handle];
701 CHECK_MSG(!view.valueless_by_exception(), "Texture view handle {} is valueless", handle);
702 return view.Visit([](auto& hdl) -> Tv { return hdl.Get(); });
703 }
710 {
711 CHECK(mSetup && handle < mSetup->trackedSamplers.size());
712 return mResources->samplers[handle].Get();
713 }
718 {
719 CHECK(mSetup && pass < mSetup->trackedPasses.size());
720 auto& tpass = mSetup->trackedPasses[pass];
721 return tpass.pso.Get();
722 }
727 {
728 CHECK(mSetup && pass < mSetup->trackedPasses.size());
729 auto& tpass = mSetup->trackedPasses[pass];
730 return tpass.pDescriptorSets;
731 }
736#pragma endregion
737#pragma region Command Recording Helpers
764 void CmdSetPipeline(PassHandle pass, RHICommandList* cmd) const;
787 void CmdBeginGraphics(PassHandle pass, RHICommandList* cmd, RHIExtent2D const& extent,
796 template <typename T>
798 T const& data)
799 {
801 auto& tpass = mSetup->trackedPasses[pass];
802 cmd->PushConstant(tpass.pso.Get(), stage, static_cast<uint32_t>(offset),
803 {reinterpret_cast<const char*>(&data), sizeof(T)});
804 }
805#pragma endregion
806#pragma region Frame Execution
810 [[nodiscard]] State GetState() const { return mState; }
821 [[nodiscard]] uint64_t GetFrame() const { return mFrameSwapped; }
832 [[nodiscard]] uint32_t GetSwap() const { return mCurrentSwap; }
846 [[nodiscard]] uint64_t GetSync() const { return mCurrentSync; }
851 {
852 CHECK_MSG(mSetup && pass < mSetup->trackedPasses.size(), "No passes available or out of bounds");
853 return mSetup->trackedPasses[pass];
854 }
868 [[nodiscard]] bool IsPresentEnabled() const { return mDesc.present; }
887 void BeginExecute();
910 void ExecuteFrame();
917 void EndExecute();
918#pragma endregion
919#pragma region Debugging
920 [[nodiscard]] String DbgDumpGraphviz() const;
938#pragma endregion
939 };
942 ENUM_NAME(Setup);
943 ENUM_NAME(PostSetup);
944 ENUM_NAME(Execute);
946} // namespace Foundation::RenderCore
#define ENUM_NAME_CONV_BEGIN(T)
Defines convince to_string() method and format_as() [fmt] for the respective enum class Example usage...
Definition Enums.hpp:82
#define ENUM_NAME(E)
Definition Enums.hpp:93
#define CHECK(expr)
Definition Logging.hpp:41
#define CHECK_MSG(expr, format_str,...)
Definition Logging.hpp:46
Implements a lock-free stack-based bump allocator.
Definition AllocatorStack.hpp:12
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Atomic, lock-free Thread Pool implementation with fixed bounds.
Definition ThreadPool.hpp:58
Definition Command.hpp:42
Definition Descriptor.hpp:12
Definition Device.hpp:16
virtual uint32_t GetVkQueueFamily() const =0
Definition Device.hpp:104
Definition Device.hpp:189
Handle type for RHI Objects.
Definition Details.hpp:42
Definition PipelineState.hpp:8
Definition PipelineState.hpp:22
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:86
Definition Resource.hpp:211
Definition Resource.hpp:190
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:89
PassHandle CreatePass(StringView name, RHIDeviceQueueType queue, size_t priority, FSetup &&setup, FRecord &&record)
Create a render pass from a Setup(Renderer*, PassHandle) and Record(Renderer*, PassHandle,...
Definition Renderer.hpp:370
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefResource(const ResourceHandle handle) const
Dereference a resource handle to its underlying RHI resource.
Definition Renderer.hpp:681
void BindTextureRTV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Binds a texture as a Render Target View (color attachment) for a graphics pass.
Definition Renderer.cpp:232
void PassSetRasterizerFlags(PassHandle pass, RHIPipelineState::PipelineStateDesc::Rasterizer const &rasterizer={}, RHIPipelineState::PipelineStateDesc::DepthStencil const &depth_stencil={}) const
Sets the rasterizer and depth-stencil state for a graphics pass.
Definition Renderer.cpp:337
UniquePtr< ExecuteResources > mResources
Definition Renderer.hpp:170
void BeginSetup()
Begins the setup phase of the render graph.
Definition Renderer.cpp:41
RHICommandList * ExecuteAllocateCommandList(RHIDeviceQueueType queue, int thread_id=-1)
Definition Renderer.cpp:1447
RHIDeviceHandle< RHISwapchain > mSwapchain
Definition Renderer.hpp:203
void DeclareBufferAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage, RHIResourceAccess access=RHIResourceAccessBits::ShaderRead) const
Explicitly declares that this pass will access the buffer in the specified stage with the specified a...
Definition Renderer.cpp:75
void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const
Declares this pass has shaders that will read from this buffer. e.g. Vertex, Index.
Definition Renderer.cpp:174
Vector< Pair< RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc > > * mExecuteSubmits
Definition Renderer.hpp:223
State mState
Definition Renderer.hpp:159
void CmdBindDescriptorSet(PassHandle pass, RHICommandList *cmd, uint32_t set_index, RHIDeviceDescriptorSet *descriptor_set) const
Helper that binds a single descriptor set to the current command list.
Definition Renderer.cpp:1822
void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for an acceleration structure.
Definition Renderer.cpp:1329
void BindTextureSRV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage, RHITextureViewDesc const &desc) const
Binds a texture as a Shader Resource View (read-only sampling / fetch).
Definition Renderer.cpp:205
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
Definition Renderer.hpp:238
RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > mSwapDescriptorSetLayout
Definition Renderer.hpp:197
void BindDescriptorSet(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout)
Manually bind an existing descriptor set (layout) to the pipeline.
Definition Renderer.cpp:199
RHIDeviceSampler * DerefSampler(const ResourceHandle handle) const
Dereference a sampler handle to its underlying RHI sampler.
Definition Renderer.hpp:709
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:1463
void ExecuteBarrierSubresourceState(PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const
Definition Renderer.cpp:1250
RHIDeviceQueue * mGraphicsQueue
Definition Renderer.hpp:204
Vector< RHIDeviceDescriptorSet * > const & DerefDescriptorSets(const PassHandle pass) const
Dereference the built descriptor sets associated with a given pass.
Definition Renderer.hpp:726
uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
Helper to get the queue index of a queue type.
Definition Renderer.hpp:249
void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, const char *shader_path, Span< const char > specializationData={}, uint32_t rtHitGroupIndex=0) const
Binds shader file path to a certain pass at a certain stage.
Definition Renderer.cpp:117
ResourceHandle CreateTextureView(PassHandle pass, ResourceHandle handle, RHITextureViewDesc const &desc) const
Definition Renderer.cpp:52
void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const
Binds a sampler to the shader.
Definition Renderer.cpp:192
void ExecuteBarrierSubresource(PassHandle pass, TrackedResource &res, RHITextureSubresourceRange const &range, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a subresource range of a texture.
Definition Renderer.cpp:1284
Vector< Pair< Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * >, RHICommandList::TransitionDesc > > ExecuteBarrierList
Definition Renderer.hpp:263
ScopedArena mExecuteArena
Definition Renderer.hpp:217
void CmdBeginGraphics(PassHandle pass, RHICommandList *cmd, RHIExtent2D const &extent, Span< const Optional< RHIClearColor > > clear_rtv={}, Optional< RHIClearDepthStencil > const &clear_dsv=RHIClearDepthStencil{0.0f, 0u})
Helper that pushes correct descriptor sets and PSO to the current command list, and pushes correct Be...
Definition Renderer.cpp:1846
void CmdDispatch(PassHandle pass, RHICommandList *cmd, RHIExtent3D thread_size) const
Helper that dispatches a compute shader with the specified THREAD count.
Definition Renderer.cpp:1904
Mutex mDescPoolMutex
Definition Renderer.hpp:172
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Definition Renderer.cpp:269
void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const
Associates Vertex Input description with this pass.
Definition Renderer.cpp:127
void CmdSetPipeline(PassHandle pass, RHICommandList *cmd) const
Helper that sets the current pass's PSO and descriptor sets to the current command list.
Definition Renderer.cpp:1808
uint32_t mFrameSwaps
Definition Renderer.hpp:166
void FinalizePasses()
Definition Renderer.cpp:1002
void BuildPipelineState(PassHandle pass)
Definition Renderer.cpp:530
void BindPass(PassHandle pass, PassHandle other)
Declares an inter-pass dependency, where the other pass should execute-before the current pass.
Definition Renderer.cpp:68
void BindBufferStorageRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const
Binds a read-only storage buffer to a specified binding point.
Definition Renderer.cpp:156
RHIDeviceScopedHandle< RHIDeviceSemaphore > mGraphicsTimeline
Definition Renderer.hpp:201
void SetSwapchain(RHIDeviceHandle< RHISwapchain > swapchain)
Update the swapchain to a new one. You must call this when the window is resized or the swapchain is ...
Definition Renderer.cpp:1143
String DbgDumpActivePasses() const
Definition Renderer.cpp:1961
RHIPipelineState * DerefPipelineState(const PassHandle pass) const
Dereference the automatically built pipeline state object handle associated with a given pass.
Definition Renderer.hpp:717
PassHandle CreatePassImpl(StringView name, RHIDeviceQueueType queue, size_t priority, Args &&... args)
Create a render pass from a RenderPass* implementation and add it to the render graph.
Definition Renderer.hpp:339
uint32_t GetFrameSwaps() const
Get the number of frames that can be simultaneously in-flight.
Definition Renderer.hpp:814
AllocatorStack mExecuteAlloc
Definition Renderer.hpp:220
Vector< FrameSyncObjects > mSwaps
Definition Renderer.hpp:199
String DbgDumpExecutionGroups() const
Definition Renderer.cpp:1974
void BindAccelerationStructureSRV(PassHandle pass, ResourceHandle as, RHIPipelineStage stage, StringView bind_point) const
Declares that this pass has shaders that will read from this AS.
Definition Renderer.cpp:323
uint64_t mFrameSwapped
Definition Renderer.hpp:164
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mDescPool
Definition Renderer.hpp:171
ThreadPool mExecuteThreadPool
Definition Renderer.hpp:225
void SetFrameSyncObjects()
Sets backbuffer views and sync primitives.
Definition Renderer.cpp:1115
void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will read from the buffer via copy.
Definition Renderer.cpp:186
uint32_t mCurrentSwap
Definition Renderer.hpp:168
void BindTextureUAV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage, RHITextureViewDesc const &desc) const
Binds a texture for unordered (UAV) read-write access in shaders.
Definition Renderer.cpp:218
void DeclareTextureAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage, RHITextureSubresourceRange range={}, RHIResourceAccess access=RHIResourceAccessBits::ShaderRead, RHITextureLayout layout=RHITextureLayout::ShaderReadOnly) const
Declares that this pass will access the texture in the specified stage with the specified access.
Definition Renderer.cpp:95
RHIExtent3D GetSwapchainExtent3D() const
Get the current swapchain extents as a 3D extent with depth 1.
Definition Renderer.hpp:661
UniquePtr< RendererSetup > mSetup
Definition Renderer.hpp:206
void CullPasses(PassHandle epilogue) const
Definition Renderer.cpp:369
Allocator * GetAllocator() const
Definition Renderer.hpp:735
void BindTextureCopyDst(PassHandle pass, ResourceHandle texture, RHITextureSubresourceRange const &range={}) const
Declares that this pass will write to the texture via copy / blit (transfer destination).
Definition Renderer.cpp:291
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:653
RHIApplicationHandle< RHIDevice > mDevice
Definition Renderer.hpp:202
RendererDesc mDesc
Definition Renderer.hpp:162
Allocator * mAllocator
Definition Renderer.hpp:160
void ExecuteBarriers(TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes all barriers for a pass.
Definition Renderer.cpp:1358
void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will write to the buffer via copy.
Definition Renderer.cpp:180
void BeginExecute()
Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to fi...
Definition Renderer.cpp:1195
TrackedPass const & GetTrackedPass(PassHandle pass)
Retrieves an internal tracked pass associated with the given handle, read-only.
Definition Renderer.hpp:850
void EndExecute()
Ends the execution phase and performs GPU submission, possibly with a RHIDeviceQueue::Present.
Definition Renderer.cpp:1756
void FinalizeResources()
Definition Renderer.cpp:1023
uint32_t mCurrentSync
Definition Renderer.hpp:167
void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const
Declares a range of Push Constant used in a stage.
Definition Renderer.cpp:136
void ExecuteBarrierBuffer(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a whole buffer.
Definition Renderer.cpp:1300
Span< const uint64_t > DbgProfilePassTiming(uint64_t sync, float &resolutionNS) const
Retrieves timings for all passes executed in the last frame associated with the specified sync index....
Definition Renderer.cpp:1989
String DbgDumpGraphviz() const
Definition Renderer.cpp:1913
void BindTextureCopySrc(PassHandle pass, ResourceHandle texture, RHITextureSubresourceRange const &range={}) const
Declares that this pass will read from the texture via copy / blit (transfer source).
Definition Renderer.cpp:301
void BindBufferUnordered(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const
Binds a buffer for unordered (UAV) access from shaders (read and/or write in any order).
Definition Renderer.cpp:165
RHIDeviceQueue * mComputeQueue
Definition Renderer.hpp:204
void BindAccelerationStructureWrite(PassHandle pass, ResourceHandle as) const
Declares that this pass will build, or update the AS.
Definition Renderer.cpp:311
RHIDeviceScopedHandle< RHIDeviceSemaphore > mComputeTimeline
Definition Renderer.hpp:201
void CmdSetPushConstant(PassHandle pass, RHICommandList *cmd, RHIShaderStage stage, size_t offset, T const &data)
Helper that sets a Push Constant range data with a single l-value.
Definition Renderer.hpp:797
bool IsAsyncComputeEnabled() const
Returns whether async compute is enabled.
Definition Renderer.hpp:861
RHIDeviceIdleGuard mWaitIdle
Definition Renderer.hpp:314
uint64_t DbgProfilePresentTiming(uint64_t sync, float &resolutionNS) const
Retrieves the total ticks between two subsequent swapchain presents by EndExecute,...
Definition Renderer.cpp:1999
uint64_t GetSync() const
Retrieves the current synchronization index.
Definition Renderer.hpp:846
State
Definition Renderer.hpp:151
bool IsPresentEnabled() const
Returns whether the swapchain is enabled.
Definition Renderer.hpp:868
void BuildPipelineStateAll()
Definition Renderer.cpp:973
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:1895
uint32_t GetSwap() const
Retrieves the current swap index at the time of ExecuteFrame().
Definition Renderer.hpp:832
uint64_t GetFrame() const
Retrieves the current frame number.
Definition Renderer.hpp:821
State GetState() const
Retrieves the current state of the renderer.
Definition Renderer.hpp:810
RHITextureView * DerefTextureView(const ResourceHandle handle) const
Dereference a texture view handle to its underlying RHI texture view.
Definition Renderer.hpp:696
void EndSetup()
Finish setting up the render graph.
Definition Renderer.cpp:348
void BindBufferUniform(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const
Binds a uniform buffer to a specified binding point in a rendering pass.
Definition Renderer.cpp:147
ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const &desc) const
Creates a sampler with the specified name and descriptor.
Definition Renderer.cpp:61
ResourceHandle CreateResource(StringView name, T const &desc)
Create a new resource to be used in the render graph.
Definition Renderer.hpp:395
void BindBackbufferUAV(PassHandle pass, int set_index) const
Binds the backbuffer as RW access at binding 0 of set index.
Definition Renderer.cpp:280
void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc) const
Binds a texture as a Depth-Stencil View for a graphics pass.
Definition Renderer.cpp:250
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mSwapDescriptorPool
Definition Renderer.hpp:196
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:130
std::basic_string< char > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:112
std::mutex Mutex
Definition Thread.hpp:10
std::map< K, V, Predicate, StlAllocator< Pair< const K, V > > > Map
std::map with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:160
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:55
std::unique_ptr< T, Deleter > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:166
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149
std::span< T > Span
Alias for std::span
Definition Container.hpp:60
std::optional< T > Optional
Alias for std::optional
Definition Container.hpp:26
const uint32_t kCommandQueueTransferIgnored
Definition Command.hpp:40
RHITextureLayout
Definition Common.hpp:148
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
RHIDeviceQueueType
Definition Common.hpp:109
Pair< float, uint32_t > RHIClearDepthStencil
Definition Common.hpp:18
static constexpr Handle kInvalidHandle
Definition Details.hpp:9
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
Handle ResourceHandle
Definition RenderPass.hpp:11
const RHIResourceAccessBits kAllShaderWrites
Definition Renderer.hpp:73
constexpr size_t kMaxRenderPasses
Definition Renderer.hpp:65
const RHIResourceAccessBits kAllShaderReads
Definition Renderer.hpp:76
const RHIPipelineStage kComputeStagesMask
Definition Renderer.hpp:70
Handle PassHandle
Definition RenderPass.hpp:10
constexpr size_t kExecuteArenaSize
Definition Renderer.hpp:69
constexpr size_t kMaxCommandListsPerThread
Definition Renderer.hpp:67
RAII wrapper for an arena allocated from an Allocator.
Definition Allocator.hpp:44
Extended std::variant with C++23 visit() behavior and convenience Get()/GetIf() methods.
Definition Variant.hpp:17
RAII guard to wait for device idle on destruction.
Definition Device.hpp:310
Definition Resource.hpp:184
Parameters for Renderer creation.
Definition Renderer.hpp:17
bool profilePasses
Enable or disable GPU profiling for the frame graph execution.
Definition Renderer.hpp:59
uint32_t threadCount
Number of worker threads to use for recording command lists.
Definition Renderer.hpp:44
bool asyncCompute
Enable Async Compute support.
Definition Renderer.hpp:32
bool present
Enable presentation support.
Definition Renderer.hpp:39
RHIPipelineStateCache * pipelineCache
Optional PSO cache to potentially speed up pipeline state recompilation in Setup time.
Definition Renderer.hpp:49
Vector< RHICommandPoolScopedHandle< RHICommandList > > computeCmds
Definition Renderer.hpp:229
RHICommandList * AllocateCompute()
Definition Renderer.cpp:1436
RHIDeviceScopedHandle< RHICommandPool > computePool
Definition Renderer.hpp:228
RHICommandList * AllocateGraphics()
Definition Renderer.cpp:1425
RHIDeviceScopedHandle< RHICommandPool > graphicsPool
Definition Renderer.hpp:228
Vector< RHICommandPoolScopedHandle< RHICommandList > > graphicsCmds
Definition Renderer.hpp:229
ResourceHandle backbuffer
Definition Renderer.hpp:184
RHIDeviceScopedHandle< RHIDeviceQueryPool > dbgQueryPool
Definition Renderer.hpp:186
RHIDeviceScopedHandle< RHIDeviceFence > computeFence
Definition Renderer.hpp:179
RHIDeviceScopedHandle< RHIDeviceFence > graphicsFence
Definition Renderer.hpp:179
uint64_t dbgSwapLastPresentToPresentTicks
Definition Renderer.hpp:190
FrameSyncObjects(size_t swapIndex, Allocator *alloc)
Definition Renderer.hpp:191
const size_t swapIndex
Definition Renderer.hpp:177
Vector< uint64_t > dbgQueryPassTimestampsResults
Definition Renderer.hpp:187
RHITextureScopedHandle< RHITextureView > view
Definition Renderer.hpp:181
RHIDeviceScopedHandle< RHIDeviceSemaphore > render
Definition Renderer.hpp:178
RHIDeviceScopedHandle< RHIDeviceSemaphore > present
Definition Renderer.hpp:178
RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > viewSet
Definition Renderer.hpp:182
std::chrono::steady_clock::time_point dbgSwapLastPresentTick
Definition Renderer.hpp:189
Vector< PassHandle > passes
Definition Renderer.hpp:117
Vector< ResourceHandle > resources
Definition Renderer.hpp:119
ExecutionGroups(int groupIndex, RHIDeviceQueueType queue, Allocator *allocator)
Definition Renderer.hpp:123
const RHIDeviceQueueType queue
Definition Renderer.hpp:116
Helper class containing all states pertaining to Renderer's Setup phase.
Definition Renderer.hpp:94
Vector< ExecutionGroups > executionGroups
Definition Renderer.hpp:128
PassHandle lastBackbufferProducer
Definition Renderer.hpp:100
bool executionAnyCompute
Definition Renderer.hpp:129
int executionNumGraphicsGroups
Definition Renderer.hpp:130
Vector< PassHandle > execution
Definition Renderer.hpp:107
Vector< Vector< Pair< PassHandle, ResourceHandle > > > graph
Definition Renderer.hpp:95
Vector< TrackedPass > trackedPasses
Definition Renderer.hpp:97
Map< ResourceHandle, Pair< PassHandle, PassHandle > > activeResources
Definition Renderer.hpp:105
int executionNumComputeGroups
Definition Renderer.hpp:130
Vector< PassHandle > in
Definition Renderer.hpp:96
void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
Definition Renderer.hpp:131
PassHandle epilogue
Definition Renderer.hpp:109
Vector< RHIDeviceSampler::SamplerDesc > trackedSamplers
Definition Renderer.hpp:103
Map< RHIDescriptorType, uint32_t > bindingCounts
Definition Renderer.hpp:108
Vector< TrackedResource > trackedResources
Definition Renderer.hpp:98
Vector< Pair< ResourceHandle, RHITextureViewDesc > > trackedViews
Definition Renderer.hpp:102
bool executionAnyGraphics
Definition Renderer.hpp:129
RendererSetup(Allocator *allocator)
Definition Renderer.hpp:141
Internal tracking information for a render pass in the frame graph.
Definition RenderPass.hpp:77
Internal tracking information for a resource in the frame graph.
Definition RenderResource.hpp:18