openglunicodeglslbyte-order-markopengl-4

GLSL simple shader results in strange compilation errors


I have a very simple shader here:

#version 460

layout (location = 0) in vec3 inPos;
layout (location = 0) out vec3 outPos;

void main() {
    gl_Position = vec4(inPos.x, inPos.y, inPos.z, 1.0);
    outPos = inPos;
}

and compiled the shader using the command:

glslangValidator -V -G -o triangle.vert.spv triangle.vert

and the compiler turned 3 errors:

error : #version: ES shaders for SPIR-V require version 310 or higher
error : Source\Shaders\triangle.vert:1: '€' : unexpected token
error : Source\Shaders\triangle.vert:1: '' : compilation terminated

It seems that the compiler is having trouble reading the very first line of the code. I am very sure I don't include a euro sign in this, and the syntax should be correct.

How should I fix this?


Solution

  • I am using Jetbrains Rider, for me: File Encoding->Remove BOM solves the issue