pub struct SubgroupOptimizer { /* private fields */ }Expand description
Vulkan subgroup operations optimizer.
Implementations§
Source§impl SubgroupOptimizer
impl SubgroupOptimizer
Sourcepub const EMU_MAX: u32 = 256
pub const EMU_MAX: u32 = 256
Upper bound on the workgroup size supported by the emulated helpers.
The emulation scratch buffers are sized to this many f32/u32
elements; the n argument passed to each helper must not exceed it.
Sourcepub fn new(features: VulkanFeatures, config: VulkanOptimizationConfig) -> Self
pub fn new(features: VulkanFeatures, config: VulkanOptimizationConfig) -> Self
Create a new subgroup optimizer.
Sourcepub fn optimize_shader(&self, shader_code: &str) -> String
pub fn optimize_shader(&self, shader_code: &str) -> String
Optimize shader code with subgroup operations.
Appends a set of subgroup_* WGSL helper functions to shader_code.
The concrete implementation depends on the detected features:
- When
VulkanFeatures::subgroup_arithmetic(respectivelyVulkanFeatures::subgroup_ballot) istrue— i.e. the device was created withwgpu::Features::SUBGROUP— the helpers wrap the native WGSL subgroup built-ins (subgroupAdd,subgroupShuffle,subgroupBallot, …). These reduce/scan across the hardware subgroup (wave) and are the fast path. - Otherwise the helpers fall back to a workgroup-shared-memory
emulation built on
workgroupBarrier(). The emulation reduces across the whole workgroup (not a subgroup) and is correct for a 1-D workgroup of up toSelf::EMU_MAXinvocations.
Every generated helper takes (…, lid: u32, n: u32) where lid is the
caller’s local_invocation_index and n is the number of active
invocations in the workgroup. The native helpers ignore lid/n; the
emulated helpers use them to index the shared scratch buffers. This
uniform signature lets shader authors switch paths without editing call
sites.