Signed-off-by: Ziqing Hui zhui@codeweavers.com --- dlls/d3dx10_43/tests/Makefile.in | 2 +- dlls/d3dx10_43/tests/d3dx10.c | 155 ++++++++++++++++++++++++++++++- 2 files changed, 153 insertions(+), 4 deletions(-)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- FTR, the patch is unchanged from 188328 that I already signed off.
From: Ziqing Hui zhui@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48856 Signed-off-by: Ziqing Hui zhui@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v4: Make a couple tiny style changes.
dlls/d3dx10_43/Makefile.in | 1 + dlls/d3dx10_43/d3dx10_43_main.c | 146 +++++++++++++++++++++++++++++++- dlls/d3dx10_43/tests/d3dx10.c | 7 +- 3 files changed, 147 insertions(+), 7 deletions(-)
diff --git a/dlls/d3dx10_43/Makefile.in b/dlls/d3dx10_43/Makefile.in index 2d0343f3b086..ca2d418be0dd 100644 --- a/dlls/d3dx10_43/Makefile.in +++ b/dlls/d3dx10_43/Makefile.in @@ -1,6 +1,7 @@ MODULE = d3dx10_43.dll IMPORTLIB = d3dx10 IMPORTS = d3d10_1 d3dcompiler dxguid +DELAYIMPORTS = windowscodecs
EXTRADLLFLAGS = -mno-cygwin
diff --git a/dlls/d3dx10_43/d3dx10_43_main.c b/dlls/d3dx10_43/d3dx10_43_main.c index 45247756b8e7..53781f5de64b 100644 --- a/dlls/d3dx10_43/d3dx10_43_main.c +++ b/dlls/d3dx10_43/d3dx10_43_main.c @@ -32,9 +32,56 @@
#include "d3d10_1.h" #include "d3dx10.h" +#include "wincodec.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
+HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT sdk_version, IWICImagingFactory **imaging_factory); + +static const struct +{ + const GUID *wic_container_guid; + D3DX10_IMAGE_FILE_FORMAT d3dx_file_format; +} +file_formats[] = +{ + { &GUID_ContainerFormatBmp, D3DX10_IFF_BMP }, + { &GUID_ContainerFormatJpeg, D3DX10_IFF_JPG }, + { &GUID_ContainerFormatPng, D3DX10_IFF_PNG }, + { &GUID_ContainerFormatDds, D3DX10_IFF_DDS }, + { &GUID_ContainerFormatTiff, D3DX10_IFF_TIFF }, + { &GUID_ContainerFormatGif, D3DX10_IFF_GIF }, + { &GUID_ContainerFormatWmp, D3DX10_IFF_WMP }, +}; + +static D3DX10_IMAGE_FILE_FORMAT wic_container_guid_to_file_format(GUID *container_format) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(file_formats); ++i) + { + if (IsEqualGUID(file_formats[i].wic_container_guid, container_format)) + return file_formats[i].d3dx_file_format; + } + return D3DX10_IFF_FORCE_DWORD; +} + +static D3D10_RESOURCE_DIMENSION wic_dimension_to_d3dx10_dimension(WICDdsDimension wic_dimension) +{ + switch (wic_dimension) + { + case WICDdsTexture1D: + return D3D10_RESOURCE_DIMENSION_TEXTURE1D; + case WICDdsTexture2D: + case WICDdsTextureCube: + return D3D10_RESOURCE_DIMENSION_TEXTURE2D; + case WICDdsTexture3D: + return D3D10_RESOURCE_DIMENSION_TEXTURE3D; + default: + return D3D10_RESOURCE_DIMENSION_UNKNOWN; + } +} + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) @@ -229,10 +276,105 @@ HRESULT WINAPI D3DX10GetFeatureLevel1(ID3D10Device *device, ID3D10Device1 **devi HRESULT WINAPI D3DX10GetImageInfoFromMemory(const void *src_data, SIZE_T src_data_size, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *img_info, HRESULT *hresult) { - FIXME("src_data %p, src_data_size %lu, pump %p, img_info %p, hresult %p.\n", + IWICBitmapFrameDecode *frame = NULL; + IWICImagingFactory *factory = NULL; + IWICDdsDecoder *dds_decoder = NULL; + IWICBitmapDecoder *decoder = NULL; + WICDdsParameters dds_params; + IWICStream *stream = NULL; + unsigned int frame_count; + GUID container_format; + HRESULT hr; + + TRACE("src_data %p, src_data_size %lu, pump %p, img_info %p, hresult %p.\n", src_data, src_data_size, pump, img_info, hresult);
- return E_NOTIMPL; + if (!src_data || !src_data_size || !img_info) + return E_FAIL; + if (pump) + FIXME("Thread pump is not supported yet.\n"); + + WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory); + IWICImagingFactory_CreateStream(factory, &stream); + hr = IWICStream_InitializeFromMemory(stream, (BYTE *)src_data, src_data_size); + if (FAILED(hr)) + { + WARN("Failed to initialize stream.\n"); + goto end; + } + hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream *)stream, NULL, 0, &decoder); + if (FAILED(hr)) + goto end; + + hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format); + if (FAILED(hr)) + goto end; + img_info->ImageFileFormat = wic_container_guid_to_file_format(&container_format); + if (img_info->ImageFileFormat == D3DX10_IFF_FORCE_DWORD) + { + hr = E_FAIL; + WARN("Unsupported image file format %s.\n", debugstr_guid(&container_format)); + goto end; + } + + hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count); + if (FAILED(hr) || !frame_count) + goto end; + hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); + if (FAILED(hr)) + goto end; + hr = IWICBitmapFrameDecode_GetSize(frame, &img_info->Width, &img_info->Height); + if (FAILED(hr)) + goto end; + + if (img_info->ImageFileFormat == D3DX10_IFF_DDS) + { + hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder); + if (FAILED(hr)) + goto end; + hr = IWICDdsDecoder_GetParameters(dds_decoder, &dds_params); + if (FAILED(hr)) + goto end; + img_info->ArraySize = dds_params.ArraySize; + img_info->Depth = dds_params.Depth; + img_info->MipLevels = dds_params.MipLevels; + img_info->ResourceDimension = wic_dimension_to_d3dx10_dimension(dds_params.Dimension); + img_info->Format = dds_params.DxgiFormat; + img_info->MiscFlags = 0; + if (dds_params.Dimension == WICDdsTextureCube) + { + img_info->MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE; + img_info->ArraySize *= 6; + } + } + else + { + img_info->ArraySize = 1; + img_info->Depth = 1; + img_info->MipLevels = 1; + img_info->ResourceDimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D; + img_info->Format = DXGI_FORMAT_R8G8B8A8_UNORM; + img_info->MiscFlags = 0; + } + +end: + if (dds_decoder) + IWICDdsDecoder_Release(dds_decoder); + if (frame) + IWICBitmapFrameDecode_Release(frame); + if (decoder) + IWICBitmapDecoder_Release(decoder); + if (stream) + IWICStream_Release(stream); + if (factory) + IWICImagingFactory_Release(factory); + + if (hr != S_OK) + { + WARN("Invalid or unsupported image file.\n"); + return E_FAIL; + } + return S_OK; }
D3DX_CPU_OPTIMIZATION WINAPI D3DXCpuOptimizations(BOOL enable) diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index 40f836d9bae9..6012dff64762 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -1051,23 +1051,21 @@ static void test_get_image_info(void)
CoInitialize(NULL);
- todo_wine { hr = D3DX10GetImageInfoFromMemory(test_image[0].data, 0, NULL, &image_info, NULL); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); hr = D3DX10GetImageInfoFromMemory(NULL, test_image[0].size, NULL, &image_info, NULL); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); hr = D3DX10GetImageInfoFromMemory(&dword, sizeof(dword), NULL, &image_info, NULL); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); - }
for (i = 0; i < ARRAY_SIZE(test_image); ++i) { hr = D3DX10GetImageInfoFromMemory(test_image[i].data, test_image[i].size, NULL, &image_info, NULL); - todo_wine ok(hr == S_OK, "Test %u: Got unexpected hr %#x.\n", i, hr); + todo_wine_if(test_image[i].expected.ImageFileFormat == D3DX10_IFF_WMP) + ok(hr == S_OK, "Test %u: Got unexpected hr %#x.\n", i, hr); if (hr != S_OK) continue;
- todo_wine { ok(image_info.Width == test_image[i].expected.Width, "Test %u: Got unexpected Width %u, expected %u.\n", i, image_info.Width, test_image[i].expected.Width); @@ -1095,7 +1093,6 @@ static void test_get_image_info(void) ok(image_info.ImageFileFormat == test_image[i].expected.ImageFileFormat, "Test %u: Got unexpected ImageFileFormat %u, expected %u.\n", i, image_info.ImageFileFormat, test_image[i].expected.ImageFileFormat); - } }
CoUninitialize();
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=75123
Your paranoid android.
=== build (build log) ===
error: patch failed: dlls/d3dx10_43/tests/d3dx10.c:1051 Task: Patch failed to apply
=== debiant (build log) ===
error: patch failed: dlls/d3dx10_43/tests/d3dx10.c:1051 Task: Patch failed to apply
=== debiant (build log) ===
error: patch failed: dlls/d3dx10_43/tests/d3dx10.c:1051 Task: Patch failed to apply
Spurred by a patch by Alex Henrie.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3dx9_36/mesh.c | 19 ++++++++++--------- dlls/d3dx9_36/tests/mesh.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/dlls/d3dx9_36/mesh.c b/dlls/d3dx9_36/mesh.c index 5e0bb98efc77..22f86f10d085 100644 --- a/dlls/d3dx9_36/mesh.c +++ b/dlls/d3dx9_36/mesh.c @@ -2409,20 +2409,21 @@ BOOL WINAPI D3DXIntersectTri(const D3DXVECTOR3 *p0, const D3DXVECTOR3 *p1, const return FALSE; }
-BOOL WINAPI D3DXSphereBoundProbe(const D3DXVECTOR3 *pcenter, float radius, - const D3DXVECTOR3 *prayposition, const D3DXVECTOR3 *praydirection) +BOOL WINAPI D3DXSphereBoundProbe(const D3DXVECTOR3 *center, float radius, + const D3DXVECTOR3 *ray_position, const D3DXVECTOR3 *ray_direction) { - D3DXVECTOR3 difference; - FLOAT a, b, c, d; + D3DXVECTOR3 difference = {0}; + float a, b, c, d;
- a = D3DXVec3LengthSq(praydirection); - if (!D3DXVec3Subtract(&difference, prayposition, pcenter)) return FALSE; - b = D3DXVec3Dot(&difference, praydirection); + D3DXVec3Subtract(&difference, ray_position, center); c = D3DXVec3LengthSq(&difference) - radius * radius; + if (c < 0.0f) + return TRUE; + a = D3DXVec3LengthSq(ray_direction); + b = D3DXVec3Dot(&difference, ray_direction); d = b * b - a * c;
- if ( ( d <= 0.0f ) || ( sqrt(d) <= b ) ) return FALSE; - return TRUE; + return d >= 0.0f && (b <= 0.0f || d > b * b); }
/************************************************************************* diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c index c357200656b0..42deb32b9341 100644 --- a/dlls/d3dx9_36/tests/mesh.c +++ b/dlls/d3dx9_36/tests/mesh.c @@ -435,18 +435,42 @@ static void D3DXBoundProbeTest(void) radius = sqrt(77.0f); center.x = 1.0f; center.y = 2.0f; center.z = 3.0f; raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f; - rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); - ok(result == TRUE, "expected TRUE, received FALSE\n"); + ok(result == TRUE, "Got unexpected result %#x.\n", result);
rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); - ok(result == FALSE, "expected FALSE, received TRUE\n"); + ok(result == FALSE, "Got unexpected result %#x.\n", result); + + raydirection.x = -2.0f; raydirection.y = 4.0f; raydirection.z = -2.0f; + result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); + ok(result == TRUE, "Got unexpected result %#x.\n", result);
rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); - ok(result == FALSE, "expected FALSE, received TRUE\n"); + ok(result == FALSE, "Got unexpected result %#x.\n", result); + + raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f; + result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); + ok(result == FALSE, "Got unexpected result %#x.\n", result); + + radius = 1.0f; + rayposition.x = 2.0f; rayposition.y = 2.0f; rayposition.z = 3.0f; + result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); + ok(result == FALSE, "Got unexpected result %#x.\n", result); + + raydirection.x = 0.0f; raydirection.y = 0.0f; raydirection.z = 1.0f; + result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); + ok(result == TRUE, "Got unexpected result %#x.\n", result); + + if (0) + { + /* All these crash on native. */ + D3DXSphereBoundProbe(¢er, radius, &rayposition, NULL); + D3DXSphereBoundProbe(¢er, radius, NULL, &raydirection); + D3DXSphereBoundProbe(NULL, radius, &rayposition, &raydirection); + } }
static void D3DXComputeBoundingBoxTest(void)
Thanks Matteo! Your patch looks great!
-Alex