shader that doesn't compile
greggman opened this issue · 4 comments
Thanks for this library!
If you're interested, this shader works in webgpu but doesn't work here
struct VertexDesc {
offset: u32,
stride: u32,
size: u32,
padding: u32,
};
struct LineInfo {
triDiv: u32,
triMul: u32,
midMod: u32,
midDiv: u32,
oddMod: u32,
triMod: u32,
pad0: u32,
pad1: u32,
};
struct VSUniforms {
worldViewProjection: mat4x4<f32>,
position: VertexDesc,
lineInfo: LineInfo,
color: vec4<f32>,
lightDirection: vec3<f32>,
};
@group(0) @binding(0) var<uniform> vsUniforms: VSUniforms;
@group(0) @binding(1) var<storage> vertData: array<f32>;
fn getVert(desc: VertexDesc, index: u32) -> vec4<f32> {
var v = vec4<f32>(0, 0, 0, 1);
let offset = desc.offset + index * desc.stride;
for (var i: u32 = 0u; i < desc.size; i += 1u) {
v[i] = vertData[offset + i];
}
return v;
}
struct MyVSOutput {
@builtin(position) position: vec4<f32>,
};
@vertex
fn myVSMain(@builtin(vertex_index) vertex_index: u32) -> MyVSOutput {
var vsOut: MyVSOutput;
var i = (vertex_index / vsUniforms.lineInfo.triDiv) * vsUniforms.lineInfo.triMul +
((vertex_index % vsUniforms.lineInfo.midMod) / vsUniforms.lineInfo.midDiv +
(vertex_index % vsUniforms.lineInfo.oddMod)) % vsUniforms.lineInfo.triMod;
let position = getVert(vsUniforms.position, i);
vsOut.position = vsUniforms.worldViewProjection * position;
return vsOut;
}
@fragment
fn myFSMain(v: MyVSOutput) -> @location(0) vec4<f32> {
return vsUniforms.color + vec4(vsUniforms.lightDirection, 0) * 0.0;
}
gets
wgsl_reflect.module.js:691 Token_lexeme: "+"_line: 33_type: {name: 'plus', type: 'token', rule: '+', toString: ƒ}[[Prototype]]: Object "Expected '='."
_error @ wgsl_reflect.module.js:691
wgsl_reflect.module.js:719 Uncaught Objectmessage: "Expected '='."toString: ƒ ()token: Token {_type: {…}, _lexeme: '+', _line: 33}[[Prototype]]: Object
Thanks, I'll get it fixed.
The error you're getting about the expected '=' should have been fixed back in August with 66c280f, which added the missing compound operators like +=.
There is another shader error with vec4(vsUniforms.lightDirection, 0)
, and it was expecting a '<' for the vec4 template type. I don't see where in the WGSL spec it allows vec4 to be declared without a type specifier.
I can make the type specifier optional, if that's how the spec is defined. Or I could make it optional even if it's not in the spec, since you say it works in Tint.
I think I had forgotten to build the rolled up wgsl_reflect.module.js when I added the += operator support. Whoops.
I made template format type declarations optional, so that vec4(vsUniforms.lightDirection, 0)
line will work now, and made sure I did the rollup build.
Fix in commit b2eadf0.