Skip to main content

PushConstantsBuffer

Struct PushConstantsBuffer 

Source
pub struct PushConstantsBuffer {
    pub data: Vec<u8>,
    pub layout: PushConstantsLayout,
}
Expand description

A typed byte buffer holding push-constant (immediate) data.

Callers write scalar and vector values into the buffer via the typed helper methods (write_u32, write_f32, etc.) and then upload the raw bytes to the GPU via wgpu::ComputePass::set_immediates.

§Layout

The buffer is zero-initialised at construction. Writes use little-endian byte order (matching wgpu’s expectation on all supported platforms).

Fields§

§data: Vec<u8>

Raw byte storage.

§layout: PushConstantsLayout

Layout that governs this buffer’s structure.

Implementations§

Source§

impl PushConstantsBuffer

Source

pub fn new(layout: PushConstantsLayout) -> Self

Allocate a new zero-initialised buffer sized to layout.total_size.

§Examples
use oxigdal_gpu::push_constants::{PushConstantsBuffer, PushConstantsLayout};

let layout = PushConstantsLayout::compute_only(16);
let buf = PushConstantsBuffer::new(layout);
assert_eq!(buf.size(), 16);
assert!(buf.as_bytes().iter().all(|&b| b == 0));
Source

pub fn write<T: NoUninit + Copy>( &mut self, offset: u32, value: T, ) -> GpuResult<()>

Write any NoUninit + Copy type at offset bytes into the buffer.

The write is bounds-checked: an error is returned if offset + size_of::<T>() would exceed the buffer size.

§Errors

Returns GpuError::InvalidKernelParams on bounds overflow.

Source

pub fn write_u32(&mut self, offset: u32, value: u32) -> GpuResult<()>

Write a u32 at offset bytes (little-endian).

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn write_i32(&mut self, offset: u32, value: i32) -> GpuResult<()>

Write an i32 at offset bytes (little-endian).

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn write_f32(&mut self, offset: u32, value: f32) -> GpuResult<()>

Write an f32 at offset bytes (little-endian, IEEE 754).

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn write_vec4_f32(&mut self, offset: u32, value: [f32; 4]) -> GpuResult<()>

Write a [f32; 4] vec4 starting at offset bytes.

This writes 16 bytes: [x, y, z, w] in little-endian order.

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn write_uvec4(&mut self, offset: u32, value: [u32; 4]) -> GpuResult<()>

Write a [u32; 4] uvec4 starting at offset bytes (16 bytes total).

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn write_vec2_f32(&mut self, offset: u32, value: [f32; 2]) -> GpuResult<()>

Write a [f32; 2] vec2 starting at offset bytes (8 bytes total).

§Errors

Returns an error when the write would exceed the buffer bounds.

Source

pub fn as_bytes(&self) -> &[u8]

Return a view of the raw byte content.

Source

pub fn size(&self) -> u32

Return the size of the buffer in bytes.

Source

pub fn clear(&mut self)

Reset all bytes to zero.

Trait Implementations§

Source§

impl Clone for PushConstantsBuffer

Source§

fn clone(&self) -> PushConstantsBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PushConstantsBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

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