mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-02-18 15:04:53 -05:00
obs-qsv11: Fix for QSV AV1 in multi-GPU system
This commit is contained in:
@@ -79,30 +79,7 @@ void qsv_encoder_version(unsigned short *major, unsigned short *minor)
|
||||
|
||||
qsv_t *qsv_encoder_open(qsv_param_t *pParams, enum qsv_codec codec)
|
||||
{
|
||||
obs_video_info ovi;
|
||||
obs_get_video_info(&ovi);
|
||||
size_t adapter_idx = ovi.adapter;
|
||||
|
||||
// Select current adapter - will be iGPU if exists due to adapter reordering
|
||||
if (codec == QSV_CODEC_AV1 && !adapters[adapter_idx].supports_av1) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (adapters[i].supports_av1) {
|
||||
adapter_idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!adapters[adapter_idx].is_intel) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (adapters[i].is_intel) {
|
||||
adapter_idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isDGPU = adapters[adapter_idx].is_dgpu;
|
||||
|
||||
QSV_Encoder_Internal *pEncoder = new QSV_Encoder_Internal(ver, isDGPU);
|
||||
QSV_Encoder_Internal *pEncoder = new QSV_Encoder_Internal(ver);
|
||||
mfxStatus sts = pEncoder->Open(pParams, codec);
|
||||
if (sts != MFX_ERR_NONE) {
|
||||
|
||||
@@ -191,12 +168,6 @@ qsv_t *qsv_encoder_open(qsv_param_t *pParams, enum qsv_codec codec)
|
||||
return (qsv_t *)pEncoder;
|
||||
}
|
||||
|
||||
bool qsv_encoder_is_dgpu(qsv_t *pContext)
|
||||
{
|
||||
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
|
||||
return pEncoder->IsDGPU();
|
||||
}
|
||||
|
||||
int qsv_encoder_headers(qsv_t *pContext, uint8_t **pSPS, uint8_t **pPPS,
|
||||
uint16_t *pnSPS, uint16_t *pnPPS)
|
||||
{
|
||||
|
||||
@@ -159,7 +159,6 @@ int qsv_param_default_preset(qsv_param_t *, const char *preset,
|
||||
int qsv_encoder_reconfig(qsv_t *, qsv_param_t *);
|
||||
void qsv_encoder_version(unsigned short *major, unsigned short *minor);
|
||||
qsv_t *qsv_encoder_open(qsv_param_t *, enum qsv_codec codec);
|
||||
bool qsv_encoder_is_dgpu(qsv_t *);
|
||||
void qsv_encoder_add_roi(qsv_t *, const struct obs_encoder_roi *roi);
|
||||
void qsv_encoder_clear_roi(qsv_t *pContext);
|
||||
int qsv_encoder_encode(qsv_t *, uint64_t, uint8_t *, uint8_t *, uint32_t,
|
||||
|
||||
@@ -71,7 +71,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
mfxHDL QSV_Encoder_Internal::g_DX_Handle = NULL;
|
||||
mfxU16 QSV_Encoder_Internal::g_numEncodersOpen = 0;
|
||||
|
||||
QSV_Encoder_Internal::QSV_Encoder_Internal(mfxVersion &version, bool isDGPU)
|
||||
QSV_Encoder_Internal::QSV_Encoder_Internal(mfxVersion &version)
|
||||
: m_pmfxSurfaces(NULL),
|
||||
m_pmfxENC(NULL),
|
||||
m_nSPSBufferSize(1024),
|
||||
@@ -81,8 +81,8 @@ QSV_Encoder_Internal::QSV_Encoder_Internal(mfxVersion &version, bool isDGPU)
|
||||
m_nTaskIdx(0),
|
||||
m_nFirstSyncTask(0),
|
||||
m_outBitstream(),
|
||||
m_isDGPU(isDGPU),
|
||||
m_sessionData(NULL)
|
||||
m_sessionData(NULL),
|
||||
m_ver(version)
|
||||
{
|
||||
mfxVariant tempImpl;
|
||||
mfxStatus sts;
|
||||
|
||||
@@ -63,7 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
class QSV_Encoder_Internal {
|
||||
public:
|
||||
QSV_Encoder_Internal(mfxVersion &version, bool isDGPU);
|
||||
QSV_Encoder_Internal(mfxVersion &version);
|
||||
~QSV_Encoder_Internal();
|
||||
|
||||
mfxStatus Open(qsv_param_t *pParams, enum qsv_codec codec);
|
||||
@@ -85,8 +85,6 @@ public:
|
||||
mfxI16 delta);
|
||||
void ClearROI();
|
||||
|
||||
bool IsDGPU() const { return m_isDGPU; }
|
||||
|
||||
protected:
|
||||
mfxStatus InitParams(qsv_param_t *pParams, enum qsv_codec codec);
|
||||
mfxStatus AllocateSurfaces();
|
||||
@@ -135,7 +133,6 @@ private:
|
||||
mfxBitstream m_outBitstream;
|
||||
bool m_bUseD3D11;
|
||||
bool m_bUseTexAlloc;
|
||||
bool m_isDGPU;
|
||||
static mfxU16 g_numEncodersOpen;
|
||||
static mfxHDL
|
||||
g_DX_Handle; // we only want one handle for all instances to use;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
struct adapter_info adapters[MAX_ADAPTERS] = {0};
|
||||
size_t adapter_count = 0;
|
||||
size_t adapter_index = 0;
|
||||
|
||||
void PrintErrString(int err, const char *filestr, int line)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ struct adapter_info {
|
||||
#define MAX_ADAPTERS 10
|
||||
extern struct adapter_info adapters[MAX_ADAPTERS];
|
||||
extern size_t adapter_count;
|
||||
extern size_t adapter_index;
|
||||
|
||||
void util_cpuid(int cpuinfo[4], int flags);
|
||||
void check_adapters(struct adapter_info *adapters, size_t *adapter_count);
|
||||
@@ -162,7 +163,7 @@ int GetFreeTaskIndex(Task *pTaskPool, mfxU16 nPoolSize);
|
||||
mfxStatus Initialize(mfxVersion ver, mfxSession *pSession,
|
||||
mfxFrameAllocator *pmfxAllocator, mfxHDL *deviceHandle,
|
||||
bool bCreateSharedHandles, enum qsv_codec codec,
|
||||
void **data); //vpl change
|
||||
void **data);
|
||||
|
||||
// Release global shared resources (device/display)
|
||||
void Release();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <intrin.h>
|
||||
#include <inttypes.h>
|
||||
#include <obs-module.h>
|
||||
|
||||
/* =======================================================
|
||||
* Windows implementation of OS-specific utility functions
|
||||
@@ -29,6 +30,29 @@ mfxStatus Initialize(mfxVersion ver, mfxSession *pSession,
|
||||
UNUSED_PARAMETER(codec);
|
||||
UNUSED_PARAMETER(data);
|
||||
|
||||
obs_video_info ovi;
|
||||
obs_get_video_info(&ovi);
|
||||
mfxU32 adapter_idx = ovi.adapter;
|
||||
|
||||
// Select current adapter - will be iGPU if exists due to adapter reordering
|
||||
if (codec == QSV_CODEC_AV1 && !adapters[adapter_idx].supports_av1) {
|
||||
for (mfxU32 i = 0; i < 4; i++) {
|
||||
if (adapters[i].supports_av1) {
|
||||
adapter_idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!adapters[adapter_idx].is_intel) {
|
||||
for (mfxU32 i = 0; i < 4; i++) {
|
||||
if (adapters[i].is_intel) {
|
||||
adapter_idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
adapter_index = adapter_idx;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
mfxVariant impl;
|
||||
|
||||
@@ -56,7 +80,7 @@ mfxStatus Initialize(mfxVersion ver, mfxSession *pSession,
|
||||
(const mfxU8 *)"mfxImplDescription.AccelerationMode",
|
||||
impl);
|
||||
|
||||
sts = MFXCreateSession(loader, 0, pSession);
|
||||
sts = MFXCreateSession(loader, adapter_idx, pSession);
|
||||
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
|
||||
|
||||
// Create DirectX device context
|
||||
@@ -109,7 +133,7 @@ mfxStatus Initialize(mfxVersion ver, mfxSession *pSession,
|
||||
(const mfxU8 *)"mfxImplDescription.AccelerationMode",
|
||||
impl);
|
||||
|
||||
sts = MFXCreateSession(loader, 0, pSession);
|
||||
sts = MFXCreateSession(loader, adapter_idx, pSession);
|
||||
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
|
||||
}
|
||||
return sts;
|
||||
|
||||
@@ -1098,7 +1098,7 @@ static inline void cap_resolution(struct obs_qsv *obsqsv,
|
||||
uint32_t width = obs_encoder_get_width(obsqsv->encoder);
|
||||
uint32_t height = obs_encoder_get_height(obsqsv->encoder);
|
||||
|
||||
if (qsv_encoder_is_dgpu(obsqsv->context))
|
||||
if (adapters[adapter_index].is_dgpu == true)
|
||||
qsv_platform = QSV_CPU_PLATFORM_UNKNOWN;
|
||||
|
||||
info->height = height;
|
||||
|
||||
Reference in New Issue
Block a user