Log in

View Full Version : KODI 19.0 Matrix HDR Windows API (merged)


Pages : [1] 2

pistacho
19th January 2020, 11:41
This is a fork of Kodi 19.0 "Matrix" version that adds full HDR support with maximum image quality and HDR10 metadata passthrough in Windows 10 and UWP.

Because we are in January 2020 and Kodi does not have (yet) an official version that supports playing 4K HDR content for Windows 10, I created this fork, as a personal initiative to cover this important lack in the official version.

The source code is publicly available and has also been sent to "Kodi Team" to be merged.


KEY FEATURES


Maximum 4K image quality with passthrough of HDR10 metadata perfectly (independently verified with HDMI analyzer).
Perfect adjustment of the display refresh rate to match with content: 23,976 fps, 24,000 fps, etc.
NEW: Auto switch HDR mode and color space. Enable this feature from "Settings > Player > Use HDR display capabilities" = ON.
Toggle HDR keymap, default assigned to 'F11' key, to toggle HDR on/off from keyboard/remote (manual mode).
No need to install external programs or addons. madVR, MPC-HC, LAV filters, DSPlayer are not needed.
Play the SDR content correctly with the Windows HDR switch ON, although it is recommended for maximum quality to play the SDR content with the Windows HDR switch OFF.
On systems that do not have an HDR display, it playback HDR content using tone mapping in both DXVA and pixel shaders (HDR to SDR conversion).
Fixed important bugs in the tone mapping function present in the official versions of Kodi 18.5 and 19.0: very dark image or washed colors.
It supports the HLG (Hybrid Log-Gamma) format used for HDR in Live TV broadcasts. Compatible with the "IPTV PVR Simple client" addon but in the future more addons can be created / updated supporting it.
All HDR functionality has been implemented using only the standard Microsoft Windows API. It does not use pre-compiled external libraries or proprietary APIs from Intel or Nvidia. It does not use hacks that only work for a specific type of HW, therefore, it is highly compatible with most Intel, Nvidia, AMD or Ryzen HDMI 2.0 graphics cards.
Improved swapchain performance using some new DX12 / Windows 10 features.
Fixed NVIDIA only related stuttering/tearing issues. These are also common for 1080p SDR content but it's less obvious (still present in 18.5 / 19 master and can affect some users).



Tested on Intel NUC 8i3BEK + Denon AVX-1600H + Sony TV KD-55AG9 OLED.

and

Asus Maximus XI Hero + Asus Nvidia GTX1650 + Denon AVX-1600H + Sony TV KD-55AG9 OLED



DOWNLOAD

https://github.com/thexai/xbmc/releases



CHANGE LOG


Version 3.7.2
Updated at 29-06-2020 (merged in Kodi 19 alpha master).

Updated with latest master branch commits: includes ffmpeg 4.3, estuary skin improvements, addons installation fixes and improvements.
No changes in HDR code.


Version 3.7.1
Updated at 17-06-2020 (forked from Kodi 19 alpha master).

New advancedsettings option 'disableDXVAdiscretedecoder' for some Nvidia systems who still need it.
Updated with latest master branch commits.


Version 3.7.0
Updated at 13-06-2020 (forked from Kodi 19 alpha master).

Removed "Nvidia shared textures" workaround due is not longer need on Windows 10 2004.
Some code refactored and clean-up.
Updated with latest master branch commits.


Version 3.6.5
Updated at 30-05-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits.
Includes "peripheral.joystick" addon in installer.
No changes in HDR code.


Version 3.6.4
Updated at 20-05-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits.
No changes in HDR code.


Version 3.6.3
Updated at 09-05-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits: increased various add-on API's version.
No changes in HDR code.


Version 3.6.2
Updated at 30-04-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits: fixed seek on interlaced content DXVA.
No changes in HDR code.


Version 3.6.1
Updated at 25-04-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits: increased addons API's (inputstream v2.3.0, PVR v6.4.0) and other updates.
No changes in HDR code.


Version 3.6.0
Updated at 18-04-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits: ISO BluRay is now part of master branch, libdav1d, spdlog, inputstream bump API to v2.2.0 and many other changes.
No important changes in HDR code, only some fixes in log code after spdlog merge.


Version 3.5.0
Updated at 09-04-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits: includes fix for libraries sorting by date, add-ons updates and other issues.
Re-enabled ISO BluRay support using libudfread (although it has not yet merged into master branch).
More robust DXVA code in tone mapping mode: avoids potential apply double mappings in some systems.


Version 3.4.0
Updated at 02-04-2020 (forked from Kodi 19 alpha master).

