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/tests/texture.c | 17 +++++++++++++++++ dlls/d3dx9_36/texture.c | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-)
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 12cb2f3983..d71682117c 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1149,6 +1149,9 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic if (!device || !data || !data_size || !volume_texture) return D3DERR_INVALIDCALL;
+ if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) + return D3DERR_NOTAVAILABLE; + hr = D3DXGetImageInfoFromFileInMemory(data, data_size, &image_info); if (FAILED(hr)) return hr;
@@ -1234,7 +1237,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);
On Fri, 25 Oct 2019 at 17:08, Paul Gofman gofmanp@gmail.com wrote:
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 12cb2f3983..d71682117c 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1149,6 +1149,9 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic if (!device || !data || !data_size || !volume_texture) return D3DERR_INVALIDCALL;
- if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
return D3DERR_NOTAVAILABLE;
Does this really need to be explicitly handled in d3dx9? You can't use 3D textures as render targets in d3d9, see also volumetexture_init().
Going by D3DERR_NOTAVAILABLE, I suspect the real issue is that D3DXCheckVolumeTextureRequirements() should catch this through CheckDeviceFormat(), but it currently doesn't because it goes through D3DXCheckTextureRequirements(), which calls CheckDeviceFormat() with D3DRTYPE_TEXTURE instead of D3DRTYPE_VOLUMETEXTURE. The underlying assumption that format capabilities are the same for 2D and 3D resources isn't quite true.
On Fri, Oct 25, 2019 at 6:11 PM Henri Verbeet hverbeet@gmail.com wrote:
On Fri, 25 Oct 2019 at 17:08, Paul Gofman gofmanp@gmail.com wrote:
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 12cb2f3983..d71682117c 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1149,6 +1149,9 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic if (!device || !data || !data_size || !volume_texture) return D3DERR_INVALIDCALL;
- if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
return D3DERR_NOTAVAILABLE;
Does this really need to be explicitly handled in d3dx9? You can't use 3D textures as render targets in d3d9, see also volumetexture_init().
Going by D3DERR_NOTAVAILABLE, I suspect the real issue is that D3DXCheckVolumeTextureRequirements() should catch this through CheckDeviceFormat(), but it currently doesn't because it goes through D3DXCheckTextureRequirements(), which calls CheckDeviceFormat() with D3DRTYPE_TEXTURE instead of D3DRTYPE_VOLUMETEXTURE. The underlying assumption that format capabilities are the same for 2D and 3D resources isn't quite true.
Yes, that's one of the traps lying around in d3dx9. I'm sure there are more...
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 d71682117c..66bbd51aa9 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1229,7 +1229,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