mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
Create implicit layouts for compute pipelines
This commit is contained in:
1 parent
f18fa7ef9b
commit
a9b8a99e19
4 files changed
+357
-222
No files matched your search
+1
-1
@@ -248,7 +248,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
}
|
||||
A::CreateComputePipeline(id, desc) => {
|
||||
self.device_maintain_ids::<B>(device).unwrap();
|
||||
self.device_create_compute_pipeline::<B>(device, &desc, id)
|
||||
self.device_create_compute_pipeline::<B>(device, &desc, id, None)
|
||||
.unwrap();
|
||||
}
|
||||
A::DestroyComputePipeline(id) => {
|
||||
|
||||
+339
-220
@@ -6,7 +6,9 @@ use crate::{
|
||||
binding_model::{self, CreateBindGroupError, CreatePipelineLayoutError},
|
||||
command, conv,
|
||||
device::life::WaitIdleError,
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Hub, Input, InvalidId, Token},
|
||||
hub::{
|
||||
GfxBackend, Global, GlobalIdentityHandlerFactory, Hub, Input, InvalidId, Storage, Token,
|
||||
},
|
||||
id, pipeline, resource, span, swap_chain,
|
||||
track::{BufferState, TextureState, TrackerSet},
|
||||
validation::{self, check_buffer_usage, check_texture_usage},
|
||||
@@ -59,6 +61,9 @@ pub const MAX_VERTEX_BUFFERS: usize = 16;
|
||||
pub const MAX_ANISOTROPY: u8 = 16;
|
||||
pub const SHADER_STAGE_COUNT: usize = 3;
|
||||
|
||||
/// Number of implicit bind groups derived at pipeline creation.
|
||||
pub type DerivedBindGroupCount = u8;
|
||||
|
||||
pub fn all_buffer_stages() -> hal::pso::PipelineStage {
|
||||
use hal::pso::PipelineStage as Ps;
|
||||
Ps::DRAW_INDIRECT
|
||||
@@ -601,6 +606,203 @@ impl<B: GfxBackend> Device<B> {
|
||||
unsafe { self.raw.create_render_pass(all, iter::once(subpass), &[]) }
|
||||
}
|
||||
|
||||
fn deduplicate_bind_group_layout(
|
||||
self_id: id::DeviceId,
|
||||
entry_map: &binding_model::BindEntryMap,
|
||||
guard: &Storage<binding_model::BindGroupLayout<B>, id::BindGroupLayoutId>,
|
||||
) -> Option<id::BindGroupLayoutId> {
|
||||
guard
|
||||
.iter(self_id.backend())
|
||||
.find(|(_, bgl)| bgl.device_id.value.0 == self_id && bgl.entries == *entry_map)
|
||||
.map(|(id, value)| {
|
||||
value.multi_ref_count.inc();
|
||||
id
|
||||
})
|
||||
}
|
||||
|
||||
fn create_bind_group_layout(
|
||||
&self,
|
||||
self_id: id::DeviceId,
|
||||
label: Option<&str>,
|
||||
entry_map: binding_model::BindEntryMap,
|
||||
) -> Result<binding_model::BindGroupLayout<B>, binding_model::CreateBindGroupLayoutError> {
|
||||
// Validate the count parameter
|
||||
for binding in entry_map.values() {
|
||||
if let Some(count) = binding.count {
|
||||
if count == 0 {
|
||||
return Err(binding_model::CreateBindGroupLayoutError::ZeroCount);
|
||||
}
|
||||
match binding.ty {
|
||||
wgt::BindingType::SampledTexture { .. } => {
|
||||
if !self
|
||||
.features
|
||||
.contains(wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY)
|
||||
{
|
||||
return Err(binding_model::CreateBindGroupLayoutError::MissingFeature(
|
||||
wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY,
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => return Err(binding_model::CreateBindGroupLayoutError::ArrayUnsupported),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let raw_bindings = entry_map
|
||||
.values()
|
||||
.map(|entry| hal::pso::DescriptorSetLayoutBinding {
|
||||
binding: entry.binding,
|
||||
ty: conv::map_binding_type(entry),
|
||||
count: entry
|
||||
.count
|
||||
.map_or(1, |v| v as hal::pso::DescriptorArrayIndex), //TODO: consolidate
|
||||
stage_flags: conv::map_shader_stage_flags(entry.visibility),
|
||||
immutable_samplers: false, // TODO
|
||||
})
|
||||
.collect::<Vec<_>>(); //TODO: avoid heap allocation
|
||||
|
||||
let raw = unsafe {
|
||||
let mut raw_layout = self
|
||||
.raw
|
||||
.create_descriptor_set_layout(&raw_bindings, &[])
|
||||
.or(Err(DeviceError::OutOfMemory))?;
|
||||
if let Some(label) = label {
|
||||
self.raw
|
||||
.set_descriptor_set_layout_name(&mut raw_layout, label);
|
||||
}
|
||||
raw_layout
|
||||
};
|
||||
|
||||
let mut count_validator = binding_model::BindingTypeMaxCountValidator::default();
|
||||
for entry in entry_map.values() {
|
||||
count_validator.add_binding(entry);
|
||||
}
|
||||
// If a single bind group layout violates limits, the pipeline layout is definitely
|
||||
// going to violate limits too, lets catch it now.
|
||||
count_validator
|
||||
.validate(&self.limits)
|
||||
.map_err(binding_model::CreateBindGroupLayoutError::TooManyBindings)?;
|
||||
|
||||
Ok(binding_model::BindGroupLayout {
|
||||
raw,
|
||||
device_id: Stored {
|
||||
value: id::Valid(self_id),
|
||||
ref_count: self.life_guard.add_ref(),
|
||||
},
|
||||
multi_ref_count: MultiRefCount::new(),
|
||||
desc_counts: raw_bindings.iter().cloned().collect(),
|
||||
dynamic_count: entry_map
|
||||
.values()
|
||||
.filter(|b| b.has_dynamic_offset())
|
||||
.count(),
|
||||
count_validator,
|
||||
entries: entry_map,
|
||||
})
|
||||
}
|
||||
|
||||
fn create_pipeline_layout(
|
||||
&self,
|
||||
self_id: id::DeviceId,
|
||||
desc: &wgt::PipelineLayoutDescriptor<id::BindGroupLayoutId>,
|
||||
bgl_guard: &Storage<binding_model::BindGroupLayout<B>, id::BindGroupLayoutId>,
|
||||
) -> Result<binding_model::PipelineLayout<B>, CreatePipelineLayoutError> {
|
||||
let bind_group_layouts_count = desc.bind_group_layouts.len();
|
||||
let device_max_bind_groups = self.limits.max_bind_groups as usize;
|
||||
if bind_group_layouts_count > device_max_bind_groups {
|
||||
return Err(CreatePipelineLayoutError::TooManyGroups {
|
||||
actual: bind_group_layouts_count,
|
||||
max: device_max_bind_groups,
|
||||
});
|
||||
}
|
||||
|
||||
if !desc.push_constant_ranges.is_empty()
|
||||
&& !self.features.contains(wgt::Features::PUSH_CONSTANTS)
|
||||
{
|
||||
return Err(CreatePipelineLayoutError::MissingFeature(
|
||||
wgt::Features::PUSH_CONSTANTS,
|
||||
));
|
||||
}
|
||||
let mut used_stages = wgt::ShaderStage::empty();
|
||||
for (index, pc) in desc.push_constant_ranges.iter().enumerate() {
|
||||
if pc.stages.intersects(used_stages) {
|
||||
return Err(
|
||||
CreatePipelineLayoutError::MoreThanOnePushConstantRangePerStage {
|
||||
index,
|
||||
provided: pc.stages,
|
||||
intersected: pc.stages & used_stages,
|
||||
},
|
||||
);
|
||||
}
|
||||
used_stages |= pc.stages;
|
||||
|
||||
let device_max_pc_size = self.limits.max_push_constant_size;
|
||||
if device_max_pc_size < pc.range.end {
|
||||
return Err(CreatePipelineLayoutError::PushConstantRangeTooLarge {
|
||||
index,
|
||||
range: pc.range.clone(),
|
||||
max: device_max_pc_size,
|
||||
});
|
||||
}
|
||||
|
||||
if pc.range.start % wgt::PUSH_CONSTANT_ALIGNMENT != 0 {
|
||||
return Err(CreatePipelineLayoutError::MisalignedPushConstantRange {
|
||||
index,
|
||||
bound: pc.range.start,
|
||||
});
|
||||
}
|
||||
if pc.range.end % wgt::PUSH_CONSTANT_ALIGNMENT != 0 {
|
||||
return Err(CreatePipelineLayoutError::MisalignedPushConstantRange {
|
||||
index,
|
||||
bound: pc.range.end,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let mut count_validator = binding_model::BindingTypeMaxCountValidator::default();
|
||||
|
||||
// validate total resource counts
|
||||
for &id in desc.bind_group_layouts.iter() {
|
||||
let bind_group_layout = bgl_guard
|
||||
.get(id)
|
||||
.map_err(|_| CreatePipelineLayoutError::InvalidBindGroupLayout(id))?;
|
||||
count_validator.merge(&bind_group_layout.count_validator);
|
||||
}
|
||||
count_validator
|
||||
.validate(&self.limits)
|
||||
.map_err(CreatePipelineLayoutError::TooManyBindings)?;
|
||||
|
||||
let descriptor_set_layouts = desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| &bgl_guard.get(id).unwrap().raw);
|
||||
let push_constants = desc
|
||||
.push_constant_ranges
|
||||
.iter()
|
||||
.map(|pc| (conv::map_shader_stage_flags(pc.stages), pc.range.clone()));
|
||||
|
||||
Ok(binding_model::PipelineLayout {
|
||||
raw: unsafe {
|
||||
self.raw
|
||||
.create_pipeline_layout(descriptor_set_layouts, push_constants)
|
||||
.or(Err(DeviceError::OutOfMemory))?
|
||||
},
|
||||
device_id: Stored {
|
||||
value: id::Valid(self_id),
|
||||
ref_count: self.life_guard.add_ref(),
|
||||
},
|
||||
life_guard: LifeGuard::new(),
|
||||
bind_group_layout_ids: desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| {
|
||||
bgl_guard.get(id).unwrap().multi_ref_count.inc();
|
||||
id::Valid(id)
|
||||
})
|
||||
.collect(),
|
||||
push_constant_ranges: desc.push_constant_ranges.iter().cloned().collect(),
|
||||
})
|
||||
}
|
||||
|
||||
fn wait_for_submit(
|
||||
&self,
|
||||
submission_index: SubmissionIndex,
|
||||
@@ -707,6 +909,11 @@ impl DeviceError {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ImplicitPipelineIds<'a, G: GlobalIdentityHandlerFactory> {
|
||||
pub root_id: Input<G, id::PipelineLayoutId>,
|
||||
pub group_ids: &'a [Input<G, id::BindGroupLayoutId>],
|
||||
}
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_features<B: GfxBackend>(
|
||||
&self,
|
||||
@@ -1400,97 +1607,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
// so their inputs are `PhantomData` of size 0.
|
||||
if mem::size_of::<Input<G, id::BindGroupLayoutId>>() == 0 {
|
||||
let (bgl_guard, _) = hub.bind_group_layouts.read(&mut token);
|
||||
let bind_group_layout_id = bgl_guard
|
||||
.iter(device_id.backend())
|
||||
.find(|(_, bgl)| bgl.device_id.value.0 == device_id && bgl.entries == entry_map);
|
||||
|
||||
if let Some((id, value)) = bind_group_layout_id {
|
||||
value.multi_ref_count.inc();
|
||||
if let Some(id) =
|
||||
Device::deduplicate_bind_group_layout(device_id, &entry_map, &*bgl_guard)
|
||||
{
|
||||
return Ok(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the count parameter
|
||||
for binding in desc
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|binding| binding.count.is_some())
|
||||
{
|
||||
if let Some(count) = binding.count {
|
||||
if count == 0 {
|
||||
return Err(binding_model::CreateBindGroupLayoutError::ZeroCount);
|
||||
}
|
||||
match binding.ty {
|
||||
wgt::BindingType::SampledTexture { .. } => {
|
||||
if !device
|
||||
.features
|
||||
.contains(wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY)
|
||||
{
|
||||
return Err(binding_model::CreateBindGroupLayoutError::MissingFeature(
|
||||
wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY,
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => return Err(binding_model::CreateBindGroupLayoutError::ArrayUnsupported),
|
||||
}
|
||||
} else {
|
||||
unreachable!() // programming bug
|
||||
}
|
||||
}
|
||||
|
||||
let raw_bindings = desc
|
||||
.entries
|
||||
.iter()
|
||||
.map(|binding| hal::pso::DescriptorSetLayoutBinding {
|
||||
binding: binding.binding,
|
||||
ty: conv::map_binding_type(binding),
|
||||
count: binding
|
||||
.count
|
||||
.map_or(1, |v| v as hal::pso::DescriptorArrayIndex), //TODO: consolidate
|
||||
stage_flags: conv::map_shader_stage_flags(binding.visibility),
|
||||
immutable_samplers: false, // TODO
|
||||
})
|
||||
.collect::<Vec<_>>(); //TODO: avoid heap allocation
|
||||
|
||||
let raw = unsafe {
|
||||
let mut raw_layout = device
|
||||
.raw
|
||||
.create_descriptor_set_layout(&raw_bindings, &[])
|
||||
.or(Err(DeviceError::OutOfMemory))?;
|
||||
if let Some(label) = desc.label.as_ref() {
|
||||
device
|
||||
.raw
|
||||
.set_descriptor_set_layout_name(&mut raw_layout, label);
|
||||
}
|
||||
raw_layout
|
||||
};
|
||||
|
||||
let mut count_validator = binding_model::BindingTypeMaxCountValidator::default();
|
||||
desc.entries
|
||||
.iter()
|
||||
.for_each(|b| count_validator.add_binding(b));
|
||||
// If a single bind group layout violates limits, the pipeline layout is definitely
|
||||
// going to violate limits too, lets catch it now.
|
||||
count_validator
|
||||
.validate(&device.limits)
|
||||
.map_err(binding_model::CreateBindGroupLayoutError::TooManyBindings)?;
|
||||
|
||||
let layout = binding_model::BindGroupLayout {
|
||||
raw,
|
||||
device_id: Stored {
|
||||
value: id::Valid(device_id),
|
||||
ref_count: device.life_guard.add_ref(),
|
||||
},
|
||||
multi_ref_count: MultiRefCount::new(),
|
||||
entries: entry_map,
|
||||
desc_counts: raw_bindings.iter().cloned().collect(),
|
||||
dynamic_count: desc
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|b| b.has_dynamic_offset())
|
||||
.count(),
|
||||
count_validator,
|
||||
};
|
||||
let layout = device.create_bind_group_layout(
|
||||
device_id,
|
||||
desc.label.as_ref().map(|cow| cow.as_ref()),
|
||||
entry_map,
|
||||
)?;
|
||||
|
||||
let id = hub
|
||||
.bind_group_layouts
|
||||
@@ -1557,108 +1685,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let device = device_guard
|
||||
.get(device_id)
|
||||
.map_err(|_| DeviceError::Invalid)?;
|
||||
let bind_group_layouts_count = desc.bind_group_layouts.len();
|
||||
let device_max_bind_groups = device.limits.max_bind_groups as usize;
|
||||
if bind_group_layouts_count > device_max_bind_groups {
|
||||
return Err(CreatePipelineLayoutError::TooManyGroups {
|
||||
actual: bind_group_layouts_count,
|
||||
max: device_max_bind_groups,
|
||||
});
|
||||
}
|
||||
|
||||
if !desc.push_constant_ranges.is_empty()
|
||||
&& !device.features.contains(wgt::Features::PUSH_CONSTANTS)
|
||||
{
|
||||
return Err(CreatePipelineLayoutError::MissingFeature(
|
||||
wgt::Features::PUSH_CONSTANTS,
|
||||
));
|
||||
}
|
||||
let mut used_stages = wgt::ShaderStage::empty();
|
||||
for (index, pc) in desc.push_constant_ranges.iter().enumerate() {
|
||||
if pc.stages.intersects(used_stages) {
|
||||
return Err(
|
||||
CreatePipelineLayoutError::MoreThanOnePushConstantRangePerStage {
|
||||
index,
|
||||
provided: pc.stages,
|
||||
intersected: pc.stages & used_stages,
|
||||
},
|
||||
);
|
||||
}
|
||||
used_stages |= pc.stages;
|
||||
|
||||
let device_max_pc_size = device.limits.max_push_constant_size;
|
||||
if device_max_pc_size < pc.range.end {
|
||||
return Err(CreatePipelineLayoutError::PushConstantRangeTooLarge {
|
||||
index,
|
||||
range: pc.range.clone(),
|
||||
max: device_max_pc_size,
|
||||
});
|
||||
}
|
||||
|
||||
if pc.range.start % wgt::PUSH_CONSTANT_ALIGNMENT != 0 {
|
||||
return Err(CreatePipelineLayoutError::MisalignedPushConstantRange {
|
||||
index,
|
||||
bound: pc.range.start,
|
||||
});
|
||||
}
|
||||
if pc.range.end % wgt::PUSH_CONSTANT_ALIGNMENT != 0 {
|
||||
return Err(CreatePipelineLayoutError::MisalignedPushConstantRange {
|
||||
index,
|
||||
bound: pc.range.end,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let layout = {
|
||||
let mut count_validator = binding_model::BindingTypeMaxCountValidator::default();
|
||||
let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token);
|
||||
|
||||
// validate total resource counts
|
||||
for &id in desc.bind_group_layouts.iter() {
|
||||
let bind_group_layout = bind_group_layout_guard
|
||||
.get(id)
|
||||
.map_err(|_| CreatePipelineLayoutError::InvalidBindGroupLayout(id))?;
|
||||
count_validator.merge(&bind_group_layout.count_validator);
|
||||
}
|
||||
count_validator
|
||||
.validate(&device.limits)
|
||||
.map_err(CreatePipelineLayoutError::TooManyBindings)?;
|
||||
|
||||
let descriptor_set_layouts = desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| &bind_group_layout_guard.get(id).unwrap().raw);
|
||||
let push_constants = desc
|
||||
.push_constant_ranges
|
||||
.iter()
|
||||
.map(|pc| (conv::map_shader_stage_flags(pc.stages), pc.range.clone()));
|
||||
|
||||
binding_model::PipelineLayout {
|
||||
raw: unsafe {
|
||||
device
|
||||
.raw
|
||||
.create_pipeline_layout(descriptor_set_layouts, push_constants)
|
||||
.or(Err(DeviceError::OutOfMemory))?
|
||||
},
|
||||
device_id: Stored {
|
||||
value: id::Valid(device_id),
|
||||
ref_count: device.life_guard.add_ref(),
|
||||
},
|
||||
life_guard: LifeGuard::new(),
|
||||
bind_group_layout_ids: desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| {
|
||||
bind_group_layout_guard
|
||||
.get(id)
|
||||
.unwrap()
|
||||
.multi_ref_count
|
||||
.inc();
|
||||
id::Valid(id)
|
||||
})
|
||||
.collect(),
|
||||
push_constant_ranges: desc.push_constant_ranges.iter().cloned().collect(),
|
||||
}
|
||||
let (bgl_guard, _) = hub.bind_group_layouts.read(&mut token);
|
||||
device.create_pipeline_layout(device_id, desc, &*bgl_guard)?
|
||||
};
|
||||
|
||||
let id = hub
|
||||
@@ -2810,7 +2840,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
device_id: id::DeviceId,
|
||||
desc: &pipeline::ComputePipelineDescriptor,
|
||||
id_in: Input<G, id::ComputePipelineId>,
|
||||
) -> Result<id::ComputePipelineId, pipeline::CreateComputePipelineError> {
|
||||
implicit_pipeline_ids: Option<ImplicitPipelineIds<G>>,
|
||||
) -> Result<(id::ComputePipelineId, DerivedBindGroupCount), pipeline::CreateComputePipelineError>
|
||||
{
|
||||
span!(_guard, INFO, "Device::create_compute_pipeline");
|
||||
|
||||
let hub = B::hub(self);
|
||||
@@ -2820,39 +2852,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let device = device_guard
|
||||
.get(device_id)
|
||||
.map_err(|_| DeviceError::Invalid)?;
|
||||
let (raw_pipeline, layout_id, layout_ref_count) = {
|
||||
let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token);
|
||||
let (bgl_guard, mut token) = hub.bind_group_layouts.read(&mut token);
|
||||
let (raw_pipeline, layout_id, layout_ref_count, derived_bind_group_count) = {
|
||||
//TODO: only lock mutable if the layout is derived
|
||||
let (mut pipeline_layout_guard, mut token) = hub.pipeline_layouts.write(&mut token);
|
||||
let (mut bgl_guard, mut token) = hub.bind_group_layouts.write(&mut token);
|
||||
|
||||
let mut derived_group_layouts =
|
||||
ArrayVec::<[binding_model::BindEntryMap; MAX_BIND_GROUPS]>::new();
|
||||
let given_group_layouts: ArrayVec<[&binding_model::BindEntryMap; MAX_BIND_GROUPS]>;
|
||||
let group_layouts = match desc.layout {
|
||||
Some(pipeline_layout_id) => {
|
||||
let layout = pipeline_layout_guard
|
||||
.get(pipeline_layout_id)
|
||||
.map_err(|_| pipeline::CreateComputePipelineError::InvalidLayout)?;
|
||||
given_group_layouts = layout
|
||||
.bind_group_layout_ids
|
||||
.iter()
|
||||
.map(|&id| &bgl_guard[id].entries)
|
||||
.collect();
|
||||
validation::IntrospectionBindGroupLayouts::Given(&given_group_layouts)
|
||||
}
|
||||
None => {
|
||||
for _ in 0..device.limits.max_bind_groups {
|
||||
derived_group_layouts.push(binding_model::BindEntryMap::default());
|
||||
}
|
||||
validation::IntrospectionBindGroupLayouts::Derived(&mut derived_group_layouts)
|
||||
}
|
||||
};
|
||||
|
||||
let interface = validation::StageInterface::default();
|
||||
let pipeline_stage = &desc.compute_stage;
|
||||
let (shader_module_guard, _) = hub.shader_modules.read(&mut token);
|
||||
|
||||
let entry_point_name = &pipeline_stage.entry_point;
|
||||
|
||||
let shader_module = shader_module_guard
|
||||
.get(pipeline_stage.module)
|
||||
.map_err(|_| {
|
||||
@@ -2862,6 +2874,28 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
})?;
|
||||
|
||||
if let Some(ref module) = shader_module.module {
|
||||
let given_group_layouts: ArrayVec<[&binding_model::BindEntryMap; MAX_BIND_GROUPS]>;
|
||||
let group_layouts = match desc.layout {
|
||||
Some(pipeline_layout_id) => {
|
||||
let layout = pipeline_layout_guard
|
||||
.get(pipeline_layout_id)
|
||||
.map_err(|_| pipeline::CreateComputePipelineError::InvalidLayout)?;
|
||||
given_group_layouts = layout
|
||||
.bind_group_layout_ids
|
||||
.iter()
|
||||
.map(|&id| &bgl_guard[id].entries)
|
||||
.collect();
|
||||
validation::IntrospectionBindGroupLayouts::Given(&given_group_layouts)
|
||||
}
|
||||
None => {
|
||||
for _ in 0..device.limits.max_bind_groups {
|
||||
derived_group_layouts.push(binding_model::BindEntryMap::default());
|
||||
}
|
||||
validation::IntrospectionBindGroupLayouts::Derived(
|
||||
&mut derived_group_layouts,
|
||||
)
|
||||
}
|
||||
};
|
||||
let _ = validation::check_stage(
|
||||
module,
|
||||
group_layouts,
|
||||
@@ -2883,11 +2917,87 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
// TODO
|
||||
let parent = hal::pso::BasePipeline::None;
|
||||
|
||||
let derived_bind_group_count = derived_group_layouts.len() as DerivedBindGroupCount;
|
||||
|
||||
let pipeline_layout_id = match desc.layout {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
//TODO: create a new pipeline layout
|
||||
unimplemented!()
|
||||
while derived_group_layouts
|
||||
.last()
|
||||
.map_or(false, |map| map.is_empty())
|
||||
{
|
||||
derived_group_layouts.pop();
|
||||
}
|
||||
let ids = implicit_pipeline_ids
|
||||
.as_ref()
|
||||
.ok_or(pipeline::CreateComputePipelineError::InvalidLayout)?;
|
||||
if ids.group_ids.len() < derived_group_layouts.len() {
|
||||
tracing::error!(
|
||||
"Not enough bind group IDs ({}) specified for the implicit layout ({})",
|
||||
ids.group_ids.len(),
|
||||
derived_group_layouts.len()
|
||||
);
|
||||
return Err(pipeline::CreateComputePipelineError::InvalidLayout);
|
||||
}
|
||||
|
||||
let mut derived_group_layout_ids =
|
||||
ArrayVec::<[id::BindGroupLayoutId; MAX_BIND_GROUPS]>::new();
|
||||
for (bgl_id, map) in ids.group_ids.iter().zip(derived_group_layouts) {
|
||||
let processed_id = match Device::deduplicate_bind_group_layout(
|
||||
device_id,
|
||||
&map,
|
||||
&*bgl_guard,
|
||||
) {
|
||||
Some(dedup_id) => dedup_id,
|
||||
None => {
|
||||
#[cfg(feature = "trace")]
|
||||
let bgl_desc = wgt::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: if device.trace.is_some() {
|
||||
Cow::Owned(map.values().cloned().collect())
|
||||
} else {
|
||||
Cow::Borrowed(&[])
|
||||
},
|
||||
};
|
||||
let bgl = device.create_bind_group_layout(device_id, None, map)?;
|
||||
let out_id = hub.bind_group_layouts.register_identity_locked(
|
||||
bgl_id.clone(),
|
||||
bgl,
|
||||
&mut *bgl_guard,
|
||||
);
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(
|
||||
trace::Action::CreateBindGroupLayout(out_id.0, bgl_desc),
|
||||
),
|
||||
None => (),
|
||||
};
|
||||
out_id.0
|
||||
}
|
||||
};
|
||||
derived_group_layout_ids.push(processed_id);
|
||||
}
|
||||
|
||||
let layout_desc = wgt::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Cow::Borrowed(&derived_group_layout_ids),
|
||||
push_constant_ranges: Cow::Borrowed(&[]), //TODO?
|
||||
};
|
||||
let layout =
|
||||
device.create_pipeline_layout(device_id, &layout_desc, &*bgl_guard)?;
|
||||
let layout_id = hub.pipeline_layouts.register_identity_locked(
|
||||
ids.root_id.clone(),
|
||||
layout,
|
||||
&mut *pipeline_layout_guard,
|
||||
);
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(trace::Action::CreatePipelineLayout(
|
||||
layout_id.0,
|
||||
layout_desc,
|
||||
)),
|
||||
None => (),
|
||||
};
|
||||
layout_id.0
|
||||
}
|
||||
};
|
||||
let layout = pipeline_layout_guard
|
||||
@@ -2902,7 +3012,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
match unsafe { device.raw.create_compute_pipeline(&pipeline_desc, None) } {
|
||||
Ok(pipeline) => (pipeline, pipeline_layout_id, layout.life_guard.add_ref()),
|
||||
Ok(pipeline) => (
|
||||
pipeline,
|
||||
pipeline_layout_id,
|
||||
layout.life_guard.add_ref(),
|
||||
derived_bind_group_count,
|
||||
),
|
||||
Err(hal::pso::CreationError::OutOfMemory(_)) => {
|
||||
return Err(pipeline::CreateComputePipelineError::Device(
|
||||
DeviceError::OutOfMemory,
|
||||
@@ -2930,12 +3045,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace
|
||||
.lock()
|
||||
.add(trace::Action::CreateComputePipeline(id.0, desc.clone())),
|
||||
Some(ref trace) => trace.lock().add(trace::Action::CreateComputePipeline(
|
||||
id.0,
|
||||
wgt::ComputePipelineDescriptor {
|
||||
layout: Some(layout_id),
|
||||
..desc.clone()
|
||||
},
|
||||
)),
|
||||
None => (),
|
||||
};
|
||||
Ok(id.0)
|
||||
Ok((id.0, derived_bind_group_count))
|
||||
}
|
||||
|
||||
pub fn compute_pipeline_error<B: GfxBackend>(
|
||||
|
||||
@@ -429,6 +429,17 @@ impl<T, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I, F> {
|
||||
Valid(id)
|
||||
}
|
||||
|
||||
pub(crate) fn register_identity_locked(
|
||||
&self,
|
||||
id_in: <F::Filter as IdentityHandler<I>>::Input,
|
||||
value: T,
|
||||
guard: &mut Storage<T, I>,
|
||||
) -> Valid<I> {
|
||||
let id = self.identity.process(id_in, self.backend);
|
||||
guard.insert(id, value);
|
||||
Valid(id)
|
||||
}
|
||||
|
||||
pub fn register_error<A: Access<T>>(
|
||||
&self,
|
||||
id_in: <F::Filter as IdentityHandler<I>>::Input,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::{
|
||||
binding_model::{CreateBindGroupLayoutError, CreatePipelineLayoutError},
|
||||
device::{DeviceError, RenderPassContext},
|
||||
id::{DeviceId, PipelineLayoutId, ShaderModuleId},
|
||||
validation::StageError,
|
||||
@@ -44,8 +45,12 @@ pub type ComputePipelineDescriptor<'a> =
|
||||
pub enum CreateComputePipelineError {
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error("pipelie layout is invalid")]
|
||||
#[error("pipeline layout is invalid")]
|
||||
InvalidLayout,
|
||||
#[error("implicit bind group layout failed to validate")]
|
||||
ImplicitBindGroupLayout(#[from] CreateBindGroupLayoutError),
|
||||
#[error("implicit pipeline layout failed to validate")]
|
||||
ImplicitPipelineLayout(#[from] CreatePipelineLayoutError),
|
||||
#[error(transparent)]
|
||||
Stage(StageError),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user