Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ByteAddressableBuffer prototype detached from bindless #735

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub enum SpirvAttribute {

// `fn`/closure attributes:
UnrollLoops,
BufferLoadIntrinsic,
BufferStoreIntrinsic,
}

// HACK(eddyb) this is similar to `rustc_span::Spanned` but with `value` as the
Expand Down Expand Up @@ -122,6 +124,8 @@ pub struct AggregatedSpirvAttributes {

// `fn`/closure attributes:
pub unroll_loops: Option<Spanned<()>>,
pub buffer_load_intrinsic: Option<Spanned<()>>,
pub buffer_store_intrinsic: Option<Spanned<()>>,
}

struct MultipleAttrs {
Expand Down Expand Up @@ -209,6 +213,18 @@ impl AggregatedSpirvAttributes {
"#[spirv(attachment_index)]",
),
UnrollLoops => try_insert(&mut self.unroll_loops, (), span, "#[spirv(unroll_loops)]"),
BufferLoadIntrinsic => try_insert(
&mut self.buffer_load_intrinsic,
(),
span,
"#[spirv(buffer_load_intrinsic)]",
),
BufferStoreIntrinsic => try_insert(
&mut self.buffer_store_intrinsic,
(),
span,
"#[spirv(buffer_store_intrinsic)]",
),
}
}
}
Expand Down Expand Up @@ -342,6 +358,12 @@ impl CheckSpirvAttrVisitor<'_> {

_ => Err(Expected("function or closure")),
},
SpirvAttribute::BufferLoadIntrinsic | SpirvAttribute::BufferStoreIntrinsic => {
match target {
Target::Fn => Ok(()),
_ => Err(Expected("function")),
}
}
};
match valid_target {
Err(Expected(expected_target)) => self.tcx.sess.span_err(
Expand Down
22 changes: 20 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,8 +1845,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
SpirvType::Adt { field_types, .. } => field_types[idx as usize],
SpirvType::Array { element, .. } | SpirvType::Vector { element, .. } => element,
other => self.fatal(&format!(
"extract_value not implemented on type {:?}",
other
"extract_value not implemented on type {}",
other.debug(agg_val.ty, self)
)),
};
self.emit()
Expand Down Expand Up @@ -2196,6 +2196,24 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
// needing to materialize `&core::panic::Location` or `format_args!`.
self.abort();
self.undef(result_type)
} else if self
.buffer_load_intrinsic_fn_id
.borrow()
.contains(&callee_val)
{
self.codegen_buffer_load_intrinsic(result_type, args)
} else if self
.buffer_store_intrinsic_fn_id
.borrow()
.contains(&callee_val)
{
self.codegen_buffer_store_intrinsic(args);

let void_ty = SpirvType::Void.def(rustc_span::DUMMY_SP, self);
SpirvValue {
kind: SpirvValueKind::IllegalTypeUsed(void_ty),
ty: void_ty,
}
} else {
let args = args.iter().map(|arg| arg.def(self)).collect::<Vec<_>>();
self.emit()
Expand Down
Loading