d3d9/tests: Add a test for timestamp queries.

This commit is contained in:
Matteo Bruni 2014-04-16 18:14:46 +02:00 committed by Alexandre Julliard
parent b7c5e341ae
commit cdedb06af7
1 changed files with 149 additions and 0 deletions

View File

@ -3869,6 +3869,154 @@ static void test_occlusion_query_states(void)
DestroyWindow(window);
}
static void test_timestamp_query(void)
{
static const float point[3] = {0.0, 0.0, 0.0};
IDirect3DQuery9 *query, *disjoint_query, *freq_query;
unsigned int data_size, i;
IDirect3DDevice9 *device;
IDirect3D9 *d3d9;
ULONG refcount;
HWND window;
HRESULT hr;
UINT64 timestamp, freq;
BOOL disjoint;
window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
ok(!!d3d9, "Failed to create a D3D object.\n");
if (!(device = create_device(d3d9, window, window, TRUE)))
{
skip("Failed to create a D3D device, skipping tests.\n");
IDirect3D9_Release(d3d9);
DestroyWindow(window);
return;
}
hr = IDirect3DDevice9_CreateQuery(device, D3DQUERYTYPE_TIMESTAMPFREQ, &freq_query);
ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
if (FAILED(hr))
{
skip("Timestamp queries are not supported, skipping tests.\n");
IDirect3DDevice9_Release(device);
IDirect3D9_Release(d3d9);
DestroyWindow(window);
return;
}
data_size = IDirect3DQuery9_GetDataSize(freq_query);
ok(data_size == sizeof(UINT64), "Query data size is %u, 8 expected.\n", data_size);
hr = IDirect3DDevice9_CreateQuery(device, D3DQUERYTYPE_TIMESTAMPDISJOINT, &disjoint_query);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
data_size = IDirect3DQuery9_GetDataSize(disjoint_query);
ok(data_size == sizeof(BOOL), "Query data size is %u, 4 expected.\n", data_size);
hr = IDirect3DDevice9_CreateQuery(device, D3DQUERYTYPE_TIMESTAMP, &query);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
data_size = IDirect3DQuery9_GetDataSize(query);
ok(data_size == sizeof(UINT64), "Query data size is %u, 8 expected.\n", data_size);
hr = IDirect3DQuery9_Issue(freq_query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < 500; ++i)
{
if ((hr = IDirect3DQuery9_GetData(freq_query, NULL, 0, D3DGETDATA_FLUSH)) != S_FALSE)
break;
Sleep(10);
}
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(freq_query, &freq, sizeof(freq), D3DGETDATA_FLUSH);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_BEGIN);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_BEGIN);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
ok(hr == S_FALSE || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < 500; ++i)
{
if ((hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH)) != S_FALSE)
break;
Sleep(10);
}
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(query, D3DISSUE_BEGIN);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < 500; ++i)
{
if ((hr = IDirect3DQuery9_GetData(disjoint_query, NULL, 0, D3DGETDATA_FLUSH)) != S_FALSE)
break;
Sleep(10);
}
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(disjoint_query, &disjoint, sizeof(disjoint), D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
/* It's not strictly necessary for the TIMESTAMP query to be inside
* a TIMESTAMP_DISJOINT query. */
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < 500; ++i)
{
if ((hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH)) != S_FALSE)
break;
Sleep(10);
}
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
IDirect3DQuery9_Release(query);
IDirect3DQuery9_Release(disjoint_query);
IDirect3DQuery9_Release(freq_query);
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
IDirect3D9_Release(d3d9);
DestroyWindow(window);
}
static void test_get_set_vertex_shader(void)
{
IDirect3DVertexShader9 *current_shader = NULL;
@ -7903,6 +8051,7 @@ START_TEST(device)
test_vertex_buffer_alignment();
test_query_support();
test_occlusion_query_states();
test_timestamp_query();
test_get_set_vertex_shader();
test_vertex_shader_constant();
test_get_set_pixel_shader();