Foundation
Loading...
Searching...
No Matches
Renderer.hpp
Go to the documentation of this file.
1#pragma once
5
6#include "RenderPass.hpp"
7#include "RenderResource.hpp"
12{
17 {
39 bool enablePresent{true};
44 uint32_t numRenderThreads{std::max(1u, std::thread::hardware_concurrency() - 1)};
45 };
46 /* -- Constants -- */
47 // Maximum number of render passes per frame
48 // NOTE: The limit here is mostly arbitrary - and is only used
49 // for the default priority heuristic when determining pass order.
50 constexpr size_t kMaxRenderPasses = 1024;
51 // Maximum number of command lists per frame
53 // Maximum size of the per-frame transient arena (16MB)
54 constexpr size_t kExecuteArenaSize = 16 * (1 << 20);
55 // Stub name for bind_point names that's not found in shaders. This has no
56 // effect - as bindings not found will simply not participate
57 // in the PSO building process.
58 const String kBindpointIgnored = "<ignored>"; // no constexpr in Debug?? thanks MSVC
59 const RHIPipelineStage kComputeStagesMask = RHIPipelineStageBits::FragmentShader |
60 RHIPipelineStageBits::VertexShader | RHIPipelineStageBits::MeshShader | RHIPipelineStageBits::RayTracingShader |
61 RHIPipelineStageBits::AllGraphics;
62 const RHIResourceAccessBits kAllShaderWrites = RHIResourceAccessBits::ShaderWrite |
63 RHIResourceAccessBits::RenderTargetWrite | RHIResourceAccessBits::DepthStencilWrite |
64 RHIResourceAccessBits::TransferWrite | RHIResourceAccessBits::HostWrite;
65 const RHIResourceAccessBits kAllShaderReads = RHIResourceAccessBits::ShaderRead |
66 RHIResourceAccessBits::RenderTargetRead | RHIResourceAccessBits::UniformRead |
67 RHIResourceAccessBits::TransferRead | RHIResourceAccessBits::HostRead;
78 {
83 {
88 // Backbuffer producer
90 // [resource, view desc]
93 // [resource, ord range]
95 // Passes ordered by pass.ord
99 // Execution grouped by queue type
101 {
102 const int groupIndex{}; // Index in executionGroups
103 int graphicsGroupIndex{-1}; // Index of all unique graphics groups before this one
104 int computeGroupIndex{-1}; // Index of all unique compute groups before this one
107 // Resources used in this group
109 bool isLastGraphics = false;
110 bool isLastCompute = false;
111 RHIPipelineStage allStages{}; // All stages used in this group
112
117 };
121 void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
122 {
123 while (u >= graph.size())
124 graph.emplace_back(graph.get_allocator());
125 graph[u].emplace_back(v, hdl);
126 while (v >= indegree.size())
127 indegree.push_back(0);
128 indegree[v]++;
129 }
136 };
137 public:
138 enum class State
139 {
140 Undefined,
141 Setup,
142 PostSetup,
143 Execute
144 };
145
146 private:
149
151
152 uint64_t mFrameSwapped{0}; // Frame rendered in the current Swapchain
153
154 uint32_t mFrameSwaps{1}; // Max frames in flight
157
161
175 // Semaphore for async compute
180
182 // Setup
184 RHITextureViewDesc const& desc) const;
185 // PostSetup
186 void CullPasses(PassHandle epilogue) const;
188 void FinalizeResources();
189 void FinalizePSOs();
190 // Temporary memory arena for execution
192 // Temporary allocator for execution
193 // This is reset every frame, and only guaranteed to be valid during Execute state.
195 // Temporary storage for submits calls
196 // This is reset every frame, and only guaranteed to be valid during Execute state.
198 // Thread pool for concurrent command list recording
211 // [current sync][thread id]
222 {
223 switch (queue)
224 {
225 case RHIDeviceQueueType::Undefined:
227 case RHIDeviceQueueType::Graphics:
229 case RHIDeviceQueueType::Compute:
231 default:
232 throw std::runtime_error("Unhandled queue type");
233 }
234 };
264 void SetFrameSyncObjects();
274 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead) const;
284 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead,
285 RHITextureLayout layout = RHITextureLayout::ShaderReadOnly) const;
286 RHIDeviceIdleGuard mWaitIdle; // Ensure device is idle on destruction
287 public:
290
291#pragma region Render Graph Setup
297 void BeginSetup();
310 template <typename T, typename... Args>
311 requires std::is_base_of_v<RenderPass, T>
312 T* CreatePassImpl(StringView name, RHIDeviceQueueType queue, size_t priority, Args&&... args)
313 {
315 CHECK_MSG(queue == RHIDeviceQueueType::Graphics || queue == RHIDeviceQueueType::Compute,
316 "Invalid queue type. Only Graphics and Compute queues are supported.");
317 PassHandle handle = mSetup->trackedPasses.size();
318 CHECK_MSG(handle < kMaxRenderPasses, "Exceeded maximum number of render passes ({})", kMaxRenderPasses);
320 queue = RHIDeviceQueueType::Graphics; // Force graphics queue if async compute is disabled
321 mSetup->trackedPasses.emplace_back(
322 mAllocator, handle, name, queue,
323 ConstructUniqueBase<RenderPass, T>(mAllocator, std::forward<Args>(args)...), priority);
324 mSetup->epilogue = handle;
325 return static_cast<T*>(mSetup->trackedPasses.back().pass.get());
326 }
346 template <typename FSetup, typename FRecord, typename FSkip = FSkipDefault>
348 FSetup&& setup, FRecord&& record, FSkip&& skip = {})
349 {
351 name, queue, priority, std::forward<FSetup>(setup), std::forward<FRecord>(record),
352 std::forward<FSkip>(skip));
353 }
374 template <typename T>
376 {
378 ResourceHandle index = mSetup->trackedResources.size();
379 mSetup->trackedResources.emplace_back(index, name, desc, mAllocator);
380 return mSetup->trackedResources.size() - 1;
381 }
391#pragma region Resource Binding
401 Native::Path const& shader_path) const;
418 void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const;
447 StringView bind_point) const;
462 StringView bind_point) const;
477 StringView bind_point) const;
490 void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const;
496 void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const;
502 void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const;
536 RHIPipelineStage stage, RHITextureViewDesc const& desc) const;
552 RHIPipelineStage stage, RHITextureViewDesc const& desc) const;
572 ResourceHandle BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc) const;
583 void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const& blending = {}) const;
591 RHITextureSubresourceRange const& range = {}) const;
599 RHITextureSubresourceRange const& range = {}) const;
600 /* TODO: Push Constants */
601#pragma endregion
602#pragma region PSO Flags
610 PassHandle pass,
611 RHIPipelineState::PipelineStateDesc::Rasterizer const& rasterizer = {},
612 RHIPipelineState::PipelineStateDesc::DepthStencil const& depth_stencil = {}
613 ) const;
614#pragma endregion
623 void EndSetup();
624#pragma endregion
625#pragma region Swapchain
630 {
631 CHECK(mSwapchain && "Swapchain not initialized");
632 return mSwapchain->mDesc.extents;
633 }
638 {
639 CHECK(mSwapchain && "Swapchain not initialized");
640 auto xy = mSwapchain->mDesc.extents;
641 return {xy.x, xy.y, 1};
642 }
643#pragma endregion
644#pragma region Render Graph Runtime
657 {
658 CHECK(mResources && handle < mResources->resources.size());
660 return mResources->resources[handle].Visit([](auto* ptr) -> Tv { return ptr; },
661 [](auto& hdl) -> Tv { return hdl.Get(); });
662 }
669 {
670 CHECK(mResources && handle < mResources->views.size());
671 using Tv = RHITextureView*;
672 return mResources->views[handle].Visit([](auto& hdl) -> Tv { return hdl.Get(); });
673 }
680 {
681 CHECK(mSetup && handle < mSetup->trackedSamplers.size());
682 return mResources->samplers[handle].Get();
683 }
688 {
689 CHECK(mSetup && pass < mSetup->trackedPasses.size());
690 auto& tpass = mSetup->trackedPasses[pass];
691 return tpass.pso.Get();
692 }
697 {
698 CHECK(mSetup && pass < mSetup->trackedPasses.size());
699 auto& tpass = mSetup->trackedPasses[pass];
700 return tpass.pDescriptorSets;
701 }
708 {
710 auto& tpass = mSetup->trackedPasses[pass];
711 CHECK_MSG(tpass.writeBackbuffer, "Pass {} does not write to backbuffer", tpass.name);
712 return mSwaps[GetSwap()].rtv.Get();
713 }
718#pragma endregion
719#pragma region Command Recording Helpers
745 void CmdSetPipeline(PassHandle pass, RHICommandList* cmd) const;
762 void CmdBeginGraphics(PassHandle pass, RHICommandList* cmd, RHIExtent2D const& extent,
771 template <typename T>
773 T const& data)
774 {
776 auto& tpass = mSetup->trackedPasses[pass];
777 cmd->PushConstant(tpass.pso.Get(), stage, static_cast<uint32_t>(offset),
778 {reinterpret_cast<const char*>(&data), sizeof(T)});
779 }
780#pragma endregion
781#pragma region Frame Execution
785 [[nodiscard]] State GetState() const { return mState; }
796 [[nodiscard]] uint64_t GetFrame() const { return mFrameSwapped; }
806 [[nodiscard]] uint32_t GetSwap() const { return mCurrentSwap; }
820 [[nodiscard]] uint64_t GetSync() const { return mCurrentSync; }
834 [[nodiscard]] bool IsPresentEnabled() const { return mDesc.enablePresent; }
853 void BeginExecute();
871 void ExecuteFrame();
876 void EndExecute();
877#pragma endregion
878#pragma region Debugging
879 [[nodiscard]] String DbgDumpGraphviz() const;
882#pragma endregion
883 };
886 ENUM_NAME(Setup);
887 ENUM_NAME(PostSetup);
888 ENUM_NAME(Execute);
890 /* Functional Helpers */
905 {
906 return r->CreateResource(name, desc);
907 }
914 {
915 return r->CreateSampler(desc);
916 }
927 template <typename T, typename... Args>
928 requires std::is_base_of_v<RenderPass, T>
930 {
931 return r->CreatePassImpl<T>(name, queue, priority, std::forward<Args>(args)...);
932 }
943 template <typename T, typename... Args>
944 requires std::is_base_of_v<RenderPass, T>
946 {
947 size_t pri = (queue == RHIDeviceQueueType::Graphics) ? 0 : kMaxRenderPasses; // Just a _pretty large_ value.
948 return createPassImpl<T>(r, name, queue, pri, std::forward<Args>(args)...);
949 }
969 template <typename FSetup, typename FRecord, typename FSkip = FSkipDefault>
971 size_t priority, FSetup&& setup, FRecord&& record,
972 FSkip&& skip = {})
973 {
974 return r->CreatePass(name, queue, priority, std::forward<FSetup>(setup), std::forward<FRecord>(record),
975 std::forward<FSkip>(skip));
976 }
999 template <typename FSetup, typename FRecord, typename FSkip = FSkipDefault>
1001 FSetup&& setup, FRecord&& record, FSkip&& skip = {})
1002 {
1003 size_t pri = (queue == RHIDeviceQueueType::Graphics) ? 0 : kMaxRenderPasses;
1004 return createPassPriority(r, name, queue, pri, std::forward<FSetup>(setup), std::forward<FRecord>(record),
1005 std::forward<FSkip>(skip));
1006 }
1007} // 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:84
#define ENUM_NAME(E)
Definition Enums.hpp:95
#define CHECK(expr)
Definition Logging.hpp:26
#define CHECK_MSG(expr, format_str,...)
Definition Logging.hpp:31
Atomic, lock-free Thread Pool implementation with fixed bounds.
Definition ThreadPool.hpp:64
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Implements an atomic stack-based bump allocator.
Definition StackAllocator.hpp:9
Definition Command.hpp:34
Definition Descriptor.hpp:11
Definition Device.hpp:13
virtual uint32_t GetQueueIndex() const =0
Definition Device.hpp:88
Definition Device.hpp:131
Definition PipelineState.hpp:7
Definition Resource.hpp:169
Definition Resource.hpp:146
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:78
void CmdBeginGraphics(PassHandle pass, RHICommandList *cmd, RHIExtent2D const &extent, Optional< RHIClearColor > const &clear_rtv=RHIClearColor{}, Optional< RHIClearDepthStencil > const &clear_dsv=RHIClearDepthStencil{1.0f, 0u})
Helper that pushes correct descriptor sets and PSO to the current command list, and pushes correct Be...
Definition Renderer.cpp:1630
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:280
UniquePtr< ExecuteResources > mResources
Definition Renderer.hpp:158
void BeginSetup()
Begins the setup phase of the render graph.
Definition Renderer.cpp:33
const RendererDesc mDesc
Definition Renderer.hpp:150
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:57
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:152
State mState
Definition Renderer.hpp:147
void ExecuteReleaseQueueResources(RHIDeviceQueueType currentQueue, size_t groupIndex, RHICommandList *cmd)
Performs transitions that's otherwise impossible (e.g. Fragment -> Compute) for the next group,...
Definition Renderer.cpp:1198
RHIDeviceObjectHandle< RHISwapchain > mSwapchain
Definition Renderer.hpp:178
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
Definition Renderer.hpp:212
void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, Native::Path const &shader_path) const
Binds shader file path to a certain pass at a certain stage.
Definition Renderer.cpp:98
RHIDeviceScopedObjectHandle< RHIDeviceSemaphore > mGraphicsTimeline
Definition Renderer.hpp:176
RHIDeviceSampler * DerefSampler(const ResourceHandle handle) const
Dereference a sampler handle to its underlying RHI sampler.
Definition Renderer.hpp:679
RHIDeviceScopedObjectHandle< RHIDeviceDescriptorPool > mDescPool
Definition Renderer.hpp:159
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:1350
uint32_t ExecuteGetQueueIndex(RHIDeviceQueueType queue) const
Helper to get the queue index of a queue type.
Definition Renderer.hpp:221
void ExecuteBarrierSubresourceState(PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const
Definition Renderer.cpp:1037
RHIDeviceQueue * mGraphicsQueue
Definition Renderer.hpp:179
Vector< RHIDeviceDescriptorSet * > const & DerefDescriptorSets(const PassHandle pass) const
Dereference the built descriptor sets associated with a given pass.
Definition Renderer.hpp:696
ResourceHandle 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:198
ResourceHandle CreateTextureView(PassHandle pass, ResourceHandle handle, RHITextureViewDesc const &desc) const
Definition Renderer.cpp:43
void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const
Binds a sampler to the shader.
Definition Renderer.cpp:167
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:1070
ScopedArena mExecuteArena
Definition Renderer.hpp:191
RHIDeviceScopedObjectHandle< RHIDeviceSemaphore > mComputeTimeline
Definition Renderer.hpp:176
void CmdDispatch(PassHandle pass, RHICommandList *cmd, RHIExtent3D thread_size) const
Helper that dispatches a compute shader with the specified TOTAL thread count.
Definition Renderer.cpp:1685
void FinalizePSOs()
Definition Renderer.cpp:815
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Declares that this pass will write to the current (at Record time) swapchain backbuffer.
Definition Renderer.cpp:249
void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const
Associates Vertex Input description with this pass.
Definition Renderer.cpp:110
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:1608
uint32_t mFrameSwaps
Definition Renderer.hpp:154
void BuildPipelineState(PassHandle pass)
Definition Renderer.cpp:461
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:136
String DbgDumpActivePasses() const
Definition Renderer.cpp:1722
RHIPipelineState * DerefPipelineState(const PassHandle pass) const
Dereference the automatically built pipeline state object handle associated with a given pass.
Definition Renderer.hpp:687
uint32_t GetFrameSwaps() const
Get the number of frames that can be simultaneously in-flight.
Definition Renderer.hpp:789
void SetSwapchain(RHIDeviceObjectHandle< 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:966
Vector< FrameSyncObjects > mSwaps
Definition Renderer.hpp:174
ResourceHandle 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:212
String DbgDumpExecutionGroups() const
Definition Renderer.cpp:1737
uint64_t mFrameSwapped
Definition Renderer.hpp:152
Vector< RHIDeviceQueue::SubmitDesc > * mExecuteGraphicsSubmits
Definition Renderer.hpp:197
Vector< RHIDeviceQueue::SubmitDesc > * mExecuteComputeSubmits
Definition Renderer.hpp:197
ResourceHandle BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc) const
Binds a texture as a Depth-Stencil View for a graphics pass.
Definition Renderer.cpp:230
RHIApplicationObjectHandle< RHIDevice > mDevice
Definition Renderer.hpp:177
void CmdBindDescriptorSet(PassHandle pass, RHICommandList *cmd, uint32_t index, RHIDeviceDescriptorSet *descriptor_set) const
Helper that binds a single descriptor set to the current command list.
Definition Renderer.cpp:1621
void SetFrameSyncObjects()
Definition Renderer.cpp:939
void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will read from the buffer via copy.
Definition Renderer.cpp:162
uint32_t mCurrentSwap
Definition Renderer.hpp:156
RHITextureView * DerefCurrentBackbufferView(const PassHandle pass) const
Returns a pointer to the current backbuffer texture view.
Definition Renderer.hpp:707
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:76
RHIExtent3D GetSwapchainExtent3D() const
Get the current swapchain extents as a 3D extent with depth 1.
Definition Renderer.hpp:637
UniquePtr< RendererSetup > mSetup
Definition Renderer.hpp:181
void CullPasses(PassHandle epilogue) const
Definition Renderer.cpp:310
Allocator * GetAllocator() const
Definition Renderer.hpp:717
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:262
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:629
Allocator * mAllocator
Definition Renderer.hpp:148
void ExecuteBarriers(TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes all barriers for a pass.
Definition Renderer.cpp:1115
void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will write to the buffer via copy.
Definition Renderer.cpp:157
void BeginExecute()
Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to fi...
Definition Renderer.cpp:1006
LambdaPass< FSetup, FRecord, FSkip > * CreatePass(StringView name, RHIDeviceQueueType queue, size_t priority, FSetup &&setup, FRecord &&record, FSkip &&skip={})
Create a render pass from a Setup(Renderer*, PassHandle) and Record(Renderer*, PassHandle,...
Definition Renderer.hpp:347
void EndExecute()
Ends the execution phase, and prepares for the next frame.
Definition Renderer.cpp:1568
Variant< RHIBuffer *, RHITexture * > DerefResource(const ResourceHandle handle) const
Dereference a resource handle to its underlying RHI resource.
Definition Renderer.hpp:656
void FinalizeResources()
Definition Renderer.cpp:858
uint32_t mCurrentSync
Definition Renderer.hpp:155
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:118
void ExecuteBarrierBuffer(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a whole buffer.
Definition Renderer.cpp:1086
String DbgDumpGraphviz() const
Definition Renderer.cpp:1693
RHICommandList * ExecuteAllocateCommandList(RHIDeviceQueueType queue, int thread_id)
Definition Renderer.cpp:1337
void BindDescriptorBindPoint(PassHandle pass, StringView bind_point, uint32_t binding, uint32_t set)
Declares that a bind point in a certain pass is a descriptor set at the specified set and binding ind...
Definition Renderer.cpp:180
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:271
Async::Mutex mDescPoolMutex
Definition Renderer.hpp:160
Async::ThreadPool mExecuteThreadPool
Definition Renderer.hpp:199
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:144
RHIDeviceQueue * mComputeQueue
Definition Renderer.hpp:179
Vector< Pair< Variant< RHIBuffer *, RHITexture * >, RHICommandList::TransitionDesc > > ExecuteBarrierList
Definition Renderer.hpp:235
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:772
void BindDescriptorSet(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSet *descriptor_set, RHIDeviceDescriptorSetLayout *layout)
Manually bind an existing descriptor set to the pipeline.
Definition Renderer.cpp:173
ResourceHandle 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:185
bool IsAsyncComputeEnabled() const
Returns whether async compute is enabled.
Definition Renderer.hpp:827
RHIDeviceIdleGuard mWaitIdle
Definition Renderer.hpp:286
StackAllocator mExecuteAlloc
Definition Renderer.hpp:194
T * 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:312
uint64_t GetSync() const
Retrieves the current synchronization index.
Definition Renderer.hpp:820
State
Definition Renderer.hpp:139
bool IsPresentEnabled() const
Returns whether the swapchain is enabled.
Definition Renderer.hpp:834
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:1677
uint32_t GetSwap() const
Retrieves the current swap index at the time of ExecuteFrame().
Definition Renderer.hpp:806
uint64_t GetFrame() const
Retrieves the current frame number.
Definition Renderer.hpp:796
State GetState() const
Retrieves the current state of the renderer.
Definition Renderer.hpp:785
RHITextureView * DerefTextureView(const ResourceHandle handle) const
Dereference a texture view handle to its underlying RHI texture view.
Definition Renderer.hpp:668
void EndSetup()
Finish setting up the render graph.
Definition Renderer.cpp:290
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:128
void ExecuteAcquireQueueResources(RHIDeviceQueueType currentQueue, size_t groupIndex, RHICommandList *cmd)
Acquires resources for the current group.
Definition Renderer.cpp:1154
ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const &desc) const
Creates a sampler with the specified name and descriptor.
Definition Renderer.cpp:51
ResourceHandle CreateResource(StringView name, T const &desc)
Create a new resource to be used in the render graph.
Definition Renderer.hpp:375
std::mutex Mutex
Definition Future.hpp:15
std::basic_string< char > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:141
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:53
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161
std::filesystem::path Path
OS specific filesystem path. Alias of std::filesystem::path.
Definition Filesystem.hpp:10
const uint32_t kCommandQueueTransferIgnored
Definition Command.hpp:33
RHITextureLayout
Definition Common.hpp:99
glm::vec< 4, float > RHIClearColor
Definition Common.hpp:16
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
Pair< float, uint32_t > RHIClearDepthStencil
Definition Common.hpp:18
static constexpr Handle kInvalidHandle
Definition Details.hpp:10
RHIDeviceQueueType
Definition Common.hpp:69
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
Core functionalities for rendering, including the Frame Graph implementation.
Definition Renderer.hpp:12
ResourceHandle createResource(Renderer *r, StringView name, T const &desc)
Convenient functional wrapper to create a resource.
Definition Renderer.hpp:904
LambdaPass< FSetup, FRecord, FSkip > * createPass(Renderer *r, StringView name, RHIDeviceQueueType queue, FSetup &&setup, FRecord &&record, FSkip &&skip={})
Convenient functional wrapper to create a pass from Setup/Record lambdas.
Definition Renderer.hpp:1000
size_t ResourceHandle
Definition RenderPass.hpp:12
T * createPassImpl(Renderer *r, StringView name, RHIDeviceQueueType queue, Args &&... args)
Convenient functional wrapper to create a pass from a RenderPass* implementation.
Definition Renderer.hpp:945
ResourceHandle createSampler(Renderer *r, RHIDeviceSampler::SamplerDesc const &desc)
Convenient functional wrapper to create a sampler.
Definition Renderer.hpp:913
size_t PassHandle
Definition RenderPass.hpp:11
const RHIResourceAccessBits kAllShaderWrites
Definition Renderer.hpp:62
LambdaPass< FSetup, FRecord, FSkip > * createPassPriority(Renderer *r, StringView name, RHIDeviceQueueType queue, size_t priority, FSetup &&setup, FRecord &&record, FSkip &&skip={})
Convenient functional wrapper to create a pass from Setup/Record lambdas with custom priority.
Definition Renderer.hpp:970
T * createPassImplPriority(Renderer *r, StringView name, RHIDeviceQueueType queue, size_t priority, Args &&... args)
Convenient functional wrapper to create a pass from a RenderPass* implementation with custom priority...
Definition Renderer.hpp:929
constexpr size_t kMaxRenderPasses
Definition Renderer.hpp:50
const RHIResourceAccessBits kAllShaderReads
Definition Renderer.hpp:65
const RHIPipelineStage kComputeStagesMask
Definition Renderer.hpp:59
const String kBindpointIgnored
Definition Renderer.hpp:58
constexpr size_t kExecuteArenaSize
Definition Renderer.hpp:54
constexpr size_t kMaxCommandListsPerThread
Definition Renderer.hpp:52
Extended std::variant with C++23 visit() behavior and convenience Get()/GetIf() methods.
Definition Functional.hpp:17
RAII wrapper for an arena allocated from an Allocator.
Definition Allocator.hpp:43
RAII guard to wait for device idle on destruction.
Definition Device.hpp:205
Definition Resource.hpp:141
Parameters for Renderer creation.
Definition Renderer.hpp:17
bool enableAsyncCompute
Enable Async Compute support.
Definition Renderer.hpp:32
bool enablePresent
Enable presentation support.
Definition Renderer.hpp:39
uint32_t numRenderThreads
Number of worker threads to use for recording command lists.
Definition Renderer.hpp:44
RHICommandList * AllocateCompute(int thread_id)
Definition Renderer.cpp:1327
Vector< RHICommandPoolScopedHandle< RHICommandList > > computeCmds
Definition Renderer.hpp:203
RHIDeviceScopedObjectHandle< RHICommandPool > graphicsPool
Definition Renderer.hpp:202
RHIDeviceScopedObjectHandle< RHICommandPool > computePool
Definition Renderer.hpp:202
Vector< RHICommandPoolScopedHandle< RHICommandList > > graphicsCmds
Definition Renderer.hpp:203
RHICommandList * AllocateGraphics(int thread_id)
Definition Renderer.cpp:1317
RHIDeviceScopedObjectHandle< RHIDeviceSemaphore > render
Definition Renderer.hpp:166
RHIDeviceScopedObjectHandle< RHIDeviceSemaphore > present
Definition Renderer.hpp:166
RHIDeviceScopedObjectHandle< RHIDeviceFence > graphicsFence
Definition Renderer.hpp:167
ResourceHandle backbuffer
Definition Renderer.hpp:171
FrameSyncObjects(size_t swapIndex)
Definition Renderer.hpp:172
RHITextureScopedHandle< RHITextureView > rtv
Definition Renderer.hpp:169
RHIDeviceScopedObjectHandle< RHIDeviceFence > computeFence
Definition Renderer.hpp:167
const size_t swapIndex
Definition Renderer.hpp:165
Vector< PassHandle > passes
Definition Renderer.hpp:106
Vector< ResourceHandle > resources
Definition Renderer.hpp:108
ExecutionGroups(int groupIndex, RHIDeviceQueueType queue, Allocator *allocator)
Definition Renderer.hpp:113
const RHIDeviceQueueType queue
Definition Renderer.hpp:105
RHIPipelineStage allStages
Definition Renderer.hpp:111
Helper class containing all states pertaining to Renderer's Setup phase.
Definition Renderer.hpp:83
Vector< ExecutionGroups > executionGroups
Definition Renderer.hpp:118
PassHandle lastBackbufferProducer
Definition Renderer.hpp:89
bool executionAnyCompute
Definition Renderer.hpp:119
int executionNumGraphicsGroups
Definition Renderer.hpp:120
Vector< PassHandle > execution
Definition Renderer.hpp:96
Vector< Vector< Pair< PassHandle, ResourceHandle > > > graph
Definition Renderer.hpp:84
Vector< TrackedPass > trackedPasses
Definition Renderer.hpp:86
Map< ResourceHandle, Pair< PassHandle, PassHandle > > activeResources
Definition Renderer.hpp:94
int executionNumComputeGroups
Definition Renderer.hpp:120
void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
Definition Renderer.hpp:121
PassHandle epilogue
Definition Renderer.hpp:98
Vector< RHIDeviceSampler::SamplerDesc > trackedSamplers
Definition Renderer.hpp:92
Map< RHIDescriptorType, uint32_t > bindingCounts
Definition Renderer.hpp:97
Vector< TrackedResource > trackedResources
Definition Renderer.hpp:87
Vector< Pair< ResourceHandle, RHITextureViewDesc > > trackedViews
Definition Renderer.hpp:91
Vector< PassHandle > indegree
Definition Renderer.hpp:85
bool executionAnyGraphics
Definition Renderer.hpp:119
RendererSetup(Allocator *allocator)
Definition Renderer.hpp:130
Internal tracking information for a render pass in the frame graph.
Definition RenderPass.hpp:99
Internal tracking information for a resource in the frame graph.
Definition RenderResource.hpp:18