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

◆ compute_histogram()

std::array< uint32_t, 256 > MayaFlux::Yantra::VisionAnalyzer::compute_histogram ( const std::shared_ptr< Core::VKImage > &  image,
uint32_t  w,
uint32_t  h 
)
private

Dispatch otsu_histogram.comp over image, zeroing the buffer first.

Definition at line 331 of file VisionAnalyzer.cpp.

333{
334 if (!m_histogram_ctx) {
335 m_histogram_ctx = std::make_shared<TextureExecutionContext>(
336 GpuComputeConfig {
337 .shader_path = "otsu_histogram.comp.spv",
338 .workgroup_size = { 8, 8, 1 },
339 .push_constant_size = sizeof(HistogramPC) },
340 Portal::Graphics::ImageFormat::RGBA8,
342 1,
343 std::vector<GpuBufferBinding> {
344 { .set = 0, .binding = 3, .direction = GpuBufferBinding::Direction::INPUT_OUTPUT, .element_type = GpuBufferBinding::ElementType::UINT32 } },
346 }
347
348 m_histogram_ctx->ensure_shared_buffer(0, 3, 768, GpuBufferBinding::ElementType::UINT32,
350
351 const std::array<uint32_t, 768> zero {};
352 m_histogram_ctx->upload_shared_raw(0, 3, reinterpret_cast<const uint8_t*>(zero.data()), sizeof(zero));
353
354 m_histogram_ctx->stage_image(image);
355 m_histogram_ctx->set_push_constants(HistogramPC { .width = w, .height = h, .channels = 0 });
356 m_histogram_ctx->set_output_dimensions(w, h);
357
358 auto& foundry = Portal::Graphics::get_shader_foundry();
359 const auto fence = m_histogram_ctx->dispatch_async({});
360 m_histogram_ctx->clear_output_dimensions();
361 foundry.wait_for_fence(fence);
362 foundry.release_fence(fence);
363
364 std::array<uint32_t, 256> histogram {};
365 m_histogram_ctx->download_shared(0, 3, histogram.data(), sizeof(histogram));
366 return histogram;
367}
vk::Fence fence
IO::ImageData image
Definition Decoder.cpp:47
uint32_t h
Definition InkPress.cpp:29
@ SCALAR
Return SSBO readback via collect_result(); no image download.
std::shared_ptr< TextureExecutionContext > m_histogram_ctx
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
@ COMPUTE
Storage buffer for compute shaders (device-local)

References MayaFlux::Portal::Graphics::COMPUTE, fence, MayaFlux::Portal::Graphics::get_shader_foundry(), h, image, MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_STORAGE, MayaFlux::Portal::Graphics::GpuBufferBinding::INPUT_OUTPUT, m_histogram_ctx, MayaFlux::Yantra::TextureExecutionContext::SCALAR, MayaFlux::Portal::Graphics::GpuComputeConfig::shader_path, and MayaFlux::Portal::Graphics::GpuBufferBinding::UINT32.

Referenced by measure_appearance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: