Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateTypeChecks> getName> missing parent for ArrowFunctionExpression> Missing param: uniforms #11

Open
kungfooman opened this issue Nov 3, 2023 · 0 comments
Assignees
Labels
todo to do

Comments

@kungfooman
Copy link
Owner

kungfooman commented Nov 3, 2023

Simplified test code for warnings:

class ShaderProcessor {
    /**
     * Process the lines with uniforms. The function receives the lines containing all uniforms,
     * both numerical as well as textures/samplers. The function also receives the format of uniform
     * buffers (numerical) and bind groups (textures) for view and material level. All uniforms that
     * match any of those are ignored, as those would be supplied by view / material level buffers.
     * All leftover uniforms create uniform buffer and bind group for the mesh itself, containing
     * uniforms that change on the level of the mesh.
     *
     * @param {import('./graphics-device.js').GraphicsDevice} device - The graphics device.
     * @param {Array<UniformLine>} uniforms - Lines containing uniforms.
     * @param {import('./shader-processor-options.js').ShaderProcessorOptions} processingOptions -
     * Uniform formats.
     * @param {import('./shader.js').Shader} shader - The shader definition.
     * @returns {object} - The uniform data. Returns a shader code block containing uniforms, to be
     * inserted into the shader, as well as generated uniform format structures for the mesh level.
     */
    static processUniforms(device, uniforms, processingOptions, shader) {
        // split uniform lines into samplers and the rest
        /** @type {Array<UniformLine>} */
        const uniformLinesSamplers = [];
        /** @type {Array<UniformLine>} */
        const uniformLinesNonSamplers = [];
        uniforms.forEach((uniform) => {
            if (uniform.isSampler) {
                uniformLinesSamplers.push(uniform);
            } else {
                uniformLinesNonSamplers.push(uniform);
            }
        });
        // build mesh uniform buffer format
        const meshUniforms = [];
        uniformLinesNonSamplers.forEach((uniform) => {
            // uniforms not already in supplied uniform buffers go to the mesh buffer
            if (!processingOptions.hasUniform(uniform.name)) {
                const uniformType = uniformTypeToName.indexOf(uniform.type);
                const uniformFormat = new UniformFormat(uniform.name, uniformType, uniform.arraySize);
                meshUniforms.push(uniformFormat);
            }
        });
        const meshUniformBufferFormat = meshUniforms.length ? new UniformBufferFormat(device, meshUniforms) : null;
        // build mesh bind group format - start with uniform buffer
        const bufferFormats = [];
        if (meshUniformBufferFormat) {
            // TODO: we could optimize visibility to only stages that use any of the data
            bufferFormats.push(new BindBufferFormat(UNIFORM_BUFFER_DEFAULT_SLOT_NAME, SHADERSTAGE_VERTEX | SHADERSTAGE_FRAGMENT));
        }

        // add textures uniforms
        const textureFormats = [];
        uniformLinesSamplers.forEach((uniform) => {
            // unmatched texture uniforms go to mesh block
            if (!processingOptions.hasTexture(uniform.name)) {

                // sample type
                // WebGpu does not currently support filtered float format textures, and so we map them to unfilterable type
                // as we sample them without filtering anyways
                let sampleType = SAMPLETYPE_FLOAT;
                if (uniform.precision === 'highp')
                    sampleType = SAMPLETYPE_UNFILTERABLE_FLOAT;
                if (shadowSamplers.has(uniform.type))
                    sampleType = SAMPLETYPE_DEPTH;

                // dimension
                const dimension = textureDimensions[uniform.type];

                // TODO: we could optimize visibility to only stages that use any of the data
                textureFormats.push(new BindTextureFormat(uniform.name, SHADERSTAGE_VERTEX | SHADERSTAGE_FRAGMENT, dimension, sampleType));
            }

            // validate types in else

        });
        const meshBindGroupFormat = new BindGroupFormat(device, bufferFormats, textureFormats);

        // generate code for uniform buffers
        let code = '';
        processingOptions.uniformFormats.forEach((format, bindGroupIndex) => {
            if (format) {
                code += format.getShaderDeclaration(bindGroupIndex, 0);
            }
        });

        // and also for generated mesh format, which is at the slot 0 of the bind group
        if (meshUniformBufferFormat) {
            code += meshUniformBufferFormat.getShaderDeclaration(BINDGROUP_MESH, 0);
        }

        // generate code for textures
        processingOptions.bindGroupFormats.forEach((format, bindGroupIndex) => {
            if (format) {
                code += format.getShaderDeclarationTextures(bindGroupIndex);
            }
        });

        // and also for generated mesh format
        code += meshBindGroupFormat.getShaderDeclarationTextures(BINDGROUP_MESH);

        return {
            code,
            meshUniformBufferFormat,
            meshBindGroupFormat
        };
    }

}

export { ShaderProcessor };

Currently produces eleven of these warnings:

generateTypeChecks> getName> missing parent for ArrowFunctionExpression> Missing param: uniforms
@kungfooman kungfooman self-assigned this Nov 3, 2023
@kungfooman kungfooman added the todo to do label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo to do
Projects
None yet
Development

No branches or pull requests

1 participant