MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ execute_shader()

void MayaFlux::Buffers::ComputeProcessor::execute_shader ( const std::shared_ptr< VKBuffer > &  buffer)
overrideprivatevirtual

Implements MayaFlux::Buffers::ShaderProcessor.

Definition at line 186 of file ComputeProcessor.cpp.

187{
190 "Cannot dispatch without pipeline and descriptors");
191 return;
192 }
193
194 if (m_descriptor_set_ids.empty()) {
196 "Descriptor sets not initialized");
197 return;
198 }
199
200 auto& foundry = Portal::Graphics::get_shader_foundry();
201 auto& compute_press = Portal::Graphics::get_compute_press();
202
203 auto cmd_id = foundry.begin_commands(Portal::Graphics::ShaderFoundry::CommandBufferType::COMPUTE);
204
205 m_last_command_buffer = cmd_id;
207
208 compute_press.bind_pipeline(cmd_id, m_pipeline_id);
209
210 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
211 if (!descriptor_bindings.empty()) {
212 for (const auto& binding : descriptor_bindings) {
213 if (binding.set >= m_descriptor_set_ids.size()) {
215 "Descriptor set index {} out of range", binding.set);
216 continue;
217 }
218
219 foundry.update_descriptor_buffer(
220 m_descriptor_set_ids[binding.set],
221 binding.binding,
222 binding.type,
223 binding.buffer_info.buffer,
224 binding.buffer_info.offset,
225 binding.buffer_info.range);
226 }
227 }
228
229 if (!m_descriptor_set_ids.empty()) {
230 compute_press.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
231 }
232
233 const auto& staging = buffer->get_pipeline_context();
234 if (!staging.push_constant_staging.empty()) {
235 compute_press.push_constants(
236 cmd_id,
238 staging.push_constant_staging.data(),
239 staging.push_constant_staging.size());
240 } else if (!m_push_constant_data.empty()) {
241 compute_press.push_constants(
242 cmd_id,
245 m_push_constant_data.size());
246 }
247
248 on_before_execute(cmd_id, buffer);
249
250 auto dispatch_size = calculate_dispatch_size(buffer);
251 compute_press.dispatch(cmd_id, dispatch_size[0], dispatch_size[1], dispatch_size[2]);
252
253 on_after_execute(cmd_id, buffer);
254
255 foundry.buffer_barrier(
256 cmd_id,
257 buffer->get_buffer(),
258 vk::AccessFlagBits::eShaderWrite,
259 vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eTransferRead,
260 vk::PipelineStageFlagBits::eComputeShader,
261 vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eTransfer);
262
263 foundry.submit_and_wait(cmd_id);
264}
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
Portal::Graphics::ComputePipelineID m_pipeline_id
virtual std::array< uint32_t, 3 > calculate_dispatch_size(const std::shared_ptr< VKBuffer > &buffer)
Calculate dispatch size from buffer.
Portal::Graphics::CommandBufferID m_last_command_buffer
std::vector< uint8_t > m_push_constant_data
virtual void on_after_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called after each process callback.
virtual bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called before each process callback.
std::shared_ptr< VKBuffer > m_last_processed_buffer
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr ComputePipelineID INVALID_COMPUTE_PIPELINE
MAYAFLUX_API ComputePress & get_compute_press()

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, calculate_dispatch_size(), MayaFlux::Portal::Graphics::ShaderFoundry::COMPUTE, MayaFlux::Portal::Graphics::get_compute_press(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::INVALID_COMPUTE_PIPELINE, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, MayaFlux::Buffers::ShaderProcessor::m_last_command_buffer, MayaFlux::Buffers::ShaderProcessor::m_last_processed_buffer, m_pipeline_id, MayaFlux::Buffers::ShaderProcessor::m_push_constant_data, MF_ERROR, MF_RT_ERROR, MayaFlux::Buffers::ShaderProcessor::on_after_execute(), and MayaFlux::Buffers::ShaderProcessor::on_before_execute().

+ Here is the call graph for this function: