MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / draw

Method draw

framework/rendering/postprocessing_renderpass.cpp:125–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void PostProcessingSubpass::draw(vkb::core::CommandBufferC &command_buffer)
126{
127 // Get shaders from cache
128 auto &resource_cache = command_buffer.get_device().get_resource_cache();
129 auto &vert_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, get_vertex_shader());
130 auto &frag_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, get_fragment_shader(), fs_variant);
131
132 std::vector<ShaderModule *> shader_modules{&vert_shader_module, &frag_shader_module};
133
134 // Create pipeline layout and bind it
135 auto &pipeline_layout = resource_cache.request_pipeline_layout(shader_modules);
136 command_buffer.bind_pipeline_layout(pipeline_layout);
137
138 // Disable culling
139 vkb::rendering::RasterizationStateC rasterization_state;
140 rasterization_state.cull_mode = VK_CULL_MODE_NONE;
141 command_buffer.set_rasterization_state(rasterization_state);
142
143 auto &render_target = *parent->draw_render_target;
144 const auto &target_views = render_target.get_views();
145 const uint32_t n_input_attachments = static_cast<uint32_t>(get_input_attachments().size());
146
147 if (parent->uniform_buffer_alloc != nullptr)
148 {
149 // Bind buffer to set = 0, binding = 0
150 auto &uniform_alloc = *parent->uniform_buffer_alloc;
151 command_buffer.bind_buffer(uniform_alloc.get_buffer(), uniform_alloc.get_offset(), uniform_alloc.get_size(), 0, 0, 0);
152 }
153
154 const auto &bindings = pipeline_layout.get_descriptor_set_layout(0);
155
156 // Bind subpass inputs to set = 0, binding = <according to name>
157 for (const auto &it : input_attachments)
158 {
159 if (auto layout_binding = bindings.get_layout_binding(it.first))
160 {
161 assert(it.second < target_views.size());
162 command_buffer.bind_input(target_views[it.second], 0, layout_binding->binding, 0);
163 }
164 }
165
166 // Bind samplers to set = 0, binding = <according to name>
167 for (const auto &it : sampled_images)
168 {
169 if (auto layout_binding = bindings.get_layout_binding(it.first))
170 {
171 const auto &view = it.second.get_image_view(render_target);
172
173 // Get the properties for the image format. We need to check whether a linear sampler is valid.
174 const VkFormatProperties fmtProps = get_render_context().get_device().get_gpu().get_format_properties(view.get_format());
175 bool has_linear_filter = (fmtProps.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
176
177 const auto &sampler = it.second.get_sampler() ? *it.second.get_sampler() :
178 (has_linear_filter ? *parent->default_sampler : *parent->default_sampler_nearest);
179
180 command_buffer.bind_image(view, sampler, 0, layout_binding->binding, 0);
181 }
182 }

Callers 1

default_draw_funcMethod · 0.45

Calls 15

bind_pipeline_layoutMethod · 0.80
sizeMethod · 0.80
get_bufferMethod · 0.80
get_offsetMethod · 0.80
get_format_propertiesMethod · 0.80
push_constantsMethod · 0.80
emptyMethod · 0.80
allocate_bufferMethod · 0.80
end_render_passMethod · 0.80
bind_bufferMethod · 0.45

Tested by

no test coverage detected