Initial work on AV1 support

This commit is contained in:
Cameron Gutman
2023-07-03 00:45:36 -05:00
parent 53a572a4a4
commit a81c6a1c5e
6 changed files with 127 additions and 37 deletions
@@ -988,6 +988,36 @@ bool D3D11VARenderer::checkDecoderSupport(IDXGIAdapter* adapter)
}
break;
case VIDEO_FORMAT_AV1_MAIN8:
if (FAILED(videoDevice->CheckVideoDecoderFormat(&D3D11_DECODER_PROFILE_AV1_VLD_PROFILE0, DXGI_FORMAT_NV12, &supported))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"GPU doesn't support AV1 decoding");
videoDevice->Release();
return false;
}
else if (!supported) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"GPU doesn't support AV1 decoding to NV12 format");
videoDevice->Release();
return false;
}
break;
case VIDEO_FORMAT_AV1_MAIN10:
if (FAILED(videoDevice->CheckVideoDecoderFormat(&D3D11_DECODER_PROFILE_AV1_VLD_PROFILE0, DXGI_FORMAT_P010, &supported))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"GPU doesn't support AV1 Main10 decoding");
videoDevice->Release();
return false;
}
else if (!supported) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"GPU doesn't support AV1 Main10 decoding to P010 format");
videoDevice->Release();
return false;
}
break;
default:
SDL_assert(false);
videoDevice->Release();
@@ -19,6 +19,7 @@
#include <Limelight.h>
DEFINE_GUID(DXVADDI_Intel_ModeH264_E, 0x604F8E68,0x4951,0x4C54,0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
DEFINE_GUID(DXVA2_ModeAV1_VLD_Profile0,0xb8be4ccb,0xcf53,0x46ba,0x8d,0x59,0xd6,0xb8,0xa6,0xda,0x5d,0x2a);
#define SAFE_COM_RELEASE(x) if (x) { (x)->Release(); }
@@ -202,6 +203,12 @@ bool DXVA2Renderer::initializeDecoder()
break;
}
}
else if (m_VideoFormat == VIDEO_FORMAT_AV1_MAIN8 || m_VideoFormat == VIDEO_FORMAT_AV1_MAIN10) {
if (IsEqualGUID(guids[i], DXVA2_ModeAV1_VLD_Profile0)) {
chosenDeviceGuid = guids[i];
break;
}
}
}
CoTaskMemFree(guids);
@@ -774,7 +781,7 @@ bool DXVA2Renderer::initialize(PDECODER_PARAMETERS params)
// the screen in full-screen mode at 720p/1080p unless we use 32 pixel alignment.
// This appears to work without issues on AMD and Nvidia GPUs too, so we will
// do it unconditionally for now.
if (m_VideoFormat & VIDEO_FORMAT_MASK_H265) {
if (!(m_VideoFormat & VIDEO_FORMAT_MASK_H264)) {
alignment = 32;
}
else {
+47 -1
View File
@@ -78,6 +78,9 @@ static const QList<codec_info_t> k_NonHwaccelHEVCCodecs = {
{"hevc_omx", 0},
};
static const QList<codec_info_t> k_NonHwaccelAV1Codecs = {
};
bool FFmpegVideoDecoder::isHardwareAccelerated()
{
return m_HwDecodeCfg != nullptr ||
@@ -633,6 +636,19 @@ void FFmpegVideoDecoder::stringifyVideoStats(VIDEO_STATS& stats, char* output)
}
break;
case VIDEO_FORMAT_AV1_MAIN8:
codecString = "AV1";
break;
case VIDEO_FORMAT_AV1_MAIN10:
if (LiGetCurrentHostDisplayHdrMode()) {
codecString = "AV1 10-bit HDR";
}
else {
codecString = "AV1 10-bit SDR";
}
break;
default:
SDL_assert(false);
codecString = "UNKNOWN";
@@ -996,6 +1012,23 @@ bool FFmpegVideoDecoder::initialize(PDECODER_PARAMETERS params)
}
}
}
{
QString av1DecoderHint = qgetenv("AV1_DECODER_HINT");
if (!av1DecoderHint.isEmpty() && (params->videoFormat & VIDEO_FORMAT_MASK_AV1)) {
QByteArray decoderString = av1DecoderHint.toLocal8Bit();
if (tryInitializeRendererForDecoderByName(decoderString.constData(), params)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using custom AV1 decoder (AV1_DECODER_HINT): %s",
decoderString.constData());
return true;
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Custom AV1 decoder (AV1_DECODER_HINT) failed to load: %s",
decoderString.constData());
}
}
}
const AVCodec* decoder;
@@ -1005,6 +1038,9 @@ bool FFmpegVideoDecoder::initialize(PDECODER_PARAMETERS params)
else if (params->videoFormat & VIDEO_FORMAT_MASK_H265) {
decoder = avcodec_find_decoder(AV_CODEC_ID_HEVC);
}
else if (params->videoFormat & VIDEO_FORMAT_MASK_AV1) {
decoder = avcodec_find_decoder(AV_CODEC_ID_AV1);
}
else {
Q_ASSERT(false);
decoder = nullptr;
@@ -1042,13 +1078,23 @@ bool FFmpegVideoDecoder::initialize(PDECODER_PARAMETERS params)
}
}
}
else {
else if (params->videoFormat & VIDEO_FORMAT_MASK_H265) {
for (const codec_info_t& codecInfo : k_NonHwaccelHEVCCodecs) {
if (tryInitializeRendererForDecoderByName(codecInfo.codec, params)) {
return true;
}
}
}
else if (params->videoFormat & VIDEO_FORMAT_MASK_AV1) {
for (const codec_info_t& codecInfo : k_NonHwaccelAV1Codecs) {
if (tryInitializeRendererForDecoderByName(codecInfo.codec, params)) {
return true;
}
}
}
else {
Q_ASSERT(false);
}
// Look for the first matching hwaccel hardware decoder (pass 1)
// This picks up "second-tier" hwaccels like CUDA.