Automatically determine the image layouts in descriptor sets

This commit is contained in:
Pierre Krieger 2016-03-28 09:49:03 +02:00
parent c4cc6e0349
commit 50b19b4fec
7 changed files with 38 additions and 38 deletions

View File

@ -67,7 +67,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
Some((
"::vulkano::descriptor_set::DescriptorType::SampledImage",
"::std::sync::Arc<::vulkano::image::ImageView>",
"::vulkano::descriptor_set::DescriptorBind::SampledImage(data, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::SampledImage(data)"
))
},
&parse::Instruction::TypeImage { result_id, sampled_type_id, ref dim, arrayed, ms,
@ -77,7 +77,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
Some((
"::vulkano::descriptor_set::DescriptorType::InputAttachment", // FIXME: can be `StorageImage`
"::std::sync::Arc<::vulkano::image::ImageView>",
"::vulkano::descriptor_set::DescriptorBind::InputAttachment(data, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::InputAttachment(data)"
))
},
&parse::Instruction::TypeSampledImage { result_id, image_type_id }
@ -86,7 +86,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
Some((
"::vulkano::descriptor_set::DescriptorType::CombinedImageSampler",
"(::std::sync::Arc<::vulkano::sampler::Sampler>, ::std::sync::Arc<::vulkano::image::ImageView>)",
"::vulkano::descriptor_set::DescriptorBind::CombinedImageSampler(data.0, data.1, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::CombinedImageSampler(data.0, data.1)"
))
},
_ => None, // TODO: other types

View File

