From a1b46c0fa518aed85179d1a7ff9e14799122e476 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 3 Oct 2014 14:29:47 -0700 Subject: [PATCH] libobs-d3d11: Don't depend on specific D3DCompiler I do not want the D3D11 library to depend on a specific compiler version. This way, I do not have to distribute D3D Compiler libraries with the program (proprietary binary blobs). Any particular version works because the API for the D3DCompiler function appears to be the same; the only things that change are other features and additions mostly (at least as far as I can tell). Using any version available on the system should be more than sufficient rather than depending on some specific D3D compiler version. If the user doesn't have it, a download of the latest D3D distributables should be fine, though it should work with the ones that come with windows 7+ as well. --- libobs-d3d11/CMakeLists.txt | 3 +-- libobs-d3d11/d3d11-shader.cpp | 4 ++-- libobs-d3d11/d3d11-subsystem.cpp | 26 ++++++++++++++++++++++++++ libobs-d3d11/d3d11-subsystem.hpp | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libobs-d3d11/CMakeLists.txt b/libobs-d3d11/CMakeLists.txt index d5cc5fdde..0ca632acf 100644 --- a/libobs-d3d11/CMakeLists.txt +++ b/libobs-d3d11/CMakeLists.txt @@ -29,7 +29,6 @@ set_target_properties(libobs-d3d11 target_link_libraries(libobs-d3d11 libobs d3d11 - dxgi - d3dcompiler) + dxgi) install_obs_core(libobs-d3d11) diff --git a/libobs-d3d11/d3d11-shader.cpp b/libobs-d3d11/d3d11-shader.cpp index 5b498089b..690e6c2a9 100644 --- a/libobs-d3d11/d3d11-shader.cpp +++ b/libobs-d3d11/d3d11-shader.cpp @@ -180,8 +180,8 @@ void gs_shader::Compile(const char *shaderString, const char *file, if (!shaderString) throw "No shader string specified"; - hr = D3DCompile(shaderString, strlen(shaderString), file, NULL, NULL, - "main", target, + hr = device->d3dCompile(shaderString, strlen(shaderString), file, NULL, + NULL, "main", target, D3D10_SHADER_OPTIMIZATION_LEVEL1, 0, shader, errorsBlob.Assign()); if (FAILED(hr)) { diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 07fc2f289..35de8a648 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -135,6 +135,31 @@ gs_swap_chain::gs_swap_chain(gs_device *device, const gs_init_data *data) Init(data); } +void gs_device::InitCompiler() +{ + char d3dcompiler[40] = {}; + int ver = 49; + + while (ver > 30) { + sprintf_s(d3dcompiler, 40, "D3DCompiler_%02d.dll", ver); + + HMODULE module = LoadLibraryA(d3dcompiler); + if (module) { + d3dCompile = (pD3DCompile)GetProcAddress(module, + "D3DCompile"); + if (d3dCompile) { + return; + } + + FreeLibrary(module); + } + + ver--; + } + + throw "Could not find any D3DCompiler libraries"; +} + void gs_device::InitFactory(uint32_t adapterIdx, IDXGIAdapter1 **padapter) { HRESULT hr; @@ -423,6 +448,7 @@ gs_device::gs_device(const gs_init_data *data) curSamplers[i] = NULL; } + InitCompiler(); InitFactory(data->adapter, adapter.Assign()); InitDevice(data, adapter); device_set_render_target(this, NULL, NULL); diff --git a/libobs-d3d11/d3d11-subsystem.hpp b/libobs-d3d11/d3d11-subsystem.hpp index 19fd8fec1..237649304 100644 --- a/libobs-d3d11/d3d11-subsystem.hpp +++ b/libobs-d3d11/d3d11-subsystem.hpp @@ -605,6 +605,8 @@ struct gs_device { ID3D11BlendState *curBlendState; D3D11_PRIMITIVE_TOPOLOGY curToplogy; + pD3DCompile d3dCompile; + gs_rect viewport; vector projStack; @@ -613,6 +615,7 @@ struct gs_device { matrix4 curViewMatrix; matrix4 curViewProjMatrix; + void InitCompiler(); void InitFactory(uint32_t adapterIdx, IDXGIAdapter1 **adapter); void InitDevice(const gs_init_data *data, IDXGIAdapter *adapter);