wgpu/tests/in/extra.wgsl
initial-algebra 602368d9f0
Support builtin(primitive_index) (#1097)
* Hack in support for PrimitiveID on Vulkan

* Rename to PrimitiveIndex and add preliminary support for GLSL, HLSL and MSL

* Implement as an extra WGSL built-in

* Update extra.wgsl outputs

* Run rustfmt; fix WGSL writer

* Add rustfmt changes I forgot

* Update extra.wgsl test output for WGSL fix

* Bump macOS version to 10.15 in validate-msl to support primitive_index
2021-07-16 22:18:20 -04:00

21 lines
462 B
WebGPU Shading Language

[[block]]
struct PushConstants {
index: u32;
double: vec2<f64>;
};
var<push_constant> pc: PushConstants;
struct FragmentIn {
[[location(0)]] color: vec4<f32>;
[[builtin(primitive_index)]] primitive_index: u32;
};
[[stage(fragment)]]
fn main(in: FragmentIn) -> [[location(0)]] vec4<f32> {
if (in.primitive_index % 2u == 0u) {
return in.color;
} else {
return vec4<f32>(vec3<f32>(1.0) - in.color.rgb, in.color.a);
}
}