Skip to content

Commit

Permalink
Fix: Attempted write update to an immutable sampler descriptor. (#76)
Browse files Browse the repository at this point in the history
* Remove redundant sampler assignment.

---------

Co-authored-by: John Wells <[email protected]>
  • Loading branch information
DGriffin91 and attackgoat authored Jul 17, 2024
1 parent 05e27d3 commit 2a9b9fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
16 changes: 2 additions & 14 deletions src/driver/graphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use {
device::Device,
image::SampleCount,
merge_push_constant_ranges,
shader::{
DescriptorBindingMap, DescriptorInfo, PipelineDescriptorInfo, Shader,
SpecializationInfo,
},
DescriptorBinding, DriverError,
shader::{DescriptorBindingMap, PipelineDescriptorInfo, Shader, SpecializationInfo},
DriverError,
},
ash::vk,
derive_builder::{Builder, UninitializedFieldError},
Expand Down Expand Up @@ -366,7 +363,6 @@ pub struct GraphicPipeline {
pub name: Option<String>,

pub(crate) push_constants: Vec<vk::PushConstantRange>,
pub(crate) separate_samplers: Box<[DescriptorBinding]>,
pub(crate) shader_modules: Vec<vk::ShaderModule>,
pub(super) state: GraphicPipelineState,
}
Expand Down Expand Up @@ -463,13 +459,6 @@ impl GraphicPipeline {
}
}

let separate_samplers = descriptor_bindings
.iter()
.filter_map(|(&descriptor_binding, (descriptor_info, _))| {
matches!(descriptor_info, DescriptorInfo::Sampler(..)).then_some(descriptor_binding)
})
.collect();

let descriptor_info = PipelineDescriptorInfo::create(&device, &descriptor_bindings)?;
let descriptor_sets_layouts = descriptor_info
.layouts
Expand Down Expand Up @@ -571,7 +560,6 @@ impl GraphicPipeline {
layout,
name: None,
push_constants,
separate_samplers,
shader_modules,
state: GraphicPipelineState {
layout,
Expand Down
2 changes: 1 addition & 1 deletion src/driver/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl DescriptorInfo {
}
}

pub fn sampler(&self) -> Option<&Sampler> {
fn sampler(&self) -> Option<&Sampler> {
match self {
Self::CombinedImageSampler(_, sampler, _) | Self::Sampler(_, sampler, _) => {
Some(sampler)
Expand Down
25 changes: 2 additions & 23 deletions src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,6 @@ impl Resolver {
image_view_info.aspect_mask = format_aspect_mask(image.info.fmt);
}

let sampler = descriptor_info.sampler().map(|sampler| **sampler).unwrap_or_default();
let image_view = Image::view(image, image_view_info)?;
let image_layout = match descriptor_type {
vk::DescriptorType::COMBINED_IMAGE_SAMPLER | vk::DescriptorType::SAMPLED_IMAGE => {
Expand Down Expand Up @@ -2891,7 +2890,7 @@ impl Resolver {
tls.image_infos.push(vk::DescriptorImageInfo {
image_layout,
image_view,
sampler,
sampler: vk::Sampler::null(),
});
} else if let Some(buffer) = bound_node.as_driver_buffer() {
let view_info = view_info.as_ref().unwrap();
Expand Down Expand Up @@ -2941,25 +2940,6 @@ impl Resolver {
}

if let ExecutionPipeline::Graphic(pipeline) = pipeline {
for descriptor_binding @ DescriptorBinding(descriptor_set_idx, dst_binding) in pipeline.separate_samplers.iter().copied() {
tls.image_writes.push(IndexWrite {
idx: tls.image_infos.len(),
write: vk::WriteDescriptorSet {
dst_set: *descriptor_sets[descriptor_set_idx as usize],
dst_binding,
descriptor_type: vk::DescriptorType::SAMPLER,
descriptor_count: 1,
..Default::default()
},
}
);
tls.image_infos.push(vk::DescriptorImageInfo {
image_layout: Default::default(),
image_view: Default::default(),
sampler: **pipeline.descriptor_bindings[&descriptor_binding].0.sampler().unwrap(),
});
}

// Write graphic render pass input attachments (they're automatic)
if exec_idx > 0 {
for (&DescriptorBinding(descriptor_set_idx, dst_binding), (descriptor_info, _)) in
Expand Down Expand Up @@ -3000,7 +2980,6 @@ impl Resolver {
ty: image.info.ty,
};
let image_view = Image::view(image, image_view_info)?;
let sampler = descriptor_info.sampler().map(|sampler| **sampler).unwrap_or_else(vk::Sampler::null);

tls.image_writes.push(IndexWrite {
idx: tls.image_infos.len(),
Expand All @@ -3021,7 +3000,7 @@ impl Resolver {
true,
),
image_view,
sampler,
sampler: vk::Sampler::null(),
});
}
}
Expand Down

0 comments on commit 2a9b9fe

Please sign in to comment.