mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-22 14:56:27 +00:00
Fix accidental non-caching of pointers
This commit is contained in:
parent
69773635e9
commit
1ace323688
@ -80,6 +80,12 @@ impl<'tcx> Context<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// rspirv doesn't cache type_pointer, so cache it ourselves here.
|
||||||
|
pub fn type_pointer(&mut self, storage_class: StorageClass, pointee_type: Word) -> Word {
|
||||||
|
self.spirv_helper
|
||||||
|
.type_pointer(&mut self.spirv, storage_class, pointee_type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FnCtx is the "bag of random variables" used for state when compiling a particular function - i.e. variables that are
|
/// FnCtx is the "bag of random variables" used for state when compiling a particular function - i.e. variables that are
|
||||||
@ -128,10 +134,8 @@ impl<'ctx, 'tcx> FnCtx<'ctx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// rspirv doesn't cache type_pointer, so cache it ourselves here.
|
/// rspirv doesn't cache type_pointer, so cache it ourselves here.
|
||||||
pub fn type_pointer(&mut self, pointee_type: Word) -> Word {
|
pub fn type_pointer(&mut self, storage_class: StorageClass, pointee_type: Word) -> Word {
|
||||||
self.ctx
|
self.ctx.type_pointer(storage_class, pointee_type)
|
||||||
.spirv_helper
|
|
||||||
.type_pointer(&mut self.ctx.spirv, pointee_type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copied from rustc_codegen_cranelift
|
// copied from rustc_codegen_cranelift
|
||||||
@ -168,7 +172,7 @@ impl<T: Eq + Hash> ForwardReference<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct SpirvHelper {
|
struct SpirvHelper {
|
||||||
pointer: HashMap<Word, Word>,
|
pointer: HashMap<(Word, StorageClass), Word>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpirvHelper {
|
impl SpirvHelper {
|
||||||
@ -178,11 +182,15 @@ impl SpirvHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_pointer(&mut self, spirv: &mut Builder, pointee_type: Word) -> Word {
|
fn type_pointer(
|
||||||
// TODO: StorageClass
|
&mut self,
|
||||||
|
spirv: &mut Builder,
|
||||||
|
storage_class: StorageClass,
|
||||||
|
pointee_type: Word,
|
||||||
|
) -> Word {
|
||||||
*self
|
*self
|
||||||
.pointer
|
.pointer
|
||||||
.entry(pointee_type)
|
.entry((pointee_type, storage_class))
|
||||||
.or_insert_with(|| spirv.type_pointer(None, StorageClass::Generic, pointee_type))
|
.or_insert_with(|| spirv.type_pointer(None, storage_class, pointee_type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,7 @@ pub fn trans_locals<'tcx>(ctx: &mut FnCtx<'_, 'tcx>, parameters_spirv: Vec<Word>
|
|||||||
for (local, decl) in ctx.body.local_decls.iter_enumerated() {
|
for (local, decl) in ctx.body.local_decls.iter_enumerated() {
|
||||||
// TODO: ZSTs
|
// TODO: ZSTs
|
||||||
let local_type = trans_type(ctx, decl.ty);
|
let local_type = trans_type(ctx, decl.ty);
|
||||||
let local_ptr_type_def =
|
let local_ptr_type_def = ctx.type_pointer(StorageClass::Function, local_type.def());
|
||||||
ctx.spirv()
|
|
||||||
.type_pointer(None, StorageClass::Function, local_type.def());
|
|
||||||
let local_ptr_type = SpirvType::Pointer {
|
let local_ptr_type = SpirvType::Pointer {
|
||||||
def: local_ptr_type_def,
|
def: local_ptr_type_def,
|
||||||
pointee: Box::new(local_type),
|
pointee: Box::new(local_type),
|
||||||
@ -136,7 +134,7 @@ fn trans_type<'tcx>(ctx: &mut FnCtx<'_, 'tcx>, ty: Ty<'tcx>) -> SpirvType {
|
|||||||
let pointee_type = trans_type(ctx, type_and_mut.ty);
|
let pointee_type = trans_type(ctx, type_and_mut.ty);
|
||||||
// note: use custom cache
|
// note: use custom cache
|
||||||
SpirvType::Pointer {
|
SpirvType::Pointer {
|
||||||
def: ctx.type_pointer(pointee_type.def()),
|
def: ctx.type_pointer(StorageClass::Generic, pointee_type.def()),
|
||||||
pointee: Box::new(pointee_type),
|
pointee: Box::new(pointee_type),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +142,7 @@ fn trans_type<'tcx>(ctx: &mut FnCtx<'_, 'tcx>, ty: Ty<'tcx>) -> SpirvType {
|
|||||||
let pointee_type = trans_type(ctx, pointee_ty);
|
let pointee_type = trans_type(ctx, pointee_ty);
|
||||||
// note: use custom cache
|
// note: use custom cache
|
||||||
SpirvType::Pointer {
|
SpirvType::Pointer {
|
||||||
def: ctx.type_pointer(pointee_type.def()),
|
def: ctx.type_pointer(StorageClass::Generic, pointee_type.def()),
|
||||||
pointee: Box::new(pointee_type),
|
pointee: Box::new(pointee_type),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,10 +532,9 @@ fn trans_place<'tcx>(ctx: &mut FnCtx<'_, 'tcx>, place: &Place<'tcx>) -> (Word, S
|
|||||||
let pointer = if access_chain.is_empty() {
|
let pointer = if access_chain.is_empty() {
|
||||||
local.def
|
local.def
|
||||||
} else {
|
} else {
|
||||||
let result_ptr_type =
|
let result_ptr_type = ctx
|
||||||
ctx.ctx
|
.ctx
|
||||||
.spirv
|
.type_pointer(StorageClass::Function, result_type.def());
|
||||||
.type_pointer(None, StorageClass::Function, result_type.def());
|
|
||||||
ctx.ctx
|
ctx.ctx
|
||||||
.spirv
|
.spirv
|
||||||
.access_chain(result_ptr_type, None, local.def, access_chain)
|
.access_chain(result_ptr_type, None, local.def, access_chain)
|
||||||
|
@ -78,7 +78,7 @@ fn go(code: &str, expected: &str) {
|
|||||||
|
|
||||||
let cmd = Command::new("rustc")
|
let cmd = Command::new("rustc")
|
||||||
.args(&[
|
.args(&[
|
||||||
#[cfg(target_os = "unix")]
|
#[cfg(unix)]
|
||||||
"-Zcodegen-backend=target/debug/librustc_codegen_spirv.so",
|
"-Zcodegen-backend=target/debug/librustc_codegen_spirv.so",
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
"-Zcodegen-backend=target/debug/rustc_codegen_spirv.dll",
|
"-Zcodegen-backend=target/debug/rustc_codegen_spirv.dll",
|
||||||
|
Loading…
Reference in New Issue
Block a user