From 0652153f1d895744ea9a1ccaf266d662fcafa621 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Thu, 2 Dec 2021 09:46:34 +0000 Subject: [PATCH] No longer require the workaround for the collatz example (#778) * No longer require the workaround for the collatz example * and remove the `Int8` cap --- examples/runners/wgpu/builder/src/main.rs | 27 ++++++---------------- examples/runners/wgpu/src/lib.rs | 17 ++++++-------- examples/shaders/compute-shader/src/lib.rs | 10 +------- 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/examples/runners/wgpu/builder/src/main.rs b/examples/runners/wgpu/builder/src/main.rs index d85cfa5fd3..0e7483dc34 100644 --- a/examples/runners/wgpu/builder/src/main.rs +++ b/examples/runners/wgpu/builder/src/main.rs @@ -1,21 +1,13 @@ -use spirv_builder::{Capability, SpirvBuilder}; +use spirv_builder::SpirvBuilder; use std::env; use std::error::Error; use std::fs; use std::path::Path; -fn build_shader( - path_to_crate: &str, - codegen_names: bool, - caps: &[Capability], -) -> Result<(), Box> { +fn build_shader(path_to_crate: &str, codegen_names: bool) -> Result<(), Box> { let builder_dir = &Path::new(env!("CARGO_MANIFEST_DIR")); let path_to_crate = builder_dir.join(path_to_crate); - let mut builder = SpirvBuilder::new(path_to_crate, "spirv-unknown-vulkan1.1"); - for &cap in caps { - builder = builder.capability(cap); - } - let result = builder.build()?; + let result = SpirvBuilder::new(path_to_crate, "spirv-unknown-vulkan1.1").build()?; if codegen_names { let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("entry_points.rs"); @@ -26,14 +18,9 @@ fn build_shader( } fn main() -> Result<(), Box> { - build_shader("../../../shaders/sky-shader", true, &[])?; - build_shader("../../../shaders/simplest-shader", false, &[])?; - // We need the int8 capability for using `Option` - build_shader( - "../../../shaders/compute-shader", - false, - &[Capability::Int8], - )?; - build_shader("../../../shaders/mouse-shader", false, &[])?; + build_shader("../../../shaders/sky-shader", true)?; + build_shader("../../../shaders/simplest-shader", false)?; + build_shader("../../../shaders/compute-shader", false)?; + build_shader("../../../shaders/mouse-shader", false)?; Ok(()) } diff --git a/examples/runners/wgpu/src/lib.rs b/examples/runners/wgpu/src/lib.rs index 16af215a29..18d94ec3a0 100644 --- a/examples/runners/wgpu/src/lib.rs +++ b/examples/runners/wgpu/src/lib.rs @@ -90,7 +90,7 @@ fn maybe_watch( ) -> wgpu::ShaderModuleDescriptorSpirV<'static> { #[cfg(not(any(target_os = "android", target_arch = "wasm32")))] { - use spirv_builder::{Capability, CompileResult, MetadataPrintout, SpirvBuilder}; + use spirv_builder::{CompileResult, MetadataPrintout, SpirvBuilder}; use std::borrow::Cow; use std::path::PathBuf; // Hack: spirv_builder builds into a custom directory if running under cargo, to not @@ -101,22 +101,19 @@ fn maybe_watch( // under cargo by setting these environment variables. std::env::set_var("OUT_DIR", env!("OUT_DIR")); std::env::set_var("PROFILE", env!("PROFILE")); - let (crate_name, capabilities): (_, &[Capability]) = match shader { - RustGPUShader::Simplest => ("simplest-shader", &[]), - RustGPUShader::Sky => ("sky-shader", &[]), - RustGPUShader::Compute => ("compute-shader", &[Capability::Int8]), - RustGPUShader::Mouse => ("mouse-shader", &[]), + let crate_name = match shader { + RustGPUShader::Simplest => "simplest-shader", + RustGPUShader::Sky => "sky-shader", + RustGPUShader::Compute => "compute-shader", + RustGPUShader::Mouse => "mouse-shader", }; let manifest_dir = env!("CARGO_MANIFEST_DIR"); let crate_path = [manifest_dir, "..", "..", "shaders", crate_name] .iter() .copied() .collect::(); - let mut builder = SpirvBuilder::new(crate_path, "spirv-unknown-vulkan1.1") + let builder = SpirvBuilder::new(crate_path, "spirv-unknown-vulkan1.1") .print_metadata(MetadataPrintout::None); - for &cap in capabilities { - builder = builder.capability(cap); - } let initial_result = if let Some(mut f) = on_watch { builder .watch(move |compile_result| f(handle_compile_result(compile_result))) diff --git a/examples/shaders/compute-shader/src/lib.rs b/examples/shaders/compute-shader/src/lib.rs index 9953b30aea..602c3bda8c 100644 --- a/examples/shaders/compute-shader/src/lib.rs +++ b/examples/shaders/compute-shader/src/lib.rs @@ -44,13 +44,5 @@ pub fn main_cs( #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] prime_indices: &mut [u32], ) { let index = id.x as usize; - prime_indices[index] = unwrap_or_max(collatz(prime_indices[index])); -} - -// Work around https://github.com/EmbarkStudios/rust-gpu/issues/677 -fn unwrap_or_max(option: Option) -> u32 { - match option { - Some(inner) => inner, - None => u32::MAX, - } + prime_indices[index] = collatz(prime_indices[index]).unwrap_or(u32::MAX); }