Skip to content

Feature detection for HDR canvas #4828

Closed

Description

@kainino0x

Right now it seems we don't have a way for webpages to feature-detect whether WebGPU can do HDR canvas. Only whether the device is HDR (by checking the media query).

See discussion here webgpu/webgpu-samples#432 (comment)
cc @beaufortfrancois @ccameron-chromium

Activity

  1. added this to the Milestone 1 milestone on Aug 27, 2024
  2. ccameron-chromium commented on Aug 28, 2024

    @ccameron-chromium
    Contributor

    It appears that several of the properties set in the GPUCanvasConfiguration are not query-able (GPUCanvasAlphaMode and the PredefinedColorSpace). If we were to be able to query "what is the current GPU canvas configuration", we could check to see what the tone mapping property (and all of those other ones) were set to. And if there is no tone mapping property, then we know that it isn't supported.

  3. beaufortfrancois commented on Aug 29, 2024

    @beaufortfrancois
    Contributor

    Following the similar CanvasRenderingContext2D: getContextAttributes() method, I'd propose something like GPUCanvasContext: getContextAttributes() method:

    dictionary GPUCanvasContextAttributes {
      PredefinedColorSpace colorSpace = "srgb";
      GPUCanvasToneMapping toneMapping = {};
      GPUCanvasAlphaMode alphaMode = "opaque";
    };
    
    partial interface GPUCanvasContext {
        GPUCanvasContextAttributes getContextAttributes();
    };

    And the spec text change would be as simple as something like: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-canvas-getcontextattributes

  4. mdrejhon commented on Sep 4, 2024

    @mdrejhon

    FYI, as of September 1st, I have now publicly launched a HDR CANVAs testing website also good for browser engine devs: https://beta.testufo.com and its HDR tester at https://beta.testufo.com/hdr

    It would be nice at the javascript level if I could feature-detect whether HDR support is GPU-accelerated or not, since some HDR operations are ginormously slow compared to SDR operations. The prevailing recommendation is instead internally benchmark HDR performance though, and disable HDR when it's not performant enough. But that slows startup if I have to briefly benchmark first.

    On MacBook M1, it runs really fast, but on some really old Intel internal GPUs from years ago (when HDR first introduced), enabling HDR suddenly causes some things to really slow down in mysterious ways -- highly suggestive of some HDR operations not GPU accelerated.

  5. mwyrzykowski commented on Sep 11, 2024

    @mwyrzykowski

    Would feature detection of HDR canvas be beneficial? Even assuming a browser supports HDR canvas and the display does as well, the brightness of the display combined with absolute headroom may result in available headroom not much above 1 at maximal brightness.

    E.g., on my Studio Display with 600 nits brightness, a difference in HDR particles is observable at lower brightness display levels but unobservable at maximal brightness due to reduced headroom.

  6. kainino0x commented on Sep 11, 2024

    @kainino0x
    ContributorAuthor

    I was actually thinking mainly about detecting browser support. The media query provides hardware support info (and any headroom info should be communicated through some media query too).
    The issue is a browser can have HDR support via the media query without having it via WebGPU, and apps need to be able to feature-detect the specific path they're going to use.

    Of course the detection could be rolled together in some way, but I think they are best separate. This depends on what browsers that support WebGPU HDR do on devices that don't support it. IIRC it is allowed and the browser just does some tonemapping to SDR?

  7. ccameron-chromium commented on Sep 12, 2024

    @ccameron-chromium
    Contributor

    While the browser detection is a "nice to have, but hopefully will be forgotten in the mists of time once all browsers support this", the suggested API in this comment has benefits that are worth considering on their own.

    In particular, if I am a library and I am handed a canvas, I really really do want to know what the GPUCanvasAlphaMode of the canvas is. And so being able to query all of these things is extremely useful on its own.

  8. mdrejhon commented on Sep 16, 2024

    @mdrejhon

    Would feature detection of HDR canvas be beneficial? Even assuming a browser supports HDR canvas

    Yes. At beta.testufo.com you can turn on/off HDR canvas via the gear icon. I hand multiple offscreen canvas to central functions for processing and I've needed to track separately what color space these canvas are.

    Would be nice to get straight from the horse's mouth instead of an accompanying variable or property that tracks this.

  9. added
    api resolved
    on Sep 18, 2024
  10. Kangz commented on Sep 24, 2024

    @Kangz
    Contributor
    GPU Web WG 2024-09-18
    • KN: came up on WebGPU Samples - have an HDR sample now. ccameron suggests reflecting what the canvas configuration is, so you know whether your tone mapping request was honored. (Paid attention to by the browser, and obeyed.) How does feature detection work for hardware support? Know if the browser's looking at the option, or not.
    • MW: thumbs up
    • KG: there's a way to know if the browser consumed the request. Add a get observer to the dictionary, find out whether the browser actually accessed it. You still don't know whether the browser used it. Was recommended by HTML spec authors for WebGL-related dictionaries. Could do something similar here.
    • KN: messy but can be done. Would you prefer to rely on that rather than reflecting the configuration?
    • KG: I like reflection.
    • KN: sounds like everyone's happy with that.
    • KG/KN: testufo also asked for a query about “whether HDR support is GPU-accelerated or not”, not totally clear what this would mean
    • Resolved - reflect the information.
  11. beaufortfrancois commented on Sep 25, 2024

    @beaufortfrancois
    Contributor

    What are the next steps?

  12. Kangz commented on Sep 25, 2024

    @Kangz
    Contributor

    Someone makes a proposal for how information is reflected.

  13. beaufortfrancois commented on Sep 25, 2024

    @beaufortfrancois
    Contributor

    I've already proposed #4828 (comment). What do you think?

  14. Kangz commented on Sep 25, 2024

    @Kangz
    Contributor

    I don't have an opinion at this point, maybe editors or other folks would?

  15. 17 remaining items

  16. greggman commented on Oct 2, 2024

    @greggman
    Member

    I think it would be good to be explicit in the spec for configure.

    It should say toneMapping.mode is a request that may be ignored. It should be spelled out when it is ignored and what value will it will be set it when it is ignored.

    As it is, it says toneMapping: defaults to {} even though it says GPUToneMapping defaults to { mode: 'standard' }. That's seems to suggest toneMapping.mode can be undefined even after calling configure

    context.configure({ device, format }}; 
    console.log(context.getConfiguration().toneMapping.mode); // prints undefined
    
    context.configure({ device, format, toneMapping: { mode: 'standard' }};
    console.log(context.getConfiguration().toneMapping.mode); // prints 'standard'
    
    context.configure({ device, format, toneMapping: { mode: 'extended' }};
    console.log(context.getConfiguration().toneMapping.mode); // prints ???

    According to the spec currently it seems like in this last case toneMapping.mode will be "extended", always. If it's supposed to be ignorable then the configure spec seems like it should spell out when, how and what it becomes instead.

  17. beaufortfrancois commented on Oct 2, 2024

    @beaufortfrancois
    Contributor

    @greggman Here's a PR that hopefully addresses your valid concerns: #4909
    Thank you!

  18. kainino0x commented on Oct 2, 2024

    @kainino0x
    ContributorAuthor

    That proposal is probably fine with me (with wording tweaks), but I don't think it's necessary.

    No WebGPU implementation that supports getConfiguration would be missing toneMapping since it's require by the spec. But, the implementation is allowed to ignore that the user specified extended mode?

    I don't want HDR canvas to be optional, I want our spec to require it but also provide a way for applications to feature-detect whether the browser actually implements that part of the spec or not. It's similar to checking whether, like, GPUCommandEncoder.prototype.clearBuffer exists, even though the spec requires it, because it's newer. My expectation was:

    • Browsers with actual HDR support would avoid adding toneMapping to their dictionary definition until they've actually implemented it, because clamping to SDR on an HDR display would be out-of-spec. They could still implement other new parts of the spec while staying behind on this.
    • Browsers that don't have HDR support (or that want to prevent some webpages from accessing HDR) would pretend all displays are SDR, so they would be able to add toneMapping because "extended" and "standard" behave the same on SDR displays per spec.

    We could include a full explanation of that in the spec, non-normatively.

    Or we could make it all explicit/normative and make getConfiguration() able to return toneMapping: undefined / not return toneMapping, or we could do something like #4909.

    Or worded differently, a UA is free to ignore a request for .toneMappingMode = extended if the hardware does not support it.

    Even if we do #4909 it should only be allowed when the browser doesn't support HDR WebGPU canvas at all. It shouldn't be allowed based on hardware because it's a per-display ability, and can change if for example an HDR display is plugged into a laptop that has an SDR internal display. Technically the request could be ignored if the GPU is somehow incapable of HDR, but we should not allow sites to observe the difference between that, and the displays being incapable.

    Also the value of getConfiguration().toneMapping.mode shouldn't change when the window is dragged between displays; if it could, we would want to expose some kind of event for that, but media query change events already provide what sites need.

  19. beaufortfrancois commented on Oct 7, 2024

    @beaufortfrancois
    Contributor

    That proposal is probably fine with me (with wording tweaks), but I don't think it's necessary.

    What do you suggest as next steps? We could make #4909 non normative so that it's clear that the spec requires HDR canvas BUT we explain how web apps can feature-detect when the browser does not support yet HDR canvas. OR we can close #4909 and decide this does not belong to the spec world and should/will be explained in developer documentation (which I'll do).

    Even if we do #4909 it should only be allowed when the browser doesn't support HDR WebGPU canvas at all.

    That was the plan indeed. The value of getConfiguration().toneMapping.mode shouldn't change until configure(newConfig) or unconfigure() is called.

  20. greggman commented on Oct 7, 2024

    @greggman
    Member

    Is it per display thing?

    I think I'm confused about the different features

    1. can the display show HDR.

      I thought this was done with media queries

    2. can WebGPU provide values > 1.0

      I thought this was the toneMapping thing

    So, show a toneMapping: { mode: 'extended' } on a display that doesn't support HDR and it gets clipped or remapped (or something). ?

    As always, this color management stuff has too many parts for me to follow 😅

  21. beaufortfrancois commented on Oct 7, 2024

    @beaufortfrancois
    Contributor

    So, show a toneMapping: { mode: 'extended' } on a display that doesn't support HDR and it gets clipped or remapped (or something). ?

    "extended" unlocks the full HDR range of the screen. This mode matches "standard" in the [0, 1] range of the screen. Clamping or projection is done to the extended dynamic range of the screen but not [0, 1]. See https://developer.chrome.com/blog/new-in-webgpu-129#hdr_support_with_canvas_tone_mapping_mode

  22. ccameron-chromium commented on Oct 7, 2024

    @ccameron-chromium
    Contributor

    There should be no way for a rendering context to reject a request for any value of toneMapping.

    I view this primarily as a way to query a context for the current value of toneMapping (and the GPUCanvasAlphaMode, and everything else).

    In the short term this can be used to check "has this particular browser implemented toneMapping yet", but in the long term the answer will always only be "yes".

  23. beaufortfrancois commented on Oct 14, 2024

    @beaufortfrancois
    Contributor

    @kainino0x (gentle ping)

  24. kainino0x commented on Oct 15, 2024

    @kainino0x
    ContributorAuthor

    In the short term this can be used to check "has this particular browser implemented toneMapping yet", but in the long term the answer will always only be "yes".

    This matches what I'm suggesting. In order to make it clearer we can update the non-normative parts in the spec to explain what you're supposed to do with it, and what implementations that don't support HDR WebGPU are supposed to do (i.e. exactly how they should violate the spec to indicate their nonconformance in a detectable way).

  25. beaufortfrancois commented on Oct 16, 2024

    @beaufortfrancois
    Contributor

    @kainino0x I've started #4922. Let me know what you think.

  26. kainino0x commented on Sep 3, 2025

    @kainino0x
    ContributorAuthor

    IIRC this is all done.

  27. mdrejhon commented on Sep 4, 2025

    @mdrejhon

    There are some general canvas finer-granularity limitations that will require additional ongoing standardization work:

    Details

    Firstly, my new easier September 2025 version of HDR Test at at https://beta.testufo.com/hdr I have added best-attempt feature detection at TestUFO, with much easier switching between 2D/WebGL and SDR/WCG/HDR if your browser is already setup:

    • Canvas2D HDR
    • WebGL HDR
    • (soon) WebGPU HDR

    Relevant to gpuweb, I'm eventually adding WebGPU + WebGPU HDR there (ETA yearend) based on the good standardization progress here. That said, we've got over half a dozen canvas framebuffer combos (2D, WebGL, WebGPU, and their SDR/HDR versions).

    Standardization Refinement Request

    • More display caps info: the limbo land (HDR-less WCG displays that can use colors outside srgb gamut). It still doesn't reliably detect whether a HDR-less display is WCG-vs-SDR (e.g. srgb vs display-p3 at the display-side, not at the canvas-side).
    • More browser caps info: Need to see things at a fine granularity than SDR-vs-HDR. Unfortunately I still had to add a modicum of useragent detection, for FireFox, because of a quirk, and due to lack of HTML APIs for feature detection.

    In Chromium I finally made it 100% feature-detection, although I still have to try it via "attempt to create canvas in this colorspace" method, rather than pre-emptive capability checks.

    Example Works-But-Visual-Fail

    For example, FireFox successfully creates a display-p3 CANVAS, but doesn't show WCG properly on screen, unlike default Chromium (non-Experimental Flags). So the same display-p3 canvas on Mac under FireFox and Chrome, shows different WCG results (WCG doesn't show in the test in FireFox, but does in default stock Chromium.

    There may not (yet) be much demand in the web developer side of things for such fine capability checks, but as a trailblazer, I wanted to add these lineitems for ongoing work.

  28. kainino0x commented on Sep 4, 2025

    @kainino0x
    ContributorAuthor

    @mdrejhon if https://developer.mozilla.org/en-US/docs/Web/CSS/@media/color-gamut is insufficient could you go into some detail about why?

    Browsers are supposed to support 'display-p3' in WebGPU regardless of the screen or browser capabilities, but the media query should reflect the screen and browser capabilities. (I tested this by putting custom query color-gamut: p3 into https://mediaqueriestest.com/ and it works on chrome/safari on my mac dragging back and forth between a SDR sRGB display and the built-in HDR P3 display, with firefox always saying 'false' as expected)

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

    apiapi resolved

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions