Use separate samplers and sampled images in the examples (#2354)

* Use separate samplers and sampled images in the examples

* Update examples/src/bin/push-descriptors/main.rs

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
This commit is contained in:
Rua 2023-10-08 14:10:19 +02:00 committed by GitHub
parent 518369e7f1
commit 444c88dfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 196 additions and 155 deletions

View File

@ -399,10 +399,11 @@ fn main() {
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 1, binding = 0) uniform sampler2D tex; layout(set = 1, binding = 0) uniform sampler s;
layout(set = 1, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }
@ -505,11 +506,10 @@ fn main() {
PersistentDescriptorSet::new( PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
pipeline.layout().set_layouts()[1].clone(), pipeline.layout().set_layouts()[1].clone(),
[WriteDescriptorSet::image_view_sampler( [
0, WriteDescriptorSet::sampler(0, sampler.clone()),
ImageView::new_default(texture).unwrap(), WriteDescriptorSet::image_view(1, ImageView::new_default(texture).unwrap()),
sampler.clone(), ],
)],
[], [],
) )
.unwrap() .unwrap()

View File

@ -270,9 +270,10 @@ mod linux {
let set = PersistentDescriptorSet::new( let set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler( [
0, image_view, sampler, WriteDescriptorSet::sampler(0, sampler),
)], WriteDescriptorSet::image_view(1, image_view),
],
[], [],
) )
.unwrap(); .unwrap();
@ -798,9 +799,12 @@ mod linux {
#version 450 #version 450
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex;
layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }

View File

@ -389,7 +389,10 @@ fn main() {
let set = PersistentDescriptorSet::new( let set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler(0, texture, sampler)], [
WriteDescriptorSet::sampler(0, sampler),
WriteDescriptorSet::image_view(1, texture),
],
[], [],
) )
.unwrap(); .unwrap();
@ -578,10 +581,11 @@ mod fs {
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }

View File

@ -337,7 +337,10 @@ fn main() {
let set = PersistentDescriptorSet::new( let set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler(0, texture, sampler)], [
WriteDescriptorSet::sampler(0, sampler),
WriteDescriptorSet::image_view(1, texture),
],
[], [],
) )
.unwrap(); .unwrap();
@ -526,10 +529,11 @@ mod fs {
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }

View File

@ -358,7 +358,7 @@ fn main() {
let set = PersistentDescriptorSet::new( let set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view(0, texture)], [WriteDescriptorSet::image_view(1, texture)],
[], [],
) )
.unwrap(); .unwrap();
@ -547,10 +547,11 @@ mod fs {
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }

View File

@ -198,7 +198,10 @@ impl PixelsDrawPipeline {
PersistentDescriptorSet::new( PersistentDescriptorSet::new(
&self.descriptor_set_allocator, &self.descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler(0, image, sampler)], [
WriteDescriptorSet::sampler(0, sampler),
WriteDescriptorSet::image_view(1, image),
],
[], [],
) )
.unwrap() .unwrap()
@ -279,10 +282,11 @@ mod fs {
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, v_tex_coords); f_color = texture(sampler2D(tex, s), v_tex_coords);
} }
", ",
} }

View File

@ -194,7 +194,10 @@ impl PixelsDrawPipeline {
PersistentDescriptorSet::new( PersistentDescriptorSet::new(
&self.descriptor_set_allocator, &self.descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler(0, image, sampler)], [
WriteDescriptorSet::sampler(0, sampler),
WriteDescriptorSet::image_view(1, image),
],
[], [],
) )
.unwrap() .unwrap()
@ -275,10 +278,11 @@ mod fs {
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, v_tex_coords); f_color = texture(sampler2D(tex, s), v_tex_coords);
} }
", ",
} }

View File

