From 820b99ae4e7d3ad1e61e2f1c3230537f1ae1195e Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 7 Jul 2019 01:00:26 -0700 Subject: [PATCH] forked shade_runner and added compiler options. Going to add buttons along with a workflow for picking swatches --- Cargo.toml | 4 +++- src/button.rs | 0 src/main.rs | 5 +++-- src/util.rs | 34 ++++++++++++++++++++++++++++++++++ src/vkprocessor.rs | 12 ++++++++++-- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/button.rs diff --git a/Cargo.toml b/Cargo.toml index 5cd50bfa..ad9482e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,7 @@ rand = "0.6.5" vulkano = "0.12.0" vulkano-shaders = "0.12.0" time = "0.1.38" -shade_runner = "0.1.1" +shaderc = "0.5.0" +shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"} +#shade_runner = {version = "0.1.1", path = "../shade_runner"} diff --git a/src/button.rs b/src/button.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/main.rs b/src/main.rs index 6988df5c..37a08741 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,6 @@ use sfml::window::{Event, Key, Style}; use sfml::window::mouse::*; use sfml::window::mouse; - use vulkano::sync; use std::sync::Arc; use std::{fs, mem, iter, ptr}; @@ -30,7 +29,6 @@ use crate::slider::Slider; use crate::timer::Timer; use na::DimAdd; use std::time::{SystemTime, Duration}; -use shade_runner as sr; use std::ffi::CStr; use std::ptr::write; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess}; @@ -40,11 +38,14 @@ use vulkano::device::{Device, DeviceExtensions}; use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice}; use vulkano::pipeline::ComputePipeline; use vulkano::sync::GpuFuture; +use shaderc::CompileOptions; +use shade_runner::CompileError; mod slider; mod timer; mod input; mod vkprocessor; +mod util; // What next? diff --git a/src/util.rs b/src/util.rs index e69de29b..e8c2a924 100644 --- a/src/util.rs +++ b/src/util.rs @@ -0,0 +1,34 @@ +//use crate::error::CompileError; +//use shaderc::{IncludeType, ResolvedInclude}; +//use shaderc::{ShaderKind, CompileOptions}; +//use std::fs::File; +//use std::io::Read; +//use std::path::{Path, PathBuf}; +// +// +// +//pub fn compile(path: T, shader_kind: ShaderKind) -> Result, CompileError> +// where +// T: AsRef, +//{ +// // TODO Probably shouldn't create this every time. +// let mut compiler = shaderc::Compiler::new().ok_or(CompileError::CreateCompiler)?; +// let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler)?; +// let mut f = File::open(&path).map_err(CompileError::Open)?; +// let mut src = String::new(); +// f.read_to_string(&mut src).map_err(CompileError::Open)?; +// options.set_include_callback(|path, include_type, folder_path, depth| { +// get_include(path, include_type, folder_path, depth) +// }); +// let result = compiler +// .compile_into_spirv( +// src.as_str(), +// shader_kind, +// path.as_ref().to_str().ok_or(CompileError::InvalidPath)?, +// "main", +// Some(&options), +// ) +// .map_err(CompileError::Compile)?; +// let data = result.as_binary(); +// Ok(data.to_owned()) +//} \ No newline at end of file diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 00a710f3..1c96d1e8 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -15,8 +15,9 @@ use image::{DynamicImage, ImageBuffer}; use image::GenericImageView; use vulkano::descriptor::pipeline_layout::PipelineLayout; use image::GenericImage; -use shade_runner::ComputeLayout; +use shade_runner::{ComputeLayout, CompileError}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSetBuf; +use shaderc::CompileOptions; pub struct VkProcessor<'a> { pub instance: Arc, @@ -68,8 +69,15 @@ impl<'a> VkProcessor<'a> { compute_path.push(PathBuf::from("resources/shaders/")); compute_path.push(PathBuf::from(filename)); + + let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); + options.add_macro_definition("SETTING_POS_X", Some("0")); + options.add_macro_definition("SETTING_POS_Y", Some("1")); + options.add_macro_definition("SETTING_BUCKETS_START", Some("2")); + options.add_macro_definition("SETTING_BUCKETS_LEN", Some("2")); + let shader = - sr::load_compute(compute_path) + sr::load_compute_with_options(compute_path, options) .expect("Failed to compile"); let vulkano_entry =