Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Commit c70cee8

Browse files
authored
Add flat attribute (#317)
* Add flat attribute * Document attributes
1 parent 130b457 commit c70cee8

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl<'tcx> CodegenCx<'tcx> {
185185
);
186186
has_location = false;
187187
}
188+
SpirvAttribute::Flat => {
189+
self.emit_global()
190+
.decorate(variable, Decoration::Flat, std::iter::empty());
191+
}
188192
_ => {}
189193
}
190194
}

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ impl Symbols {
337337
),
338338
("sampler", SpirvAttribute::Sampler),
339339
("block", SpirvAttribute::Block),
340+
("flat", SpirvAttribute::Flat),
340341
]
341342
.iter()
342343
.cloned();
@@ -453,6 +454,7 @@ pub enum SpirvAttribute {
453454
},
454455
Sampler,
455456
Block,
457+
Flat,
456458
}
457459

458460
// Note that we could mark the attr as used via cx.tcx.sess.mark_attr_used(attr), but unused

docs/src/attributes.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ When declaring inputs and outputs, sometimes you want to declare it as a "builti
2323

2424
Example:
2525

26-
```rust:
26+
```rust
2727
#[spirv(fragment)]
2828
fn main(
2929
#[spirv(position)] mut out_pos: Output<Vec4>,
@@ -38,11 +38,40 @@ A SPIR-V shader must declare where uniform variables are located with explicit i
3838

3939
Example:
4040

41-
```rust:
41+
```rust
4242
#[spirv(fragment)]
4343
fn main(
4444
#[spirv(descriptor_set = 2, binding = 5)] mut var: Uniform<Vec4>,
4545
) { }
4646
```
4747

4848
Both descriptor_set and binding take an integer argument that specifies the uniform's index.
49+
50+
## Block
51+
52+
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.
53+
54+
Example:
55+
56+
```rust
57+
#[spirv(block)]
58+
struct Thing {
59+
a: Vec4,
60+
b: Vec4,
61+
c: Vec4,
62+
}
63+
64+
#[spirv(fragment)]
65+
fn main(obj: PushConstant<ShaderConstants>) { }
66+
```
67+
68+
## Flat
69+
70+
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.
71+
72+
Example:
73+
74+
```rust
75+
#[spirv(fragment)]
76+
fn main(#[spirv(flat)] obj: Input<u32>) { }
77+
```

0 commit comments

Comments
 (0)