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>
impl<T: Pod + Zeroable> ComputePipeline<T>
Sourcepub fn new(
context: &GpuContext,
input: GpuBuffer<T>,
width: u32,
height: u32,
) -> GpuResult<Self>
pub fn new( context: &GpuContext, input: GpuBuffer<T>, width: u32, height: u32, ) -> GpuResult<Self>
Create a new compute pipeline from a GPU buffer.
Sourcepub fn from_data(
context: &GpuContext,
data: &[T],
width: u32,
height: u32,
) -> GpuResult<Self>
pub fn from_data( context: &GpuContext, data: &[T], width: u32, height: u32, ) -> GpuResult<Self>
Create a pipeline from data.
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Get the current dimensions.
Sourcepub fn element_wise(
self,
op: ElementWiseOp,
other: &GpuBuffer<T>,
) -> GpuResult<Self>
pub fn element_wise( self, op: ElementWiseOp, other: &GpuBuffer<T>, ) -> GpuResult<Self>
Apply element-wise operation with another buffer.
Sourcepub fn gaussian_blur(self, sigma: f32) -> GpuResult<Self>
pub fn gaussian_blur(self, sigma: f32) -> GpuResult<Self>
Apply Gaussian blur.
Sourcepub fn resize(
self,
new_width: u32,
new_height: u32,
method: ResamplingMethod,
) -> GpuResult<Self>
pub fn resize( self, new_width: u32, new_height: u32, method: ResamplingMethod, ) -> GpuResult<Self>
Resize the raster.
Sourcepub fn threshold(
self,
threshold: f32,
above: f32,
below: f32,
) -> GpuResult<Self>
pub fn threshold( self, threshold: f32, above: f32, below: f32, ) -> GpuResult<Self>
Apply threshold.
Sourcepub async fn statistics(&self) -> GpuResult<Statistics>
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.
Sourcepub async fn statistics_with_conversion(
&self,
src_type: GpuDataType,
params: &ConversionParams,
) -> GpuResult<Statistics>
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.
Sourcepub async fn histogram(
&self,
num_bins: u32,
min_value: f32,
max_value: f32,
) -> GpuResult<Vec<u32>>
pub async fn histogram( &self, num_bins: u32, min_value: f32, max_value: f32, ) -> GpuResult<Vec<u32>>
Compute histogram on current buffer.
Sourcepub async fn reduce(&self, op: ReductionOp) -> GpuResult<T>where
T: Copy,
pub async fn reduce(&self, op: ReductionOp) -> GpuResult<T>where
T: Copy,
Compute reduction (sum, min, max, etc.).
Sourcepub fn read_blocking(self) -> GpuResult<Vec<T>>
pub fn read_blocking(self) -> GpuResult<Vec<T>>
Read the result to CPU memory synchronously.
Sourcepub fn convert_to_f32(
self,
src_type: GpuDataType,
params: &ConversionParams,
) -> GpuResult<ComputePipeline<f32>>
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.
Sourcepub fn linear_transform(self, scale: f32, offset: f32) -> GpuResult<Self>
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§impl ComputePipeline<f32>
Specialized implementation for f32 pipelines with full conversion support.
impl ComputePipeline<f32>
Specialized implementation for f32 pipelines with full conversion support.
Sourcepub fn convert_to_type<U: Pod + Zeroable>(
self,
dst_type: GpuDataType,
params: &ConversionParams,
) -> GpuResult<ComputePipeline<U>>
pub fn convert_to_type<U: Pod + Zeroable>( self, dst_type: GpuDataType, params: &ConversionParams, ) -> GpuResult<ComputePipeline<U>>
Sourcepub fn from_u8_normalized(
context: &GpuContext,
data: &[u8],
width: u32,
height: u32,
) -> GpuResult<Self>
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.
Sourcepub fn from_u16_normalized(
context: &GpuContext,
data: &[u16],
width: u32,
height: u32,
) -> GpuResult<Self>
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.
Sourcepub fn scale_offset(self, scale: f32, offset: f32) -> GpuResult<Self>
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.