Skip to content

wgsl: limiting undefined behaviour; subdividing "dynamic error" #1844

Closed

Description

@dneto0

This was prompted again by various recent discussions:

Right now, the spec defines:

  • program error: "a failure to satisfy the requirements of the specification"
  • and its sub-category: dynamic error as is any program occurring during shader execution.

Portability desires push us to make the spec specify outcomes in more situations, i.e. minimize the bad cases.

There are common patterns of "bad cases":

  • Sometimes a computation produces an "unspecified value", i.e. some value (of the target type) but not pinned down by the spec.
    • In some languages, each observation of that produced value can materialize as a different value of the target type. (Hilarity ensues.)
  • Sometimes the result is "Undefined behavior". The spec no longer applies in this case and therefore provides no guidance on the behaviour of the program, either before or after the occurrence of the triggering behaviour. The program literally has no specified meaning.
    * Example: In C, integer division by zero yields undefined behaviour. (MSL softens this case to undef value.)

Sometimes an undef value triggers undefined behaviour later on. For example, it is undefined behaviour to branch on an undef value.

Things to be decided:

  • reconciling bad cases in underlying platforms vs. WGSL
  • Can we reasonably polyfill make WGSL more specified than what comes out of the box from the underlying platform's undefined behaviour, or undef values.
  • Do we need to make new subcategories of "dynamic error".

I'm obliged to point to Taming undefined behavior in LLVM (which I consider a classic). Further work proposes replacing "undef" with a combination of a "freeze" primitive and "poison" value. E.g. RFC and presentation. Note that LLVM still has undef and freeze and poison values. (For the hardware-inclined, undef is analogous to a metastable or unsettled value, and 'freeze' is analogous to a chain of synchronization registers with a given MTBF.)

Activity

  1. added
    wgsl
    on Jun 15, 2021
  2. added this to the V1.0 milestone on Feb 3, 2022
  3. dneto0 commented on Feb 8, 2022

    @dneto0
    ContributorAuthor

    Led to partitioning of error cases:

    • shader-creation, pipeline-creation
    • dynamic error
    • uncategorized error.

    Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgsl

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions