Skip to content

Commit 478f52c

Browse files
authored
Introduce unified version of vkb::GeometrySubpass into vkb::rendering::subpasses::GeometrySubpass<bindingType> (#1451)
1 parent 85d8416 commit 478f52c

28 files changed

Lines changed: 798 additions & 432 deletions

framework/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ set(RENDERING_SUBPASSES_FILES
130130
rendering/subpasses/hpp_forward_subpass.h
131131
# Source files
132132
rendering/subpasses/forward_subpass.cpp
133-
rendering/subpasses/lighting_subpass.cpp
134-
rendering/subpasses/geometry_subpass.cpp)
133+
rendering/subpasses/lighting_subpass.cpp)
135134

136135
set(SCENE_GRAPH_FILES
137136
# Header Files

framework/core/hpp_descriptor_set_layout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class HPPDescriptorSetLayout : private vkb::DescriptorSetLayout
6464
reinterpret_cast<vk::DescriptorSetLayoutBinding *>(vkb::DescriptorSetLayout::get_layout_binding(binding_index).release()));
6565
}
6666

67+
std::unique_ptr<vk::DescriptorSetLayoutBinding> get_layout_binding(std::string const &name) const
68+
{
69+
return std::unique_ptr<vk::DescriptorSetLayoutBinding>(
70+
reinterpret_cast<vk::DescriptorSetLayoutBinding *>(vkb::DescriptorSetLayout::get_layout_binding(name).release()));
71+
}
72+
6773
vk::DescriptorBindingFlagsEXT get_layout_binding_flag(const uint32_t binding_index) const
6874
{
6975
return static_cast<vk::DescriptorBindingFlagsEXT>(vkb::DescriptorSetLayout::get_layout_binding_flag(binding_index));

framework/core/hpp_shader_module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct HPPShaderResource
8484
class HPPShaderSource : private vkb::ShaderSource
8585
{
8686
public:
87+
HPPShaderSource() = default;
8788
HPPShaderSource(const std::string &filename) :
8889
vkb::ShaderSource(filename)
8990
{}
@@ -96,6 +97,7 @@ class HPPShaderModule : private vkb::ShaderModule
9697
{
9798
public:
9899
using vkb::ShaderModule::get_id;
100+
using vkb::ShaderModule::set_resource_mode;
99101

100102
public:
101103
HPPShaderModule(vkb::core::DeviceCpp &device,

framework/rendering/subpass.h

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
namespace vkb
3131
{
3232
class RenderTarget;
33-
class ShaderSource;
3433

3534
namespace core
3635
{
@@ -83,12 +82,12 @@ class Subpass
8382
using ResolveModeFlagBitsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::ResolveModeFlagBits, VkResolveModeFlagBits>::type;
8483
using SampleCountflagBitsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::SampleCountFlagBits, VkSampleCountFlagBits>::type;
8584

86-
using DepthStencilStateType =
87-
typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPDepthStencilState, vkb::DepthStencilState>::type;
88-
using RenderTargetType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPRenderTarget, vkb::RenderTarget>::type;
85+
using DepthStencilStateType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPDepthStencilState, vkb::DepthStencilState>::type;
86+
using RenderTargetType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPRenderTarget, vkb::RenderTarget>::type;
87+
using ShaderSourceType = typename std::conditional<bindingType == BindingType::Cpp, vkb::core::HPPShaderSource, vkb::ShaderSource>::type;
8988

9089
public:
91-
Subpass(vkb::rendering::RenderContext<bindingType> &render_context, ShaderSource &&vertex_shader, ShaderSource &&fragment_shader);
90+
Subpass(vkb::rendering::RenderContext<bindingType> &render_context, ShaderSourceType &&vertex_shader, ShaderSourceType &&fragment_shader);
9291

9392
Subpass(const Subpass &) = delete;
9493
Subpass(Subpass &&) = default;
@@ -124,14 +123,14 @@ class Subpass
124123
ResolveModeFlagBitsType get_depth_stencil_resolve_mode() const;
125124
DepthStencilStateType &get_depth_stencil_state();
126125
const bool &get_disable_depth_stencil_attachment() const;
127-
const ShaderSource &get_fragment_shader() const;
126+
const ShaderSourceType &get_fragment_shader() const;
128127
const std::vector<uint32_t> &get_input_attachments() const;
129128
LightingState<bindingType> &get_lighting_state();
130129
const std::vector<uint32_t> &get_output_attachments() const;
131130
RenderContext<bindingType> &get_render_context();
132131
std::unordered_map<std::string, ShaderResourceMode> const &get_resource_mode_map() const;
133132
SampleCountflagBitsType get_sample_count() const;
134-
const ShaderSource &get_vertex_shader() const;
133+
const ShaderSourceType &get_vertex_shader() const;
135134
void set_color_resolve_attachments(std::vector<uint32_t> const &color_resolve);
136135
void set_debug_name(const std::string &name);
137136
void set_disable_depth_stencil_attachment(bool disable_depth_stencil);
@@ -148,6 +147,14 @@ class Subpass
148147
*/
149148
void update_render_target_attachments(RenderTargetType &render_target);
150149

150+
protected:
151+
vkb::rendering::HPPDepthStencilState get_depth_stencil_state_impl() const;
152+
vkb::core::HPPShaderSource const &get_fragment_shader_impl() const;
153+
LightingStateCpp &get_lighting_state_impl();
154+
vk::SampleCountFlagBits get_sample_count_impl() const;
155+
vkb::rendering::RenderContextCpp &get_render_context_impl();
156+
vkb::core::HPPShaderSource const &get_vertex_shader_impl() const;
157+
151158
private:
152159
/// Default to no color resolve attachments
153160
std::vector<uint32_t> color_resolve_attachments = {};
@@ -175,7 +182,7 @@ class Subpass
175182
/// The structure containing all the requested render-ready lights for the scene
176183
LightingStateCpp lighting_state{};
177184

178-
ShaderSource fragment_shader;
185+
vkb::core::HPPShaderSource fragment_shader;
179186

180187
/// Default to no input attachments
181188
std::vector<uint32_t> input_attachments = {};
@@ -188,8 +195,8 @@ class Subpass
188195
// A map of shader resource names and the mode of constant data
189196
std::unordered_map<std::string, ShaderResourceMode> resource_mode_map;
190197

191-
vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1};
192-
ShaderSource vertex_shader;
198+
vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1};
199+
vkb::core::HPPShaderSource vertex_shader;
193200
};
194201

195202
using SubpassC = Subpass<vkb::BindingType::C>;
@@ -206,12 +213,20 @@ inline glm::mat4 vulkan_style_projection(const glm::mat4 &proj)
206213

207214
template <vkb::BindingType bindingType>
208215
inline Subpass<bindingType>::Subpass(vkb::rendering::RenderContext<bindingType> &render_context,
209-
ShaderSource &&vertex_source,
210-
ShaderSource &&fragment_source) :
211-
render_context{reinterpret_cast<vkb::rendering::RenderContextCpp &>(render_context)},
212-
vertex_shader{std::move(vertex_source)},
213-
fragment_shader{std::move(fragment_source)}
216+
ShaderSourceType &&vertex_source,
217+
ShaderSourceType &&fragment_source) :
218+
render_context{reinterpret_cast<vkb::rendering::RenderContextCpp &>(render_context)}
214219
{
220+
if constexpr (bindingType == vkb::BindingType::Cpp)
221+
{
222+
vertex_shader = std::move(vertex_source);
223+
fragment_shader = std::move(fragment_source);
224+
}
225+
else
226+
{
227+
vertex_shader = std::move(reinterpret_cast<vkb::core::HPPShaderSource &&>(vertex_source));
228+
fragment_shader = std::move(reinterpret_cast<vkb::core::HPPShaderSource &&>(fragment_source));
229+
}
215230
}
216231

217232
template <vkb::BindingType bindingType>
@@ -263,18 +278,25 @@ inline typename Subpass<bindingType>::SampleCountflagBitsType Subpass<bindingTyp
263278
{
264279
if constexpr (bindingType == vkb::BindingType::Cpp)
265280
{
266-
return sample_count;
281+
return get_sample_count_impl();
267282
}
268283
else
269284
{
270-
return static_cast<VkSampleCountFlagBits>(sample_count);
285+
return static_cast<VkSampleCountFlagBits>(get_sample_count_impl());
271286
}
272287
}
273288

274289
template <vkb::BindingType bindingType>
275-
inline const ShaderSource &Subpass<bindingType>::get_vertex_shader() const
290+
inline const typename Subpass<bindingType>::ShaderSourceType &Subpass<bindingType>::get_vertex_shader() const
276291
{
277-
return vertex_shader;
292+
if constexpr (bindingType == vkb::BindingType::Cpp)
293+
{
294+
return get_vertex_shader_impl();
295+
}
296+
else
297+
{
298+
return reinterpret_cast<vkb::ShaderSource const &>(get_vertex_shader_impl());
299+
}
278300
}
279301

280302
template <vkb::BindingType bindingType>
@@ -402,9 +424,16 @@ inline const bool &Subpass<bindingType>::get_disable_depth_stencil_attachment()
402424
}
403425

404426
template <vkb::BindingType bindingType>
405-
inline const ShaderSource &Subpass<bindingType>::get_fragment_shader() const
427+
inline const typename Subpass<bindingType>::ShaderSourceType &Subpass<bindingType>::get_fragment_shader() const
406428
{
407-
return fragment_shader;
429+
if constexpr (bindingType == vkb::BindingType::Cpp)
430+
{
431+
return get_fragment_shader_impl();
432+
}
433+
else
434+
{
435+
return reinterpret_cast<vkb::ShaderSource const &>(get_fragment_shader_impl());
436+
}
408437
}
409438

410439
template <vkb::BindingType bindingType>
@@ -475,5 +504,42 @@ inline void Subpass<bindingType>::update_render_target_attachments(RenderTargetT
475504
render_target.set_input_attachments(input_attachments);
476505
render_target.set_output_attachments(output_attachments);
477506
}
507+
508+
template <vkb::BindingType bindingType>
509+
inline vkb::core::HPPShaderSource const &Subpass<bindingType>::get_fragment_shader_impl() const
510+
{
511+
return fragment_shader;
512+
}
513+
514+
template <vkb::BindingType bindingType>
515+
inline vk::SampleCountFlagBits Subpass<bindingType>::get_sample_count_impl() const
516+
{
517+
return sample_count;
518+
}
519+
520+
template <vkb::BindingType bindingType>
521+
inline vkb::rendering::HPPDepthStencilState Subpass<bindingType>::get_depth_stencil_state_impl() const
522+
{
523+
return depth_stencil_state;
524+
}
525+
526+
template <vkb::BindingType bindingType>
527+
inline LightingStateCpp &Subpass<bindingType>::get_lighting_state_impl()
528+
{
529+
return lighting_state;
530+
}
531+
532+
template <vkb::BindingType bindingType>
533+
inline vkb::rendering::RenderContextCpp &Subpass<bindingType>::get_render_context_impl()
534+
{
535+
return render_context;
536+
}
537+
538+
template <vkb::BindingType bindingType>
539+
inline vkb::core::HPPShaderSource const &Subpass<bindingType>::get_vertex_shader_impl() const
540+
{
541+
return vertex_shader;
542+
}
543+
478544
} // namespace rendering
479545
} // namespace vkb

