From 0be20eb959f51e5c71c031151c14e7608e8aa6da Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 11 Aug 2019 17:23:58 -0700 Subject: [PATCH] removed the extra stuff from the kernels. Having some issues with the layouts not agreeing with the set size... --- resources/shaders/color-passthrough.fragment | 6 +--- resources/shaders/color-passthrough.vertex | 3 +- resources/shaders/simple_texture.fragment | 13 ++++----- resources/shaders/simple_texture.vertex | 3 -- src/canvas.rs | 17 +++++------ src/input.rs | 1 - src/main.rs | 30 ++------------------ src/sprite.rs | 1 - src/util/compute_image.rs | 1 - src/util/compute_kernel.rs | 29 ------------------- src/vkprocessor.rs | 9 ++---- 11 files changed, 21 insertions(+), 92 deletions(-) diff --git a/resources/shaders/color-passthrough.fragment b/resources/shaders/color-passthrough.fragment index cd2ee6df..5f7ea3be 100644 --- a/resources/shaders/color-passthrough.fragment +++ b/resources/shaders/color-passthrough.fragment @@ -1,12 +1,8 @@ #version 450 -layout(location = 0) in vec2 tex_coords; -layout(location = 1) in vec4 out_color; +layout(location = 0) in vec4 out_color; layout(location = 0) out vec4 f_color; -layout(set = 0, binding = 0) uniform sampler2D tex; -layout(set = 0, binding = 1, rgba32ui) readonly uniform uimage2D img; - void main() { f_color = out_color; } \ No newline at end of file diff --git a/resources/shaders/color-passthrough.vertex b/resources/shaders/color-passthrough.vertex index 9be947e5..6ecded1e 100644 --- a/resources/shaders/color-passthrough.vertex +++ b/resources/shaders/color-passthrough.vertex @@ -2,8 +2,7 @@ layout(location = 0) in vec2 position; layout(location = 1) in vec4 color; -layout(location = 0) out vec2 tex_coords; -layout(location = 1) out vec4 out_color; +layout(location = 0) out vec4 out_color; void main() { out_color = color; diff --git a/resources/shaders/simple_texture.fragment b/resources/shaders/simple_texture.fragment index 07fcc053..d38a0c5e 100644 --- a/resources/shaders/simple_texture.fragment +++ b/resources/shaders/simple_texture.fragment @@ -1,21 +1,18 @@ #version 450 layout(location = 0) in vec2 tex_coords; -layout(location = 1) in vec4 out_color; layout(location = 0) out vec4 f_color; layout(set = 0, binding = 0) uniform sampler2D tex; -layout(set = 0, binding = 1, rgba32ui) readonly uniform uimage2D img; void main() { ivec2 pos = ivec2(gl_FragCoord.x, gl_FragCoord.y); - f_color = imageLoad(img, ivec2(pos)) / (255.0); +// f_color = imageLoad(img, ivec2(pos)) / (255.0); +// +// float gamma = 0.5; +// f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); - float gamma = 0.5; - f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); - - //f_color = out_color; - // f_color = texture(tex, tex_coords); + 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 ebac0b4f..5f5af841 100644 --- a/resources/shaders/simple_texture.vertex +++ b/resources/shaders/simple_texture.vertex @@ -1,12 +1,9 @@ #version 450 layout(location = 0) in vec2 position; -layout(location = 1) in vec4 color; layout(location = 0) out vec2 tex_coords; -layout(location = 1) out vec4 out_color; void main() { - out_color = color; gl_Position = vec4(position, 0.0, 1.0); tex_coords = position; diff --git a/src/canvas.rs b/src/canvas.rs index 92ff7611..43857f6e 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -1,6 +1,5 @@ use crate::vertex_2d::{ColoredVertex2D, Vertex2D}; use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState}; - use std::collections::HashMap; use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer}; use std::sync::Arc; @@ -19,7 +18,6 @@ use image::GenericImageView; use crate::util::compute_image::ComputeImage; use std::iter::FromIterator; use vulkano::swapchain::Capabilities; - use winit::Window; use vulkano::pipeline::viewport::Viewport; @@ -128,7 +126,7 @@ impl Canvas { let shader_kernels = HashMap::from_iter(vec![ (ShaderType::SOLID, ShaderKernels::new(solid_color_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone())), - (ShaderType::TEXTURED, ShaderKernels::new(texture_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone())) + //(ShaderType::TEXTURED, ShaderKernels::new(texture_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone())) ]); Canvas { @@ -271,6 +269,9 @@ impl Canvas { } fn get_solid_color_descriptor_set(&self) -> Box { + + println!("{}", self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone().num_sets()); + let o: Box = Box::new( PersistentDescriptorSet::start( self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone(), 0 @@ -338,11 +339,11 @@ impl Canvas { ).unwrap(); }, ShaderType::TEXTURED => { - command_buffer = command_buffer.draw( - kernel.clone().get_pipeline().clone(), - &dynamic_state.clone(), self.colored_vertex_buffer.clone(), - vec![self.get_textured_descriptor_set(String::from("funky-bird"))], () - ).unwrap(); +// command_buffer = command_buffer.draw( +// kernel.clone().get_pipeline().clone(), +// &dynamic_state.clone(), self.textured_vertex_buffer.clone(), +// vec![self.get_textured_descriptor_set(String::from("funky-bird.jpg"))], () +// ).unwrap(); }, ShaderType::COMPUTE => {}, } diff --git a/src/input.rs b/src/input.rs index 735c6507..18e3adfd 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,7 +1,6 @@ use std::collections::HashSet; use sfml::window::{Key, Event, mouse::Button}; - pub struct Input { held_keys: HashSet, held_mouse: HashSet, diff --git a/src/main.rs b/src/main.rs index d4120f75..d106d32f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,36 +10,11 @@ extern crate rand; extern crate sfml; extern crate time; - - use sfml::system::*; - - - - use vulkano::sync; - - - - - - - use crate::timer::Timer; - - - - - - - - use vulkano::instance::{Instance}; - - use vulkano::sync::GpuFuture; - - use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualKeyCode, ElementState}; use winit::dpi::LogicalSize; use vulkano_win::VkSurfaceBuild; @@ -47,7 +22,6 @@ use sprite::Sprite; mod util; - mod slider; mod timer; mod input; @@ -73,7 +47,8 @@ fn main() { let mut processor = vkprocessor::VkProcessor::new(&instance, &surface); processor.compile_kernel(String::from("simple-edge.compute")); - processor.load_textures(String::from("background.jpg")); + processor.load_compute_image(String::from("background.jpg")); + processor.load_textures(String::from("funky-bird.jpg")); processor.create_swapchain(&surface); let mut timer = Timer::new(); @@ -136,6 +111,7 @@ fn main() { } + (frame_future) = processor.run(&surface, frame_future); } } diff --git a/src/sprite.rs b/src/sprite.rs index 1f6be35e..9d0adaa3 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -1,4 +1,3 @@ - use crate::canvas::Drawable; #[derive(Debug, Clone)] diff --git a/src/util/compute_image.rs b/src/util/compute_image.rs index 2e26268a..51f27ab4 100644 --- a/src/util/compute_image.rs +++ b/src/util/compute_image.rs @@ -1,5 +1,4 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; - use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet}; use vulkano::device::{Device}; use vulkano::pipeline::{ComputePipeline}; diff --git a/src/util/compute_kernel.rs b/src/util/compute_kernel.rs index b9f750bc..f2c5d4d8 100644 --- a/src/util/compute_kernel.rs +++ b/src/util/compute_kernel.rs @@ -1,43 +1,14 @@ - - - use vulkano::device::{Device}; - use vulkano::pipeline::{ComputePipeline}; - - - use std::sync::Arc; use std::ffi::CStr; use std::path::PathBuf; use shade_runner as sr; - - use vulkano::descriptor::pipeline_layout::PipelineLayout; - use shade_runner::{CompileError, FragLayout, FragInput, FragOutput, VertInput, VertOutput, VertLayout, CompiledShaders, Entry}; - use shaderc::CompileOptions; - use vulkano::pipeline::shader::{ShaderModule, GraphicsEntryPoint, SpecializationConstants, SpecializationMapEntry}; - - - - - - - - - - - - - - - - - #[derive(Clone)] pub struct ComputeKernel { diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index b776ca9e..998526ed 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -12,6 +12,7 @@ use crate::util::compute_image::ComputeImage; use crate::canvas::Canvas; pub struct VkProcessor<'a> { + // Vulkan state fields pub instance: Arc, pub physical: PhysicalDevice<'a>, @@ -20,7 +21,6 @@ pub struct VkProcessor<'a> { pub queue: Arc, pub dynamic_state: DynamicState, - // TODO: This will need to handle multiple of each type pub compute_kernel: Option, pub compute_image: Option, @@ -138,10 +138,7 @@ impl<'a> VkProcessor<'a> { self.compute_image = Some(ComputeImage::new(self.device.clone(), image_filename.clone())); } - pub fn load_textures(&mut self, image_filename: String) - { - self.load_compute_image(image_filename.clone()); - + pub fn load_textures(&mut self, image_filename: String) { self.canvas.load_texture_from_filename(image_filename.clone()); } @@ -149,7 +146,6 @@ impl<'a> VkProcessor<'a> { self.compute_image.clone().unwrap().clone().save_image(); } - pub fn run(&mut self, surface: &'a Arc>, mut frame_future: Box, @@ -180,7 +176,6 @@ impl<'a> VkProcessor<'a> { Err(err) => panic!("{:?}", err) }; - let xy = self.compute_image.clone().unwrap().get_size(); let mut command_buffer =