Reverted master branch commits to 18-feb to fix ISO BluRay bug, incorrect libraries sorting by date (year 1601 bug) and other issues.
Fixed bad render HDR10 sources on some non HDR capable systems using DXVA render method.
Lighter installer since it does not include binary addons (they are also downloaded from the repository).


Version 3.3.1
Updated at 28-03-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits (fix some addons related crashes).
No changes in HDR code.


Version 3.3.0
Updated at 23-03-2020 (forked from Kodi 19 alpha master).

Fixed oversaturated HLG colors.
Switch Windows HDR off on every stop when is played HDR content.
Updated with latest master branch commits.


Version 3.2.1
Updated at 14-03-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits.
No changes in HDR code.


Version 3.2.0
Updated at 06-03-2020 (forked from Kodi 19 alpha master).

On screen notification when toggle HDR with 'F11' key (manual mode).
Removed toggle HDR from power options menu and all associated code.
Improved display HDR detection/status if system has multiple displays HDR or Kodi is using a non HDR display in a system that has HDR display.
Updated with latest master branch commits.


Version 3.1.0
Updated at 28-02-2020 (forked from Kodi 19 alpha master).

Improved HDR auto-switch timings synchronization: playing not start until switch is finished.
SDR is not restored on exit if auto switch setting is not enabled.
Updated with latest master branch commits.


Version 3.0.0
Updated at 21-02-2020 (forked from Kodi 19 alpha master).

Auto switch HDR mode and color space.
Only toggles HDR in screen currently used by Kodi (if system has various HDR screens).
Changed behavior of setting "Use display HDR capabilities": now enables HDR auto switch mode.
Updated with latest master branch commits. Includes ffmpeg 4.2.2.


Version 2.2.2
Updated at 14-02-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits.
Minor improvements in HDR code.


Version 2.2.1
Updated at 07-02-2020 (forked from Kodi 19 alpha master).

In Windows 10 is used swapchain with 6 backbuffers for all content HDR / SDR / 3D.
Updated with latest master branch commits. Includes fix libaacs decryption.
Simplified code to turn HDR on/off when Kodi starts/exits.
HDR display detection code refactored.


Version 2.2.0
Updated at 04-02-2020 (forked from Kodi 19 alpha master).

'F11' keymap to toggle HDR on/off
Restores original Windows HDR config when Kodi exits
Refactor HDR display detection code
Removed unneeded code


Version 2.1.0
Updated at 02-02-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits. Includes UHD BD improvements.
Fix for 4K HDR 60 fps content (Gemini Man).
Disabled Nvidia sharing textures (stuttering fix).
SetMaximumFrameLatency to 1 again.
Discrete decoding can use D3D_FEATURE_LEVEL_12_0.


Version 2.0.0
Updated at 01-02-2020 (forked from Kodi 19 alpha master).

Improved swapchain with some DX12/Windows 10 exclusive features.
Improved NVIDIA stability keeping low latency.
Reduced video memory usage in HDR rendering (all graphics cards).


Version 1.9.2
Updated at 31-01-2020 (forked from Kodi 19 alpha master).

Definitive cure for NVIDIA stuttering/tearing issues. (thanks @bentom)
NVIDIA Control Panel 3D profile (power management) may be no longer necessary but leave it in 'Adaptive' may be a good practice.


Version 1.9.1
Updated at 28-01-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits. Fix some crashes related to Live TV / EPG.
No changes in HDR code.


Version 1.9.0
Updated at 25-01-2020 (forked from Kodi 19 alpha master).

Removed specific NVIDIA code to workaround tearing/stuttering issues. These are due to the power saving functionality in the drivers. It is solved by
creating a maximum performance profile in NVIDIA control panel > 3D settings.
Removed 'autoHDR' option in advancedsettings.xml. Now is used GUI setting in Settings > Player > Use HDR display capabilities.


Version 1.8.1
Updated at 23-01-2020 (forked from Kodi 19 alpha master).

Fix NVIDIA HDR refresh rate match (tearing).
Updated with latest master branch commits.


Version 1.8.0
Updated at 18-01-2020 (forked from Kodi 19 alpha master).

Improves stability in NVIDIA HDR full screen switching.
Improves detection of HDR display in some multi-screen escenarios.


Version 1.7.5
Updated at 14-01-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits. Fix some crashes due recent libraries updates.
No changes in HDR code.


Version 1.7.4
Updated at 10-01-2020 (forked from Kodi 19 alpha master).

New advancedsettings option 'autoHDR' to turn on display HDR when Kodi starts.

(Copy or create text file advancedsettings.xml and place in Kodi 'userdata' folder)


Version 1.7.3
Updated at 07-01-2020 (forked from Kodi 19 alpha master).

Rebased to latest master. Now includes libbluray 1.1.2


