Closed jmatsushita closed 7 months ago
Just try to change const
to let
:
// before
const tmax = 2000.0;
// after
let tmax = 2000.0;
Or declare it in module scope:
const tmax = 2000.0;
fn main_image() {}
I will check if it's a bug relative to naga, since according to WGSL Spec, a const-declaration can be declared in function scope: https://www.w3.org/TR/WGSL/#const-decls
Thank you. Indeed the change you suggested fixes the error:
// after
let tmax = 2000.0;
However, should this be a panic (sometimes just swallowed or displaying RuntimeError: unreachable
) would it be possible to have a more granular error message to help troubleshoot the shader next time?
You're right, I should throw the compiling error message from naga
.
I update both naga
& naga-oil
to the latest version and throw error message from Rust side.
// before
naga = { version = "0.14.1", features = ["glsl-in", "wgsl-in", "wgsl-out"] }
naga_oil = "0.11.0"
// after
naga = { version = "0.19.2", features = ["glsl-in", "wgsl-in", "wgsl-out"] }
naga_oil = "0.13.0"
Now the error message can be shown correctly. For example, in the tmax
case, naga-oil
will complain the following message:
make_naga_module Composer error: expected assignment or increment/decrement, found 'tmax'
But we cannot use alias
for now: https://github.com/bevyengine/naga_oil/issues/79
If we try to prepend alias int = i32;
to our shader chunk:
Composable module identifiers must not require substitution according to naga writeback rules: `int`
So we have to do some alias work when borrowing shaders from compute-toys
. Here is the complete alias map used in compute-toys
:
alias int = i32;
alias uint = u32;
alias float = f32;
alias int2 = vec2<i32>;
alias int3 = vec3<i32>;
alias int4 = vec4<i32>;
alias uint2 = vec2<u32>;
alias uint3 = vec3<u32>;
alias uint4 = vec4<u32>;
alias float2 = vec2<f32>;
alias float3 = vec3<f32>;
alias float4 = vec4<f32>;
alias bool2 = vec2<bool>;
alias bool3 = vec3<bool>;
alias bool4 = vec4<bool>;
alias float2x2 = mat2x2<f32>;
alias float2x3 = mat2x3<f32>;
alias float2x4 = mat2x4<f32>;
alias float3x2 = mat3x2<f32>;
alias float3x3 = mat3x3<f32>;
alias float3x4 = mat3x4<f32>;
alias float4x2 = mat4x2<f32>;
alias float4x3 = mat4x3<f32>;
alias float4x4 = mat4x4<f32>;
Or use predeclares instead, eg.
Just use the latest @antv/g-device-api@1.6.8
& WASM:
import { WebGPUDeviceContribution } from '@antv/g-device-api';
const deviceContribution = new WebGPUDeviceContribution({
shaderCompilerPath: '/glsl_wgsl_compiler_bg.wasm',
// From CDN
// shaderCompilerPath: 'https://unpkg.com/@antv/g-device-api@1.6.8/rust/pkg/glsl_wgsl_compiler_bg.wasm',
});
Calls begin/endFrame()
at the beginning and end of computePass:
device.beginFrame();
const computePass = device.createComputePass();
computePass.setPipeline(computePipeline);
computePass.setBindings(bindings);
computePass.dispatchWorkgroups(1);
device.submitPass(computePass);
device.endFrame();
Hi,
Sorry for opening the issue directly on github, but I cannot see this repo in the dropdown menu in https://antv-issue-helper.surge.sh
I created a reproducer in ObservableHQ for a panic when using a specific shader: https://observablehq.com/d/bece57b91ebd5a40
I'm using a compute-toys notebook fork which pulls in the latest version @antv/g-device-api@1.6.4
The setup works for the origami shader, however when using shader code that compiles and runs fine in compute.toys (see https://compute.toys/view/1079) I can get the following stack trace in the console:
Additional context
Chrome on MacOS
Version 122.0.6261.94 (Official Build) (arm64)
I have noticed the following in regard to errors and error handling in general:
run
function take in the shader string, there are cases where in particular reusing the prelude without binding for instancetime.elapsed
will result in these errors being constantly spammed in the console.Using a trick such as:
Works to bypass that problem and avoid having to reinitialise each cell with a different set of bindings.
[ ] Is there a better way to enable using a notebook to progressively build a compute shader? Maybe some variables can be initialised and made available to the page first, like
device
and only runningcreateProgram()
anddevice.createComputePipeline()
on each cell? If you had a example notebook with this approach that would be great to be able to use observablehq to explain shaders step by step.[ ] Some code that runs on
compute.toys
doesn't work withg-device-api
. This seems to have to do with type checking.compute.toys
seems able to infer the types but this will spam this error message withg-device-api
:The fix is easy enough, but the error handling and lack of error messages makes it difficult to use.
Thank you very much for the great library, I'm really looking forward to using it more in observablehq and I hope my remarks are helpful to improve the error handling experience!
Cheers,
Jun