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
27 {
42 bool asyncCompute{true};
47 uint32_t threadCount{4u};
62 bool profilePasses{true};
63 };
64 /* -- Constants -- */
65 // Maximum number of render passes per frame
66 // NOTE: The limit here is mostly arbitrary - and is only used
67 // for the default priority heuristic when determining pass order.
68 constexpr size_t kMaxRenderPasses = 1024;
69 // Maximum number of command lists per frame
71 // Maximum size of the per-frame transient arena (16MB)
72 constexpr size_t kExecuteArenaSize = 16 * (1 << 20);
73 const RHIPipelineStage kComputeStagesMask = RHIPipelineStageBits::FragmentShader |
74 RHIPipelineStageBits::VertexShader | RHIPipelineStageBits::MeshShader | RHIPipelineStageBits::RayTracingShader |
75 RHIPipelineStageBits::AllGraphics;
76 const RHIResourceAccessBits kAllShaderWrites = RHIResourceAccessBits::ShaderWrite |
77 RHIResourceAccessBits::RenderTargetWrite | RHIResourceAccessBits::DepthStencilWrite |
78 RHIResourceAccessBits::TransferWrite | RHIResourceAccessBits::HostWrite;
79 const RHIResourceAccessBits kAllShaderReads = RHIResourceAccessBits::ShaderRead |
80 RHIResourceAccessBits::RenderTargetRead | RHIResourceAccessBits::DepthStencilRead |
81 RHIResourceAccessBits::UniformRead | RHIResourceAccessBits::TransferRead | RHIResourceAccessBits::HostRead;
84 RHITextureDesc, /* RHIAccelerationStructureDesc - not yet. Do we want to do this in RG at all? */
86 const size_t kTextureAspectCount = 3; // Color, depth, stencil @ref RHITextureAspectFlag
91 {
92 ResourceHandle handle; // Index to tracked resources
95 bool hasComputeUsage{false}; // Used in a compute pass?
96 bool hasGraphicsUsage{false}; // Used in a graphics pass?
97 /* --- states --- */
98 // (Buffer) Last known state
99 // Transitions here are always global since granularity would be too fine. And seems
100 // like drivers don't really care?
101 // See Also: https://www.reddit.com/r/vulkan/comments/v2mswb/global_memory_barriers_vs_bufferimage_memory/
102 // TODO: Investigate
104 {
105 // Last pass to write at Setup time
107 // Last pass to transition at Execute time
109 // Last frame the transition was executed
111 // Last queue this resource is owned by
112 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
113 // [Only used by @ref ExecuteReleaseQueueResources]
115 RHIResourceAccess access{};
116 RHIPipelineStage stage{};
117 void reset()
118 {
120 access = {};
121 stage = {};
122 }
124
125 // (Texture) Per-subresource states
126 uint32_t textureLayers{0}, textureMips{0};
128 {
129 size_t layer{0}, mip{0};
130 RHITextureAspectFlagBits aspect{};
131 /* -- states -- */
132 // Last pass to write at Setup time
134 // Last pass to transition at Execute time
136 // Last frame the transition was executed
138 // Last queue this resource is owned by
139 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
140 // [Only used by @ref ExecuteReleaseQueueResources]
142 RHIResourceAccess access{};
143 RHIPipelineStage stage{};
145 void reset()
146 {
148 access = {};
149 stage = {};
150 layout = {};
151 }
152 [[nodiscard]] RHITextureSubresourceRange ToRange() const;
153 };
154 // [mip...,
155 // layer...,
156 // aspect...]
159 {
160 auto [mip_begin, mip_end] = range.GetMipLevelRange();
161 auto [layer_begin, layer_end] = range.GetArrayLayerRange();
162 CHECK(mip_end < textureMips);
163 CHECK(layer_end < textureLayers);
164 uint32_t mip_stride = textureLayers * kTextureAspectCount;
165 return std::views::all(Span<SubresourceState>(lastSubresourceStates.begin() + mip_begin * mip_stride,
166 lastSubresourceStates.begin() + (mip_end + 1) * mip_stride)) |
167 std::views::filter(
168 [=](const SubresourceState& state)
169 {
170 return (RHITextureAspectFlag(state.aspect) & range.layer.aspect) && state.mip >= mip_begin &&
171 state.mip <= mip_end && state.layer >= layer_begin && state.layer <= layer_end;
172 });
173 }
174
176 // (Acceleration Structure) Last known state
179 {
180 lastBufferState = {};
181 lastASState = {};
182 for (auto& sta : lastSubresourceStates)
183 sta.reset();
184 }
186 Allocator* alloc);
187 };
192 {
198 explicit ExecuteResources(Allocator* allocator) : resources(allocator), views(allocator), samplers(allocator) {}
199 void fit(ResourceHandle handle)
200 {
201 resources.resize(std::max(resources.size(), static_cast<size_t>(handle + 1)));
202 views.resize(std::max(views.size(), static_cast<size_t>(handle + 1)));
203 samplers.resize(std::max(samplers.size(), static_cast<size_t>(handle + 1)));
204 }
205 };
209 class RenderPass : public RHIObject
210 {
211 public:
216 RenderPass() = default;
224 virtual void Setup(PassHandle self, Renderer* r) = 0;
234 virtual void Record(PassHandle self, Renderer* r, RHICommandList* cmd) = 0;
235 };
240 {
241 void operator()(PassHandle, Renderer*) const { /* nop */ }
242 };
247 {
248 void operator()(PassHandle, Renderer*, RHICommandList*) const { /* nop */ }
249 };
255 template <typename FSetup, typename FRecord>
257 {
258 FSetup mSetup;
259 FRecord mRecord;
260 LambdaPass(FSetup&& setup, FRecord&& record) :
261 mSetup(std::forward<FSetup>(setup)), mRecord(std::forward<FRecord>(record))
262 {
263 }
264 void Setup(PassHandle self, Renderer* r) override { mSetup(self, r); }
265 void Record(PassHandle self, Renderer* r, RHICommandList* cmd) override { mRecord(self, r, cmd); }
266 };
271 {
273 PassHandle handle; // Index to tracked passes
274 int priority{0}; // Higher priority passes are scheduled earlier
275 // The queue to run this pass on
277 bool used{false}; // Culled?
278 bool unCullable{false}; // Acts as an additional execution root
279 // Backbuffer specializations
281 Optional<int> backbufferUAV; // opt: set index
282 // Uses compute shader? (not necessarily in a compute queue)
283 // Should be mutually exclusive with write_backbuffer and other graphics states
284 bool isComputePass{false};
285 // Uses RayGen/RayHit/RayMiss at all?
286 // Should be compatible with most graphics states, and can be run on either queue
287 bool isRayTracingPass{false};
288 // Local size for compute/mesh shaders
290 size_t depth{}; // Depth in RG
291 size_t ord{}; // Execution order
292 size_t frameExec{}; // Last frame this pass is executed
293 /* -- Resources -- */
294 Vector<PassHandle> bindPasses; // Referenced, explicit pass execute-before.
295 Vector<Tuple<ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange,
297 textureUsages; // Referenced texture sub resources
298 Vector<Tuple<ResourceHandle, RHIResourceAccess,
299 RHIPipelineStage>> bufferUsages; // Referenced buffers
300 Vector<Tuple<ResourceHandle, RHIResourceAccess,
301 RHIPipelineStage>>
302 asUsages; // Referenced Acceleration Structures
303 // Unique referenced resources (tex/buf/AS)
305 // Unique texture views
307 /* -- Pipeline -- */
308 // Shader [path, entry point, stage, specialization data, RT hit group, RT hit group type]
312 // Bind points [view(tex) or buffer(buf), desc type, binding point]
314 // External Bind Sets [binding point, layout ptr, set index (set when built)]
315 // Sorted lexicographically if the pipeline is built.
317 // Samplers
319 // Push Constant
321 // Specialization Constants by [stage, offset, value]
323 // (Graphics Only) Render Target View[s], Blending Op
325 // (Graphics Only) Depth Stencil View
327 bool isDepthReadOnly{false};
328 // (Graphics Only) Vertex Input assembly
331 /* --- */
334 UniquePtr<RenderPass> renderPass, size_t priority);
335 /* -- Pipeline states (built at PSO setup) -- */
336 int groupIndex{}; // executionGroup index
337 // All stages used in this pass
338 RHIPipelineStageBits piplineStages{};
339 // Pipeline states for the entire pass
341 // PSO Creation parameters
345 // Layouts created by ourselves
347 // Pointers. Can also contain external sets
349 // Sets created by ourselves
351 // Pointers. Can also contain external sets
353 // [Set Index, Set, Layout], correspond to externalBindings
355
356
357 RHIDevicePipelineType GetPipelineType() const
358 {
359 if (isComputePass)
360 return RHIDevicePipelineType::Compute;
362 return RHIDevicePipelineType::RayTracing;
363 return RHIDevicePipelineType::Graphics;
364 }
365 void ResetPipeline();
366 };
377 {
382 {
387 // Backbuffer specializations
389 // [resource, view desc]
392 // [resource, ord range]
395 // Passes ordered by pass.ord
399 // Execution grouped by queue type
401 {
402 const int groupIndex{}; // Index in executionGroups
403 int graphicsGroupIndex{-1}; // Index of all unique graphics groups before this one
404 int computeGroupIndex{-1}; // Index of all unique compute groups before this one
407 // Resources used in this group
409 bool isLastGraphics = false;
410 bool isLastCompute = false;
411
413 groupIndex(groupIndex), queue(queue), passes(allocator), resources(allocator)
414 {
415 }
416 };
420 void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
421 {
423 while (u >= graph.size())
424 graph.emplace_back(graph.get_allocator());
425 graph[u].emplace_back(v, hdl);
426 while (v >= in.size())
427 in.push_back(0);
428 in[v]++;
429 }
430 explicit RendererSetup(Allocator* allocator) :
431 graph(allocator), in(allocator), trackedPasses(allocator), trackedResources(allocator),
432 trackedViews(allocator), trackedSamplers(allocator), activeResources(allocator),
433 descriptorSetWriters(allocator), execution(allocator), bindingCounts(allocator), executionGroups(allocator)
434 {
435 }
436 };
437
438 public:
439 enum class State
440 {
441 Undefined, // Initialized
442 Setup, // During BeginSetup(), EndSetup(). No work on the GPU yet.
443 PostSetup, // Safe state (with a device wait), after EndSetup(), EndExecute()
444 Execute // During BeginExecute(), EndExecute()
445 };
446
447 private:
452
454
455 uint64_t mFrameSwapped{0}; // Frame rendered in the current Swapchain
456
457 uint32_t mFrameSwaps{1}; // Max frames in flight
458 uint32_t mCurrentSync{0};
459 uint32_t mCurrentSwap{0};
461
465 // Per swap primitives
488
490 // Semaphore for async compute
495
497 // Setup
499 RHITextureViewDesc const& desc) const;
500 // PostSetup
501 void CullPasses(PassHandle epilogue) const;
504 void FinalizeResources();
505 void FinalizePasses();
506 // Temporary memory arena for execution
508 // Temporary allocator for execution
509 // This is reset every frame, and only guaranteed to be valid during Execute state.
511 // Temporary storage for submits calls
512 // This is reset every frame, and only guaranteed to be valid during Execute state.
514 // Thread pool for concurrent command list recording
527 // [current sync][thread id]
539 [[nodiscard]] uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
540 {
541 switch (queue)
542 {
543 case RHIDeviceQueueType::Undefined:
545 case RHIDeviceQueueType::Graphics:
547 case RHIDeviceQueueType::Compute:
549 default:
550 CHECK_MSG(false, "Unhandled queue type");
552 }
553 }
558 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
564 RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout,
569 void ExecuteBarrierBuffer(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
570 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
574 void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource& res, RHIResourceAccess access,
575 RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd);
584 void AcquireSync();
598 void BeginExecute(uint32_t swapImageIndex, RHIDeviceSemaphore* imageAcquire);
602 void SetFrameSyncObjects();
611 void DeclareBufferAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
612 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead) const;
620 void DeclareTextureAccess(PassHandle pass, ResourceHandle handle, RHIPipelineStage stage,
622 RHIResourceAccess access = RHIResourceAccessBits::ShaderRead,
623 RHITextureLayout layout = RHITextureLayout::ShaderReadOnly) const;
624 RHIDeviceIdleGuard mWaitIdle; // Ensure device is idle on destruction
625 public:
626 Renderer() = delete;
628 RHIDeviceHandle<RHISwapchain> swapchain, Core::JobSystem* jobs, Allocator* allocator);
629
630#pragma region Render Graph Setup
636 void BeginSetup();
647 template <typename T, typename... Args>
648 requires std::is_base_of_v<RenderPass, T>
649 PassHandle CreatePassImpl(StringView name, RHIDeviceQueueType queue, size_t priority, Args&&... args)
650 {
652 CHECK_MSG(queue == RHIDeviceQueueType::Graphics || queue == RHIDeviceQueueType::Compute,
653 "Invalid queue type. Only Graphics and Compute queues are supported.");
654 PassHandle handle = mSetup->trackedPasses.size();
655 CHECK_MSG(handle < kMaxRenderPasses, "Exceeded maximum number of render passes ({})", kMaxRenderPasses);
656 if (!mDesc.asyncCompute)
657 queue = RHIDeviceQueueType::Graphics; // Force graphics queue if async compute is disabled
658 mSetup->trackedPasses.emplace_back(
659 mAllocator, handle, name, queue,
660 ConstructUniqueBase<RenderPass, T>(mAllocator, std::forward<Args>(args)...), priority);
661 mSetup->epilogue = handle;
662 return handle;
663 }
679 template <typename FSetup, typename FRecord>
680 PassHandle CreatePass(StringView name, RHIDeviceQueueType queue, size_t priority, FSetup&& setup,
681 FRecord&& record)
682 {
683 return CreatePassImpl<LambdaPass<FSetup, FRecord>>(name, queue, priority, std::forward<FSetup>(setup),
684 std::forward<FRecord>(record));
685 }
704 template <typename T>
705 [[nodiscard]] ResourceHandle CreateResource(StringView name, T const& desc)
706 {
707
709
710 ResourceHandle index = mSetup->trackedResources.size();
711 mSetup->trackedResources.emplace_back(index, name, desc, mAllocator);
712 return mSetup->trackedResources.size() - 1;
713 }
722 [[nodiscard]] ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const& desc) const;
723#pragma region Resource Binding
730 void BindPass(PassHandle pass, PassHandle other);
742 void BindShader(PassHandle pass, RHIShaderStage stage, StringView entry_point, StringView shader_path,
743 Span<const char> specializationData = {}, uint32_t rtHitGroupIndex = 0,
745 RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles) const;
754 void BindPushConstant(PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const;
781 void BindBufferUniform(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
782 StringView bind_point) const;
795 void BindBufferStorageRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
796 StringView bind_point) const;
809 void BindBufferUnordered(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage,
810 StringView bind_point) const;
819 void BindBufferShaderRead(PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const;
826 void BindBufferIndirectRead(PassHandle pass, ResourceHandle buffer) const;
832 void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const;
838 void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const;
847 void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const;
859 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
866 RHIDeviceDescriptorSetLayout* reading_layout = nullptr);
881 void MakePassUncullable(PassHandle pass) const;
892 void BindTextureSRV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
893 RHITextureViewDesc const& desc) const;
907 void BindTextureUAV(PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage,
908 RHITextureViewDesc const& desc) const;
914 void BindTextureShaderRead(PassHandle pass, ResourceHandle texture, RHIPipelineStage stage,
915 RHITextureSubresourceRange const& range) const;
926 void BindTextureRTV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
936 void BindTextureDSV(PassHandle pass, ResourceHandle texture, RHITextureViewDesc const& desc,
937 bool readOnly = false) const;
950 void BindBackbufferUAV(PassHandle pass, int set_index) const;
958 RHITextureSubresourceRange const& range = {}) const;
966 RHITextureSubresourceRange const& range = {}) const;
977 void BindAccelerationStructureSRV(PassHandle pass, ResourceHandle as, RHIPipelineStage stage,
978 StringView bind_point) const;
979
980#pragma endregion
981#pragma region PSO Flags
990 RHIPipelineState::PipelineStateDesc::DepthStencil const& depth_stencil = {}) const;
995#pragma endregion
1007 Core::JobBarrier EndSetup(bool wait = true);
1008#pragma endregion
1009#pragma region Diagnostics
1011 {
1013 size_t bytes;
1014 };
1023 void DbgGetMemoryStatistics(Vector<MemoryStat>& outStats) const;
1025#pragma endregion
1026#pragma region Swapchain
1030 [[nodiscard]] RHIDevice* GetDevice() const { return mDevice.Get(); }
1034 [[nodiscard]] const RHIApplication* GetApplication() const { return &mDevice->mApp; }
1039 [[nodiscard]] RHIExtent2D GetSwapchainExtent() const
1040 {
1041 CHECK(mSwapchain && "Swapchain not initialized");
1042 return mSwapchain->mDesc.extents;
1043 }
1048 [[nodiscard]] RHIExtent3D GetSwapchainExtent3D() const
1049 {
1050 CHECK(mSwapchain && "Swapchain not initialized");
1051 auto xy = mSwapchain->mDesc.extents;
1052 return {xy.x, xy.y, 1};
1053 }
1054#pragma endregion
1055#pragma region Render Graph Runtime
1068 DerefResource(const ResourceHandle handle) const
1069 {
1070 CHECK(mResources && handle < mResources->resources.size());
1072 auto& res = mResources->resources[handle];
1073 CHECK_MSG(!res.valueless_by_exception(), "Resource handle {} is valueless", handle);
1074 auto ptr = res.Visit([](auto* ptr) -> Tv { return ptr; }, [](auto& hdl) -> Tv { return hdl.Get(); });
1075 CHECK_MSG(!ptr.valueless_by_exception(), "Resource handle {} is null", handle);
1076 return ptr;
1077 }
1083 [[nodiscard]] RHITextureView* DerefTextureView(const ResourceHandle handle) const
1084 {
1085 CHECK(mResources && handle < mResources->views.size());
1086 using Tv = RHITextureView*;
1087 auto& view = mResources->views[handle];
1088 CHECK_MSG(!view.valueless_by_exception(), "Texture view handle {} is valueless", handle);
1089 return view.Visit([](auto& hdl) -> Tv { return hdl.Get(); });
1090 }
1096 [[nodiscard]] RHIDeviceSampler* DerefSampler(const ResourceHandle handle) const
1097 {
1098 CHECK(mSetup && handle < mSetup->trackedSamplers.size());
1099 return mResources->samplers[handle].Get();
1100 }
1104 [[nodiscard]] RHIPipelineState* DerefPipelineState(const PassHandle pass) const
1105 {
1106 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1107 auto& tpass = mSetup->trackedPasses[pass];
1108 return tpass.pso.Get();
1109 }
1114 {
1115 CHECK(mSetup && pass < mSetup->trackedPasses.size());
1116 auto& tpass = mSetup->trackedPasses[pass];
1117 return tpass.pDescriptorSets;
1118 }
1122 [[nodiscard]] Allocator* GetAllocator() const { return mAllocator; }
1123#pragma endregion
1124#pragma region Command Recording Helpers
1130 [[nodiscard]] RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const;
1146 void CmdDispatch(PassHandle pass, RHICommandList* cmd, RHIExtent3D thread_size) const;
1151 void CmdSetPipeline(PassHandle pass, RHICommandList* cmd) const;
1155 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, uint32_t set_index,
1156 RHIDeviceDescriptorSet* descriptor_set) const;
1163 void CmdBindDescriptorSet(PassHandle pass, RHICommandList* cmd, StringView bind_point,
1164 RHIDeviceDescriptorSet* descriptor_set) const;
1174 void CmdBeginGraphics(PassHandle pass, RHICommandList* cmd, RHIExtent2D const& extent,
1176 RHIDepthAttachmentLoad dsv_load = {RHIAttachmentLoadOp::Clear, {0.0f, 0u}});
1183 template <typename T>
1184 void CmdSetPushConstant(PassHandle pass, RHICommandList* cmd, RHIShaderStage stage, size_t offset,
1185 T const& data)
1186 {
1188 auto& tpass = mSetup->trackedPasses[pass];
1189 cmd->PushConstant(tpass.pso.Get(), stage, static_cast<uint32_t>(offset),
1190 {reinterpret_cast<const char*>(&data), sizeof(T)});
1191 }
1192#pragma endregion
1193#pragma region Frame Execution
1197 [[nodiscard]] State GetState() const { return mState; }
1201 [[nodiscard]] uint32_t GetFrameSwaps() const { return mFrameSwaps; }
1208 [[nodiscard]] uint64_t GetFrame() const { return mFrameSwapped; }
1219 [[nodiscard]] uint32_t GetSwap() const { return mCurrentSwap; }
1233 [[nodiscard]] uint64_t GetSync() const { return mCurrentSync; }
1238 {
1239 CHECK_MSG(mSetup && pass < mSetup->trackedPasses.size(), "No passes available or out of bounds");
1240 return mSetup->trackedPasses[pass];
1241 }
1248 [[nodiscard]] bool IsAsyncComputeEnabled() const { return mDesc.asyncCompute; }
1258 [[nodiscard]] bool IsPresentEnabled() const { return mSwapchain.IsValid(); }
1272 RHISwapchain* GetSwapchain() const { return mSwapchain.Get(); }
1273
1278
1299 void WaitForFrame();
1311 void BeginExecute();
1332 void ExecuteFrame();
1339 void EndExecute();
1340#pragma endregion
1341#pragma region Debugging
1342 [[nodiscard]] String DbgDumpGraphviz() const;
1343 [[nodiscard]] String DbgDumpActivePasses() const;
1344 [[nodiscard]] String DbgDumpExecutionGroups() const;
1353 Span<const uint64_t> DbgProfilePassTiming(uint64_t sync, float& resolutionNS) const;
1354
1355#pragma endregion
1356 };
1360 ENUM_NAME(PostSetup);
1361 ENUM_NAME(Execute);
1363} // 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:210
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:377
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:680
void DbgGetTexturePreviews(Vector< TexturePreviewStat > &outStats) const
Definition Renderer.cpp:1401
Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > DerefResource(const ResourceHandle handle) const
Dereference a resource handle to its underlying RHI resource.
Definition Renderer.hpp:1068
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:388
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:504
Atomic< bool > mPipelineStateCompilationComplete
Definition Renderer.hpp:451
UniquePtr< ExecuteResources > mResources
Definition Renderer.hpp:462
RHIDeviceSemaphore * mExecuteImageAcquire
Definition Renderer.hpp:460
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:378
void BeginSetup()
Begins the setup phase of the render graph.
Definition Renderer.cpp:123
void DbgGetMemoryStatistics(Vector< MemoryStat > &outStats) const
Definition Renderer.cpp:1362
RHICommandList * ExecuteAllocateCommandList(RHIDeviceQueueType queue, int thread_id=-1)
Definition Renderer.cpp:1816
RHIDeviceHandle< RHISwapchain > mSwapchain
Definition Renderer.hpp:493
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:170
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:279
Vector< Pair< RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc > > * mExecuteSubmits
Definition Renderer.hpp:513
void WaitForFrame()
Blocks until the most recently submitted frame has finished executing on the GPU.
Definition Renderer.cpp:1510
State mState
Definition Renderer.hpp:448
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:2186
void ExecuteBarrierAccelerationStructure(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for an acceleration structure.
Definition Renderer.cpp:1697
Core::JobBarrier BuildPipelineStateAll()
Definition Renderer.cpp:1223
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:351
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
Definition Renderer.hpp:528
RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > mSwapDescriptorSetLayout
Definition Renderer.hpp:487
RHIDeviceSampler * DerefSampler(const ResourceHandle handle) const
Dereference a sampler handle to its underlying RHI sampler.
Definition Renderer.hpp:1096
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:1833
void ExecuteBarrierSubresourceState(PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const
Definition Renderer.cpp:1618
RHIDeviceQueue * mGraphicsQueue
Definition Renderer.hpp:494
Vector< RHIDeviceDescriptorSet * > const & DerefDescriptorSets(const PassHandle pass) const
Dereference the built descriptor sets associated with a given pass.
Definition Renderer.hpp:1113
uint32_t ExecuteGetQueueFamily(RHIDeviceQueueType queue) const
Helper to get the queue index of a queue type.
Definition Renderer.hpp:539
ResourceHandle CreateTextureView(PassHandle pass, ResourceHandle handle, RHITextureViewDesc const &desc) const
Definition Renderer.cpp:144
void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const
Binds a sampler to the shader.
Definition Renderer.cpp:303
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:1652
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:310
Vector< Pair< Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * >, RHICommandList::TransitionDesc > > ExecuteBarrierList
Definition Renderer.hpp:555
const RHIApplication * GetApplication() const
Get the RHIApplication this Renderer was constructed with.
Definition Renderer.hpp:1034
ScopedArena mExecuteArena
Definition Renderer.hpp:507
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:138
void CmdDispatch(PassHandle pass, RHICommandList *cmd, RHIExtent3D thread_size) const
Helper that dispatches a compute shader with the specified THREAD count.
Definition Renderer.cpp:2272
Mutex mDescPoolMutex
Definition Renderer.hpp:464
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Definition Renderer.cpp:430
void BindVertexInput(PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const
Associates Vertex Input description with this pass.
Definition Renderer.cpp:232
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:2174
uint32_t mFrameSwaps
Definition Renderer.hpp:457
void FinalizePasses()
Definition Renderer.cpp:1250
void BuildPipelineState(PassHandle pass)
Definition Renderer.cpp:766
void BindPass(PassHandle pass, PassHandle other)
Declares an inter-pass dependency, where the other pass should execute-before the current pass.
Definition Renderer.cpp:160
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:261
RHIDeviceScopedHandle< RHIDeviceSemaphore > mGraphicsTimeline
Definition Renderer.hpp:491
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:1451
String DbgDumpActivePasses() const
Definition Renderer.cpp:2329
RHIPipelineState * DerefPipelineState(const PassHandle pass) const
Dereference the automatically built pipeline state object handle associated with a given pass.
Definition Renderer.hpp:1104
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:649
uint32_t GetFrameSwaps() const
Get the number of frames that can be simultaneously in-flight.
Definition Renderer.hpp:1201
AllocatorStack mExecuteAlloc
Definition Renderer.hpp:510
Vector< FrameSyncObjects > mSwaps
Definition Renderer.hpp:489
String DbgDumpExecutionGroups() const
Definition Renderer.cpp:2342
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:490
uint64_t mFrameSwapped
Definition Renderer.hpp:455
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:2209
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mDescPool
Definition Renderer.hpp:463
ThreadPool mExecuteThreadPool
Definition Renderer.hpp:515
void AcquireSync()
Acquires the synchronization primitives for the current frame. Internal. Called by BeginExecute.
Definition Renderer.cpp:1538
void SetFrameSyncObjects()
Sets backbuffer views and sync primitives.
Definition Renderer.cpp:1425
RHISwapchain * GetSwapchain() const
Returns the currently used RHISwapchain object.
Definition Renderer.hpp:1272
void BindBufferCopySrc(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will read from the buffer via copy.
Definition Renderer.cpp:297
Core::JobBarrier EndSetup(bool wait=true)
Finish setting up the render graph.
Definition Renderer.cpp:521
uint32_t mCurrentSwap
Definition Renderer.hpp:459
RHIDevice * GetDevice() const
Get the RHIDevice this Renderer was constructed with.
Definition Renderer.hpp:1030
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:364
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:199
RHIExtent3D GetSwapchainExtent3D() const
Get the current swapchain extents as a 3D extent with depth 1.
Definition Renderer.hpp:1048
UniquePtr< RendererSetup > mSetup
Definition Renderer.hpp:496
void CullPasses(PassHandle epilogue) const
Definition Renderer.cpp:546
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:408
Allocator * GetAllocator() const
Definition Renderer.hpp:1122
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:458
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:1039
RHIDeviceHandle< RHIDeviceSemaphore > GetRenderCompleteSemaphore() const
Binary semaphore signaled when GPU work for the current swap image is complete.
Definition Renderer.cpp:1502
RHIApplicationHandle< RHIDevice > mDevice
Definition Renderer.hpp:492
RendererDesc mDesc
Definition Renderer.hpp:453
Allocator * mAllocator
Definition Renderer.hpp:449
void ExecuteBarriers(TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes all barriers for a pass.
Definition Renderer.cpp:1727
void BindBufferCopyDst(PassHandle pass, ResourceHandle buffer) const
Declares that this pass will write to the buffer via copy.
Definition Renderer.cpp:291
void BeginExecute()
Begins execution for a headless (no swapchain) frame.
Definition Renderer.cpp:1602
TrackedPass const & GetTrackedPass(PassHandle pass)
Retrieves an internal tracked pass associated with the given handle, read-only.
Definition Renderer.hpp:1237
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:285
void EndExecute()
Ends the execution phase and performs GPU submission.
Definition Renderer.cpp:2132
void FinalizeResources()
Definition Renderer.cpp:1270
uint32_t mCurrentSync
Definition Renderer.hpp:458
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:241
void ExecuteBarrierBuffer(PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd)
Executes barriers for a whole buffer.
Definition Renderer.cpp:1668
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:2357
String DbgDumpGraphviz() const
Definition Renderer.cpp:2281
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:468
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:270
void PassSetTopology(PassHandle pass, RHIPipelineState::PipelineStateDesc::Topology topology) const
Sets the input assembly topology for a graphics pass (TriangleList, LineList, etc....
Definition Renderer.cpp:514
RHIDeviceQueue * mComputeQueue
Definition Renderer.hpp:494
void BindAccelerationStructureWrite(PassHandle pass, ResourceHandle as) const
Declares that this pass will build, or update the AS.
Definition Renderer.cpp:478
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:221
Core::JobSystem * mJobs
Definition Renderer.hpp:450
RHIDeviceScopedHandle< RHIDeviceSemaphore > mComputeTimeline
Definition Renderer.hpp:491
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:1184
void BindDescriptorSetRead(PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout)
Binds an externally managed descriptor set that this pass reads.
Definition Renderer.cpp:337
bool IsAsyncComputeEnabled() const
Returns whether async compute is enabled.
Definition Renderer.hpp:1248
RHIDeviceIdleGuard mWaitIdle
Definition Renderer.hpp:624
uint64_t GetSync() const
Retrieves the current synchronization index.
Definition Renderer.hpp:1233
State
Definition Renderer.hpp:440
bool IsPresentEnabled() const
Returns whether a swapchain is bound.
Definition Renderer.hpp:1258
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:2263
uint32_t GetSwap() const
Retrieves the current swap index at the time of ExecuteFrame().
Definition Renderer.hpp:1219
uint64_t GetFrame() const
Retrieves the current frame number.
Definition Renderer.hpp:1208
State GetState() const
Retrieves the current state of the renderer.
Definition Renderer.hpp:1197
RHITextureView * DerefTextureView(const ResourceHandle handle) const
Dereference a texture view handle to its underlying RHI texture view.
Definition Renderer.hpp:1083
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:252
ResourceHandle CreateSampler(RHIDeviceSampler::SamplerDesc const &desc) const
Creates a sampler with the specified name and descriptor.
Definition Renderer.cpp:153
ResourceHandle CreateResource(StringView name, T const &desc)
Create a new resource to be used in the render graph.
Definition Renderer.hpp:705
void BindBackbufferUAV(PassHandle pass, int set_index) const
Binds the backbuffer as RW access at binding 0 of set index.
Definition Renderer.cpp:444
RHIDeviceScopedHandle< RHIDeviceDescriptorPool > mSwapDescriptorPool
Definition Renderer.hpp:486
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
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:86
const RHIResourceAccessBits kAllShaderWrites
Definition Renderer.hpp:76
constexpr size_t kMaxRenderPasses
Definition Renderer.hpp:68
const RHIResourceAccessBits kAllShaderReads
Definition Renderer.hpp:79
const RHIPipelineStage kComputeStagesMask
Definition Renderer.hpp:73
Handle PassHandle
Definition Renderer.hpp:21
constexpr size_t kExecuteArenaSize
Definition Renderer.hpp:72
constexpr size_t kMaxCommandListsPerThread
Definition Renderer.hpp:70
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
Helper class containing runtime resources either imported, or created by the Renderer.
Definition Renderer.hpp:192
Vector< Variant< RHIBuffer *, RHIDeviceScopedHandle< RHIBuffer >, RHITexture *, RHIDeviceScopedHandle< RHITexture >, RHIAccelerationStructure * > > resources
Definition Renderer.hpp:195
Vector< RHIDeviceScopedHandle< RHIDeviceSampler > > samplers
Definition Renderer.hpp:197
Vector< Variant< RHITextureScopedHandle< RHITextureView >, RHITextureHandle< RHITextureView > > > views
Definition Renderer.hpp:196
ExecuteResources(Allocator *allocator)
Definition Renderer.hpp:198
void fit(ResourceHandle handle)
Definition Renderer.hpp:199
Default "no-op" functor for Record()
Definition Renderer.hpp:247
void operator()(PassHandle, Renderer *, RHICommandList *) const
Definition Renderer.hpp:248
Default "no-op" functor for Setup()
Definition Renderer.hpp:240
void operator()(PassHandle, Renderer *) const
Definition Renderer.hpp:241
Functional wrapper for a render pass.
Definition Renderer.hpp:257
LambdaPass(FSetup &&setup, FRecord &&record)
Definition Renderer.hpp:260
void Record(PassHandle self, Renderer *r, RHICommandList *cmd) override
Record the commands of this pass into the given command list.
Definition Renderer.hpp:265
FRecord mRecord
Definition Renderer.hpp:259
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:264
FSetup mSetup
Definition Renderer.hpp:258
Parameters for Renderer creation.
Definition Renderer.hpp:27
bool profilePasses
Enable or disable GPU profiling for the frame graph execution.
Definition Renderer.hpp:62
uint32_t threadCount
Number of worker threads to use for recording command lists.
Definition Renderer.hpp:47
bool asyncCompute
Enable Async Compute support.
Definition Renderer.hpp:42
RHIPipelineStateCache * pipelineCache
Optional PSO cache to potentially speed up pipeline state recompilation in Setup time.
Definition Renderer.hpp:52
Vector< RHICommandPoolScopedHandle< RHICommandList > > computeCmds
Definition Renderer.hpp:519
RHICommandList * AllocateCompute()
Definition Renderer.cpp:1805
RHIDeviceScopedHandle< RHICommandPool > computePool
Definition Renderer.hpp:518
RHICommandList * AllocateGraphics()
Definition Renderer.cpp:1794
RHIDeviceScopedHandle< RHICommandPool > graphicsPool
Definition Renderer.hpp:518
Vector< RHICommandPoolScopedHandle< RHICommandList > > graphicsCmds
Definition Renderer.hpp:519
ResourceHandle backbuffer
Definition Renderer.hpp:476
RHIDeviceScopedHandle< RHIDeviceQueryPool > dbgQueryPool
Definition Renderer.hpp:478
RHIDeviceScopedHandle< RHIDeviceFence > computeFence
Definition Renderer.hpp:471
RHIDeviceScopedHandle< RHIDeviceFence > graphicsFence
Definition Renderer.hpp:471
FrameSyncObjects(size_t swapIndex, Allocator *alloc)
Definition Renderer.hpp:481
const size_t swapIndex
Definition Renderer.hpp:469
Vector< uint64_t > dbgQueryPassTimestampsResults
Definition Renderer.hpp:479
RHITextureScopedHandle< RHITextureView > view
Definition Renderer.hpp:473
RHIDeviceScopedHandle< RHIDeviceSemaphore > render
Definition Renderer.hpp:470
RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > viewSet
Definition Renderer.hpp:474
String name
Definition Renderer.hpp:1012
size_t bytes
Definition Renderer.hpp:1013
Vector< PassHandle > passes
Definition Renderer.hpp:406
Vector< ResourceHandle > resources
Definition Renderer.hpp:408
ExecutionGroups(int groupIndex, RHIDeviceQueueType queue, Allocator *allocator)
Definition Renderer.hpp:412
const RHIDeviceQueueType queue
Definition Renderer.hpp:405
Helper class containing all states pertaining to Renderer's Setup phase.
Definition Renderer.hpp:382
Vector< ExecutionGroups > executionGroups
Definition Renderer.hpp:417
PassHandle lastBackbufferProducer
Definition Renderer.hpp:388
bool executionAnyCompute
Definition Renderer.hpp:418
int executionNumGraphicsGroups
Definition Renderer.hpp:419
Vector< PassHandle > execution
Definition Renderer.hpp:396
Vector< Vector< Pair< PassHandle, ResourceHandle > > > graph
Definition Renderer.hpp:383
Vector< TrackedPass > trackedPasses
Definition Renderer.hpp:385
Map< ResourceHandle, Pair< PassHandle, PassHandle > > activeResources
Definition Renderer.hpp:393
int executionNumComputeGroups
Definition Renderer.hpp:419
Vector< PassHandle > in
Definition Renderer.hpp:384
Map< uintptr_t, PassHandle > descriptorSetWriters
Definition Renderer.hpp:394
void add_edge(const PassHandle u, const PassHandle v, const ResourceHandle hdl)
Definition Renderer.hpp:420
PassHandle epilogue
Definition Renderer.hpp:398
Vector< RHIDeviceSampler::SamplerDesc > trackedSamplers
Definition Renderer.hpp:391
Map< RHIDescriptorType, uint32_t > bindingCounts
Definition Renderer.hpp:397
Vector< TrackedResource > trackedResources
Definition Renderer.hpp:386
Vector< Pair< ResourceHandle, RHITextureViewDesc > > trackedViews
Definition Renderer.hpp:390
bool executionAnyGraphics
Definition Renderer.hpp:418
RendererSetup(Allocator *allocator)
Definition Renderer.hpp:430
String name
Definition Renderer.hpp:1017
ResourceHandle resourceHandle
Definition Renderer.hpp:1018
RHITextureView * view
Definition Renderer.hpp:1021
RHIResourceFormat format
Definition Renderer.hpp:1020
ResourceHandle viewHandle
Definition Renderer.hpp:1019
Internal tracking information for a render pass in the frame graph.
Definition Renderer.hpp:271
size_t frameExec
Definition Renderer.hpp:292
int priority
Definition Renderer.hpp:274
RHIPipelineState::PipelineStateDesc::DepthStencil psoDepthStencil
Definition Renderer.hpp:343
ResourceHandle dsv
Definition Renderer.hpp:326
Vector< Tuple< String, String, RHIShaderStage, Vector< char >, uint32_t, RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType > > shaders
Definition Renderer.hpp:311
Vector< RHIPipelineState::PipelineStateDesc::VertexInput::Binding > vertexInputBindings
Definition Renderer.hpp:329
Vector< RHIDeviceDescriptorSetLayout * > pDescriptorLayouts
Definition Renderer.hpp:348
RHIPipelineStageBits piplineStages
Definition Renderer.hpp:338
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage, RHITextureSubresourceRange, RHITextureLayout > > textureUsages
Definition Renderer.hpp:297
UniquePtr< RenderPass > pass
Definition Renderer.hpp:332
Vector< RHIDeviceDescriptorSet * > pDescriptorSets
Definition Renderer.hpp:352
RHIDeviceQueueType queue
Definition Renderer.hpp:276
RHIPipelineState::PipelineStateDesc::Rasterizer psoRasterizer
Definition Renderer.hpp:342
int groupIndex
Definition Renderer.hpp:336
size_t ord
Definition Renderer.hpp:291
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > textureBindings
Definition Renderer.hpp:313
Vector< Pair< ResourceHandle, String > > samplers
Definition Renderer.hpp:318
RHIDeviceScopedHandle< RHIPipelineState > pso
Definition Renderer.hpp:340
Vector< RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > > descriptorLayouts
Definition Renderer.hpp:346
bool unCullable
Definition Renderer.hpp:278
bool isRayTracingPass
Definition Renderer.hpp:287
Vector< RHIPipelineState::PipelineStateDesc::PushConstant > pushConstants
Definition Renderer.hpp:320
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > asUsages
Definition Renderer.hpp:302
Optional< RHIPipelineState::PipelineStateDesc::Attachment::Blending > backbufferRTV
Definition Renderer.hpp:280
bool isDepthReadOnly
Definition Renderer.hpp:327
bool used
Definition Renderer.hpp:277
Vector< RHIVertexAttribute > vertexInputAttributes
Definition Renderer.hpp:330
void ResetPipeline()
Definition Renderer.cpp:59
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > bufferBindings
Definition Renderer.hpp:313
Vector< Tuple< size_t, RHIDeviceDescriptorSetLayout * > > pExternalDescriptorSets
Definition Renderer.hpp:354
Vector< Tuple< RHIShaderStage, size_t, Vector< char > > > specializationConstants
Definition Renderer.hpp:322
Vector< RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > > descriptorSets
Definition Renderer.hpp:350
Vector< Tuple< ResourceHandle, RHIDescriptorType, String > > asBindings
Definition Renderer.hpp:313
PassHandle handle
Definition Renderer.hpp:273
Tuple< uint32_t, uint32_t, uint32_t > groupLocalSize
Definition Renderer.hpp:289
Vector< ResourceHandle > texviews
Definition Renderer.hpp:306
Vector< Tuple< ResourceHandle, RHIResourceAccess, RHIPipelineStage > > bufferUsages
Definition Renderer.hpp:299
Optional< int > backbufferUAV
Definition Renderer.hpp:281
size_t depth
Definition Renderer.hpp:290
Vector< PassHandle > bindPasses
Definition Renderer.hpp:294
Vector< Pair< ResourceHandle, RHIPipelineState::PipelineStateDesc::Attachment::Blending > > rtvs
Definition Renderer.hpp:324
bool isComputePass
Definition Renderer.hpp:284
RHIPipelineState::PipelineStateDesc::Topology psoTopology
Definition Renderer.hpp:344
Vector< ResourceHandle > resources
Definition Renderer.hpp:304
String name
Definition Renderer.hpp:272
Vector< Tuple< String, RHIDeviceDescriptorSetLayout *, int > > externalBindings
Definition Renderer.hpp:316
RHIDevicePipelineType GetPipelineType() const
Definition Renderer.hpp:357
RHIPipelineStage stage
Definition Renderer.hpp:116
size_t lastProducedFrame
Definition Renderer.hpp:110
PassHandle lastProducer
Definition Renderer.hpp:108
RHIResourceAccess access
Definition Renderer.hpp:115
bool executeTempTransitionFlag
Definition Renderer.hpp:114
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:112
PassHandle producer
Definition Renderer.hpp:106
RHIResourceAccess access
Definition Renderer.hpp:142
RHIDeviceQueueType lastOwnerQueue
Definition Renderer.hpp:139
bool executeTempTransitionFlag
Definition Renderer.hpp:141
RHIPipelineStage stage
Definition Renderer.hpp:143
RHITextureAspectFlagBits aspect
Definition Renderer.hpp:130
RHITextureLayout layout
Definition Renderer.hpp:144
PassHandle producer
Definition Renderer.hpp:133
size_t lastProducedFrame
Definition Renderer.hpp:137
PassHandle lastProducer
Definition Renderer.hpp:135
RHITextureSubresourceRange ToRange() const
Definition Renderer.cpp:8
Internal tracking information for a resource in the frame graph.
Definition Renderer.hpp:91
Vector< SubresourceState > lastSubresourceStates
Definition Renderer.hpp:157
auto GetLastSubresourceStateOf(RHITextureSubresourceRange const &range)
Definition Renderer.hpp:158
bool hasGraphicsUsage
Definition Renderer.hpp:96
String name
Definition Renderer.hpp:93
void ResetStates()
Definition Renderer.hpp:178
ResourceDefinition desc
Definition Renderer.hpp:94
AccelerationStructureState lastASState
Definition Renderer.hpp:177
uint32_t textureMips
Definition Renderer.hpp:126
uint32_t textureLayers
Definition Renderer.hpp:126
bool hasComputeUsage
Definition Renderer.hpp:95
struct Foundation::RenderCore::TrackedResource::BufferState lastBufferState
ResourceHandle handle
Definition Renderer.hpp:92