Skip to content

Commit 5ac500d

Browse files
authored
Split out a new -types crate so spirv-builder stops loading LLVM 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.
1 parent 595f8e7 commit 5ac500d

File tree

12 files changed

+63
-33
lines changed

12 files changed

+63
-33
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"examples/multibuilder",
1414

1515
"crates/rustc_codegen_spirv",
16+
"crates/rustc_codegen_spirv-types",
1617
"crates/spirv-builder",
1718
"crates/spirv-std",
1819
"crates/spirv-std/shared",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "rustc_codegen_spirv-types"
3+
description = "SPIR-V backend types shared between rustc_codegen_spirv and spirv-builder"
4+
version = "0.4.0-alpha.12"
5+
authors = ["Embark <[email protected]>"]
6+
edition = "2018"
7+
license = "MIT OR Apache-2.0"
8+
repository = "https://github.com/EmbarkStudios/rust-gpu"
9+
10+
[dependencies]
11+
rspirv = "0.11"
12+
serde = { version = "1.0", features = ["derive"] }

crates/rustc_codegen_spirv/src/compile_result.rs renamed to crates/rustc_codegen_spirv-types/src/compile_result.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use rustc_data_structures::fx::FxHashMap;
21
use serde::{Deserialize, Serialize};
2+
use std::collections::BTreeMap;
33
use std::fmt::Write;
44
use std::path::{Path, PathBuf};
55

66
#[derive(Debug, Serialize, Deserialize)]
77
#[serde(untagged)]
88
pub enum ModuleResult {
99
SingleModule(PathBuf),
10-
MultiModule(FxHashMap<String, PathBuf>),
10+
MultiModule(BTreeMap<String, PathBuf>),
1111
}
1212

1313
impl ModuleResult {
@@ -20,7 +20,7 @@ impl ModuleResult {
2020
}
2121
}
2222

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

4848
#[derive(Default)]
49-
struct Trie {
49+
struct Trie<'a> {
5050
present: bool,
51-
children: FxHashMap<String, Box<Trie>>,
51+
children: BTreeMap<&'a str, Trie<'a>>,
5252
}
5353