Version 1.7.2
Updated at 06-01-2020 (forked from Kodi 19 alpha master).

Eliminate rounding errors when handling HDR metadata.
Updated with latest master branch commits.


Version 1.7.1
Updated at 05-01-2020 (forked from Kodi 19 alpha master).

Power options menu closes dialog when toggle HDR is done.
Code cleanup.


Version 1.7.0
Updated at 04-01-2020 (forked from Kodi 19 alpha master).

Toggle display HDR on/off without restart.
Internal code improvements.
Fixed: small incorrectness DXVA HW tone mapping (clipped high luminance values).


Version 1.6.1
Updated at 31-12-2019 (forked from Kodi 19 alpha master).

Some performance improvements.
Internal code changes and refactorings.


Version 1.6.0
Updated at 27-12-2019 (forked from Kodi 19 alpha master).

Fixed: bad image when is used pixel shaders render method in HDR source to SDR render.
Several internal changes that do not affect functionality but are necessary to merge with Kodi master branch.


Version 1.5.1
Updated at 26-12-2019 (forked from Kodi 19 alpha master).

Fixed: bad image when is used pixel shaders render method in HDR mode.
Improved: prevents use tone mapping when HDR is active (regardless of settings).


Version 1.5.0
Updated at 24-12-2019 (forked from Kodi 19 alpha master).

NEW: Toggles Windows HDR On/Off from power options menu.


Version 1.4.1
Updated at 19-12-2019 (forked from Kodi 19 alpha master).

Fixed: very dark image in HDR10 to SRD conversion using DXVA HW tone mapping.


Version 1.4.0
Updated at 19-12-2019 (forked from Kodi 19 alpha master).

Added support for HLG (Hybrid Log-Gamma) and Rec.2020 for Live TV


Version 1.3.0
Updated at 14-12-2019 (forked from Kodi 19 alpha master).

Improved the detection of some HDR10 streams (The Mandalorian).
Improved handle of changes in metadata at middle of stream.


Version 1.2.0
Updated at 11-12-2019 (forked from Kodi 19 alpha master).

Fixed: Some streams 4K BT.2020 are incorrect detected as HDR resulting in bad image (live IPTV).
Various improvements.


Version 1.1.0
Updated at 08-12-2019 (forked from Kodi 19 alpha master).

New: Handle changes in static HDR metadata.
New: Python 2 & Python 3 compatible versions.


Version 1.0.0:
Updated at 06-12-2019 (forked from Kodi 19 alpha master).

First release.

Klaus1189
19th January 2020, 12:34
I tested it, but again (I tested Kodi HDR builds already earlier) the HDR image is very greyisch when playing HDR videos, HDR is enabled in windows wia toggle in kodi and TV also shows HDR in OSD.
What do I do wrong here?

I deleted the old Kodi profile folder and used new settings, but the issue appears again like on the older builds.

MPC-BE with madVR looks OK here, but with wrong color because the 5700 XT has the BT2020 issue.

pistacho
19th January 2020, 12:46
Some specific models of graphics cards and some drivers have serious bugs.

"MPC-BE with madVR looks OK here, but with wrong color" OK with wrong color = NG

=> "MPC-BE with madVR also has problems with in my setup"

Klaus1189
19th January 2020, 12:52
I tested HDR videos from YouTube, some Samsung HDR testclips and some UHD Blu-rays, but every video is displayed very greyisch and TV is showing HDR in OSD info. With very greyisch I mean very, like displaying HDR video on SDR mode of TV and madVR not doing anything HDR related.

madVR should not have problems at all. I use it for several years now and the only thing is the 5700 XT BT.2020 bug in the drivers up to now. What problems do you have?

pistacho
19th January 2020, 13:43
What problems do you have?

With my HW I have no problem:

Intel NUC 8i3BEK + Denon AVX-1600H + Sony TV KD-55AG9 OLED.

also

Nvidia GTX1650 + Denon AVX-1600H + Sony TV KD-55AG9


With this HW, Kodi HDR version works perfect. I don't need madVR at all (I've never tried it).

pistacho
19th January 2020, 15:10
the HDR image is very greyisch when playing HDR videos, HDR is enabled in windows wia toggle in kodi and TV also shows HDR in OSD.
What do I do wrong here?


For some odd reason seems Kodi is not detecting HDR capable display in your system.

Check this log line at startup:


