Skip to main content

Module push_constants

Module push_constants 

Source
Expand description

WGSL push constants (immediates) helper for oxigdal-gpu.

In wgpu 29 the Vulkan “push constants” concept is exposed as immediate data (var<immediate> in WGSL, wgpu::Features::IMMEDIATES on the device, and wgpu::PipelineLayoutDescriptor::immediate_size). This module provides ergonomic Rust wrappers around that API and remains forward-compatible with the naming used in earlier wgpu versions.

§Quick start

use oxigdal_gpu::push_constants::{
    PushConstantsLayout, PushConstantsBuffer, make_push_constants_shader_source,
    build_push_constants_pipeline,
};
use oxigdal_gpu::GpuContext;

let ctx = GpuContext::new().await?;

let layout = PushConstantsLayout::compute_only(16);
let mut buf = PushConstantsBuffer::new(layout.clone());
buf.write_u32(0, 42)?;
buf.write_f32(4, 3.14)?;

let struct_wgsl = "struct PushConstantsBlock { value: u32, scale: f32, _pad0: u32, _pad1: u32, }";
let body_wgsl = "let v = pc.value;";
let src = make_push_constants_shader_source(struct_wgsl, body_wgsl);

§Compatibility note

wgpu 29 renamed Vulkan push constants to “immediates”. The public API of this module deliberately preserves the PushConstants* naming to keep the call-site interface stable regardless of the underlying wgpu version.

Structs§

PushConstantRange
Describes one logical push-constant range within a pipeline layout.
PushConstantRangeDesc
Descriptive wrapper returned by PushConstantsLayout::to_wgpu_ranges.
PushConstantsBuffer
A typed byte buffer holding push-constant (immediate) data.
PushConstantsLayout
Describes all push-constant data ranges used by a pipeline.

Constants§

MAX_PUSH_CONSTANTS_SIZE_BYTES
Minimum guaranteed push-constants (immediates) size per the Vulkan spec (128 bytes). Adapters may expose a larger limit via max_push_constants_size.
PUSH_CONSTANTS_ALIGNMENT
Required alignment for the start and end of each push-constant range.

Functions§

build_push_constants_pipeline
Compile a compute pipeline that uses immediate data (push constants) with the given layout.
dispatch_with_push_constants
Upload immediate (push-constant) data and dispatch a compute pass.
make_push_constants_shader_source
Generate a WGSL compute shader source that uses a var<immediate> block.
max_push_constants_size
Return the maximum immediate-data (push-constants) size in bytes supported by the current adapter’s device.
supports_push_constants
Return true if the GPU context supports immediate data (push constants).