Module naga::front::atomic_upgrade
source · Expand description
Upgrade the types of scalars observed to be accessed as atomics to Atomic
types.
In SPIR-V, atomic operations can be applied to any scalar value, but in Naga
IR atomic operations can only be applied to values of type Atomic
. Naga
IR’s restriction matches Metal Shading Language and WGSL, so we don’t want
to relax that. Instead, when the SPIR-V front end observes a value being
accessed using atomic instructions, it promotes the value’s type from
Scalar
to Atomic
. This module implements Module::upgrade_atomics
,
the function that makes that change.
Atomics can only appear in global variables in the Storage
and
Workgroup
address spaces. These variables can either have Atomic
types
themselves, or be Array
s of such, or be Struct
s containing such.
So we only need to change the types of globals and struct fields.
Naga IR Load
expressions and Store
statements can operate directly
on Atomic
values, retrieving and depositing ordinary Scalar
values,
so changing the types doesn’t have much effect on the code that operates on
those values.
Future work:
- The GLSL front end could use this transformation as well.