Skip to content

Commit

Permalink
Update to upstream naga
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho authored and kvark committed Jan 22, 2022
1 parent 83d0d16 commit dcd07f0
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 175 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ default-members = ["wgpu", "wgpu-hal", "wgpu-info"]

[patch."https://github.com/gfx-rs/naga"]
#naga = { path = "../naga" }
naga = { git = "https://github.com/JCapucho/naga", branch = "glsl-out-push-constants-v2" }

[patch."https://github.com/zakarumych/gpu-descriptor"]
#gpu-descriptor = { path = "../gpu-descriptor/gpu-descriptor" }
Expand Down
12 changes: 7 additions & 5 deletions cts_runner/examples/hello-compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const numbers = [1, 4, 3, 295];

const device = await adapter.requestDevice();

const shaderCode = `[[block]]
const shaderCode = `@block
struct PrimeIndices {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
}; // this is used as both input and output for convenience
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> v_indices: PrimeIndices;
// The Collatz Conjecture states that for any integer n:
// If n is even, n = n/2
Expand Down Expand Up @@ -37,8 +38,9 @@ fn collatz_iterations(n_base: u32) -> u32{
}
return i;
}
[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}`;

Expand Down
3 changes: 2 additions & 1 deletion player/tests/data/empty.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[[stage(compute), workgroup_size(1)]]
@stage(compute)
@workgroup_size(1)
fn main() {
}
8 changes: 4 additions & 4 deletions player/tests/data/quad.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<f32> {
// hacky way to draw a large triangle
let tmp1 = i32(vertex_index) / 2;
let tmp2 = i32(vertex_index) & 1;
Expand All @@ -10,7 +10,7 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]]
return vec4<f32>(pos, 0.0, 1.0);
}

[[stage(fragment)]]
fn fs_main() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}
10 changes: 6 additions & 4 deletions player/tests/data/zero-init-buffer-for-binding.wgsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
struct InOutBuffer {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
};

[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> buffer: InOutBuffer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
buffer.data[global_id.x] = buffer.data[global_id.x] + global_id.x;
}
9 changes: 5 additions & 4 deletions player/tests/data/zero-init-texture-binding.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[[group(0), binding(0)]] var tex: texture_2d<f32>;
[[group(0), binding(1)]] var tex_storage: texture_storage_2d<rgba8uint, write>;
@group(0) @binding(0) var tex: texture_2d<f32>;
@group(0) @binding(1) var tex_storage: texture_storage_2d<rgba8uint, write>;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
}
2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ thiserror = "1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["span", "validate", "wgsl-in"]

Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ js-sys = { version = "0.3" }

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"

# DEV dependencies

[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-in"]

Expand Down
26 changes: 15 additions & 11 deletions wgpu-hal/examples/halmark/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,37 @@ struct Locals {
color: u32;
};

[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> globals: Globals;

[[group(1), binding(0)]]
@group(1)
@binding(0)
var<uniform> locals: Locals;

struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] color: vec4<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
@location(1) color: vec4<f32>;
};

[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vi: u32) -> VertexOutput {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput {
let tc = vec2<f32>(f32(vi & 1u), 0.5 * f32(vi & 2u));
let offset = vec2<f32>(tc.x * globals.size.x, tc.y * globals.size.y);
let pos = globals.mvp * vec4<f32>(locals.position + offset, 0.0, 1.0);
let color = vec4<f32>((vec4<u32>(locals.color) >> vec4<u32>(0u, 8u, 16u, 24u)) & vec4<u32>(255u)) / 255.0;
return VertexOutput(pos, tc, color);
}

[[group(0), binding(1)]]
@group(0)
@binding(1)
var texture: texture_2d<f32>;
[[group(0), binding(2)]]
@group(0)
@binding(2)
var sam: sampler;

[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color * textureSampleLevel(texture, sam, in.tex_coords, 0.0);
}
6 changes: 3 additions & 3 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ env_logger = "0.8"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
optional = true

# used to test all the example shaders
[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-in"]

[target.'cfg(target_arch = "wasm32")'.dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-out"]

Expand Down
13 changes: 7 additions & 6 deletions wgpu/examples/boids/compute.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ struct SimParams {
};

struct Particles {
particles : [[stride(16)]] array<Particle>;
particles : @stride(16) array<Particle>;
};

[[group(0), binding(0)]] var<uniform> params : SimParams;
[[group(0), binding(1)]] var<storage, read> particlesSrc : Particles;
[[group(0), binding(2)]] var<storage, read_write> particlesDst : Particles;
@group(0) @binding(0) var<uniform> params : SimParams;
@group(0) @binding(1) var<storage, read> particlesSrc : Particles;
@group(0) @binding(2) var<storage, read_write> particlesDst : Particles;

// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
[[stage(compute), workgroup_size(64)]]
fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
@stage(compute)
@workgroup_size(64)
fn main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>) {
let total = arrayLength(&particlesSrc.particles);
let index = global_invocation_id.x;
if (index >= total) {
Expand Down
14 changes: 7 additions & 7 deletions wgpu/examples/boids/draw.wgsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[stage(vertex)]]
@stage(vertex)
fn main_vs(
[[location(0)]] particle_pos: vec2<f32>,
[[location(1)]] particle_vel: vec2<f32>,
[[location(2)]] position: vec2<f32>,
) -> [[builtin(position)]] vec4<f32> {
@location(0) particle_pos: vec2<f32>,
@location(1) particle_vel: vec2<f32>,
@location(2) position: vec2<f32>,
) -> @builtin(position) vec4<f32> {
let angle = -atan2(particle_vel.x, particle_vel.y);
let pos = vec2<f32>(
position.x * cos(angle) - position.y * sin(angle),
Expand All @@ -12,7 +12,7 @@ fn main_vs(
return vec4<f32>(pos + particle_pos, 0.0, 1.0);
}

[[stage(fragment)]]
fn main_fs() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn main_fs() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}
16 changes: 8 additions & 8 deletions wgpu/examples/conservative-raster/triangle_and_lines.wgsl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<f32> {
let i: i32 = i32(vertex_index % 3u);
let x: f32 = f32(i - 1) * 0.75;
let y: f32 = f32((i & 1) * 2 - 1) * 0.75 + x * 0.2 + 0.1;
return vec4<f32>(x, y, 0.0, 1.0);
}

[[stage(fragment)]]
fn fs_main_red() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_red() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}

[[stage(fragment)]]
fn fs_main_blue() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_blue() -> @location(0) vec4<f32> {
return vec4<f32>(0.13, 0.31, 0.85, 1.0); // cornflower blue in linear space
}

[[stage(fragment)]]
fn fs_main_white() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_white() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}
20 changes: 11 additions & 9 deletions wgpu/examples/conservative-raster/upscale.wgsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
};

[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
let x: f32 = f32(i32(vertex_index & 1u) << 2u) - 1.0;
let y: f32 = f32(i32(vertex_index & 2u) << 1u) - 1.0;
var output: VertexOutput;
Expand All @@ -13,12 +13,14 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
return output;
}

[[group(0), binding(0)]]
@group(0)
@binding(0)
var r_color: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_sampler: sampler;

[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}
}
24 changes: 13 additions & 11 deletions wgpu/examples/cube/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
@location(0) tex_coord: vec2<f32>;
@builtin(position) position: vec4<f32>;
};

struct Locals {
transform: mat4x4<f32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> r_locals: Locals;

[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec4<f32>,
[[location(1)]] tex_coord: vec2<f32>,
@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;
}

[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_color: texture_2d<u32>;

[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(in.tex_coord * 256.0), 0);
let v = f32(tex.x) / 255.0;
return vec4<f32>(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0);
}

[[stage(fragment)]]
fn fs_wire() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_wire() -> @location(0) vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}
10 changes: 6 additions & 4 deletions wgpu/examples/hello-compute/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
struct PrimeIndices {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
}; // this is used as both input and output for convenience

[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> v_indices: PrimeIndices;

// The Collatz Conjecture states that for any integer n:
Expand Down Expand Up @@ -34,7 +35,8 @@ fn collatz_iterations(n_base: u32) -> u32{
return i;
}

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}
Loading

0 comments on commit dcd07f0

Please sign in to comment.