mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-25 16:25:25 +00:00
No longer require the workaround for the collatz example (#778)
* No longer require the workaround for the collatz example * and remove the `Int8` cap
This commit is contained in:
parent
d5d0c90652
commit
0652153f1d
@ -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<dyn Error>> {
|
||||
fn build_shader(path_to_crate: &str, codegen_names: bool) -> Result<(), Box<dyn Error>> {
|
||||
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<dyn Error>> {
|
||||
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(())
|
||||
}
|
||||
|
@ -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::<PathBuf>();
|
||||
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)))
|
||||
|
@ -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>) -> u32 {
|
||||
match option {
|
||||
Some(inner) => inner,
|
||||
None => u32::MAX,
|
||||
}
|
||||
prime_indices[index] = collatz(prime_indices[index]).unwrap_or(u32::MAX);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user