Add flat attribute (#317)

* Add flat attribute

* Document attributes
This commit is contained in:
Ashley Hauck 2020-12-04 12:20:58 +01:00 committed by GitHub
parent 130b457c7b
commit c70cee8f97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View File

@ -185,6 +185,10 @@ impl<'tcx> CodegenCx<'tcx> {
);
has_location = false;
}
SpirvAttribute::Flat => {
self.emit_global()
.decorate(variable, Decoration::Flat, std::iter::empty());
}
_ => {}
}
}

View File

@ -337,6 +337,7 @@ impl Symbols {
),
("sampler", SpirvAttribute::Sampler),
("block", SpirvAttribute::Block),
("flat", SpirvAttribute::Flat),
]
.iter()
.cloned();
@ -453,6 +454,7 @@ pub enum SpirvAttribute {
},
Sampler,
Block,
Flat,
}
// Note that we could mark the attr as used via cx.tcx.sess.mark_attr_used(attr), but unused

View File

@ -23,7 +23,7 @@ When declaring inputs and outputs, sometimes you want to declare it as a "builti
Example:
```rust:
```rust
#[spirv(fragment)]
fn main(
#[spirv(position)] mut out_pos: Output<Vec4>,
@ -38,7 +38,7 @@ A SPIR-V shader must declare where uniform variables are located with explicit i
Example:
```rust:
```rust
#[spirv(fragment)]
fn main(
#[spirv(descriptor_set = 2, binding = 5)] mut var: Uniform<Vec4>,
@ -46,3 +46,32 @@ fn main(
```
Both descriptor_set and binding take an integer argument that specifies the uniform's index.
## Block
This attribute is a temporary quick fix before we implement a more fully-featured binding model. If you get validation errors about missing a Block decoration on a struct due to being used as uniform block data, try adding this attribute to the struct definition. If you get errors around the struct definition not being an aggregate, but rather the type of the field, try adding `#[repr(C)]` to the struct definition.
Example:
```rust
#[spirv(block)]
struct Thing {
a: Vec4,
b: Vec4,
c: Vec4,
}
#[spirv(fragment)]
fn main(obj: PushConstant<ShaderConstants>) { }
```
## Flat
The flat attribute corresponds to the flat keyword in glsl - in other words, the data is not interpolated across the triangle when invoking the fragment shader.
Example:
```rust
#[spirv(fragment)]
fn main(#[spirv(flat)] obj: Input<u32>) { }
```