mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
[naga] Implement vec2<f16> ↔ u32 bitcasts (#10613)
This commit is contained in:
1 parent
9f3690208d
commit
97474455ba
71 files changed
+1972
-659
No files matched your search
@@ -144,6 +144,7 @@ By @sagudev in [#10307](https://github.com/gfx-rs/wgpu/pull/10307).
|
||||
#### Naga
|
||||
|
||||
- Add `@builtin(hit_barycentrics)`, a `vec2<f32>` readable in `@any_hit` and `@closest_hit` ray tracing pipeline shaders, holding two of the barycentric coordinates of the hit point on the triangle (the third is `1.0 - x - y`). Currently only supported with the SPIR-V backend. By @JMS55 in [#10193](https://github.com/gfx-rs/wgpu/pull/10193).
|
||||
- Support WGSL `bitcast` between `vec2<f16>` and 32-bit scalars, between `vec4<f16>` and `vec2` of 32-bit scalars, between `f16` and `i16`/`u16` (with `wgpu_int16`), and the corresponding SPIR-V `OpBitcast`s. By @DouglasDwyer in [#10613](https://github.com/gfx-rs/wgpu/pull/10613).
|
||||
|
||||
#### Hal
|
||||
|
||||
@@ -204,6 +205,7 @@ By @sagudev in [#10307](https://github.com/gfx-rs/wgpu/pull/10307).
|
||||
- `naga::valid::ValidationError` is now always returned boxed, to avoid `clippy::large_result_err` warning. By @beicause in [#9612](https://github.com/gfx-rs/wgpu/pull/9612)
|
||||
- Added `naga::valid::Capabilities::LINEAR_INTERPOLATION`, which is now required in order to use `@interpolate(linear)`. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
- The GLSL backend's `MissingFeatures` error now names the GLSL version that lacks the features, e.g. `GLSL 300 es doesn't support the required feature(s): NOPERSPECTIVE_QUALIFIER`. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
- Bit reinterpretation is now represented in the Naga IR by the new `naga::ir::Expression::Bitcast`, which names its result type. `naga::ir::Expression::As` now only converts, and its `kind` and `convert` fields are replaced by `target: Scalar`. By @DouglasDwyer in [#10613](https://github.com/gfx-rs/wgpu/pull/10613).
|
||||
|
||||
#### Metal
|
||||
|
||||
|
||||
@@ -746,17 +746,16 @@ fn write_function_expressions(
|
||||
}
|
||||
(format!("{fun:?}").into(), 7)
|
||||
}
|
||||
E::As {
|
||||
kind,
|
||||
expr,
|
||||
convert,
|
||||
} => {
|
||||
E::As { expr, target } => {
|
||||
edges.insert("", expr);
|
||||
let string = match convert {
|
||||
Some(width) => format!("Convert<{kind:?},{width}>"),
|
||||
None => format!("Bitcast<{kind:?}>"),
|
||||
};
|
||||
(string.into(), 3)
|
||||
(
|
||||
format!("Convert<{:?},{}>", target.kind, target.width).into(),
|
||||
3,
|
||||
)
|
||||
}
|
||||
E::Bitcast { expr, ty } => {
|
||||
edges.insert("", expr);
|
||||
(format!("Bitcast<{ty:?}>").into(), 3)
|
||||
}
|
||||
E::CallResult(_function) => ("CallResult".into(), 4),
|
||||
E::AtomicResult { .. } => ("AtomicResult".into(), 4),
|
||||
|
||||
@@ -3741,92 +3741,66 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
}
|
||||
// `As` is always a call.
|
||||
// If `convert` is true the function name is the type
|
||||
// Else the function name is one of the glsl provided bitcast functions
|
||||
Expression::As {
|
||||
expr,
|
||||
kind: target_kind,
|
||||
convert,
|
||||
} => {
|
||||
// `As` is always a call, whose name is the target type.
|
||||
Expression::As { expr, target } => {
|
||||
let inner = ctx.resolve_type(expr, &self.module.types);
|
||||
match convert {
|
||||
Some(width) => {
|
||||
// this is similar to `write_type`, but with the target kind
|
||||
let scalar = glsl_scalar(crate::Scalar {
|
||||
kind: target_kind,
|
||||
width,
|
||||
})?;
|
||||
match *inner {
|
||||
TypeInner::Matrix { columns, rows, .. } => write!(
|
||||
self.out,
|
||||
"{}mat{}x{}",
|
||||
scalar.prefix, columns as u8, rows as u8
|
||||
)?,
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(self.out, "{}vec{}", scalar.prefix, size as u8)?
|
||||
}
|
||||
_ => write!(self.out, "{}", scalar.full)?,
|
||||
}
|
||||
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(expr, ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
None => {
|
||||
use crate::ScalarKind as Sk;
|
||||
|
||||
let target_vector_type = match *inner {
|
||||
TypeInner::Vector { size, scalar } => Some(TypeInner::Vector {
|
||||
size,
|
||||
scalar: crate::Scalar {
|
||||
kind: target_kind,
|
||||
width: scalar.width,
|
||||
},
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let source_kind = inner.scalar_kind().unwrap();
|
||||
|
||||
match (source_kind, target_kind, target_vector_type) {
|
||||
// No conversion needed
|
||||
(Sk::Sint, Sk::Sint, _)
|
||||
| (Sk::Uint, Sk::Uint, _)
|
||||
| (Sk::Float, Sk::Float, _)
|
||||
| (Sk::Bool, Sk::Bool, _) => {
|
||||
self.write_expr(expr, ctx)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Cast to/from floats
|
||||
(Sk::Float, Sk::Sint, _) => write!(self.out, "floatBitsToInt")?,
|
||||
(Sk::Float, Sk::Uint, _) => write!(self.out, "floatBitsToUint")?,
|
||||
(Sk::Sint, Sk::Float, _) => write!(self.out, "intBitsToFloat")?,
|
||||
(Sk::Uint, Sk::Float, _) => write!(self.out, "uintBitsToFloat")?,
|
||||
|
||||
// Cast between vector types
|
||||
(_, _, Some(vector)) => {
|
||||
self.write_value_type(&vector)?;
|
||||
}
|
||||
|
||||
// There is no way to bitcast between Uint/Sint in glsl. Use constructor conversion
|
||||
(Sk::Uint | Sk::Bool, Sk::Sint, None) => write!(self.out, "int")?,
|
||||
(Sk::Sint | Sk::Bool, Sk::Uint, None) => write!(self.out, "uint")?,
|
||||
(Sk::Bool, Sk::Float, None) => write!(self.out, "float")?,
|
||||
(Sk::Sint | Sk::Uint | Sk::Float, Sk::Bool, None) => {
|
||||
write!(self.out, "bool")?
|
||||
}
|
||||
|
||||
(Sk::AbstractInt | Sk::AbstractFloat, _, _)
|
||||
| (_, Sk::AbstractInt | Sk::AbstractFloat, _) => unreachable!(),
|
||||
};
|
||||
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(expr, ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
// this is similar to `write_type`, but with the target scalar
|
||||
let scalar = glsl_scalar(target)?;
|
||||
match *inner {
|
||||
TypeInner::Matrix { columns, rows, .. } => write!(
|
||||
self.out,
|
||||
"{}mat{}x{}",
|
||||
scalar.prefix, columns as u8, rows as u8
|
||||
)?,
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(self.out, "{}vec{}", scalar.prefix, size as u8)?
|
||||
}
|
||||
_ => write!(self.out, "{}", scalar.full)?,
|
||||
}
|
||||
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(expr, ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
// `Bitcast` is a call to one of the glsl provided bitcast functions,
|
||||
// or to a constructor when only the signedness of an integer changes.
|
||||
Expression::Bitcast { expr, ty } => {
|
||||
use crate::ScalarKind as Sk;
|
||||
|
||||
let inner = ctx.resolve_type(expr, &self.module.types);
|
||||
let target = &self.module.types[ty].inner;
|
||||
|
||||
if inner == target {
|
||||
return self.write_expr(expr, ctx);
|
||||
}
|
||||
|
||||
let unsupported =
|
||||
|| Error::Custom(format!("GLSL cannot bitcast from {inner:?} to {target:?}"));
|
||||
let (Some((src_size, src)), Some((dst_size, dst))) = (
|
||||
inner.vector_size_and_scalar(),
|
||||
target.vector_size_and_scalar(),
|
||||
) else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
if src_size != dst_size {
|
||||
return Err(unsupported());
|
||||
}
|
||||
|
||||
match (src.kind, dst.kind) {
|
||||
(Sk::Float, Sk::Sint) if src.width == 4 => write!(self.out, "floatBitsToInt")?,
|
||||
(Sk::Float, Sk::Uint) if src.width == 4 => write!(self.out, "floatBitsToUint")?,
|
||||
(Sk::Sint, Sk::Float) if src.width == 4 => write!(self.out, "intBitsToFloat")?,
|
||||
(Sk::Uint, Sk::Float) if src.width == 4 => write!(self.out, "uintBitsToFloat")?,
|
||||
// There is no way to bitcast between Uint/Sint in glsl. Use constructor conversion
|
||||
(Sk::Uint, Sk::Sint) | (Sk::Sint, Sk::Uint) => {
|
||||
self.write_value_type(target)?;
|
||||
}
|
||||
_ => return Err(unsupported()),
|
||||
};
|
||||
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(expr, ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
// These expressions never show up in `Emit`.
|
||||
Expression::CallResult(_)
|
||||
|
||||
@@ -14,6 +14,15 @@ impl crate::ScalarKind {
|
||||
Self::Bool | Self::AbstractInt | Self::AbstractFloat => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn to_hlsl_cast_16bit(self) -> &'static str {
|
||||
match self {
|
||||
Self::Float => "asfloat16",
|
||||
Self::Sint => "asint16",
|
||||
Self::Uint => "asuint16",
|
||||
Self::Bool | Self::AbstractInt | Self::AbstractFloat => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Scalar {
|
||||
|
||||
+129
-4
@@ -26,7 +26,7 @@ int dim_1d = NagaDimensions1D(image_1d);
|
||||
```
|
||||
*/
|
||||
|
||||
use alloc::format;
|
||||
use alloc::{format, string::String};
|
||||
use core::fmt::Write;
|
||||
|
||||
use super::{
|
||||
@@ -119,6 +119,39 @@ pub(super) struct WrappedCast {
|
||||
pub(super) dst_scalar: crate::Scalar,
|
||||
}
|
||||
|
||||
/// A function that bitcasts between scalar or vector types of different shapes,
|
||||
/// such as `half2` and `uint`.
|
||||
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub(super) struct WrappedBitcast {
|
||||
pub(super) src: (Option<crate::VectorSize>, crate::Scalar),
|
||||
pub(super) dst: (Option<crate::VectorSize>, crate::Scalar),
|
||||
}
|
||||
|
||||
impl WrappedBitcast {
|
||||
/// Return the wrapped bitcast needed to implement a bitcast from `src_ty` to `dst_ty`,
|
||||
/// or `None` if the bitcast can be written inline.
|
||||
pub(super) fn new(src_ty: &crate::TypeInner, dst_ty: &crate::TypeInner) -> Option<Self> {
|
||||
let src = src_ty.vector_size_and_scalar()?;
|
||||
let dst = dst_ty.vector_size_and_scalar()?;
|
||||
(src.0 != dst.0 || src.1.width != dst.1.width).then_some(Self { src, dst })
|
||||
}
|
||||
|
||||
pub(super) fn function_name(&self) -> Result<String, super::Error> {
|
||||
let type_name = |(size, scalar): (Option<crate::VectorSize>, crate::Scalar)| {
|
||||
Ok::<_, super::Error>(format!(
|
||||
"{}{}",
|
||||
scalar.to_hlsl_str()?,
|
||||
size.map(crate::common::vector_size_str).unwrap_or("")
|
||||
))
|
||||
};
|
||||
Ok(format!(
|
||||
"naga_bitcast_{}_to_{}",
|
||||
type_name(self.src)?,
|
||||
type_name(self.dst)?
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// HLSL backend requires its own `ImageQuery` enum.
|
||||
///
|
||||
/// It is used inside `WrappedImageQuery` and should be unique per ImageQuery function.
|
||||
@@ -1788,8 +1821,7 @@ impl<W: Write> super::Writer<'_, W> {
|
||||
for (_, expression) in func_ctx.expressions.iter() {
|
||||
if let crate::Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert: Some(width),
|
||||
target: dst_scalar,
|
||||
} = *expression
|
||||
{
|
||||
// Avoid undefined behaviour when casting from a float to integer
|
||||
@@ -1806,7 +1838,6 @@ impl<W: Write> super::Writer<'_, W> {
|
||||
let Some((vector_size, src_scalar)) = src_ty.vector_size_and_scalar() else {
|
||||
continue;
|
||||
};
|
||||
let dst_scalar = crate::Scalar { kind, width };
|
||||
if src_scalar.kind != ScalarKind::Float
|
||||
|| (dst_scalar.kind != ScalarKind::Sint && dst_scalar.kind != ScalarKind::Uint)
|
||||
{
|
||||
@@ -1871,6 +1902,99 @@ impl<W: Write> super::Writer<'_, W> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write the functions for `Bitcast` expressions that change the number of
|
||||
/// components, which HLSL has no intrinsics for.
|
||||
fn write_wrapped_bitcast_functions(
|
||||
&mut self,
|
||||
module: &crate::Module,
|
||||
func_ctx: &FunctionCtx,
|
||||
) -> BackendResult {
|
||||
use crate::ScalarKind as Sk;
|
||||
|
||||
for (_, expression) in func_ctx.expressions.iter() {
|
||||
let crate::Expression::Bitcast { expr, ty } = *expression else {
|
||||
continue;
|
||||
};
|
||||
let src_ty = func_ctx.resolve_type(expr, &module.types);
|
||||
let dst_ty = &module.types[ty].inner;
|
||||
let Some(wrapped) = WrappedBitcast::new(src_ty, dst_ty) else {
|
||||
continue;
|
||||
};
|
||||
if !self.wrapped.insert(WrappedType::Bitcast(wrapped)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let fun_name = wrapped.function_name()?;
|
||||
self.write_value_type(module, dst_ty)?;
|
||||
write!(self.out, " {fun_name}(")?;
|
||||
self.write_value_type(module, src_ty)?;
|
||||
writeln!(self.out, " value) {{")?;
|
||||
let level = crate::back::Level(1);
|
||||
|
||||
match (wrapped.src, wrapped.dst) {
|
||||
// Pack the bits of two or four halves into one or two words.
|
||||
((Some(src_size), crate::Scalar::F16), (dst_size, dst)) if dst.width == 4 => {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{level}uint16_t{} bits = asuint16(value);",
|
||||
src_size as u8
|
||||
)?;
|
||||
let word =
|
||||
|lo: &str, hi: &str| format!("(uint(bits.{lo}) | (uint(bits.{hi}) << 16))");
|
||||
let packed = if dst_size.is_none() {
|
||||
word("x", "y")
|
||||
} else {
|
||||
format!("uint2({}, {})", word("x", "y"), word("z", "w"))
|
||||
};
|
||||
if dst.kind == Sk::Uint {
|
||||
writeln!(self.out, "{level}return {packed};")?;
|
||||
} else {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{level}return {}({packed});",
|
||||
dst.kind.to_hlsl_cast()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
// Unpack one or two words into two or four halves.
|
||||
((src_size, src), (Some(dst_size), crate::Scalar::F16)) if src.width == 4 => {
|
||||
let (bits_ty, words) = match src_size {
|
||||
None => ("uint", &[""][..]),
|
||||
Some(_) => ("uint2", &[".x", ".y"][..]),
|
||||
};
|
||||
if src.kind == Sk::Uint {
|
||||
writeln!(self.out, "{level}{bits_ty} bits = value;")?;
|
||||
} else {
|
||||
writeln!(self.out, "{level}{bits_ty} bits = asuint(value);")?;
|
||||
}
|
||||
write!(
|
||||
self.out,
|
||||
"{level}return asfloat16(uint16_t{}(",
|
||||
dst_size as u8
|
||||
)?;
|
||||
for (i, word) in words.iter().enumerate() {
|
||||
if i != 0 {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
write!(
|
||||
self.out,
|
||||
"uint16_t(bits{word} & 0xFFFFu), uint16_t(bits{word} >> 16)"
|
||||
)?;
|
||||
}
|
||||
writeln!(self.out, "));")?;
|
||||
}
|
||||
_ => {
|
||||
return Err(super::Error::Unimplemented(format!(
|
||||
"bitcast from {src_ty:?} to {dst_ty:?}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
writeln!(self.out, "}}")?;
|
||||
writeln!(self.out)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Helper function that writes various wrapped functions
|
||||
pub(super) fn write_wrapped_functions(
|
||||
&mut self,
|
||||
@@ -1883,6 +2007,7 @@ impl<W: Write> super::Writer<'_, W> {
|
||||
self.write_wrapped_expression_functions(module, func_ctx.expressions, Some(func_ctx))?;
|
||||
self.write_wrapped_zero_value_functions(module, func_ctx.expressions)?;
|
||||
self.write_wrapped_cast_functions(module, func_ctx)?;
|
||||
self.write_wrapped_bitcast_functions(module, func_ctx)?;
|
||||
|
||||
for (handle, _) in func_ctx.expressions.iter() {
|
||||
match func_ctx.expressions[handle] {
|
||||
|
||||
@@ -707,6 +707,7 @@ enum WrappedType {
|
||||
UnaryOp(help::WrappedUnaryOp),
|
||||
BinaryOp(help::WrappedBinaryOp),
|
||||
Cast(help::WrappedCast),
|
||||
Bitcast(help::WrappedBitcast),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -4478,97 +4478,97 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => {
|
||||
Expression::As { expr, target } => {
|
||||
let inner = func_ctx.resolve_type(expr, &module.types);
|
||||
if inner.scalar_kind() == Some(ScalarKind::Float)
|
||||
&& (kind == ScalarKind::Sint || kind == ScalarKind::Uint)
|
||||
&& convert.is_some()
|
||||
&& matches!(convert, Some(4) | Some(8))
|
||||
&& (target.kind == ScalarKind::Sint || target.kind == ScalarKind::Uint)
|
||||
&& matches!(target.width, 4 | 8)
|
||||
{
|
||||
// Use helper functions for float to int casts in order to
|
||||
// avoid undefined behaviour when value is out of range for
|
||||
// the target type.
|
||||
let fun_name = match (kind, convert) {
|
||||
(ScalarKind::Sint, Some(4)) => F2I32_FUNCTION,
|
||||
(ScalarKind::Uint, Some(4)) => F2U32_FUNCTION,
|
||||
(ScalarKind::Sint, Some(8)) => F2I64_FUNCTION,
|
||||
(ScalarKind::Uint, Some(8)) => F2U64_FUNCTION,
|
||||
let fun_name = match (target.kind, target.width) {
|
||||
(ScalarKind::Sint, 4) => F2I32_FUNCTION,
|
||||
(ScalarKind::Uint, 4) => F2U32_FUNCTION,
|
||||
(ScalarKind::Sint, 8) => F2I64_FUNCTION,
|
||||
(ScalarKind::Uint, 8) => F2U64_FUNCTION,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
} else {
|
||||
let close_paren = match convert {
|
||||
Some(dst_width) => {
|
||||
let scalar = Scalar {
|
||||
kind,
|
||||
width: dst_width,
|
||||
};
|
||||
match *inner {
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}(",
|
||||
scalar.to_hlsl_str()?,
|
||||
common::vector_size_str(size)
|
||||
)?;
|
||||
}
|
||||
TypeInner::Scalar(_) => {
|
||||
write!(self.out, "{}(", scalar.to_hlsl_str()?,)?;
|
||||
}
|
||||
TypeInner::Matrix { columns, rows, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}x{}(",
|
||||
scalar.to_hlsl_str()?,
|
||||
common::vector_size_str(columns),
|
||||
common::vector_size_str(rows)
|
||||
)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::as {inner:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
true
|
||||
match *inner {
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}(",
|
||||
target.to_hlsl_str()?,
|
||||
common::vector_size_str(size)
|
||||
)?;
|
||||
}
|
||||
None => {
|
||||
if inner.scalar_width() == Some(8) {
|
||||
false
|
||||
} else if inner.scalar_width() == Some(2) {
|
||||
// HLSL's asint()/asuint() only work on 32-bit types.
|
||||
// For 16-bit bitcasts, use type constructor instead.
|
||||
let dst_scalar = Scalar { kind, width: 2 };
|
||||
match *inner {
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}(",
|
||||
dst_scalar.to_hlsl_str()?,
|
||||
common::vector_size_str(size)
|
||||
)?;
|
||||
}
|
||||
_ => {
|
||||
write!(self.out, "{}(", dst_scalar.to_hlsl_str()?)?;
|
||||
}
|
||||
};
|
||||
true
|
||||
} else {
|
||||
write!(self.out, "{}(", kind.to_hlsl_cast(),)?;
|
||||
true
|
||||
}
|
||||
TypeInner::Scalar(_) => {
|
||||
write!(self.out, "{}(", target.to_hlsl_str()?,)?;
|
||||
}
|
||||
TypeInner::Matrix { columns, rows, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}x{}(",
|
||||
target.to_hlsl_str()?,
|
||||
common::vector_size_str(columns),
|
||||
common::vector_size_str(rows)
|
||||
)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::as {inner:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
if close_paren {
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
}
|
||||
Expression::Bitcast { expr, ty } => {
|
||||
let src_ty = func_ctx.resolve_type(expr, &module.types);
|
||||
let dst_ty = &module.types[ty].inner;
|
||||
let unsupported =
|
||||
|| Error::Unimplemented(format!("bitcast from {src_ty:?} to {dst_ty:?}"));
|
||||
let (Some((src_size, src)), Some((dst_size, dst))) = (
|
||||
src_ty.vector_size_and_scalar(),
|
||||
dst_ty.vector_size_and_scalar(),
|
||||
) else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
|
||||
if let Some(wrapped) = help::WrappedBitcast::new(src_ty, dst_ty) {
|
||||
write!(self.out, "{}(", wrapped.function_name()?)?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
} else if src == dst {
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
} else {
|
||||
debug_assert_eq!(src_size, dst_size);
|
||||
let is_int =
|
||||
|scalar: Scalar| matches!(scalar.kind, ScalarKind::Sint | ScalarKind::Uint);
|
||||
// HLSL's `asint()`, `asuint()` and `asfloat()` only work on
|
||||
// 32-bit types, and 16-bit types have `asint16()` and so
|
||||
// on. For other widths of integers, use a constructor
|
||||
// instead.
|
||||
match (src.width, is_int(src) && is_int(dst)) {
|
||||
(2 | 8, true) => {
|
||||
write!(self.out, "{}", dst.to_hlsl_str()?)?;
|
||||
if let Some(size) = dst_size {
|
||||
write!(self.out, "{}", common::vector_size_str(size))?;
|
||||
}
|
||||
write!(self.out, "(")?;
|
||||
}
|
||||
(2, false) => write!(self.out, "{}(", dst.kind.to_hlsl_cast_16bit())?,
|
||||
(4, _) => write!(self.out, "{}(", dst.kind.to_hlsl_cast())?,
|
||||
_ => return Err(unsupported()),
|
||||
};
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
}
|
||||
Expression::Math {
|
||||
|
||||
@@ -255,6 +255,7 @@ pub(super) const fn is_statement_result(expression: &crate::Expression) -> bool
|
||||
| Ex::Relational { .. }
|
||||
| Ex::Math { .. }
|
||||
| Ex::As { .. }
|
||||
| Ex::Bitcast { .. }
|
||||
| Ex::ArrayLength(_)
|
||||
| Ex::RayQueryVertexPositions { .. }
|
||||
| Ex::RayQueryGetIntersection { .. }
|
||||
|
||||
+35
-45
@@ -3044,60 +3044,40 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => match *context.resolve_type(expr) {
|
||||
crate::Expression::As { expr, target } => match *context.resolve_type(expr) {
|
||||
crate::TypeInner::Scalar(src) | crate::TypeInner::Vector { scalar: src, .. } => {
|
||||
if src.kind == crate::ScalarKind::Float
|
||||
&& (kind == crate::ScalarKind::Sint || kind == crate::ScalarKind::Uint)
|
||||
&& convert.is_some()
|
||||
&& (target.kind == crate::ScalarKind::Sint
|
||||
|| target.kind == crate::ScalarKind::Uint)
|
||||
{
|
||||
// Use helper functions for float to int casts in order to avoid
|
||||
// undefined behaviour when value is out of range for the target
|
||||
// type.
|
||||
let fun_name = match (kind, convert) {
|
||||
(crate::ScalarKind::Sint, Some(4)) => F2I32_FUNCTION,
|
||||
(crate::ScalarKind::Uint, Some(4)) => F2U32_FUNCTION,
|
||||
(crate::ScalarKind::Sint, Some(8)) => F2I64_FUNCTION,
|
||||
(crate::ScalarKind::Uint, Some(8)) => F2U64_FUNCTION,
|
||||
let fun_name = match (target.kind, target.width) {
|
||||
(crate::ScalarKind::Sint, 4) => F2I32_FUNCTION,
|
||||
(crate::ScalarKind::Uint, 4) => F2U32_FUNCTION,
|
||||
(crate::ScalarKind::Sint, 8) => F2I64_FUNCTION,
|
||||
(crate::ScalarKind::Uint, 8) => F2U64_FUNCTION,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.put_expression(expr, context, true)?;
|
||||
write!(self.out, ")")?;
|
||||
} else {
|
||||
let target_scalar = crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(src.width),
|
||||
};
|
||||
let op = match convert {
|
||||
Some(_) => "static_cast",
|
||||
None => "as_type",
|
||||
};
|
||||
write!(self.out, "{op}<")?;
|
||||
write!(self.out, "static_cast<")?;
|
||||
match *context.resolve_type(expr) {
|
||||
crate::TypeInner::Vector { size, .. } => {
|
||||
put_numeric_type(&mut self.out, target_scalar, &[size])?
|
||||
put_numeric_type(&mut self.out, target, &[size])?
|
||||
}
|
||||
_ => put_numeric_type(&mut self.out, target_scalar, &[])?,
|
||||
_ => put_numeric_type(&mut self.out, target, &[])?,
|
||||
};
|
||||
write!(self.out, ">(")?;
|
||||
self.put_expression(expr, context, true)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
}
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
scalar,
|
||||
} => {
|
||||
let target_scalar = crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(scalar.width),
|
||||
};
|
||||
put_numeric_type(&mut self.out, target_scalar, &[rows, columns])?;
|
||||
crate::TypeInner::Matrix { columns, rows, .. } => {
|
||||
put_numeric_type(&mut self.out, target, &[rows, columns])?;
|
||||
write!(self.out, "(")?;
|
||||
self.put_expression(expr, context, true)?;
|
||||
write!(self.out, ")")?;
|
||||
@@ -3108,6 +3088,25 @@ impl<W: Write> Writer<W> {
|
||||
)))
|
||||
}
|
||||
},
|
||||
crate::Expression::Bitcast { expr, ty } => {
|
||||
write!(self.out, "as_type<")?;
|
||||
match context.module.types[ty].inner {
|
||||
crate::TypeInner::Scalar(scalar) => {
|
||||
put_numeric_type(&mut self.out, scalar, &[])?
|
||||
}
|
||||
crate::TypeInner::Vector { size, scalar } => {
|
||||
put_numeric_type(&mut self.out, scalar, &[size])?
|
||||
}
|
||||
ref other => {
|
||||
return Err(Error::GenericValidation(format!(
|
||||
"Unsupported type for Bitcast: {other:?}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
write!(self.out, ">(")?;
|
||||
self.put_expression(expr, context, true)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
// These have no inline form, so they are only ever read through
|
||||
// the temporary the statement that produced them stored them in,
|
||||
// which one of the two tables above names. The one place that is
|
||||
@@ -6452,8 +6451,7 @@ template <typename A>
|
||||
module: &crate::Module,
|
||||
func_ctx: &back::FunctionCtx,
|
||||
expr: Handle<crate::Expression>,
|
||||
kind: crate::ScalarKind,
|
||||
convert: Option<crate::Bytes>,
|
||||
dst_scalar: crate::Scalar,
|
||||
) -> BackendResult {
|
||||
// Avoid undefined behaviour when casting from a float to integer
|
||||
// when the value is out of range for the target type. Additionally
|
||||
@@ -6466,13 +6464,9 @@ template <typename A>
|
||||
// truncate(X) and also exactly representable in the original
|
||||
// floating point type.
|
||||
let src_ty = func_ctx.resolve_type(expr, &module.types);
|
||||
let Some(width) = convert else {
|
||||
return Ok(());
|
||||
};
|
||||
let Some((vector_size, src_scalar)) = src_ty.vector_size_and_scalar() else {
|
||||
return Ok(());
|
||||
};
|
||||
let dst_scalar = crate::Scalar { kind, width };
|
||||
if src_scalar.kind != crate::ScalarKind::Float
|
||||
|| (dst_scalar.kind != crate::ScalarKind::Sint
|
||||
&& dst_scalar.kind != crate::ScalarKind::Uint)
|
||||
@@ -6969,12 +6963,8 @@ template <typename A>
|
||||
} => {
|
||||
self.write_wrapped_math_function(module, func_ctx, fun, arg, arg1, arg2, arg3)?;
|
||||
}
|
||||
crate::Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => {
|
||||
self.write_wrapped_cast(module, func_ctx, expr, kind, convert)?;
|
||||
crate::Expression::As { expr, target } => {
|
||||
self.write_wrapped_cast(module, func_ctx, expr, target)?;
|
||||
}
|
||||
crate::Expression::ImageLoad {
|
||||
image,
|
||||
|
||||
@@ -656,8 +656,13 @@ fn adjust_expr(new_pos: &HandleVec<Expression, Handle<Expression>>, expr: &mut E
|
||||
}
|
||||
Expression::As {
|
||||
ref mut expr,
|
||||
kind: _,
|
||||
convert: _,
|
||||
target: _,
|
||||
} => {
|
||||
adjust(expr);
|
||||
}
|
||||
Expression::Bitcast {
|
||||
ref mut expr,
|
||||
ty: _,
|
||||
} => {
|
||||
adjust(expr);
|
||||
}
|
||||
|
||||
+56
-32
@@ -2054,11 +2054,12 @@ impl BlockContext<'_> {
|
||||
| crate::Expression::RayQueryProceedResult
|
||||
| crate::Expression::SubgroupBallotResult
|
||||
| crate::Expression::SubgroupOperationResult { .. } => self.cached[expr_handle],
|
||||
crate::Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => self.write_as_expression(expr, convert, kind, block, result_type_id)?,
|
||||
crate::Expression::As { expr, target } => {
|
||||
self.write_as_expression(expr, target, block, result_type_id)?
|
||||
}
|
||||
crate::Expression::Bitcast { expr, ty } => {
|
||||
self.write_bitcast_expression(expr, ty, block, result_type_id)
|
||||
}
|
||||
crate::Expression::ImageLoad {
|
||||
image,
|
||||
coordinate,
|
||||
@@ -2288,18 +2289,49 @@ impl BlockContext<'_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Helper which generates [`Bitcast`] expressions.
|
||||
///
|
||||
/// [`Bitcast`]: crate::Expression::Bitcast
|
||||
fn write_bitcast_expression(
|
||||
&mut self,
|
||||
expr: Handle<crate::Expression>,
|
||||
ty: Handle<crate::Type>,
|
||||
block: &mut Block,
|
||||
result_type_id: u32,
|
||||
) -> Word {
|
||||
let expr_id = self.cached[expr];
|
||||
|
||||
// Filter out identity casts. Some Adreno drivers are
|
||||
// confused by no-op OpBitCast instructions.
|
||||
let source_inner = self.fun_info[expr].ty.inner_with(&self.ir_module.types);
|
||||
if *source_inner == self.ir_module.types[ty].inner {
|
||||
return expr_id;
|
||||
}
|
||||
|
||||
let id = self.gen_id();
|
||||
block.body.push(Instruction::unary(
|
||||
spirv::Op::Bitcast,
|
||||
result_type_id,
|
||||
id,
|
||||
expr_id,
|
||||
));
|
||||
id
|
||||
}
|
||||
|
||||
/// Helper which focuses on generating the `As` expressions and the various conversions
|
||||
/// that need to happen because of that.
|
||||
fn write_as_expression(
|
||||
&mut self,
|
||||
expr: Handle<crate::Expression>,
|
||||
convert: Option<u8>,
|
||||
kind: crate::ScalarKind,
|
||||
|
||||
target: crate::Scalar,
|
||||
block: &mut Block,
|
||||
result_type_id: u32,
|
||||
) -> Result<u32, Error> {
|
||||
use crate::ScalarKind as Sk;
|
||||
let crate::Scalar {
|
||||
kind,
|
||||
width: dst_width,
|
||||
} = target;
|
||||
let expr_id = self.cached[expr];
|
||||
let ty = self.fun_info[expr].ty.inner_with(&self.ir_module.types);
|
||||
|
||||
@@ -2313,12 +2345,7 @@ impl BlockContext<'_> {
|
||||
scalar,
|
||||
} = *ty
|
||||
{
|
||||
let Some(convert) = convert else {
|
||||
// No conversion needs to be done, passes through.
|
||||
return Ok(expr_id);
|
||||
};
|
||||
|
||||
if convert == scalar.width {
|
||||
if dst_width == scalar.width {
|
||||
// No conversion needs to be done, passes through.
|
||||
return Ok(expr_id);
|
||||
}
|
||||
@@ -2341,7 +2368,7 @@ impl BlockContext<'_> {
|
||||
size: rows,
|
||||
scalar: crate::Scalar {
|
||||
kind,
|
||||
width: convert,
|
||||
width: dst_width,
|
||||
},
|
||||
})));
|
||||
|
||||
@@ -2393,19 +2420,15 @@ impl BlockContext<'_> {
|
||||
Binary(spirv::Op, Word, Word),
|
||||
Ternary(spirv::Op, Word, Word, Word),
|
||||
}
|
||||
let cast = match (src_scalar.kind, kind, convert) {
|
||||
let cast = match (src_scalar.kind, kind, dst_width) {
|
||||
// Filter out identity casts. Some Adreno drivers are
|
||||
// confused by no-op OpBitCast instructions.
|
||||
(src_kind, kind, convert)
|
||||
if src_kind == kind
|
||||
&& convert.filter(|&width| width != src_scalar.width).is_none() =>
|
||||
{
|
||||
(src_kind, kind, dst_width) if src_kind == kind && dst_width == src_scalar.width => {
|
||||
Cast::Identity(expr_id)
|
||||
}
|
||||
(Sk::Bool, Sk::Bool, _) => Cast::Unary(spirv::Op::CopyObject, expr_id),
|
||||
(_, _, None) => Cast::Unary(spirv::Op::Bitcast, expr_id),
|
||||
// casting to a bool - generate `OpXxxNotEqual`
|
||||
(_, Sk::Bool, Some(_)) => {
|
||||
(_, Sk::Bool, _) => {
|
||||
let op = match src_scalar.kind {
|
||||
Sk::Sint | Sk::Uint => spirv::Op::INotEqual,
|
||||
Sk::Float => spirv::Op::FUnordNotEqual,
|
||||
@@ -2431,7 +2454,7 @@ impl BlockContext<'_> {
|
||||
Cast::Binary(op, expr_id, zero_id)
|
||||
}
|
||||
// casting from a bool - generate `OpSelect`
|
||||
(Sk::Bool, _, Some(dst_width)) => {
|
||||
(Sk::Bool, _, dst_width) => {
|
||||
let dst_scalar = crate::Scalar {
|
||||
kind,
|
||||
width: dst_width,
|
||||
@@ -2472,7 +2495,7 @@ impl BlockContext<'_> {
|
||||
// * Otherwise, the result is the value in T closest to
|
||||
// truncate(X) and also exactly representable in the original
|
||||
// floating point type.
|
||||
(Sk::Float, Sk::Sint | Sk::Uint, Some(width)) => {
|
||||
(Sk::Float, Sk::Sint | Sk::Uint, width) => {
|
||||
let dst_scalar = crate::Scalar { kind, width };
|
||||
let (min, max) =
|
||||
crate::proc::min_max_float_representable_by(src_scalar, dst_scalar);
|
||||
@@ -2512,24 +2535,25 @@ impl BlockContext<'_> {
|
||||
};
|
||||
Cast::Unary(op, clamp_id)
|
||||
}
|
||||
(Sk::Float, Sk::Float, Some(dst_width)) if src_scalar.width != dst_width => {
|
||||
(Sk::Float, Sk::Float, dst_width) if src_scalar.width != dst_width => {
|
||||
Cast::Unary(spirv::Op::FConvert, expr_id)
|
||||
}
|
||||
(Sk::Sint, Sk::Float, Some(_)) => Cast::Unary(spirv::Op::ConvertSToF, expr_id),
|
||||
(Sk::Sint, Sk::Sint, Some(dst_width)) if src_scalar.width != dst_width => {
|
||||
(Sk::Sint, Sk::Float, _) => Cast::Unary(spirv::Op::ConvertSToF, expr_id),
|
||||
(Sk::Sint, Sk::Sint, dst_width) if src_scalar.width != dst_width => {
|
||||
Cast::Unary(spirv::Op::SConvert, expr_id)
|
||||
}
|
||||
(Sk::Uint, Sk::Float, Some(_)) => Cast::Unary(spirv::Op::ConvertUToF, expr_id),
|
||||
(Sk::Uint, Sk::Uint, Some(dst_width)) if src_scalar.width != dst_width => {
|
||||
(Sk::Uint, Sk::Float, _) => Cast::Unary(spirv::Op::ConvertUToF, expr_id),
|
||||
(Sk::Uint, Sk::Uint, dst_width) if src_scalar.width != dst_width => {
|
||||
Cast::Unary(spirv::Op::UConvert, expr_id)
|
||||
}
|
||||
(Sk::Uint, Sk::Sint, Some(dst_width)) if src_scalar.width != dst_width => {
|
||||
(Sk::Uint, Sk::Sint, dst_width) if src_scalar.width != dst_width => {
|
||||
Cast::Unary(spirv::Op::SConvert, expr_id)
|
||||
}
|
||||
(Sk::Sint, Sk::Uint, Some(dst_width)) if src_scalar.width != dst_width => {
|
||||
(Sk::Sint, Sk::Uint, dst_width) if src_scalar.width != dst_width => {
|
||||
Cast::Unary(spirv::Op::UConvert, expr_id)
|
||||
}
|
||||
// We assume it's either an identity cast, or int-uint.
|
||||
// Converting between signed and unsigned integers of the same
|
||||
// width preserves the bits.
|
||||
_ => Cast::Unary(spirv::Op::Bitcast, expr_id),
|
||||
};
|
||||
Ok(match cast {
|
||||
|
||||
@@ -1762,59 +1762,26 @@ impl<W: Write> Writer<W> {
|
||||
write!(self.out, "{name}")?;
|
||||
}
|
||||
|
||||
Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => {
|
||||
Expression::As { expr, target } => {
|
||||
let inner = func_ctx.resolve_type(expr, &module.types);
|
||||
let scalar_str = target.to_wgsl_if_implemented()?;
|
||||
match *inner {
|
||||
TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
scalar,
|
||||
} => {
|
||||
let scalar = crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(scalar.width),
|
||||
};
|
||||
let scalar_kind_str = scalar.to_wgsl_if_implemented()?;
|
||||
TypeInner::Matrix { columns, rows, .. } => write!(
|
||||
self.out,
|
||||
"mat{}x{}<{}>",
|
||||
common::vector_size_str(columns),
|
||||
common::vector_size_str(rows),
|
||||
scalar_str
|
||||
)?,
|
||||
TypeInner::Vector { size, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"mat{}x{}<{}>",
|
||||
common::vector_size_str(columns),
|
||||
common::vector_size_str(rows),
|
||||
scalar_kind_str
|
||||
"vec{}<{}>",
|
||||
common::vector_size_str(size),
|
||||
scalar_str
|
||||
)?;
|
||||
}
|
||||
TypeInner::Vector {
|
||||
size,
|
||||
scalar: crate::Scalar { width, .. },
|
||||
} => {
|
||||
let scalar = crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(width),
|
||||
};
|
||||
let vector_size_str = common::vector_size_str(size);
|
||||
let scalar_kind_str = scalar.to_wgsl_if_implemented()?;
|
||||
if convert.is_some() {
|
||||
write!(self.out, "vec{vector_size_str}<{scalar_kind_str}>")?;
|
||||
} else {
|
||||
write!(self.out, "bitcast<vec{vector_size_str}<{scalar_kind_str}>>")?;
|
||||
}
|
||||
}
|
||||
TypeInner::Scalar(crate::Scalar { width, .. }) => {
|
||||
let scalar = crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(width),
|
||||
};
|
||||
let scalar_kind_str = scalar.to_wgsl_if_implemented()?;
|
||||
if convert.is_some() {
|
||||
write!(self.out, "{scalar_kind_str}")?
|
||||
} else {
|
||||
write!(self.out, "bitcast<{scalar_kind_str}>")?
|
||||
}
|
||||
}
|
||||
TypeInner::Scalar(_) => write!(self.out, "{scalar_str}")?,
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::as {inner:?}"
|
||||
@@ -1825,6 +1792,13 @@ impl<W: Write> Writer<W> {
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
Expression::Bitcast { expr, ty } => {
|
||||
write!(self.out, "bitcast<")?;
|
||||
self.write_type(module, ty)?;
|
||||
write!(self.out, ">(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
Expression::Load { pointer } => {
|
||||
let is_atomic_pointer = func_ctx
|
||||
.resolve_type(pointer, &module.types)
|
||||
|
||||
@@ -228,11 +228,11 @@ impl ExpressionTracer<'_> {
|
||||
self.expressions_used.insert_iter(arg2);
|
||||
self.expressions_used.insert_iter(arg3);
|
||||
}
|
||||
Ex::As {
|
||||
expr,
|
||||
kind: _,
|
||||
convert: _,
|
||||
} => {
|
||||
Ex::As { expr, target: _ } => {
|
||||
self.expressions_used.insert(expr);
|
||||
}
|
||||
Ex::Bitcast { expr, ty } => {
|
||||
self.types_used.insert(ty);
|
||||
self.expressions_used.insert(expr);
|
||||
}
|
||||
Ex::ArrayLength(expr) => {
|
||||
@@ -407,9 +407,15 @@ impl ModuleMap {
|
||||
}
|
||||
Ex::As {
|
||||
ref mut expr,
|
||||
kind: _,
|
||||
convert: _,
|
||||
target: _,
|
||||
} => adjust(expr),
|
||||
Ex::Bitcast {
|
||||
ref mut expr,
|
||||
ref mut ty,
|
||||
} => {
|
||||
adjust(expr);
|
||||
self.types.adjust(ty);
|
||||
}
|
||||
Ex::CallResult(ref mut function) => {
|
||||
self.functions.adjust(function);
|
||||
}
|
||||
|
||||
@@ -938,8 +938,7 @@ fn array_length_override_mutual() {
|
||||
let init = module.global_expressions.append(
|
||||
Ex::As {
|
||||
expr: sum,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar::U32,
|
||||
},
|
||||
nowhere,
|
||||
);
|
||||
@@ -1273,8 +1272,7 @@ fn unnamed_override_type() {
|
||||
let named_init = module.global_expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: unnamed_override_expr,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: None,
|
||||
target: crate::Scalar::I32,
|
||||
},
|
||||
nowhere,
|
||||
);
|
||||
|
||||
@@ -1775,8 +1775,7 @@ impl MacroCall {
|
||||
ctx.add_expression(
|
||||
Expression::As {
|
||||
expr,
|
||||
kind: Sk::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
},
|
||||
Span::default(),
|
||||
)?
|
||||
@@ -1793,8 +1792,7 @@ impl MacroCall {
|
||||
ctx.add_expression(
|
||||
Expression::As {
|
||||
expr,
|
||||
kind: Sk::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
},
|
||||
Span::default(),
|
||||
)?
|
||||
@@ -1860,8 +1858,7 @@ impl MacroCall {
|
||||
ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: res,
|
||||
kind: Sk::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
},
|
||||
Span::default(),
|
||||
)?
|
||||
@@ -1870,16 +1867,14 @@ impl MacroCall {
|
||||
let conv_arg_2 = ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: args[2],
|
||||
kind: Sk::Uint,
|
||||
convert: Some(4),
|
||||
target: Scalar::U32,
|
||||
},
|
||||
Span::default(),
|
||||
)?;
|
||||
let conv_arg_3 = ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: args[3],
|
||||
kind: Sk::Uint,
|
||||
convert: Some(4),
|
||||
target: Scalar::U32,
|
||||
},
|
||||
Span::default(),
|
||||
)?;
|
||||
@@ -1898,16 +1893,14 @@ impl MacroCall {
|
||||
let conv_arg_1 = ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: args[1],
|
||||
kind: Sk::Uint,
|
||||
convert: Some(4),
|
||||
target: Scalar::U32,
|
||||
},
|
||||
Span::default(),
|
||||
)?;
|
||||
let conv_arg_2 = ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: args[2],
|
||||
kind: Sk::Uint,
|
||||
convert: Some(4),
|
||||
target: Scalar::U32,
|
||||
},
|
||||
Span::default(),
|
||||
)?;
|
||||
@@ -2017,14 +2010,21 @@ impl MacroCall {
|
||||
Span::default(),
|
||||
)?
|
||||
}
|
||||
MacroCall::BitCast(kind) => ctx.add_expression(
|
||||
Expression::As {
|
||||
expr: args[0],
|
||||
kind,
|
||||
convert: None,
|
||||
},
|
||||
Span::default(),
|
||||
)?,
|
||||
MacroCall::BitCast(kind) => {
|
||||
let inner = match *ctx.resolve_type(args[0], meta)? {
|
||||
TypeInner::Scalar(_) => TypeInner::Scalar(Scalar { kind, width: 4 }),
|
||||
TypeInner::Vector { size, .. } => TypeInner::Vector {
|
||||
size,
|
||||
scalar: Scalar { kind, width: 4 },
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let ty = ctx
|
||||
.module
|
||||
.types
|
||||
.insert(Type { name: None, inner }, Span::default());
|
||||
ctx.add_expression(Expression::Bitcast { expr: args[0], ty }, meta)?
|
||||
}
|
||||
MacroCall::Derivate(axis, ctrl) => ctx.add_expression(
|
||||
Expression::Derivative {
|
||||
axis,
|
||||
|
||||
@@ -1417,8 +1417,7 @@ impl<'a> Context<'a> {
|
||||
*expr = self.add_expression(
|
||||
Expression::As {
|
||||
expr: *expr,
|
||||
kind: scalar.kind,
|
||||
convert: Some(scalar.width),
|
||||
target: scalar,
|
||||
},
|
||||
meta,
|
||||
)?;
|
||||
|
||||
@@ -139,9 +139,8 @@ impl Frontend {
|
||||
|
||||
ctx.add_expression(
|
||||
Expression::As {
|
||||
kind: scalar.kind,
|
||||
target: scalar,
|
||||
expr,
|
||||
convert: Some(scalar.width),
|
||||
},
|
||||
meta,
|
||||
)?
|
||||
@@ -153,9 +152,8 @@ impl Frontend {
|
||||
|
||||
ctx.add_expression(
|
||||
Expression::As {
|
||||
kind: scalar.kind,
|
||||
target: scalar,
|
||||
expr: value,
|
||||
convert: Some(scalar.width),
|
||||
},
|
||||
meta,
|
||||
)?
|
||||
|
||||
@@ -354,8 +354,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
let handle = function.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: arg_expr,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
target: crate::Scalar::I32,
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
@@ -125,9 +125,8 @@ fn extract_image_coordinates(
|
||||
let array_index_f32 = ctx.expressions.append(extra_expr, base_span);
|
||||
let array_index = ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
kind: crate::ScalarKind::Sint,
|
||||
target: Scalar::I32,
|
||||
expr: array_index_f32,
|
||||
convert: Some(4),
|
||||
},
|
||||
base_span,
|
||||
);
|
||||
@@ -556,8 +555,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
);
|
||||
let expr = crate::Expression::As {
|
||||
expr: lod_handle,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
};
|
||||
let s32_lod_handle = ctx.expressions.append(expr, span);
|
||||
crate::SampleLevel::Exact(s32_lod_handle)
|
||||
@@ -866,8 +864,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
let expr = if maybe_scalar_kind == Some(crate::ScalarKind::Sint) {
|
||||
crate::Expression::As {
|
||||
expr: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
}
|
||||
} else {
|
||||
expr
|
||||
@@ -911,8 +908,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
let expr = if maybe_scalar_kind == Some(crate::ScalarKind::Sint) {
|
||||
crate::Expression::As {
|
||||
expr: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
target: Scalar::I32,
|
||||
}
|
||||
} else {
|
||||
expr
|
||||
|
||||
+29
-40
@@ -1076,9 +1076,9 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let left = self.get_expr_handle(p1_id, p1_lexp, ctx, emitter, block, body_idx);
|
||||
|
||||
let result_lookup_ty = self.lookup_type.lookup(result_type_id)?;
|
||||
let kind = ctx.module.types[result_lookup_ty.handle]
|
||||
let target = ctx.module.types[result_lookup_ty.handle]
|
||||
.inner
|
||||
.scalar_kind()
|
||||
.scalar()
|
||||
.unwrap();
|
||||
|
||||
let expr = crate::Expression::Unary {
|
||||
@@ -1086,14 +1086,8 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
expr: if p1_lexp.type_id == result_type_id {
|
||||
left
|
||||
} else {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: left,
|
||||
kind,
|
||||
convert: None,
|
||||
},
|
||||
span,
|
||||
)
|
||||
ctx.expressions
|
||||
.append(crate::Expression::As { expr: left, target }, span)
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1142,9 +1136,9 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
SignAnchor::Operand => p1_lexp.type_id,
|
||||
};
|
||||
let expected_lookup_ty = self.lookup_type.lookup(expected_type_id)?;
|
||||
let kind = ctx.module.types[expected_lookup_ty.handle]
|
||||
let target = ctx.module.types[expected_lookup_ty.handle]
|
||||
.inner
|
||||
.scalar_kind()
|
||||
.scalar()
|
||||
.unwrap();
|
||||
|
||||
let expr = crate::Expression::Binary {
|
||||
@@ -1152,14 +1146,8 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
left: if p1_lexp.type_id == expected_type_id {
|
||||
left
|
||||
} else {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: left,
|
||||
kind,
|
||||
convert: None,
|
||||
},
|
||||
span,
|
||||
)
|
||||
ctx.expressions
|
||||
.append(crate::Expression::As { expr: left, target }, span)
|
||||
},
|
||||
right: if p2_lexp.type_id == expected_type_id {
|
||||
right
|
||||
@@ -1167,8 +1155,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: right,
|
||||
kind,
|
||||
convert: None,
|
||||
target,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1210,40 +1197,35 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let p1_lexp = self.lookup_expression.lookup(p1_id)?;
|
||||
let left = self.get_expr_handle(p1_id, p1_lexp, ctx, emitter, block, body_idx);
|
||||
let p1_lookup_ty = self.lookup_type.lookup(p1_lexp.type_id)?;
|
||||
let p1_kind = ctx.module.types[p1_lookup_ty.handle]
|
||||
let p1_scalar = ctx.module.types[p1_lookup_ty.handle]
|
||||
.inner
|
||||
.scalar_kind()
|
||||
.scalar()
|
||||
.unwrap();
|
||||
let p2_lexp = self.lookup_expression.lookup(p2_id)?;
|
||||
let right = self.get_expr_handle(p2_id, p2_lexp, ctx, emitter, block, body_idx);
|
||||
let p2_lookup_ty = self.lookup_type.lookup(p2_lexp.type_id)?;
|
||||
let p2_kind = ctx.module.types[p2_lookup_ty.handle]
|
||||
let p2_scalar = ctx.module.types[p2_lookup_ty.handle]
|
||||
.inner
|
||||
.scalar_kind()
|
||||
.scalar()
|
||||
.unwrap();
|
||||
|
||||
let expr = crate::Expression::Binary {
|
||||
op,
|
||||
left: if p1_kind == kind {
|
||||
left: if p1_scalar.kind == kind {
|
||||
left
|
||||
} else {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: left,
|
||||
kind,
|
||||
convert: None,
|
||||
},
|
||||
span,
|
||||
)
|
||||
let target = crate::Scalar { kind, ..p1_scalar };
|
||||
ctx.expressions
|
||||
.append(crate::Expression::As { expr: left, target }, span)
|
||||
},
|
||||
right: if p2_kind == kind {
|
||||
right: if p2_scalar.kind == kind {
|
||||
right
|
||||
} else {
|
||||
let target = crate::Scalar { kind, ..p2_scalar };
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: right,
|
||||
kind,
|
||||
convert: None,
|
||||
target,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1283,11 +1265,18 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let p2_lexp = self.lookup_expression.lookup(p2_id)?;
|
||||
let p2_handle = self.get_expr_handle(p2_id, p2_lexp, ctx, emitter, block, body_idx);
|
||||
// convert the shift to Uint
|
||||
let p2_lookup_ty = self.lookup_type.lookup(p2_lexp.type_id)?;
|
||||
let p2_scalar = ctx.module.types[p2_lookup_ty.handle]
|
||||
.inner
|
||||
.scalar()
|
||||
.unwrap();
|
||||
let right = ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: p2_handle,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
..p2_scalar
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
@@ -896,16 +896,20 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let left_cast = ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: left,
|
||||
kind: crate::ScalarKind::Float,
|
||||
convert: Some(size),
|
||||
target: crate::Scalar {
|
||||
kind: crate::ScalarKind::Float,
|
||||
width: size,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
let right_cast = ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: right,
|
||||
kind: crate::ScalarKind::Float,
|
||||
convert: Some(size),
|
||||
target: crate::Scalar {
|
||||
kind: crate::ScalarKind::Float,
|
||||
width: size,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
@@ -930,8 +934,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let cast = ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: floor,
|
||||
kind,
|
||||
convert: Some(size),
|
||||
target: crate::Scalar { kind, width: size },
|
||||
},
|
||||
span,
|
||||
);
|
||||
@@ -1130,8 +1133,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: offset_handle,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar::U32,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1143,8 +1145,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: count_handle,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar::U32,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1198,8 +1199,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: offset_handle,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar::U32,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1211,8 +1211,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
expr: count_handle,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
convert: None,
|
||||
target: crate::Scalar::U32,
|
||||
},
|
||||
span,
|
||||
)
|
||||
@@ -1619,16 +1618,16 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
_ => return Err(Error::InvalidAsType(ty_lookup.handle)),
|
||||
};
|
||||
|
||||
let expr = crate::Expression::As {
|
||||
expr: get_expr_handle!(value_id, value_lexp),
|
||||
kind: scalar.kind,
|
||||
convert: if scalar.kind == crate::ScalarKind::Bool {
|
||||
Some(crate::BOOL_WIDTH)
|
||||
} else if inst.op == Op::Bitcast {
|
||||
None
|
||||
} else {
|
||||
Some(scalar.width)
|
||||
},
|
||||
let expr = if inst.op == Op::Bitcast {
|
||||
crate::Expression::Bitcast {
|
||||
expr: get_expr_handle!(value_id, value_lexp),
|
||||
ty: ty_lookup.handle,
|
||||
}
|
||||
} else {
|
||||
crate::Expression::As {
|
||||
expr: get_expr_handle!(value_id, value_lexp),
|
||||
target: scalar,
|
||||
}
|
||||
};
|
||||
self.lookup_expression.insert(
|
||||
result_id,
|
||||
@@ -2152,9 +2151,8 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
// IR expects a signed integer, so do a bitcast
|
||||
ctx.expressions.append(
|
||||
crate::Expression::As {
|
||||
kind: crate::ScalarKind::Sint,
|
||||
expr: selector_handle,
|
||||
convert: None,
|
||||
target: crate::Scalar::I32,
|
||||
},
|
||||
span,
|
||||
)
|
||||
|
||||
@@ -193,8 +193,7 @@ impl<'source> Lowerer<'source, '_> {
|
||||
) => {
|
||||
expr = crate::Expression::As {
|
||||
expr: component,
|
||||
kind: scalar.kind,
|
||||
convert: Some(scalar.width),
|
||||
target: scalar,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -215,8 +214,7 @@ impl<'source> Lowerer<'source, '_> {
|
||||
) if dst_size == src_size => {
|
||||
expr = crate::Expression::As {
|
||||
expr: component,
|
||||
kind: dst_scalar.kind,
|
||||
convert: Some(dst_scalar.width),
|
||||
target: dst_scalar,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -258,8 +256,7 @@ impl<'source> Lowerer<'source, '_> {
|
||||
) if dst_columns == src_columns && dst_rows == src_rows => {
|
||||
expr = crate::Expression::As {
|
||||
expr: component,
|
||||
kind: dst_scalar.kind,
|
||||
convert: Some(dst_scalar.width),
|
||||
target: dst_scalar,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +152,7 @@ impl<'source> super::ExpressionContext<'source, '_, '_> {
|
||||
} else {
|
||||
let cast = crate::Expression::As {
|
||||
expr,
|
||||
kind: goal_scalar.kind,
|
||||
convert: Some(goal_scalar.width),
|
||||
target: goal_scalar,
|
||||
};
|
||||
self.append_expression(cast, expr_span)
|
||||
}
|
||||
@@ -233,8 +232,7 @@ impl<'source> super::ExpressionContext<'source, '_, '_> {
|
||||
if inner.scalar() != Some(goal) {
|
||||
let cast = crate::Expression::As {
|
||||
expr: *expr,
|
||||
kind: goal.kind,
|
||||
convert: Some(goal.width),
|
||||
target: goal,
|
||||
};
|
||||
let expr_span = self.get_expression_span(*expr);
|
||||
*expr = self.append_expression(cast, expr_span)?;
|
||||
|
||||
@@ -3180,30 +3180,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
|
||||
let ty = template_params.ty(self, ctx)?;
|
||||
|
||||
let mut args = ctx.prepare_args(arguments, 1, function_span);
|
||||
let expr = self.expression(args.next()?, ctx)?;
|
||||
let expr = self.expression_for_abstract(args.next()?, ctx)?;
|
||||
args.finish()?;
|
||||
ctx.grow_types(expr)?;
|
||||
|
||||
let element_scalar = match ctx.module.types[ty].inner {
|
||||
ir::TypeInner::Scalar(scalar) => scalar,
|
||||
ir::TypeInner::Vector { scalar, .. } => scalar,
|
||||
_ => {
|
||||
let ty_resolution = resolve!(ctx, expr);
|
||||
return Err(Box::new(Error::BadTypeCast {
|
||||
from_type: ctx.type_resolution_to_string(ty_resolution),
|
||||
span: function_span,
|
||||
to_type: ctx.type_to_string(ty),
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
(
|
||||
ir::Expression::As {
|
||||
expr,
|
||||
kind: element_scalar.kind,
|
||||
convert: None,
|
||||
},
|
||||
MustUse::Yes,
|
||||
)
|
||||
let expr = self.bitcast_operand(function_span, ty, expr, ctx)?;
|
||||
(ir::Expression::Bitcast { expr, ty }, MustUse::Yes)
|
||||
}
|
||||
"coopLoad" | "coopLoadT" => {
|
||||
let row_major = function_name.ends_with("T");
|
||||
@@ -4745,6 +4727,89 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Check that `bitcast<ty>(expr)` is one of the overloads of
|
||||
/// [WGSL's `bitcast`][spec], and return `expr`, concretized if it was abstract.
|
||||
///
|
||||
/// Naga also accepts same-shaped bitcasts between numeric types of the
|
||||
/// same width, such as `i64` and `u64`, or `f16` and `i16`.
|
||||
///
|
||||
/// [spec]: https://www.w3.org/TR/WGSL/#bitcast-builtin
|
||||
fn bitcast_operand(
|
||||
&mut self,
|
||||
span: Span,
|
||||
ty: Handle<ir::Type>,
|
||||
mut expr: Handle<ir::Expression>,
|
||||
ctx: &mut ExpressionContext<'source, '_, '_>,
|
||||
) -> Result<'source, Handle<ir::Expression>> {
|
||||
use ir::{Scalar, ScalarKind as Sk, TypeInner as Ti, VectorSize as Vs};
|
||||
|
||||
let bad_cast = |ctx: &ExpressionContext<'source, '_, '_>, expr| {
|
||||
Box::new(Error::BadTypeCast {
|
||||
from_type: ctx.type_resolution_to_string(&ctx.typifier()[expr]),
|
||||
span,
|
||||
to_type: ctx.type_to_string(ty),
|
||||
})
|
||||
};
|
||||
|
||||
let (to_size, to_scalar) = match ctx.module.types[ty].inner {
|
||||
Ti::Scalar(scalar) => (None, scalar),
|
||||
Ti::Vector { size, scalar } => (Some(size), scalar),
|
||||
_ => return Err(bad_cast(ctx, expr)),
|
||||
};
|
||||
|
||||
let (from_size, mut from_scalar) = match *resolve_inner!(ctx, expr) {
|
||||
Ti::Scalar(scalar) => (None, scalar),
|
||||
Ti::Vector { size, scalar } => (Some(size), scalar),
|
||||
_ => return Err(bad_cast(ctx, expr)),
|
||||
};
|
||||
|
||||
// Pick the overload with the best conversion rank for an abstract operand.
|
||||
if from_scalar.is_abstract() {
|
||||
let same_shape = from_size == to_size;
|
||||
let concrete = match from_scalar.kind {
|
||||
Sk::AbstractInt if same_shape && matches!(to_scalar.kind, Sk::Sint | Sk::Uint) => {
|
||||
to_scalar
|
||||
}
|
||||
Sk::AbstractInt if same_shape && to_scalar == Scalar::F16 => to_scalar,
|
||||
Sk::AbstractInt => Scalar::I32,
|
||||
_ if same_shape && to_scalar.kind == Sk::Float => to_scalar,
|
||||
_ => Scalar::F32,
|
||||
};
|
||||
expr = ctx.try_automatic_conversion_for_leaf_scalar(expr, concrete, span)?;
|
||||
ctx.grow_types(expr)?;
|
||||
from_scalar = concrete;
|
||||
}
|
||||
|
||||
let is_bit_pattern =
|
||||
|scalar: Scalar| matches!(scalar.kind, Sk::Sint | Sk::Uint | Sk::Float);
|
||||
let is_32_bit = |scalar: Scalar| is_bit_pattern(scalar) && scalar.width == 4;
|
||||
let is_f16 = |scalar: Scalar| scalar == Scalar::F16;
|
||||
|
||||
let valid = match (from_size, from_scalar, to_size, to_scalar) {
|
||||
(Some(Vs::Bi), half, None, word) | (None, word, Some(Vs::Bi), half) if is_f16(half) => {
|
||||
is_32_bit(word)
|
||||
}
|
||||
(Some(Vs::Quad), half, Some(Vs::Bi), word)
|
||||
| (Some(Vs::Bi), word, Some(Vs::Quad), half)
|
||||
if is_f16(half) =>
|
||||
{
|
||||
is_32_bit(word)
|
||||
}
|
||||
_ => {
|
||||
from_size == to_size
|
||||
&& from_scalar.width == to_scalar.width
|
||||
&& is_bit_pattern(from_scalar)
|
||||
&& is_bit_pattern(to_scalar)
|
||||
}
|
||||
};
|
||||
|
||||
if valid {
|
||||
Ok(expr)
|
||||
} else {
|
||||
Err(bad_cast(ctx, expr))
|
||||
}
|
||||
}
|
||||
|
||||
fn subgroup_gather_helper(
|
||||
&mut self,
|
||||
span: Span,
|
||||
|
||||
+22
-6
@@ -176,6 +176,7 @@ variants, whose operands (if any) are also constant expressions:
|
||||
- [`Relational`]
|
||||
- [`Math`]
|
||||
- [`As`]
|
||||
- [`Bitcast`]
|
||||
|
||||
A constant expression can be evaluated at module translation time.
|
||||
|
||||
@@ -228,6 +229,7 @@ An override expression can be evaluated at pipeline creation time.
|
||||
[`Relational`]: Expression::Relational
|
||||
[`Math`]: Expression::Math
|
||||
[`As`]: Expression::As
|
||||
[`Bitcast`]: Expression::Bitcast
|
||||
|
||||
[constant expression]: #constant-expressions
|
||||
*/
|
||||
@@ -1835,15 +1837,29 @@ pub enum Expression {
|
||||
arg2: Option<Handle<Expression>>,
|
||||
arg3: Option<Handle<Expression>>,
|
||||
},
|
||||
/// Cast a simple type to another kind.
|
||||
/// Convert the components of a scalar, vector or matrix to another scalar type.
|
||||
///
|
||||
/// The result has the same shape as `expr`, with its scalar type replaced
|
||||
/// by `target`. To reinterpret bits instead, see [`Bitcast`].
|
||||
///
|
||||
/// [`Bitcast`]: Expression::Bitcast
|
||||
As {
|
||||
/// Source expression, which can only be a scalar, a vector or a matrix.
|
||||
expr: Handle<Expression>,
|
||||
/// Scalar type of the result's components.
|
||||
target: Scalar,
|
||||
},
|
||||
/// Reinterpret the bits of a scalar or vector as another scalar or vector type.
|
||||
///
|
||||
/// `ty` and the type of `expr` must both be numeric scalars or vectors with
|
||||
/// the same size in bytes. Components are laid out as in memory, so a
|
||||
/// `vec2<f16>` can be bitcast to a `u32`, whose low bits are the first
|
||||
/// component.
|
||||
Bitcast {
|
||||
/// Source expression, which can only be a scalar or a vector.
|
||||
expr: Handle<Expression>,
|
||||
/// Target scalar kind.
|
||||
kind: ScalarKind,
|
||||
/// If provided, converts to the specified byte width.
|
||||
/// Otherwise, bitcast.
|
||||
convert: Option<Bytes>,
|
||||
/// Type of the result.
|
||||
ty: Handle<Type>,
|
||||
},
|
||||
/// Result of calling another function.
|
||||
CallResult(Handle<Function>),
|
||||
|
||||
@@ -832,7 +832,7 @@ impl ExpressionKindTracker {
|
||||
arg3.map(|arg| self.type_of(arg))
|
||||
.unwrap_or(ExpressionKind::Const),
|
||||
),
|
||||
Expression::As { expr, .. } => self.type_of(expr),
|
||||
Expression::As { expr, .. } | Expression::Bitcast { expr, .. } => self.type_of(expr),
|
||||
Expression::Select {
|
||||
condition,
|
||||
accept,
|
||||
@@ -1313,20 +1313,13 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
|
||||
self.math(arg, arg1, arg2, arg3, fun, span)
|
||||
}
|
||||
Expression::As {
|
||||
convert,
|
||||
expr,
|
||||
kind,
|
||||
} => {
|
||||
Expression::As { expr, target } => {
|
||||
let expr = self.check_and_get(expr)?;
|
||||
|
||||
match convert {
|
||||
Some(width) => self.cast(expr, crate::Scalar { kind, width }, span),
|
||||
None => Err(ConstantEvaluatorError::NotImplemented(
|
||||
"bitcast built-in function".into(),
|
||||
)),
|
||||
}
|
||||
self.cast(expr, target, span)
|
||||
}
|
||||
Expression::Bitcast { .. } => Err(ConstantEvaluatorError::NotImplemented(
|
||||
"bitcast built-in function".into(),
|
||||
)),
|
||||
Expression::Select {
|
||||
reject,
|
||||
accept,
|
||||
@@ -4483,8 +4476,8 @@ mod tests {
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use crate::{
|
||||
Arena, BinaryOperator, Constant, Expression, FastHashMap, Handle, Literal, ScalarKind,
|
||||
Type, TypeInner, UnaryOperator, UniqueArena, VectorSize,
|
||||
Arena, BinaryOperator, Constant, Expression, FastHashMap, Handle, Literal, Type, TypeInner,
|
||||
UnaryOperator, UniqueArena, VectorSize,
|
||||
};
|
||||
|
||||
use super::{Behavior, ConstantEvaluator, ExpressionKindTracker, WgslRestrictions};
|
||||
@@ -4910,8 +4903,7 @@ mod tests {
|
||||
|
||||
let root = Expression::As {
|
||||
expr,
|
||||
kind: ScalarKind::Bool,
|
||||
convert: Some(crate::BOOL_WIDTH),
|
||||
target: crate::Scalar::BOOL,
|
||||
};
|
||||
|
||||
let expression_kind_tracker = &mut ExpressionKindTracker::from_arena(&global_expressions);
|
||||
|
||||
@@ -730,47 +730,24 @@ impl<'a> ResolveContext<'a> {
|
||||
|
||||
rule.conclusion.into_resolution(self.special_types)?
|
||||
}
|
||||
crate::Expression::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => match *past(expr)?.inner_with(types) {
|
||||
Ti::Scalar(crate::Scalar { width, .. }) => {
|
||||
TypeResolution::Value(Ti::Scalar(crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(width),
|
||||
}))
|
||||
}
|
||||
Ti::Vector {
|
||||
crate::Expression::As { expr, target } => match *past(expr)?.inner_with(types) {
|
||||
Ti::Scalar(_) => TypeResolution::Value(Ti::Scalar(target)),
|
||||
Ti::Vector { size, .. } => TypeResolution::Value(Ti::Vector {
|
||||
size,
|
||||
scalar: crate::Scalar { kind: _, width },
|
||||
} => TypeResolution::Value(Ti::Vector {
|
||||
size,
|
||||
scalar: crate::Scalar {
|
||||
kind,
|
||||
width: convert.unwrap_or(width),
|
||||
},
|
||||
scalar: target,
|
||||
}),
|
||||
Ti::Matrix {
|
||||
Ti::Matrix { columns, rows, .. } => TypeResolution::Value(Ti::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
mut scalar,
|
||||
} => {
|
||||
if let Some(width) = convert {
|
||||
scalar.width = width;
|
||||
}
|
||||
TypeResolution::Value(Ti::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
scalar,
|
||||
})
|
||||
}
|
||||
scalar: target,
|
||||
}),
|
||||
ref other => {
|
||||
return Err(ResolveError::IncompatibleOperands(format!(
|
||||
"{other:?} as {kind:?}"
|
||||
"{other:?} as {target:?}"
|
||||
)))
|
||||
}
|
||||
},
|
||||
crate::Expression::Bitcast { ty, .. } => TypeResolution::Handle(ty),
|
||||
crate::Expression::CallResult(function) => {
|
||||
let result = self.functions[function]
|
||||
.result
|
||||
|
||||
@@ -804,7 +804,7 @@ impl FunctionInfo {
|
||||
requirements: UniformityRequirements::empty(),
|
||||
}
|
||||
}
|
||||
E::As { expr, .. } => Uniformity {
|
||||
E::As { expr, .. } | E::Bitcast { expr, .. } => Uniformity {
|
||||
non_uniform_result: self.add_ref(expr),
|
||||
requirements: UniformityRequirements::empty(),
|
||||
},
|
||||
|
||||
@@ -138,6 +138,8 @@ pub enum ExpressionError {
|
||||
InvalidSampleClampCoordinateToEdge(alloc::string::String),
|
||||
#[error("Unable to cast")]
|
||||
InvalidCastArgument,
|
||||
#[error("Unable to bitcast the argument to {0:?}")]
|
||||
InvalidBitcast(Handle<crate::Type>),
|
||||
#[error("Invalid argument count for {0:?}")]
|
||||
WrongArgumentCount(crate::MathFunction),
|
||||
#[error("Argument [{1}] to {0:?} as expression {2:?} has an invalid type.")]
|
||||
@@ -1299,27 +1301,38 @@ impl super::Validator {
|
||||
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::As {
|
||||
expr,
|
||||
kind,
|
||||
convert,
|
||||
} => {
|
||||
let mut base_scalar = match resolver[expr] {
|
||||
crate::TypeInner::Scalar(scalar) | crate::TypeInner::Vector { scalar, .. } => {
|
||||
scalar
|
||||
}
|
||||
crate::TypeInner::Matrix { scalar, .. } => scalar,
|
||||
E::As { expr, target } => {
|
||||
match resolver[expr] {
|
||||
Ti::Scalar(_) | Ti::Vector { .. } => {}
|
||||
Ti::Matrix { .. } if target.kind == Sk::Float => {}
|
||||
_ => return Err(ExpressionError::InvalidCastArgument),
|
||||
};
|
||||
base_scalar.kind = kind;
|
||||
if let Some(width) = convert {
|
||||
base_scalar.width = width;
|
||||
}
|
||||
if self.check_width(base_scalar).is_err() {
|
||||
if self.check_width(target).is_err() {
|
||||
return Err(ExpressionError::InvalidCastArgument);
|
||||
}
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::Bitcast { expr, ty } => {
|
||||
let is_bit_pattern = |scalar: Sc| {
|
||||
matches!(scalar.kind, Sk::Sint | Sk::Uint | Sk::Float)
|
||||
&& self.check_width(scalar).is_ok()
|
||||
};
|
||||
let byte_size = |inner: &Ti| match *inner {
|
||||
Ti::Scalar(scalar) if is_bit_pattern(scalar) => Some(scalar.width as u32),
|
||||
Ti::Vector { size, scalar } if is_bit_pattern(scalar) => {
|
||||
Some(size as u32 * scalar.width as u32)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
match (
|
||||
byte_size(&resolver[expr]),
|
||||
byte_size(&module.types[ty].inner),
|
||||
) {
|
||||
(Some(source), Some(target)) if source == target => {}
|
||||
_ => return Err(ExpressionError::InvalidBitcast(ty)),
|
||||
}
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::CallResult(function) => mod_info.functions[function.index()].available_stages,
|
||||
E::AtomicResult { .. } => {
|
||||
// These expressions are validated when we check the `Atomic` statement
|
||||
|
||||
@@ -822,6 +822,7 @@ impl super::Validator {
|
||||
| Ex::Relational { .. }
|
||||
| Ex::Math { .. }
|
||||
| Ex::As { .. }
|
||||
| Ex::Bitcast { .. }
|
||||
| Ex::ArrayLength(_)
|
||||
| Ex::RayQueryGetIntersection { .. }
|
||||
| Ex::RayQueryVertexPositions { .. }
|
||||
|
||||
@@ -482,6 +482,10 @@ impl super::Validator {
|
||||
handle.check_dep_iter(components.iter().copied())?;
|
||||
Some(ty)
|
||||
}
|
||||
crate::Expression::Bitcast { expr, ty } => {
|
||||
handle.check_dep(expr)?;
|
||||
Some(ty)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
Ok(max_type)
|
||||
@@ -638,11 +642,14 @@ impl super::Validator {
|
||||
}
|
||||
crate::Expression::As {
|
||||
expr: input,
|
||||
kind: _,
|
||||
convert: _,
|
||||
target: _,
|
||||
} => {
|
||||
handle.check_dep(input)?;
|
||||
}
|
||||
crate::Expression::Bitcast { expr: input, ty } => {
|
||||
validate_type(ty)?;
|
||||
handle.check_dep(input)?;
|
||||
}
|
||||
crate::Expression::CallResult(function) => {
|
||||
Self::validate_function_handle(function, functions)?;
|
||||
if let Some(handle) = current_function {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
OpCapability Shader
|
||||
OpCapability Float16
|
||||
OpCapability StorageBuffer16BitAccess
|
||||
OpExtension "SPV_KHR_16bit_storage"
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %main "main"
|
||||
OpName %B "B"
|
||||
OpMemberName %B 0 "a"
|
||||
OpMemberName %B 1 "h2"
|
||||
OpMemberName %B 2 "h4"
|
||||
OpMemberName %B 3 "u2"
|
||||
OpMemberName %B 4 "i"
|
||||
OpMemberName %B 5 "f"
|
||||
OpName %buf "buf"
|
||||
OpMemberDecorate %B 0 Offset 0
|
||||
OpMemberDecorate %B 1 Offset 4
|
||||
OpMemberDecorate %B 2 Offset 8
|
||||
OpMemberDecorate %B 3 Offset 16
|
||||
OpMemberDecorate %B 4 Offset 24
|
||||
OpMemberDecorate %B 5 Offset 28
|
||||
OpDecorate %B Block
|
||||
OpDecorate %buf DescriptorSet 0
|
||||
OpDecorate %buf Binding 0
|
||||
%void = OpTypeVoid
|
||||
%fn = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%int = OpTypeInt 32 1
|
||||
%float = OpTypeFloat 32
|
||||
%half = OpTypeFloat 16
|
||||
%v2h = OpTypeVector %half 2
|
||||
%v4h = OpTypeVector %half 4
|
||||
%v2u = OpTypeVector %uint 2
|
||||
%B = OpTypeStruct %uint %v2h %v4h %v2u %int %float
|
||||
%pB = OpTypePointer StorageBuffer %B
|
||||
%buf = OpVariable %pB StorageBuffer
|
||||
%c0 = OpConstant %int 0
|
||||
%c1 = OpConstant %int 1
|
||||
%c2 = OpConstant %int 2
|
||||
%c3 = OpConstant %int 3
|
||||
%c4 = OpConstant %int 4
|
||||
%c5 = OpConstant %int 5
|
||||
%p_u = OpTypePointer StorageBuffer %uint
|
||||
%p_v2h = OpTypePointer StorageBuffer %v2h
|
||||
%p_v4h = OpTypePointer StorageBuffer %v4h
|
||||
%p_v2u = OpTypePointer StorageBuffer %v2u
|
||||
%p_i = OpTypePointer StorageBuffer %int
|
||||
%p_f = OpTypePointer StorageBuffer %float
|
||||
%main = OpFunction %void None %fn
|
||||
%entry = OpLabel
|
||||
%a_ptr = OpAccessChain %p_u %buf %c0
|
||||
%h2_ptr = OpAccessChain %p_v2h %buf %c1
|
||||
%h4_ptr = OpAccessChain %p_v4h %buf %c2
|
||||
%u2_ptr = OpAccessChain %p_v2u %buf %c3
|
||||
%i_ptr = OpAccessChain %p_i %buf %c4
|
||||
%f_ptr = OpAccessChain %p_f %buf %c5
|
||||
%a = OpLoad %uint %a_ptr
|
||||
%h2 = OpLoad %v2h %h2_ptr
|
||||
%h4 = OpLoad %v4h %h4_ptr
|
||||
%r1 = OpBitcast %v2h %a
|
||||
OpStore %h2_ptr %r1
|
||||
%r2 = OpBitcast %uint %h2
|
||||
OpStore %a_ptr %r2
|
||||
%r3 = OpBitcast %v2u %h4
|
||||
OpStore %u2_ptr %r3
|
||||
%r4 = OpBitcast %int %a
|
||||
OpStore %i_ptr %r4
|
||||
%r5 = OpBitcast %float %a
|
||||
OpStore %f_ptr %r5
|
||||
%u2 = OpLoad %v2u %u2_ptr
|
||||
%r6 = OpBitcast %v4h %u2
|
||||
OpStore %h4_ptr %r6
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1 @@
|
||||
capabilities = "SHADER_FLOAT16"
|
||||
@@ -0,0 +1,52 @@
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpMemberDecorate %B 0 Offset 0
|
||||
OpMemberDecorate %B 1 Offset 4
|
||||
OpMemberDecorate %B 2 Offset 8
|
||||
OpMemberDecorate %B 3 Offset 12
|
||||
OpDecorate %B BufferBlock
|
||||
OpDecorate %buf DescriptorSet 0
|
||||
OpDecorate %buf Binding 0
|
||||
%void = OpTypeVoid
|
||||
%fn = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%int = OpTypeInt 32 1
|
||||
%bool = OpTypeBool
|
||||
%B = OpTypeStruct %uint %int %uint %int
|
||||
%pB = OpTypePointer Uniform %B
|
||||
%buf = OpVariable %pB Uniform
|
||||
%c0 = OpConstant %int 0
|
||||
%c1 = OpConstant %int 1
|
||||
%c2 = OpConstant %int 2
|
||||
%c3 = OpConstant %int 3
|
||||
%u3 = OpConstant %uint 3
|
||||
%p_u = OpTypePointer Uniform %uint
|
||||
%p_i = OpTypePointer Uniform %int
|
||||
%main = OpFunction %void None %fn
|
||||
%entry = OpLabel
|
||||
%pa = OpAccessChain %p_u %buf %c0
|
||||
%pb = OpAccessChain %p_i %buf %c1
|
||||
%pc = OpAccessChain %p_u %buf %c2
|
||||
%pd = OpAccessChain %p_i %buf %c3
|
||||
%a = OpLoad %uint %pa
|
||||
%b = OpLoad %int %pb
|
||||
%c = OpLoad %uint %pc
|
||||
%d = OpLoad %int %pd
|
||||
%neg = OpSNegate %int %a
|
||||
OpStore %pb %neg
|
||||
%add = OpIAdd %uint %a %b
|
||||
OpStore %pc %add
|
||||
%lt = OpULessThan %bool %a %b
|
||||
%shl = OpShiftLeftLogical %uint %c %d
|
||||
OpStore %pa %shl
|
||||
%ext = OpBitFieldUExtract %uint %c %b %d
|
||||
OpStore %pa %ext
|
||||
%ins = OpBitFieldInsert %uint %c %a %b %d
|
||||
OpStore %pc %ins
|
||||
OpSelectionMerge %m None
|
||||
OpSwitch %a %m 1 %m
|
||||
%m = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,15 @@
|
||||
# No GLSL support for f16
|
||||
targets = "SPIRV | METAL | HLSL | WGSL"
|
||||
capabilities = "SHADER_FLOAT16"
|
||||
|
||||
[spv]
|
||||
version = [1, 0]
|
||||
|
||||
[hlsl]
|
||||
shader_model = "V6_2"
|
||||
special_constants_binding = { space = 1, register = 0 }
|
||||
immediates_target = { space = 0, register = 0 }
|
||||
|
||||
lang_version = [1, 0]
|
||||
per_entry_point_map = {}
|
||||
zero_initialize_workgroup_memory = true
|
||||
@@ -0,0 +1,41 @@
|
||||
enable f16;
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var h2 = vec2<f16>(1.0h, 2.0h);
|
||||
var h4 = vec4<f16>(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
|
||||
var i1 = 0i;
|
||||
var u1 = 0u;
|
||||
var f1 = 0.0f;
|
||||
var i2 = vec2<i32>(0);
|
||||
var u2 = vec2<u32>(0u);
|
||||
var f2 = vec2<f32>(0.0);
|
||||
|
||||
i1 = bitcast<i32>(h2);
|
||||
u1 = bitcast<u32>(h2);
|
||||
f1 = bitcast<f32>(h2);
|
||||
|
||||
i2 = bitcast<vec2<i32>>(h4);
|
||||
u2 = bitcast<vec2<u32>>(h4);
|
||||
f2 = bitcast<vec2<f32>>(h4);
|
||||
|
||||
h2 = bitcast<vec2<f16>>(i1);
|
||||
h2 = bitcast<vec2<f16>>(u1);
|
||||
h2 = bitcast<vec2<f16>>(f1);
|
||||
|
||||
h4 = bitcast<vec4<f16>>(i2);
|
||||
h4 = bitcast<vec4<f16>>(u2);
|
||||
h4 = bitcast<vec4<f16>>(f2);
|
||||
|
||||
h2 = bitcast<vec2<f16>>(h2);
|
||||
u1 = bitcast<u32>(u1);
|
||||
|
||||
u1 = bitcast<u32>(4294967295);
|
||||
f1 = bitcast<f32>(1);
|
||||
i1 = bitcast<i32>(1.0);
|
||||
h2 = bitcast<vec2<f16>>(1);
|
||||
h2 = bitcast<vec2<f16>>(vec2(1, 2));
|
||||
h4 = bitcast<vec4<f16>>(vec2(1, 2));
|
||||
u2 = bitcast<vec2<u32>>(vec2(4294967295, 1));
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# No GLSL support for f16
|
||||
targets = "SPIRV | METAL | HLSL | WGSL"
|
||||
capabilities = "SHADER_FLOAT16 | SHADER_INT16"
|
||||
|
||||
[spv]
|
||||
version = [1, 0]
|
||||
|
||||
[hlsl]
|
||||
shader_model = "V6_2"
|
||||
special_constants_binding = { space = 1, register = 0 }
|
||||
immediates_target = { space = 0, register = 0 }
|
||||
zero_initialize_workgroup_memory = true
|
||||
@@ -0,0 +1,18 @@
|
||||
enable f16;
|
||||
enable wgpu_int16;
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var h = 1.0h;
|
||||
var i = i16(1);
|
||||
var u = u16(2);
|
||||
var h4 = vec4<f16>(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
var u4 = vec4<u16>(u16(1), u16(2), u16(3), u16(4));
|
||||
|
||||
i = bitcast<i16>(h);
|
||||
u = bitcast<u16>(h);
|
||||
h = bitcast<f16>(i);
|
||||
h = bitcast<f16>(u);
|
||||
u4 = bitcast<vec4<u16>>(h4);
|
||||
h4 = bitcast<vec4<f16>>(u4);
|
||||
}
|
||||
@@ -484,6 +484,140 @@ fn builtin_sign_unsigned_arg() {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitcast_operand_and_result_types() {
|
||||
use naga::{Type, TypeInner, VectorSize};
|
||||
|
||||
fn variant(src: TypeInner, dst: TypeInner) -> Result<ModuleInfo, Box<valid::ValidationError>> {
|
||||
let span = naga::Span::default();
|
||||
let mut module = Module::default();
|
||||
let ty_src = module.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: src,
|
||||
},
|
||||
span,
|
||||
);
|
||||
let ty_dst = module.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: dst,
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
let mut fun = Function {
|
||||
result: Some(naga::ir::FunctionResult {
|
||||
ty: ty_dst,
|
||||
binding: None,
|
||||
}),
|
||||
..Function::default()
|
||||
};
|
||||
let ex_zero = fun.expressions.append(Expression::ZeroValue(ty_src), span);
|
||||
let ex_bitcast = fun.expressions.append(
|
||||
Expression::Bitcast {
|
||||
expr: ex_zero,
|
||||
ty: ty_dst,
|
||||
},
|
||||
span,
|
||||
);
|
||||
fun.body.push(
|
||||
naga::Statement::Emit(naga::Range::new_from_bounds(ex_bitcast, ex_bitcast)),
|
||||
span,
|
||||
);
|
||||
fun.body.push(
|
||||
naga::Statement::Return {
|
||||
value: Some(ex_bitcast),
|
||||
},
|
||||
span,
|
||||
);
|
||||
module.functions.append(fun, span);
|
||||
|
||||
valid::Validator::new(ValidationFlags::default(), Capabilities::all())
|
||||
.validate(&module)
|
||||
.map_err(|err| Box::new(err.into_inner()))
|
||||
}
|
||||
|
||||
let vector = |size, scalar| TypeInner::Vector { size, scalar };
|
||||
let scalar = TypeInner::Scalar;
|
||||
|
||||
for (src, dst) in [
|
||||
(scalar(Scalar::U32), scalar(Scalar::F32)),
|
||||
(scalar(Scalar::F32), scalar(Scalar::I32)),
|
||||
(scalar(Scalar::U64), scalar(Scalar::I64)),
|
||||
(
|
||||
vector(VectorSize::Tri, Scalar::U32),
|
||||
vector(VectorSize::Tri, Scalar::F32),
|
||||
),
|
||||
(vector(VectorSize::Bi, Scalar::F16), scalar(Scalar::U32)),
|
||||
(scalar(Scalar::I32), vector(VectorSize::Bi, Scalar::F16)),
|
||||
(
|
||||
vector(VectorSize::Quad, Scalar::F16),
|
||||
vector(VectorSize::Bi, Scalar::F32),
|
||||
),
|
||||
(
|
||||
vector(VectorSize::Bi, Scalar::U32),
|
||||
vector(VectorSize::Quad, Scalar::F16),
|
||||
),
|
||||
(scalar(Scalar::F16), scalar(Scalar::I16)),
|
||||
(scalar(Scalar::U16), scalar(Scalar::F16)),
|
||||
(
|
||||
vector(VectorSize::Bi, Scalar::F16),
|
||||
vector(VectorSize::Bi, Scalar::U16),
|
||||
),
|
||||
(
|
||||
vector(VectorSize::Tri, Scalar::I16),
|
||||
vector(VectorSize::Tri, Scalar::F16),
|
||||
),
|
||||
(scalar(Scalar::U32), scalar(Scalar::U32)),
|
||||
] {
|
||||
variant(src.clone(), dst.clone())
|
||||
.unwrap_or_else(|err| panic!("bitcast from {src:?} to {dst:?} should be valid: {err}"));
|
||||
}
|
||||
|
||||
for (src, dst) in [
|
||||
(scalar(Scalar::U32), scalar(Scalar::BOOL)),
|
||||
(scalar(Scalar::BOOL), scalar(Scalar::U32)),
|
||||
(scalar(Scalar::U32), scalar(Scalar::U64)),
|
||||
(
|
||||
vector(VectorSize::Bi, Scalar::U32),
|
||||
vector(VectorSize::Tri, Scalar::U32),
|
||||
),
|
||||
(vector(VectorSize::Tri, Scalar::F16), scalar(Scalar::U32)),
|
||||
(vector(VectorSize::Bi, Scalar::F16), scalar(Scalar::U64)),
|
||||
(scalar(Scalar::F16), scalar(Scalar::I32)),
|
||||
(
|
||||
vector(VectorSize::Bi, Scalar::I16),
|
||||
vector(VectorSize::Quad, Scalar::F16),
|
||||
),
|
||||
(
|
||||
TypeInner::Matrix {
|
||||
columns: VectorSize::Bi,
|
||||
rows: VectorSize::Bi,
|
||||
scalar: Scalar::F32,
|
||||
},
|
||||
vector(VectorSize::Quad, Scalar::F32),
|
||||
),
|
||||
] {
|
||||
let err = variant(src.clone(), dst.clone()).expect_err(&format!(
|
||||
"bitcast from {src:?} to {dst:?} should be invalid"
|
||||
));
|
||||
assert!(
|
||||
matches!(
|
||||
*err,
|
||||
valid::ValidationError::Function {
|
||||
source: valid::FunctionError::Expression {
|
||||
source: valid::ExpressionError::InvalidBitcast(_),
|
||||
..
|
||||
},
|
||||
..
|
||||
}
|
||||
),
|
||||
"unexpected error for bitcast from {src:?} to {dst:?}: {err:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incompatible_interpolation_and_sampling_types() {
|
||||
use dummy_interpolation_shader::DummyInterpolationShader;
|
||||
|
||||
@@ -199,6 +199,128 @@ fn bad_type_cast() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitcast_overloads() {
|
||||
let bitcast = |source: &str, dest: &str| {
|
||||
format!("enable f16; fn f(x: {source}) -> {dest} {{ return bitcast<{dest}>(x); }}")
|
||||
};
|
||||
|
||||
for (source, dest) in [
|
||||
("i32", "u32"),
|
||||
("u32", "f32"),
|
||||
("vec3<f32>", "vec3<i32>"),
|
||||
("f16", "f16"),
|
||||
("vec2<f16>", "vec2<f16>"),
|
||||
("vec2<f16>", "i32"),
|
||||
("vec2<f16>", "u32"),
|
||||
("vec2<f16>", "f32"),
|
||||
("vec4<f16>", "vec2<i32>"),
|
||||
("vec4<f16>", "vec2<u32>"),
|
||||
("vec4<f16>", "vec2<f32>"),
|
||||
("vec2<i32>", "vec4<f16>"),
|
||||
("vec2<u32>", "vec4<f16>"),
|
||||
("vec2<f32>", "vec4<f16>"),
|
||||
("i32", "vec2<f16>"),
|
||||
("u32", "vec2<f16>"),
|
||||
("f32", "vec2<f16>"),
|
||||
] {
|
||||
check_success(&bitcast(source, dest));
|
||||
}
|
||||
|
||||
for (source, dest) in [
|
||||
("bool", "u32"),
|
||||
("u32", "bool"),
|
||||
("f16", "u32"),
|
||||
("u32", "f16"),
|
||||
("vec3<f16>", "vec3<u32>"),
|
||||
("vec2<f16>", "vec2<u32>"),
|
||||
("vec2<f16>", "vec4<f16>"),
|
||||
("vec4<f16>", "u32"),
|
||||
("vec2<u32>", "vec3<u32>"),
|
||||
("vec3<u32>", "vec4<f16>"),
|
||||
("f32", "vec2<f32>"),
|
||||
("array<u32, 2>", "u32"),
|
||||
("u32", "array<u32, 1>"),
|
||||
] {
|
||||
check_error_matches(&bitcast(source, dest), "cannot cast");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitcast_int16() {
|
||||
let bitcast = |source: &str, dest: &str| {
|
||||
format!(
|
||||
"enable f16; enable wgpu_int16; \
|
||||
fn f(x: {source}) -> {dest} {{ return bitcast<{dest}>(x); }}"
|
||||
)
|
||||
};
|
||||
|
||||
for (source, dest) in [
|
||||
("f16", "i16"),
|
||||
("f16", "u16"),
|
||||
("i16", "f16"),
|
||||
("u16", "f16"),
|
||||
("i16", "u16"),
|
||||
("vec2<f16>", "vec2<i16>"),
|
||||
("vec3<f16>", "vec3<u16>"),
|
||||
("vec4<i16>", "vec4<f16>"),
|
||||
("vec4<u16>", "vec4<f16>"),
|
||||
] {
|
||||
no_validation_error(
|
||||
&bitcast(source, dest),
|
||||
Capabilities::SHADER_FLOAT16 | Capabilities::SHADER_INT16,
|
||||
);
|
||||
}
|
||||
|
||||
for (source, dest) in [
|
||||
("f16", "i32"),
|
||||
("i16", "f32"),
|
||||
("i16", "bool"),
|
||||
("vec2<f16>", "i16"),
|
||||
("vec2<i16>", "vec3<f16>"),
|
||||
("vec2<i16>", "vec4<f16>"),
|
||||
] {
|
||||
check_error_matches(&bitcast(source, dest), "cannot cast");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitcast_abstract_operand() {
|
||||
for (value, dest) in [
|
||||
("4294967295", "u32"),
|
||||
("4294967295", "vec2<u32>"),
|
||||
("1", "i32"),
|
||||
("1", "f32"),
|
||||
("1.0", "f32"),
|
||||
("1.0", "i32"),
|
||||
("1.0", "u32"),
|
||||
] {
|
||||
let dest_value = if dest.starts_with("vec") {
|
||||
format!("{dest}({value})")
|
||||
} else {
|
||||
value.to_string()
|
||||
};
|
||||
check_success(&format!(
|
||||
"fn f() -> {dest} {{ return bitcast<{dest}>({dest_value}); }}"
|
||||
));
|
||||
}
|
||||
|
||||
check_success("enable f16; fn f() -> vec2<f16> { return bitcast<vec2<f16>>(1); }");
|
||||
check_success("enable f16; fn f() -> vec2<f16> { return bitcast<vec2<f16>>(1.0); }");
|
||||
check_success("enable f16; fn f() -> f16 { return bitcast<f16>(1.0); }");
|
||||
check_success("enable f16; fn f() -> f16 { return bitcast<f16>(1); }");
|
||||
check_success("fn f() -> vec2<u32> { return bitcast<vec2<u32>>(vec2(4294967295, 1)); }");
|
||||
check_success("fn f() -> vec2<f32> { return bitcast<vec2<f32>>(vec2(1, 2)); }");
|
||||
check_success("fn f() -> vec2<i32> { return bitcast<vec2<i32>>(vec2(1.0, 2.0)); }");
|
||||
check_success("enable f16; fn f() -> vec2<f16> { return bitcast<vec2<f16>>(vec2(1, 2)); }");
|
||||
check_success("enable f16; fn f() -> vec2<f16> { return bitcast<vec2<f16>>(vec2(1.0, 2.0)); }");
|
||||
check_success("enable f16; fn f() -> vec4<f16> { return bitcast<vec4<f16>>(vec2(1, 2)); }");
|
||||
check_error_matches(
|
||||
"fn f() -> u32 { return bitcast<u32>(4294967296); }",
|
||||
"cannot",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cross_vec2() {
|
||||
check(
|
||||
|
||||
@@ -272,10 +272,7 @@
|
||||
),
|
||||
ref_count: 1,
|
||||
assignable_global: None,
|
||||
ty: Value(Scalar((
|
||||
kind: Sint,
|
||||
width: 4,
|
||||
))),
|
||||
ty: Handle(6),
|
||||
),
|
||||
(
|
||||
uniformity: (
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
struct NagaConstants {
|
||||
int first_vertex;
|
||||
int first_instance;
|
||||
uint other;
|
||||
};
|
||||
ConstantBuffer<NagaConstants> _NagaConstants: register(b0, space1);
|
||||
|
||||
int naga_bitcast_half2_to_int(half2 value) {
|
||||
uint16_t2 bits = asuint16(value);
|
||||
return asint((uint(bits.x) | (uint(bits.y) << 16)));
|
||||
}
|
||||
|
||||
uint naga_bitcast_half2_to_uint(half2 value) {
|
||||
uint16_t2 bits = asuint16(value);
|
||||
return (uint(bits.x) | (uint(bits.y) << 16));
|
||||
}
|
||||
|
||||
float naga_bitcast_half2_to_float(half2 value) {
|
||||
uint16_t2 bits = asuint16(value);
|
||||
return asfloat((uint(bits.x) | (uint(bits.y) << 16)));
|
||||
}
|
||||
|
||||
int2 naga_bitcast_half4_to_int2(half4 value) {
|
||||
uint16_t4 bits = asuint16(value);
|
||||
return asint(uint2((uint(bits.x) | (uint(bits.y) << 16)), (uint(bits.z) | (uint(bits.w) << 16))));
|
||||
}
|
||||
|
||||
uint2 naga_bitcast_half4_to_uint2(half4 value) {
|
||||
uint16_t4 bits = asuint16(value);
|
||||
return uint2((uint(bits.x) | (uint(bits.y) << 16)), (uint(bits.z) | (uint(bits.w) << 16)));
|
||||
}
|
||||
|
||||
float2 naga_bitcast_half4_to_float2(half4 value) {
|
||||
uint16_t4 bits = asuint16(value);
|
||||
return asfloat(uint2((uint(bits.x) | (uint(bits.y) << 16)), (uint(bits.z) | (uint(bits.w) << 16))));
|
||||
}
|
||||
|
||||
half2 naga_bitcast_int_to_half2(int value) {
|
||||
uint bits = asuint(value);
|
||||
return asfloat16(uint16_t2(uint16_t(bits & 0xFFFFu), uint16_t(bits >> 16)));
|
||||
}
|
||||
|
||||
half2 naga_bitcast_uint_to_half2(uint value) {
|
||||
uint bits = value;
|
||||
return asfloat16(uint16_t2(uint16_t(bits & 0xFFFFu), uint16_t(bits >> 16)));
|
||||
}
|
||||
|
||||
half2 naga_bitcast_float_to_half2(float value) {
|
||||
uint bits = asuint(value);
|
||||
return asfloat16(uint16_t2(uint16_t(bits & 0xFFFFu), uint16_t(bits >> 16)));
|
||||
}
|
||||
|
||||
half4 naga_bitcast_int2_to_half4(int2 value) {
|
||||
uint2 bits = asuint(value);
|
||||
return asfloat16(uint16_t4(uint16_t(bits.x & 0xFFFFu), uint16_t(bits.x >> 16), uint16_t(bits.y & 0xFFFFu), uint16_t(bits.y >> 16)));
|
||||
}
|
||||
|
||||
half4 naga_bitcast_uint2_to_half4(uint2 value) {
|
||||
uint2 bits = value;
|
||||
return asfloat16(uint16_t4(uint16_t(bits.x & 0xFFFFu), uint16_t(bits.x >> 16), uint16_t(bits.y & 0xFFFFu), uint16_t(bits.y >> 16)));
|
||||
}
|
||||
|
||||
half4 naga_bitcast_float2_to_half4(float2 value) {
|
||||
uint2 bits = asuint(value);
|
||||
return asfloat16(uint16_t4(uint16_t(bits.x & 0xFFFFu), uint16_t(bits.x >> 16), uint16_t(bits.y & 0xFFFFu), uint16_t(bits.y >> 16)));
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main()
|
||||
{
|
||||
half2 h2_ = half2(1.0h, 2.0h);
|
||||
half4 h4_ = half4(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
int i1_ = int(0);
|
||||
uint u1_ = 0u;
|
||||
float f1_ = 0.0;
|
||||
int2 i2_ = (int(0)).xx;
|
||||
uint2 u2_ = (0u).xx;
|
||||
float2 f2_ = (0.0).xx;
|
||||
|
||||
half2 _e25 = h2_;
|
||||
i1_ = naga_bitcast_half2_to_int(_e25);
|
||||
half2 _e27 = h2_;
|
||||
u1_ = naga_bitcast_half2_to_uint(_e27);
|
||||
half2 _e29 = h2_;
|
||||
f1_ = naga_bitcast_half2_to_float(_e29);
|
||||
half4 _e31 = h4_;
|
||||
i2_ = naga_bitcast_half4_to_int2(_e31);
|
||||
half4 _e33 = h4_;
|
||||
u2_ = naga_bitcast_half4_to_uint2(_e33);
|
||||
half4 _e35 = h4_;
|
||||
f2_ = naga_bitcast_half4_to_float2(_e35);
|
||||
int _e37 = i1_;
|
||||
h2_ = naga_bitcast_int_to_half2(_e37);
|
||||
uint _e39 = u1_;
|
||||
h2_ = naga_bitcast_uint_to_half2(_e39);
|
||||
float _e41 = f1_;
|
||||
h2_ = naga_bitcast_float_to_half2(_e41);
|
||||
int2 _e43 = i2_;
|
||||
h4_ = naga_bitcast_int2_to_half4(_e43);
|
||||
uint2 _e45 = u2_;
|
||||
h4_ = naga_bitcast_uint2_to_half4(_e45);
|
||||
float2 _e47 = f2_;
|
||||
h4_ = naga_bitcast_float2_to_half4(_e47);
|
||||
half2 _e49 = h2_;
|
||||
h2_ = _e49;
|
||||
uint _e51 = u1_;
|
||||
u1_ = _e51;
|
||||
u1_ = 4294967295u;
|
||||
f1_ = asfloat(int(1));
|
||||
i1_ = asint(1.0);
|
||||
h2_ = naga_bitcast_int_to_half2(int(1));
|
||||
h2_ = half2(1.0h, 2.0h);
|
||||
h4_ = naga_bitcast_int2_to_half4(int2(int(1), int(2)));
|
||||
u2_ = uint2(4294967295u, 1u);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
(
|
||||
vertex:[
|
||||
],
|
||||
fragment:[
|
||||
],
|
||||
compute:[
|
||||
(
|
||||
entry_point:"main",
|
||||
target_profile:"cs_6_2",
|
||||
),
|
||||
],
|
||||
task:[
|
||||
],
|
||||
mesh:[
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
struct NagaConstants {
|
||||
int first_vertex;
|
||||
int first_instance;
|
||||
uint other;
|
||||
};
|
||||
ConstantBuffer<NagaConstants> _NagaConstants: register(b0, space1);
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main()
|
||||
{
|
||||
half h = 1.0h;
|
||||
int16_t i = int16_t(1);
|
||||
uint16_t u = uint16_t(2);
|
||||
half4 h4_ = half4(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
uint16_t4 u4_ = uint16_t4(uint16_t(1), uint16_t(2), uint16_t(3), uint16_t(4));
|
||||
|
||||
half _e18 = h;
|
||||
i = asint16(_e18);
|
||||
half _e20 = h;
|
||||
u = asuint16(_e20);
|
||||
int16_t _e22 = i;
|
||||
h = asfloat16(_e22);
|
||||
uint16_t _e24 = u;
|
||||
h = asfloat16(_e24);
|
||||
half4 _e26 = h4_;
|
||||
u4_ = asuint16(_e26);
|
||||
uint16_t4 _e28 = u4_;
|
||||
h4_ = asfloat16(_e28);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
(
|
||||
vertex:[
|
||||
],
|
||||
fragment:[
|
||||
],
|
||||
compute:[
|
||||
(
|
||||
entry_point:"main",
|
||||
target_profile:"cs_6_2",
|
||||
),
|
||||
],
|
||||
task:[
|
||||
],
|
||||
mesh:[
|
||||
],
|
||||
)
|
||||
@@ -90,16 +90,16 @@ int64_t int64_function(int64_t x)
|
||||
val = (_e44 + (_e47).xxx.z);
|
||||
int64_t _e51 = val;
|
||||
uint64_t _e54 = input_uniform.val_u64_;
|
||||
val = (_e51 + _e54);
|
||||
val = (_e51 + int64_t(_e54));
|
||||
int64_t _e57 = val;
|
||||
uint64_t2 _e60 = input_uniform.val_u64_2_;
|
||||
val = (_e57 + _e60.y);
|
||||
val = (_e57 + int64_t2(_e60).y);
|
||||
int64_t _e64 = val;
|
||||
uint64_t3 _e67 = input_uniform.val_u64_3_;
|
||||
val = (_e64 + _e67.z);
|
||||
val = (_e64 + int64_t3(_e67).z);
|
||||
int64_t _e71 = val;
|
||||
uint64_t4 _e74 = input_uniform.val_u64_4_;
|
||||
val = (_e71 + _e74.w);
|
||||
val = (_e71 + int64_t4(_e74).w);
|
||||
int64_t _e78 = val;
|
||||
val = (_e78 + (-9223372036854775807L - 1L));
|
||||
int64_t _e85 = input_uniform.val_i64_;
|
||||
@@ -183,16 +183,16 @@ uint64_t uint64_function(uint64_t x_1)
|
||||
val_1 = (_e42 + (_e45).xxx.z);
|
||||
uint64_t _e49 = val_1;
|
||||
int64_t _e52 = input_uniform.val_i64_;
|
||||
val_1 = (_e49 + _e52);
|
||||
val_1 = (_e49 + uint64_t(_e52));
|
||||
uint64_t _e55 = val_1;
|
||||
int64_t2 _e58 = input_uniform.val_i64_2_;
|
||||
val_1 = (_e55 + _e58.y);
|
||||
val_1 = (_e55 + uint64_t2(_e58).y);
|
||||
uint64_t _e62 = val_1;
|
||||
int64_t3 _e65 = input_uniform.val_i64_3_;
|
||||
val_1 = (_e62 + _e65.z);
|
||||
val_1 = (_e62 + uint64_t3(_e65).z);
|
||||
uint64_t _e69 = val_1;
|
||||
int64_t4 _e72 = input_uniform.val_i64_4_;
|
||||
val_1 = (_e69 + _e72.w);
|
||||
val_1 = (_e69 + uint64_t4(_e72).w);
|
||||
uint64_t _e80 = input_uniform.val_u64_;
|
||||
uint64_t _e83 = input_storage.Load<uint64_t>(16);
|
||||
output.Store(16, (_e80 + _e83));
|
||||
@@ -240,6 +240,6 @@ void main()
|
||||
{
|
||||
const uint64_t _e3 = uint64_function(67uL);
|
||||
const int64_t _e5 = int64_function(60L);
|
||||
output.Store(224, (_e3 + _e5));
|
||||
output.Store(224, (_e3 + uint64_t(_e5)));
|
||||
return;
|
||||
}
|
||||
@@ -456,15 +456,16 @@
|
||||
base: 19,
|
||||
index: 1,
|
||||
),
|
||||
As(
|
||||
Bitcast(
|
||||
expr: 6,
|
||||
kind: Sint,
|
||||
convert: None,
|
||||
ty: 6,
|
||||
),
|
||||
As(
|
||||
expr: 22,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Compose(
|
||||
ty: 1,
|
||||
@@ -513,8 +514,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 32,
|
||||
kind: Sint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Sint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
ImageSample(
|
||||
image: 1,
|
||||
|
||||
@@ -711,15 +711,16 @@
|
||||
base: 55,
|
||||
index: 1,
|
||||
),
|
||||
As(
|
||||
Bitcast(
|
||||
expr: 42,
|
||||
kind: Sint,
|
||||
convert: None,
|
||||
ty: 8,
|
||||
),
|
||||
As(
|
||||
expr: 58,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Compose(
|
||||
ty: 1,
|
||||
@@ -768,8 +769,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 68,
|
||||
kind: Sint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Sint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
ImageSample(
|
||||
image: 5,
|
||||
|
||||
@@ -2185,8 +2185,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 2,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: NotEqual,
|
||||
@@ -2290,8 +2292,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 10,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: NotEqual,
|
||||
@@ -2475,8 +2479,10 @@
|
||||
CallResult(2),
|
||||
As(
|
||||
expr: 18,
|
||||
kind: Sint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Sint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Literal(I32(3)),
|
||||
Literal(I32(4)),
|
||||
@@ -2518,8 +2524,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 50,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: Multiply,
|
||||
|
||||
@@ -2185,8 +2185,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 2,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: NotEqual,
|
||||
@@ -2290,8 +2292,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 10,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: NotEqual,
|
||||
@@ -2475,8 +2479,10 @@
|
||||
CallResult(2),
|
||||
As(
|
||||
expr: 18,
|
||||
kind: Sint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Sint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Literal(I32(3)),
|
||||
Literal(I32(4)),
|
||||
@@ -2518,8 +2524,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 50,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Binary(
|
||||
op: Multiply,
|
||||
|
||||
@@ -337,8 +337,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 8,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
],
|
||||
named_expressions: {
|
||||
|
||||
@@ -337,8 +337,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 8,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
],
|
||||
named_expressions: {
|
||||
|
||||
@@ -100,8 +100,10 @@
|
||||
Override(0),
|
||||
As(
|
||||
expr: 1,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Literal(U32(1)),
|
||||
AtomicResult(
|
||||
|
||||
@@ -100,8 +100,10 @@
|
||||
Override(0),
|
||||
As(
|
||||
expr: 1,
|
||||
kind: Uint,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Literal(U32(1)),
|
||||
AtomicResult(
|
||||
|
||||
@@ -318,8 +318,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 21,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Swizzle(
|
||||
size: Quad,
|
||||
|
||||
@@ -318,8 +318,10 @@
|
||||
),
|
||||
As(
|
||||
expr: 21,
|
||||
kind: Float,
|
||||
convert: Some(4),
|
||||
target: (
|
||||
kind: Float,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Swizzle(
|
||||
size: Quad,
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// language: metal1.0
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using metal::uint;
|
||||
|
||||
|
||||
kernel void main_(
|
||||
) {
|
||||
metal::half2 h2_ = metal::half2(1.0h, 2.0h);
|
||||
metal::half4 h4_ = metal::half4(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
int i1_ = 0;
|
||||
uint u1_ = 0u;
|
||||
float f1_ = 0.0;
|
||||
metal::int2 i2_ = metal::int2(0);
|
||||
metal::uint2 u2_ = metal::uint2(0u);
|
||||
metal::float2 f2_ = metal::float2(0.0);
|
||||
metal::half2 _e25 = h2_;
|
||||
i1_ = as_type<int>(_e25);
|
||||
metal::half2 _e27 = h2_;
|
||||
u1_ = as_type<uint>(_e27);
|
||||
metal::half2 _e29 = h2_;
|
||||
f1_ = as_type<float>(_e29);
|
||||
metal::half4 _e31 = h4_;
|
||||
i2_ = as_type<metal::int2>(_e31);
|
||||
metal::half4 _e33 = h4_;
|
||||
u2_ = as_type<metal::uint2>(_e33);
|
||||
metal::half4 _e35 = h4_;
|
||||
f2_ = as_type<metal::float2>(_e35);
|
||||
int _e37 = i1_;
|
||||
h2_ = as_type<metal::half2>(_e37);
|
||||
uint _e39 = u1_;
|
||||
h2_ = as_type<metal::half2>(_e39);
|
||||
float _e41 = f1_;
|
||||
h2_ = as_type<metal::half2>(_e41);
|
||||
metal::int2 _e43 = i2_;
|
||||
h4_ = as_type<metal::half4>(_e43);
|
||||
metal::uint2 _e45 = u2_;
|
||||
h4_ = as_type<metal::half4>(_e45);
|
||||
metal::float2 _e47 = f2_;
|
||||
h4_ = as_type<metal::half4>(_e47);
|
||||
metal::half2 _e49 = h2_;
|
||||
h2_ = as_type<metal::half2>(_e49);
|
||||
uint _e51 = u1_;
|
||||
u1_ = as_type<uint>(_e51);
|
||||
u1_ = as_type<uint>(4294967295u);
|
||||
f1_ = as_type<float>(1);
|
||||
i1_ = as_type<int>(1.0);
|
||||
h2_ = as_type<metal::half2>(1);
|
||||
h2_ = as_type<metal::half2>(metal::half2(1.0h, 2.0h));
|
||||
h4_ = as_type<metal::half4>(metal::int2(1, 2));
|
||||
u2_ = as_type<metal::uint2>(metal::uint2(4294967295u, 1u));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// language: metal1.0
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using metal::uint;
|
||||
|
||||
|
||||
kernel void main_(
|
||||
) {
|
||||
half h = 1.0h;
|
||||
short i = static_cast<short>(1);
|
||||
ushort u = static_cast<ushort>(2);
|
||||
metal::half4 h4_ = metal::half4(1.0h, 2.0h, 3.0h, 4.0h);
|
||||
metal::ushort4 u4_ = metal::ushort4(static_cast<ushort>(1), static_cast<ushort>(2), static_cast<ushort>(3), static_cast<ushort>(4));
|
||||
half _e18 = h;
|
||||
i = as_type<short>(_e18);
|
||||
half _e20 = h;
|
||||
u = as_type<ushort>(_e20);
|
||||
short _e22 = i;
|
||||
h = as_type<half>(_e22);
|
||||
ushort _e24 = u;
|
||||
h = as_type<half>(_e24);
|
||||
metal::half4 _e26 = h4_;
|
||||
u4_ = as_type<metal::ushort4>(_e26);
|
||||
metal::ushort4 _e28 = u4_;
|
||||
h4_ = as_type<metal::half4>(_e28);
|
||||
return;
|
||||
}
|
||||
@@ -6,24 +6,24 @@ OpCapability Shader
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %18 "test_atomic_compare_exchange_i32"
|
||||
OpEntryPoint GLCompute %19 "test_atomic_compare_exchange_i32"
|
||||
OpEntryPoint GLCompute %104 "test_atomic_compare_exchange_u32"
|
||||
OpExecutionMode %18 LocalSize 1 1 1
|
||||
OpExecutionMode %19 LocalSize 1 1 1
|
||||
OpExecutionMode %104 LocalSize 1 1 1
|
||||
OpDecorate %5 ArrayStride 4
|
||||
OpDecorate %7 ArrayStride 4
|
||||
OpMemberDecorate %9 0 Offset 0
|
||||
OpMemberDecorate %9 1 Offset 4
|
||||
OpMemberDecorate %10 0 Offset 0
|
||||
OpMemberDecorate %10 1 Offset 4
|
||||
OpDecorate %11 DescriptorSet 0
|
||||
OpDecorate %11 Binding 0
|
||||
OpDecorate %12 Block
|
||||
OpMemberDecorate %12 0 Offset 0
|
||||
OpDecorate %14 DescriptorSet 0
|
||||
OpDecorate %14 Binding 1
|
||||
OpDecorate %15 Block
|
||||
OpMemberDecorate %15 0 Offset 0
|
||||
OpMemberDecorate %11 0 Offset 0
|
||||
OpMemberDecorate %11 1 Offset 4
|
||||
OpDecorate %12 DescriptorSet 0
|
||||
OpDecorate %12 Binding 0
|
||||
OpDecorate %13 Block
|
||||
OpMemberDecorate %13 0 Offset 0
|
||||
OpDecorate %15 DescriptorSet 0
|
||||
OpDecorate %15 Binding 1
|
||||
OpDecorate %16 Block
|
||||
OpMemberDecorate %16 0 Offset 0
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeInt 32 0
|
||||
%4 = OpTypeInt 32 1
|
||||
@@ -31,20 +31,20 @@ OpMemberDecorate %15 0 Offset 0
|
||||
%5 = OpTypeArray %4 %6
|
||||
%7 = OpTypeArray %3 %6
|
||||
%8 = OpTypeBool
|
||||
%9 = OpTypeStruct %4 %8
|
||||
%10 = OpTypeStruct %3 %8
|
||||
%12 = OpTypeStruct %5
|
||||
%13 = OpTypePointer StorageBuffer %12
|
||||
%11 = OpVariable %13 StorageBuffer
|
||||
%15 = OpTypeStruct %7
|
||||
%16 = OpTypePointer StorageBuffer %15
|
||||
%14 = OpVariable %16 StorageBuffer
|
||||
%19 = OpTypeFunction %2
|
||||
%20 = OpTypePointer StorageBuffer %5
|
||||
%21 = OpConstant %3 0
|
||||
%23 = OpConstantFalse %8
|
||||
%24 = OpTypeFloat 32
|
||||
%25 = OpConstant %24 1
|
||||
%9 = OpTypeFloat 32
|
||||
%10 = OpTypeStruct %4 %8
|
||||
%11 = OpTypeStruct %3 %8
|
||||
%13 = OpTypeStruct %5
|
||||
%14 = OpTypePointer StorageBuffer %13
|
||||
%12 = OpVariable %14 StorageBuffer
|
||||
%16 = OpTypeStruct %7
|
||||
%17 = OpTypePointer StorageBuffer %16
|
||||
%15 = OpVariable %17 StorageBuffer
|
||||
%20 = OpTypeFunction %2
|
||||
%21 = OpTypePointer StorageBuffer %5
|
||||
%22 = OpConstant %3 0
|
||||
%24 = OpConstantFalse %8
|
||||
%25 = OpConstant %9 1
|
||||
%26 = OpConstant %3 1
|
||||
%28 = OpTypePointer Function %3
|
||||
%30 = OpTypePointer Function %4
|
||||
@@ -54,7 +54,7 @@ OpMemberDecorate %15 0 Offset 0
|
||||
%40 = OpTypeVector %3 2
|
||||
%41 = OpTypePointer Function %40
|
||||
%42 = OpTypeVector %8 2
|
||||
%43 = OpConstantComposite %40 %21 %21
|
||||
%43 = OpConstantComposite %40 %22 %22
|
||||
%44 = OpConstant %3 4294967295
|
||||
%45 = OpConstantComposite %40 %44 %44
|
||||
%64 = OpTypePointer StorageBuffer %4
|
||||
@@ -63,14 +63,14 @@ OpMemberDecorate %15 0 Offset 0
|
||||
%109 = OpConstantNull %3
|
||||
%111 = OpConstantNull %8
|
||||
%135 = OpTypePointer StorageBuffer %3
|
||||
%18 = OpFunction %2 None %19
|
||||
%17 = OpLabel
|
||||
%27 = OpVariable %28 Function %21
|
||||
%19 = OpFunction %2 None %20
|
||||
%18 = OpLabel
|
||||
%27 = OpVariable %28 Function %22
|
||||
%29 = OpVariable %30 Function %31
|
||||
%32 = OpVariable %33 Function %34
|
||||
%46 = OpVariable %41 Function %45
|
||||
%72 = OpVariable %41 Function %45
|
||||
%22 = OpAccessChain %20 %11 %21
|
||||
%23 = OpAccessChain %21 %12 %22
|
||||
OpBranch %35
|
||||
%35 = OpLabel
|
||||
OpBranch %36
|
||||
@@ -85,8 +85,8 @@ OpSelectionMerge %51 None
|
||||
OpBranchConditional %50 %37 %51
|
||||
%51 = OpLabel
|
||||
%52 = OpCompositeExtract %3 %48 1
|
||||
%53 = OpIEqual %8 %52 %21
|
||||
%54 = OpSelect %3 %53 %26 %21
|
||||
%53 = OpIEqual %8 %52 %22
|
||||
%54 = OpSelect %3 %53 %26 %22
|
||||
%55 = OpCompositeConstruct %40 %54 %26
|
||||
%56 = OpISub %40 %48 %55
|
||||
OpStore %46 %56
|
||||
@@ -102,10 +102,10 @@ OpBranch %37
|
||||
OpBranch %61
|
||||
%61 = OpLabel
|
||||
%63 = OpLoad %3 %27
|
||||
%65 = OpAccessChain %64 %22 %63
|
||||
%66 = OpAtomicLoad %4 %65 %67 %21
|
||||
%65 = OpAccessChain %64 %23 %63
|
||||
%66 = OpAtomicLoad %4 %65 %67 %22
|
||||
OpStore %29 %66
|
||||
OpStore %32 %23
|
||||
OpStore %32 %24
|
||||
OpBranch %68
|
||||
%68 = OpLabel
|
||||
OpLoopMerge %69 %71 None
|
||||
@@ -118,8 +118,8 @@ OpSelectionMerge %77 None
|
||||
OpBranchConditional %76 %69 %77
|
||||
%77 = OpLabel
|
||||
%78 = OpCompositeExtract %3 %74 1
|
||||
%79 = OpIEqual %8 %78 %21
|
||||
%80 = OpSelect %3 %79 %26 %21
|
||||
%79 = OpIEqual %8 %78 %22
|
||||
%80 = OpSelect %3 %79 %26 %22
|
||||
%81 = OpCompositeConstruct %40 %80 %26
|
||||
%82 = OpISub %40 %74 %81
|
||||
OpStore %72 %82
|
||||
@@ -135,15 +135,15 @@ OpBranch %69
|
||||
OpBranch %87
|
||||
%87 = OpLabel
|
||||
%89 = OpLoad %4 %29
|
||||
%90 = OpBitcast %24 %89
|
||||
%91 = OpFAdd %24 %90 %25
|
||||
%90 = OpBitcast %9 %89
|
||||
%91 = OpFAdd %9 %90 %25
|
||||
%92 = OpBitcast %4 %91
|
||||
%93 = OpLoad %3 %27
|
||||
%94 = OpLoad %4 %29
|
||||
%96 = OpAccessChain %64 %22 %93
|
||||
%97 = OpAtomicCompareExchange %4 %96 %67 %21 %21 %92 %94
|
||||
%96 = OpAccessChain %64 %23 %93
|
||||
%97 = OpAtomicCompareExchange %4 %96 %67 %22 %22 %92 %94
|
||||
%98 = OpIEqual %8 %97 %94
|
||||
%95 = OpCompositeConstruct %9 %97 %98
|
||||
%95 = OpCompositeConstruct %10 %97 %98
|
||||
%99 = OpCompositeExtract %4 %95 0
|
||||
OpStore %29 %99
|
||||
%100 = OpCompositeExtract %8 %95 1
|
||||
@@ -165,14 +165,14 @@ OpBranch %36
|
||||
%37 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%104 = OpFunction %2 None %19
|
||||
%104 = OpFunction %2 None %20
|
||||
%103 = OpLabel
|
||||
%107 = OpVariable %28 Function %21
|
||||
%107 = OpVariable %28 Function %22
|
||||
%108 = OpVariable %28 Function %109
|
||||
%110 = OpVariable %33 Function %111
|
||||
%117 = OpVariable %41 Function %45
|
||||
%142 = OpVariable %41 Function %45
|
||||
%106 = OpAccessChain %105 %14 %21
|
||||
%106 = OpAccessChain %105 %15 %22
|
||||
OpBranch %112
|
||||
%112 = OpLabel
|
||||
OpBranch %113
|
||||
@@ -187,8 +187,8 @@ OpSelectionMerge %122 None
|
||||
OpBranchConditional %121 %114 %122
|
||||
%122 = OpLabel
|
||||
%123 = OpCompositeExtract %3 %119 1
|
||||
%124 = OpIEqual %8 %123 %21
|
||||
%125 = OpSelect %3 %124 %26 %21
|
||||
%124 = OpIEqual %8 %123 %22
|
||||
%125 = OpSelect %3 %124 %26 %22
|
||||
%126 = OpCompositeConstruct %40 %125 %26
|
||||
%127 = OpISub %40 %119 %126
|
||||
OpStore %117 %127
|
||||
@@ -205,9 +205,9 @@ OpBranch %132
|
||||
%132 = OpLabel
|
||||
%134 = OpLoad %3 %107
|
||||
%136 = OpAccessChain %135 %106 %134
|
||||
%137 = OpAtomicLoad %3 %136 %67 %21
|
||||
%137 = OpAtomicLoad %3 %136 %67 %22
|
||||
OpStore %108 %137
|
||||
OpStore %110 %23
|
||||
OpStore %110 %24
|
||||
OpBranch %138
|
||||
%138 = OpLabel
|
||||
OpLoopMerge %139 %141 None
|
||||
@@ -220,8 +220,8 @@ OpSelectionMerge %147 None
|
||||
OpBranchConditional %146 %139 %147
|
||||
%147 = OpLabel
|
||||
%148 = OpCompositeExtract %3 %144 1
|
||||
%149 = OpIEqual %8 %148 %21
|
||||
%150 = OpSelect %3 %149 %26 %21
|
||||
%149 = OpIEqual %8 %148 %22
|
||||
%150 = OpSelect %3 %149 %26 %22
|
||||
%151 = OpCompositeConstruct %40 %150 %26
|
||||
%152 = OpISub %40 %144 %151
|
||||
OpStore %142 %152
|
||||
@@ -237,15 +237,15 @@ OpBranch %139
|
||||
OpBranch %157
|
||||
%157 = OpLabel
|
||||
%159 = OpLoad %3 %108
|
||||
%160 = OpBitcast %24 %159
|
||||
%161 = OpFAdd %24 %160 %25
|
||||
%160 = OpBitcast %9 %159
|
||||
%161 = OpFAdd %9 %160 %25
|
||||
%162 = OpBitcast %3 %161
|
||||
%163 = OpLoad %3 %107
|
||||
%164 = OpLoad %3 %108
|
||||
%166 = OpAccessChain %135 %106 %163
|
||||
%167 = OpAtomicCompareExchange %3 %166 %67 %21 %21 %162 %164
|
||||
%167 = OpAtomicCompareExchange %3 %166 %67 %22 %22 %162 %164
|
||||
%168 = OpIEqual %8 %167 %164
|
||||
%165 = OpCompositeConstruct %10 %167 %168
|
||||
%165 = OpCompositeConstruct %11 %167 %168
|
||||
%169 = OpCompositeExtract %3 %165 0
|
||||
OpStore %108 %169
|
||||
%170 = OpCompositeExtract %8 %165 1
|
||||
|
||||
@@ -4,27 +4,27 @@
|
||||
#version 460
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
struct _9
|
||||
struct _10
|
||||
{
|
||||
int _m0;
|
||||
bool _m1;
|
||||
};
|
||||
|
||||
struct _10
|
||||
struct _11
|
||||
{
|
||||
uint _m0;
|
||||
bool _m1;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, std430) buffer _12_11
|
||||
layout(set = 0, binding = 0, std430) buffer _13_12
|
||||
{
|
||||
int _m0[128];
|
||||
} _11;
|
||||
} _12;
|
||||
|
||||
layout(set = 0, binding = 1, std430) buffer _15_14
|
||||
layout(set = 0, binding = 1, std430) buffer _16_15
|
||||
{
|
||||
uint _m0[128];
|
||||
} _14;
|
||||
} _15;
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -44,7 +44,7 @@ void main()
|
||||
{
|
||||
break;
|
||||
}
|
||||
int _66 = atomicAdd(_11._m0[_27], 0);
|
||||
int _66 = atomicAdd(_12._m0[_27], 0);
|
||||
_29 = _66;
|
||||
_32 = false;
|
||||
for (;;)
|
||||
@@ -59,8 +59,8 @@ void main()
|
||||
break;
|
||||
}
|
||||
int _94 = _29;
|
||||
int _97 = atomicCompSwap(_11._m0[_27], _94, floatBitsToInt(intBitsToFloat(_29) + 1.0));
|
||||
_9 _95 = _9(_97, _97 == _94);
|
||||
int _97 = atomicCompSwap(_12._m0[_27], _94, floatBitsToInt(intBitsToFloat(_29) + 1.0));
|
||||
_10 _95 = _10(_97, _97 == _94);
|
||||
_29 = _95._m0;
|
||||
_32 = _95._m1;
|
||||
continue;
|
||||
@@ -77,27 +77,27 @@ void main()
|
||||
#version 460
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
struct _9
|
||||
struct _10
|
||||
{
|
||||
int _m0;
|
||||
bool _m1;
|
||||
};
|
||||
|
||||
struct _10
|
||||
struct _11
|
||||
{
|
||||
uint _m0;
|
||||
bool _m1;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, std430) buffer _12_11
|
||||
layout(set = 0, binding = 0, std430) buffer _13_12
|
||||
{
|
||||
int _m0[128];
|
||||
} _11;
|
||||
} _12;
|
||||
|
||||
layout(set = 0, binding = 1, std430) buffer _15_14
|
||||
layout(set = 0, binding = 1, std430) buffer _16_15
|
||||
{
|
||||
uint _m0[128];
|
||||
} _14;
|
||||
} _15;
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -117,7 +117,7 @@ void main()
|
||||
{
|
||||
break;
|
||||
}
|
||||
uint _137 = atomicAdd(_14._m0[_107], 0u);
|
||||
uint _137 = atomicAdd(_15._m0[_107], 0u);
|
||||
_108 = _137;
|
||||
_110 = false;
|
||||
for (;;)
|
||||
@@ -132,8 +132,8 @@ void main()
|
||||
break;
|
||||
}
|
||||
uint _164 = _108;
|
||||
uint _167 = atomicCompSwap(_14._m0[_107], _164, floatBitsToUint(uintBitsToFloat(_108) + 1.0));
|
||||
_10 _165 = _10(_167, _167 == _164);
|
||||
uint _167 = atomicCompSwap(_15._m0[_107], _164, floatBitsToUint(uintBitsToFloat(_108) + 1.0));
|
||||
_11 _165 = _11(_167, _167 == _164);
|
||||
_108 = _165._m0;
|
||||
_110 = _165._m1;
|
||||
continue;
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
; Bound: 81
|
||||
OpCapability Shader
|
||||
OpCapability Float16
|
||||
OpCapability StorageBuffer16BitAccess
|
||||
OpCapability UniformAndStorageBuffer16BitAccess
|
||||
OpCapability StorageInputOutput16
|
||||
OpExtension "SPV_KHR_16bit_storage"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %13 "main"
|
||||
OpExecutionMode %13 LocalSize 1 1 1
|
||||
%2 = OpTypeVoid
|
||||
%4 = OpTypeFloat 16
|
||||
%3 = OpTypeVector %4 2
|
||||
%5 = OpTypeVector %4 4
|
||||
%6 = OpTypeInt 32 1
|
||||
%7 = OpTypeInt 32 0
|
||||
%8 = OpTypeFloat 32
|
||||
%9 = OpTypeVector %6 2
|
||||
%10 = OpTypeVector %7 2
|
||||
%11 = OpTypeVector %8 2
|
||||
%14 = OpTypeFunction %2
|
||||
%15 = OpConstant %4 0.000000000000000000000000000000000000000021524
|
||||
%16 = OpConstant %4 0.000000000000000000000000000000000000000022959
|
||||
%17 = OpConstantComposite %3 %15 %16
|
||||
%18 = OpConstant %4 0.000000000000000000000000000000000000000023676
|
||||
%19 = OpConstant %4 0.000000000000000000000000000000000000000024394
|
||||
%20 = OpConstantComposite %5 %15 %16 %18 %19
|
||||
%21 = OpConstant %6 0
|
||||
%22 = OpConstant %7 0
|
||||
%23 = OpConstant %8 0
|
||||
%24 = OpConstantComposite %9 %21 %21
|
||||
%25 = OpConstantComposite %10 %22 %22
|
||||
%26 = OpConstantComposite %11 %23 %23
|
||||
%27 = OpConstant %7 4294967295
|
||||
%28 = OpConstant %6 1
|
||||
%29 = OpConstant %8 1
|
||||
%30 = OpConstant %6 2
|
||||
%31 = OpConstantComposite %9 %28 %30
|
||||
%32 = OpConstant %7 1
|
||||
%33 = OpConstantComposite %10 %27 %32
|
||||
%35 = OpTypePointer Function %3
|
||||
%37 = OpTypePointer Function %5
|
||||
%39 = OpTypePointer Function %6
|
||||
%41 = OpTypePointer Function %7
|
||||
%43 = OpTypePointer Function %8
|
||||
%45 = OpTypePointer Function %9
|
||||
%47 = OpTypePointer Function %10
|
||||
%49 = OpTypePointer Function %11
|
||||
%13 = OpFunction %2 None %14
|
||||
%12 = OpLabel
|
||||
%46 = OpVariable %47 Function %25
|
||||
%40 = OpVariable %41 Function %22
|
||||
%34 = OpVariable %35 Function %17
|
||||
%48 = OpVariable %49 Function %26
|
||||
%42 = OpVariable %43 Function %23
|
||||
%36 = OpVariable %37 Function %20
|
||||
%44 = OpVariable %45 Function %24
|
||||
%38 = OpVariable %39 Function %21
|
||||
OpBranch %50
|
||||
%50 = OpLabel
|
||||
%51 = OpLoad %3 %34
|
||||
%52 = OpBitcast %6 %51
|
||||
OpStore %38 %52
|
||||
%53 = OpLoad %3 %34
|
||||
%54 = OpBitcast %7 %53
|
||||
OpStore %40 %54
|
||||
%55 = OpLoad %3 %34
|
||||
%56 = OpBitcast %8 %55
|
||||
OpStore %42 %56
|
||||
%57 = OpLoad %5 %36
|
||||
%58 = OpBitcast %9 %57
|
||||
OpStore %44 %58
|
||||
%59 = OpLoad %5 %36
|
||||
%60 = OpBitcast %10 %59
|
||||
OpStore %46 %60
|
||||
%61 = OpLoad %5 %36
|
||||
%62 = OpBitcast %11 %61
|
||||
OpStore %48 %62
|
||||
%63 = OpLoad %6 %38
|
||||
%64 = OpBitcast %3 %63
|
||||
OpStore %34 %64
|
||||
%65 = OpLoad %7 %40
|
||||
%66 = OpBitcast %3 %65
|
||||
OpStore %34 %66
|
||||
%67 = OpLoad %8 %42
|
||||
%68 = OpBitcast %3 %67
|
||||
OpStore %34 %68
|
||||
%69 = OpLoad %9 %44
|
||||
%70 = OpBitcast %5 %69
|
||||
OpStore %36 %70
|
||||
%71 = OpLoad %10 %46
|
||||
%72 = OpBitcast %5 %71
|
||||
OpStore %36 %72
|
||||
%73 = OpLoad %11 %48
|
||||
%74 = OpBitcast %5 %73
|
||||
OpStore %36 %74
|
||||
%75 = OpLoad %3 %34
|
||||
OpStore %34 %75
|
||||
%76 = OpLoad %7 %40
|
||||
OpStore %40 %76
|
||||
OpStore %40 %27
|
||||
%77 = OpBitcast %8 %28
|
||||
OpStore %42 %77
|
||||
%78 = OpBitcast %6 %29
|
||||
OpStore %38 %78
|
||||
%79 = OpBitcast %3 %28
|
||||
OpStore %34 %79
|
||||
OpStore %34 %17
|
||||
%80 = OpBitcast %5 %31
|
||||
OpStore %36 %80
|
||||
OpStore %46 %33
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,44 @@
|
||||
#version 460
|
||||
#if defined(GL_AMD_gpu_shader_half_float)
|
||||
#extension GL_AMD_gpu_shader_half_float : require
|
||||
#elif defined(GL_EXT_shader_explicit_arithmetic_types_float16)
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
|
||||
#else
|
||||
#error No extension available for FP16.
|
||||
#endif
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
uvec2 _46 = uvec2(0u);
|
||||
uint _40 = 0u;
|
||||
f16vec2 _34 = f16vec2(float16_t(1.0), float16_t(2.0));
|
||||
vec2 _48 = vec2(0.0);
|
||||
float _42 = 0.0;
|
||||
f16vec4 _36 = f16vec4(float16_t(1.0), float16_t(2.0), float16_t(3.0), float16_t(4.0));
|
||||
ivec2 _44 = ivec2(0);
|
||||
int _38 = 0;
|
||||
_38 = (_34);
|
||||
_40 = packFloat2x16(_34);
|
||||
_42 = uintBitsToFloat(packFloat2x16(_34));
|
||||
_44 = (_36);
|
||||
_46 = (_36);
|
||||
_48 = (_36);
|
||||
_34 = (_38);
|
||||
_34 = unpackFloat2x16(_40);
|
||||
_34 = unpackFloat2x16(floatBitsToUint(_42));
|
||||
_36 = (_44);
|
||||
_36 = (_46);
|
||||
_36 = (_48);
|
||||
_34 = _34;
|
||||
_40 = _40;
|
||||
_40 = 4294967295u;
|
||||
_42 = intBitsToFloat(1);
|
||||
_38 = floatBitsToInt(1.0);
|
||||
_34 = (1);
|
||||
_34 = f16vec2(float16_t(1.0), float16_t(2.0));
|
||||
_36 = (ivec2(1, 2));
|
||||
_46 = uvec2(4294967295u, 1u);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
; Bound: 45
|
||||
OpCapability Shader
|
||||
OpCapability Float16
|
||||
OpCapability StorageBuffer16BitAccess
|
||||
OpCapability UniformAndStorageBuffer16BitAccess
|
||||
OpCapability StorageInputOutput16
|
||||
OpCapability Int16
|
||||
OpExtension "SPV_KHR_16bit_storage"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %9 "main"
|
||||
OpExecutionMode %9 LocalSize 1 1 1
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeFloat 16
|
||||
%4 = OpTypeInt 16 1
|
||||
%5 = OpTypeInt 16 0
|
||||
%6 = OpTypeVector %3 4
|
||||
%7 = OpTypeVector %5 4
|
||||
%10 = OpTypeFunction %2
|
||||
%11 = OpConstant %3 0.000000000000000000000000000000000000000021524
|
||||
%12 = OpConstant %4 1
|
||||
%13 = OpConstant %5 2
|
||||
%14 = OpConstant %3 0.000000000000000000000000000000000000000022959
|
||||
%15 = OpConstant %3 0.000000000000000000000000000000000000000023676
|
||||
%16 = OpConstant %3 0.000000000000000000000000000000000000000024394
|
||||
%17 = OpConstantComposite %6 %11 %14 %15 %16
|
||||
%18 = OpConstant %5 1
|
||||
%19 = OpConstant %5 3
|
||||
%20 = OpConstant %5 4
|
||||
%21 = OpConstantComposite %7 %18 %13 %19 %20
|
||||
%23 = OpTypePointer Function %3
|
||||
%25 = OpTypePointer Function %4
|
||||
%27 = OpTypePointer Function %5
|
||||
%29 = OpTypePointer Function %6
|
||||
%31 = OpTypePointer Function %7
|
||||
%9 = OpFunction %2 None %10
|
||||
%8 = OpLabel
|
||||
%30 = OpVariable %31 Function %21
|
||||
%24 = OpVariable %25 Function %12
|
||||
%28 = OpVariable %29 Function %17
|
||||
%22 = OpVariable %23 Function %11
|
||||
%26 = OpVariable %27 Function %13
|
||||
OpBranch %32
|
||||
%32 = OpLabel
|
||||
%33 = OpLoad %3 %22
|
||||
%34 = OpBitcast %4 %33
|
||||
OpStore %24 %34
|
||||
%35 = OpLoad %3 %22
|
||||
%36 = OpBitcast %5 %35
|
||||
OpStore %26 %36
|
||||
%37 = OpLoad %4 %24
|
||||
%38 = OpBitcast %3 %37
|
||||
OpStore %22 %38
|
||||
%39 = OpLoad %5 %26
|
||||
%40 = OpBitcast %3 %39
|
||||
OpStore %22 %40
|
||||
%41 = OpLoad %6 %28
|
||||
%42 = OpBitcast %7 %41
|
||||
OpStore %30 %42
|
||||
%43 = OpLoad %7 %30
|
||||
%44 = OpBitcast %6 %43
|
||||
OpStore %28 %44
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,27 @@
|
||||
#version 460
|
||||
#if defined(GL_AMD_gpu_shader_half_float)
|
||||
#extension GL_AMD_gpu_shader_half_float : require
|
||||
#elif defined(GL_EXT_shader_explicit_arithmetic_types_float16)
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
|
||||
#else
|
||||
#error No extension available for FP16.
|
||||
#endif
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
u16vec4 _30 = u16vec4(1us, 2us, 3us, 4us);
|
||||
int16_t _24 = 1s;
|
||||
f16vec4 _28 = f16vec4(float16_t(1.0), float16_t(2.0), float16_t(3.0), float16_t(4.0));
|
||||
float16_t _22 = float16_t(1.0);
|
||||
uint16_t _26 = 2us;
|
||||
_24 = float16BitsToInt16(_22);
|
||||
_26 = float16BitsToUint16(_22);
|
||||
_22 = int16BitsToFloat16(_24);
|
||||
_22 = uint16BitsToFloat16(_26);
|
||||
_30 = float16BitsToUint16(_28);
|
||||
_28 = uint16BitsToFloat16(_30);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@ struct type_2 {
|
||||
member_1: u32,
|
||||
}
|
||||
|
||||
struct type_3 {
|
||||
struct type_4 {
|
||||
member: u32,
|
||||
}
|
||||
|
||||
struct type_5 {
|
||||
struct type_6 {
|
||||
member: atomic<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> global: type_5;
|
||||
var<storage, read_write> global: type_6;
|
||||
@group(0) @binding(1)
|
||||
var<storage> global_1: type_3;
|
||||
var<storage> global_1: type_4;
|
||||
|
||||
fn function_() {
|
||||
var phi_28_: type_2;
|
||||
|
||||
@@ -3,18 +3,18 @@ struct type_2 {
|
||||
member_1: u32,
|
||||
}
|
||||
|
||||
struct type_3 {
|
||||
struct type_4 {
|
||||
member: u32,
|
||||
}
|
||||
|
||||
struct type_5 {
|
||||
struct type_6 {
|
||||
member: atomic<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> global: type_5;
|
||||
var<storage, read_write> global: type_6;
|
||||
@group(0) @binding(1)
|
||||
var<storage> global_1: type_3;
|
||||
var<storage> global_1: type_4;
|
||||
|
||||
fn function_() {
|
||||
var phi_26_: type_2;
|
||||
|
||||
@@ -3,18 +3,18 @@ struct type_2 {
|
||||
member_1: u32,
|
||||
}
|
||||
|
||||
struct type_3 {
|
||||
struct type_4 {
|
||||
member: u32,
|
||||
}
|
||||
|
||||
struct type_5 {
|
||||
struct type_6 {
|
||||
member: atomic<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> global: type_5;
|
||||
var<storage, read_write> global: type_6;
|
||||
@group(0) @binding(1)
|
||||
var<storage> global_1: type_3;
|
||||
var<storage> global_1: type_4;
|
||||
|
||||
fn function_() {
|
||||
var phi_25_: type_2;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
enable f16;
|
||||
|
||||
struct B {
|
||||
a: u32,
|
||||
h2_: vec2<f16>,
|
||||
h4_: vec4<f16>,
|
||||
u2_: vec2<u32>,
|
||||
i: i32,
|
||||
f: f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> buf: B;
|
||||
|
||||
fn main_1() {
|
||||
let _e7 = buf.a;
|
||||
let _e8 = buf.h2_;
|
||||
let _e9 = buf.h4_;
|
||||
buf.h2_ = bitcast<vec2<f16>>(_e7);
|
||||
buf.a = bitcast<u32>(_e8);
|
||||
buf.u2_ = bitcast<vec2<u32>>(_e9);
|
||||
buf.i = bitcast<i32>(_e7);
|
||||
buf.f = bitcast<f32>(_e7);
|
||||
let _e15 = buf.u2_;
|
||||
buf.h4_ = bitcast<vec4<f16>>(_e15);
|
||||
return;
|
||||
}
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
main_1();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
struct type_2 {
|
||||
member: u32,
|
||||
member_1: i32,
|
||||
member_2: u32,
|
||||
member_3: i32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> global: type_2;
|
||||
|
||||
fn function_() {
|
||||
let _e5 = global.member;
|
||||
let _e6 = global.member_1;
|
||||
let _e7 = global.member_2;
|
||||
let _e8 = global.member_3;
|
||||
global.member_1 = -(i32(_e5));
|
||||
global.member_2 = (_e5 + u32(_e6));
|
||||
global.member = (_e7 << u32(_e8));
|
||||
global.member = extractBits(_e7, u32(_e6), u32(_e8));
|
||||
global.member_2 = insertBits(_e7, _e5, u32(_e6), u32(_e8));
|
||||
switch i32(_e5) {
|
||||
case 1: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
function_();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
enable f16;
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
var h2_: vec2<f16> = vec2<f16>(1h, 2h);
|
||||
var h4_: vec4<f16> = vec4<f16>(1h, 2h, 3h, 4h);
|
||||
var i1_: i32 = 0i;
|
||||
var u1_: u32 = 0u;
|
||||
var f1_: f32 = 0f;
|
||||
var i2_: vec2<i32> = vec2(0i);
|
||||
var u2_: vec2<u32> = vec2(0u);
|
||||
var f2_: vec2<f32> = vec2(0f);
|
||||
|
||||
let _e25 = h2_;
|
||||
i1_ = bitcast<i32>(_e25);
|
||||
let _e27 = h2_;
|
||||
u1_ = bitcast<u32>(_e27);
|
||||
let _e29 = h2_;
|
||||
f1_ = bitcast<f32>(_e29);
|
||||
let _e31 = h4_;
|
||||
i2_ = bitcast<vec2<i32>>(_e31);
|
||||
let _e33 = h4_;
|
||||
u2_ = bitcast<vec2<u32>>(_e33);
|
||||
let _e35 = h4_;
|
||||
f2_ = bitcast<vec2<f32>>(_e35);
|
||||
let _e37 = i1_;
|
||||
h2_ = bitcast<vec2<f16>>(_e37);
|
||||
let _e39 = u1_;
|
||||
h2_ = bitcast<vec2<f16>>(_e39);
|
||||
let _e41 = f1_;
|
||||
h2_ = bitcast<vec2<f16>>(_e41);
|
||||
let _e43 = i2_;
|
||||
h4_ = bitcast<vec4<f16>>(_e43);
|
||||
let _e45 = u2_;
|
||||
h4_ = bitcast<vec4<f16>>(_e45);
|
||||
let _e47 = f2_;
|
||||
h4_ = bitcast<vec4<f16>>(_e47);
|
||||
let _e49 = h2_;
|
||||
h2_ = bitcast<vec2<f16>>(_e49);
|
||||
let _e51 = u1_;
|
||||
u1_ = bitcast<u32>(_e51);
|
||||
u1_ = bitcast<u32>(4294967295u);
|
||||
f1_ = bitcast<f32>(1i);
|
||||
i1_ = bitcast<i32>(1f);
|
||||
h2_ = bitcast<vec2<f16>>(1i);
|
||||
h2_ = bitcast<vec2<f16>>(vec2<f16>(1h, 2h));
|
||||
h4_ = bitcast<vec4<f16>>(vec2<i32>(1i, 2i));
|
||||
u2_ = bitcast<vec2<u32>>(vec2<u32>(4294967295u, 1u));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
enable f16;
|
||||
enable wgpu_int16;
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
var h: f16 = 1h;
|
||||
var i: i16 = i16(1);
|
||||
var u: u16 = u16(2);
|
||||
var h4_: vec4<f16> = vec4<f16>(1h, 2h, 3h, 4h);
|
||||
var u4_: vec4<u16> = vec4<u16>(u16(1), u16(2), u16(3), u16(4));
|
||||
|
||||
let _e18 = h;
|
||||
i = bitcast<i16>(_e18);
|
||||
let _e20 = h;
|
||||
u = bitcast<u16>(_e20);
|
||||
let _e22 = i;
|
||||
h = bitcast<f16>(_e22);
|
||||
let _e24 = u;
|
||||
h = bitcast<f16>(_e24);
|
||||
let _e26 = h4_;
|
||||
u4_ = bitcast<vec4<u16>>(_e26);
|
||||
let _e28 = u4_;
|
||||
h4_ = bitcast<vec4<f16>>(_e28);
|
||||
return;
|
||||
}
|
||||
Reference in new issue
Block a user