-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature detection for HDR canvas #4828
Comments
It appears that several of the properties set in the |
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 |
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. |
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). 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 |
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. |
GPU Web WG 2024-09-18
|
What are the next steps? |
Someone makes a proposal for how information is reflected. |
I've already proposed #4828 (comment). What do you think? |
I don't have an opinion at this point, maybe editors or other folks would? |
@Kangz Gotcha! @kainino0x @jimblandy @toji Shall I send a spec PR matching #4828 (comment) or do you already have something else in mind? |
I think something like that proposal is fine and does align with WebGL. I don't recommend Finally, I don't know that it's necessary to have a new dictionary? Why not just return the full |
I like Re: the new dictionary, I'm afraid we may add stuff into |
+1 to WebGL uses the same type for both input and output, it's just a bit muddied by the fact that I think it's fine to use the same type for In any case, it would be a non-breaking change if we wanted to fork the type into two versions in the future, when adding an input we don't want as an output. |
Thank you! I've started #4899 |
I believe we can close this issue as #4899 has been merged. |
I feel like I'm missing something. That value, Is it you do this? context.configure({
...
toneMapping: { mode: 'extended' },
});
const isReallyHDR = context.getConfiguration().toneMapping?.mode === 'extended'; ??? The spec does not seem to suggest |
You'd need to test whether the display is HDR as well with the a CSS media query to detect whether or not the browser has canvas HDR support for WebGPU. const hdrMediaQuery = window.matchMedia("(dynamic-range: high)");
const configuration = context.getConfiguration();
const isReallyHDR =
configuration?.toneMapping?.mode === "extended" && hdrMediaQuery.matches; |
You lost me. In your example it appears let isReallyHDR = false;
const hdrMediaQuery = window.matchMedia("(dynamic-range: high)");
if (hdrMediaQuery.matches) {
context.configure({
...
toneMapping: { mode: 'extended' },
});
isReallyHDR = true;
} Correct or incorrect? |
Sorry I should have added the following code as well in my response to make it clear. context.configure({
...
toneMapping: { mode: 'extended' },
}); Your code is correct for browsers that actually implement HDR support for WebGPU canvas. Implementations that lack it could still be feature-detected with |
See how WebKit does this for instance: WebKit/WebKit@60fafaa |
Closing, but re-open if it seems like something is still missing. |
I'm sorry if I'm being pedantic but, it sounds like what you're saying is this configuration setting, unlike all of the others, doesn't respect the user's request. Instead, the user sets it, and then sees if the setting stuck. If it didn't stick then the device doesn't implement HDR support for WebGPU canvas. // ask for HDR (no guarantee this works)
context.configure({
...
toneMapping: { mode: 'extended' },
});
// Check if I actually got HDR
const isHDR = context.getConfiguration().toneMapping.mode === 'extended'; No If that's what you're saying I don't see where in the spec it says the user's configuration for |
I do share some concerns to what @greggman is saying. Basically it seems like the Or worded differently, a UA is free to ignore a request for In some sense, this is beneficial as it allows the website to determine if the display supports HDR without the media query. But maybe some additional spec text is needed? |
The note in https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-getconfiguration was supposed to imply that the user's configuration for toneMapping: { mode: 'extended' } could be ignored as we say
I believe it's not exactly true. The display could be non-HDR but |
FYI I've started webgpu/webgpu-samples#451 to show how web developers can use this handy method to check whether HDR canvas is implemented. |
I think it would be good to be explicit in the spec for It should say As it is, it says 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 |
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,
We could include a full explanation of that in the spec, non-normatively. Or we could make it all explicit/normative and make
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 |
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 |
Is it per display thing? I think I'm confused about the different features
So, show a As always, this color management stuff has too many parts for me to follow 😅 |
|
There should be no way for a rendering context to reject a request for any value of I view this primarily as a way to query a context for the current value of In the short term this can be used to check "has this particular browser implemented |
@kainino0x (gentle ping) |
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). |
@kainino0x I've started #4922. Let me know what you think. |
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
The text was updated successfully, but these errors were encountered: