Skip to content

Commit 66d6c55

Browse files
authored
Implement ByteAddressableBuffer prototype detached from bindless (#735)
1 parent f056082 commit 66d6c55

File tree

16 files changed

+657
-2
lines changed

16 files changed

+657
-2
lines changed

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ pub enum SpirvAttribute {
9090

9191
// `fn`/closure attributes:
9292
UnrollLoops,
93+
BufferLoadIntrinsic,
94+
BufferStoreIntrinsic,
9395
}
9496

9597
// HACK(eddyb) this is similar to `rustc_span::Spanned` but with `value` as the
@@ -123,6 +125,8 @@ pub struct AggregatedSpirvAttributes {
123125

124126
// `fn`/closure attributes:
125127
pub unroll_loops: Option<Spanned<()>>,
128+
pub buffer_load_intrinsic: Option<Spanned<()>>,
129+
pub buffer_store_intrinsic: Option<Spanned<()>>,
126130
}
127131

128132
struct MultipleAttrs {
@@ -210,6 +214,18 @@ impl AggregatedSpirvAttributes {
210214
"#[spirv(attachment_index)]",
211215
),
212216
UnrollLoops => try_insert(&mut self.unroll_loops, (), span, "#[spirv(unroll_loops)]"),
217+
BufferLoadIntrinsic => try_insert(
218+
&mut self.buffer_load_intrinsic,
219+
(),
220+
span,
221+
"#[spirv(buffer_load_intrinsic)]",
222+
),
223+
BufferStoreIntrinsic => try_insert(
224+
&mut self.buffer_store_intrinsic,
225+
(),
226+
span,
227+
"#[spirv(buffer_store_intrinsic)]",
228+
),
213229
}
214230
}
215231
}
@@ -343,6 +359,12 @@ impl CheckSpirvAttrVisitor<'_> {
343359

344360
_ => Err(Expected("function or closure")),
345361
},
362+
SpirvAttribute::BufferLoadIntrinsic | SpirvAttribute::BufferStoreIntrinsic => {
363+
match target {
364+
Target::Fn => Ok(()),
365+
_ => Err(Expected("function")),
366+
}
367+
}
346368
};
347369
match valid_target {
348370
Err(Expected(expected_target)) => self.tcx.sess.span_err(

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,8 +1850,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
18501850
| SpirvType::Vector { element, .. }
18511851
| SpirvType::Matrix { element, .. } => element,
18521852
other => self.fatal(&format!(
1853-
"extract_value not implemented on type {:?}",
1854-
other
1853+
"extract_value not implemented on type {}",
1854+
other.debug(agg_val.ty, self)
18551855
)),
18561856
};
18571857
self.emit()
@@ -2201,6 +2201,24 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
22012201
// needing to materialize `&core::panic::Location` or `format_args!`.
22022202
self.abort();
22032203
self.undef(result_type)
2204+
} else if self
2205+
.buffer_load_intrinsic_fn_id
2206+
.borrow()
2207+
.contains(&callee_val)
2208+
{
2209+
self.codegen_buffer_load_intrinsic(result_type, args)
2210+
} else if self
2211+
.buffer_store_intrinsic_fn_id
2212+
.borrow()
2213+
.contains(&callee_val)
2214+
{
2215+
self.codegen_buffer_store_intrinsic(args);
2216+
2217+
let void_ty = SpirvType::Void.def(rustc_span::DUMMY_SP, self);
2218+
SpirvValue {
2219+
kind: SpirvValueKind::IllegalTypeUsed(void_ty),
2220+
ty: void_ty,
2221+
}
22042222
} else {
22052223
let args = args.iter().map(|arg| arg.def(self)).collect::<Vec<_>>();
22062224
self.emit()

0 commit comments

Comments
 (0)