Commit d7d0deab authored by Sven Hesse's avatar Sven Hesse Committed by Alexandre Julliard

d3d11: Create DXGI surfaces for 1D textures.

parent fce60001
......@@ -1351,6 +1351,7 @@ static void test_create_texture1d(void)
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
ID3D10Device_Release(tmp);
check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
ID3D10Texture1D_Release(texture);
desc.MipLevels = 0;
......@@ -1394,6 +1395,123 @@ static void test_create_texture1d(void)
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_texture1d_interfaces(void)
{
ID3D11Texture1D *d3d11_texture;
D3D10_TEXTURE1D_DESC desc;
ID3D10Texture1D *texture;
ID3D10Device *device;
unsigned int i;
ULONG refcount;
HRESULT hr;
static const struct test
{
UINT bind_flags;
UINT misc_flags;
UINT expected_bind_flags;
UINT expected_misc_flags;
}
desc_conversion_tests[] =
{
{
D3D10_BIND_SHADER_RESOURCE, 0,
D3D11_BIND_SHADER_RESOURCE, 0
},
{
0, D3D10_RESOURCE_MISC_SHARED,
0, D3D11_RESOURCE_MISC_SHARED
},
};
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
desc.Width = 512;
desc.MipLevels = 0;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Usage = D3D10_USAGE_DEFAULT;
desc.BindFlags = D3D10_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
hr = check_interface(texture, &IID_ID3D11Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
ID3D10Texture1D_Release(texture);
if (FAILED(hr))
{
win_skip("1D textures do not implement ID3D11Texture1D, skipping tests.\n");
ID3D10Device_Release(device);
return;
}
for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
{
const struct test *current = &desc_conversion_tests[i];
D3D11_TEXTURE1D_DESC d3d11_desc;
ID3D11Device *d3d11_device;
desc.Width = 512;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = current->bind_flags;
desc.CPUAccessFlags = 0;
desc.MiscFlags = current->misc_flags;
hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
/* Shared resources are not supported by REF and WARP devices. */
ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
"Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
if (FAILED(hr))
{
win_skip("Failed to create ID3D10Texture1D, skipping test %u.\n", i);
continue;
}
check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
hr = ID3D10Texture1D_QueryInterface(texture, &IID_ID3D11Texture1D, (void **)&d3d11_texture);
ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture1D.\n", i);
ID3D10Texture1D_Release(texture);
ID3D11Texture1D_GetDesc(d3d11_texture, &d3d11_desc);
ok(d3d11_desc.Width == desc.Width,
"Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
ok(d3d11_desc.MipLevels == desc.MipLevels,
"Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
ok(d3d11_desc.ArraySize == desc.ArraySize,
"Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
ok(d3d11_desc.Format == desc.Format,
"Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
"Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
ok(d3d11_desc.BindFlags == current->expected_bind_flags,
"Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
"Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
"Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
d3d11_device = NULL;
ID3D11Texture1D_GetDevice(d3d11_texture, &d3d11_device);
ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
ID3D11Device_Release(d3d11_device);
ID3D11Texture1D_Release(d3d11_texture);
}
refcount = ID3D10Device_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_create_texture2d(void)
{
ULONG refcount, expected_refcount;
......@@ -15542,6 +15660,7 @@ START_TEST(device)
test_feature_level();
test_device_interfaces();
test_create_texture1d();
test_texture1d_interfaces();
test_create_texture2d();
test_texture2d_interfaces();
test_create_texture3d();
......
......@@ -120,6 +120,7 @@ struct d3d_texture1d
LONG refcount;
struct wined3d_private_store private_store;
IUnknown *dxgi_surface;
struct wined3d_texture *wined3d_texture;
D3D11_TEXTURE1D_DESC desc;
ID3D11Device *device;
......
......@@ -1866,6 +1866,7 @@ static void test_create_texture1d(void)
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
ID3D11Device_Release(tmp);
check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
ID3D11Texture1D_Release(texture);
desc.MipLevels = 0;
......@@ -1919,6 +1920,127 @@ static void test_create_texture1d(void)
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_texture1d_interfaces(void)
{
ID3D10Texture1D *d3d10_texture;
D3D11_TEXTURE1D_DESC desc;
ID3D11Texture1D *texture;
ID3D11Device *device;
unsigned int i;
ULONG refcount;
HRESULT hr;
static const struct test
{
BOOL implements_d3d10_interfaces;
UINT bind_flags;
UINT misc_flags;
UINT expected_bind_flags;
UINT expected_misc_flags;
}
desc_conversion_tests[] =
{
{
TRUE,
D3D11_BIND_SHADER_RESOURCE, 0,
D3D10_BIND_SHADER_RESOURCE, 0
},
{
TRUE,
D3D11_BIND_UNORDERED_ACCESS, 0,
D3D11_BIND_UNORDERED_ACCESS, 0
},
{
FALSE,
0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
0, 0
},
{
TRUE,
0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
},
};
if (!(device = create_device(NULL)))
{
skip("Failed to create ID3D11Device, skipping tests.\n");
return;
}
desc.Width = 512;
desc.MipLevels = 0;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
ID3D11Texture1D_Release(texture);
if (FAILED(hr))
{
win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
ID3D11Device_Release(device);
return;
}
for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
{
const struct test *current = &desc_conversion_tests[i];
ID3D10Device *d3d10_device;
desc.Width = 512;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = current->bind_flags;
desc.CPUAccessFlags = 0;
desc.MiscFlags = current->misc_flags;
hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
/* Shared resources are not supported by REF and WARP devices. */
ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
"Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
if (FAILED(hr))
{
win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
continue;
}
check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
ID3D11Texture1D_Release(texture);
if (current->implements_d3d10_interfaces)
{
ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
}
else
{
todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
continue;
}
d3d10_device = (ID3D10Device *)0xdeadbeef;
ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
if (d3d10_device) ID3D10Device_Release(d3d10_device);
ID3D10Texture1D_Release(d3d10_texture);
}
refcount = ID3D11Device_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_create_texture2d(void)
{
ULONG refcount, expected_refcount;
......@@ -25735,6 +25857,7 @@ START_TEST(d3d11)
run_for_each_feature_level(test_device_interfaces);
test_get_immediate_context();
test_create_texture1d();
test_texture1d_interfaces();
test_create_texture2d();
test_texture2d_interfaces();
test_create_texture3d();
......@@ -57,6 +57,12 @@ static HRESULT STDMETHODCALLTYPE d3d11_texture1d_QueryInterface(ID3D11Texture1D
return S_OK;
}
if (texture->dxgi_surface)
{
TRACE("Forwarding to dxgi surface.\n");
return IUnknown_QueryInterface(texture->dxgi_surface, iid, out);
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
*out = NULL;
......@@ -117,9 +123,19 @@ static HRESULT STDMETHODCALLTYPE d3d11_texture1d_GetPrivateData(ID3D11Texture1D
REFGUID guid, UINT *data_size, void *data)
{
struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface);
IDXGISurface *dxgi_surface;
HRESULT hr;
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
if (texture->dxgi_surface
&& SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface)))
{
hr = IDXGISurface_GetPrivateData(dxgi_surface, guid, data_size, data);
IDXGISurface_Release(dxgi_surface);
return hr;
}
return d3d_get_private_data(&texture->private_store, guid, data_size, data);
}
......@@ -127,9 +143,19 @@ static HRESULT STDMETHODCALLTYPE d3d11_texture1d_SetPrivateData(ID3D11Texture1D
REFGUID guid, UINT data_size, const void *data)
{
struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface);
IDXGISurface *dxgi_surface;
HRESULT hr;
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
if (texture->dxgi_surface
&& SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface)))
{
hr = IDXGISurface_SetPrivateData(dxgi_surface, guid, data_size, data);
IDXGISurface_Release(dxgi_surface);
return hr;
}
return d3d_set_private_data(&texture->private_store, guid, data_size, data);
}
......@@ -137,9 +163,19 @@ static HRESULT STDMETHODCALLTYPE d3d11_texture1d_SetPrivateDataInterface(ID3D11T
REFGUID guid, const IUnknown *data)
{
struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface);
IDXGISurface *dxgi_surface;
HRESULT hr;
TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
if (texture->dxgi_surface
&& SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface)))
{
hr = IDXGISurface_SetPrivateDataInterface(dxgi_surface, guid, data);
IDXGISurface_Release(dxgi_surface);
return hr;
}
return d3d_set_private_data_interface(&texture->private_store, guid, data);
}
......@@ -228,6 +264,8 @@ static void STDMETHODCALLTYPE d3d_texture1d_wined3d_object_released(void *parent
{
struct d3d_texture1d *texture = parent;
if (texture->dxgi_surface)
IUnknown_Release(texture->dxgi_surface);
wined3d_private_store_cleanup(&texture->private_store);
heap_free(texture);
}
......@@ -397,20 +435,46 @@ HRESULT d3d_texture1d_create(struct d3d_device *device, const D3D11_TEXTURE1D_DE
flags |= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS;
wined3d_mutex_lock();
hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc,
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc,
desc->ArraySize, levels, flags, (struct wined3d_sub_resource_data *)data,
texture, &d3d_texture1d_wined3d_parent_ops, &texture->wined3d_texture);
wined3d_mutex_unlock();
if (FAILED(hr))
texture, &d3d_texture1d_wined3d_parent_ops, &texture->wined3d_texture)))
{
WARN("Failed to create wined3d texture, hr %#x.\n", hr);
wined3d_private_store_cleanup(&texture->private_store);
heap_free(texture);
wined3d_mutex_unlock();
if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DERR_INVALIDCALL)
hr = E_INVALIDARG;
return hr;
}
if (desc->MipLevels == 1 && desc->ArraySize == 1)
{
IWineDXGIDevice *wine_device;
if (FAILED(hr = ID3D10Device1_QueryInterface(&device->ID3D10Device1_iface, &IID_IWineDXGIDevice,
(void **)&wine_device)))
{
ERR("Device should implement IWineDXGIDevice.\n");
wined3d_texture_decref(texture->wined3d_texture);
wined3d_mutex_unlock();
return E_FAIL;
}
hr = IWineDXGIDevice_create_surface(wine_device, texture->wined3d_texture, 0, NULL,
(IUnknown *)&texture->ID3D10Texture1D_iface, (void **)&texture->dxgi_surface);
IWineDXGIDevice_Release(wine_device);
if (FAILED(hr))
{
ERR("Failed to create DXGI surface, returning %#.x\n", hr);
texture->dxgi_surface = NULL;
wined3d_texture_decref(texture->wined3d_texture);
wined3d_mutex_unlock();
return hr;
}
}
wined3d_mutex_unlock();
texture->device = &device->ID3D11Device_iface;
ID3D11Device_AddRef(texture->device);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment