Skip to content

WGSL API proposal: shaderLog #4704

Open
@mwyrzykowski

Description

Logging debug strings is now supported across all major backends. Given the lack of native shader debugging tools, especially for mobile platforms, it would be great to support printf style logging in WGSL.

Shader logging and any improved debugging has been a requested feature amongst multiple developers.

Native API references:

Metal
(new in Metal 3.2) https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf and https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf

D3D
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/printf

Vulkan
https://github.com/KhronosGroup/SPIRV-Guide/blob/main/chapters/nonsemantic.md

API Proposal.

Under Section 4.1.1, add the following enable extension:

WGSL enable-extension | WebGPU GPUFeatureName | Description
log                   | "shader-log"          | The shaderLog function is valid to use in the WGSL module. Otherwise, using shaderLog will result in a shader-creation error.

Under Section 16, add the following built in function:

fn shaderLog(level: severity, formatString: string, ...)

where severity maps to the same error, warning, info, etc as seen under https://www.w3.org/TR/WGSL/#diagnostics , string is a new type under Section 6.2 valid only in shaderLog, and ... is a variadic argument list common to most printf and related implementations.

Assuming there is buy-off on the proposal, the corresponding API change would likely be something like, under Section 12.1 of the WebGPU specification:

enum GPUShaderExecutionMessageType {
    "error",
    "warning",
    "info",
};

[Exposed=(Window, Worker), Serializable, SecureContext]
interface GPUShaderExecutionMessage {
    readonly attribute message;
    readonly attribute GPUCompilationMessageType type;
}

[Exposed=(Window, Worker), Serializable, SecureContext]
interface GPUShaderExecutionInfo {
    readonly attribute FrozenArray<GPUShaderExecutionMessage> messages;
};

[Exposed=(Window, Worker), SecureContext]
interface GPUCommandBuffer {
    Promise< GPUShaderExecutionInfo> getShaderExecutionInfo();
};

Certainly open to other proposals, but it would be nice to do something here for the development / debugging case.

Metadata

Assignees

No one assigned

    Labels

    apiWebGPU APIproposalwgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions