ITADN

How to specify specialization constants?

#2755Openitzmeanjan 创建于 2025-12-22
I
itzmeanjancommented
### Question description Hello, I've this compute shader, where I'm trying to pass specialization constant for easy-to-configure local-workgroup size. ```glsl #version 460 #pragma shader_stage(compute) layout(constant_id = 0) const uint WG_SIZE_X = 8; layout(constant_id = 1) const uint WG_SIZE_Y = 8; layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z = 1) in; void main() { ... } ``` This is how I'm creating my compute pipeline. ```rust pub const XYM_SUBGROUP_SIZE: usize = 64; pub const XYM_WORKGROUP_SIZE_X: usize = 8; pub const XYM_WORKGROUP_SIZE_Y: usize = XYM_SUBGROUP_SIZE / XYM_WORKGROUP_SIZE_X; let pipeline = { let spec_consts = foldhash::HashMap::from_iter([ (0, SpecializationConstant::U32(XYM_WORKGROUP_SIZE_X as u32)), (1, SpecializationConstant::U32(XYM_WORKGROUP_SIZE_Y as u32)), ]); let cs = xym_shader::load(device.clone()) .map_err(|_| XymError::VulkanComputeShaderLoadingFailed)? .specialize(spec_consts) .map_err(|_| XymError::VulkanComputeShaderSpecializationConstantAttachmentFailed)?; let cs_entry_point = cs.entry_point("main").ok_or(XymError::VulkanComputeShaderLoadingFailed)?; let compute_stage = PipelineShaderStageCreateInfo::new(cs_entry_point); let layout = PipelineLayout::new( device.clone(), PipelineDescriptorSetLayoutCreateInfo::from_stages([&compute_stage]) .into_pipeline_layout_create_info(device.clone()) .map_err(|_| XymError::VulkanComputePipelineCreationFailed)?, ) .map_err(|_| XymError::VulkanComputePipelineCreationFailed)?; ComputePipeline::new(device.clone(), None, ComputePipelineCreateInfo::stage_layout(compute_stage, layout.clone())) .map_err(|_| XymError::VulkanComputePipelineCreationFailed)? }; ``` What could I possibly be doing wrong that it triggers `VulkanComputePipelineCreationFailed`? Also `vulkano` should consider exposing the `foldhash::HashMap` it uses for specialization constants, it was confusing for a while, as it doesn't use `std::collections::HashMap`.
13 条评论