forked from gfx-rs/wgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a not-yet-working vertex pulling flag to Metal pipelines.
This is an early effort to add infrastructure to support vertex pulling transformation of Metal shaders. It is *not* a working transformation that generates valid, useful shaders. It includes: 1) It adds a experimental_vertex_pulling_transform flag to msl::PipelineOptions. This flag defaults to false but can be forcibly set to true by naga tests. 2) When the flag is set, generated msl vertex shaders are passed an additional vertex id parameter, plus an additional parameter for each bound vertex buffer. 3) A new naga test is added which exercises this flag and demonstrates the effect of the transform. Future work will make the transformed shaders valid, and add tests that transformed shaders produce correct results.
- Loading branch information
Showing
8 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
( | ||
msl_pipeline: ( | ||
allow_and_force_point_size: false, | ||
experimental_vertex_pulling_transform: true, | ||
vertex_buffer_indexes: [], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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) -> 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// language: metal1.0 | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using metal::uint; | ||
|
||
struct VertexOutput { | ||
metal::float4 position; | ||
metal::float4 color; | ||
metal::float2 texcoord; | ||
}; | ||
struct VertexInput { | ||
metal::float4 position; | ||
metal::float3 normal; | ||
metal::float2 texcoord; | ||
}; | ||
|
||
metal::float4 do_lighting( | ||
metal::float4 position, | ||
metal::float3 normal | ||
) { | ||
return metal::float4(0.0); | ||
} | ||
|
||
struct render_vertexInput { | ||
metal::float4 position [[attribute(0)]]; | ||
metal::float3 normal [[attribute(1)]]; | ||
metal::float2 texcoord [[attribute(2)]]; | ||
}; | ||
struct render_vertexOutput { | ||
metal::float4 position [[position]]; | ||
metal::float4 color [[user(loc0), center_perspective]]; | ||
metal::float2 texcoord [[user(loc1), center_perspective]]; | ||
}; | ||
vertex render_vertexOutput render_vertex( | ||
render_vertexInput varyings [[stage_in]] | ||
, constant metal::float4x4& mvp_matrix [[user(fake0)]] | ||
, uint v_id [[vertex_id]] | ||
) { | ||
if (false) {return {};} | ||
const VertexInput v_in = { varyings.position, varyings.normal, varyings.texcoord }; | ||
VertexOutput v_out = {}; | ||
metal::float4x4 _e5 = mvp_matrix; | ||
v_out.position = v_in.position * _e5; | ||
metal::float4 _e10 = do_lighting(v_in.position, v_in.normal); | ||
v_out.color = _e10; | ||
v_out.texcoord = v_in.texcoord; | ||
VertexOutput _e13 = v_out; | ||
const auto _tmp = _e13; | ||
return render_vertexOutput { _tmp.position, _tmp.color, _tmp.texcoord }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters