Skip to content

[wgsl] Encoding for shader text needs to be specified #565

Closed

Description

@zoddicus

To my understanding the spec currently doesn't state the encoding for the shader text, which should be stated explicitly for compat.

From talking to @dj2 , the tokens of the language and the regex for var names are ASCII. The only thing that currently can be non-ASCII is the entry point names, which are UTF-8.

Activity

  1. added
    wgsl
    on Feb 27, 2020
  2. Kangz commented on Feb 27, 2020

    @Kangz
    Contributor

    Can comments contain UTF-8 also? (and maybe identifiers but that's more controversial)

  3. magcius commented on Feb 27, 2020

    @magcius

    UTF-8? The web is specified in some arbitrary Unicode encoding, as determined by the Content-Encoding header (or meta charset equivalent). If the strings come from JavaScript, they will be with the byte encoding of the JavaScript interpreter, which is likely UCS-2 / UTF-16, but this is an implementation detail.

  4. othermaciej commented on Feb 28, 2020

    @othermaciej

    UTF-8 is the best encoding for a textual language for the web. HTML has to deal with legacy encodings, but a new format doesn't need to.

  5. litherum commented on Feb 28, 2020

    @litherum
    Contributor

    The functions which accept shader source are IDL functions, which would accept DOMString. Encoding is handled by the underlying loading infrastructure of the webpage. It doesn't need to be defined (indeed: shouldn't be defined) by the shading language spec.

  6. othermaciej commented on Feb 29, 2020

    @othermaciej

    Any text format transmitted over the internet needs to have its charset defined, or have a known mechanism for getting the charset. Otherwise, out-of-band knowledge is required to decode it to a DOMString.

    Let's assume there's never a dedicated API to load a WGSL shader, and they are always loaded through something generic like Fetch. Then there needs to be a way to transform the bytes that come off the wire into a DOMString. Fetch can give you various packagings. Some are raw bytes. If you get one of those, you need out-of-band knowledge of the encoding. That's not good, because it stops a webpage from having generic code to load shaders, if those shaders might have come from someone using a different encoding. There's also a text packaging, which assumes UTF-8 encoding. Thus, UTF-8 will be the easiest option for authors.

    For completeness' sake, there's also the option of putting the encoding as a charset parameter on the MIME type (but then the server needs to know the encoding somehow, which is inconvenient), or the file format can have an in-band charset declaration (like HTML and CSS do), but then there probably needs to be a dedicated loading API, or an API that takes an ArrayBuffer of bytes, or a way to turn an array of bytes into a DOMString. Those are all worse than just defining it to be utf-8.

    When we submit a MIME type definition for WGSL to IANA, we will probably need to explain charset considerations there. That is yet another reason the encoding must be defined. It's not good to transmit text over the Internet without defining the charset encoding.

    Of course, none of this stops anyone from locally editing a WGSL file in whatever encoding they, or their OS, or their text editor prefer. But when it's severed on the web, the charset must be defined somehow.

  7. litherum commented on Mar 2, 2020

    @litherum
    Contributor

    (quoting myself)

    It doesn't need to be defined

    This is true. However, after discussing this offline, I realized that it's still valuable for the spec to list an encoding, even if it isn't used anywhere inside WebGPU's implementation. If we consider the possibility that WGSL is a huge success, and has loads of tools, simply stating an official encoding in the spec is generally a good idea to reduce problems in long toolchains of compilers/optimizers/compressors etc.

    And if we had to pick a particular encoding, yeah, UTF-8 is the clear winner.

  8. kdashg commented on Feb 19, 2021

    @kdashg
    Contributor

    Seems like consensus to spec as utf-8 for shader text. TBD details like identifiers.

  9. added 3 commits that reference this issue on Apr 12, 2021
    09be9c5
    55ba8c4
    8ef882a
  10. annevk commented on Apr 28, 2021

    @annevk
    Contributor

    You could use USVString for the methods taking a shader source as well, to indicate lone surrogates are not allowed (and end up as U+FFFD).

    (As for the commits above, note that USVString is not UTF-16 necessarily. What kind of backing you use for USVString is up to implementations and an ECMAScript engine written in Rust might well use Rust's native string type for it.)

  11. kainino0x commented on Apr 28, 2021

    @kainino0x
    Contributor

    We do indeed use USVString for shader sources now, and I think we have a pretty good handle on the encoding considerations (finally). WGSL doesn't actually specify an encoding but says "UTF-8 is always a valid encoding for a WGSL program."

  12. annevk commented on Apr 28, 2021

    @annevk
    Contributor

    I'd recommend saying that for interchange UTF-8 must be used. Sure, someone could handcraft something else and make it work, but there's no reason to even hint that's a thing that's endorsed.

  13. kvark commented on Apr 28, 2021

    @kvark
    Contributor

    We don't have to say UTF-8 must be used. The tools can figure this out.
    I think the issue may be closed now?

  14. 28 remaining items

  15. ben-clayton commented on Apr 21, 2022

    @ben-clayton
    Contributor

    And so is Go.

    Okay. It seems like this is the general direction of languages and compilers. I guess code-editors will move in this direction too.
    I rescind my file-format / offline tooling concerns.

  16. added
    i18n-needs-resolution
    and removed
    i18n-tracker
    on Apr 24, 2022
  17. removed their assignment
    on May 31, 2022
  18. added
    wgsl resolved
    on May 31, 2022
  19. kdashg commented on May 31, 2022

    @kdashg
    Contributor
    WGSL meeting minutes 2022-05-31
    • KG: Said I’d write something. Write up that we’re UTF-8
    • DN: Anything to discuss, or just do?
    • BC: Was against, been convinced general direction languages are moving. Think just doing UTF-8 and reject other encodings is fine
    • MOD: I agree and we should ignore BOM.
    • KG: Anyone to write?
    • DN: I can do it.
  20. mehmetoguzderin commented on May 31, 2022

    @mehmetoguzderin
    Member

    @xfq FYI, with today's meeting's decision, after the PR for this comes along, encoding of WGSL will be well-specified to be UTF-8 with ignoring of BOM. Thank you and i18n WG very much again for your help on various issues; much appreciated, and hopefully, the resolution here is satisfactory. I will delegate the close of the issue to post-PR-merge, which will also reflect in the i18n repo.

  21. added
    copyediting
    and removed
    wgsl resolved
    on Sep 20, 2022
  22. dneto0 commented on Oct 31, 2022

    @dneto0
    Contributor

    The PR didd not take the BOM into account. But RFC 3629 says protocols that only use UTF-8 should forbid the byte order mark. I have updated the PR to say the BOM is not to be used.
    See discussion at #3542 (comment)

  23. dneto0 commented on Oct 31, 2022

    @dneto0
    Contributor

    #3542 added a draft media type encoding and fixed the encoding to be UTF-8 without byte order mark.

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

Metadata

Metadata

Assignees

Labels

copyeditingi18n-needs-resolutionwgsl

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions