CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
working_image_gpu_halide.h
Go to the documentation of this file.
1
8#pragma once
9
14
15#include <memory>
16#include <expected>
17
18namespace CaptureMoment::Core {
19
20namespace ImageProcessing {
21
36public:
39
40 ~WorkingImageGPU_Halide() override = default;
41
45 [[nodiscard]] bool bindView(const ImageView& view) override;
46
52 [[nodiscard]] std::expected<void, ErrorHandling::CoreError>
53 transferToVRAM() override;
54
58 [[nodiscard]] bool isValid() const override;
59
64
69 [[nodiscard]] Halide::Buffer<float>& getExecutionBuffer();
70
74 [[nodiscard]] bool isOriginalHalideBufferValid() const { return m_original_halide_buffer.defined(); };
75
80 [[nodiscard]] Halide::Buffer<float>& getOriginalHalideBuffer() { return m_original_halide_buffer; };
81
87
96 [[nodiscard]] std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError>
97 downsample(Common::ImageDim target_width, Common::ImageDim target_height) override;
98
99protected:
100 [[nodiscard]] bool downloadDeviceToHost() override;
101
102private:
109 void initDataForHalide();
110
114 void buildDownsamplePipeline();
115
116 // --- GPU Memory Management ---
117 Halide::Buffer<float> m_original_halide_buffer;
118
119 // --- Pipelines Halide ---
120 Halide::Pipeline m_reset_pipeline;
121 Halide::Pipeline m_downsample_pipeline;
122
123 // --- Downsample Pipelines ---
124 Halide::ImageParam m_downsample_input{Halide::Float(32), 3, "downsample_src"};
125 Halide::Param<float> m_downsample_scale_x{"downsample_scale_x"};
126 Halide::Param<float> m_downsample_scale_y{"downsample_scale_y"};
127 Halide::Buffer<float> m_downsample_src_buffer;
128
129 bool m_downsample_built{false};
130 bool m_pipelines_initialized{false};
131
132};
133
134} // namespace ImageProcessing
135
136} // namespace CaptureMoment::Core
Concrete implementation of WorkingImageGPU using Halide for processing.
Halide::Buffer< float > & getOriginalHalideBuffer()
Provides access to the Halide buffer containing the original image on GPU.
bool isValid() const override
Checks if the GPU view AND the Halide buffer are valid.
std::expected< void, ErrorHandling::CoreError > transferToVRAM() override
Transfers the current image data to GPU VRAM With Halide.
Halide::Buffer< float > & getExecutionBuffer()
Provides access to the Halide buffer used for GPU execution.
void resetExecutionBuffer()
Resets the execution buffer on the GPU to prepare for a new Halide pipeline execution.
bool downloadDeviceToHost() override
A pure method that specific backends (Halide, Vulkan, etc.) must implement.
void syncToHostRAM()
Synchronizes the GPU buffer back to Host RAM.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > downsample(Common::ImageDim target_width, Common::ImageDim target_height) override
Downsamples the current image to the target dimensions using Halide on GPU.
bool isOriginalHalideBufferValid() const
Checks if the original GPU buffer is valid.
bool bindView(const ImageView &view) override
Binds the view and initializes the Halide buffer on the device.
Class extending IWorkingImageHardware for GPU-specific implementations.
Base class providing common Halide buffer functionality for image processing.
Central error handling system for CaptureMoment Core library.
Lightweight, non-owning view over image memory and its geometry.
std::size_t ImageDim
Type for image dimensions (width, height).
Definition image_types.h:20
@ ImageProcessing
Errors related to Image Processing, GPU, or Memory.
CoreError
Enumeration of all error codes for CaptureMoment Core.
Definition core_error.h:36
Manages the lifecycle of a single IWorkingImage instance.
Represents a zero-copy window over contiguous image memory.
Definition image_view.h:26
Image working buffers stored on the GPU.
Base class for Halide-based working image implementations.
CaptureMoment — footer