Switch to vk_shader_macros

This commit is contained in:
Jay Oster 2019-09-29 17:40:05 -07:00
parent 9f1afdd3b3
commit 337241c866
3 changed files with 61 additions and 41 deletions

60
Cargo.lock generated
View file

@ -683,8 +683,8 @@ version = "0.0.1"
dependencies = [ dependencies = [
"env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-spirv 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-window-handle 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "raw-window-handle 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"vk-shader-macros 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wgpu 0.3.0 (git+https://github.com/gfx-rs/wgpu-rs?rev=697393df4793e1a58578209885036114adfb9213)", "wgpu 0.3.0 (git+https://github.com/gfx-rs/wgpu-rs?rev=697393df4793e1a58578209885036114adfb9213)",
"winit 0.20.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)", "winit 0.20.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -694,6 +694,16 @@ name = "pkg-config"
version = "0.3.16" version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro-hack"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "0.4.30" version = "0.4.30"
@ -710,15 +720,6 @@ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "proc-spirv"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"shaderc 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "quick-error" name = "quick-error"
version = "1.2.2" version = "1.2.2"
@ -873,7 +874,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "shaderc" name = "shaderc"
version = "0.3.16" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"shaderc-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "shaderc-sys"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1002,6 +1012,27 @@ name = "vec_map"
version = "0.8.1" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vk-shader-macros"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"vk-shader-macros-impl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "vk-shader-macros-impl"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"shaderc 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"
@ -1374,9 +1405,9 @@ dependencies = [
"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
"checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea" "checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea"
"checksum proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e688f31d92ffd7c1ddc57a1b4e6d773c0f2a14ee437a4b0a4f5a69c80eb221c8"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afdc77cc74ec70ed262262942ebb7dac3d479e9e5cfa2da1841c0806f6cdabcc" "checksum proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afdc77cc74ec70ed262262942ebb7dac3d479e9e5cfa2da1841c0806f6cdabcc"
"checksum proc-spirv 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "02dedb5c7eaecb1fe3af7f37aa7a780c4409ff287ad920999234d758ab42ae2d"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
@ -1396,7 +1427,8 @@ dependencies = [
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum shaderc 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "d82d2c3e2d3777674ae9269a3bc1b4c2851f9b5e96dc4335e2f08a76b334482b" "checksum shaderc 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4abc3402ee1b3054a847ad1efd2c7d2721c64caf1c03bed94c461d7a1635b4"
"checksum shaderc-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "96874aafeb936b4c9b0c4fa1c79b1abdeac9289700efc5a313c3f65c95fa3f62"
"checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
@ -1412,6 +1444,8 @@ dependencies = [
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum vk-shader-macros 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a5246331741991945d983e1507507b973ac8eb65eca15de1b109cc939370a4d1"
"checksum vk-shader-macros-impl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4941ca9c0867ee70ebd9680bdcd659ff53d2d789c65586500da2ff0aa813f7b7"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" "checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
"checksum wasm-bindgen 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "dcddca308b16cd93c2b67b126c688e5467e4ef2e28200dc7dfe4ae284f2faefc" "checksum wasm-bindgen 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "dcddca308b16cd93c2b67b126c688e5467e4ef2e28200dc7dfe4ae284f2faefc"

View file

@ -11,7 +11,7 @@ categories = ["graphics", "rendering"]
license = "MIT" license = "MIT"
[dependencies] [dependencies]
proc-spirv = "0.0.1" vk-shader-macros = "0.2"
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs", rev = "697393df4793e1a58578209885036114adfb9213" } wgpu = { git = "https://github.com/gfx-rs/wgpu-rs", rev = "697393df4793e1a58578209885036114adfb9213" }
[dev-dependencies] [dev-dependencies]

View file

@ -11,14 +11,10 @@
//! manager of your choice; [`winit`](https://crates.io/crates/winit) is a good //! manager of your choice; [`winit`](https://crates.io/crates/winit) is a good
//! place to start. //! place to start.
// Needed for proc-spirv
#![feature(proc_macro_hygiene)]
use std::error::Error as StdError; use std::error::Error as StdError;
use std::fmt; use std::fmt;
use std::io::Cursor;
use proc_spirv::spirv_from_file; use vk_shader_macros::include_glsl;
pub use wgpu; pub use wgpu;
/// Represents a 2D frame buffer with an explicit image resolution. /// Represents a 2D frame buffer with an explicit image resolution.
@ -36,8 +32,8 @@ pub struct Pixels {
pub struct PixelsOptions { pub struct PixelsOptions {
request_adapter_options: wgpu::RequestAdapterOptions, request_adapter_options: wgpu::RequestAdapterOptions,
device_descriptor: wgpu::DeviceDescriptor, device_descriptor: wgpu::DeviceDescriptor,
vertex_spirv: Vec<u8>, vertex_spirv: Vec<u32>,
fragment_spirv: Vec<u8>, fragment_spirv: Vec<u32>,
} }
/// All the ways in which creating a frame buffer can fail. /// All the ways in which creating a frame buffer can fail.
@ -110,14 +106,8 @@ impl Pixels {
let adapter = wgpu::Adapter::request(&options.request_adapter_options) let adapter = wgpu::Adapter::request(&options.request_adapter_options)
.ok_or(Error::AdapterNotFound)?; .ok_or(Error::AdapterNotFound)?;
let (device, queue) = adapter.request_device(&options.device_descriptor); let (device, queue) = adapter.request_device(&options.device_descriptor);
let vs_module = device.create_shader_module( let vs_module = device.create_shader_module(&options.vertex_spirv);
&wgpu::read_spirv(Cursor::new(&options.vertex_spirv)) let fs_module = device.create_shader_module(&options.fragment_spirv);
.map_err(|_| Error::VertexShaderInvalid)?,
);
let fs_module = device.create_shader_module(
&wgpu::read_spirv(Cursor::new(&options.fragment_spirv))
.map_err(|_| Error::FragmentShaderInvalid)?,
);
// The rest of this is technically a fixed-function pipeline... For now! // The rest of this is technically a fixed-function pipeline... For now!
let bind_group_layout = let bind_group_layout =
@ -214,8 +204,7 @@ impl Pixels {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(proc_macro_hygiene)] /// use vk_shader_macros::include_glsl;
/// use proc_spirv::spirv_from_file;
/// ///
/// # use pixels::PixelsOptions; /// # use pixels::PixelsOptions;
/// # struct RWH(); /// # struct RWH();
@ -247,7 +236,7 @@ impl Pixels {
/// # fn main() -> Result<(), pixels::Error> { /// # fn main() -> Result<(), pixels::Error> {
/// # let surface = wgpu::Surface::create(&RWH()); /// # let surface = wgpu::Surface::create(&RWH());
/// let fb = PixelsOptions::new() /// let fb = PixelsOptions::new()
/// .fragment_spirv(spirv_from_file!(Fragment, "shaders/shader.frag", "main").to_vec()) /// .fragment_spirv(include_glsl!("shaders/shader.frag"))
/// .build(320, 240, &surface)?; /// .build(320, 240, &surface)?;
/// # Ok(()) /// # Ok(())
/// # } /// # }
@ -271,14 +260,14 @@ impl PixelsOptions {
} }
/// Set a SPIR-V vertex shader. /// Set a SPIR-V vertex shader.
pub fn vertex_spirv(mut self, spirv: Vec<u8>) -> PixelsOptions { pub fn vertex_spirv(mut self, spirv: &[u32]) -> PixelsOptions {
self.vertex_spirv = spirv; self.vertex_spirv = spirv.to_vec();
self self
} }
/// Set a SPIR-V fragment shader. /// Set a SPIR-V fragment shader.
pub fn fragment_spirv(mut self, spirv: Vec<u8>) -> PixelsOptions { pub fn fragment_spirv(mut self, spirv: &[u32]) -> PixelsOptions {
self.fragment_spirv = spirv; self.fragment_spirv = spirv.to_vec();
self self
} }
@ -295,14 +284,11 @@ impl PixelsOptions {
impl Default for PixelsOptions { impl Default for PixelsOptions {
fn default() -> PixelsOptions { fn default() -> PixelsOptions {
let vertex_spirv = spirv_from_file!(Vertex, "shaders/shader.vert", "main").to_vec();
let fragment_spirv = spirv_from_file!(Fragment, "shaders/shader.frag", "main").to_vec();
PixelsOptions { PixelsOptions {
request_adapter_options: wgpu::RequestAdapterOptions::default(), request_adapter_options: wgpu::RequestAdapterOptions::default(),
device_descriptor: wgpu::DeviceDescriptor::default(), device_descriptor: wgpu::DeviceDescriptor::default(),
vertex_spirv, vertex_spirv: include_glsl!("shaders/shader.vert").to_vec(),
fragment_spirv, fragment_spirv: include_glsl!("shaders/shader.frag").to_vec(),
} }
} }
} }