summaryrefslogtreecommitdiffstats
path: root/third_party/rust/naga/src/back/wgsl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/rust/naga/src/back/wgsl
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/naga/src/back/wgsl')
-rw-r--r--third_party/rust/naga/src/back/wgsl/writer.rs131
1 files changed, 130 insertions, 1 deletions
diff --git a/third_party/rust/naga/src/back/wgsl/writer.rs b/third_party/rust/naga/src/back/wgsl/writer.rs
index 3039cbbbe4..789f6f62bf 100644
--- a/third_party/rust/naga/src/back/wgsl/writer.rs
+++ b/third_party/rust/naga/src/back/wgsl/writer.rs
@@ -106,6 +106,12 @@ impl<W: Write> Writer<W> {
}
pub fn write(&mut self, module: &Module, info: &valid::ModuleInfo) -> BackendResult {
+ if !module.overrides.is_empty() {
+ return Err(Error::Unimplemented(
+ "Pipeline constants are not yet supported for this back-end".to_string(),
+ ));
+ }
+
self.reset(module);
// Save all ep result types
@@ -918,8 +924,124 @@ impl<W: Write> Writer<W> {
if barrier.contains(crate::Barrier::WORK_GROUP) {
writeln!(self.out, "{level}workgroupBarrier();")?;
}
+
+ if barrier.contains(crate::Barrier::SUB_GROUP) {
+ writeln!(self.out, "{level}subgroupBarrier();")?;
+ }
}
Statement::RayQuery { .. } => unreachable!(),
+ Statement::SubgroupBallot { result, predicate } => {
+ write!(self.out, "{level}")?;
+ let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
+ self.start_named_expr(module, result, func_ctx, &res_name)?;
+ self.named_expressions.insert(result, res_name);
+
+ write!(self.out, "subgroupBallot(")?;
+ if let Some(predicate) = predicate {
+ self.write_expr(module, predicate, func_ctx)?;
+ }
+ writeln!(self.out, ");")?;
+ }
+ Statement::SubgroupCollectiveOperation {
+ op,
+ collective_op,
+ argument,
+ result,
+ } => {
+ write!(self.out, "{level}")?;
+ let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
+ self.start_named_expr(module, result, func_ctx, &res_name)?;
+ self.named_expressions.insert(result, res_name);
+
+ match (collective_op, op) {
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::All) => {
+ write!(self.out, "subgroupAll(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Any) => {
+ write!(self.out, "subgroupAny(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Add) => {
+ write!(self.out, "subgroupAdd(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Mul) => {
+ write!(self.out, "subgroupMul(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Max) => {
+ write!(self.out, "subgroupMax(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Min) => {
+ write!(self.out, "subgroupMin(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::And) => {
+ write!(self.out, "subgroupAnd(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Or) => {
+ write!(self.out, "subgroupOr(")?
+ }
+ (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Xor) => {
+ write!(self.out, "subgroupXor(")?
+ }
+ (crate::CollectiveOperation::ExclusiveScan, crate::SubgroupOperation::Add) => {
+ write!(self.out, "subgroupExclusiveAdd(")?
+ }
+ (crate::CollectiveOperation::ExclusiveScan, crate::SubgroupOperation::Mul) => {
+ write!(self.out, "subgroupExclusiveMul(")?
+ }
+ (crate::CollectiveOperation::InclusiveScan, crate::SubgroupOperation::Add) => {
+ write!(self.out, "subgroupInclusiveAdd(")?
+ }
+ (crate::CollectiveOperation::InclusiveScan, crate::SubgroupOperation::Mul) => {
+ write!(self.out, "subgroupInclusiveMul(")?
+ }
+ _ => unimplemented!(),
+ }
+ self.write_expr(module, argument, func_ctx)?;
+ writeln!(self.out, ");")?;
+ }
+ Statement::SubgroupGather {
+ mode,
+ argument,
+ result,
+ } => {
+ write!(self.out, "{level}")?;
+ let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
+ self.start_named_expr(module, result, func_ctx, &res_name)?;
+ self.named_expressions.insert(result, res_name);
+
+ match mode {
+ crate::GatherMode::BroadcastFirst => {
+ write!(self.out, "subgroupBroadcastFirst(")?;
+ }
+ crate::GatherMode::Broadcast(_) => {
+ write!(self.out, "subgroupBroadcast(")?;
+ }
+ crate::GatherMode::Shuffle(_) => {
+ write!(self.out, "subgroupShuffle(")?;
+ }
+ crate::GatherMode::ShuffleDown(_) => {
+ write!(self.out, "subgroupShuffleDown(")?;
+ }
+ crate::GatherMode::ShuffleUp(_) => {
+ write!(self.out, "subgroupShuffleUp(")?;
+ }
+ crate::GatherMode::ShuffleXor(_) => {
+ write!(self.out, "subgroupShuffleXor(")?;
+ }
+ }
+ self.write_expr(module, argument, func_ctx)?;
+ match mode {
+ crate::GatherMode::BroadcastFirst => {}
+ crate::GatherMode::Broadcast(index)
+ | crate::GatherMode::Shuffle(index)
+ | crate::GatherMode::ShuffleDown(index)
+ | crate::GatherMode::ShuffleUp(index)
+ | crate::GatherMode::ShuffleXor(index) => {
+ write!(self.out, ", ")?;
+ self.write_expr(module, index, func_ctx)?;
+ }
+ }
+ writeln!(self.out, ");")?;
+ }
}
Ok(())
@@ -1070,7 +1192,7 @@ impl<W: Write> Writer<W> {
self.write_possibly_const_expression(
module,
expr,
- &module.const_expressions,
+ &module.global_expressions,
|writer, expr| writer.write_const_expression(module, expr),
)
}
@@ -1199,6 +1321,7 @@ impl<W: Write> Writer<W> {
|writer, expr| writer.write_expr(module, expr, func_ctx),
)?;
}
+ Expression::Override(_) => unreachable!(),
Expression::FunctionArgument(pos) => {
let name_key = func_ctx.argument_key(pos);
let name = &self.names[&name_key];
@@ -1691,6 +1814,8 @@ impl<W: Write> Writer<W> {
Expression::CallResult(_)
| Expression::AtomicResult { .. }
| Expression::RayQueryProceedResult
+ | Expression::SubgroupBallotResult
+ | Expression::SubgroupOperationResult { .. }
| Expression::WorkGroupUniformLoadResult { .. } => {}
}
@@ -1792,6 +1917,10 @@ fn builtin_str(built_in: crate::BuiltIn) -> Result<&'static str, Error> {
Bi::SampleMask => "sample_mask",
Bi::PrimitiveIndex => "primitive_index",
Bi::ViewIndex => "view_index",
+ Bi::NumSubgroups => "num_subgroups",
+ Bi::SubgroupId => "subgroup_id",
+ Bi::SubgroupSize => "subgroup_size",
+ Bi::SubgroupInvocationId => "subgroup_invocation_id",
Bi::BaseInstance
| Bi::BaseVertex
| Bi::ClipDistance