Update examples for recent WGSL changes
* Use new entry point IO syntax * Use `let` instead of `const` * Remove `-> void` from function headers Bug: dawn:755 Change-Id: I39b5687a342ea2298c3d2e85517c9b8d9017727e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47500 Commit-Queue: James Price <jrprice@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
f3fe648675
commit
9e0debd91e
|
@ -66,11 +66,12 @@ void init() {
|
|||
};
|
||||
[[set(0), binding(0)]] var<uniform> c : Constants;
|
||||
|
||||
[[location(0)]] var<out> v_color : vec4<f32>;
|
||||
[[builtin(vertex_idx)]] var<in> VertexIndex : u32;
|
||||
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||
struct VertexOut {
|
||||
[[location(0)]] v_color : vec4<f32>;
|
||||
[[builtin(position)]] Position : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]] fn main() {
|
||||
[[stage(vertex)]] fn main([[builtin(vertex_idx)]] VertexIndex : u32) -> VertexOut {
|
||||
var positions : array<vec4<f32>, 3> = array<vec4<f32>, 3>(
|
||||
vec4<f32>( 0.0, 0.1, 0.0, 1.0),
|
||||
vec4<f32>(-0.1, -0.1, 0.0, 1.0),
|
||||
|
@ -97,22 +98,22 @@ void init() {
|
|||
|
||||
var xpos : f32 = position.x * c.scale;
|
||||
var ypos : f32 = position.y * c.scale;
|
||||
const angle : f32 = 3.14159 * 2.0 * fade;
|
||||
const xrot : f32 = xpos * cos(angle) - ypos * sin(angle);
|
||||
const yrot : f32 = xpos * sin(angle) + ypos * cos(angle);
|
||||
let angle : f32 = 3.14159 * 2.0 * fade;
|
||||
let xrot : f32 = xpos * cos(angle) - ypos * sin(angle);
|
||||
let yrot : f32 = xpos * sin(angle) + ypos * cos(angle);
|
||||
xpos = xrot + c.offsetX;
|
||||
ypos = yrot + c.offsetY;
|
||||
|
||||
v_color = vec4<f32>(fade, 1.0 - fade, 0.0, 1.0) + color;
|
||||
Position = vec4<f32>(xpos, ypos, 0.0, 1.0);
|
||||
var output : VertexOut;
|
||||
output.v_color = vec4<f32>(fade, 1.0 - fade, 0.0, 1.0) + color;
|
||||
output.Position = vec4<f32>(xpos, ypos, 0.0, 1.0);
|
||||
return output;
|
||||
})");
|
||||
|
||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||
[[location(0)]] var<in> v_color : vec4<f32>;
|
||||
|
||||
[[stage(fragment)]] fn main() {
|
||||
FragColor = v_color;
|
||||
[[stage(fragment)]] fn main([[location(0)]] v_color : vec4<f32>)
|
||||
-> [[location(0)]] vec4<f32> {
|
||||
return v_color;
|
||||
})");
|
||||
|
||||
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
|
||||
|
|
|
@ -37,24 +37,21 @@ void init() {
|
|||
wgpuSwapChainConfigure(swapchain, swapChainFormat, WGPUTextureUsage_RenderAttachment, 640, 480);
|
||||
|
||||
const char* vs =
|
||||
"[[builtin(vertex_index)]] var<in> VertexIndex : u32;\n"
|
||||
"[[builtin(position)]] var<out> Position : vec4<f32>;\n"
|
||||
"const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(\n"
|
||||
"let pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(\n"
|
||||
" vec2<f32>( 0.0, 0.5),\n"
|
||||
" vec2<f32>(-0.5, -0.5),\n"
|
||||
" vec2<f32>( 0.5, -0.5)\n"
|
||||
");\n"
|
||||
"[[stage(vertex)]] fn main() {\n"
|
||||
" Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);\n"
|
||||
" return;\n"
|
||||
"[[stage(vertex)]] fn main(\n"
|
||||
" [[builtin(vertex_index)]] VertexIndex : u32\n"
|
||||
") -> [[builtin(position)]] vec4<f32> {\n"
|
||||
" return vec4<f32>(pos[VertexIndex], 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
WGPUShaderModule vsModule = utils::CreateShaderModule(device, vs).Release();
|
||||
|
||||
const char* fs =
|
||||
"[[location(0)]] var<out> fragColor : vec4<f32>;\n"
|
||||
"[[stage(fragment)]] fn main() {\n"
|
||||
" fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);\n"
|
||||
" return;\n"
|
||||
"[[stage(fragment)]] fn main() -> [[location(0)]] vec4<f32> {\n"
|
||||
" return vec4<f32>(1.0, 0.0, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
WGPUShaderModule fsModule = utils::CreateShaderModule(device, fs).Release();
|
||||
|
||||
|
|
|
@ -96,28 +96,26 @@ void initBuffers() {
|
|||
|
||||
void initRender() {
|
||||
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<in> a_particlePos : vec2<f32>;
|
||||
[[location(1)]] var<in> a_particleVel : vec2<f32>;
|
||||
[[location(2)]] var<in> a_pos : vec2<f32>;
|
||||
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||
struct VertexIn {
|
||||
[[location(0)]] a_particlePos : vec2<f32>;
|
||||
[[location(1)]] a_particleVel : vec2<f32>;
|
||||
[[location(2)]] a_pos : vec2<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() {
|
||||
var angle : f32 = -atan2(a_particleVel.x, a_particleVel.y);
|
||||
fn main(input : VertexIn) -> [[builtin(position)]] vec4<f32> {
|
||||
var angle : f32 = -atan2(input.a_particleVel.x, input.a_particleVel.y);
|
||||
var pos : vec2<f32> = vec2<f32>(
|
||||
(a_pos.x * cos(angle)) - (a_pos.y * sin(angle)),
|
||||
(a_pos.x * sin(angle)) + (a_pos.y * cos(angle)));
|
||||
Position = vec4<f32>(pos + a_particlePos, 0.0, 1.0);
|
||||
return;
|
||||
(input.a_pos.x * cos(angle)) - (input.a_pos.y * sin(angle)),
|
||||
(input.a_pos.x * sin(angle)) + (input.a_pos.y * cos(angle)));
|
||||
return vec4<f32>(pos + input.a_particlePos, 0.0, 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
FragColor = vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
return;
|
||||
fn main() -> [[location(0)]] vec4<f32> {
|
||||
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
|
@ -170,11 +168,10 @@ void initSim() {
|
|||
[[binding(0), group(0)]] var<uniform> params : SimParams;
|
||||
[[binding(1), group(0)]] var<storage> particlesA : [[access(read)]] Particles;
|
||||
[[binding(2), group(0)]] var<storage> particlesB : [[access(read_write)]] Particles;
|
||||
[[builtin(global_invocation_id)]] var<in> GlobalInvocationID : vec3<u32>;
|
||||
|
||||
// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
|
||||
[[stage(compute)]]
|
||||
fn main() {
|
||||
fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3<u32>) {
|
||||
var index : u32 = GlobalInvocationID.x;
|
||||
if (index >= params.particleCount) {
|
||||
return;
|
||||
|
|
|
@ -96,22 +96,18 @@ void init() {
|
|||
initTextures();
|
||||
|
||||
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
|
||||
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||
[[location(0)]] var<in> pos : vec4<f32>;
|
||||
[[stage(vertex)]] fn main() {
|
||||
Position = pos;
|
||||
return;
|
||||
[[stage(vertex)]] fn main([[location(0)]] pos : vec4<f32>)
|
||||
-> [[builtin(position)]] vec4<f32> {
|
||||
return pos;
|
||||
})");
|
||||
|
||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
|
||||
[[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;
|
||||
[[group(0), binding(0)]] var mySampler: sampler;
|
||||
[[group(0), binding(1)]] var myTexture : texture_2d<f32>;
|
||||
|
||||
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||
[[stage(fragment)]] fn main() {
|
||||
FragColor = textureSample(myTexture, mySampler, FragCoord.xy / vec2<f32>(640.0, 480.0));
|
||||
return;
|
||||
[[stage(fragment)]] fn main([[builtin(frag_coord)]] FragCoord : vec4<f32>)
|
||||
-> [[location(0)]] vec4<f32> {
|
||||
return textureSample(myTexture, mySampler, FragCoord.xy / vec2<f32>(640.0, 480.0));
|
||||
})");
|
||||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
|
|
|
@ -113,34 +113,30 @@ void init() {
|
|||
};
|
||||
[[group(0), binding(1)]] var<uniform> model : Model;
|
||||
|
||||
[[location(0)]] var<in> pos : vec3<f32>;
|
||||
[[location(1)]] var<in> col : vec3<f32>;
|
||||
struct VertexOut {
|
||||
[[location(2)]] f_col : vec3<f32>;
|
||||
[[builtin(position)]] Position : vec4<f32>;
|
||||
};
|
||||
|
||||
[[location(2)]] var<out> f_col : vec3<f32>;
|
||||
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||
|
||||
[[stage(vertex)]] fn main() {
|
||||
f_col = col;
|
||||
Position = camera.proj * camera.view * model.matrix * vec4<f32>(pos, 1.0);
|
||||
return;
|
||||
[[stage(vertex)]] fn main(
|
||||
[[location(0)]] pos : vec3<f32>,
|
||||
[[location(1)]] col : vec3<f32>) -> VertexOut {
|
||||
var output : VertexOut;
|
||||
output.f_col = col;
|
||||
output.Position = camera.proj * camera.view * model.matrix * vec4<f32>(pos, 1.0);
|
||||
return output;
|
||||
})");
|
||||
|
||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||
[[location(2)]] var<in> f_col : vec3<f32>;
|
||||
|
||||
[[stage(fragment)]] fn main() {
|
||||
FragColor = vec4<f32>(f_col, 1.0);
|
||||
return;
|
||||
[[stage(fragment)]] fn main(
|
||||
[[location(2)]] f_col : vec3<f32>) -> [[location(0)]] vec4<f32> {
|
||||
return vec4<f32>(f_col, 1.0);
|
||||
})");
|
||||
|
||||
wgpu::ShaderModule fsReflectionModule = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||
[[location(2)]] var<in> f_col : vec3<f32>;
|
||||
|
||||
[[stage(fragment)]] fn main() {
|
||||
FragColor = vec4<f32>(mix(f_col, vec3<f32>(0.5, 0.5, 0.5), vec3<f32>(0.5, 0.5, 0.5)), 1.0);
|
||||
return;
|
||||
[[stage(fragment)]] fn main(
|
||||
[[location(2)]] f_col : vec3<f32>) -> [[location(0)]] vec4<f32> {
|
||||
return vec4<f32>(mix(f_col, vec3<f32>(0.5, 0.5, 0.5), vec3<f32>(0.5, 0.5, 0.5)), 1.0);
|
||||
})");
|
||||
|
||||
wgpu::VertexAttribute attributes[2];
|
||||
|
|
|
@ -313,22 +313,18 @@ int main(int argc, const char* argv[]) {
|
|||
// The hacky pipeline to render a triangle.
|
||||
utils::ComboRenderPipelineDescriptor2 pipelineDesc;
|
||||
pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"(
|
||||
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
|
||||
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
||||
let pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
||||
vec2<f32>( 0.0, 0.5),
|
||||
vec2<f32>(-0.5, -0.5),
|
||||
vec2<f32>( 0.5, -0.5)
|
||||
);
|
||||
[[stage(vertex)]] fn main() {
|
||||
Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
||||
return;
|
||||
[[stage(vertex)]] fn main([[builtin(vertex_index)]] VertexIndex : u32)
|
||||
-> [[builtin(position)]] vec4<f32> {
|
||||
return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
||||
})");
|
||||
pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"(
|
||||
[[location(0)]] var<out> fragColor : vec4<f32>;
|
||||
[[stage(fragment)]] fn main() {
|
||||
fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
||||
return;
|
||||
[[stage(fragment)]] fn main() -> [[location(0)]] vec4<f32> {
|
||||
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
||||
})");
|
||||
// BGRA shouldn't be hardcoded. Consider having a map[format -> pipeline].
|
||||
pipelineDesc.cTargets[0].format = wgpu::TextureFormat::BGRA8Unorm;
|
||||
|
|
Loading…
Reference in New Issue