Skip to content

Commit 4d7fae9

Browse files
committed
Manage MASK/non-MASK variants of prepass pipelines with NTTP.
1 parent cd4bc5a commit 4d7fae9

8 files changed

+454
-464
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ target_sources(vk-gltf-viewer PRIVATE
196196
interface/vulkan/pipeline/InverseToneMappingRenderPipeline.cppm
197197
interface/vulkan/pipeline/JumpFloodComputePipeline.cppm
198198
interface/vulkan/pipeline/JumpFloodSeedRenderPipeline.cppm
199-
interface/vulkan/pipeline/MaskJumpFloodSeedRenderPipeline.cppm
200-
interface/vulkan/pipeline/MaskMultiNodeMousePickingRenderPipeline.cppm
201-
interface/vulkan/pipeline/MaskNodeIndexRenderPipeline.cppm
202199
interface/vulkan/pipeline/MousePickingRenderPipeline.cppm
203200
interface/vulkan/pipeline/MultiNodeMousePickingRenderPipeline.cppm
204201
interface/vulkan/pipeline/NodeIndexRenderPipeline.cppm

interface/vulkan/SharedData.cppm

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export import vk_gltf_viewer.vulkan.Gpu;
2121
export import vk_gltf_viewer.vulkan.pipeline.BloomApplyRenderPipeline;
2222
export import vk_gltf_viewer.vulkan.pipeline.InverseToneMappingRenderPipeline;
2323
export import vk_gltf_viewer.vulkan.pipeline.JumpFloodComputePipeline;
24-
import vk_gltf_viewer.vulkan.pipeline.JumpFloodSeedRenderPipeline;
25-
import vk_gltf_viewer.vulkan.pipeline.MaskJumpFloodSeedRenderPipeline;
26-
import vk_gltf_viewer.vulkan.pipeline.MaskMultiNodeMousePickingRenderPipeline;
27-
import vk_gltf_viewer.vulkan.pipeline.MaskNodeIndexRenderPipeline;
24+
export import vk_gltf_viewer.vulkan.pipeline.JumpFloodSeedRenderPipeline;
2825
export import vk_gltf_viewer.vulkan.pipeline.MousePickingRenderPipeline;
2926
import vk_gltf_viewer.vulkan.pipeline.MultiNodeMousePickingRenderPipeline;
3027
import vk_gltf_viewer.vulkan.pipeline.NodeIndexRenderPipeline;
@@ -41,6 +38,13 @@ export import vk_gltf_viewer.vulkan.render_pass.Scene;
4138

4239
namespace vk_gltf_viewer::vulkan {
4340
export struct SharedData {
41+
template <bool Mask>
42+
struct PrepassPipelines {
43+
NodeIndexRenderPipeline<Mask> nodeIndexRenderPipeline;
44+
MultiNodeMousePickingRenderPipeline<Mask> multiNodeMousePickingRenderPipeline;
45+
JumpFloodSeedRenderPipeline<Mask> jumpFloodSeedRenderingPipeline;
46+
};
47+
4448
const Gpu &gpu;
4549

4650
// Buffer, image and image views and samplers.
@@ -123,20 +127,6 @@ namespace vk_gltf_viewer::vulkan {
123127

124128
void handleSwapchainResize(const vk::Extent2D &newSwapchainExtent, std::span<const vk::Image> newSwapchainImages);
125129
};
126-
127-
export template <>
128-
struct SharedData::PrepassPipelines<false> {
129-
NodeIndexRenderPipeline nodeIndexRenderPipeline;
130-
MultiNodeMousePickingRenderPipeline multiNodeMousePickingRenderPipeline;
131-
JumpFloodSeedRenderPipeline jumpFloodSeedRenderingPipeline;
132-
};
133-
134-
export template <>
135-
struct SharedData::PrepassPipelines<true> {
136-
MaskNodeIndexRenderPipeline nodeIndexRenderPipeline;
137-
MaskMultiNodeMousePickingRenderPipeline multiNodeMousePickingRenderPipeline;
138-
MaskJumpFloodSeedRenderPipeline jumpFloodSeedRenderingPipeline;
139-
};
140130
}
141131

142132
#if !defined(__GNUC__) || defined(__clang__)

interface/vulkan/pipeline/JumpFloodSeedRenderPipeline.cppm

Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import vku;
99

1010
import vk_gltf_viewer.shader.jump_flood_seed_frag;
1111
import vk_gltf_viewer.shader.jump_flood_seed_vert;
12+
import vk_gltf_viewer.shader_selector.mask_jump_flood_seed_frag;
13+
import vk_gltf_viewer.shader_selector.mask_jump_flood_seed_vert;
1214
export import vk_gltf_viewer.vulkan.pipeline.PrepassPipelineConfig;
1315
export import vk_gltf_viewer.vulkan.pipeline_layout.PrimitiveNoShading;
1416
import vk_gltf_viewer.vulkan.specialization_constants.SpecializationMap;
1517

1618
namespace vk_gltf_viewer::vulkan::inline pipeline {
17-
export class JumpFloodSeedRenderPipeline final : public vk::raii::Pipeline {
19+
export template <bool Mask>
20+
class JumpFloodSeedRenderPipeline;
21+
22+
export template <>
23+
class JumpFloodSeedRenderPipeline<false> final : public vk::raii::Pipeline {
1824
public:
1925
JumpFloodSeedRenderPipeline(
2026
const vk::raii::Device &device LIFETIMEBOUND,
@@ -27,6 +33,25 @@ namespace vk_gltf_viewer::vulkan::inline pipeline {
2733

2834
[[nodiscard]] static VertexShaderSpecialization getVertexShaderSpecialization(const PrepassPipelineConfig<false> &config) noexcept;
2935
};
36+
37+
export template <>
38+
class JumpFloodSeedRenderPipeline<true> final : public vk::raii::Pipeline {
39+
public:
40+
JumpFloodSeedRenderPipeline(
41+
const vk::raii::Device &device LIFETIMEBOUND,
42+
const pl::PrimitiveNoShading &pipelineLayout LIFETIMEBOUND,
43+
const PrepassPipelineConfig<true> &config
44+
);
45+
46+
private:
47+
struct VertexShaderSpecialization;
48+
struct FragmentShaderSpecialization;
49+
50+
[[nodiscard]] static std::array<int, 2> getVertexShaderVariants(const PrepassPipelineConfig<true> &config) noexcept;
51+
[[nodiscard]] static VertexShaderSpecialization getVertexShaderSpecialization(const PrepassPipelineConfig<true> &config) noexcept;
52+
[[nodiscard]] static std::array<int, 2> getFragmentShaderVariants(const PrepassPipelineConfig<true> &config) noexcept;
53+
[[nodiscard]] static FragmentShaderSpecialization getFragmentShaderSpecialization(const PrepassPipelineConfig<true> &config) noexcept;
54+
};
3055
}
3156

3257
#if !defined(__GNUC__) || defined(__clang__)
@@ -36,14 +61,16 @@ module :private;
3661
#define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
3762
#define LIFT(...) [](auto &&...xs) { return __VA_ARGS__(FWD(xs)...); }
3863

39-
struct vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline::VertexShaderSpecialization {
64+
// ----- JumpFloodSeedRenderPipeline<false> -----
65+
66+
struct vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<false>::VertexShaderSpecialization {
4067
std::uint32_t positionComponentType;
4168
vk::Bool32 positionNormalized;
4269
std::uint32_t positionMorphTargetCount;
4370
std::uint32_t skinAttributeCount;
4471
};
4572

46-
vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline::JumpFloodSeedRenderPipeline(
73+
vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<false>::JumpFloodSeedRenderPipeline(
4774
const vk::raii::Device &device,
4875
const pl::PrimitiveNoShading &pipelineLayout,
4976
const PrepassPipelineConfig<false> &config
@@ -87,11 +114,127 @@ vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline::JumpFloodSeedRend
87114
}.get() };
88115
}() } { }
89116

90-
[[nodiscard]] vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline::VertexShaderSpecialization vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline::getVertexShaderSpecialization(const PrepassPipelineConfig<false> &config) noexcept {
117+
[[nodiscard]] auto vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<false>::getVertexShaderSpecialization(
118+
const PrepassPipelineConfig<false> &config
119+
) noexcept -> VertexShaderSpecialization {
91120
return {
92121
.positionComponentType = getGLComponentType(config.positionComponentType),
93122
.positionNormalized = config.positionNormalized,
94123
.positionMorphTargetCount = config.positionMorphTargetCount,
95124
.skinAttributeCount = config.skinAttributeCount,
96125
};
97-
}
126+
}
127+
128+
// ----- JumpFloodSeedRenderPipeline<true> -----
129+
130+
struct vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::VertexShaderSpecialization {
131+
std::uint32_t positionComponentType;
132+
vk::Bool32 positionNormalized;
133+
std::uint32_t baseColorTexcoordComponentType;
134+
vk::Bool32 baseColorTexcoordNormalized;
135+
std::uint32_t color0ComponentType;
136+
std::uint32_t positionMorphTargetCount;
137+
std::uint32_t skinAttributeCount;
138+
};
139+
140+
struct vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::FragmentShaderSpecialization {
141+
vk::Bool32 useTextureTransform;
142+
};
143+
144+
vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::JumpFloodSeedRenderPipeline::JumpFloodSeedRenderPipeline(
145+
const vk::raii::Device &device,
146+
const pl::PrimitiveNoShading &pipelineLayout,
147+
const PrepassPipelineConfig<true> &config
148+
) : Pipeline { [&] -> Pipeline {
149+
return { device, nullptr, vk::StructureChain {
150+
vku::getDefaultGraphicsPipelineCreateInfo(
151+
createPipelineStages(
152+
device,
153+
vku::Shader {
154+
std::apply(LIFT(shader_selector::mask_jump_flood_seed_vert), getVertexShaderVariants(config)),
155+
vk::ShaderStageFlagBits::eVertex,
156+
vku::unsafeAddress(vk::SpecializationInfo {
157+
SpecializationMap<VertexShaderSpecialization>::value,
158+
vku::unsafeProxy(getVertexShaderSpecialization(config)),
159+
}),
160+
},
161+
vku::Shader {
162+
std::apply(LIFT(shader_selector::mask_jump_flood_seed_frag), getFragmentShaderVariants(config)),
163+
vk::ShaderStageFlagBits::eFragment,
164+
vku::unsafeAddress(vk::SpecializationInfo {
165+
SpecializationMap<FragmentShaderSpecialization>::value,
166+
vku::unsafeProxy(getFragmentShaderSpecialization(config)),
167+
}),
168+
}).get(),
169+
*pipelineLayout, 1, true)
170+
.setPInputAssemblyState(vku::unsafeAddress(vk::PipelineInputAssemblyStateCreateInfo {
171+
{},
172+
config.topologyClass.value_or(vk::PrimitiveTopology::eTriangleList),
173+
}))
174+
.setPDepthStencilState(vku::unsafeAddress(vk::PipelineDepthStencilStateCreateInfo {
175+
{},
176+
true, true, vk::CompareOp::eGreater, // Use reverse Z.
177+
}))
178+
.setPDynamicState(vku::unsafeAddress(vk::PipelineDynamicStateCreateInfo {
179+
{},
180+
vku::unsafeProxy({
181+
vk::DynamicState::eViewport,
182+
vk::DynamicState::eScissor,
183+
vk::DynamicState::ePrimitiveTopology,
184+
vk::DynamicState::eCullMode,
185+
}),
186+
})),
187+
vk::PipelineRenderingCreateInfo {
188+
{},
189+
vku::unsafeProxy(vk::Format::eR16G16Uint),
190+
vk::Format::eD32Sfloat,
191+
}
192+
}.get() };
193+
}() } { }
194+
195+
std::array<int, 2> vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::getVertexShaderVariants(
196+
const PrepassPipelineConfig<true> &config
197+
) noexcept {
198+
return {
199+
config.baseColorTexcoordComponentTypeAndNormalized.has_value(),
200+
config.color0AlphaComponentType.has_value(),
201+
};
202+
}
203+
204+
auto vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::getVertexShaderSpecialization(
205+
const PrepassPipelineConfig<true> &config
206+
) noexcept -> VertexShaderSpecialization {
207+
VertexShaderSpecialization result {
208+
.positionComponentType = getGLComponentType(config.positionComponentType),
209+
.positionNormalized = config.positionNormalized,
210+
.color0ComponentType = config.color0AlphaComponentType.transform(fastgltf::getGLComponentType).value_or(0U),
211+
.positionMorphTargetCount = config.positionMorphTargetCount,
212+
.skinAttributeCount = config.skinAttributeCount,
213+
};
214+
215+
if (config.baseColorTexcoordComponentTypeAndNormalized) {
216+
result.baseColorTexcoordComponentType = getGLComponentType(config.baseColorTexcoordComponentTypeAndNormalized->first);
217+
result.baseColorTexcoordNormalized = config.baseColorTexcoordComponentTypeAndNormalized->second;
218+
}
219+
220+
return result;
221+
}
222+
223+
std::array<int, 2> vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::getFragmentShaderVariants(
224+
const PrepassPipelineConfig<true> &config
225+
) noexcept {
226+
return {
227+
config.baseColorTexcoordComponentTypeAndNormalized.has_value(),
228+
config.color0AlphaComponentType.has_value(),
229+
};
230+
}
231+
232+
auto vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>::getFragmentShaderSpecialization(
233+
const PrepassPipelineConfig<true> &config
234+
) noexcept -> FragmentShaderSpecialization {
235+
return { config.useTextureTransform };
236+
}
237+
238+
// Explicit template instantiations.
239+
extern template class vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<false>;
240+
extern template class vk_gltf_viewer::vulkan::pipeline::JumpFloodSeedRenderPipeline<true>;

interface/vulkan/pipeline/MaskJumpFloodSeedRenderPipeline.cppm

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)