Skip to content

Commit

Permalink
Split out a new -types crate so spirv-builder stops loading LLVM …
Browse files Browse the repository at this point in the history
…via dylibs. (#856)

* Split out a new `-types` crate so `spirv-builder` stops loading LLVM via dylibs.

* example-wgpu-runner: halve `max_push_constant_size` so it works on RADV/Fiji.
  • Loading branch information
eddyb authored Mar 30, 2022
1 parent 595f8e7 commit 5ac500d
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 33 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"examples/multibuilder",

"crates/rustc_codegen_spirv",
"crates/rustc_codegen_spirv-types",
"crates/spirv-builder",
"crates/spirv-std",
"crates/spirv-std/shared",
Expand Down
12 changes: 12 additions & 0 deletions crates/rustc_codegen_spirv-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "rustc_codegen_spirv-types"
description = "SPIR-V backend types shared between rustc_codegen_spirv and spirv-builder"
version = "0.4.0-alpha.12"
authors = ["Embark <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
repository = "https://github.com/EmbarkStudios/rust-gpu"

[dependencies]
rspirv = "0.11"
serde = { version = "1.0", features = ["derive"] }
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use rustc_data_structures::fx::FxHashMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt::Write;
use std::path::{Path, PathBuf};

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ModuleResult {
SingleModule(PathBuf),
MultiModule(FxHashMap<String, PathBuf>),
MultiModule(BTreeMap<String, PathBuf>),
}

impl ModuleResult {
Expand All @@ -20,7 +20,7 @@ impl ModuleResult {
}
}

pub fn unwrap_multi(&self) -> &FxHashMap<String, PathBuf> {
pub fn unwrap_multi(&self) -> &BTreeMap<String, PathBuf> {
match self {
ModuleResult::MultiModule(result) => result,
ModuleResult::SingleModule(_) => {
Expand All @@ -46,28 +46,24 @@ impl CompileResult {
}

#[derive(Default)]
struct Trie {
struct Trie<'a> {
present: bool,
children: FxHashMap<String, Box<Trie>>,
children: BTreeMap<&'a str, Trie<'a>>,
}

impl Trie {
fn create_from<'a>(entry_points: impl IntoIterator<Item = &'a str>) -> Self {
impl<'a> Trie<'a> {
fn create_from(entry_points: impl IntoIterator<Item = &'a str>) -> Self {
let mut result = Trie::default();
for entry in entry_points {
result.insert(entry.split("::").map(|x| x.to_owned()));
result.insert(entry.split("::"));
}
result
}

fn insert(&mut self, mut sequence: impl Iterator<Item = String>) {
fn insert(&mut self, mut sequence: impl Iterator<Item = &'a str>) {
match sequence.next() {
None => self.present = true,
Some(next) => self
.children
.entry(next)
.or_insert_with(Default::default)
.insert(sequence),
Some(next) => self.children.entry(next).or_default().insert(sequence),
}
}

Expand Down
6 changes: 6 additions & 0 deletions crates/rustc_codegen_spirv-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Types used by both `rustc_codegen_spirv` and `spirv-builder`.
pub use rspirv::spirv::Capability;

mod compile_result;
pub use compile_result::*;
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smallvec = "1.6.1"
spirv-tools = { version = "0.8", default-features = false }
rustc_codegen_spirv-types = { path = "../rustc_codegen_spirv-types", version = "0.4.0-alpha.12" }

[dev-dependencies]
pipe = "0.4"
Expand Down
3 changes: 0 additions & 3 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ mod attr;
mod builder;
mod builder_spirv;
mod codegen_cx;
mod compile_result;
mod decorations;
mod link;
mod linker;
Expand All @@ -149,8 +148,6 @@ mod target_feature;

use builder::Builder;
use codegen_cx::CodegenCx;
pub use compile_result::*;
pub use rspirv;
use rspirv::binary::Assemble;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
Expand Down
30 changes: 18 additions & 12 deletions crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::codegen_cx::{CodegenArgs, ModuleOutputType, SpirvMetadata};
use crate::{
linker, CompileResult, ModuleResult, SpirvCodegenBackend, SpirvModuleBuffer, SpirvThinBuffer,
};
use crate::{linker, SpirvCodegenBackend, SpirvModuleBuffer, SpirvThinBuffer};
use ar::{Archive, GnuBuilder, Header};
use rspirv::binary::Assemble;
use rustc_codegen_spirv_types::{CompileResult, ModuleResult};
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
use rustc_codegen_ssa::back::write::CodegenContext;
use rustc_codegen_ssa::{CodegenResults, NativeLib, METADATA_FILENAME};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::FatalError;
use rustc_middle::bug;
use rustc_middle::dep_graph::WorkProduct;
Expand Down Expand Up @@ -156,15 +155,22 @@ fn link_exe(
}
}
linker::LinkResult::MultipleModules(map) => {
let mut hashmap = FxHashMap::default();
let entry_points = map.keys().cloned().collect();
for (name, spv_binary) in map {
let mut module_filename = out_dir.clone();
module_filename.push(sanitize_filename::sanitize(&name));
post_link_single_module(sess, &cg_args, spv_binary.assemble(), &module_filename);
hashmap.insert(name, module_filename);
}
let module_result = ModuleResult::MultiModule(hashmap);
let map = map
.into_iter()
.map(|(name, spv_binary)| {
let mut module_filename = out_dir.clone();
module_filename.push(sanitize_filename::sanitize(&name));
post_link_single_module(
sess,
&cg_args,
spv_binary.assemble(),
&module_filename,
);
(name, module_filename)
})
.collect();
let module_result = ModuleResult::MultiModule(map);
CompileResult {
module: module_result,
entry_points,
Expand Down
1 change: 1 addition & 0 deletions crates/spirv-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ memchr = "2.4"
raw-string = "0.3.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rustc_codegen_spirv-types = { path = "../rustc_codegen_spirv-types" }
# See comment in lib.rs invoke_rustc for why this is here
rustc_codegen_spirv = { path = "../rustc_codegen_spirv", default-features = false }

Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

pub use rustc_codegen_spirv::rspirv::spirv::Capability;
pub use rustc_codegen_spirv::{CompileResult, ModuleResult};
pub use rustc_codegen_spirv_types::Capability;
pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult};

#[derive(Debug)]
#[non_exhaustive]
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-builder/src/watch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashSet, sync::mpsc::sync_channel};

use notify::{Event, RecursiveMode, Watcher};
use rustc_codegen_spirv::CompileResult;
use rustc_codegen_spirv_types::CompileResult;

use crate::{leaf_deps, SpirvBuilder, SpirvBuilderError};

Expand Down
2 changes: 1 addition & 1 deletion examples/runners/wgpu/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn run(

let features = wgpu::Features::PUSH_CONSTANTS;
let limits = wgpu::Limits {
max_push_constant_size: 256,
max_push_constant_size: 128,
..Default::default()
};

Expand Down

0 comments on commit 5ac500d

Please sign in to comment.