framework/rendering/subpasses/forward_subpass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ForwardSubpass::ForwardSubpass(
4343
void ForwardSubpass::prepare()
4444
{
4545
auto &device = get_render_context().get_device();
46-
for (auto &mesh : meshes)
46+
for (auto &mesh : get_meshes())
4747
{
4848
for (auto &sub_mesh : mesh->get_submeshes())
4949
{
@@ -56,7 +56,7 @@ void ForwardSubpass::prepare()
5656

5757
void ForwardSubpass::draw(vkb::core::CommandBufferC &command_buffer)
5858
{
59-
allocate_lights<ForwardLights>(scene.get_components<sg::Light>(), MAX_FORWARD_LIGHT_COUNT);
59+
allocate_lights<ForwardLights>(get_scene().get_components<sg::Light>(), MAX_FORWARD_LIGHT_COUNT);
6060
command_buffer.bind_lighting(get_lighting_state(), 0, 4);
6161

6262
GeometrySubpass::draw(command_buffer);

framework/rendering/subpasses/forward_subpass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct alignas(16) ForwardLights
4444
/**
4545
* @brief This subpass is responsible for rendering a Scene
4646
*/
47-
class ForwardSubpass : public GeometrySubpass
47+
class ForwardSubpass : public vkb::rendering::subpasses::GeometrySubpassC
4848
{
4949
public:
5050
/**

0 commit comments

Comments
 (0)