Skip to content

Allow Naga spv-in and spv-out in no_std #7760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ jobs:

# Check with all compatible features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features --features strict_asserts,fragile-send-sync-non-atomic-wasm,serde,counters
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features --features dot-out
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features --features dot-out,spv-in,spv-out
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --no-default-features --features fragile-send-sync-non-atomic-wasm
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --no-default-features --features serde

Expand Down
1 change: 1 addition & 0 deletions naga-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ naga = { workspace = true, features = [
"deserialize",
"termcolor",
"stderr",
"fs",
] }

bincode.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions naga-cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ fn run() -> anyhow::Result<()> {
params.spv_in = naga::front::spv::Options {
adjust_coordinate_space: !args.keep_coordinate_space,
strict_capabilities: false,
block_ctx_dump_prefix: args.block_ctx_dir.clone().map(std::path::PathBuf::from),
block_ctx_dump_prefix: args.block_ctx_dir.clone().map(Into::into),
};

params.entry_point.clone_from(&args.entry_point);
Expand Down Expand Up @@ -486,7 +486,7 @@ fn run() -> anyhow::Result<()> {
.set(naga::back::spv::WriterFlags::DEBUG, true);
params.spv_out.debug_info = Some(naga::back::spv::DebugInfo {
source_code: input_text,
file_name: input_path,
file_name: input_path.into(),
language,
})
} else {
Expand Down
4 changes: 3 additions & 1 deletion naga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ default = []
dot-out = []
glsl-in = ["dep:pp-rs"]
glsl-out = []
std = []

## Enables outputting to the Metal Shading Language (MSL).
##
Expand Down Expand Up @@ -79,6 +78,9 @@ termcolor = ["codespan-reporting/termcolor"]
## Enables writing output to stderr.
stderr = ["codespan-reporting/std"]

## Enables integration with the underlying filesystem.
fs = []

[dependencies]
arbitrary = { workspace = true, features = ["derive"], optional = true }
arrayvec.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion naga/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
msl_out: { any(feature = "msl-out", all(target_vendor = "apple", feature = "msl-out-if-target-apple")) },
spv_out: { feature = "spv-out" },
wgsl_out: { feature = "wgsl-out" },
std: { any(test, spv_out, feature = "spv-in", feature = "wgsl-in", feature = "stderr") },
std: { any(test, feature = "wgsl-in", feature = "stderr", feature = "fs") },
no_std: { not(std) },
}
}
79 changes: 0 additions & 79 deletions naga/src/as_diagnostic_file_path.rs

This file was deleted.

3 changes: 2 additions & 1 deletion naga/src/back/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use spirv::Word;
use thiserror::Error;

use crate::arena::{Handle, HandleVec};
use crate::path_like::PathLikeRef;
use crate::proc::{BoundsCheckPolicies, TypeResolution};

#[derive(Clone)]
Expand Down Expand Up @@ -92,7 +93,7 @@ impl IdGenerator {
#[derive(Debug, Clone)]
pub struct DebugInfo<'a> {
pub source_code: &'a str,
pub file_name: &'a std::path::Path,
pub file_name: PathLikeRef<'a>,
pub language: SourceLanguage,
}

Expand Down
9 changes: 3 additions & 6 deletions naga/src/back/spv/writer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};
use alloc::{string::String, vec, vec::Vec};

use hashbrown::hash_map::Entry;
use spirv::Word;
Expand All @@ -18,6 +14,7 @@ use super::{
use crate::{
arena::{Handle, HandleVec, UniqueArena},
back::spv::{BindingInfo, WrappedFunction},
path_like::PathLike,
proc::{Alignment, TypeResolution},
valid::{FunctionInfo, ModuleInfo},
};
Expand Down Expand Up @@ -2415,7 +2412,7 @@ impl Writer {
if let Some(debug_info) = debug_info.as_ref() {
let source_file_id = self.id_gen.next();
self.debugs.push(Instruction::string(
&debug_info.file_name.display().to_string(),
&debug_info.file_name.to_string_lossy(),
source_file_id,
));

Expand Down
16 changes: 12 additions & 4 deletions naga/src/front/spv/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,18 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
Some(ep) => format!("block_ctx.{:?}-{}.txt", ep.stage, ep.name),
None => format!("block_ctx.Fun-{}.txt", function_index),
};
let dest = prefix.join(dump_suffix);
let dump = format!("{block_ctx:#?}");
if let Err(e) = std::fs::write(&dest, dump) {
log::error!("Unable to dump the block context into {:?}: {}", dest, e);

cfg_if::cfg_if! {
if #[cfg(feature = "fs")] {
let prefix: &std::path::Path = prefix.as_ref();
let dest = prefix.join(dump_suffix);
let dump = format!("{block_ctx:#?}");
if let Err(e) = std::fs::write(&dest, dump) {
log::error!("Unable to dump the block context into {:?}: {}", dest, e);
}
} else {
log::error!("Unable to dump the block context into {:?}/{}: file system integration was not enabled with the `fs` feature", prefix, dump_suffix);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ pub use error::Error;

use alloc::{borrow::ToOwned, format, string::String, vec, vec::Vec};
use core::{convert::TryInto, mem, num::NonZeroU32};
use std::path::PathBuf;

use half::f16;
use petgraph::graphmap::GraphMap;

use super::atomic_upgrade::Upgrades;
use crate::{
arena::{Arena, Handle, UniqueArena},
path_like::PathLikeOwned,
proc::{Alignment, Layouter},
FastHashMap, FastHashSet, FastIndexMap,
};
Expand Down Expand Up @@ -381,7 +381,7 @@ pub struct Options {
pub adjust_coordinate_space: bool,
/// Only allow shaders with the known set of capabilities.
pub strict_capabilities: bool,
pub block_ctx_dump_prefix: Option<PathBuf>,
pub block_ctx_dump_prefix: Option<PathLikeOwned>,
}

impl Default for Options {
Expand Down
2 changes: 1 addition & 1 deletion naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ extern crate std;
extern crate alloc;

mod arena;
mod as_diagnostic_file_path;
pub mod back;
pub mod common;
pub mod compact;
Expand All @@ -116,6 +115,7 @@ pub mod front;
pub mod ir;
pub mod keywords;
mod non_max_u32;
mod path_like;
pub mod proc;
mod racy_lock;
mod span;
Expand Down
Loading
Loading