danielfvm / webpack-wgsl-loader

A webpack loader for wgsl shaders supporting nested imports.
MIT License
1 stars 0 forks source link

support `label` option for `device.createShaderModule` #1

Closed gszep closed 2 weeks ago

gszep commented 3 weeks ago

Great loader! Super helpful thanks. Ideally there would be support for labels to help with debugging

import shaderCode from "./shaders/example.wgsl";
const cellShaderModule = device.createShaderModule({
  label: "shader label",
  code: shaderCode
});

Do you think this is possible? Or perhaps some other way of defining a label. It is not possible to do after createShaderModule is called

danielfvm commented 3 weeks ago

Hello gszep, I just pushed a change that adds the filename as the default value for the label. For now I haven't added any built in label support (not sure what the best way to do so would be), but it can still be achieved by doing something like the following:

import shaderCode from "./shaders/example.wgsl";

shaderCode.label = "MyLabel";
const cellShaderModule = device.createShaderModule(shaderCode);

In case you meant with "labels" support for SourceMaps, I was trying to implement it but couldn't quite get it to work. Either that or my Browser doesn't support sourceMaps. From the developer.mozilla.org website:

Note: Different implementations may handle sourceMaps in different ways, including possibly ignoring them entirely.

So for the time being no sourceMap support unless someone smarter than me figures out how to implement it. :cry:

gszep commented 2 weeks ago

Amazing stuff! Yes it would be great to have source maps and eventually frame-by-frame pixel debugging one day! I came across this editor ShaderED which is amazing I hope something like this can work with WebGPU