From: Zebediah Figura zfigura@codeweavers.com
--- dlls/d3d9/d3d9_private.h | 13 +-- dlls/d3d9/device.c | 6 +- dlls/d3d9/texture.c | 185 +++++++++++---------------------------- 3 files changed, 61 insertions(+), 143 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 858568f5e1c..4169ab74973 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -228,12 +228,13 @@ struct d3d9_texture D3DTEXTUREFILTERTYPE autogen_filter_type; };
-HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; -HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; -HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; +HRESULT d3d9_texture_2d_init(struct d3d9_texture *texture, struct d3d9_device *device, unsigned int width, + unsigned int height, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool); +HRESULT d3d9_texture_3d_init(struct d3d9_texture *texture, struct d3d9_device *device, unsigned int width, + unsigned int height, unsigned int depth, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool); +HRESULT d3d9_texture_cube_init(struct d3d9_texture *texture, struct d3d9_device *device, + unsigned int edge_length, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool); + struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture9 *iface) DECLSPEC_HIDDEN; void d3d9_texture_flag_auto_gen_mipmap(struct d3d9_texture *texture) DECLSPEC_HIDDEN; void d3d9_texture_gen_auto_mipmap(struct d3d9_texture *texture) DECLSPEC_HIDDEN; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 9b8e44f6891..5f7b3f03ae3 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1323,7 +1323,7 @@ static HRESULT WINAPI d3d9_device_CreateTexture(IDirect3DDevice9Ex *iface, if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = texture_init(object, device, width, height, levels, usage, format, pool); + hr = d3d9_texture_2d_init(object, device, width, height, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize texture, hr %#x.\n", hr); @@ -1379,7 +1379,7 @@ static HRESULT WINAPI d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex *iface, if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool); + hr = d3d9_texture_3d_init(object, device, width, height, depth, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize volume texture, hr %#x.\n", hr); @@ -1424,7 +1424,7 @@ static HRESULT WINAPI d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex *iface, if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool); + hr = d3d9_texture_cube_init(object, device, edge_length, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize cube texture, hr %#x.\n", hr); diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c index 31bf95834b8..8f4798fa81c 100644 --- a/dlls/d3d9/texture.c +++ b/dlls/d3d9/texture.c @@ -1293,13 +1293,13 @@ static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops = d3d9_texture_wined3d_object_destroyed, };
-HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +static HRESULT d3d9_texture_init(struct d3d9_texture *texture, struct d3d9_device *device, + const struct wined3d_resource_desc *desc, D3DPOOL pool, DWORD usage, + unsigned int layer_count, unsigned int level_count) { struct wined3d_adapter *wined3d_adapter; - struct wined3d_resource_desc desc; unsigned int output_idx; - DWORD flags = 0; + unsigned int flags = 0; HRESULT hr;
if (pool == D3DPOOL_MANAGED && device->d3d_parent->extended) @@ -1308,25 +1308,14 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, return D3DERR_INVALIDCALL; }
- texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl; d3d9_resource_init(&texture->resource); list_init(&texture->rtv_list); texture->usage = usage;
- desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; - desc.format = wined3dformat_from_d3dformat(format); - desc.multisample_type = WINED3D_MULTISAMPLE_NONE; - desc.multisample_quality = 0; - desc.usage = wined3d_usage_from_d3d(pool, usage); - desc.bind_flags = wined3d_bind_flags_from_d3d9_usage(usage) | WINED3D_BIND_SHADER_RESOURCE; - desc.access = wined3daccess_from_d3dpool(pool, usage); - desc.width = width; - desc.height = height; - desc.depth = 1; - desc.size = 0; - - if (is_gdi_compat_wined3dformat(desc.format)) + if (desc->resource_type == WINED3D_RTYPE_TEXTURE_2D && is_gdi_compat_wined3dformat(desc->format)) flags |= WINED3D_TEXTURE_CREATE_GET_DC; + if (pool == D3DPOOL_SYSTEMMEM) + flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS;
if (usage & D3DUSAGE_WRITEONLY) { @@ -1335,14 +1324,21 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, } if (usage & D3DUSAGE_AUTOGENMIPMAP) { + if (desc->resource_type == WINED3D_RTYPE_TEXTURE_3D) + { + WARN("Texture can't be created with the D3DUSAGE_WRITEONLY flags, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } + if (pool == D3DPOOL_SYSTEMMEM) { WARN("D3DUSAGE_AUTOGENMIPMAP texture can't be in D3DPOOL_SYSTEMMEM, returning D3DERR_INVALIDCALL.\n"); return D3DERR_INVALIDCALL; } - if (levels && levels != 1) + + if (level_count && level_count != 1) { - WARN("D3DUSAGE_AUTOGENMIPMAP texture with %u levels, returning D3DERR_INVALIDCALL.\n", levels); + WARN("D3DUSAGE_AUTOGENMIPMAP texture with %u level_count, returning D3DERR_INVALIDCALL.\n", level_count); return D3DERR_INVALIDCALL; } wined3d_mutex_lock(); @@ -1350,18 +1346,18 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, wined3d_adapter = wined3d_output_get_adapter(device->d3d_parent->wined3d_outputs[output_idx]); hr = wined3d_check_device_format(device->d3d_parent->wined3d, wined3d_adapter, WINED3D_DEVICE_TYPE_HAL, WINED3DFMT_B8G8R8A8_UNORM, WINED3DUSAGE_QUERY_GENMIPMAP, - WINED3D_BIND_SHADER_RESOURCE, WINED3D_RTYPE_TEXTURE_2D, wined3dformat_from_d3dformat(format)); + WINED3D_BIND_SHADER_RESOURCE, WINED3D_RTYPE_TEXTURE_2D, desc->format); wined3d_mutex_unlock(); if (hr == D3D_OK) { flags |= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS; - levels = 0; + level_count = 0; } else { - WARN("D3DUSAGE_AUTOGENMIPMAP not supported on D3DFORMAT %#x, creating a texture " - "with a single level.\n", format); - levels = 1; + WARN("Mipmap autogeneration is not supported on wined3d format %#x, " + "creating a texture with a single level.\n", desc->format); + level_count = 1; } texture->autogen_filter_type = D3DTEXF_LINEAR; } @@ -1369,13 +1365,11 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, { texture->autogen_filter_type = D3DTEXF_NONE; } - if (!levels) - levels = wined3d_log2i(max(width, height)) + 1; - if (pool == D3DPOOL_SYSTEMMEM) - flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS; + if (!level_count) + level_count = wined3d_log2i(max(max(desc->width, desc->height), desc->depth)) + 1;
wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, flags, + hr = wined3d_texture_create(device->wined3d_device, desc, layer_count, level_count, flags, NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) @@ -1390,23 +1384,31 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, return D3D_OK; }
-HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +HRESULT d3d9_texture_2d_init(struct d3d9_texture *texture, struct d3d9_device *device, unsigned int width, + unsigned int height, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; - DWORD flags = 0; - HRESULT hr;
- if (pool == D3DPOOL_MANAGED && device->d3d_parent->extended) - { - WARN("Managed resources are not supported by d3d9ex devices.\n"); - return D3DERR_INVALIDCALL; - } + desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; + desc.format = wined3dformat_from_d3dformat(format); + desc.multisample_type = WINED3D_MULTISAMPLE_NONE; + desc.multisample_quality = 0; + desc.usage = wined3d_usage_from_d3d(pool, usage); + desc.bind_flags = wined3d_bind_flags_from_d3d9_usage(usage) | WINED3D_BIND_SHADER_RESOURCE; + desc.access = wined3daccess_from_d3dpool(pool, usage); + desc.width = width; + desc.height = height; + desc.depth = 1; + desc.size = 0;
- texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl; - d3d9_resource_init(&texture->resource); - list_init(&texture->rtv_list); - texture->usage = usage; + texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl; + return d3d9_texture_init(texture, device, &desc, pool, usage, 1, level_count); +} + +HRESULT d3d9_texture_cube_init(struct d3d9_texture *texture, struct d3d9_device *device, + unsigned int edge_length, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) +{ + struct wined3d_resource_desc desc;
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; desc.format = wined3dformat_from_d3dformat(format); @@ -1420,77 +1422,19 @@ HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *devic desc.depth = 1; desc.size = 0;
- if (is_gdi_compat_wined3dformat(desc.format)) - flags |= WINED3D_TEXTURE_CREATE_GET_DC; - - if (usage & D3DUSAGE_WRITEONLY) - { - WARN("Texture can't be created with the D3DUSAGE_WRITEONLY flags, returning D3DERR_INVALIDCALL.\n"); - return D3DERR_INVALIDCALL; - } - if (usage & D3DUSAGE_AUTOGENMIPMAP) - { - if (pool == D3DPOOL_SYSTEMMEM) - { - WARN("D3DUSAGE_AUTOGENMIPMAP texture can't be in D3DPOOL_SYSTEMMEM, returning D3DERR_INVALIDCALL.\n"); - return D3DERR_INVALIDCALL; - } - if (levels && levels != 1) - { - WARN("D3DUSAGE_AUTOGENMIPMAP texture with %u levels, returning D3DERR_INVALIDCALL.\n", levels); - return D3DERR_INVALIDCALL; - } - flags |= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS; - texture->autogen_filter_type = D3DTEXF_LINEAR; - levels = 0; - } - else - { - texture->autogen_filter_type = D3DTEXF_NONE; - } - if (!levels) - levels = wined3d_log2i(edge_length) + 1; - if (pool == D3DPOOL_SYSTEMMEM) - flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS; - - wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 6, levels, flags, - NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture); - wined3d_mutex_unlock(); - if (FAILED(hr)) - { - WARN("Failed to create wined3d cube texture, hr %#x.\n", hr); - return hr; - } - - texture->parent_device = device; - IDirect3DDevice9Ex_AddRef(&texture->parent_device->IDirect3DDevice9Ex_iface); - - return D3D_OK; + texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl; + return d3d9_texture_init(texture, device, &desc, pool, usage, 6, level_count); }
-HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device, - UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +HRESULT d3d9_texture_3d_init(struct d3d9_texture *texture, struct d3d9_device *device, unsigned int width, + unsigned int height, unsigned int depth, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; - DWORD flags = 0; - HRESULT hr; - - if (pool == D3DPOOL_MANAGED && device->d3d_parent->extended) - { - WARN("Managed resources are not supported by d3d9ex devices.\n"); - return D3DERR_INVALIDCALL; - }
/* In d3d9, 3D textures can't be used as rendertarget or depth/stencil buffer. */ if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) return D3DERR_INVALIDCALL;
- texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl; - d3d9_resource_init(&texture->resource); - list_init(&texture->rtv_list); - texture->usage = usage; - desc.resource_type = WINED3D_RTYPE_TEXTURE_3D; desc.format = wined3dformat_from_d3dformat(format); desc.multisample_type = WINED3D_MULTISAMPLE_NONE; @@ -1503,33 +1447,6 @@ HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *dev desc.depth = depth; desc.size = 0;
- if (usage & D3DUSAGE_WRITEONLY) - { - WARN("Texture can't be created with the D3DUSAGE_WRITEONLY flags, returning D3DERR_INVALIDCALL.\n"); - return D3DERR_INVALIDCALL; - } - if (usage & D3DUSAGE_AUTOGENMIPMAP) - { - WARN("D3DUSAGE_AUTOGENMIPMAP volume texture is not supported, returning D3DERR_INVALIDCALL.\n"); - return D3DERR_INVALIDCALL; - } - if (!levels) - levels = wined3d_log2i(max(max(width, height), depth)) + 1; - if (pool == D3DPOOL_SYSTEMMEM) - flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS; - - wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, flags, - NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture); - wined3d_mutex_unlock(); - if (FAILED(hr)) - { - WARN("Failed to create wined3d volume texture, hr %#x.\n", hr); - return hr; - } - - texture->parent_device = device; - IDirect3DDevice9Ex_AddRef(&texture->parent_device->IDirect3DDevice9Ex_iface); - - return D3D_OK; + texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl; + return d3d9_texture_init(texture, device, &desc, pool, usage, 1, level_count); }