From: Józef Kucia Subject: [PATCH 6/7] d3d11/tests: Port test_create_shader_resource_view() from d3d10core. Message-Id: <1439161885-32146-6-git-send-email-jkucia@codeweavers.com> Date: Mon, 10 Aug 2015 01:11:24 +0200 --- dlls/d3d11/tests/d3d11.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index d65a2a2..61abc8a 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -372,10 +372,96 @@ static void test_create_rendertarget_view(void) ok(!refcount, "Device has %u references left.\n", refcount); } +static void test_create_shader_resource_view(void) +{ + D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; + D3D11_TEXTURE2D_DESC texture_desc; + ULONG refcount, expected_refcount; + ID3D11ShaderResourceView *srview; + D3D11_BUFFER_DESC buffer_desc; + ID3D11Device *device, *tmp; + ID3D11Texture2D *texture; + ID3D11Buffer *buffer; + HRESULT hr; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + buffer_desc.ByteWidth = 1024; + buffer_desc.Usage = D3D11_USAGE_DEFAULT; + buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = 0; + buffer_desc.StructureByteStride = 0; + + hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer); + ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr); + + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview); + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + U(srv_desc).Buffer.ElementOffset = 0; + U(srv_desc).Buffer.ElementWidth = 64; + + expected_refcount = get_refcount((IUnknown *)device) + 1; + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview); + ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr); + refcount = get_refcount((IUnknown *)device); + ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount); + tmp = NULL; + expected_refcount = refcount + 1; + ID3D11ShaderResourceView_GetDevice(srview, &tmp); + ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device); + refcount = get_refcount((IUnknown *)device); + ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount); + ID3D11Device_Release(tmp); + + ID3D11ShaderResourceView_Release(srview); + ID3D11Buffer_Release(buffer); + + texture_desc.Width = 512; + texture_desc.Height = 512; + texture_desc.MipLevels = 0; + texture_desc.ArraySize = 1; + texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); + + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview); + ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr); + + ID3D11ShaderResourceView_GetDesc(srview, &srv_desc); + ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format); + ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D, + "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension); + ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n", + U(srv_desc).Texture2D.MostDetailedMip); + ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels); + + ID3D11ShaderResourceView_Release(srview); + ID3D11Texture2D_Release(texture); + + refcount = ID3D11Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + START_TEST(d3d11) { test_create_texture2d(); test_create_texture3d(); test_create_depthstencil_view(); test_create_rendertarget_view(); + test_create_shader_resource_view(); } -- 2.4.6