Skip to content

Commit

Permalink
Add flat attribute (#317)
Browse files Browse the repository at this point in the history
* Add flat attribute

* Document attributes
  • Loading branch information
khyperia committed Dec 4, 2020
1 parent 130b457 commit c70cee8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ impl<'tcx> CodegenCx<'tcx> {
);
has_location = false;
}
SpirvAttribute::Flat => {
self.emit_global()
.decorate(variable, Decoration::Flat, std::iter::empty());
}
_ => {}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/rustc_codegen_spirv/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl Symbols {
),
("sampler", SpirvAttribute::Sampler),
("block", SpirvAttribute::Block),
("flat", SpirvAttribute::Flat),
]
.iter()
.cloned();
Expand Down Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions docs/src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -38,11 +38,40 @@ 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>,
) { }
```

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>) { }
```

0 comments on commit c70cee8

Please sign in to comment.