2020-01-18 17:30:04.446 T:8760 NOTICE: -----------------------------------------------------------------------
2020-01-18 17:30:04.446 T:8760 NOTICE: Starting Kodi (19.0-ALPHA1 Git:20200114-2698a89bb6). Platform: Windows NT x86 64-bit
2020-01-18 17:30:04.446 T:8760 NOTICE: Using Release Kodi x64 build
2020-01-18 17:30:04.446 T:8760 NOTICE: Kodi compiled 2020-01-14 by MSVC 191627034 for Windows NT x86 64-bit version 10.0 (0x0A000007)
2020-01-18 17:30:04.446 T:8760 NOTICE: Running on Windows 10, kernel: Windows NT x86 64-bit version 10.0.18362
2020-01-18 17:30:04.446 T:8760 NOTICE: FFmpeg version/source: 4.0.4-Kodi
2020-01-18 17:30:04.446 T:8760 NOTICE: Host CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz, 8 cores available
2020-01-18 17:30:04.446 T:8760 NOTICE: Desktop Resolution: 1920x1200 32Bit at 59Hz
2020-01-18 17:30:04.446 T:8760 NOTICE: Running with restricted rights
2020-01-18 17:30:04.446 T:8760 NOTICE: Aero is enabled
2020-01-18 17:30:04.446 T:8760 NOTICE: HDR Display capable is detected and Windows HDR switch is ON

Klaus1189
19th January 2020, 16:20
I enabled debug logging and opened the kodi.log in \AppData\Roaming\Kodi and there is exactly the red marked line in it.
If I disable the windows HDR switch, the video looks better, but still washed out, since HDR is presented as SDR without any processing of HDR metadata.
If I enable the windows switch in Kodi menu, the video looks much more greyisch. So I come to the point where I don't know any further.

pistacho
19th January 2020, 16:46
It is clear that this is not how it has to work.

For some reason it is not going well in your system but i don't know what is happening...

Other users with AMD graphics have reported that works OK. (e.g. AMD RX580)

Klaus1189
19th January 2020, 17:35
As already mentioned I have currently a RX 5700 XT. Has anybody with that card got it working? Probably PEBCAK?

pistacho
19th January 2020, 19:04
I don't know.

People only write in forums when they have issues. If someone works OK with RX 5700 XT, he hasn't said it yet.

pistacho
24th January 2020, 10:52
Version 1.8.1
Updated at 23-01-2020 (forked from Kodi 19 alpha master).


Fix NVIDIA HDR refresh rate match (tearing).
Updated with latest master branch commits.

pistacho
25th January 2020, 13:17
I found that specific stuttering and tearing issues are caused by NVIDIA drivers bug in power saving:

To fix it create a profile for kodi.exe in 3D configuration settings NVIDIA control Panel

Leave all as default except power control mode and set to maximum performance

https://images2.imagebam.com/e7/9f/a6/34cf811332038357.png


The explanation is simple:

With the energy saving activated, the GPU clock varies continuously (throttling) and reaches low as 300 MHz. These extreme variations cause display refresh rate to destabilize at 23,976 Hz.

For some reason the effect is not noticeable so much at 60 Hz. Or simply at 60Hz it already consumes more and GPU clock does not reach such low values.

And do not worry about consumption because don't consume almost anything even with maximum performance. The fans are stopped.

https://images2.imagebam.com/16/6a/b6/a4f3f31332041328.png


EDIT: Also seems beneficial set "vertical sync" to enabled.

pistacho
26th January 2020, 16:34
Version 1.9.0
Updated at 25-01-2020 (forked from Kodi 19 alpha master).


Removed specific NVIDIA code to workaround tearing/stuttering issues. These are due to the power saving functionality in the drivers. It is solved by creating a maximum performance profile in NVIDIA control panel > 3D settings.
Removed 'autoHDR' option in advancedsettings.xml. Now is used GUI setting in Settings > Player > Use HDR display capabilities.

pistacho
26th January 2020, 17:14
As already mentioned I have currently a RX 5700 XT. Has anybody with that card got it working? Probably PEBCAK?

Seems @oldpainlesskodi has RX 5700 and it worked well: https://forum.doom9.org/showthread.php?p=1895004#post1895004

Klaus1189
26th January 2020, 19:01
With madVR it works, so for this issue it is not the 5700 XT or the driver. If you want me to test something for you, I'll do it for you. Keep in mind I am clearly not a noob, just see some other posts and a thread of me ;)
I stay with my personal favourite which is clearly MPC-BE (I also do translation work for several years for this project) with both MPC Video Render and madVR.

pistacho
26th January 2020, 20:48
People using madVR are like a sect :p :)

pistacho
26th January 2020, 20:54
This has made me laugh :)

1. extract the contents of the "madVRhdrMeasure113" folder and copy and paste it into the madVR installation folder in C: without starting any installation.

2. download the file "HDR_TOGGLE.exe" to the desktop

3. I don't understand how I should set the HDR setting in madVR: let madVR decide, passtrough HDR to display, tone map HDR using pixel shaders. Which one do I select?

