Skip to content

GLSL discard behavior #4081

@Valentin-Sarthou

Description

@Valentin-Sarthou

Hello,

Since 9323100 (merged in 15.4.0), GLSL's discard now maps to OpDemoteToHelperInvocation instead of OpTerminateInvocation when targeting SPIR-V >= 1.6.

This change has already been discussed in #3954, but I would like to add a few more elements.

From the GLSL 4.60 specification, section 6.4. Jumps, about the discard keyword:

Control flow exits the shader, and subsequent implicit or explicit derivatives are undefined when this control flow is non-uniform

This sentence seems to describe the behavior of OpTerminateInvocation, as opposed to OpDemoteToHelperInvocation.

Also, from the specification of VK_KHR_shader_terminate_invocation:

OpTerminateInvocation provides the behavior required by the GLSL discard statement, and should be used when available by GLSL compilers and applications that need the GLSL discard behavior.

So from what I understand, mapping discard to OpTerminateInvocation was indeed the expected behavior, at least according to the specification.

I understand that the ambiguity of discard may cause bugs in applications, but isn't that why GLSL_EXT_demote_to_helper_invocation and GL_EXT_terminate_invocation were introduced ? The latter states:

It is recommended that programmers use demote [...] or terminateInvocation instead of discard.

Is it reasonable for glslang to deviate from the GLSL, VK and EXTs specifications on this point? Am I missing something?

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