mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Improve WGSL interpolation attributes (#1083)
* [wgsl-in] Map interpolate(..., center) to Sampling::Center * [wgsl-out] Improve interpolation attributes * [wgsl] Fix tests/in/interpolate.wgsl typo/format * [wgsl] Snapshot WGSL artefacts * [wgsl-out] Stack-only writing of interpolation
This commit is contained in:
@@ -324,23 +324,23 @@ impl<W: Write> Writer<W> {
|
||||
Attribute::Binding(id) => format!("binding({})", id),
|
||||
Attribute::Group(id) => format!("group({})", id),
|
||||
Attribute::Interpolate(interpolation, sampling) => {
|
||||
if interpolation.is_some() || sampling.is_some() {
|
||||
let interpolation_str = if let Some(interpolation) = interpolation {
|
||||
interpolation_str(interpolation)
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let sampling_str = if let Some(sampling) = sampling {
|
||||
// Center sampling is the default
|
||||
if sampling == crate::Sampling::Center {
|
||||
String::from("")
|
||||
} else {
|
||||
format!(",{}", sampling_str(sampling))
|
||||
}
|
||||
} else {
|
||||
String::from("")
|
||||
};
|
||||
format!("interpolate({}{})", interpolation_str, sampling_str)
|
||||
if sampling.is_some() && sampling != Some(crate::Sampling::Center) {
|
||||
format!(
|
||||
"interpolate({}, {})",
|
||||
interpolation_str(
|
||||
interpolation.unwrap_or(crate::Interpolation::Perspective)
|
||||
),
|
||||
sampling_str(sampling.unwrap_or(crate::Sampling::Center))
|
||||
)
|
||||
} else if interpolation.is_some()
|
||||
&& interpolation != Some(crate::Interpolation::Perspective)
|
||||
{
|
||||
format!(
|
||||
"interpolate({})",
|
||||
interpolation_str(
|
||||
interpolation.unwrap_or(crate::Interpolation::Perspective)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
String::from("")
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ pub fn map_interpolation(word: &str, span: Span) -> Result<crate::Interpolation,
|
||||
|
||||
pub fn map_sampling(word: &str, span: Span) -> Result<crate::Sampling, Error<'_>> {
|
||||
match word {
|
||||
"center" => Ok(crate::Sampling::Center),
|
||||
"centroid" => Ok(crate::Sampling::Centroid),
|
||||
"sample" => Ok(crate::Sampling::Sample),
|
||||
_ => Err(Error::UnknownAttribute(span)),
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//TODO: mere with "interface"?
|
||||
//TODO: merge with "interface"?
|
||||
|
||||
struct FragmentInput {
|
||||
[[builtin(position)]] position: vec4<f32>;
|
||||
[[location(0), interpolate(flat)]] flat : u32;
|
||||
[[location(1), interpolate(linear)]] linear : f32;
|
||||
[[location(2), interpolate(linear,centroid)]] linear_centroid : vec2<f32>;
|
||||
[[location(3), interpolate(linear,sample)]] linear_sample : vec3<f32>;
|
||||
[[location(2), interpolate(linear, centroid)]] linear_centroid : vec2<f32>;
|
||||
[[location(3), interpolate(linear, sample)]] linear_sample : vec3<f32>;
|
||||
[[location(4), interpolate(perspective)]] perspective : vec4<f32>;
|
||||
[[location(5), interpolate(perspective,centroid)]] perspective_centroid : f32;
|
||||
[[location(6), interpolate(perspective,sample)]] perspective_sample : f32;
|
||||
[[location(5), interpolate(perspective, centroid)]] perspective_centroid : f32;
|
||||
[[location(6), interpolate(perspective, sample)]] perspective_sample : f32;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
|
||||
@@ -4,7 +4,7 @@ struct ColorMaterial_color {
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
[[location(0), interpolate(perspective)]] o_Target: vec4<f32>;
|
||||
[[location(0)]] o_Target: vec4<f32>;
|
||||
};
|
||||
|
||||
var<private> v_Uv: vec2<f32>;
|
||||
|
||||
@@ -14,7 +14,7 @@ struct Sprite_size {
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] v_Uv: vec2<f32>;
|
||||
[[location(0)]] v_Uv: vec2<f32>;
|
||||
[[builtin(position)]] member: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] Vertex_Position: vec3<f32>, [[location(2), interpolate(perspective)]] Vertex_Uv: vec2<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] Vertex_Position: vec3<f32>, [[location(2)]] Vertex_Uv: vec2<f32>) -> VertexOutput {
|
||||
Vertex_Position1 = Vertex_Position;
|
||||
Vertex_Uv1 = Vertex_Uv;
|
||||
main1();
|
||||
|
||||
@@ -9,9 +9,9 @@ struct Transform {
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] v_Position: vec3<f32>;
|
||||
[[location(1), interpolate(perspective)]] v_Normal: vec3<f32>;
|
||||
[[location(2), interpolate(perspective)]] v_Uv: vec2<f32>;
|
||||
[[location(0)]] v_Position: vec3<f32>;
|
||||
[[location(1)]] v_Normal: vec3<f32>;
|
||||
[[location(2)]] v_Uv: vec2<f32>;
|
||||
[[builtin(position)]] member: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] Vertex_Position: vec3<f32>, [[location(1), interpolate(perspective)]] Vertex_Normal: vec3<f32>, [[location(2), interpolate(perspective)]] Vertex_Uv: vec2<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] Vertex_Position: vec3<f32>, [[location(1)]] Vertex_Normal: vec3<f32>, [[location(2)]] Vertex_Uv: vec2<f32>) -> VertexOutput {
|
||||
Vertex_Position1 = Vertex_Position;
|
||||
Vertex_Normal1 = Vertex_Normal;
|
||||
Vertex_Uv1 = Vertex_Uv;
|
||||
|
||||
@@ -9,7 +9,7 @@ struct VertexPushConstants {
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] frag_color: vec4<f32>;
|
||||
[[location(0)]] frag_color: vec4<f32>;
|
||||
[[builtin(position)]] member: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] position: vec2<f32>, [[location(1), interpolate(perspective)]] color: vec4<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] position: vec2<f32>, [[location(1)]] color: vec4<f32>) -> VertexOutput {
|
||||
position1 = position;
|
||||
color1 = color;
|
||||
main1();
|
||||
|
||||
@@ -53,7 +53,7 @@ struct StandardMaterial_emissive {
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
[[location(0), interpolate(perspective)]] o_Target: vec4<f32>;
|
||||
[[location(0)]] o_Target: vec4<f32>;
|
||||
};
|
||||
|
||||
var<private> v_WorldPosition1: vec3<f32>;
|
||||
@@ -842,7 +842,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main([[location(0), interpolate(perspective)]] v_WorldPosition: vec3<f32>, [[location(1), interpolate(perspective)]] v_WorldNormal: vec3<f32>, [[location(2), interpolate(perspective)]] v_Uv: vec2<f32>, [[location(3), interpolate(perspective)]] v_WorldTangent: vec4<f32>, [[builtin(front_facing)]] param: bool) -> FragmentOutput {
|
||||
fn main([[location(0)]] v_WorldPosition: vec3<f32>, [[location(1)]] v_WorldNormal: vec3<f32>, [[location(2)]] v_Uv: vec2<f32>, [[location(3)]] v_WorldTangent: vec4<f32>, [[builtin(front_facing)]] param: bool) -> FragmentOutput {
|
||||
v_WorldPosition1 = v_WorldPosition;
|
||||
v_WorldNormal1 = v_WorldNormal;
|
||||
v_Uv1 = v_Uv;
|
||||
|
||||
@@ -9,10 +9,10 @@ struct Transform {
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] v_WorldPosition: vec3<f32>;
|
||||
[[location(1), interpolate(perspective)]] v_WorldNormal: vec3<f32>;
|
||||
[[location(2), interpolate(perspective)]] v_Uv: vec2<f32>;
|
||||
[[location(3), interpolate(perspective)]] v_WorldTangent: vec4<f32>;
|
||||
[[location(0)]] v_WorldPosition: vec3<f32>;
|
||||
[[location(1)]] v_WorldNormal: vec3<f32>;
|
||||
[[location(2)]] v_Uv: vec2<f32>;
|
||||
[[location(3)]] v_WorldTangent: vec4<f32>;
|
||||
[[builtin(position)]] member: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -54,7 +54,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] Vertex_Position: vec3<f32>, [[location(1), interpolate(perspective)]] Vertex_Normal: vec3<f32>, [[location(2), interpolate(perspective)]] Vertex_Uv: vec2<f32>, [[location(3), interpolate(perspective)]] Vertex_Tangent: vec4<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] Vertex_Position: vec3<f32>, [[location(1)]] Vertex_Normal: vec3<f32>, [[location(2)]] Vertex_Uv: vec2<f32>, [[location(3)]] Vertex_Tangent: vec4<f32>) -> VertexOutput {
|
||||
Vertex_Position1 = Vertex_Position;
|
||||
Vertex_Normal1 = Vertex_Normal;
|
||||
Vertex_Uv1 = Vertex_Uv;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
struct FragmentOutput {
|
||||
[[location(0), interpolate(perspective)]] o_color: vec4<f32>;
|
||||
[[location(0)]] o_color: vec4<f32>;
|
||||
};
|
||||
|
||||
var<private> o_color: vec4<f32>;
|
||||
|
||||
@@ -12,7 +12,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] a_pos: vec2<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] a_pos: vec2<f32>) -> VertexOutput {
|
||||
a_pos1 = a_pos;
|
||||
main1();
|
||||
let _e3: vec4<f32> = gl_Position;
|
||||
|
||||
@@ -7,6 +7,6 @@ struct PushConstants {
|
||||
var<push_constant> pc: PushConstants;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main([[location(0), interpolate(perspective)]] color: vec4<f32>) -> [[location(0)]] vec4<f32> {
|
||||
fn main([[location(0)]] color: vec4<f32>) -> [[location(0)]] vec4<f32> {
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
struct VertexOutput {
|
||||
[[builtin(position)]] position: vec4<f32>;
|
||||
[[location(1), interpolate(perspective)]] varying: f32;
|
||||
[[location(1)]] varying: f32;
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
|
||||
@@ -2,11 +2,11 @@ struct FragmentInput {
|
||||
[[builtin(position)]] position: vec4<f32>;
|
||||
[[location(0), interpolate(flat)]] flat: u32;
|
||||
[[location(1), interpolate(linear)]] linear: f32;
|
||||
[[location(2), interpolate(linear,centroid)]] linear_centroid: vec2<f32>;
|
||||
[[location(3), interpolate(linear,sample)]] linear_sample: vec3<f32>;
|
||||
[[location(4), interpolate(perspective)]] perspective: vec4<f32>;
|
||||
[[location(5), interpolate(perspective,centroid)]] perspective_centroid: f32;
|
||||
[[location(6), interpolate(perspective,sample)]] perspective_sample: f32;
|
||||
[[location(2), interpolate(linear, centroid)]] linear_centroid: vec2<f32>;
|
||||
[[location(3), interpolate(linear, sample)]] linear_sample: vec3<f32>;
|
||||
[[location(4)]] perspective: vec4<f32>;
|
||||
[[location(5), interpolate(perspective, centroid)]] perspective_centroid: f32;
|
||||
[[location(6), interpolate(perspective, sample)]] perspective_sample: f32;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
|
||||
@@ -3,7 +3,7 @@ struct VertexOutput {
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
[[location(0), interpolate(perspective)]] o_color: vec4<f32>;
|
||||
[[location(0)]] o_color: vec4<f32>;
|
||||
};
|
||||
|
||||
var<private> gl_Position: vec4<f32>;
|
||||
|
||||
@@ -4,7 +4,7 @@ struct gl_PerVertex {
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] member: vec2<f32>;
|
||||
[[location(0)]] member: vec2<f32>;
|
||||
[[builtin(position)]] gl_Position: vec4<f32>;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] uv: vec2<f32>;
|
||||
[[location(0)]] uv: vec2<f32>;
|
||||
[[builtin(position)]] position: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ fn main([[location(0)]] pos: vec2<f32>, [[location(1)]] uv: vec2<f32>) -> Vertex
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main1([[location(0), interpolate(perspective)]] uv1: vec2<f32>) -> [[location(0)]] vec4<f32> {
|
||||
fn main1([[location(0)]] uv1: vec2<f32>) -> [[location(0)]] vec4<f32> {
|
||||
let color: vec4<f32> = textureSample(u_texture, u_sampler, uv1);
|
||||
if ((color.w == 0.0)) {
|
||||
discard;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
struct FragmentOutput {
|
||||
[[location(0), interpolate(perspective)]] o_color: vec4<f32>;
|
||||
[[location(0)]] o_color: vec4<f32>;
|
||||
};
|
||||
|
||||
var<private> v_uv: vec2<f32>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
struct VertexOutput {
|
||||
[[location(0), interpolate(perspective)]] v_uv: vec2<f32>;
|
||||
[[location(0)]] v_uv: vec2<f32>;
|
||||
[[builtin(position)]] member: vec4<f32>;
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ fn main1() {
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main([[location(0), interpolate(perspective)]] a_pos: vec2<f32>, [[location(1), interpolate(perspective)]] a_uv: vec2<f32>) -> VertexOutput {
|
||||
fn main([[location(0)]] a_pos: vec2<f32>, [[location(1)]] a_uv: vec2<f32>) -> VertexOutput {
|
||||
a_pos1 = a_pos;
|
||||
a_uv1 = a_uv;
|
||||
main1();
|
||||
|
||||
@@ -37,7 +37,7 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn fs_main([[location(0), interpolate(perspective)]] raw_normal: vec3<f32>, [[location(1), interpolate(perspective)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
|
||||
fn fs_main([[location(0)]] raw_normal: vec3<f32>, [[location(1)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
|
||||
var color: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
|
||||
var i: u32 = 0u;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
struct VertexOutput {
|
||||
[[builtin(position)]] position: vec4<f32>;
|
||||
[[location(0), interpolate(perspective)]] uv: vec3<f32>;
|
||||
[[location(0)]] uv: vec3<f32>;
|
||||
};
|
||||
|
||||
[[block]]
|
||||
|
||||
Reference in New Issue
Block a user