Note for patch 7:
See https://docs.microsoft.com/en-us/windows/win32/api/d3d10/ns-d3d10-d3d10_mapp... :
A block-compressed texture is encoded in 4x4 blocks (see virtual size vs physical size) ; therefore, RowPitch is the number of bytes in a block of 4x4 texels.
-- v4: d3dx10: Return E_FAIL in D3DX10CreateEffectFromFile for NULL file name. d3dx10: Support effect creation for compiled shader. d3dx10: Introduce create_effect(). d3dx10/tests: Add tests for D3DX10CreateEffectFromResource. d3dx10/tests: Add tests for D3DX10CreateEffectFromFile. d3dx10/tests: Add tests for D3DX10CreateEffectFromMemory.
From: Ziqing Hui zhui@codeweavers.com
Passing NULL profile to effect creation will crash wine for now. So we have to skip these tests in wine. --- dlls/d3dx10_43/tests/d3dx10.c | 99 +++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index b8a9d8cf214..9c550c729e8 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -546,6 +546,34 @@ static const BYTE test_wmp_data[] = 0xff, 0xff, 0xff, 0xff };
+static const char *test_fx_source = +"cbuffer cb : register(b1)\n" +"{\n" +" float f1 : SV_POSITION;\n" +" float f2 : COLOR0;\n" +"}\n"; + +static const BYTE test_fx[] = +{ + 0x44, 0x58, 0x42, 0x43, 0x95, 0x89, 0xe1, 0xa2, 0xcc, 0x97, 0x05, 0x54, 0x73, 0x9d, 0x0b, 0x67, + 0x90, 0xe1, 0x7f, 0x77, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x46, 0x58, 0x31, 0x30, 0xde, 0x00, 0x00, 0x00, 0x01, 0x10, 0xff, 0xfe, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 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, 0x63, 0x62, 0x00, 0x66, + 0x6c, 0x6f, 0x61, 0x74, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x09, 0x00, + 0x00, 0x66, 0x31, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, + 0x66, 0x32, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x30, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, + 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + static const struct test_image { const BYTE *data; @@ -3937,6 +3965,76 @@ todo_wine { ok(!refcount, "Unexpected refcount.\n"); }
+static void test_create_effect_from_memory(void) +{ + ID3D10Device *device; + ID3D10Effect *effect; + ID3D10Blob *errors; + ULONG refcount; + HRESULT hr; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + /* 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, + 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test NULL device. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromMemory(test_fx, sizeof(test_fx), NULL, NULL, NULL, NULL, + 0x0, 0x0, NULL, NULL, NULL, &effect, &errors, NULL); + ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test creating effect from compiled shader. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromMemory(test_fx, sizeof(test_fx), NULL, NULL, NULL, NULL, + 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!errors, "Got unexpected errors %p.\n", errors); + ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + effect->lpVtbl->Release(effect); + + /* Test creating effect from source without setting profile. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + 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); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + ID3D10Blob_Release(errors); + } + + /* Test creating effect from source. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromMemory(test_fx_source, strlen(test_fx_source) + 1, NULL, NULL, NULL, "fx_4_0", + 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + todo_wine ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + if (hr == S_OK) + effect->lpVtbl->Release(effect); + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Got unexpected refcount %lu.\n", refcount); +} + static void test_create_effect_from_resource(void) { ID3D10Device *device; @@ -4005,6 +4103,7 @@ START_TEST(d3dx10) test_create_texture(); test_font(); test_sprite(); + test_create_effect_from_memory(); test_create_effect_from_resource(); test_preprocess_shader(); }
From: Ziqing Hui zhui@codeweavers.com
--- dlls/d3dx10_43/tests/d3dx10.c | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index 9c550c729e8..950a3f5c7f0 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -4035,6 +4035,111 @@ static void test_create_effect_from_memory(void) ok(!refcount, "Got unexpected refcount %lu.\n", refcount); }
+static void test_create_effect_from_file(void) +{ + static const WCHAR *test_file_name = L"test.fx"; + WCHAR path[MAX_PATH]; + ID3D10Device *device; + ID3D10Effect *effect; + ID3D10Blob *errors; + ULONG refcount; + HRESULT hr; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + /* Test NULL file name. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileW(NULL, NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileA(NULL, NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test non-existent file. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileW(L"deadbeef", NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileA("deadbeef", NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test creating effect 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; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileW(path, NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!errors, "Got unexpected errors %p.\n", errors); + ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + effect->lpVtbl->Release(effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileA(get_str_a(path), NULL, NULL, NULL, 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!errors, "Got unexpected errors %p.\n", errors); + ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + effect->lpVtbl->Release(effect); + + delete_file(test_file_name); + } + + /* Test creating effect from source file. */ + create_file(test_file_name, test_fx_source, strlen(test_fx_source) + 1, path); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileW(path, NULL, NULL, "fx_4_0", 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + todo_wine ok(effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + if (hr == S_OK) + effect->lpVtbl->Release(effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromFileA(get_str_a(path), NULL, NULL, "fx_4_0", 0x0, 0x0, + device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + todo_wine ok(effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + if (hr == S_OK) + effect->lpVtbl->Release(effect); + + delete_file(test_file_name); + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Got unexpected refcount %lu.\n", refcount); +} + static void test_create_effect_from_resource(void) { ID3D10Device *device; @@ -4104,6 +4209,7 @@ START_TEST(d3dx10) test_font(); test_sprite(); test_create_effect_from_memory(); + test_create_effect_from_file(); test_create_effect_from_resource(); test_preprocess_shader(); }
From: Ziqing Hui zhui@codeweavers.com
--- dlls/d3dx10_43/tests/d3dx10.c | 109 ++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-)
diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index 950a3f5c7f0..e178fb65e9d 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -4142,8 +4142,11 @@ static void test_create_effect_from_file(void)
static void test_create_effect_from_resource(void) { + static const WCHAR *test_resource_name = L"test.fx"; + HMODULE resource_module; ID3D10Device *device; ID3D10Effect *effect; + ID3D10Blob *errors; ULONG refcount; HRESULT hr;
@@ -4153,12 +4156,110 @@ static void test_create_effect_from_resource(void) return; }
- hr = D3DX10CreateEffectFromResourceA(GetModuleHandleA(NULL), "resource", NULL, NULL, NULL, - "fx_4_0", 0, 0, device, NULL, NULL, &effect, NULL, NULL); - ok(hr == D3DX10_ERR_INVALID_DATA, "Unexpected hr %#lx.\n", hr); + /* Test NULL module. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceW(NULL, NULL, NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceA(NULL, NULL, NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test NULL resource name. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceW(GetModuleHandleW(NULL), NULL, NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceA(GetModuleHandleA(NULL), NULL, NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test non-existent resource name. */ + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceW(GetModuleHandleW(NULL), L"deadbeef", NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceA(GetModuleHandleA(NULL), "deadbeef", NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#lx.\n", hr); + ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); + ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + + /* Test creating effect 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; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceW(resource_module, test_resource_name, NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!errors, "Got unexpected errors %p.\n", errors); + ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + effect->lpVtbl->Release(effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceA(resource_module, get_str_a(test_resource_name), NULL, NULL, NULL, NULL, + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!errors, "Got unexpected errors %p.\n", errors); + ok(!!effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + effect->lpVtbl->Release(effect); + + delete_resource_module(test_resource_name, resource_module); + } + + /* Test creating effect from source resource. */ + resource_module = create_resource_module(test_resource_name, test_fx_source, strlen(test_fx_source) + 1); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceW(resource_module, test_resource_name, NULL, NULL, NULL, "fx_4_0", + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + todo_wine ok(effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + if (hr == S_OK) + effect->lpVtbl->Release(effect); + + errors = (ID3D10Blob *)0xdeadbeef; + effect = (ID3D10Effect *)0xdeadbeef; + hr = D3DX10CreateEffectFromResourceA(resource_module, get_str_a(test_resource_name), NULL, NULL, NULL, "fx_4_0", + 0, 0, device, NULL, NULL, &effect, &errors, NULL); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); + todo_wine ok(effect && effect != (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect); + if (hr == S_OK) + effect->lpVtbl->Release(effect); + + delete_resource_module(test_resource_name, resource_module);
refcount = ID3D10Device_Release(device); - ok(!refcount, "Unexpected refcount.\n"); + ok(!refcount, "Got unexpected refcount %lu.\n", refcount); }
static void test_preprocess_shader(void)
From: Ziqing Hui zhui@codeweavers.com
--- dlls/d3dx10_43/compiler.c | 63 +++++++++++++++++++++-------------- dlls/d3dx10_43/tests/d3dx10.c | 4 +-- 2 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index ad27783eabb..34d46ea0d2d 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -28,25 +28,19 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
- -HRESULT WINAPI D3DX10CreateEffectFromMemory(const void *data, SIZE_T datasize, const char *filename, +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, - ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) + ID3D10Effect **effect, ID3D10Blob **errors) { ID3D10Blob *code; HRESULT hr;
- TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, profile %s, shader_flags %#x," - "effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, errors %p, hresult %p.\n", - data, datasize, debugstr_a(filename), defines, include, debugstr_a(profile), - shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); - - if (pump) - FIXME("Asynchronous mode is not supported.\n"); + if (!data || !device) + return E_FAIL;
- if (!include) - include = D3D_COMPILE_STANDARD_FILE_INCLUDE; + if (errors) + *errors = NULL;
if (FAILED(hr = D3DCompile(data, datasize, filename, defines, include, "main", profile, shader_flags, effect_flags, &code, errors))) @@ -62,12 +56,34 @@ HRESULT WINAPI D3DX10CreateEffectFromMemory(const void *data, SIZE_T datasize, c return hr; }
+HRESULT WINAPI D3DX10CreateEffectFromMemory(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, + ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) +{ + TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, profile %s, shader_flags %#x," + "effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, errors %p, hresult %p.\n", + data, datasize, debugstr_a(filename), defines, include, debugstr_a(profile), + shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); + + if (pump) + FIXME("Asynchronous mode is not supported.\n"); + + if (!include) + include = D3D_COMPILE_STANDARD_FILE_INCLUDE; + + return create_effect(data, datasize, filename, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, effect, errors); +} + HRESULT WINAPI D3DX10CreateEffectFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) { - ID3D10Blob *code; + char filename_a[MAX_PATH]; + void *buffer = NULL; + DWORD size = 0; HRESULT hr;
TRACE("filename %s, defines %p, include %p, profile %s, shader_flags %#x, effect_flags %#x, " @@ -81,17 +97,14 @@ HRESULT WINAPI D3DX10CreateEffectFromFileW(const WCHAR *filename, const D3D10_SH if (!include) include = D3D_COMPILE_STANDARD_FILE_INCLUDE;
- if (FAILED(hr = D3DCompileFromFile(filename, defines, include, "main", profile, shader_flags, - effect_flags, &code, errors))) + if (SUCCEEDED((hr = load_file(filename, &buffer, &size)))) { - WARN("Effect compilation failed, hr %#lx.\n", hr); - return hr; + WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, sizeof(filename_a), NULL, NULL); + hr = create_effect(buffer, size, filename_a, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, effect, errors); + free(buffer); }
- hr = D3D10CreateEffectFromMemory(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), - effect_flags, device, effect_pool, effect); - ID3D10Blob_Release(code); - return hr; }
@@ -144,8 +157,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou if (FAILED(hr)) return hr;
- return D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, - shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); + return create_effect(data, size, filename, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, effect, errors); }
HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *resource_name, @@ -178,8 +191,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, len, NULL, NULL); }
- hr = D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, - shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); + hr = create_effect(data, size, filename, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, effect, errors); free(filename); return hr; } diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index e178fb65e9d..ecea9a5420e 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -4073,7 +4073,7 @@ static void test_create_effect_from_file(void) effect = (ID3D10Effect *)0xdeadbeef; hr = D3DX10CreateEffectFromFileW(L"deadbeef", NULL, NULL, NULL, 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); - todo_wine ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); + ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
@@ -4081,7 +4081,7 @@ static void test_create_effect_from_file(void) effect = (ID3D10Effect *)0xdeadbeef; hr = D3DX10CreateEffectFromFileA("deadbeef", NULL, NULL, NULL, 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); - todo_wine ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); + ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#lx.\n", hr); todo_wine ok(!errors, "Got unexpected errors %p.\n", errors); ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
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 34d46ea0d2d..98553e78b1b 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))) { - 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 ecea9a5420e..781c28371b3 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -3980,8 +3980,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, @@ -4015,10 +4013,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 effect from source. */ errors = (ID3D10Blob *)0xdeadbeef; @@ -4086,8 +4084,6 @@ static void test_create_effect_from_file(void) ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
/* Test creating effect 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; @@ -4109,7 +4105,6 @@ static void test_create_effect_from_file(void) effect->lpVtbl->Release(effect);
delete_file(test_file_name); - }
/* Test creating effect from source file. */ create_file(test_file_name, test_fx_source, strlen(test_fx_source) + 1, path); @@ -4208,8 +4203,6 @@ static void test_create_effect_from_resource(void) ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
/* Test creating effect 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; @@ -4231,7 +4224,6 @@ static void test_create_effect_from_resource(void) effect->lpVtbl->Release(effect);
delete_resource_module(test_resource_name, resource_module); - }
/* Test creating effect from source resource. */ resource_module = create_resource_module(test_resource_name, test_fx_source, strlen(test_fx_source) + 1);
From: Ziqing Hui zhui@codeweavers.com
--- dlls/d3dx10_43/compiler.c | 5 ++++- dlls/d3dx10_43/tests/d3dx10.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 98553e78b1b..281dae329e5 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -107,6 +107,9 @@ HRESULT WINAPI D3DX10CreateEffectFromFileW(const WCHAR *filename, const D3D10_SH debugstr_w(filename), defines, include, debugstr_a(profile), shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult);
+ if (!filename) + return E_FAIL; + if (pump) FIXME("Asynchronous mode is not supported.\n");
@@ -139,7 +142,7 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA device, effect_pool, pump, effect, errors, hresult);
if (!filename) - return E_INVALIDARG; + return E_FAIL;
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0); if (!(filenameW = malloc(len * sizeof(*filenameW)))) diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index 781c28371b3..8c89a08b734 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -4054,7 +4054,7 @@ static void test_create_effect_from_file(void) effect = (ID3D10Effect *)0xdeadbeef; hr = D3DX10CreateEffectFromFileW(NULL, NULL, NULL, NULL, 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); - todo_wine ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
@@ -4062,7 +4062,7 @@ static void test_create_effect_from_file(void) effect = (ID3D10Effect *)0xdeadbeef; hr = D3DX10CreateEffectFromFileA(NULL, NULL, NULL, NULL, 0x0, 0x0, device, NULL, NULL, &effect, &errors, NULL); - todo_wine ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr); ok(errors == (ID3D10Blob *)0xdeadbeef, "Got unexpected errors %p.\n", errors); ok(effect == (ID3D10Effect *)0xdeadbeef, "Got unexpected effect %p.\n", effect);
Matteo Bruni (@Mystral) commented about dlls/d3dx10_43/compiler.c:
if (errors) *errors = NULL;
- if (FAILED(hr = D3DCompile(data, datasize, filename, defines, include, "main", profile,
shader_flags, effect_flags, &code, errors)))
- buffer = (void *)data;
I had a comment on the same cast with the older MR: https://gitlab.winehq.org/wine/wine/-/merge_requests/332#note_3151
Very unlikely that there are actual write accesses to the source data but...
It would be nice to followup with more patches handling the hresult argument (see my test to D3DX10PreprocessShaderFromMemory() from b996a969818685878f1dbe04b773bc4c5f4fd5c4 or Piotr's for the texture functions and implementation) and thread pump (again, see the relevant, recent commits from Piotr).
This merge request was approved by Matteo Bruni.