wgpu/naga/tests/in/vertex-pulling-transform.wgsl
Brad Werth 9b7a965667 Add an experimental vertex pulling flag to Metal pipelines.
This proves a flag in msl::PipelineOptions that attempts to write all
Metal vertex entry points to use a vertex pulling technique. It does
this by:

1) Forcing the _buffer_sizes structure to be generated for all vertex
entry points. The structure has additional buffer_size members that
contain the byte sizes of the vertex buffers.
2) Adding new args to vertex entry points for the vertex id and/or
the instance id and for the bound buffers. If there is an existing
@builtin(vertex_index) or @builtin(instance_index) param, then no
duplicate arg is created.
3) Adding code at the beginning of the function for vertex entry points
to compare the vertex id or instance id against the lengths of all the
bound buffers, and force an early-exit if the bounds are violated.
4) Extracting the raw bytes from the vertex buffer(s) and unpacking
those bytes into the bound attributes with the expected types.
5) Replacing the varyings input and instead using the unpacked
attributes to fill any structs-as-args that are rebuilt in the entry
point.

A new naga test is added which exercises this flag and demonstrates the
effect of the transform. The msl generated by this test passes
validation.

Eventually this transformation will be the default, always-on behavior
for Metal pipelines, though the flag may remain so that naga
translation tests can be run with and without the tranformation.
2024-05-30 13:08:59 +02:00

33 lines
766 B
WebGPU Shading Language

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) color: vec4<f32>,
@location(1) texcoord: vec2<f32>,
}
struct VertexInput {
@location(0) position: vec4<f32>,
@location(1) normal: vec3<f32>,
@location(2) texcoord: vec2<f32>,
}
@group(0) @binding(0) var<uniform> mvp_matrix: mat4x4<f32>;
@vertex
fn render_vertex(
v_in: VertexInput,
@builtin(vertex_index) v_existing_id: u32,
) -> VertexOutput
{
var v_out: VertexOutput;
v_out.position = v_in.position * mvp_matrix;
v_out.color = do_lighting(v_in.position,
v_in.normal);
v_out.texcoord = v_in.texcoord;
return v_out;
}
fn do_lighting(position: vec4<f32>, normal: vec3<f32>) -> vec4<f32> {
// blah blah blah
return vec4<f32>(0);
}