This series allows linking of our d3dx9.dll against d3dcompiler.lib from the Windows SDK. It presumably also fixes the d3dcompiler tests, although I didn't bother building them with Visual Studio so far.
And yes, I did check, that stringification macro works on MSVC.
-- v3: d3dcompiler: Make D3DAssemble a private export. d3dcompiler/tests: Load D3DAssemble via GetProcAddress. d3dx9: Load D3DAssemble via GetProcAddress.
From: Stefan Dösinger stefan@codeweavers.com
This allows linking our d3dx9.dll to Microsoft's d3dcompiler.lib implib. --- dlls/d3dx9_36/shader.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c index 1aa75d64dc5..7d06090aa15 100644 --- a/dlls/d3dx9_36/shader.c +++ b/dlls/d3dx9_36/shader.c @@ -26,11 +26,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
-/* This function is not declared in the SDK headers yet. */ -HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename, - const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, - ID3DBlob **shader, ID3DBlob **error_messages); - static inline BOOL is_valid_bytecode(DWORD token) { return (token & 0xfffe0000) == 0xfffe0000; @@ -193,19 +188,41 @@ HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const return S_FALSE; }
+static BOOL WINAPI load_d3dassemble_once(INIT_ONCE *once, void *param, void **context) +{ + /* FIXME: This assumes that d3dcompiler.h and dlls/d3dcompiler_XX/Makefile.in stay + * in sync regarding which library creates the unnumbered d3dcompiler.lib implib. + * GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, D3DCompile) would + * be nice, but "D3DCompile" will point to the IAT stub, not d3dcompiler_xy.dll */ + HMODULE mod = GetModuleHandleW(D3DCOMPILER_DLL_W); + void **assemble = param; + + if (!mod) + ERR("%s not found - which d3dcompiler are we linked against?\n", D3DCOMPILER_DLL_A); + + *assemble = (void *)GetProcAddress(mod, "D3DAssemble"); + return TRUE; +} + HRESULT WINAPI D3DXAssembleShader(const char *data, UINT data_len, const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages) { + static HRESULT (WINAPI *pD3DAssemble)(const void *data, SIZE_T datasize, const char *filename, + const D3D_SHADER_MACRO * defines, ID3DInclude * include, UINT flags, + ID3DBlob * *shader, ID3DBlob * *error_messages); + static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; HRESULT hr;
TRACE("data %p, data_len %u, defines %p, include %p, flags %#lx, shader %p, error_messages %p.\n", data, data_len, defines, include, flags, shader, error_messages);
+ InitOnceExecuteOnce(&init_once, load_d3dassemble_once, &pD3DAssemble, NULL); + /* Forward to d3dcompiler: the parameter types aren't really different, the actual data types are equivalent */ - hr = D3DAssemble(data, data_len, NULL, (D3D_SHADER_MACRO *)defines, - (ID3DInclude *)include, flags, (ID3DBlob **)shader, - (ID3DBlob **)error_messages); + hr = pD3DAssemble(data, data_len, NULL, (D3D_SHADER_MACRO *)defines, + (ID3DInclude *)include, flags, (ID3DBlob **)shader, + (ID3DBlob **)error_messages);
if(hr == E_FAIL) hr = D3DXERR_INVALIDDATA; return hr;
From: Stefan Dösinger stefan@codeweavers.com
--- dlls/d3dcompiler_43/tests/asm.c | 23 +++++++++++++++-------- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 9 +++++++-- 2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/asm.c b/dlls/d3dcompiler_43/tests/asm.c index 6c22eae66c8..6d3e7013017 100644 --- a/dlls/d3dcompiler_43/tests/asm.c +++ b/dlls/d3dcompiler_43/tests/asm.c @@ -27,7 +27,7 @@ perhaps with a different name? */ #define D3DXERR_INVALIDDATA 0x88760b59
-HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename, +static HRESULT (WINAPI *pD3DAssemble)(const void *data, SIZE_T datasize, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, ID3DBlob **shader, ID3DBlob **error_messages);
@@ -57,7 +57,7 @@ static void exec_tests(const char *name, struct shader_test tests[], unsigned in for(i = 0; i < count; i++) { /* D3DAssemble sets messages to 0 if there aren't error messages */ messages = NULL; - hr = D3DAssemble(tests[i].text, strlen(tests[i].text), NULL, NULL, + hr = pD3DAssemble(tests[i].text, strlen(tests[i].text), NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "Test %s, shader %u: D3DAssemble failed with error %#lx - %ld.\n", name, i, hr, hr & 0xffff); if(messages) { @@ -1431,7 +1431,7 @@ static void failure_test(void) { { shader = NULL; messages = NULL; - hr = D3DAssemble(tests[i], strlen(tests[i]), NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); + hr = pD3DAssemble(tests[i], strlen(tests[i]), NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == D3DXERR_INVALIDDATA, "Test %u: Got unexpected hr %#lx.\n", i, hr); if (messages) { @@ -1556,7 +1556,7 @@ static void assembleshader_test(void) { /* defines test */ shader = NULL; messages = NULL; - hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); + hr = pD3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (messages) { @@ -1567,14 +1567,14 @@ static void assembleshader_test(void) {
/* NULL messages test */ shader = NULL; - hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, NULL); + hr = pD3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, NULL); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (shader) ID3D10Blob_Release(shader);
/* NULL shader test */ messages = NULL; - hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, NULL, &messages); + hr = pD3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, NULL, &messages); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (messages) { @@ -1586,7 +1586,7 @@ static void assembleshader_test(void) { shader = NULL; messages = NULL; include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl; - hr = D3DAssemble(testshader, strlen(testshader), NULL, NULL, + hr = pD3DAssemble(testshader, strlen(testshader), NULL, NULL, &include.ID3DInclude_iface, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (messages) @@ -1599,7 +1599,7 @@ static void assembleshader_test(void) { /* NULL shader tests */ shader = NULL; messages = NULL; - hr = D3DAssemble(NULL, 0, NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); + hr = pD3DAssemble(NULL, 0, NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == D3DXERR_INVALIDDATA, "Got unexpected hr %#lx.\n", hr); if (messages) { @@ -1762,6 +1762,13 @@ static void test_disassemble_shader(void)
START_TEST(asm) { + HMODULE d3dcompiler; + char buffer[20]; + + sprintf(buffer, "d3dcompiler_%d", D3D_COMPILER_VERSION); + d3dcompiler = GetModuleHandleA(buffer); + pD3DAssemble = (void *)GetProcAddress(d3dcompiler, "D3DAssemble"); + preproc_test(); ps_1_1_test(); vs_1_1_test(); diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 4fef301a721..f99aba87753 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -26,7 +26,7 @@
#define D3DXERR_INVALIDDATA 0x88760b59
-HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename, +static HRESULT (WINAPI *pD3DAssemble)(const void *data, SIZE_T datasize, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, ID3DBlob **shader, ID3DBlob **error_messages);
@@ -1499,7 +1499,7 @@ static HRESULT call_D3DAssemble(const char *source_name, ID3DInclude *include, I "#include "include\include3.h"\n" "mov oC0, c0";
- return D3DAssemble(ps_code, sizeof(ps_code), source_name, NULL, include, 0, blob, errors); + return pD3DAssemble(ps_code, sizeof(ps_code), source_name, NULL, include, 0, blob, errors); }
static HRESULT call_D3DCompile(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) @@ -1761,6 +1761,7 @@ static void test_no_output_blob(void)
START_TEST(hlsl_d3d9) { + char buffer[20]; HMODULE mod;
if (!(mod = LoadLibraryA("d3dx9_36.dll"))) @@ -1770,6 +1771,10 @@ START_TEST(hlsl_d3d9) } pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
+ sprintf(buffer, "d3dcompiler_%d", D3D_COMPILER_VERSION); + mod = GetModuleHandleA(buffer); + pD3DAssemble = (void *)GetProcAddress(mod, "D3DAssemble"); + test_swizzle(); test_math(); test_conditionals();
From: Stefan Dösinger stefan@codeweavers.com
---
It is a private export in the Windows SDK d3dcompiler.lib import library.
Changes to files other than d3dcompiler_47.spec are academic because the import libraries they generate don't exist in the Windows SDK. --- dlls/d3dcompiler_41/d3dcompiler_41.spec | 2 +- dlls/d3dcompiler_42/d3dcompiler_42.spec | 2 +- dlls/d3dcompiler_43/d3dcompiler_43.spec | 2 +- dlls/d3dcompiler_46/d3dcompiler_46.spec | 2 +- dlls/d3dcompiler_47/d3dcompiler_47.spec | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/d3dcompiler_41/d3dcompiler_41.spec b/dlls/d3dcompiler_41/d3dcompiler_41.spec index e5127bc4ab9..604c7748cf3 100644 --- a/dlls/d3dcompiler_41/d3dcompiler_41.spec +++ b/dlls/d3dcompiler_41/d3dcompiler_41.spec @@ -1,4 +1,4 @@ -@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stdcall -private D3DAssemble(ptr long str ptr ptr long ptr ptr) @ stub DebugSetMute @ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) @ stub D3DDisassemble10Effect(ptr long ptr) diff --git a/dlls/d3dcompiler_42/d3dcompiler_42.spec b/dlls/d3dcompiler_42/d3dcompiler_42.spec index e5127bc4ab9..604c7748cf3 100644 --- a/dlls/d3dcompiler_42/d3dcompiler_42.spec +++ b/dlls/d3dcompiler_42/d3dcompiler_42.spec @@ -1,4 +1,4 @@ -@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stdcall -private D3DAssemble(ptr long str ptr ptr long ptr ptr) @ stub DebugSetMute @ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) @ stub D3DDisassemble10Effect(ptr long ptr) diff --git a/dlls/d3dcompiler_43/d3dcompiler_43.spec b/dlls/d3dcompiler_43/d3dcompiler_43.spec index ab6cfa04aff..7e2d0411b4e 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_43.spec +++ b/dlls/d3dcompiler_43/d3dcompiler_43.spec @@ -1,4 +1,4 @@ -@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stdcall -private D3DAssemble(ptr long str ptr ptr long ptr ptr) @ stub DebugSetMute @ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) @ stub D3DCompressShaders diff --git a/dlls/d3dcompiler_46/d3dcompiler_46.spec b/dlls/d3dcompiler_46/d3dcompiler_46.spec index b069779db06..d6742566502 100644 --- a/dlls/d3dcompiler_46/d3dcompiler_46.spec +++ b/dlls/d3dcompiler_46/d3dcompiler_46.spec @@ -1,4 +1,4 @@ -@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stdcall -private D3DAssemble(ptr long str ptr ptr long ptr ptr) @ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) @ stdcall D3DCompile2(ptr long str ptr ptr str str long long long ptr long ptr ptr) @ stdcall D3DCompileFromFile(wstr ptr ptr str str long long ptr ptr) diff --git a/dlls/d3dcompiler_47/d3dcompiler_47.spec b/dlls/d3dcompiler_47/d3dcompiler_47.spec index 38ae8960dc5..ca132979565 100644 --- a/dlls/d3dcompiler_47/d3dcompiler_47.spec +++ b/dlls/d3dcompiler_47/d3dcompiler_47.spec @@ -1,4 +1,4 @@ -@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stdcall -private D3DAssemble(ptr long str ptr ptr long ptr ptr) @ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) @ stdcall D3DCompile2(ptr long str ptr ptr str str long long long ptr long ptr ptr) @ stdcall D3DCompileFromFile(wstr ptr ptr str str long long ptr ptr)
This merge request was approved by Matteo Bruni.