Skip to main content

ComputePipeline

Struct ComputePipeline 

Source
pub struct ComputePipeline<T: Pod> { /* private fields */ }
Expand description

GPU compute pipeline for chaining operations.

This struct provides a high-level API for building and executing GPU compute pipelines that chain multiple operations together without intermediate CPU transfers.

Implementations§

Source§

impl<T: Pod + Zeroable> ComputePipeline<T>

Source

pub fn new( context: &GpuContext, input: GpuBuffer<T>, width: u32, height: u32, ) -> GpuResult<Self>

Create a new compute pipeline from a GPU buffer.

Source

pub fn from_data( context: &GpuContext, data: &[T], width: u32, height: u32, ) -> GpuResult<Self>

Create a pipeline from data.

Source

pub fn buffer(&self) -> &GpuBuffer<T>

Get the current buffer.

Source

pub fn dimensions(&self) -> (u32, u32)

Get the current dimensions.

Source

pub fn element_wise( self, op: ElementWiseOp, other: &GpuBuffer<T>, ) -> GpuResult<Self>

Apply element-wise operation with another buffer.

Source

pub fn unary(self, op: UnaryOp) -> GpuResult<Self>

Apply unary operation.

Source

pub fn scalar(self, op: ScalarOp) -> GpuResult<Self>

Apply scalar operation.

Source

pub fn gaussian_blur(self, sigma: f32) -> GpuResult<Self>

Apply Gaussian blur.

Source

pub fn resize( self, new_width: u32, new_height: u32, method: ResamplingMethod, ) -> GpuResult<Self>

Resize the raster.

Source

pub fn add(self, value: f32) -> GpuResult<Self>

Add a constant value.

Source

pub fn multiply(self, value: f32) -> GpuResult<Self>

Multiply by a constant value.

Source

pub fn clamp(self, min: f32, max: f32) -> GpuResult<Self>

Clamp values to a range.

Source

pub fn threshold( self, threshold: f32, above: f32, below: f32, ) -> GpuResult<Self>

Apply threshold.

Source

pub fn abs(self) -> GpuResult<Self>

Apply absolute value.

Source

pub fn sqrt(self) -> GpuResult<Self>

Apply square root.

Source

pub fn log(self) -> GpuResult<Self>

Apply natural logarithm.

Source

pub fn exp(self) -> GpuResult<Self>

Apply exponential.

Source

pub async fn statistics(&self) -> GpuResult<Statistics>

Compute statistics on current buffer.

This method converts the buffer to f32 internally for statistics computation, supporting all GPU data types.

Source

pub async fn statistics_with_conversion( &self, src_type: GpuDataType, params: &ConversionParams, ) -> GpuResult<Statistics>

Compute statistics on current buffer with explicit type conversion.

Use this method when you know the source data type for optimal conversion.

Source

pub async fn histogram( &self, num_bins: u32, min_value: f32, max_value: f32, ) -> GpuResult<Vec<u32>>

Compute histogram on current buffer.

Source

pub async fn reduce(&self, op: ReductionOp) -> GpuResult<T>
where T: Copy,

Compute reduction (sum, min, max, etc.).

Source

pub fn finish(self) -> GpuBuffer<T>

Get the result buffer (consumes the pipeline).

Source

pub async fn read(self) -> GpuResult<Vec<T>>

Read the result to CPU memory asynchronously.

Source

pub fn read_blocking(self) -> GpuResult<Vec<T>>

Read the result to CPU memory synchronously.

Source

pub fn convert_to_f32( self, src_type: GpuDataType, params: &ConversionParams, ) -> GpuResult<ComputePipeline<f32>>

Convert the current buffer to f32 with specified conversion parameters.

This creates a new pipeline with f32 data type.

§Errors

Returns an error if conversion fails.

Source

pub fn linear_transform(self, scale: f32, offset: f32) -> GpuResult<Self>

Apply linear transformation: output = input * scale + offset.

This is a convenience method for common scaling operations.

Source

pub fn normalize_range( self, current_min: f32, current_max: f32, new_min: f32, new_max: f32, ) -> GpuResult<Self>

Normalize values to a specific range.

Maps the current value range to [new_min, new_max].

Source§

impl ComputePipeline<f32>

Specialized implementation for f32 pipelines with full conversion support.

Source

pub fn convert_to_type<U: Pod + Zeroable>( self, dst_type: GpuDataType, params: &ConversionParams, ) -> GpuResult<ComputePipeline<U>>

Convert f32 buffer to another data type.

§Errors

Returns an error if conversion fails.

Source

pub fn from_u8_normalized( context: &GpuContext, data: &[u8], width: u32, height: u32, ) -> GpuResult<Self>

Create a pipeline from u8 data with automatic normalization to [0, 1].

§Errors

Returns an error if buffer creation fails.

Source

pub fn from_u16_normalized( context: &GpuContext, data: &[u16], width: u32, height: u32, ) -> GpuResult<Self>

Create a pipeline from u16 data with automatic normalization to [0, 1].

§Errors

Returns an error if buffer creation fails.

Source

pub fn scale_offset(self, scale: f32, offset: f32) -> GpuResult<Self>

Apply scale and offset transformation optimized for type conversion.

This uses GPU compute for efficient transformation.

Auto Trait Implementations§

§

impl<T> Freeze for ComputePipeline<T>

§

impl<T> !RefUnwindSafe for ComputePipeline<T>

§

impl<T> Send for ComputePipeline<T>
where T: Send,

§

impl<T> Sync for ComputePipeline<T>
where T: Sync,

§

impl<T> Unpin for ComputePipeline<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ComputePipeline<T>

§

impl<T> !UnwindSafe for ComputePipeline<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,