Spotted in https://bugs.winehq.org/show_bug.cgi?id=47974
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/tests/texture.c | 17 ++++++++++++----- dlls/d3dx9_36/texture.c | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 3416a3318b..3e4d5e5df9 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2061,8 +2061,14 @@ static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device) { - HRESULT hr; IDirect3DCubeTexture9 *cube_texture; + HRESULT hr; + + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, + D3DX_DEFAULT, D3DUSAGE_RENDERTARGET, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, + D3DX_DEFAULT, 0, NULL, NULL, &cube_texture); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + IDirect3DCubeTexture9_Release(cube_texture);
if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE)) { @@ -2070,10 +2076,11 @@ static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic return; }
- hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT, - D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture); - ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK); - if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture); + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, + D3DX_DEFAULT, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + IDirect3DCubeTexture9_Release(cube_texture); }
static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device) diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 6ee7d72e38..12cb2f3983 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1481,7 +1481,7 @@ HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device, dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC); if (pool == D3DPOOL_DEFAULT && !dynamic_texture) { - hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, D3DPOOL_SYSTEMMEM, &buftex); + hr = D3DXCreateCubeTexture(device, size, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &buftex); tex = buftex; } else
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/texture.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 12cb2f3983..3f22b050b6 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -337,12 +337,15 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN else if (h == D3DX_DEFAULT) h = (width ? w : 256);
- assert(!(fmt->block_width & (fmt->block_width - 1))); - assert(!(fmt->block_height & (fmt->block_height - 1))); - if (w & (fmt->block_width - 1)) - w = (w + fmt->block_width) & ~(fmt->block_width - 1); - if (h & (fmt->block_height - 1)) - h = (h + fmt->block_height) & ~(fmt->block_height - 1); + if (fmt) + { + assert(!(fmt->block_width & (fmt->block_width - 1))); + assert(!(fmt->block_height & (fmt->block_height - 1))); + if (w & (fmt->block_width - 1)) + w = (w + fmt->block_width) & ~(fmt->block_width - 1); + if (h & (fmt->block_height - 1)) + h = (h + fmt->block_height) & ~(fmt->block_height - 1); + }
if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w))) w = make_pow2(w);
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/texture.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 3f22b050b6..b45e55fdad 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -210,8 +210,8 @@ static D3DFORMAT get_replacement_format(D3DFORMAT format) return format; }
-HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height, - UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool) +static HRESULT check_texture_requirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height, + UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool, D3DRESOURCETYPE resource_type) { UINT w = (width && *width) ? *width : 1; UINT h = (height && *height) ? *height : 1; @@ -266,7 +266,7 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN fmt = get_format_info(usedformat);
hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, mode.Format, - usage, D3DRTYPE_TEXTURE, usedformat); + usage, resource_type, usedformat); if (FAILED(hr)) { BOOL allow_24bits; @@ -301,7 +301,7 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN continue;
hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, - mode.Format, usage, D3DRTYPE_TEXTURE, curfmt->format); + mode.Format, usage, resource_type, curfmt->format); if (FAILED(hr)) continue;
@@ -420,6 +420,12 @@ cleanup: return D3D_OK; }
+HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height, + UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool) +{ + return check_texture_requirements(device, width, height, miplevels, usage, format, pool, D3DRTYPE_TEXTURE); +} + HRESULT WINAPI D3DXCheckCubeTextureRequirements(struct IDirect3DDevice9 *device, UINT *size, UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool) {
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index b45e55fdad..37425aeb49 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -447,7 +447,7 @@ HRESULT WINAPI D3DXCheckCubeTextureRequirements(struct IDirect3DDevice9 *device, if ((caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && (!is_pow2(s))) s = make_pow2(s);
- hr = D3DXCheckTextureRequirements(device, &s, &s, miplevels, usage, format, pool); + hr = check_texture_requirements(device, &s, &s, miplevels, usage, format, pool, D3DRTYPE_CUBETEXTURE);
if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP)) {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/tests/texture.c | 17 +++++++++++++++++ dlls/d3dx9_36/texture.c | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 3e4d5e5df9..2688559c2c 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2125,6 +2125,22 @@ static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *devic ok(ref == 0, "Invalid reference count. Got %u, expected 0.\n", ref); }
+static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *device) +{ + IDirect3DVolumeTexture9 *volume_texture; + HRESULT hr; + + hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, dds_volume_map, sizeof(dds_volume_map), D3DX_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, + D3DX_DEFAULT, 0, NULL, NULL, &volume_texture); + ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr); + + hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, dds_volume_map, sizeof(dds_volume_map), D3DX_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, + D3DX_DEFAULT, 0, NULL, NULL, &volume_texture); + ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr); +} + /* fills positive x face with red color */ static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data) { @@ -2599,6 +2615,7 @@ START_TEST(texture) test_D3DXCreateCubeTextureFromFileInMemory(device); test_D3DXCreateCubeTextureFromFileInMemoryEx(device); test_D3DXCreateVolumeTextureFromFileInMemory(device); + test_D3DXCreateVolumeTextureFromFileInMemoryEx(device); test_D3DXSaveTextureToFileInMemory(device);
ref = IDirect3DDevice9_Release(device); diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 37425aeb49..f1b21b7632 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -479,7 +479,7 @@ HRESULT WINAPI D3DXCheckVolumeTextureRequirements(struct IDirect3DDevice9 *devic if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)) return D3DERR_NOTAVAILABLE;
- hr = D3DXCheckTextureRequirements(device, &w, &h, NULL, usage, format, pool); + hr = check_texture_requirements(device, &w, &h, NULL, usage, format, pool, D3DRTYPE_VOLUMETEXTURE); if (d == D3DX_DEFAULT) d = 1;
@@ -1243,7 +1243,6 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, pool, &tex); buftex = NULL; } - if (FAILED(hr)) return hr;
hr = load_volume_texture_from_dds(tex, data, palette, filter, color_key, &image_info);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index f1b21b7632..b7975e1700 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1235,7 +1235,7 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC); if (pool == D3DPOOL_DEFAULT && !dynamic_texture) { - hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, D3DPOOL_SYSTEMMEM, &buftex); + hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &buftex); tex = buftex; } else
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3dx9_36/effect.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/dlls/d3dx9_36/effect.c b/dlls/d3dx9_36/effect.c index 7d686a435d0..63c931e1728 100644 --- a/dlls/d3dx9_36/effect.c +++ b/dlls/d3dx9_36/effect.c @@ -4214,41 +4214,43 @@ static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
- if (IsEqualGUID(riid, &IID_IUnknown) || - IsEqualGUID(riid, &IID_ID3DXEffectCompiler)) + if (IsEqualGUID(riid, &IID_IUnknown) + || IsEqualGUID(riid, &IID_ID3DXEffectCompiler)) { iface->lpVtbl->AddRef(iface); *object = iface; return S_OK; }
- ERR("Interface %s not found\n", debugstr_guid(riid)); + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+ *object = NULL; return E_NOINTERFACE; }
static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface) { - struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface); + struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface); + ULONG refcount = InterlockedIncrement(&compiler->ref);
- TRACE("iface %p: AddRef from %u\n", iface, This->ref); + TRACE("%p increasing refcount to %u.\n", iface, refcount);
- return InterlockedIncrement(&This->ref); + return refcount; }
static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface) { - struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface); - ULONG ref = InterlockedDecrement(&This->ref); + struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface); + ULONG refcount = InterlockedDecrement(&compiler->ref);
- TRACE("iface %p: Release from %u\n", iface, ref + 1); + TRACE("%p decreasing refcount to %u.\n", iface, refcount);
- if (!ref) + if (!refcount) { - HeapFree(GetProcessHeap(), 0, This); + heap_free(compiler); }
- return ref; + return refcount; }
/*** ID3DXBaseEffect methods ***/
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- My own take on 172098. I had a patch like this in my queue for years but I didn't send it earlier because I didn't know anything would be affected by it. It turns out 172101 is probably the first real case where it matters.
Supersedes patch 172098 and should go in its place in the patch series.
dlls/d3dx9_36/texture.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 12cb2f3983d..736d11dfad2 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -323,6 +323,11 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN bestfmt = curfmt; } } + if (!bestfmt) + { + hr = D3DERR_NOTAVAILABLE; + goto cleanup; + } fmt = bestfmt; hr = D3D_OK; }