mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-14 10:50:13 +01:00
Added support for dynamic d3dcompile load
If you really want to use d3dcompile, then I think its better to find the most recent d3dcompile you have on your computer and load its D3DCompile function. This process is now automatically handled. Just define the right Preprocessor.
This commit is contained in:
parent
a1037e3bf2
commit
3a0d9c55c1
5 changed files with 72 additions and 4 deletions
|
@ -335,6 +335,12 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
||||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
||||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
decltype(D3DCompile)* D3DCompile = load_d3dcompile();
|
||||||
|
if (D3DCompile == nullptr)
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the vertex shader
|
// Create the vertex shader
|
||||||
{
|
{
|
||||||
#ifdef USE_D3DCOMPILE
|
#ifdef USE_D3DCOMPILE
|
||||||
|
@ -367,6 +373,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
||||||
}";
|
}";
|
||||||
|
|
||||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL);
|
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL);
|
||||||
|
|
||||||
if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -424,6 +431,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
||||||
}";
|
}";
|
||||||
|
|
||||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL);
|
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL);
|
||||||
|
|
||||||
if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||||
return false;
|
return false;
|
||||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), &g_pPixelShader) != S_OK)
|
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), &g_pPixelShader) != S_OK)
|
||||||
|
@ -434,6 +442,10 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
unload_d3dcompile();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the blending setup
|
// Create the blending setup
|
||||||
{
|
{
|
||||||
D3D10_BLEND_DESC desc;
|
D3D10_BLEND_DESC desc;
|
||||||
|
|
|
@ -342,6 +342,12 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
||||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
||||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
decltype(D3DCompile)* D3DCompile = load_d3dcompile();
|
||||||
|
if (D3DCompile == nullptr)
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the vertex shader
|
// Create the vertex shader
|
||||||
{
|
{
|
||||||
#ifdef USE_D3DCOMPILE
|
#ifdef USE_D3DCOMPILE
|
||||||
|
@ -441,6 +447,10 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
unload_d3dcompile();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the blending setup
|
// Create the blending setup
|
||||||
{
|
{
|
||||||
D3D11_BLEND_DESC desc;
|
D3D11_BLEND_DESC desc;
|
||||||
|
|
|
@ -468,6 +468,12 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
||||||
psoDesc.SampleDesc.Count = 1;
|
psoDesc.SampleDesc.Count = 1;
|
||||||
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
|
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
decltype(D3DCompile)* D3DCompile = load_d3dcompile();
|
||||||
|
if (D3DCompile == nullptr)
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the vertex shader
|
// Create the vertex shader
|
||||||
{
|
{
|
||||||
#ifdef USE_D3DCOMPILE
|
#ifdef USE_D3DCOMPILE
|
||||||
|
@ -546,6 +552,10 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
unload_d3dcompile();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create the blending setup
|
// Create the blending setup
|
||||||
{
|
{
|
||||||
D3D12_BLEND_DESC& desc = psoDesc.BlendState;
|
D3D12_BLEND_DESC& desc = psoDesc.BlendState;
|
||||||
|
|
|
@ -1,5 +1,36 @@
|
||||||
#include "ImGui_ShaderBlobs.h"
|
#include "ImGui_ShaderBlobs.h"
|
||||||
|
|
||||||
|
#ifdef USE_D3DCOMPILE
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static HMODULE d3dcompile_dll = nullptr;
|
||||||
|
|
||||||
|
decltype(D3DCompile)* load_d3dcompile()
|
||||||
|
{
|
||||||
|
decltype(D3DCompile)* func = nullptr;
|
||||||
|
for (int i = 47; i > 30; i--)
|
||||||
|
{
|
||||||
|
char dll_name[20];
|
||||||
|
sprintf_s(dll_name, "d3dcompiler_%02d.dll", i);
|
||||||
|
if (d3dcompile_dll = LoadLibraryA(dll_name))
|
||||||
|
{
|
||||||
|
func = (decltype(D3DCompile)*)GetProcAddress(d3dcompile_dll, "D3DCompile");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unload_d3dcompile()
|
||||||
|
{
|
||||||
|
if (d3dcompile_dll)
|
||||||
|
FreeLibrary(d3dcompile_dll);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
extern unsigned char ImGui_vertexShaderDX10[] = {
|
extern unsigned char ImGui_vertexShaderDX10[] = {
|
||||||
0x44, 0x58, 0x42, 0x43, 0x7a, 0x54, 0x84, 0x96, 0xdf, 0xd1, 0x9e, 0x21,
|
0x44, 0x58, 0x42, 0x43, 0x7a, 0x54, 0x84, 0x96, 0xdf, 0xd1, 0x9e, 0x21,
|
||||||
0xfd, 0x85, 0x86, 0x3d, 0x28, 0xd1, 0x03, 0xae, 0x01, 0x00, 0x00, 0x00,
|
0xfd, 0x85, 0x86, 0x3d, 0x28, 0xd1, 0x03, 0xae, 0x01, 0x00, 0x00, 0x00,
|
||||||
|
@ -283,4 +314,6 @@ extern unsigned char ImGui_pixelShaderDX12[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -6,9 +6,12 @@
|
||||||
|
|
||||||
#ifdef USE_D3DCOMPILE
|
#ifdef USE_D3DCOMPILE
|
||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
#ifdef _MSC_VER
|
//#ifdef _MSC_VER
|
||||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
// #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
|
decltype(D3DCompile)* load_d3dcompile();
|
||||||
|
void unload_d3dcompile();
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define ImGui_vertexShaderDX10_len 876
|
#define ImGui_vertexShaderDX10_len 876
|
||||||
|
|
Loading…
Reference in a new issue