8 using namespace RenderCore;
23 fmt::format(
"Mip Gen {} {}",
i, name), queue, 0u,
32 r->BindTextureSRV(
self,
src,
"srcTexture", RHIPipelineStageBits::ComputeShader,
34 .range = RHITextureSubresourceRange::Create(srcAspect, 0, 1, layer, 1)});
37 self, dst,
"srcTexture", RHIPipelineStageBits::ComputeShader,
41 self, dst,
"dstTexture", RHIPipelineStageBits::ComputeShader,
44 r->BindPushConstant(
self, RHIShaderStageBits::Compute, 0,
sizeof(
float2));
56 r->CmdSetPushConstant(
self,
cmd, RHIShaderStageBits::Compute, 0,
float2{w, h});
57 r->CmdDispatch(
self,
cmd, {w, h, 1});
76 uint32_t numWorkGroups;
93 fmt::format(
"{} SPD Atomics", name),
95 .
usage = RHIBufferUsageBits::StorageBuffer | RHIBufferUsageBits::TransferDestination,
105 case RHIDeviceSampler::SamplerDesc::Reduction::WeightedAverage:
108 case RHIDeviceSampler::SamplerDesc::Reduction::Min:
111 case RHIDeviceSampler::SamplerDesc::Reduction::Max:
119 r->BindBufferUnordered(
self,
SpdCounter, RHIPipelineStageBits::ComputeShader,
"spdGlobalAtomic");
120 CHECK_MSG(
numMips <= 12,
"Single Pass CS Mip generation supports up to 12 mips.");
121 CHECK_MSG(
numMips > 1,
"Single Pass CS Mip generation requires at least 2 mips.");
122 r->BindTextureSRV(
self,
src,
"imgSrc", RHIPipelineStageBits::ComputeShader,
125 .dimension = RHITextureDimension::E2DArray,
128 for (
uint32_t mip = 1; mip <= 12; mip++)
135 self, dst,
"imgDst", RHIPipelineStageBits::ComputeShader,
138 .dimension = RHITextureDimension::E2DArray,
143 self, dst,
"imgDst6", RHIPipelineStageBits::ComputeShader,
146 .dimension = RHITextureDimension::E2DArray,
156 pc.extents *= 2,
pc.mips++;
159 if (
r->GetFrame() == 0)
163 cmd->BeginTransition();
164 cmd->SetBufferTransition(
167 .srcAccess = RHIResourceAccessBits::TransferWrite,
168 .dstAccess = RHIResourceAccessBits::ShaderWrite,
169 .srcStage = RHIPipelineStageBits::ComputeShader | RHIPipelineStageBits::Transfer,
170 .dstStage = RHIPipelineStageBits::ComputeShader,
172 cmd->EndTransition();
175 r->CmdSetPushConstant(
self,
cmd, RHIShaderStageBits::Compute, 0,
pc);
#define CHECK_MSG(expr, format_str,...)
Definition Logging.hpp:62
Definition Resource.hpp:57
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:89
Span< const T > AsSpan(T const &data)
Helper to construct one const r-value as a single element span.
Definition Container.hpp:69
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:55
Span< const char > AsBytes(Span< T > data)
Definition Container.hpp:62
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:153
String PathsResolve(StringView relPath)
Definition Paths.cpp:18
vec2 float2
Definition Math.hpp:27
uvec2 uint2
Definition Math.hpp:33
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
RHIDeviceQueueType
Definition Common.hpp:164
RHIResourceFormat
Definition Common.hpp:34
Handle ResourceHandle
Definition RenderPass.hpp:11
Handle PassHandle
Definition RenderPass.hpp:10
Definition CSClearBuffer.hpp:6
void createCSMipGenerationPasses(Renderer *renderer, StringView name, RHIDeviceQueueType queue, ResourceHandle src, ResourceHandle dst, RHIResourceFormat srcFormat, RHIResourceFormat dstFormat, RHITextureAspectFlagBits srcAspect, RHITextureAspectFlagBits dstAspect, ResourceHandle srcSampler, uint32_t numMips, uint32_t layer=0)
Generates full mip-chain with multiple compute dispatches.
Definition CSMipGeneration.hpp:13
void createCSMipGenerationSinglePass(Renderer *renderer, StringView name, RHIDeviceQueueType queue, ResourceHandle src, ResourceHandle dst, RHIResourceFormat srcFormat, RHIResourceFormat dstFormat, RHITextureAspectFlag srcAspect, RHITextureAspectFlag dstAspect, ResourceHandle srcSampler, uint32_t numMips, uint32_t numLayer=1, RHIDeviceSampler::SamplerDesc::Reduction reduction=RHIDeviceSampler::SamplerDesc::Reduction::WeightedAverage)
Generates full mip-chain with a single compute dispatch.
Definition CSMipGeneration.hpp:65
Definition Resource.hpp:28
RHIBufferUsage usage
How the buffer can be used by the device, initially.
Definition Resource.hpp:31
Reduction
Definition Device.hpp:153
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