adding a second image buffer for GPU only access. Immutable buffer is write once for textures only. No sampler for regular image buffer though??

master
mitchellhansen 6 years ago
parent 937b4fc8ca
commit 4d5b09e9ca

@ -31,6 +31,7 @@ use std::alloc::Layout;
use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::viewport::Viewport;
use image::ImageFormat; use image::ImageFormat;
use vulkano::image::immutable::ImmutableImage; use vulkano::image::immutable::ImmutableImage;
use vulkano::image::attachment::AttachmentImage;
use vulkano::image::Dimensions; use vulkano::image::Dimensions;
use vulkano::format::Format; use vulkano::format::Format;
use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode}; use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode};
@ -114,6 +115,7 @@ pub struct VkProcessor<'a> {
pub render_pass: Option<Arc<RenderPassAbstract + Send + Sync>>, pub render_pass: Option<Arc<RenderPassAbstract + Send + Sync>>,
pub vertex_buffer: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>, pub vertex_buffer: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
pub dynamic_state: DynamicState, pub dynamic_state: DynamicState,
pub graphics_iamge_swap_buffer: Option<i32>,
} }
@ -157,6 +159,7 @@ impl<'a> VkProcessor<'a> {
render_pass: Option::None, render_pass: Option::None,
vertex_buffer: Option::None, vertex_buffer: Option::None,
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None }, dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
graphics_iamge_swap_buffer: None,
} }
} }
@ -338,13 +341,24 @@ impl<'a> VkProcessor<'a> {
).unwrap() ).unwrap()
}; };
let image = {
let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"),
ImageFormat::JPEG).unwrap().to_rgba();
let dimensions = image.dimensions();
let image_data = image.into_raw().clone();
AttachmentImage::new(self.device.clone(),
[dimensions.0, dimensions.1],
Format::R8G8B8A8Srgb)
};
let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear, let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear,
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat, MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(); SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
// Before we draw we have to create what is called a pipeline. This is similar to an OpenGL // Before we draw we have to create what is called a pipeline. This is similar to an OpenGL
// program, but much more specific. // program, but much more specific.
let pipeline = GraphicsPipeline::start() let pipeline = GraphicsPipeline::start()
// We need to indicate the layout of the vertices. // We need to indicate the layout of the vertices.
// The type `SingleBufferDefinition` actually contains a template parameter corresponding // The type `SingleBufferDefinition` actually contains a template parameter corresponding
@ -380,10 +394,12 @@ impl<'a> VkProcessor<'a> {
self.graphics_pipeline = Some(Arc::new(pipeline)); self.graphics_pipeline = Some(Arc::new(pipeline));
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0) self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0)
.add_sampled_image(texture.clone(), sampler.clone()).unwrap() .add_sampled_image(texture.clone(), sampler.clone()).unwrap()
.build().unwrap())); .add_image(image.unwrap().clone()).unwrap()
.build().unwrap()));
self.graphics_image_buffer = Some(texture.clone()); self.graphics_image_buffer = Some(texture.clone());
self.graphics_iamge_swap_buffer = Some(image.clone().unwrap());
} }
@ -468,7 +484,7 @@ impl<'a> VkProcessor<'a> {
self.compute_pipeline.clone().unwrap().clone(), self.compute_pipeline.clone().unwrap().clone(),
self.compute_set.clone().unwrap().clone(), ()).unwrap() self.compute_set.clone().unwrap().clone(), ()).unwrap()
// .copy_buffer_to_image(self.img_buffers.get(0).unwrap().clone(), self.graphics_image_buffer.clone().unwrap()).unwrap() //.copy_buffer_to_image(self.img_buffers.get(0).unwrap().clone(), self.graphics_image_buffer.clone().unwrap()).unwrap()
.begin_render_pass(framebuffers[image_num].clone(), false, clear_values) .begin_render_pass(framebuffers[image_num].clone(), false, clear_values)
.unwrap() .unwrap()

Loading…
Cancel
Save