Repository navigation
Experiment: opt-in SDR-to-EDR presentation #1
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Experimental SDR-to-EDR presentation policy. This expands an SDR picture's | ||
| // highlights; it does not recover a game's original scene-referred HDR signal. | ||
| #pragma once | ||
| #include <math.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| static inline int nvn_edr_requested(void) { | ||
| const char *value = getenv("DM_PRESENT_EDR"); | ||
| return value && !strcmp(value, "1"); | ||
| } | ||
| static inline float nvn_edr_headroom(int requested, int active, float current, float potential) { | ||
| if (!requested || !active || !isfinite(current) || !isfinite(potential)) return 1; | ||
| return fmaxf(1, fminf(2, fminf(current, potential))); | ||
| } | ||
|
|
||
| // The input is the same stored SDR bytes the stock present pass samples. | ||
| // Decode once to extended-linear sRGB, keep shadows/midtones, and expand only | ||
| // luminance above 0.5. A common RGB gain preserves the highlight's chromaticity. | ||
| #define NVN_EDR_MSL \ | ||
| "float3 edr_decode(float3 x) { x=clamp(x,0.0f,1.0f); return select(pow((x+0.055f)/1.055f,float3(2.4f)),x/12.92f,x<=0.04045f); }\n" \ | ||
| "float3 edr_map(float3 rgb,float headroom,bool alreadyLinear) { float3 l=alreadyLinear?clamp(rgb,0.0f,1.0f):edr_decode(rgb); float y=dot(l,float3(0.2126f,0.7152f,0.0722f)); float w=smoothstep(0.5f,1.0f,y); return l*(1.0f+(headroom-1.0f)*w); }\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Synthetic headroom for the GPU color-transform test, never a display claim. | ||
| #include <stdatomic.h> | ||
| _Atomic float edr_probe_headroom = 2; | ||
| float front_present_edr_headroom(void) { return atomic_load(&edr_probe_headroom); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "../nvn/nvn_edr.h" | ||
| #include <stdio.h> | ||
| static int checks, failed; | ||
| #define CHECK(name, ok) do { checks++; int pass = !!(ok); failed += !pass; printf("%s: %s\n", name, pass ? "PASS" : "FAIL"); } while (0) | ||
| int main(void) { | ||
| unsetenv("DM_PRESENT_EDR"); CHECK("EDR is off by default", !nvn_edr_requested()); | ||
| setenv("DM_PRESENT_EDR", "0", 1); CHECK("zero keeps SDR", !nvn_edr_requested()); | ||
| setenv("DM_PRESENT_EDR", "1", 1); CHECK("one explicitly opts in", nvn_edr_requested()); | ||
| setenv("DM_PRESENT_EDR", "true", 1); CHECK("other values do not accidentally opt in", !nvn_edr_requested()); | ||
| CHECK("off keeps SDR headroom", nvn_edr_headroom(0, 1, 8, 8) == 1); | ||
| CHECK("an inactive scene keeps SDR", nvn_edr_headroom(1, 0, 8, 8) == 1); | ||
| CHECK("SDR-only display keeps SDR", nvn_edr_headroom(1, 1, 1, 1) == 1); | ||
| CHECK("current headroom limits output", fabsf(nvn_edr_headroom(1, 1, 1.2f, 8) - 1.2f) < 0.00001f); | ||
| CHECK("potential headroom also limits output", nvn_edr_headroom(1, 1, 8, 1.5f) == 1.5f); | ||
| CHECK("experimental boost is capped at two", nvn_edr_headroom(1, 1, 8, 8) == 2); | ||
| CHECK("invalid headroom falls back to SDR", nvn_edr_headroom(1, 1, NAN, 8) == 1); | ||
| CHECK("invalid potential falls back to SDR", nvn_edr_headroom(1, 1, 2, INFINITY) == 1); | ||
| printf("edr policy: %d checks, %d failed\n", checks, failed); | ||
| return failed != 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the shared presentation shader and its constant-buffer layout even when EDR is disabled, but the commit's validation explicitly reports no five-game route and only a Silksong smoke test rather than a gameplay route. Synthetic GPU readbacks do not exercise integration with the other games' swapchains and presentation paths. Before merging, run
scripts/regress.py check --gamesfor the five local games most likely to be affected, or document why a smaller selection establishes a narrow reach, and attach the named-game report required byAGENTS.md.AGENTS.md reference: AGENTS.md:L30-L30
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the shared uniform/shader layout changes even with EDR off. The PR description now includes a named eight-game coverage table and the narrower final-presentation report: current GPU checks cover both presentation implementations, SDR byte parity, crop/bars, conversion/headroom and MetalFX screenshots, with separate native layer checks. The only real-game evidence is the explicitly dated short Silksong off/on smoke, not a gameplay route. Only BotW/TotK currently have prepared Mac hosts, routes and saves; five routes have not been run. Normal Mac BGRA8 routes would test shared SDR integration, not the opt-in iOS float output. Multi-game gameplay acceptance remains pending before production/default adoption; I am leaving this validation thread open rather than presenting the synthetic checks as named-game passes.