KhronosGroup/SPIRV-Cross

openGL ES lowp

JachinCcc opened this issue · 3 comments

#version 450

layout(location = 0) in mediump vec3 position;
layout(location = 1) in mediump vec2 texCoord;

layout(location = 0) out lowp vec2 texCoord_f;

layout(set = 0, binding = 0) uniform MVPBlock {
    highp mat4 MVP;
};

void main()
{
    texCoord_f = texCoord;
    gl_Position = MVP * vec4(position, 1.0);
}

after spirv-cross test.spv --version 120 --es, i get

#version 120 es

struct MVPBlock
{
    mat4 MVP;
};

uniform MVPBlock _25;

varying mediump vec2 texCoord_f;
attribute mediump vec2 texCoord;
attribute mediump vec3 position;

void main()
{
    texCoord_f = texCoord;
    gl_Position = _25.MVP * vec4(position, 1.0);
}

texCoord_f precision is mediump, not lowp what i wanted.

That's because this information is lost in the compilation of GLSL to SPIR-V. SPIR-V only has two levels of precision, normal and RelaxedPrecision. When GLSL is compiled to SPIR-V, mediump and lowp qualifiers both become RelaxedPrecision decorations in SPIR-V. Because of this, SPIRV-Cross cannot tell from the SPIR-V alone which I/O variables are supposed to be lowp and which mediump.

I'm afraid there's little that can be done with just the SPIR-V to go off of. Perhaps SPIRV-Cross could add an interface to set individual I/O variables as mediump or lowp, but I'm not sure how H-K would react to such a proposal. I'm not even sure adding such an interface is worth it; how many drivers actually draw a meaningful distinction between mediump and lowp? That SPIR-V doesn't make this distinction suggests that the number isn't very high. On the other hand, maybe you're targeting a driver that actually does make such a distinction.

Thank you very much for your reply. I also reached this answer yesterday by reading the source code.Actually, i do can't draw a meaningful distinction between mediump and lowp.Maybe I can try to implement this part myself and look forward to H-K's reply to this question.

Lowp does not exist in SPIR-V or any modern GLSL. It's a legacy relic that is promoted to mediump for all intents and purposes. Lowp is meaningless on all hardware today.