4. i impose the video card: 10 bit color depth and 4: 4: 4 RGB: standard pixel format PC (full RGB).
I impose in madVR: "PC Levels 0-255" "native bit depth display" 10 bits.
I impose in LG OLED B9 65: black level: HIGH.
I impose in the video LAV filter: PC RGB (0-255) and D3D11.

5. all other madVR settings are the Asmodian HIGH settings.

6. io uso Mediaportal e MPC-HC. Before playing a video i click on the HDR_TOGGLE.exe to activate the Windows HDR.

7. during HDR video playback it turns off, then on, then off and on again. Everything automatically. And I will see everything perfect.

DMU
26th January 2020, 21:05
This has made me laugh :)

What specifically made you laugh?

pistacho
27th January 2020, 20:05
I'm sorry, I was just wondering why "HDR toggle" is so complicated in Windows and gives so many headaches.

Thank you very much for providing the initial toggle code :)

DMU
27th January 2020, 22:07
you welcome
jogal detected:)

ashlar42
28th January 2020, 16:11
pistacho/jogal, why are you against having an external add-on for the HDR Toggle portion? I think it would make sense and it could speed up adoption of your code in the main branch.

pistacho
28th January 2020, 18:30
Short answer:

Because it is not necessary, (technically speaking there is no logical reason for it).

Moreover, without going into technical issues the demonstration is that it is already working without any add-on.

Is necessary Kodi add-on for switch display refresh rate?
Is necessary Kodi add-on for switch full-screen?
Is necessary Kodi add-on for switch 3D mode?
Is necessary Kodi add-on for DTS-MA passthrough?
Is necessary Kodi add-on for support 4K resolution?


However, I do not say that it cannot be done. Anyone is free to do it. Probably and taking into account that the add-ons are based on Python, when they start doing it they will see that it was not necessary / optimal.

If someone wants to do it and does it, I promise to adapt my code to work with the supposed (future) add-on. Already exist this add-on?

Or I am obligated for some reason to do something I don't want/need to do?


If there is real interest in this, the solution is easy:

- Someone from TK makes an official addon "HDR toggle for KODI"
- I adapt my code to the addon
- Merge
- END

The question is the same again: Is it necessary? Why? Who makes addon?

Fandangos
29th January 2020, 17:37
Short answer:

Because it is not necessary, (technically speaking there is no logical reason for it).

It's because the API that is called is not documented, it emerged from someone knows where.

According to the txt from the first release of that code, people found out about those APIs analyzing windows registry changes after triggering HDR on and OFF. That's quite a hack in my honest opinion.

That's just my guess how people did it based on that txt.

Kodi was part of a program that brought it to the Microsoft Windows Store.
It's also part of the Xbox game console store.
Both under the supervision of Microsoft.
Some of TK devs were part of the microsoft internal programs.

Since the API is not well documented and it's not publicly advertised to be used, I completly understand their stance to back away from it.

Putting it into an addon just protects Kodi.

Whilte on the other hand I completly understand your frustration and I honestly wish to put this HDR situation in the past.
Just having an automatic solution that works for everybody without restrictions.

This way we (or me) could ,ove along to something else like adding FSRCNNX upscaler to Kodi.

Just my opinion on this.

And I'm trying to fix Ryzen with private APIs here, which that code to turn HDR on and off solves the problem.
Since you are also working with that code, I would like to ask if you know why it defaults back to 60hz breaking 23hz.

It does for me no matter the moment it is triggered (except before playbackstarting).

If you have found a solution I really would like to know because this could be greatly used on my fork to help people with Ryzen igpus and RX 5700 gpus both plagued by this bug where bt.2020 flag using amd ags doesn't show up.

DMU
29th January 2020, 18:13
According to the txt from the first release of that code, people found out about those APIs analyzing windows registry changes after triggering HDR on and OFF. That's quite a hack in my honest opinion.

