Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flat attribute #317

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>) { }
```