24 std::unordered_map<size_t, std::vector<uint8_t>>
aux;
78 void set_push_constants(
const void* data,
size_t bytes);
87 set_push_constants(&data,
sizeof(T));
100 if (index >= m_binding_data.size())
101 m_binding_data.resize(index + 1);
102 auto& slot = m_binding_data[index];
103 slot.resize(data.size_bytes());
104 std::memcpy(slot.data(), data.data(), data.size_bytes());
107 template <
typename T>
110 set_binding_data(index, std::span<const T>(data));
117 m_resources.ensure_shared_buffer(set, binding_index, element_count, element_type, usage_hint);
118 m_shared_bindings.insert({ set, binding_index });
121 void upload_shared_raw(uint32_t set,
size_t binding_index,
const uint8_t* data,
size_t byte_size)
123 m_resources.upload_shared_raw(set, binding_index, data, byte_size);
126 void download_shared(uint32_t set,
size_t binding_index,
void* dest,
size_t byte_size)
128 m_resources.download_shared(set, binding_index, dest, byte_size);
134 return m_resources.make_shared_buffer_hazard(spec);
144 void set_output_size(
size_t index,
size_t byte_size);
150 bool ensure_gpu_ready();
155 [[nodiscard]]
bool is_gpu_ready()
const;
167 [[nodiscard]] std::shared_ptr<Core::VKImage> get_output_image(
size_t binding_index)
const;
176 void download_binding(
size_t index,
void* dest,
size_t byte_size);
194 m_gpu_config = std::move(config);
195 update_dispatch_key_cache();
211 void stage_image_at(
size_t binding_index,
212 std::shared_ptr<Core::VKImage>
image,
214 vk::Sampler sampler =
nullptr);
227 [[nodiscard]]
const std::string&
dispatch_key()
const {
return m_cached_dispatch_key; }
235 [[nodiscard]]
virtual std::vector<GpuBufferBinding> declare_buffer_bindings()
const;
241 virtual void on_before_gpu_dispatch(
242 const std::vector<std::vector<double>>& channels,
251 virtual void prepare_gpu_inputs(
252 const std::vector<std::vector<double>>& channels,
264 [[nodiscard]]
virtual std::array<uint32_t, 3> calculate_dispatch_size(
265 size_t total_elements,
274 void stage_passthrough(
size_t binding_index,
const void* data,
size_t byte_size);
292 void stage_native_bytes(
size_t binding_index,
const void* data,
size_t byte_size);
305 const std::vector<std::vector<double>>& channels,
318 const std::vector<std::vector<double>>& channels,
336 const std::vector<std::vector<double>>& channels,
354 const std::vector<std::vector<double>>& channels,
374 void dispatch_core_dependency(
const std::vector<DependencyStage>& stages);
385 return m_last_effective_element_count;
397 [[nodiscard]] std::vector<float> readback_primary(
size_t float_count);
413 void flatten_channels_to_staging(
414 const std::vector<std::vector<double>>& channels,
430 void flatten_native_variants_to_staging(
431 const std::vector<Kakshya::DataVariant>& variants,
434 [[nodiscard]]
size_t find_first_output_index()
const;
435 [[nodiscard]]
size_t largest_binding_data_element_count()
const;
447 std::shared_ptr<Core::VKImage>
image;
457 size_t m_last_effective_element_count {};
464 void update_dispatch_key_cache();
465 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::set< std::pair< uint32_t, size_t > > m_shared_bindings
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)
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
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.
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,...
Metadata about data structure for reconstruction.
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::shared_ptr< Core::VKImage > image