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: PushConstantsLayoutLayout that governs this buffer’s structure.
Implementations§
Source§impl PushConstantsBuffer
impl PushConstantsBuffer
Sourcepub fn new(layout: PushConstantsLayout) -> Self
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));Sourcepub fn write<T: NoUninit + Copy>(
&mut self,
offset: u32,
value: T,
) -> GpuResult<()>
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.
Sourcepub fn write_u32(&mut self, offset: u32, value: u32) -> GpuResult<()>
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.
Sourcepub fn write_i32(&mut self, offset: u32, value: i32) -> GpuResult<()>
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.
Sourcepub fn write_f32(&mut self, offset: u32, value: f32) -> GpuResult<()>
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.
Sourcepub fn write_vec4_f32(&mut self, offset: u32, value: [f32; 4]) -> GpuResult<()>
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.
Sourcepub fn write_uvec4(&mut self, offset: u32, value: [u32; 4]) -> GpuResult<()>
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.
Trait Implementations§
Source§impl Clone for PushConstantsBuffer
impl Clone for PushConstantsBuffer
Source§fn clone(&self) -> PushConstantsBuffer
fn clone(&self) -> PushConstantsBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more