d3d11: Disallow 0-sized buffer shader resource views.

Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Matteo Bruni 2017-11-24 23:29:57 +01:00 committed by Alexandre Julliard
parent 21c7b94c81
commit ee00b90fa4
2 changed files with 20 additions and 0 deletions

View File

@ -18433,6 +18433,21 @@ static void test_buffer_srv(void)
cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
buffer_desc.ByteWidth = 256;
buffer_desc.Usage = D3D11_USAGE_DEFAULT;
buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
buffer_desc.CPUAccessFlags = 0;
buffer_desc.MiscFlags = 0;
hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
srv_desc.Format = DXGI_FORMAT_R8_UNORM;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
U(srv_desc).Buffer.FirstElement = 0;
U(srv_desc).Buffer.NumElements = 0;
hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
ID3D11Buffer_Release(buffer);
ps = NULL;
srv = NULL;
buffer = NULL;

View File

@ -616,6 +616,11 @@ static HRESULT normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11R
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
if (!desc->u.Buffer.u2.NumElements)
{
WARN("Zero sized buffer view.\n");
return E_INVALIDARG;
}
return S_OK;
}