Skip to main content

GpuContext

Struct GpuContext 

Source
pub struct GpuContext { /* private fields */ }
Expand description

GPU context for compute operations

This is the main entry point for GPU-accelerated operations. It manages device selection, resource allocation, and command submission.

Implementations§

Source§

impl GpuContext

Source

pub fn new() -> Result<Self>

Create a new GPU context with automatic device selection

This will select the most suitable GPU device available on the system. If no GPU is available, an error is returned.

§Errors

Returns an error if no suitable GPU device is found or if device initialization fails.

Source

pub fn with_device(device_index: usize) -> Result<Self>

Create a new GPU context with a specific device

§Arguments
  • device_index - Index of the device to use (from list_devices)
§Errors

Returns an error if the device index is invalid or if device initialization fails.

Source

pub fn list_devices() -> Result<Vec<GpuDeviceInfo>>

List available GPU devices

Returns information about all GPU devices available on the system.

Source

pub fn device_info(&self) -> &GpuDeviceInfo

Get information about the current device

Source

pub fn rgb_to_yuv(&self, input: &[u8], output: &mut [u8]) -> Result<()>

Convert RGB to YUV (BT.601)

§Arguments
  • input - Input RGB buffer (packed RGBA format)
  • output - Output YUV buffer (packed YUVA format)
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn yuv_to_rgb(&self, input: &[u8], output: &mut [u8]) -> Result<()>

Convert YUV to RGB (BT.601)

§Arguments
  • input - Input YUV buffer (packed YUVA format)
  • output - Output RGB buffer (packed RGBA format)
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn scale_bilinear( &self, input: &[u8], src_width: u32, src_height: u32, output: &mut [u8], dst_width: u32, dst_height: u32, ) -> Result<()>

Scale an image using bilinear interpolation

§Arguments
  • input - Input image buffer (packed RGBA format)
  • src_width - Source image width
  • src_height - Source image height
  • output - Output image buffer (packed RGBA format)
  • dst_width - Destination image width
  • dst_height - Destination image height
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn scale_bicubic( &self, input: &[u8], src_width: u32, src_height: u32, output: &mut [u8], dst_width: u32, dst_height: u32, ) -> Result<()>

Scale an image using bicubic interpolation

§Arguments
  • input - Input image buffer (packed RGBA format)
  • src_width - Source image width
  • src_height - Source image height
  • output - Output image buffer (packed RGBA format)
  • dst_width - Destination image width
  • dst_height - Destination image height
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn scale_lanczos( &self, input: &[u8], src_width: u32, src_height: u32, output: &mut [u8], dst_width: u32, dst_height: u32, ) -> Result<()>

Scale an image using Lanczos-3 interpolation (highest quality)

§Arguments
  • input - Input image buffer (packed RGBA format)
  • src_width - Source image width
  • src_height - Source image height
  • output - Output image buffer (packed RGBA format)
  • dst_width - Destination image width
  • dst_height - Destination image height
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn gaussian_blur( &self, input: &[u8], output: &mut [u8], width: u32, height: u32, sigma: f32, ) -> Result<()>

Apply Gaussian blur

§Arguments
  • input - Input image buffer (packed RGBA format)
  • output - Output image buffer (packed RGBA format)
  • width - Image width
  • height - Image height
  • sigma - Blur radius (standard deviation)
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn sharpen( &self, input: &[u8], output: &mut [u8], width: u32, height: u32, amount: f32, ) -> Result<()>

Apply sharpening filter

§Arguments
  • input - Input image buffer (packed RGBA format)
  • output - Output image buffer (packed RGBA format)
  • width - Image width
  • height - Image height
  • amount - Sharpening strength
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn edge_detect( &self, input: &[u8], output: &mut [u8], width: u32, height: u32, ) -> Result<()>

Detect edges using Sobel operator

§Arguments
  • input - Input image buffer (packed RGBA format)
  • output - Output image buffer (packed RGBA format)
  • width - Image width
  • height - Image height
§Errors

Returns an error if buffer sizes are invalid or if the GPU operation fails.

Source

pub fn dct_2d( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, ) -> Result<()>

Compute 2D DCT (Discrete Cosine Transform)

§Arguments
  • input - Input data (f32 values)
  • output - Output DCT coefficients
  • width - Data width (must be multiple of 8)
  • height - Data height (must be multiple of 8)
§Errors

Returns an error if dimensions are invalid or if the GPU operation fails.

Source

pub fn idct_2d( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, ) -> Result<()>

Compute 2D IDCT (Inverse Discrete Cosine Transform)

§Arguments
  • input - Input DCT coefficients
  • output - Output reconstructed data
  • width - Data width (must be multiple of 8)
  • height - Data height (must be multiple of 8)
§Errors

Returns an error if dimensions are invalid or if the GPU operation fails.

Source

pub fn wait(&self)

Wait for all GPU operations to complete

This is useful for synchronization and benchmarking.

Auto Trait Implementations§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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,