Browse Source

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.)
Jim 2 years ago
parent
commit
e62759a3fa
3 changed files with 21 additions and 0 deletions
  1. 6 0
      libobs-d3d11/d3d11-subsystem.cpp
  2. 2 0
      libobs/obs-internal.h
  3. 13 0
      libobs/obs.c

+ 6 - 0
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<uint32_t> 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);
 	}
 }
 

+ 2 - 0
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;

+ 13 - 0
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;
+}