forked from KhronosGroup/Vulkan-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubpasses.h
More file actions
140 lines (113 loc) · 4.4 KB
/
subpasses.h
File metadata and controls
140 lines (113 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright (c) 2019-2020, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "rendering/render_pipeline.h"
#include "scene_graph/components/perspective_camera.h"
#include "vulkan_sample.h"
/**
* @brief The Subpasses sample shows how a significant amount of bandwidth
* (L2 cache ext reads and writes) can be saved, by using sub-passes instead
* of multiple render passes. In order to highlight the difference, it
* implements deferred rendering with and without sub-passes, giving the
* user the possibility to change some key settings.
*/
class Subpasses : public vkb::VulkanSample
{
public:
Subpasses();
bool prepare(vkb::Platform &platform) override;
void update(float delta_time) override;
virtual ~Subpasses() = default;
void draw_gui() override;
private:
virtual void prepare_render_context() override;
/**
* @brief Draws to a render target using the right pipeline based on the sample selection
* Not to be confused with `draw_renderpasses` which uses the bad practice
*/
virtual void draw_renderpass(vkb::CommandBuffer &command_buffer, vkb::RenderTarget &render_target) override;
/**
* @return A good pipeline
*/
std::unique_ptr<vkb::RenderPipeline> create_one_renderpass_two_subpasses();
/**
* @return A geometry render pass which should run first
*/
std::unique_ptr<vkb::RenderPipeline> create_geometry_renderpass();
/**
* @return A lighting render pass which should run second
*/
std::unique_ptr<vkb::RenderPipeline> create_lighting_renderpass();
/**
* @brief Draws using the good pipeline: one render pass with two subpasses
*/
void draw_subpasses(vkb::CommandBuffer &command_buffer, vkb::RenderTarget &render_target);
/**
* @brief Draws using the bad practice: two separate render passes
*/
void draw_renderpasses(vkb::CommandBuffer &command_buffer, vkb::RenderTarget &render_target);
std::unique_ptr<vkb::RenderTarget> create_render_target(vkb::core::Image &&swapchain_image);
/// Good pipeline with two subpasses within one render pass
std::unique_ptr<vkb::RenderPipeline> render_pipeline{};
/// 1. Bad pipeline with a geometry subpass in the first render pass
std::unique_ptr<vkb::RenderPipeline> geometry_render_pipeline{};
/// 2. Bad pipeline with a lighting subpass in the second render pass
std::unique_ptr<vkb::RenderPipeline> lighting_render_pipeline{};
vkb::sg::PerspectiveCamera *camera{};
/**
* @brief Struct that contains configurations for this sample
* with description, options, and current selected value
*/
struct Config
{
/**
* @brief Configurations type
*/
enum Type
{
RenderTechnique,
TransientAttachments,
GBufferSize
} type;
/// Used as label by the GUI
const char *description;
/// List of options to choose from
std::vector<const char *> options;
/// Index of the current selected option
int value;
};
uint16_t last_render_technique{0};
uint16_t last_transient_attachment{0};
uint16_t last_g_buffer_size{0};
VkFormat albedo_format{VK_FORMAT_R8G8B8A8_UNORM};
VkFormat normal_format{VK_FORMAT_A2B10G10R10_UNORM_PACK32};
VkImageUsageFlags rt_usage_flags{VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT};
std::vector<Config> configs = {
{/* config = */ Config::RenderTechnique,
/* description = */ "Render technique",
/* options = */ {"Subpasses", "Renderpasses"},
/* value = */ 0},
{/* config = */ Config::TransientAttachments,
/* description = */ "Transient attachments",
/* options = */ {"Enabled", "Disabled"},
/* value = */ 0},
{/* config = */ Config::GBufferSize,
/* description = */ "G-Buffer size",
/* options = */ {"128-bit", "More"},
/* value = */ 0}};
};
std::unique_ptr<vkb::VulkanSample> create_subpasses();