From: Ziqing Hui zhui@codeweavers.com
--- dlls/d3dx10_43/compiler.c | 32 ++++++++++++++++++++++++-------- dlls/d3dx10_43/tests/d3dx10.c | 14 +++----------- 2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 3ac961e907f..684615eb192 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -28,12 +28,17 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
+#define D3DERR_INVALIDCALL 0x8876086c + static HRESULT create_effect(const void *data, SIZE_T datasize, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect, ID3D10Blob **errors) { - ID3D10Blob *code; + const char dxbc[] = {'D','X','B','C'}; + ID3D10Blob *code = NULL; + void *buffer; + SIZE_T size; HRESULT hr;
if (!data || !device) @@ -42,17 +47,28 @@ static HRESULT create_effect(const void *data, SIZE_T datasize, const char *file if (errors) *errors = NULL;
- if (FAILED(hr = D3DCompile(data, datasize, filename, defines, include, "main", profile, - shader_flags, effect_flags, &code, errors))) + buffer = (void *)data; + size = datasize; + + /* Effect is not compiled. */ + if (datasize < sizeof(dxbc) || memcmp(dxbc, data, sizeof(dxbc)) != 0) { - WARN("Effect compilation failed, hr %#lx.\n", hr); - return hr; + if (!profile) + return D3DERR_INVALIDCALL; + if (FAILED(hr = D3DCompile(data, datasize, filename, defines, include, "main", profile, + shader_flags, effect_flags, &code, errors))) + { + WARN("Effect compilation failed, hr %#lx.\n", hr); + return hr; + } + buffer = ID3D10Blob_GetBufferPointer(code); + size = ID3D10Blob_GetBufferSize(code); }
- hr = D3D10CreateEffectFromMemory(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), - effect_flags, device, effect_pool, effect); - ID3D10Blob_Release(code); + hr = D3D10CreateEffectFromMemory(buffer, size, effect_flags, device, effect_pool, effect);
+ if (code) + ID3D10Blob_Release(code); return hr; }
diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index df82bfa003f..99350197acd 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -3976,8 +3976,6 @@ static void test_create_effect_from_memory(void) }
/* Test NULL data. */ - if (strcmp(winetest_platform, "wine")) /* Crash on wine. */ - { errors = (ID3D10Blob *)0xdeadbeef; effect = (ID3D10Effect *)0xdeadbeef; hr = D3DX10CreateEffectFromMemory(NULL, 0, NULL, NULL, NULL, NULL, @@ -4011,10 +4009,10 @@ static void test_create_effect_from_memory(void) hr = D3DX10CreateEffectFromMemory(test_fx_source, strlen(test_fx_source) + 1, NULL, NULL, NULL, NULL, 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr); - ok(!!errors && errors != (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + todo_wine ok(!!errors && errors != (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); - ID3D10Blob_Release(errors); - } + if (errors && errors != (ID3D10Blob *)0xdeadbeef) + ID3D10Blob_Release(errors);
/* Test creating texture from source. */ errors = (ID3D10Blob *)0xdeadbeef; @@ -4082,8 +4080,6 @@ static void test_create_effect_from_file(void) ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
/* Test creating texture from compiled shader file. */ - if (strcmp(winetest_platform, "wine")) /* Crash on wine. */ - { create_file(test_file_name, test_fx, sizeof(test_fx), path);
errors = (ID3D10Blob *)0xdeadbeef; @@ -4105,7 +4101,6 @@ static void test_create_effect_from_file(void) effect->lpVtbl->Release(effect);
delete_file(test_file_name); - }
/* Test creating texture from source file. */ create_file(test_file_name, test_fx_source, strlen(test_fx_source) + 1, path); @@ -4204,8 +4199,6 @@ static void test_create_effect_from_resource(void) ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
/* Test creating texture from compiled shader resource. */ - if (strcmp(winetest_platform, "wine")) /* Crash on wine. */ - { resource_module = create_resource_module(test_resource_name, test_fx, sizeof(test_fx));
errors = (ID3D10Blob *)0xdeadbeef; @@ -4227,7 +4220,6 @@ static void test_create_effect_from_resource(void) effect->lpVtbl->Release(effect);
delete_resource_module(test_resource_name, resource_module); - }
/* Test creating texture from source resource. */ resource_module = create_resource_module(test_resource_name, test_fx_source, strlen(test_fx_source) + 1);