Foundation
Loading...
Searching...
No Matches
Renderer.hpp
Go to the documentation of this file.
1#pragma once
3#include <Core/JobSystem.hpp>
4#include <Core/Logging.hpp>
5#include <Core/ThreadPool.hpp>
6#include <RHICore/Command.hpp>
8#include <RHICore/Device.hpp>
10#include "Shader.hpp"
11
12using namespace Foundation;
13using namespace RHI;
18{
19 class Presenter;
20 class Renderer;
21 using PassHandle = Handle; // Index in the pass definitions vector
22 using ResourceHandle = Handle; // Index in the resource definitions vector
24 {
25 friend class Renderer;
28
30 mCurrent(current), mPrevious(previous)
31 {
32 }
33
34 public:
36 [[nodiscard]] ResourceHandle Current() const { return mCurrent; }
37 [[nodiscard]] ResourceHandle Previous() const { return mPrevious; }
38 [[nodiscard]] bool IsValid() const
39 {
41 }
42 };
47 {
62 bool asyncCompute{true};
67 uint32_t threadCount{4u};
82 bool profilePasses{true};
83 };
84 /* -- Constants -- */
85 // Maximum number of render passes per frame
86 // NOTE: The limit here is mostly arbitrary - and is only used
87 // for the default priority heuristic when determining pass order.
88 constexpr size_t kMaxRenderPasses = 1024;
89 // Maximum number of command lists per frame
91 // Maximum size of the per-frame transient arena (16MB)
92 constexpr size_t kExecuteArenaSize = 16 * (1 << 20);
93 const RHIPipelineStage kComputeStagesMask = RHIPipelineStageBits::FragmentShader |
94 RHIPipelineStageBits::VertexShader | RHIPipelineStageBits::MeshShader | RHIPipelineStageBits::RayTracingShader |
95 RHIPipelineStageBits::AllGraphics;
96 const RHIResourceAccessBits kAllShaderWrites = RHIResourceAccessBits::ShaderWrite |
97 RHIResourceAccessBits::RenderTargetWrite | RHIResourceAccessBits::DepthStencilWrite |
98 RHIResourceAccessBits::TransferWrite | RHIResourceAccessBits::HostWrite;
99 const RHIResourceAccessBits kAllShaderReads = RHIResourceAccessBits::ShaderRead |
100 RHIResourceAccessBits::RenderTargetRead | RHIResourceAccessBits::DepthStencilRead |
101 RHIResourceAccessBits::UniformRead | RHIResourceAccessBits::TransferRead | RHIResourceAccessBits::HostRead;
104 RHITextureDesc, /* RHIAccelerationStructureDesc - not yet. Do we want to do this in RG at all? */
106 const size_t kTextureAspectCount = 3; // Color, depth, stencil @ref RHITextureAspectFlag
111 {
112 ResourceHandle handle; // Index to tracked resources
117 bool hasComputeUsage{false}; // Used in a compute pass?
118 bool hasGraphicsUsage{false}; // Used in a graphics pass?
119 /* --- states --- */
120 // (Buffer) Last known state
121 // Transitions here are always global since granularity would be too fine. And seems
122 // like drivers don't really care?
123 // See Also: https://www.reddit.com/r/vulkan/comments/v2mswb/global_memory_barriers_vs_bufferimage_memory/
124 // TODO: Investigate
126 {
127 // Last pass to write at Setup time
129 // Last pass to transition at Execute time
131 // Last frame the transition was executed
133 // Last queue this resource is owned by
134 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
135 // [Only used by @ref ExecuteReleaseQueueResources]
137 RHIResourceAccess access{};
138 RHIPipelineStage stage{};
139 void reset()
140 {
142 access = {};
143 stage = {};
144 }
146
147 // (Texture) Per-subresource states
148 uint32_t textureLayers{0}, textureMips{0};
150 {
151 size_t layer{0}, mip{0};
152 RHITextureAspectFlagBits aspect{};
153 /* -- states -- */
154 // Last pass to write at Setup time
156 // Last pass to transition at Execute time
158 // Last frame the transition was executed
160 // Last queue this resource is owned by
161 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
162 // [Only used by @ref ExecuteReleaseQueueResources]
164 RHIResourceAccess access{};
165 RHIPipelineStage stage{};
167 void reset()
168 {
170 access = {};
171 stage = {};
172 layout = {};
173 }
174 [[nodiscard]] RHITextureSubresourceRange ToRange() const;
175 };
176 // [mip...,
177 // layer...,
178 // aspect...]
181 {
182 auto [mip_begin, mip_end] = range.GetMipLevelRange();
183 auto [layer_begin, layer_end] = range.GetArrayLayerRange();
184 CHECK(mip_end < textureMips);
185 CHECK(layer_end < textureLayers);
186 uint32_t mip_stride = textureLayers * kTextureAspectCount;
187 return std::views::all(Span<SubresourceState>(lastSubresourceStates.begin() + mip_begin * mip_stride,
188 lastSubresourceStates.begin() + (mip_end + 1) * mip_stride)) |
189 std::views::filter(
190 [=](const SubresourceState& state)
191 {
192 return (RHITextureAspectFlag(state.aspect) & range.layer.aspect) && state.mip >= mip_begin &&
193 state.mip <= mip_end && state.layer >= layer_begin && state.layer <= layer_end;
194 });
195 }
196
198 // (Acceleration Structure) Last known state
201 {
202 lastBufferState = {};
203 lastASState = {};
204 for (auto& sta : lastSubresourceStates)
205 sta.reset();
206 }
208 Allocator* alloc);
209 };
214 {
217 {
219 bool temporal{false};
220 };
226 explicit ExecuteResources(Allocator* allocator) : resources(allocator), views(allocator), samplers(allocator) {}
227 void fit(ResourceHandle handle)
228 {
229 resources.resize(std::max(resources.size(), static_cast<size_t>(handle + 1)));
230 views.resize(std::max(views.size(), static_cast<size_t>(handle + 1)));
231 samplers.resize(std::max(samplers.size(), static_cast<size_t>(handle + 1)));
232 }
233 };
237 class RenderPass : public RHIObject
238 {
239 public:
244 RenderPass() = default;
252 virtual void Setup(PassHandle self, Renderer* r) = 0;
262 virtual void Record(PassHandle self, Renderer* r, RHICommandList* cmd) = 0;
263 };
268 {
269 void operator()(PassHandle, Renderer*) const { /* nop */ }
270 };
275 {
276 void operator()(PassHandle, Renderer*, RHICommandList*) const { /* nop */ }
277 };
283 template <typename FSetup, typename FRecord>
285 {
286 FSetup mSetup;
287 FRecord mRecord;
288 LambdaPass(FSetup&& setup, FRecord&& record) :
289 mSetup(std::forward<FSetup>(setup)), mRecord(std::forward<FRecord>(record))
290 {
291 }
292 void Setup(PassHandle self, Renderer* r) override { mSetup(self, r); }
293 void Record(PassHandle self, Renderer* r, RHICommandList* cmd) override { mRecord(self, r, cmd); }
294 };
299 {
301 PassHandle handle; // Index to tracked passes
302 int priority{0}; // Higher priority passes are scheduled earlier
303 // The queue to run this pass on
305 bool used{false}; // Culled?
306 bool unCullable{false}; // Acts as an additional execution root
307 // Backbuffer specializations
309 Optional<int> backbufferUAV; // opt: set index
310 // Uses compute shader? (not necessarily in a compute queue)
311 // Should be mutually exclusive with write_backbuffer and other graphics states
312 bool isComputePass{false};
313 // Uses RayGen/RayHit/RayMiss at all?
314 // Should be compatible with most graphics states, and can be run on either queue
315 bool isRayTracingPass{false};
316 // Local size for compute/mesh shaders
318 size_t depth{}; // Depth in RG
319 size_t ord{}; // Execution order
320 size_t frameExec{}; // Last frame this pass is executed
321 /* -- Resources -- */
322 Vector<PassHandle> bindPasses; // Referenced, explicit pass execute-before.
323 Vector<Tuple<ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange,
325 textureUsages; // Referenced texture sub resources
326 Vector<Tuple<ResourceHandle, RHIResourceAccess,
327 RHIPipelineStage>> bufferUsages; // Referenced buffers
328 Vector<Tuple<ResourceHandle, RHIResourceAccess,
329 RHIPipelineStage>>
330 asUsages; // Referenced Acceleration Structures
331 // Unique referenced resources (tex/buf/AS)
333 // Unique texture views
335 /* -- Pipeline -- */
336 // Shader [path, entry point, stage, specialization data, RT hit group, RT hit group type]
340 // Bind points [view(tex) or buffer(buf), desc type, binding point]
342 // External Bind Sets [binding point, layout ptr, set index (set when built)]
343 // Sorted lexicographically if the pipeline is built.
345 // Samplers
347 // Push Constant
349 // Specialization Constants by [stage, offset, value]
351 // (Graphics Only) Render Target View[s], Blending Op
353 // (Graphics Only) Depth Stencil View
355 bool isDepthReadOnly{false};
356 // (Graphics Only) Vertex Input assembly
359 /* --- */
362 UniquePtr<RenderPass> renderPass, size_t priority);
363 /* -- Pipeline states (built at PSO setup) -- */
364 int groupIndex{}; // executionGroup index
365 // All stages used in this pass
366 RHIPipelineStageBits piplineStages{};
367 // Pipeline states for the entire pass
369 // PSO Creation parameters
373 // Layouts created by ourselves
375 // Pointers. Can also contain external sets
377 // Sets created by ourselves, with an alternate mapping for temporal resources
380 // [Set Index, Set, Layout], correspond to externalBindings
382
383
384 RHIDevicePipelineType GetPipelineType() const
385 {
386 if (isComputePass)
387 return RHIDevicePipelineType::Compute;
389 return RHIDevicePipelineType::RayTracing;
390 return RHIDevicePipelineType::Graphics;
391 }
392 void ResetPipeline();
393 };
404 {
409 {
420 // Backbuffer specializations
422 // [resource, view desc]
425 // [resource, ord range]
428 // Passes ordered by pass.ord
432 // Execution grouped by queue type
434 {
435 const int groupIndex{}; // Index in executionGroups
436 int graphicsGroupIndex{-1}; // Index of all unique graphics groups before this one
437 int computeGroupIndex{-1}; // Index of all unique compute groups before this one
440 // Resources used in this group
442 bool isLastGraphics = false;
443 bool isLastCompute = false;
444
446 groupIndex(groupIndex), queue(queue), passes(allocator), resources(allocator)
447 {
448 }
449 };
453 void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
454 {
456 while (u >= graph.size())
457 graph.emplace_back(graph.get_allocator());
458 graph[u].emplace_back(v, hdl);
459 while (v >= in.size())
460 in.push_back(0);
461 in[v]++;
462 }
463 explicit RendererSetup(Allocator* allocator) :
464 graph(allocator), in(allocator), trackedPasses(allocator), trackedResources(allocator),
465 temporalResources(allocator), trackedViews(allocator), trackedSamplers(allocator), activeResources(allocator),
466 descriptorSetWriters(allocator), execution(allocator), bindingCounts(allocator), executionGroups(allocator)
467 {
468 }
469 };
470
471 public:
472 enum class State
473 {
474 Undefined, // Initialized
475 Setup, // During BeginSetup(), EndSetup(). No work on the GPU yet.
476 PostSetup, // Safe state (with a device wait), after EndSetup(), EndExecute()
477 Execute // During BeginExecute(), EndExecute()
478 };
479
480 private:
485
487
488 uint64_t mFrameSwapped{0}; // Frame rendered in the current Swapchain
489
490 uint32_t mFrameSwaps{1}; // Max frames in flight
491 uint32_t mCurrentSync{0};
492 uint32_t mCurrentSwap{0};
494
498 // Per swap primitives
521
523 // Semaphore for async compute
528
530 // Setup
532 RHITextureViewDesc const& desc) const;
533 // PostSetup
534 void CullPasses(PassHandle epilogue) const;
537 void FinalizeResources();
538 void FinalizePasses();
539 // Temporary memory arena for execution
541 // Temporary allocator for execution
542 // This is reset every frame, and only guaranteed to be valid during Execute state.
544 // Temporary storage for submits calls
545 // This is reset every frame, and only guaranteed to be valid during Execute state.
547 // Thread pool for concurrent command list recording
560 // [current sync][thread id]
572 [[nodiscard]] uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
573 {
574 switch (queue)
575 {
576 case RHIDeviceQueueType::Undefined:
578 case RHIDeviceQueueType::Graphics:
580 case RHIDeviceQueueType::Compute:
582 default:
583 CHECK_MSG(false, "Unhandled queue type");
585 }
586 }
591 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
597 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
602 void ExecuteBarrierBuffer(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
603 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
607 void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
608 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
609 [[nodiscard]] ResourceHandle ResolveResourceHandle(ResourceHandle handle, uint64_t frame) const;
613 DerefResourceAtFrame(ResourceHandle handle, uint64_t frame) const;
614 [[nodiscard]] RHITextureView* DerefTextureViewAtFrame(ResourceHandle handle, uint64_t frame) const;
623 void AcquireSync();
637 void BeginExecute(uint32_t swapImageIndex, RHIDeviceSemaphore* imageAcquire);
641 void SetFrameSyncObjects();
650 void DeclareBufferAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
651 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead) const;
659 void DeclareTextureAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
661 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead,
662 RHITextureLayout layout = RHITextureLayout::ShaderReadOnly) const;
663 RHIDeviceIdleGuard mWaitIdle; // Ensure device is idle on destruction
664 public:
665 Renderer() = delete;
667 RHIDeviceHandle<RHISwapchain> swapchain, Core::JobSystem* jobs, Allocator* allocator);
668
669#pragma region Render Graph Setup
675 void BeginSetup();
686 template <typename T, typename... Args>
687 requires std::is_base_of_v<RenderPass, T>
688 PassHandle CreatePassImpl(StringView name, RHIDeviceQueueType queue, size_t priority, Args&&... args)
689 {
691 CHECK_MSG(queue == RHIDeviceQueueType::Graphics || queue == RHIDeviceQueueType::Compute,
692 "Invalid queue type. Only Graphics and Compute queues are supported.");
693 PassHandle handle = mSetup->trackedPasses.size();
694 CHECK_MSG(handle < kMaxRenderPasses, "Exceeded maximum number of render passes ({})", kMaxRenderPasses);
695 if (!mDesc.asyncCompute)
696 queue = RHIDeviceQueueType::Graphics; // Force graphics queue if async compute is disabled
697 mSetup->trackedPasses.emplace_back(
698 mAllocator, handle, name, queue,
699 ConstructUniqueBase<RenderPass, T>(mAllocator, std::forward<Args>(args)...), priority);
700 mSetup->epilogue = handle;
701 return handle;
702 }
718 template <typename FSetup, typename FRecord>
719 PassHandle CreatePass(StringView name, RHIDeviceQueueType queue, size_t priority, FSetup&& setup,
720 FRecord&& record)
721 {
722 return CreatePassImpl<LambdaPass<FSetup, FRecord>>(name, queue, priority, std::forward<FSetup>(setup),
723 std::forward<FRecord>(record));
724 }
743 template <typename T>
744 [[nodiscard]] ResourceHandle CreateResource(StringView name, T const& desc)
745 {
746
748
749 ResourceHandle index = mSetup->trackedResources.size();
750 mSetup->trackedResources.emplace_back(index, name, desc, mAllocator);
751 return mSetup->trackedResources.size() - 1;
752 }
759 template <typename T>
761 {
762 static_assert(std::is_same_v<T, RHIBufferDesc> || std::is_same_v<T, RHITextureDesc>,
763 "Temporal resources currently support owned buffers and textures only");
765
766 ResourceHandle current = CreateResource(Format("{} [0]", name), desc);
767 ResourceHandle previous = CreateResource(Format("{} [1]", name), desc);
768 ResourceHandle family = mSetup->temporalResources.size();
769 mSetup->temporalResources.push_back({{current, previous}, mFrameSwapped});
770 mSetup->trackedResources[current].temporalFamily = family;
771 mSetup->trackedResources[current].temporalFramesAgo = 0;
772 mSetup->trackedResources[previous].temporalFamily = family;
773 mSetup->trackedResources[previous].temporalFramesAgo = 1;
774 return TemporalResourceHandle(current, previous);
775 }
784 [[nodiscard]] ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const& desc) const;
785#pragma region Resource Binding
792 void BindPass(PassHandle pass, PassHandle other);
804 void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, StringView shader_path,
805 Span<const char> specializationData = {}, uint32_t rtHitGroupIndex = 0,
807 RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles) const;
816 void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const;
843 void BindBufferUniform(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
844 StringView bind_point) const;
857 void BindBufferStorageRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
858 StringView bind_point) const;
871 void BindBufferUnordered(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
872 StringView bind_point) const;
881 void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const;
888 void BindBufferIndirectRead(PassHandle pass, ResourceHandle buffer) const;
894 void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const;
900 void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const;
909 void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const;
921 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
928 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
943 void MakePassUncullable(PassHandle pass) const;
954 void BindTextureSRV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
955 RHITextureViewDesc const& desc) const;
969 void BindTextureUAV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
970 RHITextureViewDesc const& desc) const;
976 void BindTextureShaderRead(PassHandle pass, ResourceHandle texture, RHIPipelineStage stage,
977 RHITextureSubresourceRange const& range) const;
988 void BindTextureRTV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
998 void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
999 bool readOnly = false) const;
1006 void BindBackbufferRTV(PassHandle pass,
1012 void BindBackbufferUAV(PassHandle pass, int set_index) const;
1019 void BindTextureCopyDst(PassHandle pass, ResourceHandle texture,
1020 RHITextureSubresourceRange const& range = {}) const;
1027 void BindTextureCopySrc(PassHandle pass, ResourceHandle texture,
1028 RHITextureSubresourceRange const& range = {}) const;
1039 void BindAccelerationStructureSRV(PassHandle pass, ResourceHandle as, RHIPipelineStage stage,
1040 StringView bind_point) const;
1041
1042#pragma endregion
1043#pragma region PSO Flags
1052 RHIPipelineState::PipelineStateDesc::DepthStencil const& depth_stencil = {}) const;
1057#pragma endregion
1069 Core::JobBarrier EndSetup(bool wait = true);
1070#pragma endregion
1071#pragma region Diagnostics
1073 {
1075 size_t bytes;
1076 };
1085 void DbgGetMemoryStatistics(Vector<MemoryStat>& outStats) const;
1087#pragma endregion
1088#pragma region Swapchain
1092 [[nodiscard]] RHIDevice* GetDevice() const { return mDevice.Get(); }
1096 [[nodiscard]] const RHIApplication* GetApplication() const { return &mDevice->mApp; }
1101 [[nodiscard]] RHIExtent2D GetSwapchainExtent() const
1102 {
1103 CHECK(mSwapchain && "Swapchain not initialized");
1104 return mSwapchain->mDesc.extents;
1105 }
1110 [[nodiscard]] RHIExtent3D GetSwapchainExtent3D() const
1111 {
1112 CHECK(mSwapchain && "Swapchain not initialized");
1113 auto xy = mSwapchain->mDesc.extents;
1114 return {xy.x, xy.y, 1};
1115 }
1116#pragma endregion
1117#pragma region Render Graph Runtime
1130 DerefResource(const ResourceHandle handle) const
1131 {
1132 return DerefResourceAtFrame(handle, mFrameSwapped);
1133 }
1139 [[nodiscard]] RHITextureView* DerefTextureView(const ResourceHandle handle) const
1140 {
1141 return DerefTextureViewAtFrame(handle, mFrameSwapped);
1142 }
1148 [[nodiscard]] RHIDeviceSampler* DerefSampler(const ResourceHandle handle) const
1149 {
1150 CHECK(mSetup && handle < mSetup->trackedSamplers.size());
1151 return mResources->samplers[handle].Get();
1152 }
1156 [[nodiscard]] RHIPipelineState* DerefPipelineState(const PassHandle pass) const
1157 {
1158 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1159 auto& tpass = mSetup->trackedPasses[pass];
1160 return tpass.pso.Get();
1161 }
1166 {
1167 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1168 auto& tpass = mSetup->trackedPasses[pass];
1169 return tpass.pDescriptorSets;
1170 }
1174 [[nodiscard]] Allocator* GetAllocator() const { return mAllocator; }
1175#pragma endregion
1176#pragma region Command Recording Helpers
1182 [[nodiscard]] RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const;
1198 void CmdDispatch(PassHandle pass, RHICommandList* cmd, RHIExtent3D thread_size) const;
1203 void CmdSetPipeline(PassHandle pass, RHICommandList* cmd) const;
1207 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, uint32_t set_index,
1208 RHIDeviceDescriptorSet* descriptor_set) const;
1215 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, StringView bind_point,
1216 RHIDeviceDescriptorSet* descriptor_set) const;
1226 void CmdBeginGraphics(PassHandle pass, RHICommandList* cmd, RHIExtent2D const& extent,
1228 RHIDepthAttachmentLoad dsv_load = {RHIAttachmentLoadOp::Clear, {0.0f, 0u}});
1235 template <typename T>
1236 void CmdSetPushConstant(PassHandle pass, RHICommandList* cmd, RHIShaderStage stage, size_t offset,
1237 T const& data)
1238 {
1240 auto& tpass = mSetup->trackedPasses[pass];
1241 cmd->PushConstant(tpass.pso.Get(), stage, static_cast<uint32_t>(offset),
1242 {reinterpret_cast<const char*>(&data), sizeof(T)});
1243 }
1244#pragma endregion
1245#pragma region Frame Execution
1249 [[nodiscard]] State GetState() const { return mState; }
1253 [[nodiscard]] uint32_t GetFrameSwaps() const { return mFrameSwaps; }
1260 [[nodiscard]] uint64_t GetFrame() const { return mFrameSwapped; }
1264 [[nodiscard]] bool IsPreviousValid(TemporalResourceHandle resource) const;
1281 [[nodiscard]] uint32_t GetSwap() const { return mCurrentSwap; }
1295 [[nodiscard]] uint64_t GetSync() const { return mCurrentSync; }
1300 {
1301 CHECK_MSG(mSetup && pass < mSetup->trackedPasses.size(), "No passes available or out of bounds");
1302 return mSetup->trackedPasses[pass];
1303 }
1310 [[nodiscard]] bool IsAsyncComputeEnabled() const { return mDesc.asyncCompute; }
1320 [[nodiscard]] bool IsPresentEnabled() const { return mSwapchain.IsValid(); }
1336 RHISwapchain* GetSwapchain() const { return mSwapchain.Get(); }
1337
1342
1363 void WaitForFrame();
1375 void BeginExecute();
1396 void ExecuteFrame();
1403 void EndExecute();
1404#pragma endregion
1405#pragma region Debugging
1407 {
1410 RHIDeviceQueueType queue{RHIDeviceQueueType::Undefined};
1411 bool used{};
1412 bool epilogue{};
1413 size_t depth{};
1414 size_t ord{};
1416 };
1423 void DbgGetGraph(Vector<DebugGraphNode>& outNodes, Vector<DebugGraphEdge>& outEdges) const;
1424 [[nodiscard]] String DbgDumpGraphviz() const;
1425 [[nodiscard]] String DbgDumpActivePasses() const;
1426 [[nodiscard]] String DbgDumpExecutionGroups() const;
1435 Span<const uint64_t> DbgProfilePassTiming(uint64_t sync, float& resolutionNS) const;
1436
1437#pragma endregion
1438 };
1442 ENUM_NAME(PostSetup);
1443 ENUM_NAME(Execute);
1445} // namespace Foundation::RenderCore
#define CHECK_MSG(expr, format_str,...)
#define CHECK(expr)
Definition Logging.hpp:92
#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
Implements a lock-free stack-based bump allocator.
Definition AllocatorStack.hpp:13
Allocator interface (noexcept)
Definition Allocator.hpp:29
Definition JobSystem.hpp:86
Definition JobSystem.hpp:135
Atomic, lock-free Thread Pool implementation with fixed bounds.
Definition ThreadPool.hpp:51
The root object of everything RHI. Implementation of this class inherently defines the RHI backend.
Definition Application.hpp:24
Definition Resource.hpp:57
Definition Command.hpp:42
virtual RHICommandList & PushConstant(RHIPipelineState *pipeline, RHIShaderStage stage, uint32_t offset, Span< const char > data)=0
Definition Descriptor.hpp:12
Definition Device.hpp:17
virtual uint32_t GetVkQueueFamily() const =0
Definition Device.hpp:105
Definition Device.hpp:56
Definition Device.hpp:246
Handle type for RHI Objects.
Definition Details.hpp:43
Base class for all RHI objects.
Definition Details.hpp:17
Definition PipelineState.hpp:43
Definition PipelineState.hpp:60
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:85
Definition Swapchain.hpp:32
Definition Resource.hpp:238
Definition Resource.hpp:216
Definition Presenter.hpp:12
Interface for a render pass.
Definition Renderer.hpp:238
virtual void Setup(PassHandle self, Renderer *r)=0
Perform any setup required for this pass. This may include creating resources, declaring resource acc...
RenderPass()=default
Constructor. You may also create resources here for early setup. However, access declaration must be ...
virtual void Record(PassHandle self, Renderer *r, RHICommandList *cmd)=0
Record the commands of this pass into the given command list.
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:404
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:719
void DbgGetTexturePreviews(Vector< TexturePreviewStat > &outStats) const
Definition Renderer.cpp:1520
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefResource(const ResourceHandle handle) const
Dereference a resource handle to its underlying RHI resource.
Definition Renderer.hpp:1130
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:441
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:557
Atomic< bool > mPipelineStateCompilationComplete
Definition Renderer.hpp:484
UniquePtr< ExecuteResources > mResources
Definition Renderer.hpp:495
RHIDeviceSemaphore * mExecuteImageAcquire
Definition Renderer.hpp:493
void BindTextureShaderRead(PassHandle pass, ResourceHandle texture, RHIPipelineStage stage, RHITextureSubresourceRange const &range) const
Declares a shader read dependency for a texture without creating an internal binding.
Definition Renderer.cpp:431
void BeginSetup()
Begins the setup phase of the render graph.
Definition Renderer.cpp:126
void DbgGetMemoryStatistics(Vector< MemoryStat > &outStats) const
Definition Renderer.cpp:1481
RHICommandList * ExecuteAllocateCommandList(RHIDeviceQueueType queue, int thread_id=-1)
Definition Renderer.cpp:1957
RHIDeviceHandle< RHISwapchain > mSwapchain
Definition Renderer.hpp:526
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:215
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:332
Vector< Pair< RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc > > * mExecuteSubmits
Definition Renderer.hpp:546
void WaitForFrame()
Blocks until the most recently submitted frame has finished executing on the GPU.
Definition Renderer.cpp:1651
State mState
Definition Renderer.hpp:481
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:2348
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefPhysicalResource(ResourceHandle handle) const
Definition Renderer.cpp:170
void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for an acceleration structure.
Definition Renderer.cpp:1838
Core::JobBarrier BuildPipelineStateAll()
Definition Renderer.cpp:1333
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:404
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
Definition Renderer.hpp:561
RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > mSwapDescriptorSetLayout
Definition Renderer.hpp:520
RHIDeviceSampler * DerefSampler(const ResourceHandle handle) const
Dereference a sampler handle to its underlying RHI sampler.
Definition Renderer.hpp:1148
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:1974
void ExecuteBarrierSubresourceState(PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const
Definition Renderer.cpp:1759
RHIDeviceQueue * mGraphicsQueue
Definition Renderer.hpp:527
Vector< RHIDeviceDescriptorSet * > const & DerefDescriptorSets(const PassHandle pass) const
Dereference the built descriptor sets associated with a given pass.
Definition Renderer.hpp:1165
uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
Helper to get the queue index of a queue type.
Definition Renderer.hpp:572
ResourceHandle CreateTextureView(PassHandle pass, ResourceHandle handle, RHITextureViewDesc const &desc) const
Definition Renderer.cpp:147
void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const
Binds a sampler to the shader.
Definition Renderer.cpp:356
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:1793
void BindDescriptorSetWrite(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout, RHIDeviceDescriptorSetLayout *reading_layout=nullptr)
Binds an externally managed descriptor set that this pass writes.
Definition Renderer.cpp:363
Vector< Pair< Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * >, RHICommandList::TransitionDesc > > ExecuteBarrierList
Definition Renderer.hpp:588
const RHIApplication * GetApplication() const
Get the RHIApplication this Renderer was constructed with.
Definition Renderer.hpp:1096
ScopedArena mExecuteArena
Definition Renderer.hpp:540
void MakePassUncullable(PassHandle pass) const
Marks a pass as "uncullable", meaning it will always be executed even if it has no dependencies.
Definition Renderer.cpp:141
void CmdDispatch(PassHandle pass, RHICommandList *cmd, RHIExtent3D thread_size) const
Helper that dispatches a compute shader with the specified THREAD count.
Definition Renderer.cpp:2434
Mutex mDescPoolMutex
Definition Renderer.hpp:497
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Definition Renderer.cpp:483
void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const
Associates Vertex Input description with this pass.
Definition Renderer.cpp:285
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:2332
uint32_t mFrameSwaps
Definition Renderer.hpp:490
void InvalidateTemporalResource(TemporalResourceHandle resource)
Invalidates Previous() until the current frame has produced a replacement.
Definition Renderer.cpp:1641
void FinalizePasses()
Definition Renderer.cpp:1360
void BuildPipelineState(PassHandle pass)
Definition Renderer.cpp:833
void BindPass(PassHandle pass, PassHandle other)
Declares an inter-pass dependency, where the other pass should execute-before the current pass.
Definition Renderer.cpp:205
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:314
RHIDeviceScopedHandle< RHIDeviceSemaphore > mGraphicsTimeline
Definition Renderer.hpp:524
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:1572
String DbgDumpActivePasses() const
Definition Renderer.cpp:2523
RHIPipelineState * DerefPipelineState(const PassHandle pass) const
Dereference the automatically built pipeline state object handle associated with a given pass.
Definition Renderer.hpp:1156
ResourceHandle ResolveResourceHandle(ResourceHandle handle, uint64_t frame) const
Definition Renderer.cpp:156
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:688
uint32_t GetFrameSwaps() const
Get the number of frames that can be simultaneously in-flight.
Definition Renderer.hpp:1253
AllocatorStack mExecuteAlloc
Definition Renderer.hpp:543
Vector< FrameSyncObjects > mSwaps
Definition Renderer.hpp:522
String DbgDumpExecutionGroups() const
Definition Renderer.cpp:2536
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:543
uint64_t mFrameSwapped
Definition Renderer.hpp:488
void CmdBeginGraphics(PassHandle pass, RHICommandList *cmd, RHIExtent2D const &extent, Span< const RHIColorAttachmentLoad > rtv_loads={}, RHIDepthAttachmentLoad dsv_load={RHIAttachmentLoadOp::Clear, {0.0f, 0u}})
Helper that pushes correct descriptor sets and PSO to the current command list, and pushes correct Be...
Definition Renderer.cpp:2371
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mDescPool
Definition Renderer.hpp:496
ThreadPool mExecuteThreadPool
Definition Renderer.hpp:548
RHITextureView * DerefTextureViewAtFrame(ResourceHandle handle, uint64_t frame) const
Definition Renderer.cpp:188
void AcquireSync()
Acquires the synchronization primitives for the current frame. Internal. Called by BeginExecute.
Definition Renderer.cpp:1679
void SetFrameSyncObjects()
Sets backbuffer views and sync primitives.
Definition Renderer.cpp:1546
RHISwapchain * GetSwapchain() const
Returns the currently used RHISwapchain object.
Definition Renderer.hpp:1336
void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will read from the buffer via copy.
Definition Renderer.cpp:350
Core::JobBarrier EndSetup(bool wait=true)
Finish setting up the render graph.
Definition Renderer.cpp:574
uint32_t mCurrentSwap
Definition Renderer.hpp:492
RHIDevice * GetDevice() const
Get the RHIDevice this Renderer was constructed with.
Definition Renderer.hpp:1092
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:417
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:248
RHIExtent3D GetSwapchainExtent3D() const
Get the current swapchain extents as a 3D extent with depth 1.
Definition Renderer.hpp:1110
UniquePtr< RendererSetup > mSetup
Definition Renderer.hpp:529
void CullPasses(PassHandle epilogue) const
Definition Renderer.cpp:599
void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc, bool readOnly=false) const
Binds a texture as a Depth-Stencil View for a graphics pass.
Definition Renderer.cpp:461
Allocator * GetAllocator() const
Definition Renderer.hpp:1174
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:511
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:1101
RHIDeviceHandle< RHIDeviceSemaphore > GetRenderCompleteSemaphore() const
Binary semaphore signaled when GPU work for the current swap image is complete.
Definition Renderer.cpp:1625
RHIApplicationHandle< RHIDevice > mDevice
Definition Renderer.hpp:525
RendererDesc mDesc
Definition Renderer.hpp:486
Allocator * mAllocator
Definition Renderer.hpp:482
void ExecuteBarriers(TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes all barriers for a pass.
Definition Renderer.cpp:1868
void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will write to the buffer via copy.
Definition Renderer.cpp:344
void BeginExecute()
Begins execution for a headless (no swapchain) frame.
Definition Renderer.cpp:1743
TrackedPass const & GetTrackedPass(PassHandle pass)
Retrieves an internal tracked pass associated with the given handle, read-only.
Definition Renderer.hpp:1299
void BindBufferIndirectRead(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will consume this buffer as the source of an indirect draw/dispatch command.
Definition Renderer.cpp:338
void EndExecute()
Ends the execution phase and performs GPU submission.
Definition Renderer.cpp:2290
void FinalizeResources()
Definition Renderer.cpp:1381
uint32_t mCurrentSync
Definition Renderer.hpp:491
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:294
void ExecuteBarrierBuffer(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a whole buffer.
Definition Renderer.cpp:1809
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:2551
String DbgDumpGraphviz() const
Definition Renderer.cpp:2475
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefResourceAtFrame(ResourceHandle handle, uint64_t frame) const
Definition Renderer.cpp:183
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:521
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:323
void PassSetTopology(PassHandle pass, RHIPipelineState::PipelineStateDesc::Topology topology) const
Sets the input assembly topology for a graphics pass (TriangleList, LineList, etc....
Definition Renderer.cpp:567
RHIDeviceQueue * mComputeQueue
Definition Renderer.hpp:527
void BindAccelerationStructureWrite(PassHandle pass, ResourceHandle as) const
Declares that this pass will build, or update the AS.
Definition Renderer.cpp:531
void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, StringView shader_path, Span< const char > specializationData={}, uint32_t rtHitGroupIndex=0, RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType rtHitGroupType=RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles) const
Binds shader file path to a certain pass at a certain stage.
Definition Renderer.cpp:274
Core::JobSystem * mJobs
Definition Renderer.hpp:483
RHIDeviceScopedHandle< RHIDeviceSemaphore > mComputeTimeline
Definition Renderer.hpp:524
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:1236
void BindDescriptorSetRead(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout)
Binds an externally managed descriptor set that this pass reads.
Definition Renderer.cpp:390
bool IsAsyncComputeEnabled() const
Returns whether async compute is enabled.
Definition Renderer.hpp:1310
RHIDeviceIdleGuard mWaitIdle
Definition Renderer.hpp:663
uint64_t GetSync() const
Retrieves the current synchronization index.
Definition Renderer.hpp:1295
State
Definition Renderer.hpp:473
bool IsPresentEnabled() const
Returns whether a swapchain is bound.
Definition Renderer.hpp:1320
TemporalResourceHandle CreateTemporalResource(StringView name, T const &desc)
Creates a double-buffered resource with frame-relative handles.
Definition Renderer.hpp:760
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:2425
uint32_t GetSwap() const
Retrieves the current swap index at the time of ExecuteFrame().
Definition Renderer.hpp:1281
uint64_t GetFrame() const
Retrieves the current frame number.
Definition Renderer.hpp:1260
bool IsPreviousValid(TemporalResourceHandle resource) const
Returns whether Previous() contains a frame produced since the last invalidation.
Definition Renderer.cpp:1633
State GetState() const
Retrieves the current state of the renderer.
Definition Renderer.hpp:1249
void DbgGetGraph(Vector< DebugGraphNode > &outNodes, Vector< DebugGraphEdge > &outEdges) const
Definition Renderer.cpp:2443
RHITextureView * DerefTextureView(const ResourceHandle handle) const
Dereference a texture view handle to its underlying RHI texture view.
Definition Renderer.hpp:1139
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:305
ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const &desc) const
Creates a sampler with the specified name and descriptor.
Definition Renderer.cpp:198
ResourceHandle CreateResource(StringView name, T const &desc)
Create a new resource to be used in the render graph.
Definition Renderer.hpp:744
void BindBackbufferUAV(PassHandle pass, int set_index) const
Binds the backbuffer as RW access at binding 0 of set index.
Definition Renderer.cpp:497
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mSwapDescriptorPool
Definition Renderer.hpp:519
ResourceHandle Current() const
Definition Renderer.hpp:36
TemporalResourceHandle(ResourceHandle current, ResourceHandle previous)
Definition Renderer.hpp:29
bool IsValid() const
Definition Renderer.hpp:38
ResourceHandle mPrevious
Definition Renderer.hpp:27
ResourceHandle mCurrent
Definition Renderer.hpp:26
ResourceHandle Previous() const
Definition Renderer.hpp:37
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:149
std::tuple< Args... > Tuple
Alias for std::tuple
Definition Container.hpp:39
std::mutex Mutex
Definition Thread.hpp:10
constexpr String Format(fmt::format_string< Args... > format, Args &&... args)
String wrapper for Format().
Definition Container.hpp:126
std::map< K, V, Predicate, StlAllocator< Pair< const K, V > > > Map
std::map with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:178
std::atomic< T > Atomic
Alias of std::atomic<T>.
Definition Atomic.hpp:26
std::basic_string< char, std::char_traits< char >, StlDefaultAllocator< char > > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:120
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:56
std::unique_ptr< T, Deleter > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:180
std::span< T > Span
Alias for std::span
Definition Container.hpp:62
const uint32_t kCommandQueueTransferIgnored
Definition Command.hpp:40
RHITextureLayout
Definition Common.hpp:218
uintptr_t Handle
Definition Details.hpp:9
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
RHIDeviceQueueType
Definition Common.hpp:179
static constexpr Handle kInvalidHandle
Definition Details.hpp:10
RHIResourceFormat
Definition Common.hpp:34
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
RHISwapchainResult
Definition Swapchain.hpp:9
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
Handle ResourceHandle
Definition Renderer.hpp:22
const size_t kTextureAspectCount
Definition Renderer.hpp:106
const RHIResourceAccessBits kAllShaderWrites
Definition Renderer.hpp:96
constexpr size_t kMaxRenderPasses
Definition Renderer.hpp:88
const RHIResourceAccessBits kAllShaderReads
Definition Renderer.hpp:99
const RHIPipelineStage kComputeStagesMask
Definition Renderer.hpp:93
Handle PassHandle
Definition Renderer.hpp:21
constexpr size_t kExecuteArenaSize
Definition Renderer.hpp:92
constexpr size_t kMaxCommandListsPerThread
Definition Renderer.hpp:90
Definition Allocator.hpp:6
std::optional with convenience Get()/GetIf() methods.
Definition Container.hpp:256
RAII wrapper for an arena allocated from an Allocator.
Definition Allocator.hpp:49
Definition Resource.hpp:28
RAII guard to wait for device idle on destruction.
Definition Device.hpp:378
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Topology TriangleList
RayTracingHitGroupType
Definition PipelineState.hpp:186
Definition Resource.hpp:142
RHITextureAspectFlag aspect
Definition Resource.hpp:161
RHITextureSubresourceLayer layer
Definition Resource.hpp:169
Pair< uint32_t, uint32_t > GetMipLevelRange() const
Definition Resource.hpp:173
Pair< uint32_t, uint32_t > GetArrayLayerRange() const
Definition Resource.hpp:178
Definition Resource.hpp:210
TextureViewHandle slots[2]
Definition Renderer.hpp:218
Helper class containing runtime resources either imported, or created by the Renderer.
Definition Renderer.hpp:214
Vector< Variant< RHIBuffer *, RHIDeviceScopedHandle< RHIBuffer >, RHITexture *, RHIDeviceScopedHandle< RHITexture >, RHIAccelerationStructure * > > resources
Definition Renderer.hpp:223
Vector< RHIDeviceScopedHandle< RHIDeviceSampler > > samplers
Definition Renderer.hpp:225
ExecuteResources(Allocator *allocator)
Definition Renderer.hpp:226
Vector< TextureViews > views
Definition Renderer.hpp:224
void fit(ResourceHandle handle)
Definition Renderer.hpp:227
Default "no-op" functor for Record()
Definition Renderer.hpp:275
void operator()(PassHandle, Renderer *, RHICommandList *) const
Definition Renderer.hpp:276
Default "no-op" functor for Setup()
Definition Renderer.hpp:268
void operator()(PassHandle, Renderer *) const
Definition Renderer.hpp:269
Functional wrapper for a render pass.
Definition Renderer.hpp:285
LambdaPass(FSetup &&setup, FRecord &&record)
Definition Renderer.hpp:288
void Record(PassHandle self, Renderer *r, RHICommandList *cmd) override
Record the commands of this pass into the given command list.
Definition Renderer.hpp:293
FRecord mRecord
Definition Renderer.hpp:287
void Setup(PassHandle self, Renderer *r) override
Perform any setup required for this pass. This may include creating resources, declaring resource acc...
Definition Renderer.hpp:292
FSetup mSetup
Definition Renderer.hpp:286
Parameters for Renderer creation.
Definition Renderer.hpp:47
bool profilePasses
Enable or disable GPU profiling for the frame graph execution.
Definition Renderer.hpp:82
uint32_t threadCount
Number of worker threads to use for recording command lists.
Definition Renderer.hpp:67
bool asyncCompute
Enable Async Compute support.
Definition Renderer.hpp:62
RHIPipelineStateCache * pipelineCache
Optional PSO cache to potentially speed up pipeline state recompilation in Setup time.
Definition Renderer.hpp:72
PassHandle consumer
Definition Renderer.hpp:1419
StringView resourceName
Definition Renderer.hpp:1421
PassHandle producer
Definition Renderer.hpp:1420
size_t depth
Definition Renderer.hpp:1413
int groupIndex
Definition Renderer.hpp:1415
bool epilogue
Definition Renderer.hpp:1412
size_t ord
Definition Renderer.hpp:1414
StringView name
Definition Renderer.hpp:1408
bool used
Definition Renderer.hpp:1411
RHIDeviceQueueType queue
Definition Renderer.hpp:1410
PassHandle handle
Definition Renderer.hpp:1409
Vector< RHICommandPoolScopedHandle< RHICommandList > > computeCmds
Definition Renderer.hpp:552
RHICommandList * AllocateCompute()
Definition Renderer.cpp:1946
RHIDeviceScopedHandle< RHICommandPool > computePool
Definition Renderer.hpp:551
RHICommandList * AllocateGraphics()
Definition Renderer.cpp:1935
RHIDeviceScopedHandle< RHICommandPool > graphicsPool
Definition Renderer.hpp:551
Vector< RHICommandPoolScopedHandle< RHICommandList > > graphicsCmds
Definition Renderer.hpp:552
ResourceHandle backbuffer
Definition Renderer.hpp:509
RHIDeviceScopedHandle< RHIDeviceQueryPool > dbgQueryPool
Definition Renderer.hpp:511
RHIDeviceScopedHandle< RHIDeviceFence > computeFence
Definition Renderer.hpp:504
RHIDeviceScopedHandle< RHIDeviceFence > graphicsFence
Definition Renderer.hpp:504
FrameSyncObjects(size_t swapIndex, Allocator *alloc)
Definition Renderer.hpp:514
const size_t swapIndex
Definition Renderer.hpp:502
Vector< uint64_t > dbgQueryPassTimestampsResults
Definition Renderer.hpp:512
RHITextureScopedHandle< RHITextureView > view
Definition Renderer.hpp:506
RHIDeviceScopedHandle< RHIDeviceSemaphore > render
Definition Renderer.hpp:503
RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > viewSet
Definition Renderer.hpp:507
String name
Definition Renderer.hpp:1074
size_t bytes
Definition Renderer.hpp:1075
Vector< PassHandle > passes
Definition Renderer.hpp:439
Vector< ResourceHandle > resources
Definition Renderer.hpp:441
ExecutionGroups(int groupIndex, RHIDeviceQueueType queue, Allocator *allocator)
Definition Renderer.hpp:445
const RHIDeviceQueueType queue
Definition Renderer.hpp:438
Helper class containing all states pertaining to Renderer's Setup phase.
Definition Renderer.hpp:409
Vector< ExecutionGroups > executionGroups
Definition Renderer.hpp:450
PassHandle lastBackbufferProducer
Definition Renderer.hpp:421
bool executionAnyCompute
Definition Renderer.hpp:451
int executionNumGraphicsGroups
Definition Renderer.hpp:452
Vector< PassHandle > execution
Definition Renderer.hpp:429
Vector< Vector< Pair< PassHandle, ResourceHandle > > > graph
Definition Renderer.hpp:410
Vector< TrackedPass > trackedPasses
Definition Renderer.hpp:412
Map< ResourceHandle, Pair< PassHandle, PassHandle > > activeResources
Definition Renderer.hpp:426
int executionNumComputeGroups
Definition Renderer.hpp:452
Vector< PassHandle > in
Definition Renderer.hpp:411
Map< uintptr_t, PassHandle > descriptorSetWriters
Definition Renderer.hpp:427
void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
Definition Renderer.hpp:453
PassHandle epilogue
Definition Renderer.hpp:431
Vector< RHIDeviceSampler::SamplerDesc > trackedSamplers
Definition Renderer.hpp:424
Map< RHIDescriptorType, uint32_t > bindingCounts
Definition Renderer.hpp:430
Vector< TrackedResource > trackedResources
Definition Renderer.hpp:413
Vector< Pair< ResourceHandle, RHITextureViewDesc > > trackedViews
Definition Renderer.hpp:423
bool executionAnyGraphics
Definition Renderer.hpp:451
Vector< TemporalResourceFamily > temporalResources
Definition Renderer.hpp:419
RendererSetup(Allocator *allocator)
Definition Renderer.hpp:463
String name
Definition Renderer.hpp:1079
ResourceHandle resourceHandle
Definition Renderer.hpp:1080
RHITextureView * view
Definition Renderer.hpp:1083
RHIResourceFormat format
Definition Renderer.hpp:1082
ResourceHandle viewHandle
Definition Renderer.hpp:1081
Internal tracking information for a render pass in the frame graph.
Definition Renderer.hpp:299
size_t frameExec
Definition Renderer.hpp:320
int priority
Definition Renderer.hpp:302
RHIPipelineState::PipelineStateDesc::DepthStencil psoDepthStencil
Definition Renderer.hpp:371
ResourceHandle dsv
Definition Renderer.hpp:354
Vector< Tuple< String, String, RHIShaderStage, Vector< char >, uint32_t, RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType > > shaders
Definition Renderer.hpp:339
Vector< RHIPipelineState::PipelineStateDesc::VertexInput::Binding > vertexInputBindings
Definition Renderer.hpp:357
Vector< RHIDeviceDescriptorSetLayout * > pDescriptorLayouts
Definition Renderer.hpp:376
RHIPipelineStageBits piplineStages
Definition Renderer.hpp:366
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange, RHITextureLayout > > textureUsages
Definition Renderer.hpp:325
UniquePtr< RenderPass > pass
Definition Renderer.hpp:360
Vector< RHIDeviceDescriptorSet * > pDescriptorSets
Definition Renderer.hpp:379
RHIDeviceQueueType queue
Definition Renderer.hpp:304
RHIPipelineState::PipelineStateDesc::Rasterizer psoRasterizer
Definition Renderer.hpp:370
int groupIndex
Definition Renderer.hpp:364
size_t ord
Definition Renderer.hpp:319
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > textureBindings
Definition Renderer.hpp:341
Vector< Pair< ResourceHandle, String > > samplers
Definition Renderer.hpp:346
RHIDeviceScopedHandle< RHIPipelineState > pso
Definition Renderer.hpp:368
Vector< RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > > descriptorLayouts
Definition Renderer.hpp:374
Vector< RHIDeviceDescriptorSet * > pAlternateDescriptorSets
Definition Renderer.hpp:379
bool unCullable
Definition Renderer.hpp:306
bool isRayTracingPass
Definition Renderer.hpp:315
Vector< RHIPipelineState::PipelineStateDesc::PushConstant > pushConstants
Definition Renderer.hpp:348
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > asUsages
Definition Renderer.hpp:330
Optional< RHIPipelineState::PipelineStateDesc::Attachment::Blending > backbufferRTV
Definition Renderer.hpp:308
bool isDepthReadOnly
Definition Renderer.hpp:355
bool used
Definition Renderer.hpp:305
Vector< RHIVertexAttribute > vertexInputAttributes
Definition Renderer.hpp:358
void ResetPipeline()
Definition Renderer.cpp:60
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > bufferBindings
Definition Renderer.hpp:341
Vector< Tuple< size_t, RHIDeviceDescriptorSetLayout * > > pExternalDescriptorSets
Definition Renderer.hpp:381
Vector< Tuple< RHIShaderStage, size_t, Vector< char > > > specializationConstants
Definition Renderer.hpp:350
Vector< RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > > descriptorSets
Definition Renderer.hpp:378
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > asBindings
Definition Renderer.hpp:341
PassHandle handle
Definition Renderer.hpp:301
Tuple< uint32_t, uint32_t, uint32_t > groupLocalSize
Definition Renderer.hpp:317
Vector< ResourceHandle > texviews
Definition Renderer.hpp:334
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > bufferUsages
Definition Renderer.hpp:327
Optional< int > backbufferUAV
Definition Renderer.hpp:309
size_t depth
Definition Renderer.hpp:318
Vector< PassHandle > bindPasses
Definition Renderer.hpp:322
Vector< Pair< ResourceHandle, RHIPipelineState::PipelineStateDesc::Attachment::Blending > > rtvs
Definition Renderer.hpp:352
bool isComputePass
Definition Renderer.hpp:312
RHIPipelineState::PipelineStateDesc::Topology psoTopology
Definition Renderer.hpp:372
Vector< ResourceHandle > resources
Definition Renderer.hpp:332
String name
Definition Renderer.hpp:300
Vector< Tuple< String, RHIDeviceDescriptorSetLayout *, int > > externalBindings
Definition Renderer.hpp:344
Vector< RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > > alternateDescriptorSets
Definition Renderer.hpp:378
RHIDevicePipelineType GetPipelineType() const
Definition Renderer.hpp:384
RHIPipelineStage stage
Definition Renderer.hpp:138
size_t lastProducedFrame
Definition Renderer.hpp:132
PassHandle lastProducer
Definition Renderer.hpp:130
RHIResourceAccess access
Definition Renderer.hpp:137
bool executeTempTransitionFlag
Definition Renderer.hpp:136
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:134
PassHandle producer
Definition Renderer.hpp:128
RHIResourceAccess access
Definition Renderer.hpp:164
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:161
bool executeTempTransitionFlag
Definition Renderer.hpp:163
RHIPipelineStage stage
Definition Renderer.hpp:165
RHITextureAspectFlagBits aspect
Definition Renderer.hpp:152
RHITextureLayout layout
Definition Renderer.hpp:166
PassHandle producer
Definition Renderer.hpp:155
size_t lastProducedFrame
Definition Renderer.hpp:159
PassHandle lastProducer
Definition Renderer.hpp:157
RHITextureSubresourceRange ToRange() const
Definition Renderer.cpp:8
Internal tracking information for a resource in the frame graph.
Definition Renderer.hpp:111
Vector< SubresourceState > lastSubresourceStates
Definition Renderer.hpp:179
auto GetLastSubresourceStateOf(RHITextureSubresourceRange const &range)
Definition Renderer.hpp:180
bool hasGraphicsUsage
Definition Renderer.hpp:118
uint8_t temporalFramesAgo
Definition Renderer.hpp:116
String name
Definition Renderer.hpp:113
ResourceHandle temporalFamily
Definition Renderer.hpp:115
void ResetStates()
Definition Renderer.hpp:200
ResourceDefinition desc
Definition Renderer.hpp:114
AccelerationStructureState lastASState
Definition Renderer.hpp:199
uint32_t textureMips
Definition Renderer.hpp:148
uint32_t textureLayers
Definition Renderer.hpp:148
bool hasComputeUsage
Definition Renderer.hpp:117
struct Foundation::RenderCore::TrackedResource::BufferState lastBufferState
ResourceHandle handle
Definition Renderer.hpp:112