ComputeShader compilation error callback

I tried creating a basic compute shader and hooked up the onError callback. It should get triggered if the compilation fails. However, it does not get called.

const cs1 = new BABYLON.ComputeShader("myCompute", engine, { computeSource: "this purposefully causes a compile error" }, { bindingsMapping:
        {
            "dest": { group: 0, binding: 0 },
            "src": { group: 0, binding: 2 }
        }
    });
    cs1.onError = (a, b) => {
        console.error(a, b);
    };

Reproduction example
Compute shader onError callback | Babylon.js Playground (babylonjs.com)

I looked through the source code and it seems like the shader is being compiled here. Also notice the try { } catch { }

Which calls the WebGPUEngine.prototype._prepareComputePipelineContext in engine.computeShader.ts, which in turn calls the WebGPUEngine.prototype._createComputePipelineStageDescriptor function in the same file. There, the native createShaderModule function is being called.

However, that native function does not throw any errors. It instead chooses to always return a shader module, from which one can get the error with getCompilationInfo.

(Iā€™d happily include more links instead of textually describing which code gets called, but I believe Discourse has some limits for new members.)

I will work on this asap!

1 Like

This PR will fix it:

2 Likes