Implement experimental WebGPU support (#1238)

* Web gpu execution MVP

Ready infrastructure for wgpu experimentation

Start implementing simple gpu test case

Fix Extract Node not working with nested networks

Convert inputs for extracted node to network inputs

Fix missing cors headers

Feature gate gcore to make it once again no-std compatible

Add skeleton structure gpu shader

Work on gpu node graph output saving

Fix Get and Set nodes

Fix storage nodes

Fix shader construction errors -> spirv errors

Add unsafe version

Add once cell node

Web gpu execution MVP
This commit is contained in:
Dennis Kobert 2023-05-27 19:27:46 +02:00 committed by Keavon Chambers
parent 4bd9fbd073
commit 0586d52f3a
33 changed files with 1080 additions and 239 deletions

View file

@ -2,22 +2,22 @@ use gpu_compiler_bin_wrapper::CompileRequest;
use gpu_executor::ShaderIO;
use graph_craft::{proto::ProtoNetwork, Type};
pub async fn compile(network: ProtoNetwork, inputs: Vec<Type>, output: Type, io: ShaderIO) -> Result<Shader, reqwest::Error> {
pub async fn compile(networks: Vec<ProtoNetwork>, inputs: Vec<Type>, outputs: Vec<Type>, io: ShaderIO) -> Result<Shader, reqwest::Error> {
let client = reqwest::Client::new();
let compile_request = CompileRequest::new(network, inputs.clone(), output.clone(), io.clone());
let compile_request = CompileRequest::new(networks, inputs.clone(), outputs.clone(), io.clone());
let response = client.post("http://localhost:3000/compile/spirv").json(&compile_request).send();
let response = response.await?;
response.bytes().await.map(|b| Shader {
spirv_binary: b.windows(4).map(|x| u32::from_le_bytes(x.try_into().unwrap())).collect(),
spirv_binary: b.chunks(4).map(|x| u32::from_le_bytes(x.try_into().unwrap())).collect(),
input_types: inputs,
output_type: output,
output_types: outputs,
io,
})
}
pub fn compile_sync(network: ProtoNetwork, inputs: Vec<Type>, output: Type, io: ShaderIO) -> Result<Shader, reqwest::Error> {
future_executor::block_on(compile(network, inputs, output, io))
pub fn compile_sync(networks: Vec<ProtoNetwork>, inputs: Vec<Type>, outputs: Vec<Type>, io: ShaderIO) -> Result<Shader, reqwest::Error> {
future_executor::block_on(compile(networks, inputs, outputs, io))
}
// TODO: should we add the entry point as a field?
@ -25,6 +25,6 @@ pub fn compile_sync(network: ProtoNetwork, inputs: Vec<Type>, output: Type, io:
pub struct Shader {
pub spirv_binary: Vec<u32>,
pub input_types: Vec<Type>,
pub output_type: Type,
pub output_types: Vec<Type>,
pub io: ShaderIO,
}

View file

@ -36,7 +36,7 @@ fn main() {
output: ShaderInput::OutputBuffer((), concrete!(&mut [u32])),
};
let compile_request = CompileRequest::new(proto_network, vec![concrete!(u32)], concrete!(u32), io);
let compile_request = CompileRequest::new(vec![proto_network], vec![concrete!(u32)], vec![concrete!(u32)], io);
let response = client
.post("http://localhost:3000/compile/spirv")
.timeout(Duration::from_secs(30))