@ -428,7 +428,12 @@ fn main() {
PipelineBindPoint::Graphics, PipelineBindPoint::Graphics,
pipeline.layout().clone(), pipeline.layout().clone(),
0, 0,
[WriteDescriptorSet::image_view(0, texture.clone())] [
// If the binding is an immutable sampler, using push descriptors
// you must write a dummy value to the binding.
WriteDescriptorSet::none(0),
WriteDescriptorSet::image_view(1, texture.clone()),
]
.into_iter() .into_iter()
.collect(), .collect(),
) )
@ -522,10 +527,11 @@ mod fs {
layout(location = 0) in vec2 tex_coords; layout(location = 0) in vec2 tex_coords;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex;
void main() { void main() {
f_color = texture(tex, tex_coords); f_color = texture(sampler2D(tex, s), tex_coords);
} }
", ",
} }

View File

@ -410,10 +410,10 @@ fn main() {
let mut layout_create_info = let mut layout_create_info =
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages); PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages);
// Adjust the info for set 0, binding 0 to make it variable with 2 descriptors. // Adjust the info for set 0, binding 1 to make it variable with 2 descriptors.
let binding = layout_create_info.set_layouts[0] let binding = layout_create_info.set_layouts[0]
.bindings .bindings
.get_mut(&0) .get_mut(&1)
.unwrap(); .unwrap();
binding.binding_flags |= DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT; binding.binding_flags |= DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT;
binding.descriptor_count = 2; binding.descriptor_count = 2;
@ -458,14 +458,10 @@ fn main() {
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
2, 2,
[WriteDescriptorSet::image_view_sampler_array(
0,
0,
[ [
(mascot_texture as _, sampler.clone()), WriteDescriptorSet::sampler(0, sampler),
(vulkano_texture as _, sampler), WriteDescriptorSet::image_view_array(1, 0, [mascot_texture as _, vulkano_texture as _]),
], ],
)],
[], [],
) )
.unwrap(); .unwrap();
@ -667,10 +663,11 @@ mod fs {
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2D tex[]; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2D tex[];
void main() { void main() {
f_color = texture(nonuniformEXT(tex[tex_i]), coords); f_color = texture(nonuniformEXT(sampler2D(tex[tex_i], s)), coords);
} }
", ",
} }

View File

@ -348,7 +348,10 @@ fn main() {
let set = PersistentDescriptorSet::new( let set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
layout.clone(), layout.clone(),
[WriteDescriptorSet::image_view_sampler(0, texture, sampler)], [
WriteDescriptorSet::sampler(0, sampler),
WriteDescriptorSet::image_view(1, texture),
],
[], [],
) )
.unwrap(); .unwrap();
@ -543,10 +546,11 @@ mod fs {
layout(location = 1) flat in uint layer; layout(location = 1) flat in uint layer;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
layout(set = 0, binding = 0) uniform sampler2DArray tex; layout(set = 0, binding = 0) uniform sampler s;
layout(set = 0, binding = 1) uniform texture2DArray tex;
void main() { void main() {
f_color = texture(tex, vec3(tex_coords, layer)); f_color = texture(sampler2DArray(tex, s), vec3(tex_coords, layer));
} }
", ",
} }

View File

