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 {
128 size_t frame{0};
130 RHIResourceAccess access{};
131 RHIPipelineStage stage{};
133 };
135 {
136 // Last pass to write at Setup time
138 // Last actual writer at Execute time
141 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
143 RHIResourceAccess access{};
144 RHIPipelineStage stage{};
145 void reset()
146 {
148 lastOwnerQueue = RHIDeviceQueueType::Undefined;
150 access = {};
151 stage = {};
152 }
154
155 // (Texture) Per-subresource states
156 uint32_t textureLayers{0}, textureMips{0};
158 {
159 size_t layer{0}, mip{0};
160 RHITextureAspectFlagBits aspect{};
161 /* -- states -- */
162 // Last pass to write at Setup time
164 // Last actual writer at Execute time
167 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
169 RHIResourceAccess access{};
170 RHIPipelineStage stage{};
172 void reset()
173 {
175 lastOwnerQueue = RHIDeviceQueueType::Undefined;
177 access = {};
178 stage = {};
179 layout = {};
180 }
181 [[nodiscard]] RHITextureSubresourceRange ToRange() const;
182 };
183 // [mip...,
184 // layer...,
185 // aspect...]
188 {
189 auto [mip_begin, mip_end] = range.GetMipLevelRange();
190 auto [layer_begin, layer_end] = range.GetArrayLayerRange();
191 CHECK(mip_end < textureMips);
192 CHECK(layer_end < textureLayers);
193 uint32_t mip_stride = textureLayers * kTextureAspectCount;
194 return std::views::all(Span<SubresourceState>(lastSubresourceStates.begin() + mip_begin * mip_stride,
195 lastSubresourceStates.begin() + (mip_end + 1) * mip_stride)) |
196 std::views::filter(
197 [=](const SubresourceState& state)
198 {
199 return (RHITextureAspectFlag(state.aspect) & range.layer.aspect) && state.mip >= mip_begin &&
200 state.mip <= mip_end && state.layer >= layer_begin && state.layer <= layer_end;
201 });
202 }
203
205 // (Acceleration Structure) Last known state
208 {
209 lastBufferState = {};
210 lastASState = {};
211 for (auto& sta : lastSubresourceStates)
212 sta.reset();
213 }
215 Allocator* alloc);
216 };
221 {
224 {
226 bool temporal{false};
227 };
233 explicit ExecuteResources(Allocator* allocator) : resources(allocator), views(allocator), samplers(allocator) {}
234 void fit(ResourceHandle handle)
235 {
236 resources.resize(std::max(resources.size(), static_cast<size_t>(handle + 1)));
237 views.resize(std::max(views.size(), static_cast<size_t>(handle + 1)));
238 samplers.resize(std::max(samplers.size(), static_cast<size_t>(handle + 1)));
239 }
240 };
244 class RenderPass : public RHIObject
245 {
246 public:
251 RenderPass() = default;
259 virtual void Setup(PassHandle self, Renderer* r) = 0;
269 virtual void Record(PassHandle self, Renderer* r, RHICommandList* cmd) = 0;
270 };
275 {
276 void operator()(PassHandle, Renderer*) const { /* nop */ }
277 };
282 {
283 void operator()(PassHandle, Renderer*, RHICommandList*) const { /* nop */ }
284 };
290 template <typename FSetup, typename FRecord>
292 {
293 FSetup mSetup;
294 FRecord mRecord;
295 LambdaPass(FSetup&& setup, FRecord&& record) :
296 mSetup(std::forward<FSetup>(setup)), mRecord(std::forward<FRecord>(record))
297 {
298 }
299 void Setup(PassHandle self, Renderer* r) override { mSetup(self, r); }
300 void Record(PassHandle self, Renderer* r, RHICommandList* cmd) override { mRecord(self, r, cmd); }
301 };
306 {
308 PassHandle handle; // Index to tracked passes
309 int priority{0}; // Higher priority passes are scheduled earlier
310 // The queue to run this pass on
312 bool used{false}; // Culled?
313 bool unCullable{false}; // Acts as an additional execution root
314 // Backbuffer specializations
316 Optional<int> backbufferUAV; // opt: set index
317 // Uses compute shader? (not necessarily in a compute queue)
318 // Should be mutually exclusive with write_backbuffer and other graphics states
319 bool isComputePass{false};
320 // Uses RayGen/RayHit/RayMiss at all?
321 // Should be compatible with most graphics states, and can be run on either queue
322 bool isRayTracingPass{false};
323 // Local size for compute/mesh shaders
325 size_t depth{}; // Depth in RG
326 size_t ord{}; // Execution order
327 size_t frameExec{}; // Last frame this pass is executed
328 /* -- Resources -- */
329 Vector<PassHandle> bindPasses; // Referenced, explicit pass execute-before.
330 Vector<Tuple<ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange,
332 textureUsages; // Referenced texture sub resources
333 Vector<Tuple<ResourceHandle, RHIResourceAccess,
334 RHIPipelineStage>> bufferUsages; // Referenced buffers
335 Vector<Tuple<ResourceHandle, RHIResourceAccess,
336 RHIPipelineStage>>
337 asUsages; // Referenced Acceleration Structures
338 // Unique referenced resources (tex/buf/AS)
340 // Unique texture views
342 /* -- Pipeline -- */
343 // Shader [path, entry point, stage, specialization data, RT hit group, RT hit group type]
347 // Bind points [view(tex) or buffer(buf), desc type, binding point]
349 // External Bind Sets [binding point, layout ptr, set index (set when built)]
350 // Sorted lexicographically if the pipeline is built.
352 // Samplers
354 // Push Constant
356 // Specialization Constants by [stage, offset, value]
358 // (Graphics Only) Render Target View[s], Blending Op
360 // (Graphics Only) Depth Stencil View
362 bool isDepthReadOnly{false};
363 // (Graphics Only) Vertex Input assembly
366 /* --- */
369 UniquePtr<RenderPass> renderPass, size_t priority);
370 /* -- Pipeline states (built at PSO setup) -- */
371 int groupIndex{}; // executionGroup index
372 // All stages used in this pass
373 RHIPipelineStageBits piplineStages{};
374 // Pipeline states for the entire pass
376 // PSO Creation parameters
380 // Layouts created by ourselves
382 // Pointers. Can also contain external sets
384 // Sets created by ourselves, with an alternate mapping for temporal resources
387 // [Set Index, Set, Layout], correspond to externalBindings
389
390
391 RHIDevicePipelineType GetPipelineType() const
392 {
393 if (isComputePass)
394 return RHIDevicePipelineType::Compute;
396 return RHIDevicePipelineType::RayTracing;
397 return RHIDevicePipelineType::Graphics;
398 }
399 void ResetPipeline();
400 };
411 {
416 {
427 // Backbuffer specializations
429 // [resource, view desc]
432 // [resource, ord range]
435 // Passes ordered by pass.ord
439 // Execution grouped by queue type
441 {
442 const int groupIndex{}; // Index in executionGroups
443 int graphicsGroupIndex{-1}; // Index of all unique graphics groups before this one
444 int computeGroupIndex{-1}; // Index of all unique compute groups before this one
447 // Resources used in this group
449 bool isLastGraphics = false;
450 bool isLastCompute = false;
451
453 groupIndex(groupIndex), queue(queue), passes(allocator), resources(allocator)
454 {
455 }
456 };
460 void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
461 {
463 while (u >= graph.size())
464 graph.emplace_back(graph.get_allocator());
465 graph[u].emplace_back(v, hdl);
466 while (v >= in.size())
467 in.push_back(0);
468 in[v]++;
469 }
470 explicit RendererSetup(Allocator* allocator) :
471 graph(allocator), in(allocator), trackedPasses(allocator), trackedResources(allocator),
472 temporalResources(allocator), trackedViews(allocator), trackedSamplers(allocator), activeResources(allocator),
473 descriptorSetWriters(allocator), execution(allocator), bindingCounts(allocator), executionGroups(allocator)
474 {
475 }
476 };
477
478 public:
479 enum class State
480 {
481 Undefined, // Initialized
482 Setup, // During BeginSetup(), EndSetup(). No work on the GPU yet.
483 PostSetup, // Safe state (with a device wait), after EndSetup(), EndExecute()
484 Execute // During BeginExecute(), EndExecute()
485 };
486
487 private:
492
494
495 uint64_t mFrameSwapped{0}; // Frame rendered in the current Swapchain
496
497 uint32_t mFrameSwaps{1}; // Max frames in flight
498 uint32_t mCurrentSync{0};
499 uint32_t mCurrentSwap{0};
501
505 // Per swap primitives
528
530 // Semaphore for async compute
535
537 // Setup
539 RHITextureViewDesc const& desc) const;
540 // PostSetup
541 void CullPasses(PassHandle epilogue) const;
544 void FinalizeResources();
545 void FinalizePasses();
546 // Temporary memory arena for execution
548 // Temporary allocator for execution
549 // This is reset every frame, and only guaranteed to be valid during Execute state.
551 // Temporary storage for submits calls
552 // This is reset every frame, and only guaranteed to be valid during Execute state.
554 // Thread pool for concurrent command list recording
567 // [current sync][thread id]
579 [[nodiscard]] uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
580 {
581 switch (queue)
582 {
583 case RHIDeviceQueueType::Undefined:
585 case RHIDeviceQueueType::Graphics:
587 case RHIDeviceQueueType::Compute:
589 default:
590 CHECK_MSG(false, "Unhandled queue type");
592 }
593 }
598 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
604 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
609 void ExecuteBarrierBuffer(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
610 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
614 void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
615 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
616 [[nodiscard]] ResourceHandle ResolveResourceHandle(ResourceHandle handle, uint64_t frame) const;
620 DerefResourceAtFrame(ResourceHandle handle, uint64_t frame) const;
621 [[nodiscard]] RHITextureView* DerefTextureViewAtFrame(ResourceHandle handle, uint64_t frame) const;
630 void WaitSync();
635 void ResetSync();
639 void AcquireSync();
653 void BeginExecute(uint32_t swapImageIndex, RHIDeviceSemaphore* imageAcquire);
657 void SetFrameSyncObjects();
666 void DeclareBufferAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
667 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead) const;
675 void DeclareTextureAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
677 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead,
678 RHITextureLayout layout = RHITextureLayout::ShaderReadOnly) const;
679 RHIDeviceIdleGuard mWaitIdle; // Ensure device is idle on destruction
680 public:
681 Renderer() = delete;
683 RHIDeviceHandle<RHISwapchain> swapchain, Core::JobSystem* jobs, Allocator* allocator);
684
685#pragma region Render Graph Setup
691 void BeginSetup();
702 template <typename T, typename... Args>
703 requires std::is_base_of_v<RenderPass, T>
704 PassHandle CreatePassImpl(StringView name, RHIDeviceQueueType queue, size_t priority, Args&&... args)
705 {
707 CHECK_MSG(queue == RHIDeviceQueueType::Graphics || queue == RHIDeviceQueueType::Compute,
708 "Invalid queue type. Only Graphics and Compute queues are supported.");
709 PassHandle handle = mSetup->trackedPasses.size();
710 CHECK_MSG(handle < kMaxRenderPasses, "Exceeded maximum number of render passes ({})", kMaxRenderPasses);
711 if (!mDesc.asyncCompute)
712 queue = RHIDeviceQueueType::Graphics; // Force graphics queue if async compute is disabled
713 mSetup->trackedPasses.emplace_back(
714 mAllocator, handle, name, queue,
715 ConstructUniqueBase<RenderPass, T>(mAllocator, std::forward<Args>(args)...), priority);
716 mSetup->epilogue = handle;
717 return handle;
718 }
734 template <typename FSetup, typename FRecord>
735 PassHandle CreatePass(StringView name, RHIDeviceQueueType queue, size_t priority, FSetup&& setup,
736 FRecord&& record)
737 {
738 return CreatePassImpl<LambdaPass<FSetup, FRecord>>(name, queue, priority, std::forward<FSetup>(setup),
739 std::forward<FRecord>(record));
740 }
759 template <typename T>
760 [[nodiscard]] ResourceHandle CreateResource(StringView name, T const& desc)
761 {
762
764
765 ResourceHandle index = mSetup->trackedResources.size();
766 mSetup->trackedResources.emplace_back(index, name, desc, mAllocator);
767 return mSetup->trackedResources.size() - 1;
768 }
775 template <typename T>
777 {
778 static_assert(std::is_same_v<T, RHIBufferDesc> || std::is_same_v<T, RHITextureDesc>,
779 "Temporal resources currently support owned buffers and textures only");
781
782 ResourceHandle current = CreateResource(Format("{} [0]", name), desc);
783 ResourceHandle previous = CreateResource(Format("{} [1]", name), desc);
784 ResourceHandle family = mSetup->temporalResources.size();
785 mSetup->temporalResources.push_back({{current, previous}, mFrameSwapped});
786 mSetup->trackedResources[current].temporalFamily = family;
787 mSetup->trackedResources[current].temporalFramesAgo = 0;
788 mSetup->trackedResources[previous].temporalFamily = family;
789 mSetup->trackedResources[previous].temporalFramesAgo = 1;
790 return TemporalResourceHandle(current, previous);
791 }
800 [[nodiscard]] ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const& desc) const;
801#pragma region Resource Binding
808 void BindPass(PassHandle pass, PassHandle other);
820 void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, StringView shader_path,
821 Span<const char> specializationData = {}, uint32_t rtHitGroupIndex = 0,
823 RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles) const;
832 void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const;
859 void BindBufferUniform(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
860 StringView bind_point) const;
873 void BindBufferStorageRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
874 StringView bind_point) const;
887 void BindBufferUnordered(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
888 StringView bind_point) const;
897 void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const;
904 void BindBufferIndirectRead(PassHandle pass, ResourceHandle buffer) const;
910 void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const;
916 void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const;
925 void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const;
937 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
944 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
959 void MakePassUncullable(PassHandle pass) const;
970 void BindTextureSRV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
971 RHITextureViewDesc const& desc) const;
985 void BindTextureUAV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
986 RHITextureViewDesc const& desc) const;
992 void BindTextureShaderRead(PassHandle pass, ResourceHandle texture, RHIPipelineStage stage,
993 RHITextureSubresourceRange const& range) const;
1004 void BindTextureRTV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
1014 void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
1015 bool readOnly = false) const;
1022 void BindBackbufferRTV(PassHandle pass,
1028 void BindBackbufferUAV(PassHandle pass, int set_index) const;
1035 void BindTextureCopyDst(PassHandle pass, ResourceHandle texture,
1036 RHITextureSubresourceRange const& range = {}) const;
1043 void BindTextureCopySrc(PassHandle pass, ResourceHandle texture,
1044 RHITextureSubresourceRange const& range = {}) const;
1055 void BindAccelerationStructureSRV(PassHandle pass, ResourceHandle as, RHIPipelineStage stage,
1056 StringView bind_point) const;
1057
1058#pragma endregion
1059#pragma region PSO Flags
1068 RHIPipelineState::PipelineStateDesc::DepthStencil const& depth_stencil = {}) const;
1073#pragma endregion
1085 Core::JobBarrier EndSetup(bool wait = true);
1086#pragma endregion
1087#pragma region Diagnostics
1089 {
1091 size_t bytes;
1092 };
1101 void DbgGetMemoryStatistics(Vector<MemoryStat>& outStats) const;
1103#pragma endregion
1104#pragma region Swapchain
1108 [[nodiscard]] RHIDevice* GetDevice() const { return mDevice.Get(); }
1112 [[nodiscard]] const RHIApplication* GetApplication() const { return &mDevice->mApp; }
1117 [[nodiscard]] RHIExtent2D GetSwapchainExtent() const
1118 {
1119 CHECK(mSwapchain && "Swapchain not initialized");
1120 return mSwapchain->mDesc.extents;
1121 }
1126 [[nodiscard]] RHIExtent3D GetSwapchainExtent3D() const
1127 {
1128 CHECK(mSwapchain && "Swapchain not initialized");
1129 auto xy = mSwapchain->mDesc.extents;
1130 return {xy.x, xy.y, 1};
1131 }
1132#pragma endregion
1133#pragma region Render Graph Runtime
1146 DerefResource(const ResourceHandle handle) const
1147 {
1148 return DerefResourceAtFrame(handle, mFrameSwapped);
1149 }
1155 [[nodiscard]] RHITextureView* DerefTextureView(const ResourceHandle handle) const
1156 {
1157 return DerefTextureViewAtFrame(handle, mFrameSwapped);
1158 }
1164 [[nodiscard]] RHIDeviceSampler* DerefSampler(const ResourceHandle handle) const
1165 {
1166 CHECK(mSetup && handle < mSetup->trackedSamplers.size());
1167 return mResources->samplers[handle].Get();
1168 }
1172 [[nodiscard]] RHIPipelineState* DerefPipelineState(const PassHandle pass) const
1173 {
1174 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1175 auto& tpass = mSetup->trackedPasses[pass];
1176 return tpass.pso.Get();
1177 }
1182 {
1183 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1184 auto& tpass = mSetup->trackedPasses[pass];
1185 return tpass.pDescriptorSets;
1186 }
1190 [[nodiscard]] Allocator* GetAllocator() const { return mAllocator; }
1191#pragma endregion
1192#pragma region Command Recording Helpers
1198 [[nodiscard]] RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const;
1214 void CmdDispatch(PassHandle pass, RHICommandList* cmd, RHIExtent3D thread_size) const;
1219 void CmdSetPipeline(PassHandle pass, RHICommandList* cmd) const;
1223 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, uint32_t set_index,
1224 RHIDeviceDescriptorSet* descriptor_set) const;
1231 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, StringView bind_point,
1232 RHIDeviceDescriptorSet* descriptor_set) const;
1242 void CmdBeginGraphics(PassHandle pass, RHICommandList* cmd, RHIExtent2D const& extent,
1244 RHIDepthAttachmentLoad dsv_load = {RHIAttachmentLoadOp::Clear, {0.0f, 0u}});
1251 template <typename T>
1252 void CmdSetPushConstant(PassHandle pass, RHICommandList* cmd, RHIShaderStage stage, size_t offset,
1253 T const& data)
1254 {
1256 auto& tpass = mSetup->trackedPasses[pass];
1257 cmd->PushConstant(tpass.pso.Get(), stage, static_cast<uint32_t>(offset),
1258 {reinterpret_cast<const char*>(&data), sizeof(T)});
1259 }
1260#pragma endregion
1261#pragma region Frame Execution
1265 [[nodiscard]] State GetState() const { return mState; }
1269 [[nodiscard]] uint32_t GetFrameSwaps() const { return mFrameSwaps; }
1276 [[nodiscard]] uint64_t GetFrame() const { return mFrameSwapped; }
1280 [[nodiscard]] bool IsPreviousValid(TemporalResourceHandle resource) const;
1297 [[nodiscard]] uint32_t GetSwap() const { return mCurrentSwap; }
1311 [[nodiscard]] uint64_t GetSync() const { return mCurrentSync; }
1316 {
1317 CHECK_MSG(mSetup && pass < mSetup->trackedPasses.size(), "No passes available or out of bounds");
1318 return mSetup->trackedPasses[pass];
1319 }
1326 [[nodiscard]] bool IsAsyncComputeEnabled() const { return mDesc.asyncCompute; }
1336 [[nodiscard]] bool IsPresentEnabled() const { return mSwapchain.IsValid(); }
1352 RHISwapchain* GetSwapchain() const { return mSwapchain.Get(); }
1353
1358
1379 void WaitForFrame();
1391 void BeginExecute();
1412 void ExecuteFrame();
1419 void EndExecute();
1420#pragma endregion
1421#pragma region Debugging
1423 {
1426 RHIDeviceQueueType queue{RHIDeviceQueueType::Undefined};
1427 bool used{};
1428 bool epilogue{};
1429 size_t depth{};
1430 size_t ord{};
1432 };
1439 void DbgGetGraph(Vector<DebugGraphNode>& outNodes, Vector<DebugGraphEdge>& outEdges) const;
1440 [[nodiscard]] String DbgDumpGraphviz() const;
1441 [[nodiscard]] String DbgDumpActivePasses() const;
1442 [[nodiscard]] String DbgDumpExecutionGroups() const;
1451 Span<const uint64_t> DbgProfilePassTiming(uint64_t sync, float& resolutionNS) const;
1452
1453#pragma endregion
1454 };
1458 ENUM_NAME(PostSetup);
1459 ENUM_NAME(Execute);
1461} // 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:245
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:411
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:735
void DbgGetTexturePreviews(Vector< TexturePreviewStat > &outStats) const
Definition Renderer.cpp:1540
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefResource(const ResourceHandle handle) const
Dereference a resource handle to its underlying RHI resource.
Definition Renderer.hpp:1146
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:460
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:577
Atomic< bool > mPipelineStateCompilationComplete
Definition Renderer.hpp:491
UniquePtr< ExecuteResources > mResources
Definition Renderer.hpp:502
RHIDeviceSemaphore * mExecuteImageAcquire
Definition Renderer.hpp:500
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:450
void BeginSetup()
Begins the setup phase of the render graph.
Definition Renderer.cpp:126
void DbgGetMemoryStatistics(Vector< MemoryStat > &outStats) const
Definition Renderer.cpp:1501
RHICommandList * ExecuteAllocateCommandList(RHIDeviceQueueType queue, int thread_id=-1)
Definition Renderer.cpp:2036
RHIDeviceHandle< RHISwapchain > mSwapchain
Definition Renderer.hpp:533
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:351
Vector< Pair< RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc > > * mExecuteSubmits
Definition Renderer.hpp:553
void WaitForFrame()
Blocks until the most recently submitted frame has finished executing on the GPU.
Definition Renderer.cpp:1688
State mState
Definition Renderer.hpp:488
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:2456
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:1917
Core::JobBarrier BuildPipelineStateAll()
Definition Renderer.cpp:1353
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:423
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
Definition Renderer.hpp:568
RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > mSwapDescriptorSetLayout
Definition Renderer.hpp:527
RHIDeviceSampler * DerefSampler(const ResourceHandle handle) const
Dereference a sampler handle to its underlying RHI sampler.
Definition Renderer.hpp:1164
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:2053
void ExecuteBarrierSubresourceState(PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const
Definition Renderer.cpp:1811
RHIDeviceQueue * mGraphicsQueue
Definition Renderer.hpp:534
Vector< RHIDeviceDescriptorSet * > const & DerefDescriptorSets(const PassHandle pass) const
Dereference the built descriptor sets associated with a given pass.
Definition Renderer.hpp:1181
uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
Helper to get the queue index of a queue type.
Definition Renderer.hpp:579
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:375
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:1859
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:382
Vector< Pair< Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * >, RHICommandList::TransitionDesc > > ExecuteBarrierList
Definition Renderer.hpp:595
const RHIApplication * GetApplication() const
Get the RHIApplication this Renderer was constructed with.
Definition Renderer.hpp:1112
ScopedArena mExecuteArena
Definition Renderer.hpp:547
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:2542
Mutex mDescPoolMutex
Definition Renderer.hpp:504
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Definition Renderer.cpp:502
void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const
Associates Vertex Input description with this pass.
Definition Renderer.cpp:304
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:2440
uint32_t mFrameSwaps
Definition Renderer.hpp:497
void InvalidateTemporalResource(TemporalResourceHandle resource)
Invalidates Previous() until the current frame has produced a replacement.
Definition Renderer.cpp:1661
void FinalizePasses()
Definition Renderer.cpp:1380
void BuildPipelineState(PassHandle pass)
Definition Renderer.cpp:853
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:333
RHIDeviceScopedHandle< RHIDeviceSemaphore > mGraphicsTimeline
Definition Renderer.hpp:531
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:1592
String DbgDumpActivePasses() const
Definition Renderer.cpp:2631
RHIPipelineState * DerefPipelineState(const PassHandle pass) const
Dereference the automatically built pipeline state object handle associated with a given pass.
Definition Renderer.hpp:1172
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:704
uint32_t GetFrameSwaps() const
Get the number of frames that can be simultaneously in-flight.
Definition Renderer.hpp:1269
AllocatorStack mExecuteAlloc
Definition Renderer.hpp:550
Vector< FrameSyncObjects > mSwaps
Definition Renderer.hpp:529
String DbgDumpExecutionGroups() const
Definition Renderer.cpp:2644
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:563
uint64_t mFrameSwapped
Definition Renderer.hpp:495
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:2479
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mDescPool
Definition Renderer.hpp:503
ThreadPool mExecuteThreadPool
Definition Renderer.hpp:555
RHITextureView * DerefTextureViewAtFrame(ResourceHandle handle, uint64_t frame) const
Definition Renderer.cpp:188
void AcquireSync()
Waits then resets the current sync slot. Headless BeginExecute path.
Definition Renderer.cpp:1739
void SetFrameSyncObjects()
Sets backbuffer views and sync primitives.
Definition Renderer.cpp:1566
RHISwapchain * GetSwapchain() const
Returns the currently used RHISwapchain object.
Definition Renderer.hpp:1352
void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will read from the buffer via copy.
Definition Renderer.cpp:369
Core::JobBarrier EndSetup(bool wait=true)
Finish setting up the render graph.
Definition Renderer.cpp:594
uint32_t mCurrentSwap
Definition Renderer.hpp:499
RHIDevice * GetDevice() const
Get the RHIDevice this Renderer was constructed with.
Definition Renderer.hpp:1108
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:436
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:1126
UniquePtr< RendererSetup > mSetup
Definition Renderer.hpp:536
void ResetSync()
Resets the GPU fences of the current sync slot after WaitSync. Internal. Called once the frame is com...
Definition Renderer.cpp:1727
void CullPasses(PassHandle epilogue) const
Definition Renderer.cpp:619
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:480
Allocator * GetAllocator() const
Definition Renderer.hpp:1190
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:530
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:1117
RHIDeviceHandle< RHIDeviceSemaphore > GetRenderCompleteSemaphore() const
Binary semaphore signaled when GPU work for the current swap image is complete.
Definition Renderer.cpp:1645
RHIApplicationHandle< RHIDevice > mDevice
Definition Renderer.hpp:532
RendererDesc mDesc
Definition Renderer.hpp:493
Allocator * mAllocator
Definition Renderer.hpp:489
void WaitSync()
Waits for the GPU fences of the sync slot about to be reused. Internal. Called by BeginExecute.
Definition Renderer.cpp:1714
void ExecuteBarriers(TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes all barriers for a pass.
Definition Renderer.cpp:1947
void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will write to the buffer via copy.
Definition Renderer.cpp:363
void BeginExecute()
Begins execution for a headless (no swapchain) frame.
Definition Renderer.cpp:1792
TrackedPass const & GetTrackedPass(PassHandle pass)
Retrieves an internal tracked pass associated with the given handle, read-only.
Definition Renderer.hpp:1315
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:357
void EndExecute()
Ends the execution phase and performs GPU submission.
Definition Renderer.cpp:2398
void FinalizeResources()
Definition Renderer.cpp:1401
uint32_t mCurrentSync
Definition Renderer.hpp:498
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:313
void ExecuteBarrierBuffer(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a whole buffer.
Definition Renderer.cpp:1875
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:2659
String DbgDumpGraphviz() const
Definition Renderer.cpp:2583
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:540
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:342
void PassSetTopology(PassHandle pass, RHIPipelineState::PipelineStateDesc::Topology topology) const
Sets the input assembly topology for a graphics pass (TriangleList, LineList, etc....
Definition Renderer.cpp:587
RHIDeviceQueue * mComputeQueue
Definition Renderer.hpp:534
void BindAccelerationStructureWrite(PassHandle pass, ResourceHandle as) const
Declares that this pass will build, or update the AS.
Definition Renderer.cpp:550
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:293
Core::JobSystem * mJobs
Definition Renderer.hpp:490
RHIDeviceScopedHandle< RHIDeviceSemaphore > mComputeTimeline
Definition Renderer.hpp:531
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:1252
void BindDescriptorSetRead(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout)
Binds an externally managed descriptor set that this pass reads.
Definition Renderer.cpp:409
bool IsAsyncComputeEnabled() const
Returns whether async compute is enabled.
Definition Renderer.hpp:1326
RHIDeviceIdleGuard mWaitIdle
Definition Renderer.hpp:679
uint64_t GetSync() const
Retrieves the current synchronization index.
Definition Renderer.hpp:1311
State
Definition Renderer.hpp:480
bool IsPresentEnabled() const
Returns whether a swapchain is bound.
Definition Renderer.hpp:1336
TemporalResourceHandle CreateTemporalResource(StringView name, T const &desc)
Creates a double-buffered resource with frame-relative handles.
Definition Renderer.hpp:776
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:2533
uint32_t GetSwap() const
Retrieves the current swap index at the time of ExecuteFrame().
Definition Renderer.hpp:1297
uint64_t GetFrame() const
Retrieves the current frame number.
Definition Renderer.hpp:1276
bool IsPreviousValid(TemporalResourceHandle resource) const
Returns whether Previous() contains a frame produced since the last invalidation.
Definition Renderer.cpp:1653
State GetState() const
Retrieves the current state of the renderer.
Definition Renderer.hpp:1265
void DbgGetGraph(Vector< DebugGraphNode > &outNodes, Vector< DebugGraphEdge > &outEdges) const
Definition Renderer.cpp:2551
RHITextureView * DerefTextureView(const ResourceHandle handle) const
Dereference a texture view handle to its underlying RHI texture view.
Definition Renderer.hpp:1155
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:324
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:760
void BindBackbufferUAV(PassHandle pass, int set_index) const
Binds the backbuffer as RW access at binding 0 of set index.
Definition Renderer.cpp:516
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mSwapDescriptorPool
Definition Renderer.hpp:526
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:225
Helper class containing runtime resources either imported, or created by the Renderer.
Definition Renderer.hpp:221
Vector< Variant< RHIBuffer *, RHIDeviceScopedHandle< RHIBuffer >, RHITexture *, RHIDeviceScopedHandle< RHITexture >, RHIAccelerationStructure * > > resources
Definition Renderer.hpp:230
Vector< RHIDeviceScopedHandle< RHIDeviceSampler > > samplers
Definition Renderer.hpp:232
ExecuteResources(Allocator *allocator)
Definition Renderer.hpp:233
Vector< TextureViews > views
Definition Renderer.hpp:231
void fit(ResourceHandle handle)
Definition Renderer.hpp:234
Default "no-op" functor for Record()
Definition Renderer.hpp:282
void operator()(PassHandle, Renderer *, RHICommandList *) const
Definition Renderer.hpp:283
Default "no-op" functor for Setup()
Definition Renderer.hpp:275
void operator()(PassHandle, Renderer *) const
Definition Renderer.hpp:276
Functional wrapper for a render pass.
Definition Renderer.hpp:292
LambdaPass(FSetup &&setup, FRecord &&record)
Definition Renderer.hpp:295
void Record(PassHandle self, Renderer *r, RHICommandList *cmd) override
Record the commands of this pass into the given command list.
Definition Renderer.hpp:300
FRecord mRecord
Definition Renderer.hpp:294
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:299
FSetup mSetup
Definition Renderer.hpp:293
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:1435
StringView resourceName
Definition Renderer.hpp:1437
PassHandle producer
Definition Renderer.hpp:1436
size_t depth
Definition Renderer.hpp:1429
int groupIndex
Definition Renderer.hpp:1431
bool epilogue
Definition Renderer.hpp:1428
size_t ord
Definition Renderer.hpp:1430
StringView name
Definition Renderer.hpp:1424
bool used
Definition Renderer.hpp:1427
RHIDeviceQueueType queue
Definition Renderer.hpp:1426
PassHandle handle
Definition Renderer.hpp:1425
Vector< RHICommandPoolScopedHandle< RHICommandList > > computeCmds
Definition Renderer.hpp:559
RHICommandList * AllocateCompute()
Definition Renderer.cpp:2025
RHIDeviceScopedHandle< RHICommandPool > computePool
Definition Renderer.hpp:558
RHICommandList * AllocateGraphics()
Definition Renderer.cpp:2014
RHIDeviceScopedHandle< RHICommandPool > graphicsPool
Definition Renderer.hpp:558
Vector< RHICommandPoolScopedHandle< RHICommandList > > graphicsCmds
Definition Renderer.hpp:559
ResourceHandle backbuffer
Definition Renderer.hpp:516
RHIDeviceScopedHandle< RHIDeviceQueryPool > dbgQueryPool
Definition Renderer.hpp:518
RHIDeviceScopedHandle< RHIDeviceFence > computeFence
Definition Renderer.hpp:511
RHIDeviceScopedHandle< RHIDeviceFence > graphicsFence
Definition Renderer.hpp:511
FrameSyncObjects(size_t swapIndex, Allocator *alloc)
Definition Renderer.hpp:521
const size_t swapIndex
Definition Renderer.hpp:509
Vector< uint64_t > dbgQueryPassTimestampsResults
Definition Renderer.hpp:519
RHITextureScopedHandle< RHITextureView > view
Definition Renderer.hpp:513
RHIDeviceScopedHandle< RHIDeviceSemaphore > render
Definition Renderer.hpp:510
RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > viewSet
Definition Renderer.hpp:514
String name
Definition Renderer.hpp:1090
size_t bytes
Definition Renderer.hpp:1091
Vector< PassHandle > passes
Definition Renderer.hpp:446
Vector< ResourceHandle > resources
Definition Renderer.hpp:448
ExecutionGroups(int groupIndex, RHIDeviceQueueType queue, Allocator *allocator)
Definition Renderer.hpp:452
const RHIDeviceQueueType queue
Definition Renderer.hpp:445
Helper class containing all states pertaining to Renderer's Setup phase.
Definition Renderer.hpp:416
Vector< ExecutionGroups > executionGroups
Definition Renderer.hpp:457
PassHandle lastBackbufferProducer
Definition Renderer.hpp:428
bool executionAnyCompute
Definition Renderer.hpp:458
int executionNumGraphicsGroups
Definition Renderer.hpp:459
Vector< PassHandle > execution
Definition Renderer.hpp:436
Vector< Vector< Pair< PassHandle, ResourceHandle > > > graph
Definition Renderer.hpp:417
Vector< TrackedPass > trackedPasses
Definition Renderer.hpp:419
Map< ResourceHandle, Pair< PassHandle, PassHandle > > activeResources
Definition Renderer.hpp:433
int executionNumComputeGroups
Definition Renderer.hpp:459
Vector< PassHandle > in
Definition Renderer.hpp:418
Map< uintptr_t, PassHandle > descriptorSetWriters
Definition Renderer.hpp:434
void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
Definition Renderer.hpp:460
PassHandle epilogue
Definition Renderer.hpp:438
Vector< RHIDeviceSampler::SamplerDesc > trackedSamplers
Definition Renderer.hpp:431
Map< RHIDescriptorType, uint32_t > bindingCounts
Definition Renderer.hpp:437
Vector< TrackedResource > trackedResources
Definition Renderer.hpp:420
Vector< Pair< ResourceHandle, RHITextureViewDesc > > trackedViews
Definition Renderer.hpp:430
bool executionAnyGraphics
Definition Renderer.hpp:458
Vector< TemporalResourceFamily > temporalResources
Definition Renderer.hpp:426
RendererSetup(Allocator *allocator)
Definition Renderer.hpp:470
String name
Definition Renderer.hpp:1095
ResourceHandle resourceHandle
Definition Renderer.hpp:1096
RHITextureView * view
Definition Renderer.hpp:1099
RHIResourceFormat format
Definition Renderer.hpp:1098
ResourceHandle viewHandle
Definition Renderer.hpp:1097
Internal tracking information for a render pass in the frame graph.
Definition Renderer.hpp:306
size_t frameExec
Definition Renderer.hpp:327
int priority
Definition Renderer.hpp:309
RHIPipelineState::PipelineStateDesc::DepthStencil psoDepthStencil
Definition Renderer.hpp:378
ResourceHandle dsv
Definition Renderer.hpp:361
Vector< Tuple< String, String, RHIShaderStage, Vector< char >, uint32_t, RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType > > shaders
Definition Renderer.hpp:346
Vector< RHIPipelineState::PipelineStateDesc::VertexInput::Binding > vertexInputBindings
Definition Renderer.hpp:364
Vector< RHIDeviceDescriptorSetLayout * > pDescriptorLayouts
Definition Renderer.hpp:383
RHIPipelineStageBits piplineStages
Definition Renderer.hpp:373
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange, RHITextureLayout > > textureUsages
Definition Renderer.hpp:332
UniquePtr< RenderPass > pass
Definition Renderer.hpp:367
Vector< RHIDeviceDescriptorSet * > pDescriptorSets
Definition Renderer.hpp:386
RHIDeviceQueueType queue
Definition Renderer.hpp:311
RHIPipelineState::PipelineStateDesc::Rasterizer psoRasterizer
Definition Renderer.hpp:377
int groupIndex
Definition Renderer.hpp:371
size_t ord
Definition Renderer.hpp:326
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > textureBindings
Definition Renderer.hpp:348
Vector< Pair< ResourceHandle, String > > samplers
Definition Renderer.hpp:353
RHIDeviceScopedHandle< RHIPipelineState > pso
Definition Renderer.hpp:375
Vector< RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > > descriptorLayouts
Definition Renderer.hpp:381
Vector< RHIDeviceDescriptorSet * > pAlternateDescriptorSets
Definition Renderer.hpp:386
bool unCullable
Definition Renderer.hpp:313
bool isRayTracingPass
Definition Renderer.hpp:322
Vector< RHIPipelineState::PipelineStateDesc::PushConstant > pushConstants
Definition Renderer.hpp:355
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > asUsages
Definition Renderer.hpp:337
Optional< RHIPipelineState::PipelineStateDesc::Attachment::Blending > backbufferRTV
Definition Renderer.hpp:315
bool isDepthReadOnly
Definition Renderer.hpp:362
bool used
Definition Renderer.hpp:312
Vector< RHIVertexAttribute > vertexInputAttributes
Definition Renderer.hpp:365
void ResetPipeline()
Definition Renderer.cpp:60
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > bufferBindings
Definition Renderer.hpp:348
Vector< Tuple< size_t, RHIDeviceDescriptorSetLayout * > > pExternalDescriptorSets
Definition Renderer.hpp:388
Vector< Tuple< RHIShaderStage, size_t, Vector< char > > > specializationConstants
Definition Renderer.hpp:357
Vector< RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > > descriptorSets
Definition Renderer.hpp:385
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > asBindings
Definition Renderer.hpp:348
PassHandle handle
Definition Renderer.hpp:308
Tuple< uint32_t, uint32_t, uint32_t > groupLocalSize
Definition Renderer.hpp:324
Vector< ResourceHandle > texviews
Definition Renderer.hpp:341
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > bufferUsages
Definition Renderer.hpp:334
Optional< int > backbufferUAV
Definition Renderer.hpp:316
size_t depth
Definition Renderer.hpp:325
Vector< PassHandle > bindPasses
Definition Renderer.hpp:329
Vector< Pair< ResourceHandle, RHIPipelineState::PipelineStateDesc::Attachment::Blending > > rtvs
Definition Renderer.hpp:359
bool isComputePass
Definition Renderer.hpp:319
RHIPipelineState::PipelineStateDesc::Topology psoTopology
Definition Renderer.hpp:379
Vector< ResourceHandle > resources
Definition Renderer.hpp:339
String name
Definition Renderer.hpp:307
Vector< Tuple< String, RHIDeviceDescriptorSetLayout *, int > > externalBindings
Definition Renderer.hpp:351
Vector< RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > > alternateDescriptorSets
Definition Renderer.hpp:385
RHIDevicePipelineType GetPipelineType() const
Definition Renderer.hpp:391
RHIPipelineStage stage
Definition Renderer.hpp:144
size_t lastProducedFrame
Definition Renderer.hpp:140
PreparedTransition preparedTransition
Definition Renderer.hpp:142
PassHandle lastProducer
Definition Renderer.hpp:139
RHIResourceAccess access
Definition Renderer.hpp:143
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:141
PassHandle producer
Definition Renderer.hpp:137
RHIResourceAccess access
Definition Renderer.hpp:130
PassHandle consumer
Definition Renderer.hpp:127
RHITextureLayout layout
Definition Renderer.hpp:132
RHIPipelineStage stage
Definition Renderer.hpp:131
PreparedTransition preparedTransition
Definition Renderer.hpp:168
RHIResourceAccess access
Definition Renderer.hpp:169
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:167
RHIPipelineStage stage
Definition Renderer.hpp:170
RHITextureAspectFlagBits aspect
Definition Renderer.hpp:160
RHITextureLayout layout
Definition Renderer.hpp:171
PassHandle producer
Definition Renderer.hpp:163
size_t lastProducedFrame
Definition Renderer.hpp:166
PassHandle lastProducer
Definition Renderer.hpp:165
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:186
auto GetLastSubresourceStateOf(RHITextureSubresourceRange const &range)
Definition Renderer.hpp:187
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:207
ResourceDefinition desc
Definition Renderer.hpp:114
AccelerationStructureState lastASState
Definition Renderer.hpp:206
uint32_t textureMips
Definition Renderer.hpp:156
uint32_t textureLayers
Definition Renderer.hpp:156
bool hasComputeUsage
Definition Renderer.hpp:117
struct Foundation::RenderCore::TrackedResource::BufferState lastBufferState
ResourceHandle handle
Definition Renderer.hpp:112