Why do you always call it "registry hack"? There is nothing registry related in this code. This code was obtained using IDA Pro Disassembler.
The DisplayConfigSetDeviceInfo (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-displayconfigsetdeviceinfo) function is documented in the MS Windows Dev Center. But its parameter DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE (https://docs.microsoft.com/ru-ru/windows/win32/api/wingdi/ne-wingdi-displayconfig_device_info_type) is not.

Fandangos
29th January 2020, 18:24
Why do you always call it "registry hack"? There is nothing registry related in this code. This code was obtained using IDA Pro Disassembler.
The DisplayConfigSetDeviceInfo (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-displayconfigsetdeviceinfo) function is documented in the MS Windows Dev Center. But its parameter DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE (https://docs.microsoft.com/ru-ru/windows/win32/api/wingdi/ne-wingdi-displayconfig_device_info_type) is not.

As I've said, I have no idea how this code was obtained.
Now it's a little more clear.

It is still a hack.

Still, using IDA Pro to perform reverse engineering to figure out a function call is a big red flag to not use it in something that will be scrutinized by the owner of the store you will put your code into.

Again, as far as I know, this can be a coincidence, PowerDVD worked with Intel during the early days of 4K UHD BD playback, before DEUHD even exist.
Intel had access to a windows API to toggle HDR on and off, that's why PowerDVD was and still is, able to toggle Windows HDR on and off.

That API is under a lot of contracts obligations according to a source from inside Intel.

If this API is the same for both, I have no idea. But if Microsoft made a special use case to be used only with it's partners like Intel and a open source software starts using because reverse engineered it using IDA Pro it doesn't seem ok.

Again, this is speculation by my part if those two apis are the same.

pistacho
29th January 2020, 18:42
It's because the API that is called is not documented, it emerged from someone knows where.

According to the txt from the first release of that code, people found out about those APIs analyzing windows registry changes after triggering HDR on and OFF. That's quite a hack in my honest opinion.

That's just my guess how people did it based on that txt.

Kodi was part of a program that brought it to the Microsoft Windows Store.
It's also part of the Xbox game console store.
Both under the supervision of Microsoft.
Some of TK devs were part of the microsoft internal programs.

Since the API is not well documented and it's not publicly advertised to be used, I completly understand their stance to back away from it.

Putting it into an addon just protects Kodi.

Whilte on the other hand I completly understand your frustration and I honestly wish to put this HDR situation in the past.
Just having an automatic solution that works for everybody without restrictions.

This way we (or me) could ,ove along to something else like adding FSRCNNX upscaler to Kodi.

Just my opinion on this.

And I'm trying to fix Ryzen with private APIs here, which that code to turn HDR on and off solves the problem.
Since you are also working with that code, I would like to ask if you know why it defaults back to 60hz breaking 23hz.

It does for me no matter the moment it is triggered (except before playbackstarting).

If you have found a solution I really would like to know because this could be greatly used on my fork to help people with Ryzen igpus and RX 5700 gpus both plagued by this bug where bt.2020 flag using amd ags doesn't show up.


This is totally false.


Code in my fork currently is not the same as original code you mention
Even original code is not a hack. Is only bad documented, buggy code and poor styling code.


For some reason some people have formed a misconception of all this and now it is very difficult (perhaps impossible) to understand things correctly.


Step one download and install Windows SDK 10.0.17763 and look at "wingdi.h"


NOTE: // comments are NOT written by me. Written by Microsoft. (download and check yourself)


typedef struct _DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
{
DISPLAYCONFIG_DEVICE_INFO_HEADER header;
union
{
struct
{
UINT32 advancedColorSupported :1; // A type of advanced color is supported
UINT32 advancedColorEnabled :1; // A type of advanced color is enabled
UINT32 wideColorEnforced :1; // Wide color gamut is enabled
UINT32 advancedColorForceDisabled :1; // Advanced color is force disabled due to system/OS policy
UINT32 reserved :28;
} DUMMYSTRUCTNAME;

UINT32 value;
} DUMMYUNIONNAME;

DISPLAYCONFIG_COLOR_ENCODING colorEncoding;
UINT32 bitsPerColorChannel;
} DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO;

typedef struct _DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
{
DISPLAYCONFIG_DEVICE_INFO_HEADER header;
union
{
struct
{
UINT32 enableAdvancedColor :1;
UINT32 reserved :31;
} DUMMYSTRUCTNAME;

UINT32 value;
}DUMMYUNIONNAME;
} DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE;

typedef enum
{
DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3,
DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4,
DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6,
DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION = 7,
DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION = 8,
DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9,
DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10,
DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL = 11,
DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_DEVICE_INFO_TYPE;



Why use a code available in the official Microsoft SDK is now a hack?

Fandangos
29th January 2020, 18:52
Why use a code available in the official Microsoft SDK is now a hack?

Ok, fair enough, now why people needed IDA Pro to come up with it?

pistacho
29th January 2020, 18:53
This is actual toggle code:



uint32_t pathCount = 0;
uint32_t modeCount = 0;
bool success = false;

if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
{
std::vector<DISPLAYCONFIG_PATH_INFO> paths(pathCount);
std::vector<DISPLAYCONFIG_MODE_INFO> modes(modeCount);

if (ERROR_SUCCESS == QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths.data(),
&modeCount, modes.data(), nullptr))
{
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO getColorInfo = {};
getColorInfo.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO;
getColorInfo.header.size = sizeof(getColorInfo);

DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE setColorState = {};
setColorState.header.type = DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE;
setColorState.header.size = sizeof(setColorState);

for (const auto& mode : modes)
{
if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
{
getColorInfo.header.adapterId.HighPart = mode.adapterId.HighPart;
getColorInfo.header.adapterId.LowPart = mode.adapterId.LowPart;
getColorInfo.header.id = mode.id;

setColorState.header.adapterId.HighPart = mode.adapterId.HighPart;
setColorState.header.adapterId.LowPart = mode.adapterId.LowPart;
setColorState.header.id = mode.id;

if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&getColorInfo.header))
{
// HDR is OFF
if (getColorInfo.advancedColorSupported && !getColorInfo.advancedColorEnabled)
{
setColorState.enableAdvancedColor = TRUE;
CLog::LogF(LOGNOTICE, "Toggle Windows HDR On (OFF => ON).");
success = (ERROR_SUCCESS == DisplayConfigSetDeviceInfo(&setColorState.header));
break;
}
// HDR is ON
else if (getColorInfo.advancedColorSupported && getColorInfo.advancedColorEnabled)
{
setColorState.enableAdvancedColor = FALSE;
CLog::LogF(LOGNOTICE, "Toggle Windows HDR Off (ON => OFF).");
success = (ERROR_SUCCESS == DisplayConfigSetDeviceInfo(&setColorState.header));
break;
}
}
}
}
}
}