@ -413,17 +413,6 @@ impl WriteDescriptorSet {
let array_element_count = elements.len(); let array_element_count = elements.len();
debug_assert!(array_element_count != 0); debug_assert!(array_element_count != 0);
// VUID-VkWriteDescriptorSet-dstArrayElement-00321
if first_array_element + array_element_count > max_descriptor_count {
return Err(Box::new(ValidationError {
problem: "`first_array_element` + the number of provided elements is greater than \
the number of descriptors in the descriptor set binding"
.into(),
vuids: &["VUID-VkWriteDescriptorSet-dstArrayElement-00321"],
..Default::default()
}));
}
let validate_image_view = let validate_image_view =
|image_view: &ImageView, index: usize| -> Result<(), Box<ValidationError>> { |image_view: &ImageView, index: usize| -> Result<(), Box<ValidationError>> {
if image_view.image().image_type() == ImageType::Dim3d { if image_view.image().image_type() == ImageType::Dim3d {
@ -530,49 +519,17 @@ impl WriteDescriptorSet {
match layout_binding.descriptor_type { match layout_binding.descriptor_type {
DescriptorType::Sampler => { DescriptorType::Sampler => {
if !layout_binding.immutable_samplers.is_empty() { if layout_binding.immutable_samplers.is_empty() {
if layout
.flags()
.intersects(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR)
{
// For push descriptors, we must write a dummy element.
if let WriteDescriptorSetElements::None(_) = elements {
// Do nothing
} else {
return Err(Box::new(ValidationError {
context: "elements".into(),
problem: format!(
"contains `{}` elements, but the descriptor set \
binding requires `none` elements",
provided_element_type(elements)
)
.into(),
// vuids?
..Default::default()
}));
}
} else {
// For regular descriptors, no element must be written.
return Err(Box::new(ValidationError {
context: "binding".into(),
problem: "no descriptors must be written to this \
descriptor set binding"
.into(),
// vuids?
..Default::default()
}));
}
}
let elements = if let WriteDescriptorSetElements::Sampler(elements) = elements { let elements = if let WriteDescriptorSetElements::Sampler(elements) = elements {
elements elements
} else { } else {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `sampler` elements", requires `sampler` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -604,13 +561,47 @@ impl WriteDescriptorSet {
problem: "this device is a portability subset device, and \ problem: "this device is a portability subset device, and \
the sampler has depth comparison enabled" the sampler has depth comparison enabled"
.into(), .into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( requires_one_of: RequiresOneOf(&[RequiresAllOf(&[
"mutable_comparison_samplers", Requires::Feature("mutable_comparison_samplers"),
)])]), ])]),
vuids: &["VUID-VkDescriptorImageInfo-mutableComparisonSamplers-04450"], vuids: &[
"VUID-VkDescriptorImageInfo-mutableComparisonSamplers-04450",
],
})); }));
} }
} }
} else if layout
.flags()
.intersects(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR)
{
// For push descriptors, we must write a dummy element.
if let WriteDescriptorSetElements::None(_) = elements {
// Do nothing
} else {
return Err(Box::new(ValidationError {
context: "elements".into(),
problem: format!(
"contains `{}` elements, but descriptor set binding {} \
requires `none` elements",
provided_element_type(elements),
binding,
)
.into(),
// vuids?
..Default::default()
}));
}
} else {
// For regular descriptors, no element must be written.
return Err(Box::new(ValidationError {
context: "binding".into(),
problem: "no descriptors must be written to this \
descriptor set binding"
.into(),
// vuids?
..Default::default()
}));
}
} }
DescriptorType::CombinedImageSampler => { DescriptorType::CombinedImageSampler => {
@ -622,9 +613,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `image_view_sampler` elements", requires `image_view_sampler` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -731,9 +723,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `image_view` elements", requires `image_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
..Default::default() ..Default::default()
@ -807,9 +800,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `image_view` elements", requires `image_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -885,9 +879,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `image_view` elements", requires `image_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -963,9 +958,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `buffer_view` elements", requires `buffer_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -1002,9 +998,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `buffer_view` elements", requires `buffer_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -1042,9 +1039,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `buffer` elements", requires `buffer` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -1094,9 +1092,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `buffer` elements", requires `buffer` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -1146,9 +1145,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `image_view` elements", requires `image_view` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
// vuids? // vuids?
@ -1235,9 +1235,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `inline_uniform_block` elements", requires `inline_uniform_block` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
..Default::default() ..Default::default()
@ -1286,9 +1287,10 @@ impl WriteDescriptorSet {
return Err(Box::new(ValidationError { return Err(Box::new(ValidationError {
context: "elements".into(), context: "elements".into(),
problem: format!( problem: format!(
"contains `{}` elements, but the descriptor set \ "contains `{}` elements, but descriptor set binding {} \
binding requires `acceleration_structure` elements", requires `acceleration_structure` elements",
provided_element_type(elements) provided_element_type(elements),
binding,
) )
.into(), .into(),
..Default::default() ..Default::default()
@ -1316,6 +1318,17 @@ impl WriteDescriptorSet {
} }
} }
// VUID-VkWriteDescriptorSet-dstArrayElement-00321
if first_array_element + array_element_count > max_descriptor_count {
return Err(Box::new(ValidationError {
problem: "`first_array_element` + the number of provided elements is greater than \
the number of descriptors in the descriptor set binding"
.into(),
vuids: &["VUID-VkWriteDescriptorSet-dstArrayElement-00321"],
..Default::default()
}));
}
Ok(()) Ok(())
} }