I think modifications to the shader compiler should be taken with care. Since resources are so limited, best to focus on the bugs and establish a baseline functionality. I have made some notes for updating the SLANG format docs including a section on HDR shader programming and how RA is supposed to handle SDR data.
From the shader developer’s perspective we have three classes of shaders that do fundamentally different things. To properly ensure our shader is displayed correctly when HDR is enabled:
SDR: set ACCURATE color space in HDR setting, set 8-bit texture format or assume it will be the default, inverse tone mapper will be applied
HDR: specify 10-bit format, encode color data as PQ, ensure scale_type is not set for the final pass <- this part isn’t intuitive
WCG: set color space in HDR settings to SUPER, append hdr_v2.slang, ensure scale_type is not set <- this compounds the unintuitive aspect even further; the shader is not HDR, why do we need to append a shader labeled hdr to get it to work correctly?
First priority: fix the scale_type bug. This is affecting both the HDR and WCG shader use cases now.
Second priority: either WCG shaders will have to be updated to include hdr_v2.slang or the shader compiler will need to be updated to support something like hdr_output = 1 or #define PQ_ENCODED or some other way where the shader tells RetroArch ‘this is PQ-encoded output, don’t apply the inverse tone-mapper’. To be clear, this isn’t an override of any of the settings in RA itself, it’s simply aiding RA in identifying what functions it needs to apply for HDR rendering.
Third priority: decoupling of tone mapping parameters from various HDR functions. The current settings don’t make sense from a user-standpoint either: if I set the peak luminance to actually match my display, this means the inverse tonemapper is going to make SDR content always reach that level. Let me ask this question: if you have a 10 000 nit display, do you actually want SDR content to be able to display 10 000 nits? The description should be changed from ‘set this value according to rtings measurements’ to ‘set this value to the maximum brightness SDR content should be allowed to display’. The UI should have its own tone map settings, as most people will want the UI dimmer than content overall.
With this perspective, the toHDR shaders getting values from the RA interface rather than from the parameter menus is probably not a good idea and not intuitive. If someone is using a shader then they would expect to have full control over that shader through the shader’s parameters. Instead it would probably be better to state that the HDR inverse tone-mapper settings apply only to SDR content and don’t affect HDR shaders. To aid users, an ‘HDR’ indicator can be added to the UI showing that the content/shader is detected as HDR.
I would also recommend a switch in the interface to turn off the inverse tone-mapper entirely and just set brightness with paper white, so one doesn’t need to set peak luminance to paper white to bypass it.