Skip to content
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

[Windows] Software Renderer Protection and 10 bit Output #23221

Merged
merged 2 commits into from
May 3, 2023

Conversation

CrystalP
Copy link
Contributor

@CrystalP CrystalP commented May 1, 2023

Description

  • Turn on D3D11 multithreading protection for dxva2 decoding + software renderer path because the main thread and the video player video thread sometimes use the non-thread safe D3D immediate context simultaneously

    • protection is disabled when playback ends, unless protection was already on (could happen if separate D3D device could not be created for DXVA decode)
    • a critical section to protect the immediate context would be better and would cover all situations, however that's a lot of changes for a case that's likely not used a lot. So, using the same solution as when a separate D3D device cannot be created for the dxva decoding.
    • no need to protect the software decode path because all operations happen on the main (=rendering) thread
  • Make swscale use the output format AV_PIX_FMT_X2BGR10 when Kodi is using a 10 bit swap chain (HDR screen&media and SDR media with "Use 10 bit for SDR" setting.

    • the rest of the code doesn't need to change as the intermediate texture is already created as DXGI_FORMAT_R10G10B10A2_UNORM in those situations

Motivation and context

The D3D debug layer triggers exceptions when using dxva2 decoding with software renderer. Can take a while, or very quickly when some breakpoints are set that significantly slow down the program and alter the usual timing.

Wrong colors on 10 bit output of software renderer.

How has this been tested?

Windows 10 x64, debug and release mode, UWP on Windows 10 as well.
Software renderer with DXVA2 decoding on and off. HDR and SDR material with HDR and SDR 10 or 8 bit output.

There are pre-existing unrelated issues with dxva2 decode + software renderer: on UWP decoded frames are presented in wrong order (improves when OSD is displayed), for x64 there are partially updated frames when playing 4k or when the OSD is displayed,

What is the effect on users?

Software renderer displays correctly HDR and works in SDR 10 bit mode.

Avoids some corruption when using dxva2 with software renderer. I didn't witness it but it would be more likely to happen on slow computers or more intensive loads (4k).

Screenshots (if appropriate):

Exception for simultaneous usage of immediate context from 2 threads:
image

Corrupted 10 bit output:
image

Fixed output:
image

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@CrystalP CrystalP added Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality Component: Video rendering Platform: Windows v21 Omega Platform: WindowsStore labels May 1, 2023
@CrystalP CrystalP added this to the Omega 21.0 Alpha 2 milestone May 1, 2023
@thexai
Copy link
Member

thexai commented May 1, 2023

Good findings! 👍

The truth is that I knew the wrong pixel format in render SW + 10 bit but I had completely forgotten.

xbmc/rendering/dx/DeviceResources.h Outdated Show resolved Hide resolved
xbmc/rendering/dx/DeviceResources.cpp Outdated Show resolved Hide resolved
xbmc/rendering/dx/DirectXHelper.cpp Outdated Show resolved Hide resolved
xbmc/rendering/dx/DirectXHelper.cpp Outdated Show resolved Hide resolved
xbmc/rendering/dx/DirectXHelper.h Outdated Show resolved Hide resolved
…tware renderer

Main thread and VP Video thread use the non-thread safe D3D immediate context simultaneously
@CrystalP
Copy link
Contributor Author

CrystalP commented May 2, 2023

Changes applied.
Further testing showed another problem with the software renderer: it has no primaries conversion so colors are a bit off when tonemapping HDR to SDR (compared with DXVA and Pixel Shaders). Not sure what to do about it.

@thexai
Copy link
Member

thexai commented May 3, 2023

Further testing showed another problem with the software renderer: it has no primaries conversion so colors are a bit off when tonemapping HDR to SDR (compared with DXVA and Pixel Shaders).

Seems this happens, probably topic for another PR...

DXVA
screenshot00002-DXVA

Software
screenshot00003-SWR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Video rendering Platform: Windows Platform: WindowsStore Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality v21 Omega
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants