From e62759a3fa3d20366f80ddaa70fa58ca4f61a358 Mon Sep 17 00:00:00 2001 From: Jim Date: Mon, 21 Nov 2022 08:20:11 -0800 Subject: [PATCH] libobs-d3d11: Make sure libobs knows the new adapter index Because Intel has wonderful code which forces it to run on the iGPU if there are both an Intel iGPU and an Intel dGPU on the same system, the adapter index OBS is set to internally will no longer be valid, thus if anyone calls `obs_get_video_info()` to try to find out what adapter index OBS is running on, it will be invalid on those computers. Wonderful. So, basically, this code here just fixe it so if you want to call `obs_get_video_info()`, it'll actually have a valid adapter index now, that way we can reference the adapter index when determining what GPU we're actually running on without having to like, do anything super complicated and silly like comparing adapter GUIDs just to figure out what adapter OBS is actually runing on. I don't want the code to be a mess anymore. (I like how in any other situation on the face of the planet, there's no need to force OBS to run on an integrated adapter. *Normally* OBS *should* run on the dedicated adapter, that way it can actually capture games properly. You can probably guess as to why they're forcing it to run on the integrated adapter rather than the dedicated adapter. But you know what? Whatever. I don't really care anymore I guess. Just... whatever. Here we are I guess. Also I was in a bad mood while writing this just as a disclaimer.) (I hate that this commit exist. I hate that the commit c83eaaa51c exists even more.) --- libobs-d3d11/d3d11-subsystem.cpp | 6 ++++++ libobs/obs-internal.h | 2 ++ libobs/obs.c | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 47b3fbb03..e9e244097 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -367,6 +367,10 @@ void gs_device::InitFactory() #define VENDOR_ID_INTEL 0x8086 #define IGPU_MEM (512 * 1024 * 1024) +extern "C" { +EXPORT void obs_internal_set_adapter_idx_this_is_dumb(uint32_t adapter_idx); +} + void gs_device::ReorderAdapters(uint32_t &adapterIdx) { std::vector adapterOrder; @@ -400,6 +404,8 @@ void gs_device::ReorderAdapters(uint32_t &adapterIdx) adapterOrder.erase(adapterOrder.begin() + iGPUIndex); adapterOrder.insert(adapterOrder.begin(), iGPUIndex); adapterIdx = adapterOrder[adapterIdx]; + + obs_internal_set_adapter_idx_this_is_dumb(adapterIdx); } } diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 185dad4eb..949bb7a9b 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -341,6 +341,8 @@ struct obs_core_video { pthread_mutex_t task_mutex; struct circlebuf tasks; + uint32_t adapter_index; + pthread_mutex_t mixes_mutex; DARRAY(struct obs_core_video_mix *) mixes; struct obs_core_video_mix *main_mix; diff --git a/libobs/obs.c b/libobs/obs.c index 7b0fd0f1d..6941055c5 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -462,6 +462,8 @@ static int obs_init_graphics(struct obs_video_info *ovi) bool success = true; int errorcode; + video->adapter_index = ovi->adapter; + errorcode = gs_create(&video->graphics, ovi->graphics_module, ovi->adapter); if (errorcode != GS_SUCCESS) { @@ -475,6 +477,8 @@ static int obs_init_graphics(struct obs_video_info *ovi) } } + ovi->adapter = video->adapter_index; + gs_enter_context(video->graphics); char *filename = obs_find_data_file("default.effect"); @@ -3088,3 +3092,12 @@ bool obs_weak_object_references_object(obs_weak_object_t *weak, { return weak && object && weak->object == object; } + +/* this function is a hack for the annoying intel igpu + dgpu situation. I + * guess. I don't care anymore. */ +EXPORT void obs_internal_set_adapter_idx_this_is_dumb(uint32_t adapter_idx) +{ + if (!obs) + return; + obs->video.adapter_index = adapter_idx; +}