|
|
|
@ -75,66 +75,26 @@ fn window_size_dependent_setup(
|
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Default, Debug, Clone)]
|
|
|
|
|
struct SimpleSpecializationConstants {
|
|
|
|
|
first_constant: i32,
|
|
|
|
|
second_constant: u32,
|
|
|
|
|
third_constant: f32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe impl SpecializationConstants for SimpleSpecializationConstants {
|
|
|
|
|
fn descriptors() -> &'static [SpecializationMapEntry] {
|
|
|
|
|
static DESCRIPTORS: [SpecializationMapEntry; 3] = [
|
|
|
|
|
SpecializationMapEntry {
|
|
|
|
|
constant_id: 0,
|
|
|
|
|
offset: 0,
|
|
|
|
|
size: 4,
|
|
|
|
|
},
|
|
|
|
|
SpecializationMapEntry {
|
|
|
|
|
constant_id: 1,
|
|
|
|
|
offset: 4,
|
|
|
|
|
size: 4,
|
|
|
|
|
},
|
|
|
|
|
SpecializationMapEntry {
|
|
|
|
|
constant_id: 2,
|
|
|
|
|
offset: 8,
|
|
|
|
|
size: 4,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
&DESCRIPTORS
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct VkProcessor<'a> {
|
|
|
|
|
pub shader_kernels: Option<ShaderKernels>,
|
|
|
|
|
pub compute_kernel: Option<ComputeKernel>,
|
|
|
|
|
pub vertex_shader_path: PathBuf,
|
|
|
|
|
pub fragment_shader_path: PathBuf,
|
|
|
|
|
|
|
|
|
|
// Vulkan state fields
|
|
|
|
|
pub instance: Arc<Instance>,
|
|
|
|
|
pub physical: PhysicalDevice<'a>,
|
|
|
|
|
pub graphics_pipeline: Option<Arc<GraphicsPipelineAbstract + Sync + Send>>,
|
|
|
|
|
pub compute_pipeline: Option<std::sync::Arc<ComputePipeline<PipelineLayout<shade_runner::layouts::ComputeLayout>>>>,
|
|
|
|
|
pub device: Arc<Device>,
|
|
|
|
|
pub queues: QueuesIter,
|
|
|
|
|
pub queue: Arc<Queue>,
|
|
|
|
|
pub compute_set: Option<Arc<PersistentDescriptorSet<std::sync::Arc<ComputePipeline<PipelineLayout<shade_runner::layouts::ComputeLayout>>>, ((((), PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<[u8]>>>), PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<[u8]>>>), PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<[u32]>>>)>>>,
|
|
|
|
|
pub img_set: Option<Arc<PersistentDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((((), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>), PersistentDescriptorSetSampler), PersistentDescriptorSetImg<Arc<AttachmentImage>>)>>>,
|
|
|
|
|
pub graphics_image_buffer: Option<Arc<ImmutableImage<Format>>>,
|
|
|
|
|
pub image_buffer: Vec<u8>,
|
|
|
|
|
pub compute_image_buffers: Vec<Arc<CpuAccessibleBuffer<[u8]>>>,
|
|
|
|
|
pub settings_buffer: Option<Arc<CpuAccessibleBuffer<[u32]>>>,
|
|
|
|
|
|
|
|
|
|
pub xy: (u32, u32),
|
|
|
|
|
pub vertex_buffer: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
pub vertex_buffer2: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
pub dynamic_state: DynamicState,
|
|
|
|
|
pub graphics_image_swap_buffer: Option<Arc<AttachmentImage>>,
|
|
|
|
|
|
|
|
|
|
// TODO: This will need to handle multiple of each type
|
|
|
|
|
pub shader_kernels: Option<ShaderKernels>,
|
|
|
|
|
pub compute_kernel: Option<ComputeKernel>,
|
|
|
|
|
|
|
|
|
|
// TODO: Move this into canvas
|
|
|
|
|
pub vertex_buffer: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
pub vertex_buffer2: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
|
|
|
|
|
pub textures: Vec<Arc<ImmutableImage<Format>>>,
|
|
|
|
|
pub image_buffer_store : Vec<Box<ImageAccess + Send + Sync>>,
|
|
|
|
|
|
|
|
|
|
pub compute_image: Option<ComputeImage>,
|
|
|
|
|
|
|
|
|
|
pub swapchain: Option<Arc<Swapchain<Window>>>,
|
|
|
|
@ -164,35 +124,18 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
let queue = queues.next().unwrap();
|
|
|
|
|
|
|
|
|
|
VkProcessor {
|
|
|
|
|
shader_kernels: Option::None,
|
|
|
|
|
compute_kernel: Option::None,
|
|
|
|
|
vertex_shader_path: Default::default(),
|
|
|
|
|
fragment_shader_path: Default::default(),
|
|
|
|
|
instance: instance.clone(),
|
|
|
|
|
physical: physical.clone(),
|
|
|
|
|
graphics_pipeline: Option::None,
|
|
|
|
|
compute_pipeline: Option::None,
|
|
|
|
|
device: device.clone(),
|
|
|
|
|
queue: queue,
|
|
|
|
|
queues: queues,
|
|
|
|
|
compute_set: Option::None,
|
|
|
|
|
img_set: Option::None,
|
|
|
|
|
graphics_image_buffer: None,
|
|
|
|
|
image_buffer: Vec::new(),
|
|
|
|
|
compute_image_buffers: Vec::new(),
|
|
|
|
|
settings_buffer: Option::None,
|
|
|
|
|
xy: (0, 0),
|
|
|
|
|
|
|
|
|
|
vertex_buffer: Option::None,
|
|
|
|
|
vertex_buffer2: None,
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
|
|
|
|
graphics_image_swap_buffer: None,
|
|
|
|
|
|
|
|
|
|
shader_kernels: None,
|
|
|
|
|
compute_kernel: None,
|
|
|
|
|
vertex_buffer: None,
|
|
|
|
|
vertex_buffer2: None,
|
|
|
|
|
textures: vec![],
|
|
|
|
|
image_buffer_store: vec![],
|
|
|
|
|
compute_image: None,
|
|
|
|
|
|
|
|
|
|
swapchain: None,
|
|
|
|
|
swapchain_images: None
|
|
|
|
|
}
|
|
|
|
@ -201,7 +144,6 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
pub fn compile_kernel(&mut self, filename: String) {
|
|
|
|
|
self.compute_kernel = Some(ComputeKernel::new(filename, self.device.clone()));
|
|
|
|
|
self.compute_pipeline = Some(self.compute_kernel.clone().unwrap().get_pipeline());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn compile_shaders(&mut self, filename: String, surface: &'a Arc<Surface<Window>>) {
|
|
|
|
@ -323,40 +265,6 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
{
|
|
|
|
|
self.load_compute_image(image_filename.clone());
|
|
|
|
|
|
|
|
|
|
let project_root =
|
|
|
|
|
std::env::current_dir()
|
|
|
|
|
.expect("failed to get root directory");
|
|
|
|
|
|
|
|
|
|
let mut compute_path = project_root.clone();
|
|
|
|
|
compute_path.push(PathBuf::from("resources/images/"));
|
|
|
|
|
compute_path.push(PathBuf::from(image_filename.clone()));
|
|
|
|
|
|
|
|
|
|
let img = image::open(compute_path).expect("Couldn't find image");
|
|
|
|
|
|
|
|
|
|
self.xy = img.dimensions();
|
|
|
|
|
|
|
|
|
|
let data_length = self.xy.0 * self.xy.1 * 4;
|
|
|
|
|
let pixel_count = img.raw_pixels().len();
|
|
|
|
|
println!("Pixel count {}", pixel_count);
|
|
|
|
|
|
|
|
|
|
if pixel_count != data_length as usize {
|
|
|
|
|
println!("Creating apha channel...");
|
|
|
|
|
for i in img.raw_pixels().iter() {
|
|
|
|
|
if (self.image_buffer.len() + 1) % 4 == 0 {
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
}
|
|
|
|
|
self.image_buffer.push(*i);
|
|
|
|
|
}
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
} else {
|
|
|
|
|
self.image_buffer = img.raw_pixels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println!("Buffer length {}", self.image_buffer.len());
|
|
|
|
|
println!("Size {:?}", self.xy);
|
|
|
|
|
|
|
|
|
|
println!("Allocating Buffers...");
|
|
|
|
|
|
|
|
|
|
let color = [1.,0.,0.,0.];
|
|
|
|
|
|
|
|
|
|
let vertex_buffer = {
|
|
|
|
@ -399,7 +307,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
let o : Box<DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0
|
|
|
|
|
self.shader_kernels.clone().unwrap().get_pipeline(), 0
|
|
|
|
|
)
|
|
|
|
|
.add_sampled_image(self.textures.get(0).unwrap().clone(), sampler.clone()).unwrap()
|
|
|
|
|
.add_image(self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
@ -416,7 +324,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
let o : Box<DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0
|
|
|
|
|
self.shader_kernels.clone().unwrap().get_pipeline(), 0
|
|
|
|
|
)
|
|
|
|
|
.add_sampled_image(self.textures.get(1).unwrap().clone(), sampler.clone()).unwrap()
|
|
|
|
|
.add_image(self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
@ -473,14 +381,16 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
let mut v2 = Vec::new();
|
|
|
|
|
v2.push(self.vertex_buffer2.clone().unwrap().clone());
|
|
|
|
|
|
|
|
|
|
let xy = self.compute_image.clone().unwrap().get_size();
|
|
|
|
|
|
|
|
|
|
let command_buffer =
|
|
|
|
|
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family())
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
|
|
.dispatch([self.xy.0, self.xy.1, 1],
|
|
|
|
|
self.compute_pipeline.clone().unwrap().clone(),
|
|
|
|
|
self.compute_image.clone().unwrap().clone().get_descriptor_set(self.compute_pipeline.clone().unwrap().clone()).clone(), ()).unwrap()
|
|
|
|
|
//self.compute_set.clone().unwrap().clone(), ()).unwrap()
|
|
|
|
|
.dispatch([xy.0, xy.1, 1],
|
|
|
|
|
self.compute_kernel.clone().unwrap().clone().get_pipeline(),
|
|
|
|
|
self.compute_image.clone().unwrap().clone()
|
|
|
|
|
.get_descriptor_set(self.compute_kernel.clone().unwrap().clone().get_pipeline()).clone(), ()).unwrap()
|
|
|
|
|
|
|
|
|
|
.copy_buffer_to_image(self.compute_image.clone().unwrap().clone().rw_buffers.get(0).unwrap().clone(),
|
|
|
|
|
self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
@ -488,12 +398,12 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
.begin_render_pass(framebuffers[image_num].clone(), false, clear_values)
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
|
|
.draw(self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(),
|
|
|
|
|
.draw(self.shader_kernels.clone().unwrap().get_pipeline(),
|
|
|
|
|
&self.dynamic_state.clone(), v,
|
|
|
|
|
vec![self.get_image_set()], ())
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
|
|
.draw(self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(),
|
|
|
|
|
.draw(self.shader_kernels.clone().unwrap().get_pipeline(),
|
|
|
|
|
&self.dynamic_state.clone(), v2,
|
|
|
|
|
vec![self.get_gui_image_set()], ())
|
|
|
|
|
.unwrap()
|
|
|
|
|