Skip to content

Glslang doesn't build spv code with RelaxedPrecision #4121

@Nelonn

Description

@Nelonn

I'm using pair of glslang and SPIRV-Cross and compiling simple shader to ES target without optimizer. Input code:

#version 450 core

precision mediump float;

layout(set = 0, binding = 1) uniform mediump sampler2D sTexture;

layout(location = 0) in VertexData {
    vec4 Color;
    vec2 UV;
} In;

layout(location = 0) out mediump vec4 fColor;

void main() {
    fColor = In.Color * texture(sTexture, In.UV.st);
}

Without any modifications im getting output:

#version 300 es
precision mediump float;
precision highp int;

uniform highp sampler2D sTexture;

layout(location = 0) out highp vec4 fColor;
in highp vec4 In_Color;
in highp vec2 In_UV;

void main()
{
    fColor = In_Color * texture(sTexture, In_UV);
}

If I modify GlslangToSpv.cpp with manually forcing precision to RelaxedPrecision

spv::Decoration TranslatePrecisionDecoration(const glslang::TType& type)
{
    return spv::Decoration::RelaxedPrecision;
    //return TranslatePrecisionDecoration(type.getQualifier().precision);
}

Then im getting following output:

#version 300 es
precision mediump float;
precision highp int;

uniform mediump sampler2D sTexture;

layout(location = 0) out vec4 fColor;
in vec4 In_Color;
in vec2 In_UV;

void main()
{
    vec4 _19 = In_Color;
    highp vec4 hp_copy_19 = _19;
    vec4 _29 = texture(sTexture, In_UV);
    highp vec4 hp_copy_29 = _29;
    fColor = hp_copy_19 * hp_copy_29;
}

What's the problem, why does it constantly generate highp without forcing? It's clear that I can't use this modification because it affects other places like uniforms, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions