Foundation
Loading...
Searching...
No Matches
CSClearBuffer.hpp
Go to the documentation of this file.
1#pragma once
2#include <Math/Math.hpp>
5{
6 using namespace RenderCore;
7 using namespace Math;
8#pragma pack(push,1)
10 {
12 uint32_t w, h;
13 };
14#pragma pack(pop)
16 {
17 return r->CreatePass(
18 name, RHIDeviceQueueType::Graphics, 0u,
19 [=](PassHandle self, Renderer* r)
20 {
21 r->BindBackbufferUAV(self, 0u);
22 r->BindShader(self, RHIShaderStageBits::Compute, "main", r->GetApplication()->ResolveRelativePathBase("Data/Shaders/CSClearBuffer.spv"));
23 r->BindPushConstant(self, RHIShaderStageBits::Compute, 0, sizeof(CSClearBufferData));
24 },
25 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
26 {
27 RHIExtent2D wh = r->GetSwapchainExtent();
28 CSClearBufferData cdata{clearColor, wh.x, wh.y};
29 r->CmdSetPipeline(self, cmd);
30 r->CmdSetPushConstant(self, cmd, RHIShaderStageBits::Compute, 0, cdata);
31 r->CmdDispatch(self, cmd, {cdata.w, cdata.h, 1});
32 });
33 }
35 {
36 return r->CreatePass(
37 name, RHIDeviceQueueType::Graphics, 0u,
38 [=](PassHandle self, Renderer* r)
39 {
40 r->BindTextureUAV(self, resource, "texture", RHIPipelineStageBits::ComputeShader, viewDesc);
41 r->BindShader(self, RHIShaderStageBits::Compute, "main", r->GetApplication()->ResolveRelativePathBase("Data/Shaders/CSClearBuffer.spv"));
42 r->BindPushConstant(self, RHIShaderStageBits::Compute, 0, sizeof(CSClearBufferData));
43 },
44 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
45 {
47 CSClearBufferData cdata{clearColor, wh.x, wh.y};
48 r->CmdSetPipeline(self, cmd);
49 r->CmdSetPushConstant(self, cmd, RHIShaderStageBits::Compute, 0, cdata);
50 r->CmdDispatch(self, cmd, {cdata.w, cdata.h, 1});
51 });
52 }
53} // namespace Foundation::RenderUtils
virtual String ResolveRelativePathBase(StringView path="") const =0
Retrives path relative to the application executable.
Definition Command.hpp:42
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
const RHIApplication * GetApplication() const
Get the RHIApplication this Renderer was constructed with.
Definition Renderer.hpp:1034
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
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 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
RHIExtent2D GetSwapchainExtent() const
Get the current swapchain extents.
Definition Renderer.hpp:1039
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 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
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
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:56
vec4 float4
Definition Math.hpp:25
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 createCSClearTexture(Renderer *r, StringView name, ResourceHandle resource, RHITextureViewDesc viewDesc, float4 clearColor)
Definition CSClearBuffer.hpp:34
PassHandle createCSClearBackBuffer(Renderer *r, StringView name, float4 clearColor={})
Definition CSClearBuffer.hpp:15
Definition Resource.hpp:210
Definition CSClearBuffer.hpp:10
float4 color
Definition CSClearBuffer.hpp:11
uint32_t h
Definition CSClearBuffer.hpp:12
uint32_t w
Definition CSClearBuffer.hpp:12