I have kinda given up trying to wrangle this descriptorsetbuilder. Going to read more on how sprites are best handled in regards to their textures
This commit is contained in:
48
notes
48
notes
@@ -7,3 +7,51 @@ StorageImage
|
||||
AttachmentImage
|
||||
ImageAccess whose purpose is to be used as a framebuffer attachment
|
||||
|
||||
|
||||
|
||||
|
||||
Hello!
|
||||
|
||||
Any of you guys use the Vulkano library? There is this PersistentDescriptorSetBuilder struct
|
||||
which uses this fun chaining dynamic
|
||||
|
||||
```
|
||||
PersistentDescriptorSet::start(layout, 0)
|
||||
.add_sampled_image(sampled_image1).unwrap()
|
||||
.add_sampled_image(sampled_image2).unwrap()
|
||||
.add_sampled_image(sampled_image3).unwrap()
|
||||
.build().unwrap();
|
||||
```
|
||||
|
||||
But it modifies the return values template values so I can't store it between loops
|
||||
|
||||
```
|
||||
let mut set_builder = PersistentDescriptorSet::start(layout, 0);
|
||||
for image in images {
|
||||
set_builder = set_builder.add_sampled_image(image);
|
||||
}
|
||||
let descriptor_set = set_builder.build().unwrap();
|
||||
```
|
||||
|
||||
The gist of the error that I get is something like:
|
||||
|
||||
```
|
||||
expected:
|
||||
PersistentDescriptorSetBuilder<Arc<GraphicsPipelineAbstract>, ()>
|
||||
got:
|
||||
PersistentDescriptorSetBuilder<Arc<GraphicsPipelineAbstract>, ((), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>)>
|
||||
```
|
||||
|
||||
So it's adding tuples of tuples of tuples of tuples of tuples each time I chain a
|
||||
.add_sampled_image() call. I really really want to be able to do this dynamically in
|
||||
a loop; I've tried this neat iter().fold() thinking that if I didn't explicitly
|
||||
overwrite the previous returned value, rust would figure it out. It didn't
|
||||
|
||||
```
|
||||
let descriptor_set = images.iter().fold(
|
||||
PersistentDescriptorSet::start(layout, 0)
|
||||
,|a, &b| a.add_image(b))
|
||||
.unwrap()).build().unwrap();
|
||||
```
|
||||
|
||||
How do I do this dynamically?
|
||||
@@ -1,6 +1,7 @@
|
||||
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess};
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, PersistentDescriptorSetBuilder};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, PersistentDescriptorSetBuilder, FixedSizeDescriptorSetsPool, StdDescriptorPool};
|
||||
use vulkano::descriptor::descriptor_set::collection::DescriptorSetsCollection;
|
||||
use vulkano::device::{Device, DeviceExtensions, QueuesIter, Queue};
|
||||
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, QueueFamily};
|
||||
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract};
|
||||
@@ -42,6 +43,53 @@ use crate::vkprocessor::compute_kernel::ComputeKernel;
|
||||
|
||||
mod shader_kernels;
|
||||
use crate::vkprocessor::shader_kernels::ShaderKernels;
|
||||
use vulkano::descriptor::descriptor::DescriptorDesc;
|
||||
|
||||
//
|
||||
//#[derive(Clone)]
|
||||
//struct ImageBuffers {
|
||||
// pub image_buffers : Vec<Box<ImageAccess + Send + Sync>>,
|
||||
//}
|
||||
//
|
||||
//impl ImageBuffers {
|
||||
//
|
||||
// pub fn new() -> ImageBuffers {
|
||||
// ImageBuffers {
|
||||
// image_buffers: vec![]
|
||||
// }
|
||||
// }
|
||||
// pub fn add_image(self) -> Self {
|
||||
//
|
||||
// self
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//unsafe impl DescriptorSetsCollection for ImageBuffers {
|
||||
// fn into_vec(self) -> Vec<Box<DescriptorSet>> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//
|
||||
// fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//
|
||||
// fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
@@ -103,7 +151,6 @@ unsafe impl SpecializationConstants for SimpleSpecializationConstants {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct VkProcessor<'a> {
|
||||
pub shader_kernels: Option<ShaderKernels>,
|
||||
pub compute_kernel: Option<ComputeKernel>,
|
||||
@@ -133,7 +180,7 @@ pub struct VkProcessor<'a> {
|
||||
|
||||
pub image_buffer_store : Vec<Box<ImageAccess + Send + Sync>>,
|
||||
|
||||
|
||||
// pub image_buffers_obj : ImageBuffers,
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +228,8 @@ impl<'a> VkProcessor<'a> {
|
||||
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
||||
graphics_image_swap_buffer: None,
|
||||
|
||||
image_buffer_store: vec![]
|
||||
image_buffer_store: vec![],
|
||||
//image_buffers_obj: ImageBuffers::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,18 +368,7 @@ impl<'a> VkProcessor<'a> {
|
||||
usage)
|
||||
};
|
||||
|
||||
let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear,
|
||||
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
||||
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
|
||||
|
||||
// img_set is only used in the run()'s command buffer construction
|
||||
// So, adding a get image set function, I can just build lazily
|
||||
|
||||
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(
|
||||
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0)
|
||||
.add_sampled_image(texture.clone(), sampler.clone()).unwrap()
|
||||
.add_image(compute_transfer_image.clone().unwrap().clone()).unwrap()
|
||||
.build().unwrap()));
|
||||
self.image_buffer_store.push(Box::new(texture.clone()));
|
||||
|
||||
self.graphics_image_buffer = Some(texture.clone());
|
||||
self.graphics_image_swap_buffer = Some(compute_transfer_image.clone().unwrap());
|
||||
@@ -348,6 +385,12 @@ impl<'a> VkProcessor<'a> {
|
||||
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
||||
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
|
||||
|
||||
let mut descriptor_sets = PersistentDescriptorSet::start(
|
||||
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0
|
||||
);
|
||||
|
||||
let descriptor_sets = descriptor_sets.add_sampled_image(self.graphics_image_buffer.clone().unwrap().clone(), sampler.clone()).unwrap();
|
||||
|
||||
let o : Box<DescriptorSet + Send + Sync> = Box::new(
|
||||
PersistentDescriptorSet::start(
|
||||
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0
|
||||
@@ -355,7 +398,6 @@ impl<'a> VkProcessor<'a> {
|
||||
.add_sampled_image(self.graphics_image_buffer.clone().unwrap().clone(), sampler.clone()).unwrap()
|
||||
.add_image(self.graphics_image_swap_buffer.clone().unwrap().clone()).unwrap()
|
||||
.build().unwrap());
|
||||
|
||||
o
|
||||
}
|
||||
|
||||
@@ -425,8 +467,7 @@ impl<'a> VkProcessor<'a> {
|
||||
|
||||
.draw(self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(),
|
||||
&self.dynamic_state.clone(), v,
|
||||
//self.img_set.clone().unwrap().clone(), ())
|
||||
self.get_image_set(), ())
|
||||
vec![self.get_image_set()], ())
|
||||
.unwrap()
|
||||
|
||||
.end_render_pass()
|
||||
|
||||
Reference in New Issue
Block a user