Update to naga-14

This commit is contained in:
Dzmitry Malyshau committed 2021-03-14 00:50:35 -05:00
1 parent b3efd07b20
commit 0cccf9ccee
13 files changed
+147 -194

No files matched your search

+5 -5
View File
@@ -26,20 +26,20 @@ webgl = ["wgc"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "0fa52d3826ec8fe8f6177a558922085fe7d0e0cc"
rev = "5e15980bb53d2a5c24546dab640dcc72d211bd36"
features = ["raw-window-handle", "cross"]
[target.'cfg(target_arch = "wasm32")'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "0fa52d3826ec8fe8f6177a558922085fe7d0e0cc"
rev = "5e15980bb53d2a5c24546dab640dcc72d211bd36"
features = ["raw-window-handle", "cross"]
optional = true
[dependencies.wgt]
package = "wgpu-types"
git = "https://github.com/gfx-rs/wgpu"
rev = "0fa52d3826ec8fe8f6177a558922085fe7d0e0cc"
rev = "5e15980bb53d2a5c24546dab640dcc72d211bd36"
[dependencies]
arrayvec = "0.5"
@@ -68,13 +68,13 @@ wgpu-subscriber = "0.1"
# used to test all the example shaders
[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
tag = "gfx-13"
tag = "gfx-14"
features = ["wgsl-in"]
# used to generate SPIR-V for the Web target
[target.'cfg(target_arch = "wasm32")'.dependencies.naga]
git = "https://github.com/gfx-rs/naga"
tag = "gfx-13"
tag = "gfx-14"
features = ["wgsl-in", "spv-out"]
[[example]]
+2 -4
View File
@@ -27,12 +27,10 @@ struct Particles {
[[group(0), binding(1)]] var<storage> particlesSrc : [[access(read)]] Particles;
[[group(0), binding(2)]] var<storage> particlesDst : [[access(read_write)]] Particles;
[[builtin(global_invocation_id)]] var gl_GlobalInvocationID : vec3<u32>;
// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
[[stage(compute), workgroup_size(64)]]
fn main() {
const index : u32 = gl_GlobalInvocationID.x;
fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
const index : u32 = global_invocation_id.x;
if (index >= NUM_PARTICLES) {
return;
}
+11 -19
View File
@@ -1,26 +1,18 @@
[[location(0)]]
var<in> in_particle_pos: vec2<f32>;
[[location(1)]]
var<in> in_particle_vel: vec2<f32>;
[[location(2)]]
var<in> in_position: vec2<f32>;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
[[stage(vertex)]]
fn main() {
const angle: f32 = -atan2(in_particle_vel.x, in_particle_vel.y);
fn main(
[[location(0)]] particle_pos: vec2<f32>,
[[location(1)]] particle_vel: vec2<f32>,
[[location(2)]] position: vec2<f32>,
) -> [[builtin(position)]] vec4<f32> {
const angle: f32 = -atan2(particle_vel.x, particle_vel.y);
const pos: vec2<f32> = vec2<f32>(
in_position.x * cos(angle) - in_position.y * sin(angle),
in_position.x * sin(angle) + in_position.y * cos(angle)
position.x * cos(angle) - position.y * sin(angle),
position.x * sin(angle) + position.y * cos(angle)
);
out_position = vec4<f32>(pos + in_particle_pos, 0.0, 1.0);
return vec4<f32>(pos + particle_pos, 0.0, 1.0);
}
[[location(0)]]
var<out> out_color: vec4<f32>;
[[stage(fragment)]]
fn main() {
out_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
fn main() -> [[location(0)]] vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}
+16 -23
View File
@@ -1,11 +1,7 @@
[[location(0)]]
var<in> in_position: vec4<f32>;
[[location(1)]]
var<in> in_tex_coord_vs: vec2<f32>;
[[location(0)]]
var<out> out_tex_coord: vec2<f32>;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
};
[[block]]
struct Locals {
@@ -15,30 +11,27 @@ struct Locals {
var r_locals: Locals;
[[stage(vertex)]]
fn vs_main() {
out_tex_coord = in_tex_coord_vs;
out_position = r_locals.transform * in_position;
fn vs_main(
[[location(0)]] position: vec4<f32>,
[[location(1)]] tex_coord: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = tex_coord;
out.position = r_locals.transform * position;
return out;
}
[[location(0)]]
var<in> in_tex_coord_fs: vec2<f32>;
[[location(0)]]
var<out> out_color: vec4<f32>;
[[group(0), binding(1)]]
var r_color: texture_2d<f32>;
[[group(0), binding(2)]]
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main() {
var tex: vec4<f32> = textureSample(r_color, r_sampler, in_tex_coord_fs);
out_color = tex;
//TODO: support `length` and `mix` functions
//var mag: f32 = length(in_tex_coord_fs-vec2<f32>(0.5, 0.5));
//out_color = vec4<f32>(mix(tex.xyz, vec3<f32>(0.0, 0.0, 0.0), mag*mag), 1.0);
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coord);
}
[[stage(fragment)]]
fn fs_wire() {
out_color = vec4<f32>(0.0, 0.5, 0.0, 0.5);
fn fs_wire() -> [[location(0)]] vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}
+1 -4
View File
@@ -1,6 +1,3 @@
[[builtin(global_invocation_id)]]
var global_id: vec3<u32>;
[[block]]
struct PrimeIndices {
data: [[stride(4)]] array<u32>;
@@ -34,6 +31,6 @@ fn collatz_iterations(n_base: u32) -> u32{
}
[[stage(compute), workgroup_size(1)]]
fn main() {
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}
+4 -12
View File
@@ -1,19 +1,11 @@
[[builtin(vertex_index)]]
var<in> in_vertex_index: u32;
[[builtin(position)]]
var<out> out_pos: vec4<f32>;
[[stage(vertex)]]
fn vs_main() {
fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
var x: f32 = f32(i32(in_vertex_index) - 1);
var y: f32 = f32(i32(in_vertex_index & 1) * 2 - 1);
out_pos = vec4<f32>(x, y, 0.0, 1.0);
return vec4<f32>(x, y, 0.0, 1.0);
}
[[location(0)]]
var<out> out_color: vec4<f32>;
[[stage(fragment)]]
fn fs_main() {
out_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
fn fs_main() -> [[location(0)]] vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
+3 -1
View File
@@ -32,7 +32,9 @@ impl ViewportDesc {
let sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: adapter.get_swap_chain_preferred_format(&self.surface).unwrap(),
format: adapter
.get_swap_chain_preferred_format(&self.surface)
.unwrap(),
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
+16 -20
View File
@@ -1,36 +1,32 @@
[[builtin(vertex_index)]]
var<in> in_vertex_index: u32;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
[[location(0)]]
var<out> out_tex_coords_vs: vec2<f32>;
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
[[stage(vertex)]]
fn vs_main() {
var x: i32 = i32(in_vertex_index) / 2;
var y: i32 = i32(in_vertex_index) & 1;
out_tex_coords_vs = vec2<f32>(
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
var x: i32 = i32(vertex_index) / 2;
var y: i32 = i32(vertex_index) & 1;
const tc: vec2<f32> = vec2<f32>(
f32(x) * 2.0,
f32(y) * 2.0
);
out_position = vec4<f32>(
out_tex_coords_vs.x * 2.0 - 1.0,
1.0 - out_tex_coords_vs.y * 2.0,
out.position = vec4<f32>(
tc.x * 2.0 - 1.0,
1.0 - tc.y * 2.0,
0.0, 1.0
);
out.tex_coords = tc;
return out;
}
[[location(0)]]
var<in> in_tex_coord_fs: vec2<f32>;
[[location(0)]]
var<out> out_color_fs: vec4<f32>;
[[group(0), binding(0)]]
var r_color: texture_2d<f32>;
[[group(0), binding(1)]]
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main() {
out_color_fs = textureSample(r_color, r_sampler, in_tex_coord_fs);
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}
+13 -18
View File
@@ -1,9 +1,7 @@
[[builtin(vertex_index)]]
var<in> in_vertex_index: u32;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
[[location(0)]]
var<out> out_tex_coords_vs: vec2<f32>;
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
[[block]]
struct Locals {
@@ -13,26 +11,23 @@ struct Locals {
var r_data: Locals;
[[stage(vertex)]]
fn vs_main() {
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
var pos: vec2<f32> = vec2<f32>(
100.0 * (1.0 - f32(in_vertex_index & 2u)),
1000.0 * f32(in_vertex_index & 1u)
100.0 * (1.0 - f32(vertex_index & 2u)),
1000.0 * f32(vertex_index & 1u)
);
out_tex_coords_vs = 0.05 * pos + vec2<f32>(0.5, 0.5);
out_position = r_data.transform * vec4<f32>(pos, 0.0, 1.0);
var out: VertexOutput;
out.tex_coords = 0.05 * pos + vec2<f32>(0.5, 0.5);
out.position = r_data.transform * vec4<f32>(pos, 0.0, 1.0);
return out;
}
[[location(0)]]
var<in> in_tex_coord_fs: vec2<f32>;
[[location(0)]]
var<out> out_color_fs: vec4<f32>;
[[group(0), binding(1)]]
var r_color: texture_2d<f32>;
[[group(0), binding(2)]]
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main() {
out_color_fs = textureSample(r_color, r_sampler, in_tex_coord_fs);
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}
+14 -18
View File
@@ -1,24 +1,20 @@
[[location(0)]]
var<in> in_position: vec2<f32>;
[[location(1)]]
var<in> in_color_vs: vec4<f32>;
[[location(0)]]
var<out> out_color_vs: vec4<f32>;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
struct VertexOutput {
[[location(0)]] color: vec4<f32>;
[[builtin(position)]] position: vec4<f32>;
};
[[stage(vertex)]]
fn vs_main() {
out_position = vec4<f32>(in_position, 0.0, 1.0);
out_color_vs = in_color_vs;
fn vs_main(
[[location(0)]] position: vec2<f32>,
[[location(1)]] color: vec4<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = vec4<f32>(position, 0.0, 1.0);
out.color = color;
return out;
}
[[location(0)]]
var<in> in_color_fs: vec4<f32>;
[[location(0)]]
var<out> out_color_fs: vec4<f32>;
[[stage(fragment)]]
fn fs_main() {
out_color_fs = in_color_fs;
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
return in.color;
}
+22 -31
View File
@@ -1,8 +1,3 @@
[[location(0)]]
var<in> in_position: vec4<i32>;
[[builtin(position)]]
var<out> out_position: vec4<f32>;
[[block]]
struct Globals {
view_proj: mat4x4<f32>;
@@ -22,25 +17,28 @@ struct Entity {
var<uniform> u_entity: Entity;
[[stage(vertex)]]
fn vs_bake() {
out_position = u_globals.view_proj * u_entity.world * vec4<f32>(in_position);
fn vs_bake([[location(0)]] position: vec4<i32>) -> [[builtin(position)]] vec4<f32> {
return u_globals.view_proj * u_entity.world * vec4<f32>(position);
}
[[location(1)]]
var<in> in_normal: vec4<i32>;
[[location(0)]]
var<out> out_normal_vs: vec3<f32>;
[[location(1)]]
var<out> out_position_vs: vec4<f32>;
struct VertexOutput {
[[builtin(position)]] proj_position: vec4<f32>;
[[location(0)]] world_normal: vec3<f32>;
[[location(1)]] world_position: vec4<f32>;
};
[[stage(vertex)]]
fn vs_main() {
fn vs_main(
[[location(0)]] position: vec4<i32>,
[[location(1)]] normal: vec4<i32>,
) -> VertexOutput {
const w: mat4x4<f32> = u_entity.world;
out_normal_vs = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(in_normal.xyz);
out_position_vs = u_entity.world * vec4<f32>(in_position);
out_position = u_globals.view_proj * out_position_vs;
const world_pos: vec4<f32> = u_entity.world * vec4<f32>(position);
var out: VertexOutput;
out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
out.world_position = world_pos;
out.proj_position = u_globals.view_proj * world_pos;
return out;
}
// fragment shader
@@ -77,19 +75,12 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
return textureSampleCompare(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction);
}
[[location(0)]]
var<in> in_normal_fs: vec3<f32>;
[[location(1)]]
var<in> in_position_fs: vec4<f32>;
[[location(0)]]
var<out> out_color_fs: vec4<f32>;
const c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
const c_max_lights: u32 = 10u;
[[stage(fragment)]]
fn fs_main() {
const normal: vec3<f32> = normalize(in_normal_fs);
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
const normal: vec3<f32> = normalize(in.world_normal);
// accumulate color
var color: vec3<f32> = c_ambient;
var i: u32 = 0u;
@@ -99,9 +90,9 @@ fn fs_main() {
}
const light: Light = s_lights.data[i];
// project into the light space
const shadow: f32 = fetch_shadow(i, light.proj * in_position_fs);
const shadow: f32 = fetch_shadow(i, light.proj * in.world_position);
// compute Lambertian diffuse term
const light_dir: vec3<f32> = normalize(light.pos.xyz - in_position_fs.xyz);
const light_dir: vec3<f32> = normalize(light.pos.xyz - in.world_position.xyz);
const diffuse: f32 = max(0.0, dot(normal, light_dir));
// add light contribution
color = color + shadow * diffuse * light.color.xyz;
@@ -110,5 +101,5 @@ fn fs_main() {
}
}
// multiply the light by material color
out_color_fs = vec4<f32>(color, 1.0) * u_entity.color;
return vec4<f32>(color, 1.0) * u_entity.color;
}
+34 -29
View File
@@ -1,7 +1,7 @@
[[builtin(position)]]
var<out> out_position: vec4<f32>;
[[location(0)]] var<out> out_uv: vec3<f32>;
[[builtin(vertex_index)]] var<in> in_vertex_index: u32;
struct SkyOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] uv: vec3<f32>;
};
[[block]]
struct Data {
@@ -18,10 +18,10 @@ struct Data {
var r_data: Data;
[[stage(vertex)]]
fn vs_sky() {
fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput {
// hacky way to draw a large triangle
var tmp1: i32 = i32(in_vertex_index) / 2;
var tmp2: i32 = i32(in_vertex_index) & 1;
var tmp1: i32 = i32(vertex_index) / 2;
var tmp2: i32 = i32(vertex_index) & 1;
const pos: vec4<f32> = vec4<f32>(
f32(tmp1) * 4.0 - 1.0,
f32(tmp2) * 4.0 - 1.0,
@@ -31,21 +31,30 @@ fn vs_sky() {
// transposition = inversion for this orthonormal matrix
const inv_model_view: mat3x3<f32> = transpose(mat3x3<f32>(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz));
var unprojected: vec4<f32> = r_data.proj_inv * pos; //TODO: const
out_uv = inv_model_view * unprojected.xyz;
out_position = pos;
const unprojected: vec4<f32> = r_data.proj_inv * pos;
var out: SkyOutput;
out.uv = inv_model_view * unprojected.xyz;
out.position = pos;
return out;
}
[[location(0)]] var<in> in_pos: vec3<f32>;
[[location(1)]] var<in> in_normal: vec3<f32>;
[[location(1)]] var<out> out_normal: vec3<f32>;
[[location(3)]] var<out> out_view: vec3<f32>;
struct EntityOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(3)]] view: vec3<f32>;
};
[[stage(vertex)]]
fn vs_entity() {
out_normal = in_normal;
out_view = in_pos - r_data.cam_pos.xyz;
out_position = r_data.proj * r_data.view * vec4<f32>(in_pos, 1.0);
fn vs_entity(
[[location(0)]] pos: vec3<f32>,
[[location(1)]] normal: vec3<f32>,
) -> EntityOutput {
var out: EntityOutput;
out.normal = normal;
out.view = pos - r_data.cam_pos.xyz;
out.position = r_data.proj * r_data.view * vec4<f32>(pos, 1.0);
return out;
}
[[group(0), binding(1)]]
@@ -53,21 +62,17 @@ var r_texture: texture_cube<f32>;
[[group(0), binding(2)]]
var r_sampler: sampler;
[[location(0)]] var<in> in_uv: vec3<f32>;
[[location(0)]] var<out> out_color: vec4<f32>;
[[location(3)]] var<in> in_view: vec3<f32>;
[[stage(fragment)]]
fn fs_sky() {
out_color = textureSample(r_texture, r_sampler, in_uv);
fn fs_sky(in: SkyOutput) -> [[location(0)]] vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
}
[[stage(fragment)]]
fn fs_entity() {
const incident: vec3<f32> = normalize(in_view);
const normal: vec3<f32> = normalize(in_normal);
fn fs_entity(in: EntityOutput) -> [[location(0)]] vec4<f32> {
const incident: vec3<f32> = normalize(in.view);
const normal: vec3<f32> = normalize(in.normal);
const reflected: vec3<f32> = incident - 2.0 * dot(normal, incident) * normal;
var reflected_color: vec4<f32> = textureSample(r_texture, r_sampler, reflected);
out_color = vec4<f32>(0.1, 0.1, 0.1, 0.1) + 0.5 * reflected_color;
const reflected_color: vec4<f32> = textureSample(r_texture, r_sampler, reflected);
return vec4<f32>(0.1, 0.1, 0.1, 0.1) + 0.5 * reflected_color;
}
+6 -10
View File
@@ -171,7 +171,7 @@ mod pass_impl {
}
fn write_timestamp(&mut self, query_set: &wgc::id::QuerySetId, query_index: u32) {
unsafe { wgpu_compute_pass_write_timestamp(self, *query_set, query_index) }
wgpu_compute_pass_write_timestamp(self, *query_set, query_index)
}
fn begin_pipeline_statistics_query(
@@ -179,13 +179,11 @@ mod pass_impl {
query_set: &wgc::id::QuerySetId,
query_index: u32,
) {
unsafe {
wgpu_compute_pass_begin_pipeline_statistics_query(self, *query_set, query_index)
}
wgpu_compute_pass_begin_pipeline_statistics_query(self, *query_set, query_index)
}
fn end_pipeline_statistics_query(&mut self) {
unsafe { wgpu_compute_pass_end_pipeline_statistics_query(self) }
wgpu_compute_pass_end_pipeline_statistics_query(self)
}
fn dispatch(&mut self, x: u32, y: u32, z: u32) {
@@ -380,7 +378,7 @@ mod pass_impl {
}
fn write_timestamp(&mut self, query_set: &wgc::id::QuerySetId, query_index: u32) {
unsafe { wgpu_render_pass_write_timestamp(self, *query_set, query_index) }
wgpu_render_pass_write_timestamp(self, *query_set, query_index)
}
fn begin_pipeline_statistics_query(
@@ -388,13 +386,11 @@ mod pass_impl {
query_set: &wgc::id::QuerySetId,
query_index: u32,
) {
unsafe {
wgpu_render_pass_begin_pipeline_statistics_query(self, *query_set, query_index)
}
wgpu_render_pass_begin_pipeline_statistics_query(self, *query_set, query_index)
}
fn end_pipeline_statistics_query(&mut self) {
unsafe { wgpu_render_pass_end_pipeline_statistics_query(self) }
wgpu_render_pass_end_pipeline_statistics_query(self)
}
fn execute_bundles<'a, I: Iterator<Item = &'a wgc::id::RenderBundleId>>(