You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.
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.
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.
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?
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.
Reacted by François Beaufort, mwyrzykowski, Kai Ninomiya and Mark Rejhon
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.
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
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 undefinedcontext.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.
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.
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.
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".
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).
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.
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)
Activity
ccameron-chromium commentedon Aug 28, 2024
It appears that several of the properties set in the
GPUCanvasConfigurationare not query-able (GPUCanvasAlphaModeand thePredefinedColorSpace). 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.beaufortfrancois commentedon Aug 29, 2024
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
mdrejhon commentedon Sep 4, 2024
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.
mwyrzykowski commentedon Sep 11, 2024
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.
kainino0x commentedon Sep 11, 2024
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?
ccameron-chromium commentedon Sep 12, 2024
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
GPUCanvasAlphaModeof the canvas is. And so being able to query all of these things is extremely useful on its own.mdrejhon commentedon Sep 16, 2024
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.
Kangz commentedon Sep 24, 2024
GPU Web WG 2024-09-18
beaufortfrancois commentedon Sep 25, 2024
What are the next steps?
Kangz commentedon Sep 25, 2024
Someone makes a proposal for how information is reflected.
beaufortfrancois commentedon Sep 25, 2024
I've already proposed #4828 (comment). What do you think?
Kangz commentedon Sep 25, 2024
I don't have an opinion at this point, maybe editors or other folks would?
17 remaining items
greggman commentedon Oct 2, 2024
I think it would be good to be explicit in the spec for
configure.It should say
toneMapping.modeis 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 saysGPUToneMappingdefaults to{ mode: 'standard' }. That's seems to suggesttoneMapping.modecan beundefinedeven after calling configureAccording to the spec currently it seems like in this last case
toneMapping.modewill be"extended", always. If it's supposed to be ignorable then theconfigurespec seems like it should spell out when, how and what it becomes instead.beaufortfrancois commentedon Oct 2, 2024
@greggman Here's a PR that hopefully addresses your valid concerns: #4909
Thank you!
kainino0x commentedon Oct 2, 2024
That proposal is probably fine with me (with wording tweaks), but I don't think it's necessary.
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.clearBufferexists, even though the spec requires it, because it's newer. My expectation was:toneMappingto 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.toneMappingbecause"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 returntoneMapping: undefined/ not returntoneMapping, or we could do something like #4909.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.modeshouldn'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.beaufortfrancois commentedon Oct 7, 2024
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).
That was the plan indeed. The value of getConfiguration().toneMapping.mode shouldn't change until
configure(newConfig)orunconfigure()is called.greggman commentedon Oct 7, 2024
Is it per display thing?
I think I'm confused about the different features
can the display show HDR.
I thought this was done with media queries
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 😅
beaufortfrancois commentedon Oct 7, 2024
"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_modeccameron-chromium commentedon Oct 7, 2024
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 theGPUCanvasAlphaMode, and everything else).In the short term this can be used to check "has this particular browser implemented
toneMappingyet", but in the long term the answer will always only be "yes".beaufortfrancois commentedon Oct 14, 2024
@kainino0x (gentle ping)
kainino0x commentedon Oct 15, 2024
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).
beaufortfrancois commentedon Oct 16, 2024
@kainino0x I've started #4922. Let me know what you think.
kainino0x commentedon Sep 3, 2025
IIRC this is all done.
mdrejhon commentedon Sep 4, 2025
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:
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
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.
kainino0x commentedon Sep 4, 2025
@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 querycolor-gamut: p3into 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)