mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 09:21:04 +01:00
[naga spv-in] Adjust types of globals used by atomic instructions.
To support atomic instructions in the SPIR-V front end, observe which global variables the input accesses using atomic instructions, and adjust their types from ordinary scalars to atomic values. See comments in `naga::front::atomic_upgrade`.
This commit is contained in:
1 parent
717507977e
commit
6405dcf611
9 files changed
+724
-65
No files matched your search
@@ -126,6 +126,7 @@ By @atlv24 in [#5383](https://github.com/gfx-rs/wgpu/pull/5383)
|
||||
|
||||
#### Naga
|
||||
|
||||
- Added type upgrades to SPIR-V atomic support. Added related infrastructure. Tracking issue is [here](https://github.com/gfx-rs/wgpu/issues/4489). By @schell in [#5775](https://github.com/gfx-rs/wgpu/pull/5775).
|
||||
- Implement `WGSL`'s `unpack4xI8`,`unpack4xU8`,`pack4xI8` and `pack4xU8`. By @VlaDexa in [#5424](https://github.com/gfx-rs/wgpu/pull/5424)
|
||||
- Began work adding support for atomics to the SPIR-V frontend. Tracking issue is [here](https://github.com/gfx-rs/wgpu/issues/4489). By @schell in [#5702](https://github.com/gfx-rs/wgpu/pull/5702).
|
||||
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
//! 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:
|
||||
//!
|
||||
//! - Atomics in structs are not implemented yet.
|
||||
//!
|
||||
//! - The GLSL front end could use this transformation as well.
|
||||
//!
|
||||
//! [`Atomic`]: TypeInner::Atomic
|
||||
//! [`Scalar`]: TypeInner::Scalar
|
||||
//! [`Storage`]: crate::AddressSpace::Storage
|
||||
//! [`WorkGroup`]: crate::AddressSpace::WorkGroup
|
||||
//! [`Array`]: TypeInner::Array
|
||||
//! [`Struct`]: TypeInner::Struct
|
||||
//! [`Load`]: crate::Expression::Load
|
||||
//! [`Store`]: crate::Statement::Store
|
||||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use crate::{GlobalVariable, Handle, Module, Type, TypeInner};
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("encountered an unsupported expression")]
|
||||
Unsupported,
|
||||
#[error("upgrading structs of more than one member is not yet implemented")]
|
||||
MultiMemberStruct,
|
||||
#[error("encountered unsupported global initializer in an atomic variable")]
|
||||
GlobalInitUnsupported,
|
||||
}
|
||||
|
||||
impl From<Error> for crate::front::spv::Error {
|
||||
fn from(source: Error) -> Self {
|
||||
crate::front::spv::Error::AtomicUpgradeError(source)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Padding(Arc<AtomicUsize>);
|
||||
|
||||
impl std::fmt::Display for Padding {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
for _ in 0..self.0.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
f.write_str(" ")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Padding {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.0.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
impl Padding {
|
||||
fn trace(&self, msg: impl std::fmt::Display, t: impl std::fmt::Debug) {
|
||||
format!("{msg} {t:#?}")
|
||||
.split('\n')
|
||||
.for_each(|ln| log::trace!("{self}{ln}"));
|
||||
}
|
||||
|
||||
fn debug(&self, msg: impl std::fmt::Display, t: impl std::fmt::Debug) {
|
||||
format!("{msg} {t:#?}")
|
||||
.split('\n')
|
||||
.for_each(|ln| log::debug!("{self}{ln}"));
|
||||
}
|
||||
|
||||
fn inc_padding(&self) -> Padding {
|
||||
let _ = self.0.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
struct UpgradeState<'a> {
|
||||
padding: Padding,
|
||||
module: &'a mut Module,
|
||||
}
|
||||
|
||||
impl<'a> UpgradeState<'a> {
|
||||
fn inc_padding(&self) -> Padding {
|
||||
self.padding.inc_padding()
|
||||
}
|
||||
|
||||
/// Upgrade the type, recursing until we reach the leaves.
|
||||
/// At the leaves, replace scalars with atomic scalars.
|
||||
fn upgrade_type(&mut self, ty: Handle<Type>) -> Result<Handle<Type>, Error> {
|
||||
let padding = self.inc_padding();
|
||||
padding.trace("upgrading type: ", ty);
|
||||
|
||||
let inner = match self.module.types[ty].inner {
|
||||
TypeInner::Scalar(scalar) => {
|
||||
log::trace!("{padding}hit the scalar leaf, replacing with an atomic");
|
||||
TypeInner::Atomic(scalar)
|
||||
}
|
||||
TypeInner::Pointer { base, space } => TypeInner::Pointer {
|
||||
base: self.upgrade_type(base)?,
|
||||
space,
|
||||
},
|
||||
TypeInner::Array { base, size, stride } => TypeInner::Array {
|
||||
base: self.upgrade_type(base)?,
|
||||
size,
|
||||
stride,
|
||||
},
|
||||
TypeInner::Struct { ref members, span } => {
|
||||
// In the future we should have to figure out which member needs
|
||||
// upgrading, but for now we'll only cover the single-member
|
||||
// case.
|
||||
let &[crate::StructMember {
|
||||
ref name,
|
||||
ty,
|
||||
ref binding,
|
||||
offset,
|
||||
}] = &members[..]
|
||||
else {
|
||||
return Err(Error::MultiMemberStruct);
|
||||
};
|
||||
|
||||
// Take our own clones of these values now, so that
|
||||
// `upgrade_type` can mutate the module.
|
||||
let name = name.clone();
|
||||
let binding = binding.clone();
|
||||
let upgraded_member_type = self.upgrade_type(ty)?;
|
||||
TypeInner::Struct {
|
||||
members: vec![crate::StructMember {
|
||||
name,
|
||||
ty: upgraded_member_type,
|
||||
binding,
|
||||
offset,
|
||||
}],
|
||||
span,
|
||||
}
|
||||
}
|
||||
TypeInner::BindingArray { base, size } => TypeInner::BindingArray {
|
||||
base: self.upgrade_type(base)?,
|
||||
size,
|
||||
},
|
||||
_ => return Ok(ty),
|
||||
};
|
||||
|
||||
// Now that we've upgraded any subtypes, re-borrow a reference to our
|
||||
// type and update its `inner`.
|
||||
let r#type = &self.module.types[ty];
|
||||
let span = self.module.types.get_span(ty);
|
||||
let new_type = Type {
|
||||
name: r#type.name.clone(),
|
||||
inner,
|
||||
};
|
||||
padding.debug("ty: ", ty);
|
||||
padding.debug("from: ", r#type);
|
||||
padding.debug("to: ", &new_type);
|
||||
let new_handle = self.module.types.insert(new_type, span);
|
||||
Ok(new_handle)
|
||||
}
|
||||
|
||||
fn upgrade_global_variable(&mut self, handle: Handle<GlobalVariable>) -> Result<(), Error> {
|
||||
let padding = self.inc_padding();
|
||||
padding.trace("upgrading global variable: ", handle);
|
||||
|
||||
let var = &self.module.global_variables[handle];
|
||||
|
||||
if var.init.is_some() {
|
||||
return Err(Error::GlobalInitUnsupported);
|
||||
}
|
||||
|
||||
let var_ty = var.ty;
|
||||
let new_ty = self.upgrade_type(var.ty)?;
|
||||
if new_ty != var_ty {
|
||||
padding.debug("upgrading global variable: ", handle);
|
||||
padding.debug("from ty: ", var_ty);
|
||||
padding.debug("to ty: ", new_ty);
|
||||
self.module.global_variables[handle].ty = new_ty;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Module {
|
||||
/// Upgrade `global_var_handles` to have [`Atomic`] leaf types.
|
||||
///
|
||||
/// [`Atomic`]: TypeInner::Atomic
|
||||
pub(crate) fn upgrade_atomics(
|
||||
&mut self,
|
||||
global_var_handles: impl IntoIterator<Item = Handle<GlobalVariable>>,
|
||||
) -> Result<(), Error> {
|
||||
let mut state = UpgradeState {
|
||||
padding: Default::default(),
|
||||
module: self,
|
||||
};
|
||||
|
||||
for handle in global_var_handles {
|
||||
state.upgrade_global_variable(handle)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ Frontend parsers that consume binary and text shaders and load them into [`Modul
|
||||
mod interpolator;
|
||||
mod type_gen;
|
||||
|
||||
#[cfg(feature = "spv-in")]
|
||||
pub mod atomic_upgrade;
|
||||
#[cfg(feature = "glsl-in")]
|
||||
pub mod glsl;
|
||||
#[cfg(feature = "spv-in")]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::ModuleState;
|
||||
use crate::arena::Handle;
|
||||
use crate::{arena::Handle, front::atomic_upgrade};
|
||||
use codespan_reporting::diagnostic::Diagnostic;
|
||||
use codespan_reporting::files::SimpleFile;
|
||||
use codespan_reporting::term;
|
||||
@@ -134,6 +134,9 @@ pub enum Error {
|
||||
NonBindingArrayOfImageOrSamplers,
|
||||
#[error("naga only supports specialization constant IDs up to 65535 but was given {0}")]
|
||||
SpecIdTooHigh(u32),
|
||||
|
||||
#[error("atomic upgrade error: {0}")]
|
||||
AtomicUpgradeError(atomic_upgrade::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
||||
+64
-38
@@ -36,6 +36,7 @@ mod null;
|
||||
use convert::*;
|
||||
pub use error::Error;
|
||||
use function::*;
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use crate::{
|
||||
arena::{Arena, Handle, UniqueArena},
|
||||
@@ -560,25 +561,44 @@ struct BlockContext<'function> {
|
||||
parameter_sampling: &'function mut [image::SamplingFlags],
|
||||
}
|
||||
|
||||
impl<'a> BlockContext<'a> {
|
||||
/// Descend into the expression with the given handle, locating a contained
|
||||
/// global variable.
|
||||
///
|
||||
/// This is used to track atomic upgrades.
|
||||
fn get_contained_global_variable(
|
||||
&self,
|
||||
mut handle: Handle<crate::Expression>,
|
||||
) -> Option<Handle<crate::GlobalVariable>> {
|
||||
log::debug!("\t\tlocating global variable in {handle:?}");
|
||||
loop {
|
||||
match self.expressions[handle] {
|
||||
crate::Expression::Access { base, index: _ } => {
|
||||
handle = base;
|
||||
log::debug!("\t\t access {handle:?}");
|
||||
}
|
||||
crate::Expression::AccessIndex { base, index: _ } => {
|
||||
handle = base;
|
||||
log::debug!("\t\t access index {handle:?}");
|
||||
}
|
||||
crate::Expression::GlobalVariable(h) => {
|
||||
log::debug!("\t\t found {h:?}");
|
||||
return Some(h);
|
||||
}
|
||||
_ => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
enum SignAnchor {
|
||||
Result,
|
||||
Operand,
|
||||
}
|
||||
|
||||
enum AtomicOpInst {
|
||||
AtomicIIncrement,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct AtomicOp {
|
||||
instruction: AtomicOpInst,
|
||||
result_type_id: spirv::Word,
|
||||
result_id: spirv::Word,
|
||||
pointer_id: spirv::Word,
|
||||
scope_id: spirv::Word,
|
||||
memory_semantics_id: spirv::Word,
|
||||
}
|
||||
|
||||
pub struct Frontend<I> {
|
||||
data: I,
|
||||
data_offset: usize,
|
||||
@@ -590,8 +610,12 @@ pub struct Frontend<I> {
|
||||
future_member_decor: FastHashMap<(spirv::Word, MemberIndex), Decoration>,
|
||||
lookup_member: FastHashMap<(Handle<crate::Type>, MemberIndex), LookupMember>,
|
||||
handle_sampling: FastHashMap<Handle<crate::GlobalVariable>, image::SamplingFlags>,
|
||||
// Used to upgrade types used in atomic ops to atomic types, keyed by pointer id
|
||||
lookup_atomic: FastHashMap<spirv::Word, AtomicOp>,
|
||||
/// The set of all global variables accessed by [`Atomic`] statements we've
|
||||
/// generated, so we can upgrade the types of their operands.
|
||||
///
|
||||
/// [`Atomic`]: crate::Statement::Atomic
|
||||
upgrade_atomics: IndexSet<Handle<crate::GlobalVariable>>,
|
||||
|
||||
lookup_type: FastHashMap<spirv::Word, LookupType>,
|
||||
lookup_void_type: Option<spirv::Word>,
|
||||
lookup_storage_buffer_types: FastHashMap<Handle<crate::Type>, crate::StorageAccess>,
|
||||
@@ -647,7 +671,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
future_member_decor: FastHashMap::default(),
|
||||
handle_sampling: FastHashMap::default(),
|
||||
lookup_member: FastHashMap::default(),
|
||||
lookup_atomic: FastHashMap::default(),
|
||||
upgrade_atomics: Default::default(),
|
||||
lookup_type: FastHashMap::default(),
|
||||
lookup_void_type: None,
|
||||
lookup_storage_buffer_types: FastHashMap::default(),
|
||||
@@ -3968,30 +3992,21 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
let result_type_id = self.next()?;
|
||||
let result_id = self.next()?;
|
||||
let pointer_id = self.next()?;
|
||||
let scope_id = self.next()?;
|
||||
let memory_semantics_id = self.next()?;
|
||||
// Store the op for a later pass where we "upgrade" the pointer type
|
||||
let atomic = AtomicOp {
|
||||
instruction: AtomicOpInst::AtomicIIncrement,
|
||||
result_type_id,
|
||||
result_id,
|
||||
pointer_id,
|
||||
scope_id,
|
||||
memory_semantics_id,
|
||||
};
|
||||
self.lookup_atomic.insert(pointer_id, atomic);
|
||||
let _scope_id = self.next()?;
|
||||
let _memory_semantics_id = self.next()?;
|
||||
|
||||
log::trace!("\t\t\tlooking up expr {:?}", pointer_id);
|
||||
|
||||
let (p_lexp_handle, p_lexp_ty_id) = {
|
||||
let lexp = self.lookup_expression.lookup(pointer_id)?;
|
||||
let handle = get_expr_handle!(pointer_id, &lexp);
|
||||
(handle, lexp.type_id)
|
||||
};
|
||||
|
||||
log::trace!("\t\t\tlooking up type {pointer_id:?}");
|
||||
let p_ty = self.lookup_type.lookup(p_lexp_ty_id)?;
|
||||
let p_ty_base_id =
|
||||
p_ty.base_id.ok_or(Error::InvalidAccessType(p_lexp_ty_id))?;
|
||||
|
||||
log::trace!("\t\t\tlooking up base type {p_ty_base_id:?} of {p_ty:?}");
|
||||
let p_base_ty = self.lookup_type.lookup(p_ty_base_id)?;
|
||||
|
||||
@@ -4032,6 +4047,10 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
result: Some(r_lexp_handle),
|
||||
};
|
||||
block.push(stmt, span);
|
||||
|
||||
// Store any associated global variables so we can upgrade their types later
|
||||
self.upgrade_atomics
|
||||
.extend(ctx.get_contained_global_variable(p_lexp_handle));
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::UnsupportedInstruction(self.state, inst.op));
|
||||
@@ -4314,6 +4333,11 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
}?;
|
||||
}
|
||||
|
||||
if !self.upgrade_atomics.is_empty() {
|
||||
log::info!("Upgrading atomic pointers...");
|
||||
module.upgrade_atomics(std::mem::take(&mut self.upgrade_atomics))?;
|
||||
}
|
||||
|
||||
// Do entry point specific processing after all functions are parsed so that we can
|
||||
// cull unused problematic builtins of gl_PerVertex.
|
||||
for (ep, fun_id) in mem::take(&mut self.deferred_entry_points) {
|
||||
@@ -5689,17 +5713,20 @@ mod test {
|
||||
#[cfg(all(feature = "wgsl-in", feature = "wgsl-out"))]
|
||||
#[test]
|
||||
fn atomic_i_inc() {
|
||||
let _ = env_logger::builder()
|
||||
.is_test(true)
|
||||
.filter_level(log::LevelFilter::Trace)
|
||||
.try_init();
|
||||
let _ = env_logger::builder().is_test(true).try_init();
|
||||
let bytes = include_bytes!("../../../tests/in/spv/atomic_i_increment.spv");
|
||||
let m = super::parse_u8_slice(bytes, &Default::default()).unwrap();
|
||||
let mut validator = crate::valid::Validator::new(
|
||||
crate::valid::ValidationFlags::empty(),
|
||||
Default::default(),
|
||||
);
|
||||
let info = validator.validate(&m).unwrap();
|
||||
let info = match validator.validate(&m) {
|
||||
Err(e) => {
|
||||
log::error!("{}", e.emit_to_string(""));
|
||||
return;
|
||||
}
|
||||
Ok(i) => i,
|
||||
};
|
||||
let wgsl =
|
||||
crate::back::wgsl::write_string(&m, &info, crate::back::wgsl::WriterFlags::empty())
|
||||
.unwrap();
|
||||
@@ -5709,15 +5736,14 @@ mod test {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
log::error!("{}", e.emit_to_string(&wgsl));
|
||||
// at this point we know atomics create invalid modules
|
||||
// so simply bail
|
||||
return;
|
||||
panic!("invalid module");
|
||||
}
|
||||
};
|
||||
let mut validator =
|
||||
crate::valid::Validator::new(crate::valid::ValidationFlags::all(), Default::default());
|
||||
if let Err(e) = validator.validate(&m) {
|
||||
log::error!("{}", e.emit_to_string(&wgsl));
|
||||
panic!("invalid generated wgsl");
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,62 @@
|
||||
; SPIR-V
|
||||
; Version: 1.5
|
||||
; Generator: Google rspirv; 0
|
||||
; Bound: 37
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpCapability VulkanMemoryModel
|
||||
OpMemoryModel Logical Vulkan
|
||||
OpEntryPoint GLCompute %1 "stage::test_atomic_i_increment" %2 %3
|
||||
OpExecutionMode %1 LocalSize 32 1 1
|
||||
OpDecorate %_struct_6 Block
|
||||
OpMemberDecorate %_struct_6 0 Offset 0
|
||||
OpDecorate %2 Binding 0
|
||||
OpDecorate %2 DescriptorSet 0
|
||||
OpDecorate %3 NonWritable
|
||||
OpDecorate %3 Binding 1
|
||||
OpDecorate %3 DescriptorSet 0
|
||||
%uint = OpTypeInt 32 0
|
||||
%void = OpTypeVoid
|
||||
%9 = OpTypeFunction %void
|
||||
%bool = OpTypeBool
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%uint_2 = OpConstant %uint 2
|
||||
%false = OpConstantFalse %bool
|
||||
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%true = OpConstantTrue %bool
|
||||
%_struct_6 = OpTypeStruct %uint
|
||||
%_ptr_StorageBuffer__struct_6 = OpTypePointer StorageBuffer %_struct_6
|
||||
%2 = OpVariable %_ptr_StorageBuffer__struct_6 StorageBuffer
|
||||
%3 = OpVariable %_ptr_StorageBuffer__struct_6 StorageBuffer
|
||||
%18 = OpUndef %uint
|
||||
%1 = OpFunction %void None %9
|
||||
%19 = OpLabel
|
||||
%20 = OpAccessChain %_ptr_StorageBuffer_uint %2 %uint_0
|
||||
%21 = OpAccessChain %_ptr_StorageBuffer_uint %3 %uint_0
|
||||
OpBranch %22
|
||||
%22 = OpLabel
|
||||
%23 = OpPhi %uint %uint_0 %19 %24 %25
|
||||
OpLoopMerge %26 %25 None
|
||||
OpBranch %27
|
||||
%27 = OpLabel
|
||||
%28 = OpLoad %uint %21
|
||||
%29 = OpUGreaterThanEqual %bool %23 %28
|
||||
OpSelectionMerge %30 None
|
||||
OpBranchConditional %29 %31 %32
|
||||
%31 = OpLabel
|
||||
OpBranch %30
|
||||
%32 = OpLabel
|
||||
%33 = OpAtomicIIncrement %uint %20 %uint_2 %uint_0
|
||||
%34 = OpIAdd %uint %23 %uint_1
|
||||
OpBranch %30
|
||||
%30 = OpLabel
|
||||
%24 = OpPhi %uint %18 %31 %34 %32
|
||||
%36 = OpSelect %bool %29 %false %true
|
||||
OpBranch %25
|
||||
%25 = OpLabel
|
||||
OpBranchConditional %36 %22 %26
|
||||
%26 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
width: 4,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Scalar((
|
||||
kind: Bool,
|
||||
width: 1,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Struct(
|
||||
@@ -21,13 +28,60 @@
|
||||
span: 4,
|
||||
),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Atomic((
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Struct(
|
||||
members: [
|
||||
(
|
||||
name: None,
|
||||
ty: 3,
|
||||
binding: None,
|
||||
offset: 0,
|
||||
),
|
||||
],
|
||||
span: 4,
|
||||
),
|
||||
),
|
||||
],
|
||||
special_types: (
|
||||
ray_desc: None,
|
||||
ray_intersection: None,
|
||||
predeclared_types: {},
|
||||
),
|
||||
constants: [],
|
||||
constants: [
|
||||
(
|
||||
name: None,
|
||||
ty: 0,
|
||||
init: 0,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 1,
|
||||
init: 1,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 0,
|
||||
init: 2,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 1,
|
||||
init: 3,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 0,
|
||||
init: 4,
|
||||
),
|
||||
],
|
||||
overrides: [],
|
||||
global_variables: [
|
||||
(
|
||||
@@ -39,40 +93,166 @@
|
||||
group: 0,
|
||||
binding: 0,
|
||||
)),
|
||||
ty: 1,
|
||||
ty: 4,
|
||||
init: None,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
space: Storage(
|
||||
access: ("LOAD"),
|
||||
),
|
||||
binding: Some((
|
||||
group: 0,
|
||||
binding: 1,
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
global_expressions: [
|
||||
Literal(U32(0)),
|
||||
Literal(Bool(false)),
|
||||
Literal(U32(1)),
|
||||
Literal(Bool(true)),
|
||||
ZeroValue(0),
|
||||
],
|
||||
functions: [
|
||||
(
|
||||
name: None,
|
||||
arguments: [],
|
||||
result: None,
|
||||
local_variables: [],
|
||||
local_variables: [
|
||||
(
|
||||
name: Some("phi_23"),
|
||||
ty: 0,
|
||||
init: None,
|
||||
),
|
||||
(
|
||||
name: Some("phi_24"),
|
||||
ty: 0,
|
||||
init: None,
|
||||
),
|
||||
],
|
||||
expressions: [
|
||||
GlobalVariable(0),
|
||||
GlobalVariable(1),
|
||||
Constant(3),
|
||||
Constant(1),
|
||||
Constant(4),
|
||||
Constant(2),
|
||||
Constant(0),
|
||||
AccessIndex(
|
||||
base: 0,
|
||||
index: 0,
|
||||
),
|
||||
AccessIndex(
|
||||
base: 1,
|
||||
index: 0,
|
||||
),
|
||||
LocalVariable(0),
|
||||
Load(
|
||||
pointer: 9,
|
||||
),
|
||||
Load(
|
||||
pointer: 8,
|
||||
),
|
||||
Binary(
|
||||
op: GreaterEqual,
|
||||
left: 10,
|
||||
right: 11,
|
||||
),
|
||||
AtomicResult(
|
||||
ty: 0,
|
||||
comparison: false,
|
||||
),
|
||||
Literal(U32(1)),
|
||||
Binary(
|
||||
op: Add,
|
||||
left: 10,
|
||||
right: 5,
|
||||
),
|
||||
LocalVariable(1),
|
||||
Load(
|
||||
pointer: 16,
|
||||
),
|
||||
Select(
|
||||
condition: 12,
|
||||
accept: 3,
|
||||
reject: 2,
|
||||
),
|
||||
Unary(
|
||||
op: LogicalNot,
|
||||
expr: 18,
|
||||
),
|
||||
LocalVariable(0),
|
||||
LocalVariable(1),
|
||||
],
|
||||
named_expressions: {},
|
||||
body: [
|
||||
Emit((
|
||||
start: 1,
|
||||
end: 3,
|
||||
start: 7,
|
||||
end: 9,
|
||||
)),
|
||||
Atomic(
|
||||
pointer: 1,
|
||||
fun: Add,
|
||||
value: 3,
|
||||
result: Some(2),
|
||||
Store(
|
||||
pointer: 20,
|
||||
value: 6,
|
||||
),
|
||||
Loop(
|
||||
body: [
|
||||
Emit((
|
||||
start: 10,
|
||||
end: 11,
|
||||
)),
|
||||
Emit((
|
||||
start: 11,
|
||||
end: 13,
|
||||
)),
|
||||
If(
|
||||
condition: 12,
|
||||
accept: [
|
||||
Store(
|
||||
pointer: 21,
|
||||
value: 4,
|
||||
),
|
||||
],
|
||||
reject: [
|
||||
Emit((
|
||||
start: 13,
|
||||
end: 14,
|
||||
)),
|
||||
Atomic(
|
||||
pointer: 7,
|
||||
fun: Add,
|
||||
value: 14,
|
||||
result: Some(13),
|
||||
),
|
||||
Emit((
|
||||
start: 15,
|
||||
end: 16,
|
||||
)),
|
||||
Store(
|
||||
pointer: 21,
|
||||
value: 15,
|
||||
),
|
||||
],
|
||||
),
|
||||
Emit((
|
||||
start: 17,
|
||||
end: 19,
|
||||
)),
|
||||
Continue,
|
||||
],
|
||||
continuing: [
|
||||
Emit((
|
||||
start: 19,
|
||||
end: 20,
|
||||
)),
|
||||
Store(
|
||||
pointer: 20,
|
||||
value: 17,
|
||||
),
|
||||
],
|
||||
break_if: Some(19),
|
||||
),
|
||||
Return(
|
||||
value: None,
|
||||
|
||||
@@ -7,6 +7,22 @@
|
||||
width: 4,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Scalar((
|
||||
kind: Bool,
|
||||
width: 1,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Pointer(
|
||||
base: 0,
|
||||
space: Storage(
|
||||
access: ("LOAD | STORE"),
|
||||
),
|
||||
),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Struct(
|
||||
@@ -24,7 +40,7 @@
|
||||
(
|
||||
name: None,
|
||||
inner: Pointer(
|
||||
base: 1,
|
||||
base: 3,
|
||||
space: Storage(
|
||||
access: ("LOAD | STORE"),
|
||||
),
|
||||
@@ -32,11 +48,23 @@
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Pointer(
|
||||
base: 0,
|
||||
space: Storage(
|
||||
access: ("LOAD | STORE"),
|
||||
),
|
||||
inner: Atomic((
|
||||
kind: Uint,
|
||||
width: 4,
|
||||
)),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
inner: Struct(
|
||||
members: [
|
||||
(
|
||||
name: None,
|
||||
ty: 5,
|
||||
binding: None,
|
||||
offset: 0,
|
||||
),
|
||||
],
|
||||
span: 4,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -56,6 +84,26 @@
|
||||
ty: 0,
|
||||
init: 1,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 1,
|
||||
init: 2,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 0,
|
||||
init: 3,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 1,
|
||||
init: 4,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
ty: 0,
|
||||
init: 5,
|
||||
),
|
||||
],
|
||||
overrides: [],
|
||||
global_variables: [
|
||||
@@ -68,45 +116,168 @@
|
||||
group: 0,
|
||||
binding: 0,
|
||||
)),
|
||||
ty: 1,
|
||||
ty: 6,
|
||||
init: None,
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
space: Storage(
|
||||
access: ("LOAD"),
|
||||
),
|
||||
binding: Some((
|
||||
group: 0,
|
||||
binding: 1,
|
||||
)),
|
||||
ty: 3,
|
||||
init: None,
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
Literal(U32(0)),
|
||||
Literal(U32(2)),
|
||||
Literal(Bool(false)),
|
||||
Literal(U32(1)),
|
||||
Literal(Bool(true)),
|
||||
ZeroValue(0),
|
||||
],
|
||||
functions: [
|
||||
(
|
||||
name: None,
|
||||
arguments: [],
|
||||
result: None,
|
||||
local_variables: [],
|
||||
local_variables: [
|
||||
(
|
||||
name: Some("phi_23"),
|
||||
ty: 0,
|
||||
init: None,
|
||||
),
|
||||
(
|
||||
name: Some("phi_24"),
|
||||
ty: 0,
|
||||
init: None,
|
||||
),
|
||||
],
|
||||
expressions: [
|
||||
GlobalVariable(0),
|
||||
GlobalVariable(1),
|
||||
Constant(4),
|
||||
Constant(2),
|
||||
Constant(5),
|
||||
Constant(3),
|
||||
Constant(1),
|
||||
Constant(0),
|
||||
AccessIndex(
|
||||
base: 0,
|
||||
index: 0,
|
||||
),
|
||||
AccessIndex(
|
||||
base: 1,
|
||||
index: 0,
|
||||
),
|
||||
LocalVariable(0),
|
||||
Load(
|
||||
pointer: 10,
|
||||
),
|
||||
Load(
|
||||
pointer: 9,
|
||||
),
|
||||
Binary(
|
||||
op: GreaterEqual,
|
||||
left: 11,
|
||||
right: 12,
|
||||
),
|
||||
AtomicResult(
|
||||
ty: 0,
|
||||
comparison: false,
|
||||
),
|
||||
Literal(U32(1)),
|
||||
Binary(
|
||||
op: Add,
|
||||
left: 11,
|
||||
right: 5,
|
||||
),
|
||||
LocalVariable(1),
|
||||
Load(
|
||||
pointer: 17,
|
||||
),
|
||||
Select(
|
||||
condition: 13,
|
||||
accept: 3,
|
||||
reject: 2,
|
||||
),
|
||||
Unary(
|
||||
op: LogicalNot,
|
||||
expr: 19,
|
||||
),
|
||||
LocalVariable(0),
|
||||
LocalVariable(1),
|
||||
],
|
||||
named_expressions: {},
|
||||
body: [
|
||||
Emit((
|
||||
start: 3,
|
||||
end: 5,
|
||||
start: 8,
|
||||
end: 10,
|
||||
)),
|
||||
Atomic(
|
||||
pointer: 3,
|
||||
fun: Add,
|
||||
value: 5,
|
||||
result: Some(4),
|
||||
Store(
|
||||
pointer: 21,
|
||||
value: 7,
|
||||
),
|
||||
Loop(
|
||||
body: [
|
||||
Emit((
|
||||
start: 11,
|
||||
end: 12,
|
||||
)),
|
||||
Emit((
|
||||
start: 12,
|
||||
end: 14,
|
||||
)),
|
||||
If(
|
||||
condition: 13,
|
||||
accept: [
|
||||
Store(
|
||||
pointer: 22,
|
||||
value: 4,
|
||||
),
|
||||
],
|
||||
reject: [
|
||||
Emit((
|
||||
start: 14,
|
||||
end: 15,
|
||||
)),
|
||||
Atomic(
|
||||
pointer: 8,
|
||||
fun: Add,
|
||||
value: 15,
|
||||
result: Some(14),
|
||||
),
|
||||
Emit((
|
||||
start: 16,
|
||||
end: 17,
|
||||
)),
|
||||
Store(
|
||||
pointer: 22,
|
||||
value: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
Emit((
|
||||
start: 18,
|
||||
end: 20,
|
||||
)),
|
||||
Continue,
|
||||
],
|
||||
continuing: [
|
||||
Emit((
|
||||
start: 20,
|
||||
end: 21,
|
||||
)),
|
||||
Store(
|
||||
pointer: 21,
|
||||
value: 18,
|
||||
),
|
||||
],
|
||||
break_if: Some(20),
|
||||
),
|
||||
Return(
|
||||
value: None,
|
||||
|
||||
Reference in new issue
Block a user