Repository: shader-slang/slang
File: source/slang/slang-ir-glsl-legalize.cpp (C++)

Code before:
    {
        context->requireGLSLVersion(ProfileVersion::GLSL_450);
        context->requireGLSLExtension(
            UnownedStringSlice::fromLiteral("GL_EXT_fragment_shader_barycentric"));
        name = "gl_BaryCoordEXT";

        // TODO: There is also the `gl_BaryCoordNoPerspNV` builtin, which
        // we ought to use if the `noperspective` modifier has been
        // applied to this varying input.
    }
    else if (semanticName == "sv_cullprimitive")
    {
        name = "gl_CullPrimitiveEXT";
    }
    else if (semanticName == "sv_shadingrate")
    {
        if (kind == LayoutResourceKind::VaryingInput)
        {
            name = "gl_ShadingRateEXT";
        }
        else
        {
            name = "gl_PrimitiveShadingRateEXT";
        }
    }
    else if (semanticName == "sv_fragsize")
    {
        name = "gl_FragSizeEXT";
    }
    else if (semanticName == "sv_fraginvocationcount")
    {
        name = "gl_FragInvocationCountEXT";
    }
    else if (semanticName == "sv_startvertexlocation")
    {
        context->requireGLSLVersion(ProfileVersion::GLSL_460);

        // uint in hlsl, int in glsl (https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL))
        requiredType = builder->getBasicType(BaseType::Int);
        name = "gl_BaseVertex";
    }
    else if (semanticName == "sv_startinstancelocation")
    {
        context->requireGLSLVersion(ProfileVersion::GLSL_460);

        // uint in hlsl, int in glsl (https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL))
        requiredType = builder->getBasicType(BaseType::Int);
        name = "gl_BaseInstance";
    }

    inStorage->targetVarName = targetVarName;

Review comment (suggestion):
We need documentation for `sv_fragsize` and `sv_fraginvocationcount`
* Add to `docs\user-guide\a2-01-spirv-target-specific.md`
    * `sv_fragsize`/`sv_fraginvocationcount` is not an HLSL concept
* Add to `docs\user-guide\a2-03-wgsl-target-specific.md`
   

Code after:
    {
        context->requireGLSLVersion(ProfileVersion::GLSL_450);
        context->requireGLSLExtension(
            UnownedStringSlice::fromLiteral("GL_EXT_fragment_shader_barycentric"));
        name = "gl_BaryCoordEXT";

        // TODO: There is also the `gl_BaryCoordNoPerspNV` builtin, which
        // we ought to use if the `noperspective` modifier has been
        // applied to this varying input.
    }
    else if (semanticName == "sv_cullprimitive")
    {
        name = "gl_CullPrimitiveEXT";
    }
    else if (semanticName == "sv_shadingrate")
    {
        if (kind == LayoutResourceKind::VaryingInput)
        {
            name = "gl_ShadingRateEXT";
        }
        else
        {
            name = "gl_PrimitiveShadingRateEXT";
        }
    }
    else if (semanticName == "sv_fragsize")
    {
        name = "gl_FragSizeEXT";
        context->requireGLSLVersion(ProfileVersion::GLSL_450);
        context->requireGLSLExtension(
            UnownedStringSlice::fromLiteral("GL_EXT_fragment_invocation_density"));
        requiredType = builder->getVectorType(
            builder->getBasicType(BaseType::Int),
            builder->getIntValue(builder->getIntType(), 2));
    }
    else if (semanticName == "sv_fraginvocationcount")
    {
        name = "gl_FragInvocationCountEXT";
        context->requireGLSLVersion(ProfileVersion::GLSL_450);
        context->requireGLSLExtension(
            UnownedStringSlice::fromLiteral("GL_EXT_fragment_invocation_density"));
        requiredType = builder->getIntType();
    }
    else if (semanticName == "sv_startvertexlocation")
    {
        context->requireGLSLVersion(ProfileVersion::GLSL_460);

        // uint in hlsl, int in glsl (https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL))
        requiredType = builder->getBasicType(BaseType::Int);
        name = "gl_BaseVertex";
    }