Foundation
Loading...
Searching...
No Matches
CSMipGeneration.hpp
Go to the documentation of this file.
1#pragma once
4{
5 using namespace RenderCore;
11 )
12 {
13 using namespace Math;
14 for (uint32 i = 0; i < maxMips; ++i)
15 {
16 if (i == 0 && src == dst)
17 continue;
18 renderer->CreatePass(
19 fmt::format("Mip Gen {} {}", i, name), queue, 0u,
20 [=](PassHandle self, Renderer* r)
21 {
22 auto sampler = renderer->CreateSampler(samplerDesc);
23 r->BindTextureSampler(self, sampler, "sampler");
24 r->BindShader(self, RHIShaderStageBits::Compute, "csMain", "data/shaders/CSMipGeneration.spv");
25 if (i == 0)
26 r->BindTextureSRV(
27 self, src, "srcTexture", RHIPipelineStageBits::ComputeShader,
28 {
29 .format = srcFormat,
30 .range = RHITextureSubresourceRange::Create(srcAspect, 0, 1, layer, 1)
31 });
32 else
33 r->BindTextureSRV(
34 self, dst, "srcTexture", RHIPipelineStageBits::ComputeShader,
35 {
36 .format = dstFormat,
37 .range = RHITextureSubresourceRange::Create(dstAspect, i - 1, 1, layer, 1)
38 });
39 r->BindTextureUAV(
40 self, dst, "dstTexture", RHIPipelineStageBits::ComputeShader,
41 {
42 .format = dstFormat,
43 .range = RHITextureSubresourceRange::Create(dstAspect, i, 1, layer, 1)
44 });
45 r->BindPushConstant(self, RHIShaderStageBits::Compute, 0, sizeof(float2));
46 },
47 [=](PassHandle self, Renderer* r, RHICommandList* cmd)
48 {
49 RHITexture* dstTex = r->DerefResource(dst).Get<RHITexture*>();
50 RHIExtent3D extent = dstTex->mDesc.extent;
51 r->CmdSetPipeline(self,cmd);
52 uint32_t w = std::max(1u, extent.x >> i);
53 uint32_t h = std::max(1u, extent.y >> i);
54 r->CmdSetPushConstant(self, cmd, RHIShaderStageBits::Compute, 0, float2{w,h});
55 r->CmdDispatch(self, cmd, {w,h,1});
56 });
57 }
58 }
59} // namespace Foundation::Rendering
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:78
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:55
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
RHIDeviceQueueType
Definition Common.hpp:107
RHIResourceFormat
Definition Common.hpp:20
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
size_t ResourceHandle
Definition RenderPass.hpp:11
size_t PassHandle
Definition RenderPass.hpp:10
Definition CSClearBuffer.hpp:5
void createCSMipGenerationPasses(Renderer *renderer, StringView name, RHIDeviceQueueType queue, ResourceHandle src, ResourceHandle dst, RHIExtent2D srcExtent, RHITextureAspectFlagBits srcAspect, RHIResourceFormat srcFormat, RHITextureAspectFlagBits dstAspect, RHIResourceFormat dstFormat, uint32_t maxMips=16, uint32_t layer=0, RHIDeviceSampler::SamplerDesc samplerDesc={})
Definition CSMipGeneration.hpp:6
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:148