Repository navigation
fix(🍏): light EDR for toneMapping "extended" on iOS/macOS/visionOS 26 - #643
andreialecu wants to merge 8 commits into
Conversation
Since the 26 SDKs, wantsExtendedDynamicRangeContent is deprecated and on its own no longer shows values above 1.0 brighter than SDR white. The layer now also asks for it with preferredDynamicRange and declares a contentsHeadroom; "standard" resets both. tvOS is unchanged.
The harness mounts two small canvases, toneMapping "extended" and "standard", and the spec reads their CAMetalLayer back: extended asks for CADynamicRangeHigh with a contentsHeadroom above 1 and wantsExtendedDynamicRangeContent, standard for CADynamicRangeStandard with no headroom; both are tagged extended sRGB. Skipped before iOS, macOS and visionOS 26 and where the canvas has no Core Animation layer. Without the preferredDynamicRange fix the extended canvas reports "standard" and the spec fails. The layer is read through a test-only RNWebGPU.describeCanvasLayer, left out of the TypeScript declarations.
| info[@"wantsExtendedDynamicRangeContent"] = | ||
| @(layer.wantsExtendedDynamicRangeContent); | ||
| } | ||
| if (@available(iOS 26.0, macOS 26.0, visionOS 26.0, *)) { |
There was a problem hiding this comment.
apparently this would break on xcode version below 26.
Recommended to guard these with #if RNWGPU_HAS_CA_DYNAMIC_RANGE where it is defined as:
#include <Availability.h>
#include <TargetConditionals.h>
// preferredDynamicRange, contentsHeadroom and CADynamicRange* are declared
// only by the iOS/macOS/visionOS 26 SDKs (Xcode 26). @available guards the
// runtime, not compilation, so older Xcodes need this too.
#if (TARGET_OS_IOS || TARGET_OS_VISION) && \
defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 260000
#define RNWGPU_HAS_CA_DYNAMIC_RANGE 1
#elif TARGET_OS_OSX && defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
__MAC_OS_X_VERSION_MAX_ALLOWED >= 260000
#define RNWGPU_HAS_CA_DYNAMIC_RANGE 1
#else
#define RNWGPU_HAS_CA_DYNAMIC_RANGE 0
#endif
There was a problem hiding this comment.
Good catch, thanks! Guarded in 540aa80.
One difference from the suggested macro: the visionOS SDK pins __IPHONE_OS_VERSION_MAX_ALLOWED at 17.0 (still on the visionOS 27.2 SDK), so that check would have quietly turned EDR off on visionOS. visionOS checks __VISION_OS_VERSION_MAX_ALLOWED instead:
#if (TARGET_OS_IOS && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 260000) || \
(TARGET_OS_VISION && defined(__VISION_OS_VERSION_MAX_ALLOWED) && \
__VISION_OS_VERSION_MAX_ALLOWED >= 260000) || \
(TARGET_OS_OSX && defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
__MAC_OS_X_VERSION_MAX_ALLOWED >= 260000)It lives in MetalLayerColorSpace.h. The setter and the test read-back are both in MetalLayerColorSpace.mm, so they share the same guards. With an older Xcode the layer should just keep wantsExtendedDynamicRangeContent, and CanvasToneMapping.spec.ts skips, because preferredDynamicRange isn't reported.
I only have Xcode 27 here, so I couldn't build it with Xcode 16 or earlier. I checked that it compiles on the 27 SDKs for iOS, visionOS and macOS, and on tvOS, where the guard is off.
preferredDynamicRange, contentsHeadroom and CADynamicRange* exist only in the iOS/macOS/visionOS 26 SDKs, and @available does not keep older Xcodes from failing to compile them. RNWGPU_HAS_CA_DYNAMIC_RANGE guards them at compile time. The visionOS SDK pins __IPHONE_OS_VERSION_MAX_ALLOWED at 17.0, so visionOS checks __VISION_OS_VERSION_MAX_ALLOWED. Also: the layer read-back for the spec now sits next to the setter and shares its guards, the headroom is a named constant, describeCanvasLayer is declared with the other test-only RNWebGPU methods, and the spec uses itSkipsOnWeb and drops its unreachable branches.
wcandillon
left a comment
There was a problem hiding this comment.
I'd rather not mount extra canvases in Tests.tsx for this. Could you move it to a diagnostic example instead (apps/example/src/Diagnostics/ToneMapping.tsx, registered in DiagnosticsList.tsx)?
What I have in mind: two rgba16float canvases side by side, one with toneMapping: { mode: "extended" } and one with "standard", each drawing a ramp from 0 to something like 4.0 with a marker at 1.0. On an HDR display the extended one should go visibly brighter than SDR white and the standard one should clip at white.
With that in place, please remove the Tests.tsx changes, CanvasToneMapping.spec.ts, and the describeCanvasLayer / describeNativeSurfaceLayer hook: the diagnostic screen shows the result directly, so we don't need a test-only method in the public API.
Manual testing
I have a concern about contentsHeadroom = 16. The comment says the display clamps to what it can show, but Core Animation may instead tone map the content down from the declared 16x peak, which would dim values that the display could show as is. Could you run the diagnostic on an HDR device on iOS 26 (and macOS 26 on an XDR display if you have one) and report the following?
Extended canvas: values above 1.0 are brighter than SDR white, and the ramp clips at the display's peak, not before.
Extended canvas: values between 1.0 and the display headroom are not dimmed. Comparing the same ramp in Safari with toneMapping: { mode: "extended" } on the same device is the easiest reference.
Extended canvas: the range from 0 to 1.0 looks identical to the standard canvas.
Standard canvas: clips at SDR white.
If (2) fails, could you try toneMapMode = CAToneMapModeNever on the layer, or declaring the screen's potential headroom instead of a fixed 16?
A screenshot won't capture EDR, so a photo of the device or a short description of what you see is fine.
The CanvasToneMapping spec and its test-only describeCanvasLayer hook are replaced by a diagnostic screen (Diagnostics > Canvas toneMapping): an "extended" and a "standard" rgba16float canvas side by side, each a ramp from 0 to 4.0 with a marker at 1.0 and steps of 0.5 above it, next to a strip of plain SDR white, with buttons to mount either canvas alone. Checked on that screen on an iPhone with iOS 27.2.1 (EDR headroom 8x): wantsExtendedDynamicRangeContent = NO no longer clipped "standard" there, with or without this PR: a float drawable is untagged, and Core Animation shows it as is unless the layer asks for tone mapping. The layer now sets toneMapMode (iOS 18 / macOS 15 SDKs): "standard" is tone mapped to SDR from a declared headroom of 1.0, which keeps 0-1.0 as is and clips above, and "extended" is never tone mapped, so it is not compressed to fit the headroom of 16 it declares and clips at the display's peak. toneMapMode is guarded at compile time like the 26-SDK APIs.
|
It turns out the premise here was wrong: I saw the clipping on a simulator, which doesn't show EDR. On real devices (iPhone on iOS 27.2.1, MacBook Pro XDR on macOS 27.2.1) "extended" already works on main; the actual bug is the other way around, "standard" doesn't clip. I'll open another PR for that, with the diagnostic screen you asked for. Thanks for pushing on the manual test. |
|
It turns out the premise here was wrong: I saw the clipping on a simulator, which doesn't show EDR. On real devices (iPhone on iOS 27.2.1, MacBook Pro XDR on macOS 27.2.1) "extended" already works on main; the actual bug is the other way around, "standard" doesn't clip. Replaced by #656, with the diagnostic screen you asked for. Thanks for pushing on the manual test. |
# [0.2.0](v0.1.3...v0.2.0) (2026-11-26) ### Features * add VideoFrame.nativeBufferColorSpace, on react-native-webgpu 0.26.0 ([6c21300](6c21300)), closes [wcandillon/react-native-skia#4510](wcandillon/react-native-skia#4510) [wcandillon/react-native-webgpu#643](wcandillon/react-native-webgpu#643) * **android:** decoded frames take the stream's color space where the config has none ([68f8e5b](68f8e5b))
Description
I hit this while adding an HDR preview to the react-native-webcodecs example app. Skia draws into a half-float texture, and a WebGPU canvas with
toneMapping: { mode: "extended" }should show the lights brighter than white.On iOS 26 everything clipped at SDR white, both on the simulator and on a real iPhone.
From what I found,
wantsExtendedDynamicRangeContentis deprecated in the 26 SDKs and no longer enough on its own. The layer also needspreferredDynamicRange = CADynamicRangeHighand acontentsHeadroom. With this patch, EDR works on my iPhone.Nothing fails when this happens. The canvas just drops to SDR, so anyone using extended tone mapping on iOS 26 gets SDR without knowing it.
Agent-written content
Since the 26 SDKs,
wantsExtendedDynamicRangeContentis deprecated, and on its own it no longer makes values above 1.0 show brighter than SDR white: a canvas withtoneMapping: { mode: "extended" }clips at white on iOS 26+. The layer now also asks for EDR withpreferredDynamicRange = CADynamicRangeHighand declares acontentsHeadroom;"standard"resets both. tvOS is unchanged.The 26-SDK APIs are guarded at compile time (
RNWGPU_HAS_CA_DYNAMIC_RANGE) so the package should still build with Xcode 16 and earlier. That hasn't been tested, only Xcode 27 was available.Tests
CanvasToneMapping.spec.ts: the e2e harness mounts two small canvases,"extended"and"standard", and the spec reads theirCAMetalLayerback through a test-onlyRNWebGPU.describeCanvasLayer, declared with the other test-only methods:"extended"asks forCADynamicRangeHigh, with acontentsHeadroomabove 1 andwantsExtendedDynamicRangeContent;"standard"asks forCADynamicRangeStandardwith no headroom;The spec is skipped before iOS, macOS and visionOS 26, and where the canvas has no Core Animation layer.
Verified: the suite passes (22/22) on the iOS 27.2 Simulator. Without the fix, the extended canvas reports
"standard"and the spec fails. EDR was also confirmed by eye on an iPhone (A20 Pro), with a half-float canvas showing values above 1.0 brighter than white. Not run on Android, where nothing changes.