Update to naga-14

This commit is contained in:
Dzmitry Malyshau 2021-03-13 23:24:29 -05:00
parent 7af0f3137d
commit 280c066e65
5 changed files with 104 additions and 83 deletions

20
Cargo.lock generated
View File

@ -487,7 +487,7 @@ dependencies = [
[[package]]
name = "gfx-auxil"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"fxhash",
"gfx-hal",
@ -497,7 +497,7 @@ dependencies = [
[[package]]
name = "gfx-backend-dx11"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"arrayvec",
"bitflags",
@ -518,7 +518,7 @@ dependencies = [
[[package]]
name = "gfx-backend-dx12"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"arrayvec",
"bit-set",
@ -538,7 +538,7 @@ dependencies = [
[[package]]
name = "gfx-backend-empty"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"gfx-hal",
"log",
@ -548,7 +548,7 @@ dependencies = [
[[package]]
name = "gfx-backend-gl"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"arrayvec",
"bitflags",
@ -571,7 +571,7 @@ dependencies = [
[[package]]
name = "gfx-backend-metal"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"arrayvec",
"bitflags",
@ -596,7 +596,7 @@ dependencies = [
[[package]]
name = "gfx-backend-vulkan"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"arrayvec",
"ash",
@ -616,7 +616,7 @@ dependencies = [
[[package]]
name = "gfx-hal"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
dependencies = [
"bitflags",
"naga",
@ -958,7 +958,7 @@ dependencies = [
[[package]]
name = "naga"
version = "0.3.1"
source = "git+https://github.com/gfx-rs/naga?tag=gfx-13#f5ee79191223e4ebe323a728f4de40830b8d10f6"
source = "git+https://github.com/gfx-rs/naga?tag=gfx-14#32a11752af99e818b14da9aa37c914a89b57b7ad"
dependencies = [
"bit-set",
"bitflags",
@ -1224,7 +1224,7 @@ dependencies = [
[[package]]
name = "range-alloc"
version = "0.1.2"
source = "git+https://github.com/gfx-rs/gfx?rev=cd96e77952dd2e330fe2c31f768203eef47a0d6a#cd96e77952dd2e330fe2c31f768203eef47a0d6a"
source = "git+https://github.com/gfx-rs/gfx?rev=aa44854b0dbd05387e26a4735f693d87f57627ab#aa44854b0dbd05387e26a4735f693d87f57627ab"
[[package]]
name = "raw-window-handle"

View File

@ -1,6 +1,3 @@
[[builtin(global_invocation_id)]]
var global_id: vec3<u32>;
[[block]]
struct InOutBuffer {
data: [[stride(4)]] array<u32>;
@ -10,6 +7,6 @@ struct InOutBuffer {
var<storage> buffer: [[access(read_write)]] InOutBuffer;
[[stage(compute), workgroup_size(1)]]
fn main() {
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
buffer.data[global_id.x] = buffer.data[global_id.x] + global_id.x;
}

View File

@ -1,24 +1,16 @@
[[builtin(vertex_index)]]
var<in> in_vertex_index: u32;
[[builtin(position)]]
var<out> out_pos: vec4<f32>;
[[stage(vertex)]]
fn vs_main() {
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
// hacky way to draw a large triangle
var tmp1: i32 = i32(in_vertex_index) / 2;
var tmp2: i32 = i32(in_vertex_index) & 1;
var pos: vec2<f32> = vec2<f32>(
const tmp1: i32 = i32(vertex_index) / 2;
const tmp2: i32 = i32(vertex_index) & 1;
const pos: vec2<f32> = vec2<f32>(
f32(tmp1) * 4.0 - 1.0,
f32(tmp2) * 4.0 - 1.0
);
out_pos = vec4<f32>(pos, 0.0, 1.0);
return vec4<f32>(pos, 0.0, 1.0);
}
[[location(0)]]
var<out> out_color: vec4<f32>;
[[stage(fragment)]]
fn fs_main() {
out_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
fn fs_main() -> [[location(0)]] vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}

View File

@ -38,28 +38,28 @@ thiserror = "1"
gpu-alloc = { version = "0.3", features = ["tracing"] }
gpu-descriptor = { version = "0.1", features = ["tracing"] }
hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
[target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies]
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a", features = ["naga"] }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab", features = ["naga"] }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a", optional = true }
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab", optional = true }
[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a", features = ["naga"] }
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab", features = ["naga"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "cd96e77952dd2e330fe2c31f768203eef47a0d6a" }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "aa44854b0dbd05387e26a4735f693d87f57627ab" }
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
tag = "gfx-13"
tag = "gfx-14"
features = ["spv-in", "spv-out", "wgsl-in"]
[dependencies.wgt]

View File

@ -690,12 +690,67 @@ pub fn check_texture_format(format: wgt::TextureFormat, output: &NumericType) ->
pub type StageIo = FastHashMap<wgt::ShaderLocation, NumericType>;
impl Interface {
fn populate(
list: &mut Vec<Varying>,
binding: Option<&naga::Binding>,
ty: naga::Handle<naga::Type>,
arena: &naga::Arena<naga::Type>,
) {
let numeric_ty = match arena[ty].inner {
naga::TypeInner::Scalar { kind, width } => NumericType {
dim: NumericDimension::Scalar,
kind,
width,
},
naga::TypeInner::Vector { size, kind, width } => NumericType {
dim: NumericDimension::Vector(size),
kind,
width,
},
naga::TypeInner::Matrix {
columns,
rows,
width,
} => NumericType {
dim: NumericDimension::Matrix(columns, rows),
kind: naga::ScalarKind::Float,
width,
},
naga::TypeInner::Struct {
block: _,
ref members,
} => {
for member in members {
Self::populate(list, member.binding.as_ref(), member.ty, arena);
}
return;
}
ref other => {
tracing::error!("Unexpected varying type: {:?}", other);
return;
}
};
let varying = match binding {
Some(&naga::Binding::Location(location, _)) => Varying::Local {
location,
ty: numeric_ty,
},
Some(&naga::Binding::BuiltIn(built_in)) => Varying::BuiltIn(built_in),
None => {
tracing::error!("Missing binding for a varying");
return;
}
};
list.push(varying);
}
pub fn new(module: &naga::Module, analysis: &naga::proc::analyzer::Analysis) -> Self {
let mut resources = naga::Arena::new();
let mut resource_mapping = FastHashMap::default();
for (var_handle, var) in module.global_variables.iter() {
let (group, binding) = match var.binding {
Some(naga::Binding::Resource { group, binding }) => (group, binding),
Some(ref br) => (br.group, br.binding),
_ => continue,
};
let ty = match module.types[var.ty].inner {
@ -722,7 +777,10 @@ impl Interface {
class,
},
naga::TypeInner::Sampler { comparison } => ResourceType::Sampler { comparison },
ref other => panic!("Unexpected resource type: {:?}", other),
ref other => {
tracing::error!("Unexpected resource type: {:?}", other);
continue;
}
};
let handle = resources.append(Resource {
group,
@ -738,54 +796,28 @@ impl Interface {
for (index, entry_point) in (&module.entry_points).iter().enumerate() {
let info = analysis.get_entry_point(index);
let mut ep = EntryPoint::default();
for arg in entry_point.function.arguments.iter() {
Self::populate(&mut ep.inputs, arg.binding.as_ref(), arg.ty, &module.types);
}
if let Some(ref result) = entry_point.function.result {
Self::populate(
&mut ep.outputs,
result.binding.as_ref(),
result.ty,
&module.types,
);
}
for (var_handle, var) in module.global_variables.iter() {
let usage = info[var_handle];
if usage.is_empty() {
continue;
}
let varying = match var.binding {
Some(naga::Binding::Resource { .. }) => {
ep.resources.push((resource_mapping[&var_handle], usage));
None
}
Some(naga::Binding::Location(location)) => {
let ty = match module.types[var.ty].inner {
naga::TypeInner::Scalar { kind, width } => NumericType {
dim: NumericDimension::Scalar,
kind,
width,
},
naga::TypeInner::Vector { size, kind, width } => NumericType {
dim: NumericDimension::Vector(size),
kind,
width,
},
naga::TypeInner::Matrix {
columns,
rows,
width,
} => NumericType {
dim: NumericDimension::Matrix(columns, rows),
kind: naga::ScalarKind::Float,
width,
},
ref other => panic!("Unexpected varying type: {:?}", other),
};
Some(Varying::Local { location, ty })
}
Some(naga::Binding::BuiltIn(built_in)) => Some(Varying::BuiltIn(built_in)),
_ => None,
};
if let Some(varying) = varying {
match var.class {
naga::StorageClass::Input => ep.inputs.push(varying),
naga::StorageClass::Output => ep.outputs.push(varying),
_ => (),
}
if var.binding.is_some() {
ep.resources.push((resource_mapping[&var_handle], usage));
}
}
entry_points.insert((entry_point.stage, entry_point.name.clone()), ep);
}