handle all type resolution in the lowerer

This commit is contained in:
teoxoy authored and Teodor Tanasoaia committed 2026-01-28 12:00:35 +01:00
1 parent cb401cef90
commit 1ef831ad2c
25 files changed
+250 -1230

No files matched your search

-9
View File
@@ -146,8 +146,6 @@ pub enum ExpectedToken<'a> {
WorkgroupSizeSeparator,
/// Expected: 'struct', 'let', 'var', 'type', ';', 'fn', eof
GlobalItem,
/// Expected a type.
Type,
/// Access of `var`, `let`, `const`.
Variable,
/// Access of a function
@@ -207,7 +205,6 @@ pub(crate) enum Error<'a> {
UnknownAccess(Span),
UnknownIdent(Span, &'a str),
UnknownScalarType(Span),
UnknownType(Span),
UnknownStorageFormat(Span),
UnknownConservativeDepth(Span),
UnknownEnableExtension(Span, &'a str),
@@ -524,7 +521,6 @@ impl<'a> Error<'a> {
"or the end of the file"
)
.to_string(),
ExpectedToken::Type => "type".to_string(),
ExpectedToken::Variable => "variable access".to_string(),
ExpectedToken::Function => "function name".to_string(),
ExpectedToken::AfterIdentListArg => {
@@ -710,11 +706,6 @@ impl<'a> Error<'a> {
labels: vec![(bad_span, "unknown conservative depth".into())],
notes: vec![],
},
Error::UnknownType(bad_span) => ParseError {
message: format!("unknown type: `{}`", &source[bad_span]),
labels: vec![(bad_span, "unknown type".into())],
notes: vec![],
},
Error::UnknownEnableExtension(span, word) => ParseError {
message: format!("unknown enable-extension `{word}`"),
labels: vec![(span, "".into())],
+55 -226
View File
@@ -93,9 +93,6 @@ pub struct GlobalContext<'source, 'temp, 'out> {
/// The `TranslationUnit`'s expressions arena.
ast_expressions: &'temp Arena<ast::Expression<'source>>,
/// The `TranslationUnit`'s types arena.
types: &'temp Arena<ast::Type<'source>>,
// Naga IR values.
/// The map from the names of module-scope declarations to the Naga IR
/// `Handle`s we have built for them, owned by `Lowerer::lower`.
@@ -117,7 +114,6 @@ impl<'source> GlobalContext<'source, '_, '_> {
enable_extensions: self.enable_extensions,
ast_expressions: self.ast_expressions,
globals: self.globals,
types: self.types,
module: self.module,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -131,7 +127,6 @@ impl<'source> GlobalContext<'source, '_, '_> {
enable_extensions: self.enable_extensions,
ast_expressions: self.ast_expressions,
globals: self.globals,
types: self.types,
module: self.module,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -162,12 +157,6 @@ pub struct StatementContext<'source, 'temp, 'out> {
/// [`TranslationUnit::expressions`]: ast::TranslationUnit::expressions
ast_expressions: &'temp Arena<ast::Expression<'source>>,
/// A reference to [`TranslationUnit::types`] for the translation unit
/// we're lowering.
///
/// [`TranslationUnit::types`]: ast::TranslationUnit::types
types: &'temp Arena<ast::Type<'source>>,
// Naga IR values.
/// The map from the names of module-scope declarations to the Naga IR
/// `Handle`s we have built for them, owned by `Lowerer::lower`.
@@ -224,7 +213,6 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> {
ExpressionContext {
enable_extensions: self.enable_extensions,
globals: self.globals,
types: self.types,
ast_expressions: self.ast_expressions,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -252,7 +240,6 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> {
ExpressionContext {
enable_extensions: self.enable_extensions,
globals: self.globals,
types: self.types,
ast_expressions: self.ast_expressions,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -275,7 +262,6 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> {
enable_extensions: self.enable_extensions,
ast_expressions: self.ast_expressions,
globals: self.globals,
types: self.types,
module: self.module,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -385,7 +371,6 @@ pub struct ExpressionContext<'source, 'temp, 'out> {
// WGSL AST values.
ast_expressions: &'temp Arena<ast::Expression<'source>>,
types: &'temp Arena<ast::Type<'source>>,
// Naga IR values.
/// The map from the names of module-scope declarations to the Naga IR
@@ -454,7 +439,6 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
ExpressionContext {
enable_extensions: self.enable_extensions,
globals: self.globals,
types: self.types,
ast_expressions: self.ast_expressions,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -483,7 +467,6 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
enable_extensions: self.enable_extensions,
ast_expressions: self.ast_expressions,
globals: self.globals,
types: self.types,
module: self.module,
const_typifier: self.const_typifier,
layouter: self.layouter,
@@ -681,7 +664,6 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
enable_extensions: self.enable_extensions,
expr_type: ExpressionContextType::Runtime(nested_rctx),
ast_expressions: self.ast_expressions,
types: self.types,
globals: self.globals,
module: self.module,
const_typifier: self.const_typifier,
@@ -1221,7 +1203,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
enable_extensions: tu.enable_extensions,
ast_expressions: &tu.expressions,
globals: &mut FastHashMap::default(),
types: &tu.types,
module: &mut module,
const_typifier: &mut Typifier::new(),
layouter: &mut proc::Layouter::default(),
@@ -1266,7 +1247,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
ast::GlobalDeclKind::Var(ref v) => {
let explicit_ty =
v.ty.map(|ast| self.resolve_ast_type(ast, &mut ctx.as_const()))
v.ty.as_ref()
.map(|ast| self.resolve_ast_type(ast, &mut ctx.as_const()))
.transpose()?;
let (ty, initializer) = self.type_and_init(
@@ -1315,7 +1297,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let mut ectx = ctx.as_const();
let explicit_ty =
c.ty.map(|ast| self.resolve_ast_type(ast, &mut ectx))
c.ty.as_ref()
.map(|ast| self.resolve_ast_type(ast, &mut ectx))
.transpose()?;
let (ty, init) = self.type_and_init(
@@ -1350,7 +1333,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
ast::GlobalDeclKind::Override(ref o) => {
let explicit_ty =
o.ty.map(|ast| self.resolve_ast_type(ast, &mut ctx.as_const()))
o.ty.as_ref()
.map(|ast| self.resolve_ast_type(ast, &mut ctx.as_const()))
.transpose()?;
let mut ectx = ctx.as_override();
@@ -1405,8 +1389,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
ast::GlobalDeclKind::Type(ref alias) => {
let ty = self.resolve_named_ast_type(
alias.ty,
Some(alias.name.name.to_string()),
&alias.ty,
alias.name.name.to_string(),
&mut ctx.as_const(),
)?;
ctx.globals
@@ -1513,7 +1497,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
.iter()
.enumerate()
.map(|(i, arg)| -> Result<'_, _> {
let ty = self.resolve_ast_type(arg.ty, &mut ctx.as_const())?;
let ty = self.resolve_ast_type(&arg.ty, &mut ctx.as_const())?;
let expr =
expressions.append(ir::Expression::FunctionArgument(i as u32), arg.name.span);
local_table.insert(arg.handle, Declared::Runtime(Typed::Plain(expr)));
@@ -1532,7 +1516,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
.result
.as_ref()
.map(|res| -> Result<'_, _> {
let ty = self.resolve_ast_type(res.ty, &mut ctx.as_const())?;
let ty = self.resolve_ast_type(&res.ty, &mut ctx.as_const())?;
Ok(ir::FunctionResult {
ty,
binding: self.binding(&res.binding, ty, ctx)?,
@@ -1562,7 +1546,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
layouter: ctx.layouter,
function: &mut function,
named_expressions: &mut named_expressions,
types: ctx.types,
module: ctx.module,
local_expression_kind_tracker: &mut local_expression_kind_tracker,
global_expression_kind_tracker: ctx.global_expression_kind_tracker,
@@ -1735,6 +1718,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let explicit_ty = l
.ty
.as_ref()
.map(|ty| self.resolve_ast_type(ty, &mut ctx.as_const(block, &mut emitter)))
.transpose()?;
@@ -1774,10 +1758,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
emitter.start(&ctx.function.expressions);
let explicit_ty =
v.ty.map(|ast| {
self.resolve_ast_type(ast, &mut ctx.as_const(block, &mut emitter))
})
.transpose()?;
v.ty.as_ref()
.map(|ast| {
self.resolve_ast_type(ast, &mut ctx.as_const(block, &mut emitter))
})
.transpose()?;
let mut ectx = ctx.as_expression(block, &mut emitter);
let (ty, initializer) = self.type_and_init(
@@ -1841,7 +1826,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let ectx = &mut ctx.as_const(block, &mut emitter);
let explicit_ty =
c.ty.map(|ast| self.resolve_ast_type(ast, &mut ectx.as_const()))
c.ty.as_ref()
.map(|ast| self.resolve_ast_type(ast, &mut ectx.as_const()))
.transpose()?;
let (_ty, init) = self.type_and_init(
@@ -2617,16 +2603,34 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let span = ctx.ast_expressions.get_span(expr);
let expr = &ctx.ast_expressions[expr];
let (ident, ident_span, template_list) = match expr {
&ast::Expression::Ident(ast::TemplateElaboratedIdent {
ident: ast::IdentExpr::Unresolved(ident),
ident_span,
ref template_list,
..
}) => (ident, ident_span, template_list),
let ident = match *expr {
ast::Expression::Ident(ref ident) => ident,
_ => return Err(Box::new(Error::UnexpectedExprForTypeExpression(span))),
};
self.type_specifier(ident, ctx, None)
}
fn type_specifier(
&mut self,
ident: &ast::TemplateElaboratedIdent<'source>,
ctx: &mut ExpressionContext<'source, '_, '_>,
alias_name: Option<String>,
) -> Result<'source, Handle<ir::Type>> {
let &ast::TemplateElaboratedIdent {
ref ident,
ident_span,
ref template_list,
..
} = ident;
let ident = match *ident {
ast::IdentExpr::Unresolved(ident) => ident,
ast::IdentExpr::Local(_) => {
return Err(Box::new(Error::UnexpectedExprForTypeExpression(ident_span)))
}
};
let mut tl = TemplateListIter::new(ident_span, template_list);
if let Some(global) = ctx.globals.get(ident) {
@@ -2635,7 +2639,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
tl.finish(ctx)?;
return Ok(handle);
}
_ => return Err(Box::new(Error::UnexpectedExprForTypeExpression(span))),
_ => return Err(Box::new(Error::UnexpectedExprForTypeExpression(ident_span))),
}
}
@@ -2643,7 +2647,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let Some(ty) = ty else {
return Err(Box::new(Error::UnknownIdent(ident_span, ident)));
};
let ty = self.finalize_type(ctx, ty, &mut tl)?;
let ty = self.finalize_type(ctx, ty, &mut tl, alias_name)?;
tl.finish(ctx)?;
@@ -2655,6 +2659,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
ctx: &mut ExpressionContext<'source, '_, '_>,
ty: conv::PredeclaredType,
tl: &mut TemplateListIter<'_, 'source>,
alias_name: Option<String>,
) -> Result<'source, Handle<ir::Type>> {
let ty = match ty {
conv::PredeclaredType::TypeInner(ty_inner) => {
@@ -2681,7 +2686,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
_ => {}
}
ctx.as_global().ensure_type_exists(None, ty_inner)
ctx.as_global().ensure_type_exists(alias_name, ty_inner)
}
conv::PredeclaredType::RayDesc => ctx.module.generate_ray_desc_type(),
conv::PredeclaredType::RayIntersection => ctx.module.generate_ray_intersection_type(),
@@ -2783,7 +2788,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
}
};
ctx.as_global().ensure_type_exists(None, ty_inner)
ctx.as_global().ensure_type_exists(alias_name, ty_inner)
}
};
Ok(ty)
@@ -3096,7 +3101,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
) if empty_template_list => {
return Err(Box::new(Error::UnderspecifiedCooperativeMatrix));
}
_ => Constructor::Type(self.finalize_type(ctx, ty, &mut tl)?),
_ => Constructor::Type(self.finalize_type(ctx, ty, &mut tl, None)?),
};
tl.finish(ctx)?;
let handle =
@@ -4381,7 +4386,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let mut doc_comments: Vec<Option<Vec<String>>> = Vec::new();
for member in s.members.iter() {
let ty = self.resolve_ast_type(member.ty, &mut ctx.as_const())?;
let ty = self.resolve_ast_type(&member.ty, &mut ctx.as_const())?;
ctx.layouter.update(ctx.module.to_ctx()).map_err(|err| {
let LayoutErrorInner::TooLarge = err.inner else {
@@ -4505,56 +4510,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
fn array_size(
&mut self,
size: ast::ArraySize<'source>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<'source, ir::ArraySize> {
Ok(match size {
ast::ArraySize::Constant(expr) => {
let span = ctx.ast_expressions.get_span(expr);
let const_expr = self.expression(expr, &mut ctx.as_const());
match const_expr {
Ok(value) => {
let len = ctx.get_const_val(value).map_err(|err| {
Box::new(match err {
proc::ConstValueError::NonConst
| proc::ConstValueError::InvalidType => {
Error::ExpectedConstExprConcreteIntegerScalar(span)
}
proc::ConstValueError::Negative => {
Error::ExpectedPositiveArrayLength(span)
}
})
})?;
let size =
NonZeroU32::new(len).ok_or(Error::ExpectedPositiveArrayLength(span))?;
ir::ArraySize::Constant(size)
}
Err(err) => {
if let Error::ConstantEvaluatorError(ref ty, _) = *err {
match **ty {
proc::ConstantEvaluatorError::OverrideExpr => {
ir::ArraySize::Pending(self.array_size_override(
expr,
&mut ctx.as_global().as_override(),
span,
)?)
}
_ => {
return Err(err);
}
}
} else {
return Err(err);
}
}
}
}
ast::ArraySize::Dynamic => ir::ArraySize::Dynamic,
})
}
fn array_size2(
&mut self,
expr: Handle<ast::Expression<'source>>,
ctx: &mut ExpressionContext<'source, '_, '_>,
@@ -4635,146 +4590,20 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
/// [`SpecialTypes`]: ir::SpecialTypes
fn resolve_named_ast_type(
&mut self,
handle: Handle<ast::Type<'source>>,
name: Option<String>,
ident: &ast::TemplateElaboratedIdent<'source>,
name: String,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<'source, Handle<ir::Type>> {
let inner = match ctx.types[handle] {
ast::Type::Scalar(scalar) => scalar.to_inner_scalar(),
ast::Type::Vector { size, ty, ty_span } => {
let ty = self.resolve_ast_type(ty, ctx)?;
let scalar = match ctx.module.types[ty].inner {
ir::TypeInner::Scalar(sc) => sc,
_ => return Err(Box::new(Error::UnknownScalarType(ty_span))),
};
ir::TypeInner::Vector { size, scalar }
}
ast::Type::Matrix {
rows,
columns,
ty,
ty_span,
} => {
let ty = self.resolve_ast_type(ty, ctx)?;
let scalar = match ctx.module.types[ty].inner {
ir::TypeInner::Scalar(sc) => sc,
_ => return Err(Box::new(Error::UnknownScalarType(ty_span))),
};
match scalar.kind {
ir::ScalarKind::Float => ir::TypeInner::Matrix {
columns,
rows,
scalar,
},
_ => return Err(Box::new(Error::BadMatrixScalarKind(ty_span, scalar))),
}
}
ast::Type::CooperativeMatrix {
columns,
rows,
ty,
ty_span,
role,
} => {
let ty = self.resolve_ast_type(ty, ctx)?;
let scalar = match ctx.module.types[ty].inner {
ir::TypeInner::Scalar(s) => s,
_ => return Err(Box::new(Error::UnsupportedCooperativeScalar(ty_span))),
};
ir::TypeInner::CooperativeMatrix {
columns,
rows,
scalar,
role,
}
}
ast::Type::Atomic(scalar) => scalar.to_inner_atomic(),
ast::Type::Pointer { base, space } => {
let base = self.resolve_ast_type(base, ctx)?;
ir::TypeInner::Pointer { base, space }
}
ast::Type::Array { base, size } => {
let base = self.resolve_ast_type(base, &mut ctx.as_const())?;
let size = self.array_size(size, ctx)?;
// Determine the size of the base type, if needed.
ctx.layouter.update(ctx.module.to_ctx()).map_err(|err| {
let LayoutErrorInner::TooLarge = err.inner else {
unreachable!("unexpected layout error: {err:?}");
};
// Lots of type definitions don't get spans, so this error
// message may not be very useful.
Box::new(Error::TypeTooLarge {
span: ctx.module.types.get_span(err.ty),
})
})?;
let stride = ctx.layouter[base].to_stride();
ir::TypeInner::Array { base, size, stride }
}
ast::Type::Image {
dim,
arrayed,
class,
} => {
if class == crate::ImageClass::External {
// Other than the WGSL backend, every backend that supports
// external textures does so by lowering them to a set of
// ordinary textures and some parameters saying how to
// sample from them. We don't know which backend will
// consume the `Module` we're building, but in case it's not
// WGSL, populate `SpecialTypes::external_texture_params`
// and `SpecialTypes::external_texture_transfer_function`
// with the types the backend will use for the parameter
// buffer.
//
// Neither of these are the type we are lowering here:
// that's an ordinary `TypeInner::Image`. But the fact we
// are lowering a `texture_external` implies the backends
// may need these additional types too.
ctx.module.generate_external_texture_types();
}
ir::TypeInner::Image {
dim,
arrayed,
class,
}
}
ast::Type::Sampler { comparison } => ir::TypeInner::Sampler { comparison },
ast::Type::AccelerationStructure { vertex_return } => {
ir::TypeInner::AccelerationStructure { vertex_return }
}
ast::Type::RayQuery { vertex_return } => ir::TypeInner::RayQuery { vertex_return },
ast::Type::BindingArray { base, size } => {
let base = self.resolve_ast_type(base, ctx)?;
let size = self.array_size(size, ctx)?;
ir::TypeInner::BindingArray { base, size }
}
ast::Type::RayDesc => {
return Ok(ctx.module.generate_ray_desc_type());
}
ast::Type::RayIntersection => {
return Ok(ctx.module.generate_ray_intersection_type());
}
ast::Type::User(ref ident) => {
return match ctx.globals.get(ident.name) {
Some(&LoweredGlobalDecl::Type(handle)) => Ok(handle),
Some(_) => Err(Box::new(Error::Unexpected(ident.span, ExpectedToken::Type))),
None => Err(Box::new(Error::UnknownType(ident.span))),
}
}
};
Ok(ctx.as_global().ensure_type_exists(name, inner))
self.type_specifier(ident, ctx, Some(name))
}
/// Return a Naga `Handle<Type>` representing the front-end type `handle`.
fn resolve_ast_type(
&mut self,
handle: Handle<ast::Type<'source>>,
ident: &ast::TemplateElaboratedIdent<'source>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<'source, Handle<ir::Type>> {
self.resolve_named_ast_type(handle, None, ctx)
self.type_specifier(ident, ctx, None)
}
fn binding(
+2 -2
View File
@@ -94,7 +94,7 @@ impl<'iter, 'source> TemplateListIter<'iter, 'source> {
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<'source, ir::ArraySize> {
if let Some(expr) = self.template_list.next() {
lowerer.array_size2(*expr, ctx)
lowerer.array_size(*expr, ctx)
} else {
Ok(ir::ArraySize::Dynamic)
}
@@ -165,7 +165,7 @@ impl<'iter, 'source> TemplateListIter<'iter, 'source> {
) -> Result<'source, bool> {
if let Some(expr) = self.template_list.next() {
let (enumerant, span) = Lowerer::enumerant(*expr, ctx)?;
conv::map_ray_flag(enumerant, span)?;
conv::map_ray_flag(&ctx.enable_extensions, enumerant, span)?;
Ok(true)
} else {
Ok(false)
+10 -83
View File
@@ -4,7 +4,6 @@ use core::hash::Hash;
use crate::diagnostic_filter::DiagnosticFilterNode;
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
use crate::front::wgsl::parse::number::Number;
use crate::front::wgsl::Scalar;
use crate::{Arena, FastIndexSet, Handle, Span};
#[derive(Debug, Default)]
@@ -24,12 +23,6 @@ pub struct TranslationUnit<'a> {
/// [`Function`]: crate::Function
pub expressions: Arena<Expression<'a>>,
/// Non-user-defined types, like `vec4<f32>` or `array<i32, 10>`.
///
/// These are referred to by `Handle<ast::Type<'a>>` values.
/// User-defined types are referred to by name until lowering.
pub types: Arena<Type<'a>>,
/// Arena for all diagnostic filter rules parsed in this module, including those in functions.
///
/// See [`DiagnosticFilterNode`] for details on how the tree is represented and used in
@@ -139,14 +132,14 @@ pub enum GlobalDeclKind<'a> {
#[derive(Debug)]
pub struct FunctionArgument<'a> {
pub name: Ident<'a>,
pub ty: Handle<Type<'a>>,
pub ty: TemplateElaboratedIdent<'a>,
pub binding: Option<Binding<'a>>,
pub handle: Handle<Local>,
}
#[derive(Debug)]
pub struct FunctionResult<'a> {
pub ty: Handle<Type<'a>>,
pub ty: TemplateElaboratedIdent<'a>,
pub binding: Option<Binding<'a>>,
pub must_use: bool,
}
@@ -197,7 +190,7 @@ pub struct GlobalVariable<'a> {
pub name: Ident<'a>,
pub template_list: Vec<Handle<Expression<'a>>>,
pub binding: Option<ResourceBinding<'a>>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Option<Handle<Expression<'a>>>,
pub doc_comments: Vec<&'a str>,
}
@@ -205,7 +198,7 @@ pub struct GlobalVariable<'a> {
#[derive(Debug)]
pub struct StructMember<'a> {
pub name: Ident<'a>,
pub ty: Handle<Type<'a>>,
pub ty: TemplateElaboratedIdent<'a>,
pub binding: Option<Binding<'a>>,
pub align: Option<Handle<Expression<'a>>>,
pub size: Option<Handle<Expression<'a>>>,
@@ -222,13 +215,13 @@ pub struct Struct<'a> {
#[derive(Debug)]
pub struct TypeAlias<'a> {
pub name: Ident<'a>,
pub ty: Handle<Type<'a>>,
pub ty: TemplateElaboratedIdent<'a>,
}
#[derive(Debug)]
pub struct Const<'a> {
pub name: Ident<'a>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Handle<Expression<'a>>,
pub doc_comments: Vec<&'a str>,
}
@@ -237,76 +230,10 @@ pub struct Const<'a> {
pub struct Override<'a> {
pub name: Ident<'a>,
pub id: Option<Handle<Expression<'a>>>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Option<Handle<Expression<'a>>>,
}
/// The size of an [`Array`] or [`BindingArray`].
///
/// [`Array`]: Type::Array
/// [`BindingArray`]: Type::BindingArray
#[derive(Debug, Copy, Clone)]
pub enum ArraySize<'a> {
/// The length as a constant expression.
Constant(Handle<Expression<'a>>),
Dynamic,
}
#[derive(Debug)]
pub enum Type<'a> {
Scalar(Scalar),
Vector {
size: crate::VectorSize,
ty: Handle<Type<'a>>,
ty_span: Span,
},
Matrix {
columns: crate::VectorSize,
rows: crate::VectorSize,
ty: Handle<Type<'a>>,
ty_span: Span,
},
CooperativeMatrix {
columns: crate::CooperativeSize,
rows: crate::CooperativeSize,
ty: Handle<Type<'a>>,
ty_span: Span,
role: crate::CooperativeRole,
},
Atomic(Scalar),
Pointer {
base: Handle<Type<'a>>,
space: crate::AddressSpace,
},
Array {
base: Handle<Type<'a>>,
size: ArraySize<'a>,
},
Image {
dim: crate::ImageDimension,
arrayed: bool,
class: crate::ImageClass,
},
Sampler {
comparison: bool,
},
AccelerationStructure {
vertex_return: bool,
},
RayQuery {
vertex_return: bool,
},
RayDesc,
RayIntersection,
BindingArray {
base: Handle<Type<'a>>,
size: ArraySize<'a>,
},
/// A user-defined type, like a struct or a type alias.
User(Ident<'a>),
}
#[derive(Debug, Default)]
pub struct Block<'a> {
pub stmts: Vec<Statement<'a>>,
@@ -405,7 +332,7 @@ pub enum Expression<'a> {
#[derive(Debug)]
pub struct LocalVariable<'a> {
pub name: Ident<'a>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Option<Handle<Expression<'a>>>,
pub handle: Handle<Local>,
}
@@ -413,7 +340,7 @@ pub struct LocalVariable<'a> {
#[derive(Debug)]
pub struct Let<'a> {
pub name: Ident<'a>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Handle<Expression<'a>>,
pub handle: Handle<Local>,
}
@@ -421,7 +348,7 @@ pub struct Let<'a> {
#[derive(Debug)]
pub struct LocalConst<'a> {
pub name: Ident<'a>,
pub ty: Option<Handle<Type<'a>>>,
pub ty: Option<TemplateElaboratedIdent<'a>>,
pub init: Handle<Expression<'a>>,
pub handle: Handle<Local>,
}
+28 -56
View File
@@ -46,9 +46,21 @@ pub fn map_access_mode(word: &str, span: Span) -> Result<'_, crate::StorageAcces
}
}
pub fn map_ray_flag(word: &str, span: Span) -> Result<'_, ()> {
pub fn map_ray_flag(
enable_extensions: &EnableExtensions,
word: &str,
span: Span,
) -> Result<'static, ()> {
match word {
"vertex_return" => Ok(()),
"vertex_return" => {
if !enable_extensions.contains(ImplementedEnableExtension::WgpuRayQueryVertexReturn) {
return Err(Box::new(Error::EnableExtensionNotEnabled {
span,
kind: ImplementedEnableExtension::WgpuRayQueryVertexReturn.into(),
}));
}
Ok(())
}
_ => Err(Box::new(Error::UnknownRayFlag(span))),
}
}
@@ -204,60 +216,6 @@ pub fn map_storage_format(word: &str, span: Span) -> Result<'_, crate::StorageFo
})
}
pub fn get_scalar_type(
enable_extensions: &EnableExtensions,
span: Span,
word: &str,
) -> Result<'static, Option<Scalar>> {
use crate::ScalarKind as Sk;
let scalar = match word {
"f16" => Some(Scalar {
kind: Sk::Float,
width: 2,
}),
"f32" => Some(Scalar {
kind: Sk::Float,
width: 4,
}),
"f64" => Some(Scalar {
kind: Sk::Float,
width: 8,
}),
"i32" => Some(Scalar {
kind: Sk::Sint,
width: 4,
}),
"u32" => Some(Scalar {
kind: Sk::Uint,
width: 4,
}),
"i64" => Some(Scalar {
kind: Sk::Sint,
width: 8,
}),
"u64" => Some(Scalar {
kind: Sk::Uint,
width: 8,
}),
"bool" => Some(Scalar {
kind: Sk::Bool,
width: crate::BOOL_WIDTH,
}),
_ => None,
};
if matches!(scalar, Some(Scalar::F16))
&& !enable_extensions.contains(ImplementedEnableExtension::F16)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
span,
kind: ImplementedEnableExtension::F16.into(),
}));
}
Ok(scalar)
}
pub fn map_derivative(word: &str) -> Option<(crate::DerivativeAxis, crate::DerivativeControl)> {
use crate::{DerivativeAxis as Axis, DerivativeControl as Ctrl};
match word {
@@ -592,5 +550,19 @@ pub fn map_predeclared_type(
}
}
if matches!(
ty,
PredeclaredType::RayDesc
| PredeclaredType::RayIntersection
| PredeclaredType::TypeGenerator(TypeGenerator::AccelerationStructure)
| PredeclaredType::TypeGenerator(TypeGenerator::RayQuery)
) && !enable_extensions.contains(ImplementedEnableExtension::WgpuRayQuery)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
span,
kind: ImplementedEnableExtension::WgpuRayQuery.into(),
}));
}
Ok(Some(ty))
}
+4 -68
View File
@@ -1,8 +1,9 @@
use super::{number::consume_number, Error, ExpectedToken, Result};
use crate::front::wgsl::error::NumberError;
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
use crate::front::wgsl::parse::{conv, Number};
use crate::front::wgsl::{ImplementedEnableExtension, Scalar};
use crate::front::wgsl::parse::directive::enable_extension::{
EnableExtensions, ImplementedEnableExtension,
};
use crate::front::wgsl::parse::Number;
use crate::Span;
use alloc::{boxed::Box, vec::Vec};
@@ -554,10 +555,6 @@ impl<'a> Lexer<'a> {
Ok(())
}
pub(in crate::front::wgsl) fn end_of_generic_arguments(&mut self) -> bool {
self.next_if(Token::Separator(',')) && self.peek().0 != Token::TemplateArgsEnd
}
pub(in crate::front::wgsl) fn next_ident_with_span(&mut self) -> Result<'a, (&'a str, Span)> {
match self.next() {
(Token::Word("_"), span) => Err(Box::new(Error::InvalidIdentifierUnderscore(span))),
@@ -586,67 +583,6 @@ impl<'a> Lexer<'a> {
}
}
/// Parses a generic scalar type, for example `<f32>`.
///
/// Returns the span covering the inner type, excluding the brackets.
pub(in crate::front::wgsl) fn next_scalar_generic_with_span(
&mut self,
) -> Result<'a, (Scalar, Span)> {
self.expect(Token::TemplateArgsStart)?;
let (scalar, span) = match self.next() {
(Token::Word(word), span) => {
conv::get_scalar_type(&self.enable_extensions, span, word)?
.map(|scalar| (scalar, span))
.ok_or(Error::UnknownScalarType(span))?
}
(_, span) => return Err(Box::new(Error::UnknownScalarType(span))),
};
self.expect(Token::TemplateArgsEnd)?;
Ok((scalar, span))
}
pub(in crate::front::wgsl) fn next_format_generic(
&mut self,
) -> Result<'a, (crate::StorageFormat, crate::StorageAccess)> {
self.expect(Token::TemplateArgsStart)?;
let (ident, ident_span) = self.next_ident_with_span()?;
let format = conv::map_storage_format(ident, ident_span)?;
self.expect(Token::Separator(','))?;
let (ident, ident_span) = self.next_ident_with_span()?;
let access = conv::map_access_mode(ident, ident_span)?;
self.expect(Token::TemplateArgsEnd)?;
Ok((format, access))
}
pub(in crate::front::wgsl) fn next_acceleration_structure_flags(&mut self) -> Result<'a, bool> {
Ok(if self.next_if(Token::TemplateArgsStart) {
if !self.next_if(Token::TemplateArgsEnd) {
let (name, span) = self.next_ident_with_span()?;
let ret = if name == "vertex_return" {
true
} else {
return Err(Box::new(Error::UnknownAttribute(span)));
};
self.next_if(Token::Separator(','));
self.expect(Token::TemplateArgsEnd)?;
ret
} else {
false
}
} else {
false
})
}
pub(in crate::front::wgsl) fn next_cooperative_role(
&mut self,
) -> Result<'a, crate::CooperativeRole> {
let (ident, span) = self.next_ident_with_span()?;
conv::map_cooperative_role(ident, span)
}
pub(in crate::front::wgsl) fn open_arguments(&mut self) -> Result<'a, ()> {
self.expect(Token::Paren('('))
}
+5 -649
View File
@@ -11,7 +11,7 @@ use crate::front::wgsl::parse::directive::language_extension::LanguageExtension;
use crate::front::wgsl::parse::directive::DirectiveKind;
use crate::front::wgsl::parse::lexer::{Lexer, Token, TokenSpan};
use crate::front::wgsl::parse::number::Number;
use crate::front::wgsl::{Result, Scalar};
use crate::front::wgsl::Result;
use crate::front::SymbolTable;
use crate::{Arena, FastHashSet, FastIndexSet, Handle, ShaderStage, Span};
@@ -34,12 +34,6 @@ struct ExpressionContext<'input, 'temp, 'out> {
/// [`TranslationUnit::expressions`]: ast::TranslationUnit::expressions
expressions: &'out mut Arena<ast::Expression<'input>>,
/// The [`TranslationUnit::types`] arena to which we should contribute new
/// types.
///
/// [`TranslationUnit::types`]: ast::TranslationUnit::types
types: &'out mut Arena<ast::Type<'input>>,
/// A map from identifiers in scope to the locals/arguments they represent.
///
/// The handles refer to the [`locals`] arena; see that field's
@@ -120,11 +114,6 @@ impl<'a> ExpressionContext<'a, '_, '_> {
Ok(handle)
}
}
fn new_scalar(&mut self, scalar: Scalar) -> Handle<ast::Type<'a>> {
self.types
.append(ast::Type::Scalar(scalar), Span::UNDEFINED)
}
}
/// Which grammar rule we are in the midst of parsing.
@@ -136,7 +125,6 @@ impl<'a> ExpressionContext<'a, '_, '_> {
enum Rule {
Attribute,
VariableDecl,
TypeDecl,
FunctionDecl,
Block,
Statement,
@@ -561,17 +549,6 @@ impl Parser {
Ok(expr)
}
fn const_generic_expression<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, Handle<ast::Expression<'a>>> {
self.push_rule_span(Rule::GenericExpr, lexer);
let expr = self.expression(lexer, ctx)?;
self.pop_rule_span(lexer);
Ok(expr)
}
/// Parse a `unary_expression`.
fn unary_expression<'a>(
&mut self,
@@ -873,7 +850,7 @@ impl Parser {
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, (ast::Ident<'a>, Option<Handle<ast::Type<'a>>>)> {
) -> Result<'a, (ast::Ident<'a>, Option<ast::TemplateElaboratedIdent<'a>>)> {
let name = lexer.next_ident()?;
let ty = if lexer.next_if(Token::Separator(':')) {
@@ -1024,632 +1001,13 @@ impl Parser {
})
}
/// Parses `<T>`, returning T and span of T
fn singular_generic<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, (Handle<ast::Type<'a>>, Span)> {
lexer.expect(Token::TemplateArgsStart)?;
let start = lexer.start_byte_offset();
let ty = self.type_specifier(lexer, ctx)?;
let span = lexer.span_from(start);
lexer.next_if(Token::Separator(','));
lexer.expect(Token::TemplateArgsEnd)?;
Ok((ty, span))
}
/// Parses `<T,R>`, returning (T, span of T, R)
fn cooperative_scalar_and_role<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, (Handle<ast::Type<'a>>, Span, crate::CooperativeRole)> {
lexer.expect(Token::TemplateArgsStart)?;
let start = lexer.start_byte_offset();
let ty = self.type_specifier(lexer, ctx)?;
let ty_span = lexer.span_from(start);
lexer.expect(Token::Separator(','))?;
let role = lexer.next_cooperative_role()?;
lexer.expect(Token::TemplateArgsEnd)?;
Ok((ty, ty_span, role))
}
fn matrix_with_type<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
columns: crate::VectorSize,
rows: crate::VectorSize,
) -> Result<'a, ast::Type<'a>> {
let (ty, ty_span) = self.singular_generic(lexer, ctx)?;
Ok(ast::Type::Matrix {
columns,
rows,
ty,
ty_span,
})
}
fn cooperative_matrix_with_type<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
columns: crate::CooperativeSize,
rows: crate::CooperativeSize,
) -> Result<'a, ast::Type<'a>> {
let (ty, ty_span, role) = self.cooperative_scalar_and_role(lexer, ctx)?;
Ok(ast::Type::CooperativeMatrix {
columns,
rows,
ty,
ty_span,
role,
})
}
fn type_specifier_impl<'a>(
&mut self,
lexer: &mut Lexer<'a>,
word: &'a str,
span: Span,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, Option<ast::Type<'a>>> {
if let Some(scalar) = conv::get_scalar_type(&lexer.enable_extensions, span, word)? {
return Ok(Some(ast::Type::Scalar(scalar)));
}
Ok(Some(match word {
"vec2" => {
let (ty, ty_span) = self.singular_generic(lexer, ctx)?;
ast::Type::Vector {
size: crate::VectorSize::Bi,
ty,
ty_span,
}
}
"vec2i" => ast::Type::Vector {
size: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::I32),
ty_span: Span::UNDEFINED,
},
"vec2u" => ast::Type::Vector {
size: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::U32),
ty_span: Span::UNDEFINED,
},
"vec2f" => ast::Type::Vector {
size: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"vec2h" => ast::Type::Vector {
size: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"vec3" => {
let (ty, ty_span) = self.singular_generic(lexer, ctx)?;
ast::Type::Vector {
size: crate::VectorSize::Tri,
ty,
ty_span,
}
}
"vec3i" => ast::Type::Vector {
size: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::I32),
ty_span: Span::UNDEFINED,
},
"vec3u" => ast::Type::Vector {
size: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::U32),
ty_span: Span::UNDEFINED,
},
"vec3f" => ast::Type::Vector {
size: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"vec3h" => ast::Type::Vector {
size: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"vec4" => {
let (ty, ty_span) = self.singular_generic(lexer, ctx)?;
ast::Type::Vector {
size: crate::VectorSize::Quad,
ty,
ty_span,
}
}
"vec4i" => ast::Type::Vector {
size: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::I32),
ty_span: Span::UNDEFINED,
},
"vec4u" => ast::Type::Vector {
size: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::U32),
ty_span: Span::UNDEFINED,
},
"vec4f" => ast::Type::Vector {
size: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"vec4h" => ast::Type::Vector {
size: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat2x2" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Bi, crate::VectorSize::Bi)?
}
"mat2x2f" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat2x2h" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat2x3" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Bi, crate::VectorSize::Tri)?
}
"mat2x3f" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat2x3h" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat2x4" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Bi, crate::VectorSize::Quad)?
}
"mat2x4f" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat2x4h" => ast::Type::Matrix {
columns: crate::VectorSize::Bi,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat3x2" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Tri, crate::VectorSize::Bi)?
}
"mat3x2f" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat3x2h" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat3x3" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Tri, crate::VectorSize::Tri)?
}
"mat3x3f" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat3x3h" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat3x4" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Tri, crate::VectorSize::Quad)?
}
"mat3x4f" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat3x4h" => ast::Type::Matrix {
columns: crate::VectorSize::Tri,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat4x2" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Quad, crate::VectorSize::Bi)?
}
"mat4x2f" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat4x2h" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Bi,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat4x3" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Quad, crate::VectorSize::Tri)?
}
"mat4x3f" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat4x3h" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Tri,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"mat4x4" => {
self.matrix_with_type(lexer, ctx, crate::VectorSize::Quad, crate::VectorSize::Quad)?
}
"mat4x4f" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F32),
ty_span: Span::UNDEFINED,
},
"mat4x4h" => ast::Type::Matrix {
columns: crate::VectorSize::Quad,
rows: crate::VectorSize::Quad,
ty: ctx.new_scalar(Scalar::F16),
ty_span: Span::UNDEFINED,
},
"coop_mat8x8" => {
lexer.require_enable_extension(
ImplementedEnableExtension::WgpuCooperativeMatrix,
span,
)?;
self.cooperative_matrix_with_type(
lexer,
ctx,
crate::CooperativeSize::Eight,
crate::CooperativeSize::Eight,
)?
}
"coop_mat16x16" => {
lexer.require_enable_extension(
ImplementedEnableExtension::WgpuCooperativeMatrix,
span,
)?;
self.cooperative_matrix_with_type(
lexer,
ctx,
crate::CooperativeSize::Sixteen,
crate::CooperativeSize::Sixteen,
)?
}
"atomic" => {
let (scalar, _) = lexer.next_scalar_generic_with_span()?;
ast::Type::Atomic(scalar)
}
"ptr" => {
lexer.expect(Token::TemplateArgsStart)?;
let (ident, span) = lexer.next_ident_with_span()?;
let mut space = conv::map_address_space(ident, span, &lexer.enable_extensions)?;
lexer.expect(Token::Separator(','))?;
let base = self.type_specifier(lexer, ctx)?;
if let crate::AddressSpace::Storage { ref mut access } = space {
*access = if lexer.end_of_generic_arguments() {
let (ident, span) = lexer.next_ident_with_span()?;
let access = conv::map_access_mode(ident, span)?;
lexer.next_if(Token::Separator(','));
access
} else {
crate::StorageAccess::LOAD
};
}
lexer.expect(Token::TemplateArgsEnd)?;
ast::Type::Pointer { base, space }
}
"array" => {
lexer.expect(Token::TemplateArgsStart)?;
let base = self.type_specifier(lexer, ctx)?;
let size = if lexer.end_of_generic_arguments() {
let size = self.const_generic_expression(lexer, ctx)?;
lexer.next_if(Token::Separator(','));
ast::ArraySize::Constant(size)
} else {
ast::ArraySize::Dynamic
};
lexer.expect(Token::TemplateArgsEnd)?;
ast::Type::Array { base, size }
}
"binding_array" => {
lexer.expect(Token::TemplateArgsStart)?;
let base = self.type_specifier(lexer, ctx)?;
let size = if lexer.end_of_generic_arguments() {
let size = self.unary_expression(lexer, ctx)?;
lexer.next_if(Token::Separator(','));
ast::ArraySize::Constant(size)
} else {
ast::ArraySize::Dynamic
};
lexer.expect(Token::TemplateArgsEnd)?;
ast::Type::BindingArray { base, size }
}
"sampler" => ast::Type::Sampler { comparison: false },
"sampler_comparison" => ast::Type::Sampler { comparison: true },
"texture_1d" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D1,
arrayed: false,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_1d_array" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D1,
arrayed: true,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_2d" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_2d_array" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: true,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_3d" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D3,
arrayed: false,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_cube" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::Cube,
arrayed: false,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_cube_array" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::Cube,
arrayed: true,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: false,
},
}
}
"texture_multisampled_2d" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: true,
},
}
}
"texture_multisampled_2d_array" => {
let (scalar, span) = lexer.next_scalar_generic_with_span()?;
Self::check_texture_sample_type(scalar, span)?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: true,
class: crate::ImageClass::Sampled {
kind: scalar.kind,
multi: true,
},
}
}
"texture_depth_2d" => ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::Depth { multi: false },
},
"texture_depth_2d_array" => ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: true,
class: crate::ImageClass::Depth { multi: false },
},
"texture_depth_cube" => ast::Type::Image {
dim: crate::ImageDimension::Cube,
arrayed: false,
class: crate::ImageClass::Depth { multi: false },
},
"texture_depth_cube_array" => ast::Type::Image {
dim: crate::ImageDimension::Cube,
arrayed: true,
class: crate::ImageClass::Depth { multi: false },
},
"texture_depth_multisampled_2d" => ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::Depth { multi: true },
},
"texture_external" => ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::External,
},
"texture_storage_1d" => {
let (format, access) = lexer.next_format_generic()?;
ast::Type::Image {
dim: crate::ImageDimension::D1,
arrayed: false,
class: crate::ImageClass::Storage { format, access },
}
}
"texture_storage_1d_array" => {
let (format, access) = lexer.next_format_generic()?;
ast::Type::Image {
dim: crate::ImageDimension::D1,
arrayed: true,
class: crate::ImageClass::Storage { format, access },
}
}
"texture_storage_2d" => {
let (format, access) = lexer.next_format_generic()?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: false,
class: crate::ImageClass::Storage { format, access },
}
}
"texture_storage_2d_array" => {
let (format, access) = lexer.next_format_generic()?;
ast::Type::Image {
dim: crate::ImageDimension::D2,
arrayed: true,
class: crate::ImageClass::Storage { format, access },
}
}
"texture_storage_3d" => {
let (format, access) = lexer.next_format_generic()?;
ast::Type::Image {
dim: crate::ImageDimension::D3,
arrayed: false,
class: crate::ImageClass::Storage { format, access },
}
}
"acceleration_structure" => {
lexer.require_enable_extension(ImplementedEnableExtension::WgpuRayQuery, span)?;
let vertex_return = lexer.next_acceleration_structure_flags()?;
if vertex_return {
lexer.require_enable_extension(
ImplementedEnableExtension::WgpuRayQueryVertexReturn,
span,
)?;
}
ast::Type::AccelerationStructure { vertex_return }
}
"ray_query" => {
lexer.require_enable_extension(ImplementedEnableExtension::WgpuRayQuery, span)?;
let vertex_return = lexer.next_acceleration_structure_flags()?;
if vertex_return {
lexer.require_enable_extension(
ImplementedEnableExtension::WgpuRayQueryVertexReturn,
span,
)?;
}
ast::Type::RayQuery { vertex_return }
}
"RayDesc" => {
lexer.require_enable_extension(ImplementedEnableExtension::WgpuRayQuery, span)?;
ast::Type::RayDesc
}
"RayIntersection" => {
lexer.require_enable_extension(ImplementedEnableExtension::WgpuRayQuery, span)?;
ast::Type::RayIntersection
}
_ => return Ok(None),
}))
}
fn check_texture_sample_type(scalar: Scalar, span: Span) -> Result<'static, ()> {
use crate::ScalarKind::*;
// Validate according to https://gpuweb.github.io/gpuweb/wgsl/#sampled-texture-type
match scalar {
Scalar {
kind: Float | Sint | Uint,
width: 4,
} => Ok(()),
Scalar {
kind: Uint,
width: 8,
} => Ok(()),
_ => Err(Box::new(Error::BadTextureSampleType { span, scalar })),
}
}
fn type_specifier<'a>(
&mut self,
lexer: &mut Lexer<'a>,
ctx: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, Handle<ast::Type<'a>>> {
self.track_recursion(|this| {
this.push_rule_span(Rule::TypeDecl, lexer);
let (name, span) = lexer.next_ident_with_span()?;
let ty = match this.type_specifier_impl(lexer, name, span, ctx)? {
Some(ty) => ty,
None => {
ctx.unresolved.insert(ast::Dependency {
ident: name,
usage: span,
});
ast::Type::User(ast::Ident { name, span })
}
};
this.pop_rule_span(lexer);
let handle = ctx.types.append(ty, Span::UNDEFINED);
Ok(handle)
})
) -> Result<'a, ast::TemplateElaboratedIdent<'a>> {
let (name, span) = lexer.next_ident_with_span()?;
self.template_elaborated_ident(name, span, lexer, ctx)
}
/// Parses assignment, increment and decrement statements
@@ -2324,7 +1682,6 @@ impl Parser {
expressions: &mut out.expressions,
local_table: &mut SymbolTable::default(),
locals: &mut locals,
types: &mut out.types,
unresolved: dependencies,
};
@@ -2458,7 +1815,6 @@ impl Parser {
expressions: &mut out.expressions,
local_table: &mut SymbolTable::default(),
locals: &mut Arena::new(),
types: &mut out.types,
unresolved: &mut dependencies,
};
let mut diagnostic_filters = DiagnosticFilterMap::new();
+17 -8
View File
@@ -345,7 +345,7 @@ fn parse_texture_load() {
.unwrap();
parse_str(
"
var t: texture_multisampled_2d_array<i32>;
var t: texture_2d_array<i32>;
fn foo() {
let r: vec4<i32> = textureLoad(t, vec2<i32>(10, 20), 2, 3);
}
@@ -354,9 +354,9 @@ fn parse_texture_load() {
.unwrap();
parse_str(
"
var t: texture_storage_1d_array<r32float,read>;
var t: texture_storage_1d<r32float,read>;
fn foo() {
let r: vec4<f32> = textureLoad(t, 10, 2);
let r: vec4<f32> = textureLoad(t, 10);
}
",
)
@@ -380,12 +380,21 @@ fn parse_texture_store() {
fn parse_texture_query() {
parse_str(
"
var t: texture_multisampled_2d_array<f32>;
var t: texture_multisampled_2d<f32>;
fn foo() {
var dim: vec2<u32> = textureDimensions(t);
dim = textureDimensions(t, 0);
let layers: u32 = textureNumLayers(t);
let samples: u32 = textureNumSamples(t);
let dim = textureDimensions(t);
let samples = textureNumSamples(t);
}
",
)
.unwrap();
parse_str(
"
var t: texture_2d_array<f32>;
fn foo() {
let dim = textureDimensions(t);
let levels = textureNumLevels(t);
let layers = textureNumLayers(t);
}
",
)
+14 -14
View File
@@ -121,12 +121,12 @@ fn invalid_float() {
#[test]
fn invalid_texture_sample_type() {
check(
"const x: texture_2d<bool>;",
"var x: texture_2d<bool>;",
r###"error: texture sample type must be one of f32, i32 or u32, but found bool
┌─ wgsl:1:21
┌─ wgsl:1:19
│
1 │ const x: texture_2d<bool>;
│ ^^^^ must be one of f32, i32 or u32
1 │ var x: texture_2d<bool>;
│ ^^^^ must be one of f32, i32 or u32
"###,
);
@@ -534,11 +534,11 @@ fn unknown_type() {
r#"
const a: Vec = 10;
"#,
r#"error: unknown type: `Vec`
r#"error: no definition in scope for identifier: `Vec`
┌─ wgsl:2:22
│
2 │ const a: Vec = 10;
│ ^^^ unknown type
│ ^^^ unknown identifier
"#,
);
@@ -548,13 +548,13 @@ fn unknown_type() {
fn unknown_storage_format() {
check(
r#"
const storage1: texture_storage_1d<rgba>;
var storage1: texture_storage_1d<rgba>;
"#,
r#"error: unknown storage format: `rgba`
┌─ wgsl:2:48
┌─ wgsl:2:46
│
2 │ const storage1: texture_storage_1d<rgba>;
│ ^^^^ unknown storage format
2 │ var storage1: texture_storage_1d<rgba>;
│ ^^^^ unknown storage format
"#,
);
@@ -4399,10 +4399,10 @@ fn ray_query_vertex_return_enable_extension() {
}
"#,
r#"error: the `wgpu_ray_query_vertex_return` enable extension is not enabled
┌─ wgsl:4:20
┌─ wgsl:4:30
│
4 │ var a: ray_query<vertex_return>;
│ ^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
│ ^^^^^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
│
= note: You can enable this extension by adding `enable wgpu_ray_query_vertex_return;` at the top of the shader, before any other items.
@@ -4423,10 +4423,10 @@ fn ray_query_vertex_return_enable_extension() {
var acc_struct: acceleration_structure<vertex_return>;
"#,
r#"error: the `wgpu_ray_query_vertex_return` enable extension is not enabled
┌─ wgsl:4:25
┌─ wgsl:4:48
│
4 │ var acc_struct: acceleration_structure<vertex_return>;
│ ^^^^^^^^^^^^^^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
│ ^^^^^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
│
= note: You can enable this extension by adding `enable wgpu_ray_query_vertex_return;` at the top of the shader, before any other items.
@@ -15,7 +15,7 @@ struct _atomic_compare_exchange_result_Uint_4_ {
};
const uint SIZE = 128u;
layout(std430) buffer type_2_block_0Compute { int _group_0_binding_0_cs[128]; };
layout(std430) buffer type_3_block_0Compute { int _group_0_binding_0_cs[128]; };
void main() {
@@ -15,7 +15,7 @@ struct _atomic_compare_exchange_result_Uint_4_ {
};
const uint SIZE = 128u;
layout(std430) buffer type_4_block_0Compute { uint _group_0_binding_1_cs[128]; };
layout(std430) buffer type_5_block_0Compute { uint _group_0_binding_1_cs[128]; };
void main() {
@@ -17,9 +17,9 @@ struct _atomic_compare_exchange_result_Sint_4_ {
int old_value;
bool exchanged;
};
layout(std430) buffer type_block_0Compute { uint _group_0_binding_0_cs; };
layout(std430) buffer type_1_block_0Compute { uint _group_0_binding_0_cs; };
layout(std430) buffer type_2_block_1Compute { int _group_0_binding_1_cs[2]; };
layout(std430) buffer type_4_block_1Compute { int _group_0_binding_1_cs[2]; };
layout(std430) buffer Struct_block_2Compute { Struct _group_0_binding_2_cs; };
@@ -9,14 +9,14 @@
),
(
name: None,
inner: Atomic((
inner: Scalar((
kind: Uint,
width: 4,
)),
),
(
name: None,
inner: Scalar((
inner: Atomic((
kind: Uint,
width: 4,
)),
@@ -34,7 +34,7 @@
members: [
(
name: Some("old_value"),
ty: 2,
ty: 1,
binding: None,
offset: 0,
),
@@ -76,7 +76,7 @@
name: Some("a"),
space: WorkGroup,
binding: None,
ty: 1,
ty: 2,
init: None,
),
],
@@ -9,14 +9,14 @@
),
(
name: None,
inner: Atomic((
inner: Scalar((
kind: Uint,
width: 4,
)),
),
(
name: None,
inner: Scalar((
inner: Atomic((
kind: Uint,
width: 4,
)),
@@ -34,7 +34,7 @@
members: [
(
name: Some("old_value"),
ty: 2,
ty: 1,
binding: None,
offset: 0,
),
@@ -76,7 +76,7 @@
name: Some("a"),
space: WorkGroup,
binding: None,
ty: 1,
ty: 2,
init: None,
),
],
@@ -4,10 +4,10 @@
using metal::uint;
struct type_2 {
struct type_3 {
metal::atomic_int inner[128];
};
struct type_4 {
struct type_5 {
metal::atomic_uint inner[128];
};
struct _atomic_compare_exchange_result_Sint_4_ {
@@ -73,7 +73,7 @@ _atomic_compare_exchange_result_Uint_4_ naga_atomic_compare_exchange_weak_explic
constant uint SIZE = 128u;
kernel void test_atomic_compare_exchange_i32_(
device type_2& arr_i32_ [[user(fake0)]]
device type_3& arr_i32_ [[user(fake0)]]
) {
uint i = 0u;
int old = {};
@@ -124,7 +124,7 @@ kernel void test_atomic_compare_exchange_i32_(
kernel void test_atomic_compare_exchange_u32_(
device type_4& arr_u32_ [[user(fake0)]]
device type_5& arr_u32_ [[user(fake0)]]
) {
uint i_1 = 0u;
uint old_1 = {};
@@ -4,12 +4,12 @@
using metal::uint;
struct type_1 {
struct type_2 {
metal::atomic_float inner[2];
};
struct Struct {
metal::atomic_float atomic_scalar;
type_1 atomic_arr;
type_2 atomic_arr;
};
struct cs_mainInput {
@@ -17,7 +17,7 @@ struct cs_mainInput {
kernel void cs_main(
metal::uint3 id [[thread_position_in_threadgroup]]
, device metal::atomic_float& storage_atomic_scalar [[user(fake0)]]
, device type_1& storage_atomic_arr [[user(fake0)]]
, device type_2& storage_atomic_arr [[user(fake0)]]
, device Struct& storage_struct [[user(fake0)]]
) {
metal::atomic_store_explicit(&storage_atomic_scalar, 1.5, metal::memory_order_relaxed);
@@ -4,12 +4,12 @@
using metal::uint;
struct type_1 {
struct type_2 {
metal::atomic_ulong inner[2];
};
struct Struct {
metal::atomic_ulong atomic_scalar;
type_1 atomic_arr;
type_2 atomic_arr;
};
struct cs_mainInput {
@@ -17,7 +17,7 @@ struct cs_mainInput {
kernel void cs_main(
metal::uint3 id [[thread_position_in_threadgroup]]
, device metal::atomic_ulong& storage_atomic_scalar [[user(fake0)]]
, device type_1& storage_atomic_arr [[user(fake0)]]
, device type_2& storage_atomic_arr [[user(fake0)]]
, device Struct& storage_struct [[user(fake0)]]
, constant ulong& input [[user(fake0)]]
) {
+4 -4
View File
@@ -4,12 +4,12 @@
using metal::uint;
struct type_2 {
struct type_4 {
metal::atomic_int inner[2];
};
struct Struct {
metal::atomic_uint atomic_scalar;
type_2 atomic_arr;
type_4 atomic_arr;
};
struct _atomic_compare_exchange_result_Uint_4_ {
uint old_value;
@@ -77,10 +77,10 @@ struct cs_mainInput {
kernel void cs_main(
metal::uint3 id [[thread_position_in_threadgroup]]
, device metal::atomic_uint& storage_atomic_scalar [[user(fake0)]]
, device type_2& storage_atomic_arr [[user(fake0)]]
, device type_4& storage_atomic_arr [[user(fake0)]]
, device Struct& storage_struct [[user(fake0)]]
, threadgroup metal::atomic_uint& workgroup_atomic_scalar
, threadgroup type_2& workgroup_atomic_arr
, threadgroup type_4& workgroup_atomic_arr
, threadgroup Struct& workgroup_struct
) {
if (metal::all(id == metal::uint3(0u))) {
@@ -14,14 +14,14 @@ struct _mslBufferSizes {
uint size0;
};
struct type_1 {
struct type_2 {
metal::atomic_uint inner[10];
};
typedef metal::atomic_uint type_2[1];
typedef metal::atomic_uint type_3[1];
struct Globals {
metal::atomic_uint a;
type_1 b;
type_2 c;
type_2 b;
type_3 c;
};
uint fetch_add_atomic(
@@ -4,12 +4,12 @@
using metal::uint;
struct type_2 {
struct type_4 {
metal::atomic_int inner[2];
};
struct AtomicStruct {
metal::atomic_uint atomic_scalar;
type_2 atomic_arr;
type_4 atomic_arr;
};
struct test_atomic_workgroup_uniform_loadInput {
@@ -3,8 +3,8 @@
; Generator: rspirv
; Bound: 172
OpCapability Shader
OpCapability Int64Atomics
OpCapability Int64
OpCapability Int64Atomics
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
@@ -3,8 +3,8 @@
; Generator: rspirv
; Bound: 66
OpCapability Shader
OpCapability Int64Atomics
OpCapability Int64
OpCapability Int64Atomics
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
@@ -3,8 +3,8 @@
; Generator: rspirv
; Bound: 225
OpCapability Shader
OpCapability Int64Atomics
OpCapability Int64
OpCapability Int64Atomics
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
+62 -62
View File
@@ -82,27 +82,27 @@ OpDecorate %395 NonUniform
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
%4 = OpTypeStruct %3
%6 = OpTypeFloat 32
%5 = OpTypeImage %6 2D 0 0 0 1 Unknown
%7 = OpTypeRuntimeArray %5
%5 = OpTypeFloat 32
%6 = OpTypeImage %5 2D 0 0 0 1 Unknown
%7 = OpTypeRuntimeArray %6
%9 = OpConstant %3 5
%8 = OpTypeArray %5 %9
%10 = OpTypeImage %6 2D 0 1 0 1 Unknown
%8 = OpTypeArray %6 %9
%10 = OpTypeImage %5 2D 0 1 0 1 Unknown
%11 = OpTypeArray %10 %9
%12 = OpTypeImage %6 2D 0 0 1 1 Unknown
%12 = OpTypeImage %5 2D 0 0 1 1 Unknown
%13 = OpTypeArray %12 %9
%14 = OpTypeImage %6 2D 1 0 0 1 Unknown
%14 = OpTypeImage %5 2D 1 0 0 1 Unknown
%15 = OpTypeArray %14 %9
%16 = OpTypeImage %6 2D 0 0 0 2 Rgba32f
%16 = OpTypeImage %5 2D 0 0 0 2 Rgba32f
%17 = OpTypeArray %16 %9
%18 = OpTypeSampler
%19 = OpTypeArray %18 %9
%20 = OpTypeArray %18 %9
%21 = OpTypeStruct %3
%22 = OpTypeVector %6 4
%22 = OpTypeVector %5 4
%23 = OpTypeVector %3 2
%26 = OpConstant %3 10
%25 = OpTypeArray %5 %26
%25 = OpTypeArray %6 %26
%27 = OpTypePointer UniformConstant %25
%24 = OpVariable %27 UniformConstant
%29 = OpTypePointer UniformConstant %8
@@ -130,9 +130,9 @@ OpDecorate %395 NonUniform
%54 = OpTypePointer Uniform %4
%55 = OpConstant %3 0
%57 = OpConstantComposite %23 %55 %55
%58 = OpConstant %6 0
%58 = OpConstant %5 0
%59 = OpConstantComposite %22 %58 %58 %58 %58
%60 = OpTypeVector %6 2
%60 = OpTypeVector %5 2
%61 = OpConstantComposite %60 %58 %58
%62 = OpTypeInt 32 1
%63 = OpConstant %62 0
@@ -140,12 +140,12 @@ OpDecorate %395 NonUniform
%65 = OpConstantComposite %64 %63 %63
%67 = OpTypePointer Function %3
%69 = OpTypePointer Function %23
%71 = OpTypePointer Function %6
%71 = OpTypePointer Function %5
%73 = OpTypePointer Function %22
%75 = OpTypePointer Uniform %3
%79 = OpTypePointer UniformConstant %5
%79 = OpTypePointer UniformConstant %6
%97 = OpTypePointer UniformConstant %18
%100 = OpTypeSampledImage %5
%100 = OpTypeSampledImage %6
%121 = OpTypePointer UniformConstant %14
%126 = OpTypeSampledImage %14
%149 = OpTypeBool
@@ -170,25 +170,25 @@ OpBranch %74
%77 = OpLoad %3 %76
%78 = OpCompositeExtract %3 %46 0
%80 = OpAccessChain %79 %24 %55
%81 = OpLoad %5 %80
%81 = OpLoad %6 %80
%82 = OpImageQuerySizeLod %23 %81 %55
%83 = OpLoad %23 %68
%84 = OpIAdd %23 %83 %82
OpStore %68 %84
%85 = OpAccessChain %79 %24 %77
%86 = OpLoad %5 %85
%86 = OpLoad %6 %85
%87 = OpImageQuerySizeLod %23 %86 %55
%88 = OpLoad %23 %68
%89 = OpIAdd %23 %88 %87
OpStore %68 %89
%90 = OpAccessChain %79 %24 %78
%91 = OpLoad %5 %90
%91 = OpLoad %6 %90
%92 = OpImageQuerySizeLod %23 %91 %55
%93 = OpLoad %23 %68
%94 = OpIAdd %23 %93 %92
OpStore %68 %94
%95 = OpAccessChain %79 %28 %55
%96 = OpLoad %5 %95
%96 = OpLoad %6 %95
%98 = OpAccessChain %97 %38 %55
%99 = OpLoad %18 %98
%101 = OpSampledImage %100 %96 %99
@@ -197,7 +197,7 @@ OpStore %68 %94
%104 = OpFAdd %22 %103 %102
OpStore %72 %104
%105 = OpAccessChain %79 %28 %77
%106 = OpLoad %5 %105
%106 = OpLoad %6 %105
%107 = OpAccessChain %97 %38 %77
%108 = OpLoad %18 %107
%109 = OpSampledImage %100 %106 %108
@@ -206,7 +206,7 @@ OpStore %72 %104
%112 = OpFAdd %22 %111 %110
OpStore %72 %112
%113 = OpAccessChain %79 %28 %78
%114 = OpLoad %5 %113
%114 = OpLoad %6 %113
%115 = OpAccessChain %97 %38 %78
%116 = OpLoad %18 %115
%117 = OpSampledImage %100 %114 %116
@@ -242,7 +242,7 @@ OpStore %72 %138
%146 = OpFAdd %22 %145 %144
OpStore %72 %146
%147 = OpAccessChain %79 %24 %55
%148 = OpLoad %5 %147
%148 = OpLoad %6 %147
%151 = OpImageQueryLevels %62 %148
%152 = OpULessThan %149 %63 %151
OpSelectionMerge %153 None
@@ -261,7 +261,7 @@ OpBranch %153
%163 = OpFAdd %22 %162 %161
OpStore %72 %163
%164 = OpAccessChain %79 %24 %77
%165 = OpLoad %5 %164
%165 = OpLoad %6 %164
%166 = OpImageQueryLevels %62 %165
%167 = OpULessThan %149 %63 %166
OpSelectionMerge %168 None
@@ -280,7 +280,7 @@ OpBranch %168
%177 = OpFAdd %22 %176 %175
OpStore %72 %177
%178 = OpAccessChain %79 %24 %78
%179 = OpLoad %5 %178
%179 = OpLoad %6 %178
%180 = OpImageQueryLevels %62 %179
%181 = OpULessThan %149 %63 %180
OpSelectionMerge %182 None
@@ -320,19 +320,19 @@ OpStore %66 %205
%211 = OpIAdd %3 %210 %209
OpStore %66 %211
%212 = OpAccessChain %79 %28 %55
%213 = OpLoad %5 %212
%213 = OpLoad %6 %212
%214 = OpImageQueryLevels %3 %213
%215 = OpLoad %3 %66
%216 = OpIAdd %3 %215 %214
OpStore %66 %216
%217 = OpAccessChain %79 %28 %77
%218 = OpLoad %5 %217
%218 = OpLoad %6 %217
%219 = OpImageQueryLevels %3 %218
%220 = OpLoad %3 %66
%221 = OpIAdd %3 %220 %219
OpStore %66 %221
%222 = OpAccessChain %79 %28 %78
%223 = OpLoad %5 %222
%223 = OpLoad %6 %222
%224 = OpImageQueryLevels %3 %223
%225 = OpLoad %3 %66
%226 = OpIAdd %3 %225 %224
@@ -356,7 +356,7 @@ OpStore %66 %237
%242 = OpIAdd %3 %241 %240
OpStore %66 %242
%243 = OpAccessChain %79 %28 %55
%244 = OpLoad %5 %243
%244 = OpLoad %6 %243
%245 = OpAccessChain %97 %38 %55
%246 = OpLoad %18 %245
%247 = OpSampledImage %100 %244 %246
@@ -365,7 +365,7 @@ OpStore %66 %242
%250 = OpFAdd %22 %249 %248
OpStore %72 %250
%251 = OpAccessChain %79 %28 %77
%252 = OpLoad %5 %251
%252 = OpLoad %6 %251
%253 = OpAccessChain %97 %38 %77
%254 = OpLoad %18 %253
%255 = OpSampledImage %100 %252 %254
@@ -374,7 +374,7 @@ OpStore %72 %250
%258 = OpFAdd %22 %257 %256
OpStore %72 %258
%259 = OpAccessChain %79 %28 %78
%260 = OpLoad %5 %259
%260 = OpLoad %6 %259
%261 = OpAccessChain %97 %38 %78
%262 = OpLoad %18 %261
%263 = OpSampledImage %100 %260 %262
@@ -383,7 +383,7 @@ OpStore %72 %258
%266 = OpFAdd %22 %265 %264
OpStore %72 %266
%267 = OpAccessChain %79 %28 %55
%268 = OpLoad %5 %267
%268 = OpLoad %6 %267
%269 = OpAccessChain %97 %38 %55
%270 = OpLoad %18 %269
%271 = OpSampledImage %100 %268 %270
@@ -392,7 +392,7 @@ OpStore %72 %266
%274 = OpFAdd %22 %273 %272
OpStore %72 %274
%275 = OpAccessChain %79 %28 %77
%276 = OpLoad %5 %275
%276 = OpLoad %6 %275
%277 = OpAccessChain %97 %38 %77
%278 = OpLoad %18 %277
%279 = OpSampledImage %100 %276 %278
@@ -401,7 +401,7 @@ OpStore %72 %274
%282 = OpFAdd %22 %281 %280
OpStore %72 %282
%283 = OpAccessChain %79 %28 %78
%284 = OpLoad %5 %283
%284 = OpLoad %6 %283
%285 = OpAccessChain %97 %38 %78
%286 = OpLoad %18 %285
%287 = OpSampledImage %100 %284 %286
@@ -414,57 +414,57 @@ OpStore %72 %290
%293 = OpAccessChain %97 %40 %55
%294 = OpLoad %18 %293
%295 = OpSampledImage %126 %292 %294
%296 = OpImageSampleDrefImplicitLod %6 %295 %61 %58
%297 = OpLoad %6 %70
%298 = OpFAdd %6 %297 %296
%296 = OpImageSampleDrefImplicitLod %5 %295 %61 %58
%297 = OpLoad %5 %70
%298 = OpFAdd %5 %297 %296
OpStore %70 %298
%299 = OpAccessChain %121 %34 %77
%300 = OpLoad %14 %299
%301 = OpAccessChain %97 %40 %77
%302 = OpLoad %18 %301
%303 = OpSampledImage %126 %300 %302
%304 = OpImageSampleDrefImplicitLod %6 %303 %61 %58
%305 = OpLoad %6 %70
%306 = OpFAdd %6 %305 %304
%304 = OpImageSampleDrefImplicitLod %5 %303 %61 %58
%305 = OpLoad %5 %70
%306 = OpFAdd %5 %305 %304
OpStore %70 %306
%307 = OpAccessChain %121 %34 %78
%308 = OpLoad %14 %307
%309 = OpAccessChain %97 %40 %78
%310 = OpLoad %18 %309
%311 = OpSampledImage %126 %308 %310
%312 = OpImageSampleDrefImplicitLod %6 %311 %61 %58
%313 = OpLoad %6 %70
%314 = OpFAdd %6 %313 %312
%312 = OpImageSampleDrefImplicitLod %5 %311 %61 %58
%313 = OpLoad %5 %70
%314 = OpFAdd %5 %313 %312
OpStore %70 %314
%315 = OpAccessChain %121 %34 %55
%316 = OpLoad %14 %315
%317 = OpAccessChain %97 %40 %55
%318 = OpLoad %18 %317
%319 = OpSampledImage %126 %316 %318
%320 = OpImageSampleDrefExplicitLod %6 %319 %61 %58 Lod %58
%321 = OpLoad %6 %70
%322 = OpFAdd %6 %321 %320
%320 = OpImageSampleDrefExplicitLod %5 %319 %61 %58 Lod %58
%321 = OpLoad %5 %70
%322 = OpFAdd %5 %321 %320
OpStore %70 %322
%323 = OpAccessChain %121 %34 %77
%324 = OpLoad %14 %323
%325 = OpAccessChain %97 %40 %77
%326 = OpLoad %18 %325
%327 = OpSampledImage %126 %324 %326
%328 = OpImageSampleDrefExplicitLod %6 %327 %61 %58 Lod %58
%329 = OpLoad %6 %70
%330 = OpFAdd %6 %329 %328
%328 = OpImageSampleDrefExplicitLod %5 %327 %61 %58 Lod %58
%329 = OpLoad %5 %70
%330 = OpFAdd %5 %329 %328
OpStore %70 %330
%331 = OpAccessChain %121 %34 %78
%332 = OpLoad %14 %331
%333 = OpAccessChain %97 %40 %78
%334 = OpLoad %18 %333
%335 = OpSampledImage %126 %332 %334
%336 = OpImageSampleDrefExplicitLod %6 %335 %61 %58 Lod %58
%337 = OpLoad %6 %70
%338 = OpFAdd %6 %337 %336
%336 = OpImageSampleDrefExplicitLod %5 %335 %61 %58 Lod %58
%337 = OpLoad %5 %70
%338 = OpFAdd %5 %337 %336
OpStore %70 %338
%339 = OpAccessChain %79 %28 %55
%340 = OpLoad %5 %339
%340 = OpLoad %6 %339
%341 = OpAccessChain %97 %38 %55
%342 = OpLoad %18 %341
%343 = OpSampledImage %100 %340 %342
@@ -473,7 +473,7 @@ OpStore %70 %338
%346 = OpFAdd %22 %345 %344
OpStore %72 %346
%347 = OpAccessChain %79 %28 %77
%348 = OpLoad %5 %347
%348 = OpLoad %6 %347
%349 = OpAccessChain %97 %38 %77
%350 = OpLoad %18 %349
%351 = OpSampledImage %100 %348 %350
@@ -482,7 +482,7 @@ OpStore %72 %346
%354 = OpFAdd %22 %353 %352
OpStore %72 %354
%355 = OpAccessChain %79 %28 %78
%356 = OpLoad %5 %355
%356 = OpLoad %6 %355
%357 = OpAccessChain %97 %38 %78
%358 = OpLoad %18 %357
%359 = OpSampledImage %100 %356 %358
@@ -491,7 +491,7 @@ OpStore %72 %354
%362 = OpFAdd %22 %361 %360
OpStore %72 %362
%363 = OpAccessChain %79 %28 %55
%364 = OpLoad %5 %363
%364 = OpLoad %6 %363
%365 = OpAccessChain %97 %38 %55
%366 = OpLoad %18 %365
%367 = OpSampledImage %100 %364 %366
@@ -500,7 +500,7 @@ OpStore %72 %362
%370 = OpFAdd %22 %369 %368
OpStore %72 %370
%371 = OpAccessChain %79 %28 %77
%372 = OpLoad %5 %371
%372 = OpLoad %6 %371
%373 = OpAccessChain %97 %38 %77
%374 = OpLoad %18 %373
%375 = OpSampledImage %100 %372 %374
@@ -509,7 +509,7 @@ OpStore %72 %370
%378 = OpFAdd %22 %377 %376
OpStore %72 %378
%379 = OpAccessChain %79 %28 %78
%380 = OpLoad %5 %379
%380 = OpLoad %6 %379
%381 = OpAccessChain %97 %38 %78
%382 = OpLoad %18 %381
%383 = OpSampledImage %100 %380 %382
@@ -535,13 +535,13 @@ OpImageWrite %395 %65 %396
%400 = OpIAdd %23 %397 %399
%401 = OpConvertUToF %60 %400
%402 = OpLoad %22 %72
%403 = OpCompositeExtract %6 %401 0
%404 = OpCompositeExtract %6 %401 1
%405 = OpCompositeExtract %6 %401 0
%406 = OpCompositeExtract %6 %401 1
%403 = OpCompositeExtract %5 %401 0
%404 = OpCompositeExtract %5 %401 1
%405 = OpCompositeExtract %5 %401 0
%406 = OpCompositeExtract %5 %401 1
%407 = OpCompositeConstruct %22 %403 %404 %405 %406
%408 = OpFAdd %22 %402 %407
%409 = OpLoad %6 %70
%409 = OpLoad %5 %70
%410 = OpCompositeConstruct %22 %409 %409 %409 %409
%411 = OpFAdd %22 %408 %410
OpStore %50 %411
+18 -18
View File
@@ -52,11 +52,11 @@ OpDecorate %73 Location 1
OpDecorate %75 Location 2
OpDecorate %77 BuiltIn Position
%2 = OpTypeVoid
%3 = OpTypeFloat 32
%4 = OpTypeVector %3 3
%5 = OpTypeStruct %4 %3
%6 = OpTypeVector %3 4
%7 = OpTypeStruct %3 %4 %3
%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%5 = OpTypeStruct %3 %4
%6 = OpTypeVector %4 4
%7 = OpTypeStruct %4 %3 %4
%9 = OpTypeStruct %5
%10 = OpTypePointer Uniform %9
%8 = OpVariable %10 Uniform
@@ -69,14 +69,14 @@ OpDecorate %77 BuiltIn Position
%18 = OpTypeStruct %7
%19 = OpTypePointer StorageBuffer %18
%17 = OpVariable %19 StorageBuffer
%23 = OpTypePointer Input %4
%23 = OpTypePointer Input %3
%22 = OpVariable %23 Input
%26 = OpTypePointer Input %3
%26 = OpTypePointer Input %4
%25 = OpVariable %26 Input
%29 = OpTypePointer Output %6
%28 = OpVariable %29 Output
%31 = OpTypeFunction %2
%32 = OpConstant %3 0
%32 = OpConstant %4 0
%33 = OpConstantComposite %6 %32 %32 %32 %32
%37 = OpVariable %23 Input
%39 = OpVariable %26 Input
@@ -101,8 +101,8 @@ OpDecorate %77 BuiltIn Position
%88 = OpConstantNull %7
%30 = OpFunction %2 None %31
%20 = OpLabel
%24 = OpLoad %4 %22
%27 = OpLoad %3 %25
%24 = OpLoad %3 %22
%27 = OpLoad %4 %25
%21 = OpCompositeConstruct %5 %24 %27
OpBranch %34
%34 = OpLabel
@@ -111,8 +111,8 @@ OpReturn
OpFunctionEnd
%42 = OpFunction %2 None %31
%35 = OpLabel
%38 = OpLoad %4 %37
%40 = OpLoad %3 %39
%38 = OpLoad %3 %37
%40 = OpLoad %4 %39
%36 = OpCompositeConstruct %5 %38 %40
OpBranch %43
%43 = OpLabel
@@ -134,9 +134,9 @@ OpReturn
OpFunctionEnd
%67 = OpFunction %2 None %31
%58 = OpLabel
%61 = OpLoad %3 %60
%63 = OpLoad %4 %62
%65 = OpLoad %3 %64
%61 = OpLoad %4 %60
%63 = OpLoad %3 %62
%65 = OpLoad %4 %64
%59 = OpCompositeConstruct %7 %61 %63 %65
OpBranch %68
%68 = OpLabel
@@ -145,9 +145,9 @@ OpReturn
OpFunctionEnd
%78 = OpFunction %2 None %31
%69 = OpLabel
%72 = OpLoad %3 %71
%74 = OpLoad %4 %73
%76 = OpLoad %3 %75
%72 = OpLoad %4 %71
%74 = OpLoad %3 %73
%76 = OpLoad %4 %75
%70 = OpCompositeConstruct %7 %72 %74 %76
OpBranch %79
%79 = OpLabel