@ -87,17 +87,17 @@ pub struct DescriptorWrite {
// FIXME: incomplete
#[derive(Clone)] // TODO: Debug
pub enum DescriptorBind {
StorageImage(Arc<ImageView>, ImageLayout),
StorageImage(Arc<ImageView>),
Sampler(Arc<Sampler>),
SampledImage(Arc<ImageView>, ImageLayout),
CombinedImageSampler(Arc<Sampler>, Arc<ImageView>, ImageLayout),
SampledImage(Arc<ImageView>),
CombinedImageSampler(Arc<Sampler>, Arc<ImageView>),
//UniformTexelBuffer(Arc<Buffer>), // FIXME: requires buffer views
//StorageTexelBuffer(Arc<Buffer>), // FIXME: requires buffer views
UniformBuffer { buffer: Arc<Buffer>, offset: usize, size: usize },
StorageBuffer { buffer: Arc<Buffer>, offset: usize, size: usize },
DynamicUniformBuffer { buffer: Arc<Buffer>, offset: usize, size: usize },
DynamicStorageBuffer { buffer: Arc<Buffer>, offset: usize, size: usize },
InputAttachment(Arc<ImageView>, ImageLayout),
InputAttachment(Arc<ImageView>),
}
impl DescriptorBind {
@ -106,16 +106,16 @@ impl DescriptorBind {
pub fn ty(&self) -> DescriptorType {
match *self {
DescriptorBind::Sampler(_) => DescriptorType::Sampler,
DescriptorBind::CombinedImageSampler(_, _, _) => DescriptorType::CombinedImageSampler,
DescriptorBind::SampledImage(_, _) => DescriptorType::SampledImage,
DescriptorBind::StorageImage(_, _) => DescriptorType::StorageImage,
DescriptorBind::CombinedImageSampler(_, _) => DescriptorType::CombinedImageSampler,
DescriptorBind::SampledImage(_) => DescriptorType::SampledImage,
DescriptorBind::StorageImage(_) => DescriptorType::StorageImage,
//DescriptorBind::UniformTexelBuffer(_) => DescriptorType::UniformTexelBuffer,
//DescriptorBind::StorageTexelBuffer(_) => DescriptorType::StorageTexelBuffer,
DescriptorBind::UniformBuffer { .. } => DescriptorType::UniformBuffer,
DescriptorBind::StorageBuffer { .. } => DescriptorType::StorageBuffer,
DescriptorBind::DynamicUniformBuffer { .. } => DescriptorType::UniformBufferDynamic,
DescriptorBind::DynamicStorageBuffer { .. } => DescriptorType::StorageBufferDynamic,
DescriptorBind::InputAttachment(_, _) => DescriptorType::InputAttachment,
DescriptorBind::InputAttachment(_) => DescriptorType::InputAttachment,
}
}
}

View File

@ -164,43 +164,43 @@ impl<S> DescriptorSet<S> where S: SetLayout {
imageLayout: 0,
})
},
DescriptorBind::CombinedImageSampler(ref sampler, ref image, layout) => {
DescriptorBind::CombinedImageSampler(ref sampler, ref image) => {
assert!(image.inner_view().usage_sampled());
self_resources_samplers.push(sampler.clone());
self_resources_image_views.push(image.clone());
Some(vk::DescriptorImageInfo {
sampler: sampler.internal_object(),
imageView: image.inner_view().internal_object(),
imageLayout: layout as u32,
imageLayout: image.descriptor_set_combined_image_sampler_layout() as u32,
})
},
DescriptorBind::StorageImage(ref image, layout) => {
DescriptorBind::StorageImage(ref image) => {
assert!(image.inner_view().usage_storage());
assert!(image.identity_swizzle());
self_resources_image_views.push(image.clone());
Some(vk::DescriptorImageInfo {
sampler: 0,
imageView: image.inner_view().internal_object(),
imageLayout: layout as u32,
imageLayout: image.descriptor_set_storage_image_layout() as u32,
})
},
DescriptorBind::SampledImage(ref image, layout) => {
DescriptorBind::SampledImage(ref image) => {
assert!(image.inner_view().usage_sampled());
self_resources_image_views.push(image.clone());
Some(vk::DescriptorImageInfo {
sampler: 0,
imageView: image.inner_view().internal_object(),
imageLayout: layout as u32,
imageLayout: image.descriptor_set_sampled_image_layout() as u32,
})
},
DescriptorBind::InputAttachment(ref image, layout) => {
DescriptorBind::InputAttachment(ref image) => {
assert!(image.inner_view().usage_input_attachment());
assert!(image.identity_swizzle());
self_resources_image_views.push(image.clone());
Some(vk::DescriptorImageInfo {
sampler: 0,
imageView: image.inner_view().internal_object(),
imageLayout: layout as u32,
imageLayout: image.descriptor_set_input_attachment_layout() as u32,
})
},
_ => None
@ -213,9 +213,9 @@ impl<S> DescriptorSet<S> where S: SetLayout {
let vk_writes = write.iter().map(|write| {
let (buffer_info, image_info) = match write.content {
DescriptorBind::Sampler(_) | DescriptorBind::CombinedImageSampler(_, _ ,_) |
DescriptorBind::SampledImage(_, _) | DescriptorBind::StorageImage(_, _) |
DescriptorBind::InputAttachment(_, _) => {
DescriptorBind::Sampler(_) | DescriptorBind::CombinedImageSampler(_, _) |
DescriptorBind::SampledImage(_) | DescriptorBind::StorageImage(_) |
DescriptorBind::InputAttachment(_) => {
let img = image_descriptors.as_ptr().offset(next_image_desc as isize);
next_image_desc += 1;
(ptr::null(), img)

View File

@ -211,22 +211,22 @@ unsafe impl<F: 'static> ImageView for AttachmentImage<F> {
}
#[inline]
fn descriptor_set_storage_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_storage_image_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_combined_image_sampler_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_combined_image_sampler_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_sampled_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_sampled_image_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_input_attachment_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_input_attachment_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}

View File

@ -178,22 +178,22 @@ unsafe impl<F: 'static> ImageView for ImmutableImage<F> {
}
#[inline]
fn descriptor_set_storage_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_storage_image_layout(&self) -> Layout {
Layout::ShaderReadOnlyOptimal
}
#[inline]
fn descriptor_set_combined_image_sampler_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_combined_image_sampler_layout(&self) -> Layout {
Layout::ShaderReadOnlyOptimal
}
#[inline]
fn descriptor_set_sampled_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_sampled_image_layout(&self) -> Layout {
Layout::ShaderReadOnlyOptimal
}
#[inline]
fn descriptor_set_input_attachment_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_input_attachment_layout(&self) -> Layout {
Layout::ShaderReadOnlyOptimal
}

View File

@ -173,22 +173,22 @@ unsafe impl ImageView for SwapchainImage {
}
#[inline]
fn descriptor_set_storage_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_storage_image_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_combined_image_sampler_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_combined_image_sampler_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_sampled_image_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_sampled_image_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_input_attachment_layout(&self, _: AccessRange) -> Layout {
fn descriptor_set_input_attachment_layout(&self) -> Layout {
Layout::ColorAttachmentOptimal
}

View File

@ -132,13 +132,13 @@ pub unsafe trait ImageView {
}
/// Returns the image layout to use in a descriptor with the given subresource.
fn descriptor_set_storage_image_layout(&self, AccessRange) -> Layout;
fn descriptor_set_storage_image_layout(&self) -> Layout;
/// Returns the image layout to use in a descriptor with the given subresource.
fn descriptor_set_combined_image_sampler_layout(&self, AccessRange) -> Layout;
fn descriptor_set_combined_image_sampler_layout(&self) -> Layout;
/// Returns the image layout to use in a descriptor with the given subresource.
fn descriptor_set_sampled_image_layout(&self, AccessRange) -> Layout;
fn descriptor_set_sampled_image_layout(&self) -> Layout;
/// Returns the image layout to use in a descriptor with the given subresource.
fn descriptor_set_input_attachment_layout(&self, AccessRange) -> Layout;
fn descriptor_set_input_attachment_layout(&self) -> Layout;
/// Returns true if the view doesn't use components swizzling.
///