return success;



Why is a hack?

Where are undocumented bytes?

Why can't this code be in Kodi core?

Why is an add-on necessary?

pistacho
29th January 2020, 18:58
Why can people (in general) become so stupid?

oldpainlesskodi
29th January 2020, 19:01
Can we all have a group hug now?

Just asking for a friend...

Fandangos
29th January 2020, 19:01
Why can people (in general) become so stupid?

I don't know talk about yourself.

If this is so explict why you needed _DMU_ code?

Why you needed somebody else to point out to you on your github by a PR? Isn't that available on Microsoft documentation?

And you are saying that people that needed to use IDA Pro to figure out a API did it because they don't know how to read documentation?

Fandangos
29th January 2020, 19:05
Can we all have a group hug now?

Just asking for a friend...

He doesn't enjoy anything group related but I am in :)

oldpainlesskodi
29th January 2020, 19:09
Laugh out loud moment right there.

DMU
29th January 2020, 19:29
And you are saying that people that needed to use IDA Pro to figure out a API did it because they don't know how to read documentation?
Yes it is. My friend does not know C++, so it was easier for him to use a disassembler to solve the problem that I asked him about.

Fandangos
29th January 2020, 19:39
Yes it is. My friend does not know C++, so it was easier for him to use a disassembler to solve the problem that I asked him about.

I don't want to add salt to the injury but... your friend that doesn't know c++, used ida pro to figure out a c++ code that, while not knowing c++ wrote a very complex c++ code that you sent us?

Am I getting this right?

DMU
29th January 2020, 19:53
Exactly. And I would not call this code "very complex" (his words).
It is easier for him to use a disassembler than to understand/study in the documentation.

Fandangos
29th January 2020, 20:15
I know you only want to best for everybody else just like me that wants the best user experience but...

Yeah, I don't buy it sorry, I can explain my reasons not to, not that it matters in the end but here it goes.

1. To be able to write that code you have to know c++ enough to at least be able to read documentation, using a disassembler claiming it's the easiest route I don't get it. This would only be needed if the documentation is lacking.
2. Microsoft has an entire sample code in GitHub with everything related to HDR on Windows, it doesn't have any kind of reference to that API. It has everything, setting the swapchain, the output format, except this.

3. Not a single soul, until you posted that, used that API on github. No one, so no one knows how to read documentation? We have tons of people with Nvidia and AMD API, including big companies like Unreal Engine with sample codes, that use Nvidia, AMD and when it comes to Intel the sample ends with, not implemented. Those people could use this API and choose not to.

4. Netflix APP that is part of Microsoft store doesn't use it. You need to enable HDR manually for 4K HDR.

5. Games on Microsoft store like the new Blair Witch as one example on the top of my head, doesn't turn HDR automatically by using this API.

So everybody else that develops for Windows and creates HDR applications be video players or games, doesn't use it but we do, only because of the code you supplied, or else we could not have done it.

So yeah... sorry man, I don't buy it.

pistacho
29th January 2020, 20:31
Microsoft aims to promote Universal apps:

(Netflix is Windows Store App)

And yes it is also well documented:
https://docs.microsoft.com/en-us/uwp/api/windows.graphics.display.core

And yes toggle code can also be ported to UWP

And yes it is also documented:
https://docs.microsoft.com/en-us/uwp/api/windows.devices.display.core

