24 std::unordered_map<size_t, std::vector<uint8_t>>
aux;
99 void set_push_constants(
const void* data,
size_t bytes);
105 template <
typename T>
108 set_push_constants(&data,
sizeof(T));
118 template <
typename T>
121 if (
index >= m_binding_data.size())
122 m_binding_data.resize(
index + 1);
123 auto& slot = m_binding_data[
index];
124 slot.resize(data.size_bytes());
125 std::memcpy(slot.data(), data.data(), data.size_bytes());
128 template <
typename T>
131 set_binding_data(
index, std::span<const T>(data));
149 m_resources.ensure_shared_buffer(set, binding_index, element_count, element_type, usage_hint);
152 void upload_shared_raw(uint32_t set,
size_t binding_index,
const uint8_t* data,
size_t byte_size)
154 m_resources.upload_shared_raw(set, binding_index, data, byte_size);
157 void download_shared(uint32_t set,
size_t binding_index,
void* dest,
size_t byte_size)
159 m_resources.download_shared(set, binding_index, dest, byte_size);
165 return m_resources.make_shared_buffer_hazard(spec);
175 void set_output_size(
size_t index,
size_t byte_size);
181 bool ensure_gpu_ready();
186 [[nodiscard]]
bool is_gpu_ready()
const;
198 [[nodiscard]] std::shared_ptr<Core::VKImage> get_output_image(
size_t binding_index)
const;
207 void download_binding(
size_t index,
void* dest,
size_t byte_size);
225 m_gpu_config = std::move(config);
226 update_dispatch_key_cache();
242 void stage_image_at(
size_t binding_index,
243 std::shared_ptr<Core::VKImage>
image,
245 vk::Sampler sampler =
nullptr);
256 return m_resources.shared_buffer_handle(set, binding_index);
270 [[nodiscard]]
const std::string&
dispatch_key()
const {
return m_cached_dispatch_key; }
278 [[nodiscard]]
virtual std::vector<GpuBufferBinding> declare_buffer_bindings()
const;
284 virtual void on_before_gpu_dispatch(
285 const std::vector<std::vector<double>>&
channels,
294 virtual void prepare_gpu_inputs(
295 const std::vector<std::vector<double>>&
channels,
307 [[nodiscard]]
virtual std::array<uint32_t, 3> calculate_dispatch_size(
308 size_t total_elements,
317 void stage_passthrough(
size_t binding_index,
const void* data,
size_t byte_size);
335 void stage_native_bytes(
size_t binding_index,
const void* data,
size_t byte_size);
348 const std::vector<std::vector<double>>&
channels,
361 const std::vector<std::vector<double>>&
channels,
379 const std::vector<std::vector<double>>&
channels,
397 const std::vector<std::vector<double>>&
channels,
417 void dispatch_core_dependency(
const std::vector<DependencyStage>& stages);
444 const std::vector<DependencyStage>& stages);
455 return m_last_effective_element_count;
467 [[nodiscard]] std::vector<float> readback_primary(
size_t float_count);
483 void flatten_channels_to_staging(
484 const std::vector<std::vector<double>>&
channels,
500 void flatten_native_variants_to_staging(
501 const std::vector<Kakshya::DataVariant>& variants,
504 [[nodiscard]]
size_t find_first_output_index()
const;
505 [[nodiscard]]
size_t largest_binding_data_element_count()
const;
516 std::shared_ptr<Core::VKImage>
image;
525 std::vector<std::array<uint32_t, 3>>
groups;
527 std::vector<std::vector<Portal::Graphics::HazardResource>>
hazards;
528 std::vector<Portal::Graphics::IndirectDispatch>
indirect;
531 [[nodiscard]]
DependencyPlan prepare_dependency(
const std::vector<DependencyStage>& stages);
536 size_t m_last_effective_element_count {};
543 void update_dispatch_key_cache();
544 void bind_all_descriptors();
std::vector< ImageBinding > m_image_bindings
GpuResourceManager m_resources
std::vector< uint8_t > m_native_staging_bytes
Native-typed staging buffer.
GpuComputeConfig m_gpu_config
GpuDispatchCore(GpuDispatchCore &&)=delete
std::string m_cached_dispatch_key
Portal::Graphics::HazardResource shared_buffer_hazard(const GpuBufferBinding &spec) const
void ensure_shared_buffer(uint32_t set, size_t binding_index, size_t element_count, GpuBufferBinding::ElementType element_type, Portal::Graphics::BufferUsageHint usage_hint=Portal::Graphics::BufferUsageHint::COMPUTE_STORAGE)
Ensure a shared storage buffer of at least element_count elements exists at (set, binding_index).
const std::string & dispatch_key() const
The key used for this context's GpuResourceManager unit.
void download_shared(uint32_t set, size_t binding_index, void *dest, size_t byte_size)
std::vector< uint8_t > m_push_constants
void upload_shared_raw(uint32_t set, size_t binding_index, const uint8_t *data, size_t byte_size)
void set_binding_data(size_t index, const std::vector< T > &data)
std::vector< std::vector< uint8_t > > m_binding_data
Portal::Graphics::GpuBufferHandle shared_buffer_handle(uint32_t set, size_t binding_index) const
Non-owning view of the shared buffer at (set, binding_index).
void swap_shader(GpuComputeConfig config)
Switch which shader subsequent dispatch_core calls target.
std::vector< GpuBufferBinding > m_bindings
std::vector< size_t > m_output_size_overrides
virtual ~GpuDispatchCore()=default
void set_push_constants(const T &data)
Typed convenience wrapper for set_push_constants(const void*, size_t).
size_t last_effective_element_count() const
Effective element count used by the last dispatch_core or dispatch_core_async call.
GpuDispatchCore & operator=(GpuDispatchCore &&)=delete
std::vector< std::vector< uint8_t > > m_passthrough_bytes
std::vector< float > m_staging_floats
GpuDispatchCore(const GpuDispatchCore &)=delete
GpuDispatchCore & operator=(const GpuDispatchCore &)=delete
void set_binding_data(size_t index, std::span< const T > data)
Pre-stage typed data for a specific binding slot, bypassing the default channel-flattening path in pr...
Non-template base that owns all type-independent GPU dispatch logic.
Encapsulates all Vulkan resource lifecycle behind Portal facades.
BufferUsageHint
Semantic usage hint for buffer allocation and memory properties.
ElementType
Element type the shader expects in this binding.
Declares a single storage buffer or image binding a compute shader expects.
Non-owning view of a GPU storage buffer produced by a compute path.
Plain-data description of the compute shader to dispatch.
One resource this stage's dispatch reads/writes that a later stage in the sequence depends on,...
Dimensions, modality, source type, and optional Composite field schema.
std::optional< IndirectGroupsSource > indirect_groups
Shared buffer holding this stage's workgroup counts, when they come from GPU data.
std::function< void(GpuDispatchCore &)> stage_fn
std::function< std::vector< Portal::Graphics::HazardResource >(GpuDispatchCore &)> hazard_fn
std::optional< std::array< uint32_t, 3 > > explicit_groups
One stage in a dispatch_core_dependency call.
Context information controlling how a compute operation executes.
std::unordered_map< size_t, std::vector< uint8_t > > aux
std::vector< float > primary
Erased output of a GPU dispatch: reconstructed float data plus any raw auxiliary outputs keyed by bin...
std::vector< std::vector< uint8_t > > push_constants
std::vector< std::string > keys
std::vector< Portal::Graphics::IndirectDispatch > indirect
std::vector< std::vector< Portal::Graphics::HazardResource > > hazards
std::vector< std::array< uint32_t, 3 > > groups
std::shared_ptr< Core::VKImage > image
Location of GPU-resident workgroup counts for a DependencyStage.