Foundation
Loading...
Searching...
No Matches
PSFullscreen.hpp
Go to the documentation of this file.
1#pragma once
4 using namespace RenderCore;
11 template<typename FSetup, typename FRecord>
13 Renderer* r,
14 StringView name,
15 FSetup&& setup,
16 FRecord&& record
17 ) {
18 return r->CreatePass(name, RHIDeviceQueueType::Graphics, 0u,
19 [=](PassHandle self, Renderer* r) {
20 r->BindBackbufferRTV(self);
21 r->BindShader(self, RHIShaderStageBits::Vertex, "vertMain", r->GetApplication()->ResolveRelativePathBase("Data/Shaders/VSFullscreen.spv"));
22 setup(self, r);
23 },
24 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
25 {
26 auto const& img_wh = r->GetSwapchainExtent();
27 r->CmdSetPipeline(self, cmd);
28 record(self, r, cmd);
29 r->CmdBeginGraphics(self, cmd, img_wh, {{RHIColorAttachmentLoad{RHIAttachmentLoadOp::DontCare}}},
30 {RHIAttachmentLoadOp::DontCare}); // No clear necessary
31 cmd->SetViewport(0, 0, img_wh.x, img_wh.y)
32 .SetScissor(0, 0, img_wh.x, img_wh.y);
33 cmd->Draw(3);
34 cmd->EndGraphics();
35 });
36 }
37 template<typename FSetup>
39 Renderer* r,
40 StringView name,
41 FSetup&& setup)
42 {
43 return createPSFullscreenPass(r, name, std::forward<FSetup>(setup), FRecordDefault{});
44 }
54 template<typename FSetup, typename FRecord>
56 Renderer* r,
57 StringView name,
58 ResourceHandle rtvTexture,
59 RHITextureViewDesc const& rtvViewDesc,
60 RHIExtent2D extent,
61 FSetup&& setup,
62 FRecord&& record
63 ) {
64 return r->CreatePass(name, RHIDeviceQueueType::Graphics, 0u,
65 [=](PassHandle self, Renderer* r) {
66 r->BindTextureRTV(self, rtvTexture, rtvViewDesc);
67 r->BindShader(self, RHIShaderStageBits::Vertex, "vertMain", r->GetApplication()->ResolveRelativePathBase("Data/Shaders/VSFullscreen.spv"));
68 setup(self, r);
69 },
70 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
71 {
72 RHIExtent2D img_wh = extent;
73 if (img_wh.x == 0u || img_wh.y == 0u)
74 {
75 auto const* rtv = r->DerefResource(rtvTexture).Get<RHITexture*>();
76 img_wh = {rtv->mDesc.extent.x, rtv->mDesc.extent.y};
77 }
78 r->CmdSetPipeline(self, cmd);
79 record(self, r, cmd);
80 r->CmdBeginGraphics(self, cmd, img_wh, {{RHIColorAttachmentLoad{RHIAttachmentLoadOp::DontCare}}},
81 {RHIAttachmentLoadOp::DontCare});
82 cmd->SetViewport(0, 0, img_wh.x, img_wh.y)
83 .SetScissor(0, 0, img_wh.x, img_wh.y);
84 cmd->Draw(3);
85 cmd->EndGraphics();
86 });
87 }
88 template<typename FSetup>
90 Renderer* r,
91 StringView name,
92 ResourceHandle rtvTexture,
93 RHITextureViewDesc const& rtvViewDesc,
94 FSetup&& setup)
95 {
96 return createPSFullscreenPassRTV(r, name, rtvTexture, rtvViewDesc, RHIExtent2D{0u, 0u},
97 std::forward<FSetup>(setup), FRecordDefault{});
98 }
104 Renderer* r,
105 StringView name,
106 ResourceHandle copy_sampler,
107 ResourceHandle copy_source,
108 RHIResourceFormat srcFormat = RHIResourceFormat::R8G8B8A8Unorm
109 ) {
111 r,
112 name,
113 [=](PassHandle self, Renderer*) {
114 r->BindTextureSampler(self, copy_sampler, "sampler");
115 r->BindTextureSRV(self, copy_source, "srcTexture", RHIPipelineStageBits::FragmentShader, {
116 .format = srcFormat,
118 });
119 r->BindShader(self, RHIShaderStageBits::Fragment, "fragMain", r->GetApplication()->ResolveRelativePathBase("Data/Shaders/PSCopy.spv"));
120 },
122 );
123 }
124 // Color R32 (etc.) -> D32 depth via SV_Depth; CopyImage cannot cross aspects without maintenance8.
126 ResourceHandle dstDepth, RHIExtent2D extent,
127 RHIResourceFormat srcFormat = RHIResourceFormat::R32SignedFloat)
128 {
129 return r->CreatePass(
130 name, RHIDeviceQueueType::Graphics, 0u,
131 [=](PassHandle self, Renderer* r)
132 {
133 r->BindShader(self, RHIShaderStageBits::Vertex, "vertMain",
134 r->GetApplication()->ResolveRelativePathBase("Data/Shaders/VSFullscreen.spv"));
135 r->BindShader(self, RHIShaderStageBits::Fragment, "fragMain",
136 r->GetApplication()->ResolveRelativePathBase("Data/Shaders/PSCopyDepth.spv"));
137 r->BindTextureSRV(self, srcDepth, "srcDepth", RHIPipelineStageBits::FragmentShader,
138 RHITextureViewDesc{.format = srcFormat,
140 RHITextureAspectFlagBits::Color)});
141 r->BindTextureDSV(self, dstDepth,
142 RHITextureViewDesc{.format = RHIResourceFormat::D32SignedFloat,
144 RHITextureAspectFlagBits::Depth)});
147 {.depthTest = true,
148 .depthWrite = true,
150 },
151 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
152 {
153 r->CmdSetPipeline(self, cmd);
154 r->CmdBeginGraphics(self, cmd, extent, {}, {RHIAttachmentLoadOp::DontCare});
155 cmd->SetViewport(0, 0, extent.x, extent.y).SetScissor(0, 0, extent.x, extent.y);
156 cmd->Draw(3);
157 cmd->EndGraphics();
158 });
159 }
160}
virtual String ResolveRelativePathBase(StringView path="") const =0
Retrives path relative to the application executable.
Definition Command.hpp:42
Definition Resource.hpp:216
const RHITextureDesc mDesc
Definition Resource.hpp:221
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
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
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
void BindTextureSampler(PassHandle pass, ResourceHandle sampler, StringView bind_point) const
Binds a sampler to the shader.
Definition Renderer.cpp:303
const RHIApplication * GetApplication() const
Get the RHIApplication this Renderer was constructed with.
Definition Renderer.hpp:1034
void BindBackbufferRTV(PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const
Definition Renderer.cpp:430
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
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
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
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:1039
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
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:56
RHIResourceFormat
Definition Common.hpp:34
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
Handle ResourceHandle
Definition Renderer.hpp:22
Handle PassHandle
Definition Renderer.hpp:21
Definition CSClearBuffer.hpp:5
PassHandle createPSFullscreenPass(Renderer *r, StringView name, FSetup &&setup, FRecord &&record)
Creates a full-screen triangle pass that writes to the current backbuffer.
Definition PSFullscreen.hpp:12
PassHandle createPSDepthCopyPass(Renderer *r, StringView name, ResourceHandle srcDepth, ResourceHandle dstDepth, RHIExtent2D extent, RHIResourceFormat srcFormat=RHIResourceFormat::R32SignedFloat)
Definition PSFullscreen.hpp:125
PassHandle createPSBackbufferBlitPass(Renderer *r, StringView name, ResourceHandle copy_sampler, ResourceHandle copy_source, RHIResourceFormat srcFormat=RHIResourceFormat::R8G8B8A8Unorm)
Creates a full-screen triangle pass that renders a texture to the current backbuffer.
Definition PSFullscreen.hpp:103
PassHandle createPSFullscreenPassRTV(Renderer *r, StringView name, ResourceHandle rtvTexture, RHITextureViewDesc const &rtvViewDesc, RHIExtent2D extent, FSetup &&setup, FRecord &&record)
Creates a full-screen triangle pass that writes to an arbitrary texture RTV instead of the backbuffer...
Definition PSFullscreen.hpp:55
RHIExtent3D extent
Definition Resource.hpp:146
static RHITextureSubresourceRange Create(RHITextureAspectFlag aspect=RHITextureAspectFlagBits::Color, uint32_t base_mip_level=0, uint32_t mip_count=1, uint32_t base_array_layer=0, uint32_t layer_count=1)
Helper function to create a Subresource Range with default parameters.
Definition Resource.hpp:191
Definition Resource.hpp:210
RHIResourceFormat format
Definition Resource.hpp:211
Default "no-op" functor for Record()
Definition Renderer.hpp:247