diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 33e1504..5fe9603 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,5 +9,6 @@ "shader-slang.slang-language-extension" ] } - } + }, + "postCreateCommand": "sudo apt update && sudo apt install -y build-essential cmake libx11-dev" } diff --git a/Cargo.lock b/Cargo.lock index 19b1642..56a96a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,10 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +[[package]] +name = "flare" +version = "0.1.0" + [[package]] name = "xflags" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 4905c5c..5a2044f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "crates/flare", "crates/xtask" ] resolver = "2" diff --git a/crates/flare/Cargo.toml b/crates/flare/Cargo.toml index 04e00df..704e84d 100644 --- a/crates/flare/Cargo.toml +++ b/crates/flare/Cargo.toml @@ -3,8 +3,4 @@ name = "flare" version.workspace = true edition.workspace = true -[dependencies] - -[build-dependencies] -reqwest.workspace = true -zip-extract.workspace = true \ No newline at end of file +[dependencies] \ No newline at end of file diff --git a/crates/flare/build.rs b/crates/flare/build.rs deleted file mode 100644 index a153c87..0000000 --- a/crates/flare/build.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::env; -use std::fs::{File}; -use std::io::{BufReader, Write}; -use std::path::PathBuf; -use std::process::Command; - -pub fn main() { - /* - println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-changed=../shader"); - - let url = "https://github.com/shader-slang/slang/releases/download/v2024.17/slang-2024.17-linux-x86_64.zip"; - let output_path = PathBuf::from(format!("{}/slang.zip", env::var("OUT_DIR").unwrap())); - let output_dir = PathBuf::from(format!("{}/slang", env::var("OUT_DIR").unwrap())); - - let mut response = reqwest::blocking::get(url).expect("Unable to fetch shader compiler"); - - let mut response_out = File::create(&output_path).unwrap(); - response.copy_to(&mut response_out).expect("Unable to copy file"); - response_out.flush().expect("Unable to flush output file"); - - let response_out = File::open(output_path).expect("Unable to create output file"); - let output_reader = BufReader::new(response_out); - zip_extract::extract(output_reader, output_dir.as_path(), true).expect("Unable to extract shader compiler"); - - let slangc_path = output_dir.join("bin/slangc"); - let shader_path= PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("../../shader"); - */ -} \ No newline at end of file diff --git a/crates/xtask/src/shader_test.rs b/crates/xtask/src/shader_test.rs index 259f284..b68e233 100644 --- a/crates/xtask/src/shader_test.rs +++ b/crates/xtask/src/shader_test.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::flags::ShaderTest; use crate::slang_build::SlangBuild; use xshell::Shell; @@ -18,11 +20,11 @@ impl ShaderTest { let build_dir = build_dir.to_str().unwrap(); // slang-test currently relies on a folder named `tests/` in the current directory - sh.cmd("cp") - .arg("-r") - .arg("shader-tests") - .arg(format!("{build_dir}/tests")) - .run()?; + let tests_dir = PathBuf::from(format!("{build_dir}/tests")); + sh.cmd("rm").arg("-rf").arg(&tests_dir).run()?; + sh.create_dir(&tests_dir)?; + + sh.cmd("cp").arg("-r").arg("shader").arg(tests_dir).run()?; let _dir_guard = sh.push_dir(&build_dir); sh.cmd(format!("Release/bin/slang-test")) diff --git a/crates/xtask/src/slang_build.rs b/crates/xtask/src/slang_build.rs index baa4812..065cf20 100644 --- a/crates/xtask/src/slang_build.rs +++ b/crates/xtask/src/slang_build.rs @@ -54,8 +54,8 @@ impl SlangBuild { .args(["-S", source_dir.to_str().unwrap()]) .args(["-B", build_dir.to_str().unwrap()]) .arg("-DCMAKE_BUILD_TYPE=Release") - // https://github.com/shader-slang/slang/issues/5832#issuecomment-2533324982 - .arg("-DCMAKE_SKIP_INSTALL_RULES=ON") + .arg("-DCMAKE_C_FLAGS=-Wno-stringop-overflow") + .arg("-DCMAKE_CXX_FLAGS=-Wno-stringop-overflow") .run() .context("slang-build configure")?; diff --git a/shader-tests/enum.slang b/shader-tests/enum.slang deleted file mode 100644 index fe35f43..0000000 --- a/shader-tests/enum.slang +++ /dev/null @@ -1,67 +0,0 @@ -// enum.slang -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj - -// Confirm that basic `enum` declarations are supported. - -enum Color -{ - Red, - Green = (1 << 1), - Blue, -} - - -int test(int val) -{ - Color c = Color.Red; - - if(val > 1) - { - c = Color.Green; - } - - if(c == Color.Red) - { - if((val & 1) != 0) - { - c = Color.Blue; - } - } - - switch(c) - { - case Color.Red: - val = 1; - break; - - case Color.Green: - val = 2; - break; - - case Color.Blue: - val = 3; - break; - - default: - val = -1; - break; - } - - return (val << 4) + int(c); -} - -//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer -RWStructuredBuffer outputBuffer; - -[numthreads(4, 1, 1)] -void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) -{ - int tid = dispatchThreadID.x; - - int val = int(tid); - val = test(val); - - outputBuffer[tid] = val; -} \ No newline at end of file diff --git a/shader-tests/enum.slang.expected.txt b/shader-tests/enum.slang.expected.txt deleted file mode 100644 index 3080040..0000000 --- a/shader-tests/enum.slang.expected.txt +++ /dev/null @@ -1,4 +0,0 @@ -10 -33 -22 -22 \ No newline at end of file diff --git a/shader/_test-rng-xoroshiro128plus.slang b/shader/_test-rng-xoroshiro128plus.slang new file mode 100644 index 0000000..afdad7d --- /dev/null +++ b/shader/_test-rng-xoroshiro128plus.slang @@ -0,0 +1,18 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -output-using-type + +import rng; + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + Xoroshiro128Plus rng = {1, 2}; + for (int i = 0; i < 5; i++) + { + outputBuffer[i] = rng.next(); + } +} \ No newline at end of file diff --git a/shader/_test-rng-xoroshiro128plus.slang.expected.txt b/shader/_test-rng-xoroshiro128plus.slang.expected.txt new file mode 100644 index 0000000..140478c --- /dev/null +++ b/shader/_test-rng-xoroshiro128plus.slang.expected.txt @@ -0,0 +1,6 @@ +type: uint64_t +3 +412333834243 +2360170716294286339 +9295852285959843169 +2797080929874688578 \ No newline at end of file diff --git a/shader/hello-world.slang b/shader/hello-world.slang index c4264f5..85ac64b 100644 --- a/shader/hello-world.slang +++ b/shader/hello-world.slang @@ -2,10 +2,15 @@ StructuredBuffer buffer0; StructuredBuffer buffer1; RWStructuredBuffer result; +import rng; + [shader("compute")] [numthreads(1,1,1)] void computeMain(uint3 threadId : SV_DispatchThreadID) { - uint index = threadId.x; - result[index] = buffer0[index] + buffer1[index]; -} + Xoroshiro128Plus generator = {1, 2}; + for (var i = 0; i < 10; i++) + { + result[i] = generator.next(); + } +} \ No newline at end of file diff --git a/shader/rng.slang b/shader/rng.slang new file mode 100644 index 0000000..1da4edf --- /dev/null +++ b/shader/rng.slang @@ -0,0 +1,44 @@ +module rng; + +public interface IRngCore +{ + [mutating] + public uint64_t next(); + + [mutating] + public float next_float(); +} + +uint64_t rotl(uint64_t x, int k) +{ + return (x << k) | (x >> (64 - k)); +} + +float u64_to_float(uint64_t x) +{ + return 0; +} + +public struct Xoroshiro128Plus : IRngCore +{ + internal uint64_t s0; + internal uint64_t s1; + + [mutating] + public uint64_t next() + { + var result = s0 + s1; + + s1 ^= s0; + s0 = rotl(s0, 24) ^ s1 ^ (s1 << 16); + s1 = rotl(s1, 37); + + return result; + } + + [mutating] + public float next_float() + { + return u64_to_float(next()); + } +} \ No newline at end of file