Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index a950fa83d89..ad27084dce0 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1523,7 +1523,7 @@ struct test_d3dinclude static void test_d3dcompile(void) { struct test_d3dinclude include = {{&test_d3dinclude_vtbl}}; - WCHAR filename[MAX_PATH], directory[MAX_PATH]; + WCHAR filename[MAX_PATH], directory[MAX_PATH], include_filename[MAX_PATH]; ID3D10Blob *blob = NULL, *errors = NULL; CHAR filename_a[MAX_PATH]; HRESULT hr; @@ -1542,12 +1542,20 @@ static void test_d3dcompile(void) static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + static const char ps_absolute_template[] = + "#include "%ls"\n" + "\n" + "float4 main() : COLOR\n" + "{\n" + " return light_color;\n" + "}"; + char ps_absolute_buffer[sizeof(ps_absolute_template) + MAX_PATH];
create_file(L"source.ps", ps_code, strlen(ps_code), filename); create_directory(L"include"); create_file(L"include\include1.h", include1_wrong, strlen(include1_wrong), NULL); create_file(L"include1.h", include1, strlen(include1), NULL); - create_file(L"include\include2.h", include2, strlen(include2), NULL); + create_file(L"include\include2.h", include2, strlen(include2), include_filename);
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL); @@ -1650,6 +1658,18 @@ static void test_d3dcompile(void) blob = NULL; }
+ sprintf(ps_absolute_buffer, ps_absolute_template, include_filename); + hr = ppD3DCompile(ps_absolute_buffer, sizeof(ps_absolute_buffer), filename_a, NULL, + D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(!!blob, "Got unexpected blob.\n"); + todo_wine ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } + GetCurrentDirectoryW(MAX_PATH, directory); SetCurrentDirectoryW(temp_dir);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/Makefile.in | 1 + dlls/d3dcompiler_43/tests/Makefile.in | 2 +- dlls/d3dcompiler_43/tests/asm.c | 80 +++++++------------------- dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 32 ++--------- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 78 ++++++++----------------- dlls/d3dcompiler_43/tests/reflection.c | 52 ++++------------- dlls/d3dcompiler_47/tests/Makefile.in | 2 +- 7 files changed, 62 insertions(+), 185 deletions(-)
diff --git a/dlls/d3dcompiler_43/Makefile.in b/dlls/d3dcompiler_43/Makefile.in index 2172217515b..1540516b607 100644 --- a/dlls/d3dcompiler_43/Makefile.in +++ b/dlls/d3dcompiler_43/Makefile.in @@ -1,4 +1,5 @@ MODULE = d3dcompiler_43.dll +IMPORTLIB = d3dcompiler_43 EXTRADEFS = -DD3D_COMPILER_VERSION=43
EXTRADLLFLAGS = -mno-cygwin -Wb,--prefer-native diff --git a/dlls/d3dcompiler_43/tests/Makefile.in b/dlls/d3dcompiler_43/tests/Makefile.in index 1b9024b7a55..6584ae92bea 100644 --- a/dlls/d3dcompiler_43/tests/Makefile.in +++ b/dlls/d3dcompiler_43/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = d3dcompiler_43.dll -IMPORTS = d3d9 user32 +IMPORTS = d3d9 user32 d3dcompiler_43 EXTRADEFS = -DD3D_COMPILER_VERSION=43
C_SRCS = \ diff --git a/dlls/d3dcompiler_43/tests/asm.c b/dlls/d3dcompiler_43/tests/asm.c index bc5af487627..3b765d3dae8 100644 --- a/dlls/d3dcompiler_43/tests/asm.c +++ b/dlls/d3dcompiler_43/tests/asm.c @@ -27,11 +27,9 @@ perhaps with a different name? */ #define D3DXERR_INVALIDDATA 0x88760b59
-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 pD3DPreprocess ppD3DPreprocess; -static pD3DDisassemble ppD3DDisassemble; +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);
struct shader_test { const char *text; @@ -59,9 +57,8 @@ 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 = pD3DAssemble(tests[i].text, strlen(tests[i].text), NULL, - NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, - &shader, &messages); + hr = D3DAssemble(tests[i].text, strlen(tests[i].text), NULL, NULL, + NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "Test %s, shader %d: D3DAssemble failed with error 0x%x - %d\n", name, i, hr, hr & 0x0000FFFF); if(messages) { trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages)); @@ -1415,9 +1412,7 @@ static void failure_test(void) { { shader = NULL; messages = NULL; - hr = pD3DAssemble(tests[i], strlen(tests[i]), NULL, - NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, - &shader, &messages); + hr = D3DAssemble(tests[i], strlen(tests[i]), NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == D3DXERR_INVALIDDATA, "Failure test, shader %d: " "expected D3DAssemble failure with D3DXERR_INVALIDDATA, " "got 0x%x - %d\n", i, hr, hr & 0x0000FFFF); @@ -1543,9 +1538,7 @@ static void assembleshader_test(void) { /* defines test */ shader = NULL; messages = NULL; - hr = pD3DAssemble(test1, strlen(test1), NULL, - defines, NULL, D3DCOMPILE_SKIP_VALIDATION, - &shader, &messages); + hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "defines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if(messages) { trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages)); @@ -1555,17 +1548,13 @@ static void assembleshader_test(void) {
/* NULL messages test */ shader = NULL; - hr = pD3DAssemble(test1, strlen(test1), NULL, - defines, NULL, D3DCOMPILE_SKIP_VALIDATION, - &shader, NULL); + hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, NULL); ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if(shader) ID3D10Blob_Release(shader);
/* NULL shader test */ messages = NULL; - hr = pD3DAssemble(test1, strlen(test1), NULL, - defines, NULL, D3DCOMPILE_SKIP_VALIDATION, - NULL, &messages); + hr = D3DAssemble(test1, strlen(test1), NULL, defines, NULL, D3DCOMPILE_SKIP_VALIDATION, NULL, &messages); ok(hr == S_OK, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if(messages) { trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages)); @@ -1576,8 +1565,8 @@ static void assembleshader_test(void) { shader = NULL; messages = NULL; include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl; - hr = pD3DAssemble(testshader, strlen(testshader), NULL, NULL, &include.ID3DInclude_iface, - D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); + hr = D3DAssemble(testshader, strlen(testshader), NULL, NULL, + &include.ID3DInclude_iface, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == S_OK, "D3DInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if(messages) { trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages)); @@ -1588,9 +1577,7 @@ static void assembleshader_test(void) { /* NULL shader tests */ shader = NULL; messages = NULL; - hr = pD3DAssemble(NULL, 0, NULL, - NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, - &shader, &messages); + hr = D3DAssemble(NULL, 0, NULL, NULL, NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages); ok(hr == D3DXERR_INVALIDDATA, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if(messages) { trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages)); @@ -1650,8 +1637,7 @@ static void d3dpreprocess_test(void) /* pDefines test */ shader = NULL; messages = NULL; - hr = ppD3DPreprocess(test1, strlen(test1), NULL, - defines, NULL, &shader, &messages); + hr = D3DPreprocess(test1, strlen(test1), NULL, defines, NULL, &shader, &messages); ok(hr == S_OK, "pDefines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (messages) { @@ -1662,15 +1648,13 @@ static void d3dpreprocess_test(void)
/* NULL messages test */ shader = NULL; - hr = ppD3DPreprocess(test1, strlen(test1), NULL, - defines, NULL, &shader, NULL); + hr = D3DPreprocess(test1, strlen(test1), NULL, defines, NULL, &shader, NULL); ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (shader) ID3D10Blob_Release(shader);
/* NULL shader test */ messages = NULL; - hr = ppD3DPreprocess(test1, strlen(test1), NULL, - defines, NULL, NULL, &messages); + hr = D3DPreprocess(test1, strlen(test1), NULL, defines, NULL, NULL, &messages); ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (messages) { @@ -1681,8 +1665,7 @@ static void d3dpreprocess_test(void) /* quotation marks test */ shader = NULL; messages = NULL; - hr = ppD3DPreprocess(quotation_marks_test, strlen(quotation_marks_test), NULL, - NULL, NULL, &shader, &messages); + hr = D3DPreprocess(quotation_marks_test, strlen(quotation_marks_test), NULL, NULL, NULL, &shader, &messages); todo_wine ok(hr == S_OK, "quotation marks test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (messages) { @@ -1697,7 +1680,7 @@ static void d3dpreprocess_test(void) { shader = NULL; messages = NULL; - hr = ppD3DPreprocess(include_test_shaders[i], strlen(include_test_shaders[i]), NULL, NULL, + hr = D3DPreprocess(include_test_shaders[i], strlen(include_test_shaders[i]), NULL, NULL, &include.ID3DInclude_iface, &shader, &messages); ok(hr == S_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (messages) @@ -1711,8 +1694,7 @@ static void d3dpreprocess_test(void) /* NULL shader tests */ shader = NULL; messages = NULL; - hr = ppD3DPreprocess(NULL, 0, NULL, - NULL, NULL, &shader, &messages); + hr = D3DPreprocess(NULL, 0, NULL, NULL, NULL, &shader, &messages); ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF); if (messages) { @@ -1742,7 +1724,7 @@ static void test_disassemble_shader(void) ID3DBlob *blob; HRESULT hr;
- hr = ppD3DDisassemble(vs_2_0, 0, 0, NULL, &blob); + hr = D3DDisassemble(vs_2_0, 0, 0, NULL, &blob); todo_wine #if D3D_COMPILER_VERSION == 47 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); @@ -1750,37 +1732,15 @@ todo_wine ok(hr == E_FAIL, "Unexpected hr %#x.\n", hr); #endif
- hr = ppD3DDisassemble(vs_2_0, sizeof(vs_2_0), 0, NULL, &blob); + hr = D3DDisassemble(vs_2_0, sizeof(vs_2_0), 0, NULL, &blob); todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); if (SUCCEEDED(hr)) ID3D10Blob_Release(blob); }
-static BOOL load_d3dcompiler(void) -{ - HMODULE module; - -#if D3D_COMPILER_VERSION == 47 - if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE; -#else - if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE; -#endif - - pD3DAssemble = (void*)GetProcAddress(module, "D3DAssemble"); - ppD3DPreprocess = (void*)GetProcAddress(module, "D3DPreprocess"); - ppD3DDisassemble = (void *)GetProcAddress(module, "D3DDisassemble"); - return TRUE; -} - START_TEST(asm) { - if (!load_d3dcompiler()) - { - win_skip("Could not load DLL.\n"); - return; - } - preproc_test(); ps_1_1_test(); vs_1_1_test(); diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d11.c b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c index 36716ed753d..8e19d4d5aa3 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d11.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c @@ -24,9 +24,6 @@ #include "d3d11.h" #include "wine/test.h"
-static pD3DCompile ppD3DCompile; -static HRESULT (WINAPI *pD3DReflect)(const void *data, SIZE_T size, REFIID iid, void **out); - static HRESULT (WINAPI *pD3D11CreateDevice)(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, @@ -49,7 +46,7 @@ static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const ID3D10Blob *blob = NULL, *errors = NULL; HRESULT hr;
- hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors); + hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors); ok_(__FILE__, line)(hr == S_OK, "Failed to compile shader, hr %#x.\n", hr); if (errors) { @@ -832,7 +829,7 @@ static void test_reflection(void) if (!code) return;
- hr = pD3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), + hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), &IID_ID3D11ShaderReflection, (void **)&reflection); ok(hr == S_OK, "Got hr %#x.\n", hr);
@@ -910,7 +907,7 @@ static void test_reflection(void) ok(!refcount, "Got unexpected refcount %u.\n", refcount);
code = compile_shader_flags(ps_source, "ps_4_0", D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY); - hr = pD3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), + hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), &IID_ID3D11ShaderReflection, (void **)&reflection); ok(hr == S_OK, "Got hr %#x.\n", hr);
@@ -1140,7 +1137,7 @@ static void test_semantic_reflection(void) continue; }
- hr = pD3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), + hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), &IID_ID3D11ShaderReflection, (void **)&reflection); ok(hr == S_OK, "Got hr %#x.\n", hr);
@@ -1177,31 +1174,10 @@ static void test_semantic_reflection(void) } }
-static BOOL load_d3dcompiler(void) -{ - HMODULE module; - -#if D3D_COMPILER_VERSION == 47 - if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE; -#else - if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE; -#endif - - ppD3DCompile = (void *)GetProcAddress(module, "D3DCompile"); - pD3DReflect = (void *)GetProcAddress(module, "D3DReflect"); - return TRUE; -} - START_TEST(hlsl_d3d11) { HMODULE mod;
- if (!load_d3dcompiler()) - { - win_skip("Could not load DLL.\n"); - return; - } - test_reflection(); test_semantic_reflection();
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index ad27084dce0..7a18992b18a 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -24,14 +24,6 @@
#include <math.h>
-static pD3DCompile ppD3DCompile; - -static HRESULT (WINAPI *pD3DCompile2)(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, - ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, UINT secondary_flags, - const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, ID3DBlob **error_messages); -static HRESULT (WINAPI *pD3DCompileFromFile)(const WCHAR *filename, const D3D_SHADER_MACRO *defines, - ID3DInclude *include, const char *entrypoint, const char *target, UINT flags1, UINT flags2, - ID3DBlob **code, ID3DBlob **errors); static HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
struct vec2 @@ -107,7 +99,7 @@ static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const ID3D10Blob *blob = NULL, *errors = NULL; HRESULT hr;
- hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors); + hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors); ok_(__FILE__, line)(hr == D3D_OK, "Failed to compile shader, hr %#x.\n", hr); if (errors) { @@ -1435,7 +1427,7 @@ static void test_fail(void) for (i = 0; i < ARRAY_SIZE(tests); ++i) { compiled = errors = NULL; - hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors); + hr = D3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors); todo_wine ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr); if (hr == E_FAIL) { @@ -1447,22 +1439,6 @@ static void test_fail(void) } }
-static BOOL load_d3dcompiler(void) -{ - HMODULE module; - -#if D3D_COMPILER_VERSION == 47 - if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE; - pD3DCompile2 = (void*)GetProcAddress(module, "D3DCompile2"); - pD3DCompileFromFile = (void*)GetProcAddress(module, "D3DCompileFromFile"); -#else - if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE; -#endif - - ppD3DCompile = (void*)GetProcAddress(module, "D3DCompile"); - return TRUE; -} - static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data, UINT *bytes) { @@ -1523,7 +1499,7 @@ struct test_d3dinclude static void test_d3dcompile(void) { struct test_d3dinclude include = {{&test_d3dinclude_vtbl}}; - WCHAR filename[MAX_PATH], directory[MAX_PATH], include_filename[MAX_PATH]; + WCHAR filename[MAX_PATH], include_filename[MAX_PATH]; ID3D10Blob *blob = NULL, *errors = NULL; CHAR filename_a[MAX_PATH]; HRESULT hr; @@ -1542,6 +1518,9 @@ static void test_d3dcompile(void) static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + +#if D3D_COMPILER_VERSION >= 46 + WCHAR directory[MAX_PATH]; static const char ps_absolute_template[] = "#include "%ls"\n" "\n" @@ -1550,6 +1529,7 @@ static void test_d3dcompile(void) " return light_color;\n" "}"; char ps_absolute_buffer[sizeof(ps_absolute_template) + MAX_PATH]; +#endif
create_file(L"source.ps", ps_code, strlen(ps_code), filename); create_directory(L"include"); @@ -1560,7 +1540,8 @@ static void test_d3dcompile(void) len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
- hr = ppD3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); + hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, + &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); ok(!errors, "Got unexpected errors.\n"); @@ -1570,15 +1551,8 @@ static void test_d3dcompile(void) blob = NULL; }
- /* Also skip D3DCompile() D3D_COMPILE_STANDARD_FILE_INCLUDE tests from - * d3dcompiler_43 or earlier since they crash on Windows. */ - if (!pD3DCompile2) - { - skip("D3DCompile2() isn't supported.\n"); - goto cleanup; - } - - hr = ppD3DCompile(ps_code, sizeof(ps_code), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, +#if D3D_COMPILER_VERSION >= 46 + hr = D3DCompile(ps_code, sizeof(ps_code), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); ok(hr == E_FAIL, "Got hr %#x.\n", hr); ok(!blob, "Got unexpected blob.\n"); @@ -1589,7 +1563,7 @@ static void test_d3dcompile(void) /* Windows always seems to resolve includes from the initial file location * instead of using the immediate parent, as it would be the case for * standard C preprocessor includes. */ - hr = ppD3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, + hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1600,7 +1574,7 @@ static void test_d3dcompile(void) blob = NULL; }
- hr = pD3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, &include.ID3DInclude_iface, + hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1611,7 +1585,7 @@ static void test_d3dcompile(void) blob = NULL; }
- hr = pD3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, + hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1622,12 +1596,12 @@ static void test_d3dcompile(void) blob = NULL; }
- hr = pD3DCompileFromFile(L"nonexistent", NULL, NULL, "main", "vs_2_0", 0, 0, &blob, &errors); + hr = D3DCompileFromFile(L"nonexistent", NULL, NULL, "main", "vs_2_0", 0, 0, &blob, &errors); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Got hr %#x.\n", hr); ok(!blob, "Got unexpected blob.\n"); ok(!errors, "Got unexpected errors.\n");
- hr = pD3DCompileFromFile(filename, NULL, NULL, "main", "ps_2_0", 0, 0, &blob, &errors); + hr = D3DCompileFromFile(filename, NULL, NULL, "main", "ps_2_0", 0, 0, &blob, &errors); ok(hr == E_FAIL, "Got hr %#x.\n", hr); ok(!blob, "Got unexpected blob.\n"); ok(!!errors, "Got unexpected errors.\n"); @@ -1635,7 +1609,7 @@ static void test_d3dcompile(void) ID3D10Blob_Release(errors); errors = NULL;
- hr = pD3DCompileFromFile(filename, NULL, &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); + hr = D3DCompileFromFile(filename, NULL, &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); ok(!errors, "Got unexpected errors.\n"); @@ -1648,7 +1622,7 @@ static void test_d3dcompile(void) /* Windows always seems to resolve includes from the initial file location * instead of using the immediate parent, as it would be the case for * standard C preprocessor includes. */ - hr = pD3DCompileFromFile(filename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); + hr = D3DCompileFromFile(filename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); ok(!errors, "Got unexpected errors.\n"); @@ -1659,7 +1633,7 @@ static void test_d3dcompile(void) }
sprintf(ps_absolute_buffer, ps_absolute_template, include_filename); - hr = ppD3DCompile(ps_absolute_buffer, sizeof(ps_absolute_buffer), filename_a, NULL, + hr = D3DCompile(ps_absolute_buffer, sizeof(ps_absolute_buffer), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1673,7 +1647,7 @@ static void test_d3dcompile(void) GetCurrentDirectoryW(MAX_PATH, directory); SetCurrentDirectoryW(temp_dir);
- hr = ppD3DCompile(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, + hr = D3DCompile(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1684,7 +1658,7 @@ static void test_d3dcompile(void) blob = NULL; }
- hr = pD3DCompile2(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, + hr = D3DCompile2(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); @@ -1695,7 +1669,7 @@ static void test_d3dcompile(void) blob = NULL; }
- hr = pD3DCompileFromFile(L"source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); + hr = D3DCompileFromFile(L"source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(!!blob, "Got unexpected blob.\n"); ok(!errors, "Got unexpected errors.\n"); @@ -1706,8 +1680,8 @@ static void test_d3dcompile(void) }
SetCurrentDirectoryW(directory); +#endif /* D3D_COMPILER_VERSION >= 46 */
-cleanup: delete_file(L"source.ps"); delete_file(L"include\include1.h"); delete_file(L"include1.h"); @@ -1719,12 +1693,6 @@ START_TEST(hlsl_d3d9) { HMODULE mod;
- if (!load_d3dcompiler()) - { - win_skip("Could not load DLL.\n"); - return; - } - if (!(mod = LoadLibraryA("d3dx9_36.dll"))) { win_skip("Failed to load d3dx9_36.dll.\n"); diff --git a/dlls/d3dcompiler_43/tests/reflection.c b/dlls/d3dcompiler_43/tests/reflection.c index bc802f016a5..75f30e45dce 100644 --- a/dlls/d3dcompiler_43/tests/reflection.c +++ b/dlls/d3dcompiler_43/tests/reflection.c @@ -38,14 +38,10 @@ */ #define D3DERR_INVALIDCALL 0x8876086c
-#if D3D_COMPILER_VERSION -static HRESULT (WINAPI *pD3DReflect)(const void *, SIZE_T, REFIID, void **); -#endif - static HRESULT call_reflect(const void *data, SIZE_T data_size, REFIID riid, void **reflection) { #if D3D_COMPILER_VERSION - return pD3DReflect(data, data_size, riid, reflection); + return D3DReflect(data, data_size, riid, reflection); #else return D3D10ReflectShader(data, data_size, (ID3D10ShaderReflection **)reflection); #endif @@ -93,7 +89,7 @@ static void test_reflection_references(void) HRESULT hr, expected; ULONG count;
- hr = pD3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D11ShaderReflection, (void **)&ref11); + hr = D3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D11ShaderReflection, (void **)&ref11); ok(hr == S_OK, "D3DReflect failed, got %x, expected %x\n", hr, S_OK);
hr = ref11->lpVtbl->QueryInterface(ref11, &IID_ID3D11ShaderReflection, (void **)&ref11_test); @@ -117,22 +113,22 @@ static void test_reflection_references(void) #else expected = E_NOINTERFACE; #endif - hr = pD3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D10ShaderReflection, (void **)&ref10); + hr = D3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D10ShaderReflection, (void **)&ref10); ok(hr == expected || broken(hr == E_NOINTERFACE) /* Windows 8 */, "D3DReflect failed, got %x, expected %x\n", hr, expected);
- hr = pD3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D10ShaderReflection1, (void **)&ref10_1); + hr = D3DReflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D10ShaderReflection1, (void **)&ref10_1); ok(hr == expected || broken(hr == E_NOINTERFACE) /* Windows 8 */, "D3DReflect failed, got %x, expected %x\n", hr, expected);
- hr = pD3DReflect(NULL, test_reflection_blob[6], &IID_ID3D10ShaderReflection1, (void **)&ref10_1); + hr = D3DReflect(NULL, test_reflection_blob[6], &IID_ID3D10ShaderReflection1, (void **)&ref10_1); ok(hr == D3DERR_INVALIDCALL, "D3DReflect failed, got %x, expected %x\n", hr, D3DERR_INVALIDCALL);
- hr = pD3DReflect(NULL, test_reflection_blob[6], &IID_ID3D11ShaderReflection, (void **)&ref11); + hr = D3DReflect(NULL, test_reflection_blob[6], &IID_ID3D11ShaderReflection, (void **)&ref11); ok(hr == D3DERR_INVALIDCALL, "D3DReflect failed, got %x, expected %x\n", hr, D3DERR_INVALIDCALL);
/* returns different errors with different sizes */ - hr = pD3DReflect(test_reflection_blob, 31, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); + hr = D3DReflect(test_reflection_blob, 31, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); ok(hr == D3DERR_INVALIDCALL, "D3DReflect failed, got %x, expected %x\n", hr, D3DERR_INVALIDCALL);
#if D3D_COMPILER_VERSION >= 46 @@ -140,19 +136,19 @@ static void test_reflection_references(void) #else expected = E_FAIL; #endif - hr = pD3DReflect(test_reflection_blob, 32, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); + hr = D3DReflect(test_reflection_blob, 32, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); ok(hr == expected, "Got %x, expected %x.\n", hr, expected);
- hr = pD3DReflect(test_reflection_blob, test_reflection_blob[6]-1, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); + hr = D3DReflect(test_reflection_blob, test_reflection_blob[6]-1, &IID_ID3D10ShaderReflection1, (void **)&ref10_1); ok(hr == expected, "Got %x, expected %x.\n", hr, expected);
- hr = pD3DReflect(test_reflection_blob, 31, &IID_ID3D11ShaderReflection, (void **)&ref11); + hr = D3DReflect(test_reflection_blob, 31, &IID_ID3D11ShaderReflection, (void **)&ref11); ok(hr == D3DERR_INVALIDCALL, "Got %x, expected %x.\n", hr, D3DERR_INVALIDCALL);
- hr = pD3DReflect(test_reflection_blob, 32, &IID_ID3D11ShaderReflection, (void **)&ref11); + hr = D3DReflect(test_reflection_blob, 32, &IID_ID3D11ShaderReflection, (void **)&ref11); ok(hr == expected, "Got %x, expected %x.\n", hr, expected);
- hr = pD3DReflect(test_reflection_blob, test_reflection_blob[6]-1, &IID_ID3D11ShaderReflection, (void **)&ref11); + hr = D3DReflect(test_reflection_blob, test_reflection_blob[6]-1, &IID_ID3D11ShaderReflection, (void **)&ref11); ok(hr == expected, "Got %x, expected %x.\n", hr, expected); } #endif @@ -2122,32 +2118,8 @@ static const D3D12_SHADER_INPUT_BIND_DESC test_reflection_bound_resources_sm51_r {"c2", D3D_SIT_CBUFFER, 0, 1, D3D_SIF_USERPACKED, 0, D3D_SRV_DIMENSION_UNKNOWN, 0, 1, 1}, };
-static BOOL load_d3dreflect(void) -{ -#if D3D_COMPILER_VERSION == 47 - static const char filename[] = "d3dcompiler_47.dll"; -#elif D3D_COMPILER_VERSION - static const char filename[] = "d3dcompiler_43.dll"; -#endif -#if D3D_COMPILER_VERSION - HMODULE module; - - if (!(module = LoadLibraryA(filename))) - return FALSE; - - pD3DReflect = (void*)GetProcAddress(module, "D3DReflect"); -#endif - return TRUE; -} - START_TEST(reflection) { - if (!load_d3dreflect()) - { - win_skip("Could not load DLL.\n"); - return; - } - #if D3D_COMPILER_VERSION test_reflection_references(); test_reflection_interfaces(); diff --git a/dlls/d3dcompiler_47/tests/Makefile.in b/dlls/d3dcompiler_47/tests/Makefile.in index 80e0144bc40..ba4bf1b99a3 100644 --- a/dlls/d3dcompiler_47/tests/Makefile.in +++ b/dlls/d3dcompiler_47/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = d3dcompiler_47.dll -IMPORTS = d3d9 user32 +IMPORTS = d3d9 user32 d3dcompiler_47 EXTRADEFS = -DD3D_COMPILER_VERSION=47 PARENTSRC = ../../d3dcompiler_43/tests
On Wed, Sep 1, 2021 at 7:13 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/Makefile.in | 1 + dlls/d3dcompiler_43/tests/Makefile.in | 2 +- dlls/d3dcompiler_43/tests/asm.c | 80 +++++++------------------- dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 32 ++--------- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 78 ++++++++----------------- dlls/d3dcompiler_43/tests/reflection.c | 52 ++++------------- dlls/d3dcompiler_47/tests/Makefile.in | 2 +- 7 files changed, 62 insertions(+), 185 deletions(-)
This is effectively a revert of a8496091931c65d7a2437281195b388498fb4533. For reference, the original emails for that patch series from Jacek are https://www.winehq.org/pipermail/wine-devel/2018-July/129711.html, https://www.winehq.org/pipermail/wine-devel/2018-July/129712.html.
I don't think we care about winelib dxvk at this point and, regardless, we probably don't have any reason for loading d3dcompiler_xx.dll dynamically anymore. AFAIU with this we're basically reintroducing a (versioned) importlib for d3dcompiler_43.dll, which seems fine to me.
So, I guess I'm asking for anybody to confirm that this seems all correct, or let me know if not. I'm probably going to sign-off on this in a day or so if I don't hear anything.
On 9/2/21 5:36 PM, Matteo Bruni wrote:
On Wed, Sep 1, 2021 at 7:13 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/Makefile.in | 1 + dlls/d3dcompiler_43/tests/Makefile.in | 2 +- dlls/d3dcompiler_43/tests/asm.c | 80 +++++++------------------- dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 32 ++--------- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 78 ++++++++----------------- dlls/d3dcompiler_43/tests/reflection.c | 52 ++++------------- dlls/d3dcompiler_47/tests/Makefile.in | 2 +- 7 files changed, 62 insertions(+), 185 deletions(-)
This is effectively a revert of a8496091931c65d7a2437281195b388498fb4533. For reference, the original emails for that patch series from Jacek are https://www.winehq.org/pipermail/wine-devel/2018-July/129711.html, https://www.winehq.org/pipermail/wine-devel/2018-July/129712.html.
I don't think we care about winelib dxvk at this point and, regardless, we probably don't have any reason for loading d3dcompiler_xx.dll dynamically anymore. AFAIU with this we're basically reintroducing a (versioned) importlib for d3dcompiler_43.dll, which seems fine to me.
So, I guess I'm asking for anybody to confirm that this seems all correct, or let me know if not. I'm probably going to sign-off on this in a day or so if I don't hear anything.
dxvk has apparently removed support for winelib builds, but dxvk notwithstanding, I'm not sure why the former patch would be necessary for the latter; it's just a matter of which library gets the unsuffixed IMPORTLIB statement. Am I missing something?
On 9/3/21 12:36 AM, Matteo Bruni wrote:
On Wed, Sep 1, 2021 at 7:13 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/Makefile.in | 1 + dlls/d3dcompiler_43/tests/Makefile.in | 2 +- dlls/d3dcompiler_43/tests/asm.c | 80 +++++++------------------- dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 32 ++--------- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 78 ++++++++----------------- dlls/d3dcompiler_43/tests/reflection.c | 52 ++++------------- dlls/d3dcompiler_47/tests/Makefile.in | 2 +- 7 files changed, 62 insertions(+), 185 deletions(-)
This is effectively a revert of a8496091931c65d7a2437281195b388498fb4533. For reference, the original emails for that patch series from Jacek are https://www.winehq.org/pipermail/wine-devel/2018-July/129711.html, https://www.winehq.org/pipermail/wine-devel/2018-July/129712.html.
I don't think we care about winelib dxvk at this point and, regardless, we probably don't have any reason for loading d3dcompiler_xx.dll dynamically anymore. AFAIU with this we're basically reintroducing a (versioned) importlib for d3dcompiler_43.dll, which seems fine to me.
So, I guess I'm asking for anybody to confirm that this seems all correct, or let me know if not. I'm probably going to sign-off on this in a day or so if I don't hear anything.
Now that we use PARENTSRC for tests, dynamic loading indeed doesn't make much sense. We still want to provide an importlib without a version in its name, but as long as d3dcompiler_47 uses a non-versioned name, that's fine.
Jacek
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- configure | 1 + configure.ac | 1 + dlls/d3dcompiler_43/tests/asm.c | 2 +- dlls/d3dcompiler_46/Makefile.in | 1 + dlls/d3dcompiler_46/tests/Makefile.in | 11 +++++++++++ 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 dlls/d3dcompiler_46/tests/Makefile.in
diff --git a/configure b/configure index 46ae09a38e8..9c40004f151 100755 --- a/configure +++ b/configure @@ -20372,6 +20372,7 @@ wine_fn_config_makefile dlls/d3dcompiler_42 enable_d3dcompiler_42 wine_fn_config_makefile dlls/d3dcompiler_43 enable_d3dcompiler_43 wine_fn_config_makefile dlls/d3dcompiler_43/tests enable_tests wine_fn_config_makefile dlls/d3dcompiler_46 enable_d3dcompiler_46 +wine_fn_config_makefile dlls/d3dcompiler_46/tests enable_tests wine_fn_config_makefile dlls/d3dcompiler_47 enable_d3dcompiler_47 wine_fn_config_makefile dlls/d3dcompiler_47/tests enable_tests wine_fn_config_makefile dlls/d3dim enable_d3dim diff --git a/configure.ac b/configure.ac index 11c43cdce47..c06eb2701ff 100644 --- a/configure.ac +++ b/configure.ac @@ -3072,6 +3072,7 @@ WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_42) WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_43) WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_43/tests) WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_46) +WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_46/tests) WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_47) WINE_CONFIG_MAKEFILE(dlls/d3dcompiler_47/tests) WINE_CONFIG_MAKEFILE(dlls/d3dim) diff --git a/dlls/d3dcompiler_43/tests/asm.c b/dlls/d3dcompiler_43/tests/asm.c index 3b765d3dae8..e467cec9623 100644 --- a/dlls/d3dcompiler_43/tests/asm.c +++ b/dlls/d3dcompiler_43/tests/asm.c @@ -1726,7 +1726,7 @@ static void test_disassemble_shader(void)
hr = D3DDisassemble(vs_2_0, 0, 0, NULL, &blob); todo_wine -#if D3D_COMPILER_VERSION == 47 +#if D3D_COMPILER_VERSION >= 46 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); #else ok(hr == E_FAIL, "Unexpected hr %#x.\n", hr); diff --git a/dlls/d3dcompiler_46/Makefile.in b/dlls/d3dcompiler_46/Makefile.in index f58176c61eb..9d3c6546923 100644 --- a/dlls/d3dcompiler_46/Makefile.in +++ b/dlls/d3dcompiler_46/Makefile.in @@ -1,4 +1,5 @@ MODULE = d3dcompiler_46.dll +IMPORTLIB = d3dcompiler_46 IMPORTS = dxguid uuid EXTRADEFS = -DD3D_COMPILER_VERSION=46 PARENTSRC = ../d3dcompiler_43 diff --git a/dlls/d3dcompiler_46/tests/Makefile.in b/dlls/d3dcompiler_46/tests/Makefile.in new file mode 100644 index 00000000000..7d2b899c0eb --- /dev/null +++ b/dlls/d3dcompiler_46/tests/Makefile.in @@ -0,0 +1,11 @@ +TESTDLL = d3dcompiler_46.dll +IMPORTS = d3d9 user32 d3dcompiler_46 +EXTRADEFS = -DD3D_COMPILER_VERSION=46 +PARENTSRC = ../../d3dcompiler_43/tests + +C_SRCS = \ + asm.c \ + blob.c \ + hlsl_d3d11.c \ + hlsl_d3d9.c \ + reflection.c
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/compiler.c | 164 ++++++++++++++++----------------- 1 file changed, 82 insertions(+), 82 deletions(-)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index 4fae71d4196..d4523edb99c 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -481,13 +481,95 @@ int wpp_parse( const char *input, FILE *output ) return ret; }
+static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, + const char *filename, const void *parent_data, const void **data, UINT *bytes) +{ + char *fullpath, *buffer = NULL, current_dir[MAX_PATH + 1]; + const char *initial_dir; + SIZE_T size; + HANDLE file; + ULONG read; + DWORD len; + + if ((initial_dir = strrchr(initial_filename, '\'))) + { + len = initial_dir - initial_filename + 1; + initial_dir = initial_filename; + } + else + { + len = GetCurrentDirectoryA(MAX_PATH, current_dir); + current_dir[len] = '\'; + len++; + initial_dir = current_dir; + } + fullpath = heap_alloc(len + strlen(filename) + 1); + if (!fullpath) + return E_OUTOFMEMORY; + memcpy(fullpath, initial_dir, len); + strcpy(fullpath + len, filename); + + file = CreateFileA(fullpath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (file == INVALID_HANDLE_VALUE) + goto error; + + TRACE("Include file found at %s.\n", debugstr_a(fullpath)); + + size = GetFileSize(file, NULL); + if (size == INVALID_FILE_SIZE) + goto error; + buffer = heap_alloc(size); + if (!buffer) + goto error; + if (!ReadFile(file, buffer, size, &read, NULL) || read != size) + goto error; + + *bytes = size; + *data = buffer; + + heap_free(fullpath); + CloseHandle(file); + return S_OK; + +error: + heap_free(fullpath); + heap_free(buffer); + CloseHandle(file); + WARN("Returning E_FAIL.\n"); + return E_FAIL; +} + +static HRESULT WINAPI d3dcompiler_include_from_file_close(ID3DInclude *iface, const void *data) +{ + heap_free((void *)data); + return S_OK; +} + +const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl = +{ + d3dcompiler_include_from_file_open, + d3dcompiler_include_from_file_close +}; + +struct d3dcompiler_include_from_file +{ + ID3DInclude ID3DInclude_iface; +}; + static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages) { + struct d3dcompiler_include_from_file include_from_file; int ret; HRESULT hr = S_OK; const D3D_SHADER_MACRO *def = defines;
+ if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE) + { + include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl; + include = &include_from_file.ID3DInclude_iface; + } + if (def != NULL) { while (def->Name != NULL) @@ -654,88 +736,12 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena return hr; }
-static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, - const char *filename, const void *parent_data, const void **data, UINT *bytes) -{ - char *fullpath, *buffer = NULL, current_dir[MAX_PATH + 1]; - const char *initial_dir; - SIZE_T size; - HANDLE file; - ULONG read; - DWORD len; - - if ((initial_dir = strrchr(initial_filename, '\'))) - { - len = initial_dir - initial_filename + 1; - initial_dir = initial_filename; - } - else - { - len = GetCurrentDirectoryA(MAX_PATH, current_dir); - current_dir[len] = '\'; - len++; - initial_dir = current_dir; - } - fullpath = heap_alloc(len + strlen(filename) + 1); - if (!fullpath) - return E_OUTOFMEMORY; - memcpy(fullpath, initial_dir, len); - strcpy(fullpath + len, filename); - - file = CreateFileA(fullpath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (file == INVALID_HANDLE_VALUE) - goto error; - - TRACE("Include file found at %s.\n", debugstr_a(fullpath)); - - size = GetFileSize(file, NULL); - if (size == INVALID_FILE_SIZE) - goto error; - buffer = heap_alloc(size); - if (!buffer) - goto error; - if (!ReadFile(file, buffer, size, &read, NULL) || read != size) - goto error; - - *bytes = size; - *data = buffer; - - heap_free(fullpath); - CloseHandle(file); - return S_OK; - -error: - heap_free(fullpath); - heap_free(buffer); - CloseHandle(file); - WARN("Returning E_FAIL.\n"); - return E_FAIL; -} - -static HRESULT WINAPI d3dcompiler_include_from_file_close(ID3DInclude *iface, const void *data) -{ - heap_free((void *)data); - return S_OK; -} - -const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl = -{ - d3dcompiler_include_from_file_open, - d3dcompiler_include_from_file_close -}; - -struct d3dcompiler_include_from_file -{ - ID3DInclude ID3DInclude_iface; -}; - HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, UINT secondary_flags, const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, ID3DBlob **error_messages) { - struct d3dcompiler_include_from_file include_from_file; HRESULT hr;
TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, " @@ -751,12 +757,6 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen if (shader) *shader = NULL; if (error_messages) *error_messages = NULL;
- if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE) - { - include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl; - include = &include_from_file.ID3DInclude_iface; - } - EnterCriticalSection(&wpp_mutex);
hr = preprocess_shader(data, data_size, filename, defines, include, error_messages);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Otherwise state might leak to the next preprocessed shader.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3dcompiler_43/compiler.c | 1 + dlls/d3dcompiler_43/wpp_private.h | 1 + 2 files changed, 2 insertions(+)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index d4523edb99c..b75a1d0a6a5 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -475,6 +475,7 @@ int wpp_parse( const char *input, FILE *output ) } /* Clean if_stack, it could remain dirty on errors */ while (pp_get_if_depth()) pp_pop_if(); + ppy_lex_destroy(); del_special_defines(); del_cmdline_defines(); pp_pop_define_state(); diff --git a/dlls/d3dcompiler_43/wpp_private.h b/dlls/d3dcompiler_43/wpp_private.h index 325c7f1e510..3b6d947d8a8 100644 --- a/dlls/d3dcompiler_43/wpp_private.h +++ b/dlls/d3dcompiler_43/wpp_private.h @@ -235,6 +235,7 @@ extern includelogicentry_t *pp_includelogiclist; extern FILE *ppy_out; extern char *ppy_text; int ppy_lex(void); +int ppy_lex_destroy(void);
void pp_do_include(char *fname, int type); void pp_push_ignore_state(void);
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2 (Matteo): Drop todo_wine for the D3DCompile() case (after the fix from the previous patch).
FWIW the issue went something like this: the second test (i == 1, D3DPreprocess()) fails with the current preprocessor because the final line of the test shader is an #endif without a newline at the end. That's all fine, we have todo_wine for that case, except we didn't fully clear the state of the preprocessor so that the following time it was called in action it would be confused by the end of the shader and still think that something is missing. This new failure in practice ended up resetting enough of the state so that the i == 3 case of the test actually managed to pass through preprocessing without errors.
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 218 +++++++++++++++++--------- 1 file changed, 147 insertions(+), 71 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 7a18992b18a..febfa5a7d4f 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -24,6 +24,12 @@
#include <math.h>
+#define D3DXERR_INVALIDDATA 0x88760b59 + +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 HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
struct vec2 @@ -1443,10 +1449,13 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE const char *filename, const void *parent_data, const void **data, UINT *bytes) { static const char include1[] = - "#define LIGHT float4(0.0f, 0.2f, 0.5f, 1.0f)\n"; + "#define LIGHT 1\n"; static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + static const char include3[] = + "#include "include1.h"\n" + "def c0, LIGHT, 0, 0, 0\n"; char *buffer;
trace("filename %s.\n", filename); @@ -1458,7 +1467,7 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE CopyMemory(buffer, include1, strlen(include1)); *bytes = strlen(include1); ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); - ok(!strncmp(include2, parent_data, strlen(include2)), + ok(!strncmp(include2, parent_data, strlen(include2)) || !strncmp(include3, parent_data, strlen(include3)), "Unexpected parent_data value.\n"); } else if (!strcmp(filename, "include\include2.h")) @@ -1469,6 +1478,14 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE ok(!parent_data, "Unexpected parent_data value.\n"); ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); } + else if (!strcmp(filename, "include\include3.h")) + { + buffer = heap_alloc(strlen(include3)); + CopyMemory(buffer, include3, strlen(include3)); + *bytes = strlen(include3); + ok(!parent_data, "Unexpected parent_data value.\n"); + ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); + } else { ok(0, "Unexpected #include for file %s.\n", filename); @@ -1496,12 +1513,65 @@ struct test_d3dinclude ID3DInclude ID3DInclude_iface; };
-static void test_d3dcompile(void) +static HRESULT call_D3DAssemble(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "ps_2_0\n" + "#include "include\include3.h"\n" + "mov oC0, c0"; + + return D3DAssemble(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) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "\n" + "float4 main() : COLOR\n" + "{\n" + " return light_color;\n" + "}"; + + return D3DCompile(ps_code, sizeof(ps_code), source_name, NULL, include, "main", "ps_2_0", 0, 0, blob, errors); +} + +#if D3D_COMPILER_VERSION >= 46 +static HRESULT call_D3DCompile2(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "\n" + "float4 main() : COLOR\n" + "{\n" + " return light_color;\n" + "}"; + + return D3DCompile2(ps_code, sizeof(ps_code), source_name, NULL, include, + "main", "ps_2_0", 0, 0, 0, NULL, 0, blob, errors); +} +#endif + +static HRESULT call_D3DPreprocess(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "#if LIGHT != 1\n" + "#error\n" + "#endif"; + + return D3DPreprocess(ps_code, sizeof(ps_code), source_name, NULL, include, blob, errors); +} + +typedef HRESULT (*include_test_cb)(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors); + +static void test_include(void) { struct test_d3dinclude include = {{&test_d3dinclude_vtbl}}; WCHAR filename[MAX_PATH], include_filename[MAX_PATH]; ID3D10Blob *blob = NULL, *errors = NULL; CHAR filename_a[MAX_PATH]; + unsigned int i; HRESULT hr; DWORD len; static const char ps_code[] = @@ -1512,12 +1582,15 @@ static void test_d3dcompile(void) " return light_color;\n" "}"; static const char include1[] = - "#define LIGHT float4(0.0f, 0.2f, 0.5f, 1.0f)\n"; + "#define LIGHT 1\n"; static const char include1_wrong[] = "#define LIGHT nope\n"; static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + static const char include3[] = + "#include "include1.h"\n" + "def c0, LIGHT, 0, 0, 0\n";
#if D3D_COMPILER_VERSION >= 46 WCHAR directory[MAX_PATH]; @@ -1531,70 +1604,74 @@ static void test_d3dcompile(void) char ps_absolute_buffer[sizeof(ps_absolute_template) + MAX_PATH]; #endif
+ static const include_test_cb tests[] = + { + call_D3DAssemble, + call_D3DPreprocess, + call_D3DCompile, +#if D3D_COMPILER_VERSION >= 46 + call_D3DCompile2, +#endif + }; + create_file(L"source.ps", ps_code, strlen(ps_code), filename); create_directory(L"include"); create_file(L"include\include1.h", include1_wrong, strlen(include1_wrong), NULL); create_file(L"include1.h", include1, strlen(include1), NULL); create_file(L"include\include2.h", include2, strlen(include2), include_filename); + create_file(L"include\include3.h", include3, strlen(include3), NULL);
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
- hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, - &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - ID3D10Blob_Release(blob); - blob = NULL; - } + winetest_push_context("Test %u", i); + + hr = tests[i](filename_a, &include.ID3DInclude_iface, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + }
#if D3D_COMPILER_VERSION >= 46 - hr = D3DCompile(ps_code, sizeof(ps_code), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - ok(hr == E_FAIL, "Got hr %#x.\n", hr); - ok(!blob, "Got unexpected blob.\n"); - ok(!!errors, "Got unexpected errors.\n"); - ID3D10Blob_Release(errors); - errors = NULL; + hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i == 0) ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got hr %#x.\n", hr); + ok(!blob, "Got unexpected blob.\n"); + ok(!!errors, "Got unexpected errors.\n"); + ID3D10Blob_Release(errors); + errors = NULL;
- /* Windows always seems to resolve includes from the initial file location - * instead of using the immediate parent, as it would be the case for - * standard C preprocessor includes. */ - hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; - } + /* Windows always seems to resolve includes from the initial file location + * instead of using the immediate parent, as it would be the case for + * standard C preprocessor includes. */ + hr = tests[i](filename_a, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } +#endif /* D3D_COMPILER_VERSION >= 46 */
- hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, &include.ID3DInclude_iface, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; + winetest_pop_context(); }
- hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; - } +#if D3D_COMPILER_VERSION >= 46
hr = D3DCompileFromFile(L"nonexistent", NULL, NULL, "main", "vs_2_0", 0, 0, &blob, &errors); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Got hr %#x.\n", hr); @@ -1647,26 +1724,25 @@ static void test_d3dcompile(void) GetCurrentDirectoryW(MAX_PATH, directory); SetCurrentDirectoryW(temp_dir);
- hr = D3DCompile(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - ID3D10Blob_Release(blob); - blob = NULL; - } + winetest_push_context("Test %u", i);
- hr = D3DCompile2(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; + hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } + + winetest_pop_context(); }
hr = D3DCompileFromFile(L"source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); @@ -1716,5 +1792,5 @@ START_TEST(hlsl_d3d9)
test_constant_table(); test_fail(); - test_d3dcompile(); + test_include(); }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 224 +++++++++++++++++--------- 1 file changed, 150 insertions(+), 74 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 7a18992b18a..6dba1f4803b 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -24,6 +24,12 @@
#include <math.h>
+#define D3DXERR_INVALIDDATA 0x88760b59 + +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 HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
struct vec2 @@ -1443,10 +1449,13 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE const char *filename, const void *parent_data, const void **data, UINT *bytes) { static const char include1[] = - "#define LIGHT float4(0.0f, 0.2f, 0.5f, 1.0f)\n"; + "#define LIGHT 1\n"; static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + static const char include3[] = + "#include "include1.h"\n" + "def c0, LIGHT, 0, 0, 0\n"; char *buffer;
trace("filename %s.\n", filename); @@ -1458,7 +1467,7 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE CopyMemory(buffer, include1, strlen(include1)); *bytes = strlen(include1); ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); - ok(!strncmp(include2, parent_data, strlen(include2)), + ok(!strncmp(include2, parent_data, strlen(include2)) || !strncmp(include3, parent_data, strlen(include3)), "Unexpected parent_data value.\n"); } else if (!strcmp(filename, "include\include2.h")) @@ -1469,6 +1478,14 @@ static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE ok(!parent_data, "Unexpected parent_data value.\n"); ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); } + else if (!strcmp(filename, "include\include3.h")) + { + buffer = heap_alloc(strlen(include3)); + CopyMemory(buffer, include3, strlen(include3)); + *bytes = strlen(include3); + ok(!parent_data, "Unexpected parent_data value.\n"); + ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type); + } else { ok(0, "Unexpected #include for file %s.\n", filename); @@ -1496,12 +1513,65 @@ struct test_d3dinclude ID3DInclude ID3DInclude_iface; };
-static void test_d3dcompile(void) +static HRESULT call_D3DAssemble(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "ps_2_0\n" + "#include "include\include3.h"\n" + "mov oC0, c0"; + + return D3DAssemble(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) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "\n" + "float4 main() : COLOR\n" + "{\n" + " return light_color;\n" + "}"; + + return D3DCompile(ps_code, sizeof(ps_code), source_name, NULL, include, "main", "ps_2_0", 0, 0, blob, errors); +} + +#if D3D_COMPILER_VERSION >= 46 +static HRESULT call_D3DCompile2(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "\n" + "float4 main() : COLOR\n" + "{\n" + " return light_color;\n" + "}"; + + return D3DCompile2(ps_code, sizeof(ps_code), source_name, NULL, include, + "main", "ps_2_0", 0, 0, 0, NULL, 0, blob, errors); +} +#endif + +static HRESULT call_D3DPreprocess(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors) +{ + static const char ps_code[] = + "#include "include\include2.h"\n" + "#if LIGHT != 1\n" + "#error\n" + "#endif"; + + return D3DPreprocess(ps_code, sizeof(ps_code), source_name, NULL, include, blob, errors); +} + +typedef HRESULT (*include_test_cb)(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors); + +static void test_include(void) { struct test_d3dinclude include = {{&test_d3dinclude_vtbl}}; WCHAR filename[MAX_PATH], include_filename[MAX_PATH]; ID3D10Blob *blob = NULL, *errors = NULL; CHAR filename_a[MAX_PATH]; + unsigned int i; HRESULT hr; DWORD len; static const char ps_code[] = @@ -1512,12 +1582,15 @@ static void test_d3dcompile(void) " return light_color;\n" "}"; static const char include1[] = - "#define LIGHT float4(0.0f, 0.2f, 0.5f, 1.0f)\n"; + "#define LIGHT 1\n"; static const char include1_wrong[] = "#define LIGHT nope\n"; static const char include2[] = "#include "include1.h"\n" "float4 light_color = LIGHT;\n"; + static const char include3[] = + "#include "include1.h"\n" + "def c0, LIGHT, 0, 0, 0\n";
#if D3D_COMPILER_VERSION >= 46 WCHAR directory[MAX_PATH]; @@ -1531,70 +1604,74 @@ static void test_d3dcompile(void) char ps_absolute_buffer[sizeof(ps_absolute_template) + MAX_PATH]; #endif
+ static const include_test_cb tests[] = + { + call_D3DAssemble, + call_D3DPreprocess, + call_D3DCompile, +#if D3D_COMPILER_VERSION >= 46 + call_D3DCompile2, +#endif + }; + create_file(L"source.ps", ps_code, strlen(ps_code), filename); create_directory(L"include"); create_file(L"include\include1.h", include1_wrong, strlen(include1_wrong), NULL); create_file(L"include1.h", include1, strlen(include1), NULL); create_file(L"include\include2.h", include2, strlen(include2), include_filename); + create_file(L"include\include3.h", include3, strlen(include3), NULL);
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
- hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, - &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - ID3D10Blob_Release(blob); - blob = NULL; + winetest_push_context("Test %u", i); + + hr = tests[i](filename_a, &include.ID3DInclude_iface, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1 || i == 2) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } + +#if D3D_COMPILER_VERSION >= 46 + hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i == 0) ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got hr %#x.\n", hr); + ok(!blob, "Got unexpected blob.\n"); + ok(!!errors, "Got unexpected errors.\n"); + ID3D10Blob_Release(errors); + errors = NULL; + + /* Windows always seems to resolve includes from the initial file location + * instead of using the immediate parent, as it would be the case for + * standard C preprocessor includes. */ + hr = tests[i](filename_a, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } +#endif /* D3D_COMPILER_VERSION >= 46 */ + + winetest_pop_context(); }
#if D3D_COMPILER_VERSION >= 46 - hr = D3DCompile(ps_code, sizeof(ps_code), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - ok(hr == E_FAIL, "Got hr %#x.\n", hr); - ok(!blob, "Got unexpected blob.\n"); - ok(!!errors, "Got unexpected errors.\n"); - ID3D10Blob_Release(errors); - errors = NULL; - - /* Windows always seems to resolve includes from the initial file location - * instead of using the immediate parent, as it would be the case for - * standard C preprocessor includes. */ - hr = D3DCompile(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; - } - - hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, &include.ID3DInclude_iface, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; - } - - hr = D3DCompile2(ps_code, sizeof(ps_code), filename_a, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; - }
hr = D3DCompileFromFile(L"nonexistent", NULL, NULL, "main", "vs_2_0", 0, 0, &blob, &errors); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Got hr %#x.\n", hr); @@ -1647,26 +1724,25 @@ static void test_d3dcompile(void) GetCurrentDirectoryW(MAX_PATH, directory); SetCurrentDirectoryW(temp_dir);
- hr = D3DCompile(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - ID3D10Blob_Release(blob); - blob = NULL; - } + winetest_push_context("Test %u", i);
- hr = D3DCompile2(ps_code, sizeof(ps_code), "source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", "ps_2_0", 0, 0, 0, NULL, 0, &blob, &errors); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(!!blob, "Got unexpected blob.\n"); - ok(!errors, "Got unexpected errors.\n"); - if (blob) - { - ID3D10Blob_Release(blob); - blob = NULL; + hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors); + todo_wine_if (i != 0) + { + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!blob, "Got unexpected blob.\n"); + } + todo_wine_if (i == 1 || i == 2) + ok(!errors, "Got unexpected errors.\n"); + if (blob) + { + ID3D10Blob_Release(blob); + blob = NULL; + } + + winetest_pop_context(); }
hr = D3DCompileFromFile(L"source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors); @@ -1716,5 +1792,5 @@ START_TEST(hlsl_d3d9)
test_constant_table(); test_fail(); - test_d3dcompile(); + test_include(); }