Basic RNG
This commit is contained in:
parent
52110f4e29
commit
68890ac229
@ -9,5 +9,6 @@
|
|||||||
"shader-slang.slang-language-extension"
|
"shader-slang.slang-language-extension"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"postCreateCommand": "sudo apt update && sudo apt install -y build-essential cmake libx11-dev"
|
||||||
}
|
}
|
||||||
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -8,6 +8,10 @@ version = "1.0.95"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flare"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xflags"
|
name = "xflags"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
"crates/flare",
|
||||||
"crates/xtask"
|
"crates/xtask"
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
@ -3,8 +3,4 @@ name = "flare"
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
reqwest.workspace = true
|
|
||||||
zip-extract.workspace = true
|
|
@ -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");
|
|
||||||
*/
|
|
||||||
}
|
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::flags::ShaderTest;
|
use crate::flags::ShaderTest;
|
||||||
use crate::slang_build::SlangBuild;
|
use crate::slang_build::SlangBuild;
|
||||||
use xshell::Shell;
|
use xshell::Shell;
|
||||||
@ -18,11 +20,11 @@ impl ShaderTest {
|
|||||||
let build_dir = build_dir.to_str().unwrap();
|
let build_dir = build_dir.to_str().unwrap();
|
||||||
|
|
||||||
// slang-test currently relies on a folder named `tests/` in the current directory
|
// slang-test currently relies on a folder named `tests/` in the current directory
|
||||||
sh.cmd("cp")
|
let tests_dir = PathBuf::from(format!("{build_dir}/tests"));
|
||||||
.arg("-r")
|
sh.cmd("rm").arg("-rf").arg(&tests_dir).run()?;
|
||||||
.arg("shader-tests")
|
sh.create_dir(&tests_dir)?;
|
||||||
.arg(format!("{build_dir}/tests"))
|
|
||||||
.run()?;
|
sh.cmd("cp").arg("-r").arg("shader").arg(tests_dir).run()?;
|
||||||
|
|
||||||
let _dir_guard = sh.push_dir(&build_dir);
|
let _dir_guard = sh.push_dir(&build_dir);
|
||||||
sh.cmd(format!("Release/bin/slang-test"))
|
sh.cmd(format!("Release/bin/slang-test"))
|
||||||
|
@ -54,8 +54,8 @@ impl SlangBuild {
|
|||||||
.args(["-S", source_dir.to_str().unwrap()])
|
.args(["-S", source_dir.to_str().unwrap()])
|
||||||
.args(["-B", build_dir.to_str().unwrap()])
|
.args(["-B", build_dir.to_str().unwrap()])
|
||||||
.arg("-DCMAKE_BUILD_TYPE=Release")
|
.arg("-DCMAKE_BUILD_TYPE=Release")
|
||||||
// https://github.com/shader-slang/slang/issues/5832#issuecomment-2533324982
|
.arg("-DCMAKE_C_FLAGS=-Wno-stringop-overflow")
|
||||||
.arg("-DCMAKE_SKIP_INSTALL_RULES=ON")
|
.arg("-DCMAKE_CXX_FLAGS=-Wno-stringop-overflow")
|
||||||
.run()
|
.run()
|
||||||
.context("slang-build configure")?;
|
.context("slang-build configure")?;
|
||||||
|
|
||||||
|
@ -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<int> 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;
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
10
|
|
||||||
33
|
|
||||||
22
|
|
||||||
22
|
|
18
shader/_test-rng-xoroshiro128plus.slang
Normal file
18
shader/_test-rng-xoroshiro128plus.slang
Normal file
@ -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<uint64_t> 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();
|
||||||
|
}
|
||||||
|
}
|
6
shader/_test-rng-xoroshiro128plus.slang.expected.txt
Normal file
6
shader/_test-rng-xoroshiro128plus.slang.expected.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
type: uint64_t
|
||||||
|
3
|
||||||
|
412333834243
|
||||||
|
2360170716294286339
|
||||||
|
9295852285959843169
|
||||||
|
2797080929874688578
|
@ -2,10 +2,15 @@ StructuredBuffer<float> buffer0;
|
|||||||
StructuredBuffer<float> buffer1;
|
StructuredBuffer<float> buffer1;
|
||||||
RWStructuredBuffer<float> result;
|
RWStructuredBuffer<float> result;
|
||||||
|
|
||||||
|
import rng;
|
||||||
|
|
||||||
[shader("compute")]
|
[shader("compute")]
|
||||||
[numthreads(1,1,1)]
|
[numthreads(1,1,1)]
|
||||||
void computeMain(uint3 threadId : SV_DispatchThreadID)
|
void computeMain(uint3 threadId : SV_DispatchThreadID)
|
||||||
{
|
{
|
||||||
uint index = threadId.x;
|
Xoroshiro128Plus generator = {1, 2};
|
||||||
result[index] = buffer0[index] + buffer1[index];
|
for (var i = 0; i < 10; i++)
|
||||||
}
|
{
|
||||||
|
result[i] = generator.next();
|
||||||
|
}
|
||||||
|
}
|
44
shader/rng.slang
Normal file
44
shader/rng.slang
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user