Repository: playcanvas/engine
File: src/platform/graphics/webgpu/webgpu-shader-processor-wgsl.js (JavaScript)

Code before:
        return code;
    }

    /**
     * Generates a shader code for a bind group, something like:
     * ```
     *    @group(0) @binding(0) var diffuseTexture: texture_2d<f32>;
     *    @group(0) @binding(1) var diffuseTexture_sampler: sampler;  // optional
     * ```
     * @param {BindGroupFormat} format - The format of the bind group.
     * @param {number} bindGroup - The bind group index.
     * @param {number} startBindIndex - The starting bind index.
     * @returns {string} - The shader code for the bind group.
     */
    static getTextureShaderDeclaration(format, bindGroup, startBindIndex) {
        let code = '';

        format.textureFormats.forEach((format) => {

            const textureTypeName = getTextureDeclarationType(format.textureDimension, format.sampleType);
            code += `@group(${bindGroup}) @binding(${format.slot}) var ${format.name}: ${textureTypeName};\n`;

            if (format.hasSampler) {
                // A slot should have been left empty for the sampler at format.slot+1
                const samplerName = format.sampleType === SAMPLETYPE_DEPTH ? 'sampler_comparison' : 'sampler';
                code += `@group(${bindGroup}) @binding(${format.slot+1}) var ${format.samplerName}: ${samplerName};\n`;
            }
        });

        format.storageBufferFormats.forEach((format) => {

            const access = format.readOnly ? 'read' : 'read_write';
            code += `@group(${bindGroup}) @binding(${format.slot}) var<storage, ${access}> ${format.name} : ${format.format};\n`;

        });

        Debug.assert(format.storageTextureFormats.length === 0, 'Implement support for storage textures here');
        // TODO: also add external texture support here

        return code;
    }

    static processVaryings(varyingLines, varyingMap, isVertex) {
        let block = '';
        let blockPrivates = '';
        let blockCopy = '';
        varyingLines.forEach((line, index) => {
            const match = line.match(VARYING);
            Debug.assert(match, `Varying line is not valid: ${line}`);

            if (match) {

Review comment (suggestion):
```suggestion
                code += `@group(${bindGroup}) @binding(${format.slot + 1}) var ${format.samplerName}: ${samplerName};\n`;
```

Code after:
        return code;
    }

    /**
     * Generates a shader code for a bind group, something like:
     * ```
     *    @group(0) @binding(0) var diffuseTexture: texture_2d<f32>;
     *    @group(0) @binding(1) var diffuseTexture_sampler: sampler;  // optional
     * ```
     * @param {BindGroupFormat} format - The format of the bind group.
     * @param {number} bindGroup - The bind group index.
     * @param {number} startBindIndex - The starting bind index.
     * @returns {string} - The shader code for the bind group.
     */
    static getTextureShaderDeclaration(format, bindGroup, startBindIndex) {
        let code = '';

        format.textureFormats.forEach((format) => {

            const textureTypeName = getTextureDeclarationType(format.textureDimension, format.sampleType);
            code += `@group(${bindGroup}) @binding(${format.slot}) var ${format.name}: ${textureTypeName};\n`;

            if (format.hasSampler) {
                // A slot should have been left empty for the sampler at format.slot+1
                const samplerName = format.sampleType === SAMPLETYPE_DEPTH ? 'sampler_comparison' : 'sampler';
                code += `@group(${bindGroup}) @binding(${format.slot + 1}) var ${format.samplerName}: ${samplerName};\n`;
            }
        });

        format.storageBufferFormats.forEach((format) => {

            const access = format.readOnly ? 'read' : 'read_write';
            code += `@group(${bindGroup}) @binding(${format.slot}) var<storage, ${access}> ${format.name} : ${format.format};\n`;

        });

        Debug.assert(format.storageTextureFormats.length === 0, 'Implement support for storage textures here');
        // TODO: also add external texture support here

        return code;
    }

    static processVaryings(varyingLines, varyingMap, isVertex) {
        let block = '';
        let blockPrivates = '';
        let blockCopy = '';
        varyingLines.forEach((line, index) => {
            const match = line.match(VARYING);
            Debug.assert(match, `Varying line is not valid: ${line}`);

            if (match) {