From 26410b78a2497772fedda9de018842e7a23c1bc9 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Wed, 17 Jul 2019 20:11:53 -0700 Subject: [PATCH] Got something working. Need to test and verify I'm getting the data from the compute kernel --- Cargo.toml | 4 ++-- notes | 9 +++++++++ resources/shaders/simple_texture.fragment | 1 + resources/shaders/simple_texture.vertex | 6 +++++- src/vkprocessor.rs | 24 ++++++++++++++--------- 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 notes diff --git a/Cargo.toml b/Cargo.toml index df50f314..cd39eecb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ vulkano-shaders = "0.13.0" vulkano-win = "0.13.0" time = "0.1.38" shaderc = "0.5.0" -shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"} -#shade_runner = {path = "../shade_runner"} +#shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"} +shade_runner = {path = "../shade_runner"} winit = "0.19.1" \ No newline at end of file diff --git a/notes b/notes new file mode 100644 index 00000000..eb345f39 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ + + + + +StorageImage + General-purpose image in device memory. +AttachmentImage + ImageAccess whose purpose is to be used as a framebuffer attachment + diff --git a/resources/shaders/simple_texture.fragment b/resources/shaders/simple_texture.fragment index 30cb5d7f..3a91974e 100644 --- a/resources/shaders/simple_texture.fragment +++ b/resources/shaders/simple_texture.fragment @@ -2,6 +2,7 @@ layout(location = 0) in vec2 tex_coords; layout(location = 0) out vec4 f_color; layout(set = 0, binding = 0) uniform sampler2D tex; +layout(set = 0, binding = 1, rgba8ui) readonly uniform uimage2D img; void main() { f_color = texture(tex, tex_coords); } \ No newline at end of file diff --git a/resources/shaders/simple_texture.vertex b/resources/shaders/simple_texture.vertex index 82553791..c51506a3 100644 --- a/resources/shaders/simple_texture.vertex +++ b/resources/shaders/simple_texture.vertex @@ -4,4 +4,8 @@ layout(location = 0) out vec2 tex_coords; void main() { gl_Position = vec4(position, 0.0, 1.0); tex_coords = position; -} \ No newline at end of file +} + + + + diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 129faf77..a984e66d 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -32,7 +32,7 @@ use vulkano::pipeline::viewport::Viewport; use image::ImageFormat; use vulkano::image::immutable::ImmutableImage; use vulkano::image::attachment::AttachmentImage; -use vulkano::image::Dimensions; +use vulkano::image::{Dimensions, ImageUsage}; use vulkano::format::Format; use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode}; @@ -104,7 +104,7 @@ pub struct VkProcessor<'a> { pub queues: QueuesIter, pub queue: Arc, pub compute_set: Option>>, ((((), PersistentDescriptorSetBuf>>), PersistentDescriptorSetBuf>>), PersistentDescriptorSetBuf>>)>>>, - pub img_set: Option, (((), PersistentDescriptorSetImg>>), PersistentDescriptorSetSampler)>>>, + pub img_set: Option, ((((), PersistentDescriptorSetImg>>), PersistentDescriptorSetSampler), PersistentDescriptorSetImg>)>>>, pub graphics_image_buffer: Option>>, pub image_buffer: Vec, pub img_buffers: Vec>>, @@ -115,7 +115,7 @@ pub struct VkProcessor<'a> { pub render_pass: Option>, pub vertex_buffer: Option>, pub dynamic_state: DynamicState, - pub graphics_iamge_swap_buffer: Option, + pub graphics_iamge_swap_buffer: Option>, } @@ -341,15 +341,21 @@ impl<'a> VkProcessor<'a> { ).unwrap() }; - let image = { + let attachment_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 mut usage = ImageUsage::none(); + usage.transfer_destination = true; + usage.storage = true; + + AttachmentImage::with_usage( + self.device.clone(), + [dimensions.0, dimensions.1], + Format::R8G8B8A8Uint, + usage) }; let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear, @@ -395,11 +401,11 @@ impl<'a> VkProcessor<'a> { self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0) .add_sampled_image(texture.clone(), sampler.clone()).unwrap() - .add_image(image.unwrap().clone()).unwrap() + .add_image(attachment_image.clone().unwrap().clone()).unwrap() .build().unwrap())); self.graphics_image_buffer = Some(texture.clone()); - self.graphics_iamge_swap_buffer = Some(image.clone().unwrap()); + self.graphics_iamge_swap_buffer = Some(attachment_image.clone().unwrap()); }