54-
impl Trie {
55-
fn create_from<'a>(entry_points: impl IntoIterator<Item = &'a str>) -> Self {
54+
impl<'a> Trie<'a> {
55+
fn create_from(entry_points: impl IntoIterator<Item = &'a str>) -> Self {
5656
let mut result = Trie::default();
5757
for entry in entry_points {
58-
result.insert(entry.split("::").map(|x| x.to_owned()));
58+
result.insert(entry.split("::"));
5959
}
6060
result
6161
}
6262

63-
fn insert(&mut self, mut sequence: impl Iterator<Item = String>) {
63+
fn insert(&mut self, mut sequence: impl Iterator<Item = &'a str>) {
6464
match sequence.next() {
6565
None => self.present = true,
66-
Some(next) => self
67-
.children
68-
.entry(next)
69-
.or_insert_with(Default::default)
70-
.insert(sequence),
66+
Some(next) => self.children.entry(next).or_default().insert(sequence),
7167
}
7268
}
7369

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Types used by both `rustc_codegen_spirv` and `spirv-builder`.
2+
3+
pub use rspirv::spirv::Capability;
4+
5+
mod compile_result;
6+
pub use compile_result::*;

crates/rustc_codegen_spirv/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ serde = { version = "1.0", features = ["derive"] }
4545
serde_json = "1.0"
4646
smallvec = "1.6.1"
4747
spirv-tools = { version = "0.8", default-features = false }
48+
rustc_codegen_spirv-types = { path = "../rustc_codegen_spirv-types", version = "0.4.0-alpha.12" }
4849

4950
[dev-dependencies]
5051
pipe = "0.4"

crates/rustc_codegen_spirv/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ mod attr;
137137
mod builder;
138138
mod builder_spirv;
139139
mod codegen_cx;
140-
mod compile_result;
141140
mod decorations;
142141
mod link;
143142
mod linker;
@@ -149,8 +148,6 @@ mod target_feature;
149148

150149
use builder::Builder;
151150
use codegen_cx::CodegenCx;
152-
pub use compile_result::*;
153-
pub use rspirv;
154151
use rspirv::binary::Assemble;
155152
use rustc_ast::expand::allocator::AllocatorKind;
156153
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};

crates/rustc_codegen_spirv/src/link.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::codegen_cx::{CodegenArgs, ModuleOutputType, SpirvMetadata};
2-
use crate::{
3-
linker, CompileResult, ModuleResult, SpirvCodegenBackend, SpirvModuleBuffer, SpirvThinBuffer,
4-
};
2+
use crate::{linker, SpirvCodegenBackend, SpirvModuleBuffer, SpirvThinBuffer};
53
use ar::{Archive, GnuBuilder, Header};
64
use rspirv::binary::Assemble;
5+
use rustc_codegen_spirv_types::{CompileResult, ModuleResult};
76
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
87
use rustc_codegen_ssa::back::write::CodegenContext;
98
use rustc_codegen_ssa::{CodegenResults, NativeLib, METADATA_FILENAME};
10-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::FxHashSet;
1110
use rustc_errors::FatalError;
1211
use rustc_middle::bug;
1312
use rustc_middle::dep_graph::WorkProduct;
@@ -156,15 +155,22 @@ fn link_exe(
156155
}
157156
}
158157
linker::LinkResult::MultipleModules(map) => {
159-
let mut hashmap = FxHashMap::default();
160158
let entry_points = map.keys().cloned().collect();
161-
for (name, spv_binary) in map {
162-
let mut module_filename = out_dir.clone();
163-
module_filename.push(sanitize_filename::sanitize(&name));
164-
post_link_single_module(sess, &cg_args, spv_binary.assemble(), &module_filename);
165-
hashmap.insert(name, module_filename);
166-
}
167-
let module_result = ModuleResult::MultiModule(hashmap);
159+
let map = map
160+
.into_iter()
161+
.map(|(name, spv_binary)| {
162+
let mut module_filename = out_dir.clone();
163+
module_filename.push(sanitize_filename::sanitize(&name));
164+
post_link_single_module(
165+
sess,
166+
&cg_args,
167+
spv_binary.assemble(),
168+
&module_filename,
169+
);
170+
(name, module_filename)
171+
})
172+
.collect();
173+
let module_result = ModuleResult::MultiModule(map);
168174
CompileResult {
169175
module: module_result,
170176
entry_points,

crates/spirv-builder/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ memchr = "2.4"
1717
raw-string = "0.3.5"
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
20+
rustc_codegen_spirv-types = { path = "../rustc_codegen_spirv-types" }
2021
# See comment in lib.rs invoke_rustc for why this is here
2122
rustc_codegen_spirv = { path = "../rustc_codegen_spirv", default-features = false }
2223

crates/spirv-builder/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ use std::io::BufReader;
8686
use std::path::{Path, PathBuf};
8787
use std::process::{Command, Stdio};
8888

89-
pub use rustc_codegen_spirv::rspirv::spirv::Capability;
90-
pub use rustc_codegen_spirv::{CompileResult, ModuleResult};
89+
pub use rustc_codegen_spirv_types::Capability;
90+
pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult};
9191

9292
#[derive(Debug)]
9393
#[non_exhaustive]

crates/spirv-builder/src/watch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::HashSet, sync::mpsc::sync_channel};
22

33
use notify::{Event, RecursiveMode, Watcher};
4-
use rustc_codegen_spirv::CompileResult;
4+
use rustc_codegen_spirv_types::CompileResult;
55

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

examples/runners/wgpu/src/graphics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async fn run(
5959

6060
let features = wgpu::Features::PUSH_CONSTANTS;
6161
let limits = wgpu::Limits {
62-
max_push_constant_size: 256,
62+
max_push_constant_size: 128,
6363
..Default::default()
6464
};
6565

0 commit comments

Comments
 (0)