Shader compilation failed: simpleDraw.vs:14: error: '' : unexpected token

Started by ss123she, March 28, 2025, 13:54:17

Previous topic - Next topic

ss123she

Shader compilation failed: simpleDraw.vs:14: error: '' : unexpected token

While trying to compile:

#version 450
layout(location = 0) in vec3 a_position;
layout(location = 1) in vec2 a_texcoord0;

layout(location = 0) out vec2 v_texcoord0;

layout(binding = 0) uniform Uniforms {
    mat4 u_modelViewProj;
};

void main() {
    v_texcoord0 = a_texcoord0;
    gl_Position = u_modelViewProj * vec4(a_position, 1.0);
}

UTF-8, no BOM

here is my compiling code:
    public static ByteBuffer compileShader(Path shaderPath, int shaderType) {
        long compiler = Shaderc.shaderc_compiler_initialize();
        long options = Shaderc.shaderc_compile_options_initialize();

        try {
            String shaderSource = Files.readString(shaderPath, StandardCharsets.UTF_8);

            try (MemoryStack stack = MemoryStack.stackPush()) {
                ByteBuffer sourceBuffer = stack.UTF8(shaderSource.trim());
                ByteBuffer shaderName = stack.UTF8(shaderPath.getFileName().toString());
                ByteBuffer entryPoint = stack.UTF8("main");

                long result = Shaderc.shaderc_compile_into_spv(
                        compiler,
                        sourceBuffer,
                        shaderType,
                        shaderName,
                        entryPoint,
                        options
                );

                if (Shaderc.shaderc_result_get_compilation_status(result) != Shaderc.shaderc_compilation_status_success) {
                    System.err.println("Shader compilation failed: " + Shaderc.shaderc_result_get_error_message(result));
                    System.err.println("Shader compile log: " + Shaderc.shaderc_result_get_error_message(result));
                    Shaderc.shaderc_result_release(result);
                    return null;
                }

                int spirvSize = (int) Shaderc.shaderc_result_get_length(result);

                ByteBuffer spirv = ByteBuffer.allocateDirect(spirvSize);
                spirv.put(Shaderc.shaderc_result_get_bytes(result)).flip();

                Shaderc.shaderc_result_release(result);
                return spirv;
            }

        } catch (IOException e) {
            System.err.println("Failed to load shader: " + e.getMessage());
            return null;
        } finally {
            Shaderc.shaderc_compile_options_release(options);
            Shaderc.shaderc_compiler_release(compiler);
        }
    }