30 "Cannot create pipeline without shader");
38 const auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
39 for (
const auto& binding : descriptor_bindings) {
40 unified_bindings[{ binding.set, binding.binding }] = binding;
44 auto key = std::make_pair(binding.set, binding.binding);
45 if (unified_bindings.find(key) == unified_bindings.end()) {
48 .binding = binding.binding,
56 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
57 for (
const auto& [key, binding] : unified_bindings) {
58 bindings_by_set[binding.set].push_back(binding);
61 std::vector<std::vector<Portal::Graphics::DescriptorBindingInfo>> descriptor_sets;
63 descriptor_sets.reserve(bindings_by_set.size());
64 for (
const auto& [set_index, set_bindings] : bindings_by_set) {
65 descriptor_sets.push_back(set_bindings);
75 "Failed to create compute pipeline");
82 "Compute pipeline created (ID: {}, {} descriptor sets, {} bytes push constants)",
90 "Cannot allocate descriptor sets without pipeline");
102 "Failed to allocate descriptor sets");
138 std::function<std::array<uint32_t, 3>(
const std::shared_ptr<VKBuffer>&)> calculator)
149 case DispatchMode::MANUAL:
152 case DispatchMode::ELEMENT_COUNT: {
153 uint64_t element_count = 0;
154 const auto& dimensions = buffer->get_dimensions();
156 if (!dimensions.empty()) {
157 element_count = dimensions[0].size;
159 element_count = buffer->get_size_bytes() /
sizeof(float);
162 auto groups_x =
static_cast<uint32_t
>(
164 return { groups_x, 1, 1 };
167 case DispatchMode::BUFFER_SIZE: {
168 uint64_t size_bytes = buffer->get_size_bytes();
169 auto groups_x =
static_cast<uint32_t
>(
171 return { groups_x, 1, 1 };
174 case DispatchMode::CUSTOM:
189 "Cannot dispatch without pipeline and descriptors");
195 "Descriptor sets not initialized");
209 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
210 if (!descriptor_bindings.empty()) {
211 for (
const auto& binding : descriptor_bindings) {
214 "Descriptor set index {} out of range", binding.set);
218 foundry.update_descriptor_buffer(
222 binding.buffer_info.buffer,
223 binding.buffer_info.offset,
224 binding.buffer_info.range);
235 if (!push_data.empty()) {
236 compute_press.push_constants(
241 compute_press.dispatch(cmd_id, dispatch_size[0], dispatch_size[1], dispatch_size[2]);
245 foundry.buffer_barrier(
247 buffer->get_buffer(),
248 vk::AccessFlagBits::eShaderWrite,
249 vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eTransferRead,
250 vk::PipelineStageFlagBits::eComputeShader,
251 vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eTransfer);
253 foundry.submit_and_wait(cmd_id);
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void set_workgroup_size(uint32_t x, uint32_t y=1, uint32_t z=1)
Set workgroup size (should match shader local_size)
ShaderDispatchConfig m_dispatch_config
void initialize_descriptors(const std::shared_ptr< VKBuffer > &buffer) override
void execute_shader(const std::shared_ptr< VKBuffer > &buffer) override
ComputeProcessor(const std::string &shader_path, uint32_t workgroup_x=256)
Construct processor with shader path.
void initialize_pipeline(const std::shared_ptr< VKBuffer > &buffer) override
Portal::Graphics::ComputePipelineID m_pipeline_id
void set_dispatch_mode(ShaderDispatchConfig::DispatchMode mode)
Set dispatch mode.
void set_manual_dispatch(uint32_t x, uint32_t y=1, uint32_t z=1)
Set manual dispatch group counts.
virtual std::array< uint32_t, 3 > calculate_dispatch_size(const std::shared_ptr< VKBuffer > &buffer)
Calculate dispatch size from buffer.
void set_custom_dispatch(std::function< std::array< uint32_t, 3 >(const std::shared_ptr< VKBuffer > &)> calculator)
Set custom dispatch calculator.
Portal::Graphics::CommandBufferID m_last_command_buffer
std::unordered_map< std::string, std::shared_ptr< VKBuffer > > m_bound_buffers
Portal::Graphics::ShaderID m_shader_id
virtual void on_after_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called after each process callback.
virtual void on_descriptors_created()
Called after descriptor sets are created.
size_t resolve_push_constant_size(const std::shared_ptr< VKBuffer > &buffer) const
Byte width of this processor's push constant block, extended to cover any fragment staged on the buff...
virtual void update_descriptors(const std::shared_ptr< VKBuffer > &buffer)
virtual bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called before each process callback.
virtual void on_pipeline_created(Portal::Graphics::ComputePipelineID pipeline_id)
Called after pipeline is created.
std::shared_ptr< VKBuffer > m_last_processed_buffer
virtual void on_before_descriptors_create()
Called before descriptor sets are created.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
std::vector< uint8_t > resolve_push_constants(const std::shared_ptr< VKBuffer > &buffer) const
This processor's push constant data with buffer-staged fragments overlaid at their declared offsets.
Abstract base class for shader-based buffer processing.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr ShaderID INVALID_SHADER
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr ComputePipelineID INVALID_COMPUTE_PIPELINE
MAYAFLUX_API ComputePress & get_compute_press()
std::unordered_map< std::string, ShaderBinding > bindings
size_t push_constant_size
enum MayaFlux::Buffers::ShaderDispatchConfig::DispatchMode mode
std::function< std::array< uint32_t, 3 >(const std::shared_ptr< VKBuffer > &)> custom_calculator
@ CUSTOM
User-provided calculation function.
@ MANUAL
Use explicit group counts.
uint32_t workgroup_x
Workgroup size X (should match shader)
std::array< uint32_t, 3 > workgroup_size
Complete declarative description of a generated compute shader.