From d4ec962a7917532f353ceac0d97f894b63d55690 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Sat, 19 Dec 2020 22:54:56 +0100 Subject: [PATCH] Add `location` decoration attribute --- crates/rustc_codegen_spirv/src/codegen_cx/entry.rs | 7 ++++++- crates/rustc_codegen_spirv/src/symbols.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs index 08cc9bdd0d..2350bf05f9 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs @@ -169,6 +169,11 @@ impl<'tcx> CodegenCx<'tcx> { ); has_location = false; } + SpirvAttribute::Location(index) => { + // Overwrite the current location value for the given storage class. + // The decoration will be assigned below. + decoration_locations.insert(storage_class, index); + } SpirvAttribute::DescriptorSet(index) => { self.emit_global().decorate( variable, @@ -195,7 +200,7 @@ impl<'tcx> CodegenCx<'tcx> { // Assign locations from left to right, incrementing each storage class // individually. // TODO: Is this right for UniformConstant? Do they share locations with - // input/outpus? + // input/outputs? if has_location { let location = decoration_locations .entry(storage_class) diff --git a/crates/rustc_codegen_spirv/src/symbols.rs b/crates/rustc_codegen_spirv/src/symbols.rs index 229fcd569b..1ae6421843 100644 --- a/crates/rustc_codegen_spirv/src/symbols.rs +++ b/crates/rustc_codegen_spirv/src/symbols.rs @@ -30,6 +30,7 @@ pub struct Symbols { pub spirv13: Symbol, pub spirv14: Symbol, pub spirv15: Symbol, + location: Symbol, descriptor_set: Symbol, binding: Symbol, image: Symbol, @@ -383,6 +384,7 @@ impl Symbols { spirv13: Symbol::intern("spirv1.3"), spirv14: Symbol::intern("spirv1.4"), spirv15: Symbol::intern("spirv1.5"), + location: Symbol::intern("location"), descriptor_set: Symbol::intern("descriptor_set"), binding: Symbol::intern("binding"), image: Symbol::intern("image"), @@ -442,6 +444,7 @@ pub enum SpirvAttribute { Builtin(BuiltIn), StorageClass(StorageClass), Entry(Entry), + Location(u32), DescriptorSet(u32), Binding(u32), ReallyUnsafeIgnoreBitcasts, @@ -499,6 +502,11 @@ pub fn parse_attrs( Some(x) => Some(SpirvAttribute::DescriptorSet(x)), None => None, } + } else if arg.has_name(cx.sym.location) { + match parse_attr_int_value(cx, arg) { + Some(x) => Some(SpirvAttribute::Location(x)), + None => None, + } } else if arg.has_name(cx.sym.binding) { match parse_attr_int_value(cx, arg) { Some(x) => Some(SpirvAttribute::Binding(x)),