oldpainlesskodi
29th January 2020, 20:36
So, no group hug tonite?

Fandangos
29th January 2020, 20:58
Microsoft aims to promote Universal apps:

(Netflix is Windows Store App)

And yes it is also well documented:
https://docs.microsoft.com/en-us/uwp/api/windows.graphics.display.core

And yes toggle code can also be ported to UWP

And yes it is also documented:
https://docs.microsoft.com/en-us/uwp/api/windows.devices.display.core

This doesn't explain anything.
To be "universal" the user must toggle a switch before opening the app?
And this is only true for windows?

This universatility ends with the xbox one?

Read your own comment above, you said that it's ridiculous an addon to toggle hdr on and off because everything else you used as an example, be resolution, be audio format, everything is automatic on Kodi.
With the netflix app it can put your receiver into dolby format. Games can change your refresh and resolution the only thing that can't be done is hdr that requires a toggle.



I

oldpainlesskodi
29th January 2020, 21:41
So, about that group hug.....

pistacho
29th January 2020, 21:41
Games can change your refresh and resolution the only thing that can't be done is hdr that requires a toggle.

One more time providing false information:

https://www.reddit.com/r/nvidia/comments/bk5pvz/uh_so_does_hdr_automatically_turn_on_and_off_now/

Fandangos
29th January 2020, 22:09
One more time providing false information:

https://www.reddit.com/r/nvidia/comments/bk5pvz/uh_so_does_hdr_automatically_turn_on_and_off_now/

The guy is describing hdr with the nvidia api.

ashlar42
30th January 2020, 00:32
pistachio, Fandangos... don't fight, please. Kodi for Windows needs developers. From the "outside" it's quite obvious that you have potential, don't waste it fighting. Please. :)

This way we (or me) could ,ove along to something else like adding FSRCNNX upscaler to Kodi.That would absolutely awesome. Kodi's scalers are so old by now... Do it! :D (pretty please)

huhn
30th January 2020, 04:03
The guy is describing hdr with the nvidia api.

you should highlight that the user in question is not aware of the nvidia API and that it is used instead of the windows API for his game.

"everything" he talks about is "accurate" he simple doesn't understand know or why things are different.

Fandangos
30th January 2020, 11:38
you should highlight that the user in question is not aware of the nvidia API and that it is used instead of the windows API for his game.

"everything" he talks about is "accurate" he simple doesn't understand know or why things are different.

It's not that.
We are discussing an automatic method to toggle hdr state from on to off and vice versa.

It's obvious that this is possible with private apis as amd ags or nvidia nvapi, that's what I use on my fork and the example I used for unreal engine source code.

What I meant is for games that do not have those private apis like the blair witch (it's just an example) it will not switch hdr on for you, you have to turn hdr on in windows display settings.

What the guy describes on Reddit is the nvidia api because hdr is toggled on but windows hdr switch stays off.

And just a fun fact, Shadow Warrior 2 along witb Mass Effect where the one of the first pc games to get hdr support. I have not played mass effect but Shadow Warrior is really cool.

pistacho
31st January 2020, 10:49
Version 1.9.2
Updated at 31-01-2020 (forked from Kodi 19 alpha master).

Definitive cure for NVIDIA stuttering/tearing issues. (thanks @bentom)
NVIDIA Control Panel 3D profile (power management) may be no longer necessary but leave it in 'Adaptive' may be a good practice.

https://github.com/thexai/xbmc/releases

pistacho
2nd February 2020, 15:08
Version 2.1.0
Updated at 02-02-2020 (forked from Kodi 19 alpha master).

Updated with latest master branch commits. Includes UHD BD improvements.
Fix for 4K HDR 60 fps content (Gemini Man).
Disabled Nvidia sharing textures (stuttering fix).
SetMaximumFrameLatency to 1 again.
Discrete decoding can use D3D_FEATURE_LEVEL_12_0.

https://github.com/thexai/xbmc/releases

pistacho
5th February 2020, 10:50
Version 2.2.0
Updated at 04-02-2020 (forked from Kodi 19 alpha master).

'F11' keymap to toggle HDR on/off
Restores original Windows HDR config when Kodi exits
Refactor HDR display detection code
Removed unneeded code

https://github.com/thexai/xbmc/releases

pistacho
7th February 2020, 10:59
Version 2.2.1
Updated at 07-02-2020 (forked from Kodi 19 alpha master).

In Windows 10 is used swapchain with 6 backbuffers for all content HDR / SDR / 3D.
Updated with latest master branch commits. Includes libaacs decryption fix.
Simplified code to turn HDR on/off when Kodi starts/exits.
HDR display detection code refactored.

https://github.com/thexai/xbmc/releases