ddraw/tests: Add some video memory accounting tests.

This commit is contained in:
Stefan Dösinger 2022-07-26 15:50:03 +03:00 committed by Alexandre Julliard
parent 8bddb9808e
commit 7fa1259823
4 changed files with 202 additions and 12 deletions

View file

@ -6010,8 +6010,9 @@ cleanup:
static void test_create_surface_pitch(void)
{
IDirectDrawSurface *surface;
IDirectDrawSurface *surface, *primary;
DDSURFACEDESC surface_desc;
DDCAPS caps1, caps2;
IDirectDraw *ddraw;
unsigned int i;
ULONG refcount;
@ -6070,16 +6071,19 @@ static void test_create_surface_pitch(void)
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
0, 0, 0 },
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
0, 0, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 15 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
/* 15 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
0, 0, 0 },
@ -6089,11 +6093,26 @@ static void test_create_surface_pitch(void)
window = create_window();
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
/* We need a primary surface and exclusive mode for video memory accounting to work
* right on Windows. Otherwise it gives us junk data, like creating a video memory
* surface freeing up memory. */
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
ok(SUCCEEDED(hr), "Failed to create a primary surface, hr %#lx.\n", hr);
memset(&caps1, 0, sizeof(caps1));
caps1.dwSize = sizeof(caps1);
hr = IDirectDraw_GetCaps(ddraw, &caps1, NULL);
ok(SUCCEEDED(hr), "Failed to get ddraw caps, hr %#lx.\n", hr);
for (i = 0; i < ARRAY_SIZE(test_data); ++i)
{
memset(&surface_desc, 0, sizeof(surface_desc));
@ -6143,7 +6162,34 @@ static void test_create_surface_pitch(void)
}
ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
memset(&caps2, 0, sizeof(caps2));
caps2.dwSize = sizeof(caps2);
hr = IDirectDraw_GetCaps(ddraw, &caps2, NULL);
ok(SUCCEEDED(hr), "Failed to get ddraw caps, hr %#lx.\n", hr);
if (surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
/* Star Trek Starfleet Academy cares about this bit here: That creating a system memory
* resource does not influence available video memory. */
ok(caps2.dwVidMemFree == caps1.dwVidMemFree, "Free video memory changed from %#lx to %#lx, test %u.\n",
caps1.dwVidMemFree, caps2.dwVidMemFree, i);
}
else if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
{
/* DDSCAPS_ALLOCONLOAD does not seem to delay video memory allocation, at least not on
* modern Windows.
*
* The amount of video memory consumed is different from what dwHeight * lPitch would
* suggest, although not by much. */
ok(caps2.dwVidMemFree < caps1.dwVidMemFree,
"Expected free video memory to change, but it did not, test %u.\n", i);
}
IDirectDrawSurface_Release(surface);
hr = IDirectDraw_GetCaps(ddraw, &caps2, NULL);
ok(SUCCEEDED(hr), "Failed to get ddraw caps, hr %#lx.\n", hr);
ok(caps2.dwVidMemFree == caps1.dwVidMemFree, "Free video memory changed from %#lx to %#lx, test %u.\n",
caps1.dwVidMemFree, caps2.dwVidMemFree, i);
}
HeapFree(GetProcessHeap(), 0, mem);

View file

@ -7107,7 +7107,9 @@ cleanup:
static void test_create_surface_pitch(void)
{
IDirectDrawSurface *surface;
DWORD vidmem_total = 0, vidmem_free = 0, vidmem_free2 = 0;
DDSCAPS vidmem_caps = {DDSCAPS_TEXTURE};
IDirectDrawSurface * surface, *primary;
DDSURFACEDESC surface_desc;
IDirectDraw2 *ddraw;
unsigned int i;
@ -7167,16 +7169,19 @@ static void test_create_surface_pitch(void)
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
0, 0, 0 },
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
0, 0, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 15 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
/* 15 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
0, 0, 0 },
@ -7186,11 +7191,25 @@ static void test_create_surface_pitch(void)
window = create_window();
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
/* We need a primary surface and exclusive mode for video memory accounting to work
* right on Windows. Otherwise it gives us junk data, like creating a video memory
* surface freeing up memory. */
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &primary, NULL);
ok(SUCCEEDED(hr), "Failed to create a primary surface, hr %#lx.\n", hr);
hr = IDirectDraw2_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
for (i = 0; i < ARRAY_SIZE(test_data); ++i)
{
memset(&surface_desc, 0, sizeof(surface_desc));
@ -7241,9 +7260,38 @@ static void test_create_surface_pitch(void)
}
ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
hr = IDirectDraw2_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
/* Star Trek Starfleet Academy cares about this bit here: That creating a system memory
* resource does not influence available video memory. */
ok(vidmem_free2 == vidmem_free, "Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
else if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
{
/* DDSCAPS_ALLOCONLOAD does not seem to delay video memory allocation, at least not on
* modern Windows.
*
* The amount of video memory consumed is different from what dwHeight * lPitch would
* suggest, although not by much. */
ok(vidmem_free2 < vidmem_free,
"Expected free video memory to change, but it did not, test %u.\n", i);
}
IDirectDrawSurface_Release(surface);
hr = IDirectDraw2_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
ok(hr == DDERR_NODIRECTDRAWHW || vidmem_free2 == vidmem_free,
"Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
IDirectDrawSurface_Release(primary);
HeapFree(GetProcessHeap(), 0, mem);
refcount = IDirectDraw2_Release(ddraw);
ok(!refcount, "Got unexpected refcount %lu.\n", refcount);

View file

@ -8990,7 +8990,9 @@ cleanup:
static void test_create_surface_pitch(void)
{
IDirectDrawSurface4 *surface;
DWORD vidmem_total = 0, vidmem_free = 0, vidmem_free2 = 0;
DDSCAPS2 vidmem_caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
IDirectDrawSurface4 * surface, *primary;
DDSURFACEDESC2 surface_desc;
IDirectDraw4 *ddraw;
unsigned int i;
@ -9069,13 +9071,16 @@ static void test_create_surface_pitch(void)
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 20 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
0, 0, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 20 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
@ -9088,11 +9093,25 @@ static void test_create_surface_pitch(void)
window = create_window();
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
/* We need a primary surface and exclusive mode for video memory accounting to work
* right on Windows. Otherwise it gives us junk data, like creating a video memory
* surface freeing up memory. */
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
ok(SUCCEEDED(hr), "Failed to create a primary surface, hr %#lx.\n", hr);
hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
for (i = 0; i < ARRAY_SIZE(test_data); ++i)
{
memset(&surface_desc, 0, sizeof(surface_desc));
@ -9143,9 +9162,38 @@ static void test_create_surface_pitch(void)
}
ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
/* Star Trek Starfleet Academy cares about this bit here: That creating a system memory
* resource does not influence available video memory. */
ok(vidmem_free2 == vidmem_free, "Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
else if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
{
/* DDSCAPS_ALLOCONLOAD does not seem to delay video memory allocation, at least not on
* modern Windows.
*
* The amount of video memory consumed is different from what dwHeight * lPitch would
* suggest, although not by much. */
ok(vidmem_free2 < vidmem_free,
"Expected free video memory to change, but it did not, test %u.\n", i);
}
IDirectDrawSurface4_Release(surface);
hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
ok(hr == DDERR_NODIRECTDRAWHW || vidmem_free2 == vidmem_free,
"Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
IDirectDrawSurface4_Release(primary);
HeapFree(GetProcessHeap(), 0, mem);
refcount = IDirectDraw4_Release(ddraw);
ok(!refcount, "Got unexpected refcount %lu.\n", refcount);

View file

@ -8830,7 +8830,9 @@ cleanup:
static void test_create_surface_pitch(void)
{
IDirectDrawSurface7 *surface;
DWORD vidmem_total = 0, vidmem_free = 0, vidmem_free2 = 0;
DDSCAPS2 vidmem_caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
IDirectDrawSurface7 *surface, *primary;
DDSURFACEDESC2 surface_desc;
IDirectDraw7 *ddraw;
unsigned int i;
@ -8909,13 +8911,16 @@ static void test_create_surface_pitch(void)
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
{DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 20 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
0, 0, DDERR_INVALIDCAPS,
0, 0, 0 },
/* 20 */
{DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
0, 0, DD_OK,
DDSD_PITCH, 0x100, 0 },
@ -8928,11 +8933,25 @@ static void test_create_surface_pitch(void)
window = create_window();
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
/* We need a primary surface and exclusive mode for video memory accounting to work
* right on Windows. Otherwise it gives us junk data, like creating a video memory
* surface freeing up memory. */
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
ok(SUCCEEDED(hr), "Failed to create a primary surface, hr %#lx.\n", hr);
hr = IDirectDraw7_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
for (i = 0; i < ARRAY_SIZE(test_data); ++i)
{
memset(&surface_desc, 0, sizeof(surface_desc));
@ -8986,9 +9005,38 @@ static void test_create_surface_pitch(void)
}
ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
hr = IDirectDraw7_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
/* Star Trek Starfleet Academy cares about this bit here: That creating a system memory
* resource does not influence available video memory. */
ok(vidmem_free2 == vidmem_free, "Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
else if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
{
/* DDSCAPS_ALLOCONLOAD does not seem to delay video memory allocation, at least not on
* modern Windows.
*
* The amount of video memory consumed is different from what dwHeight * lPitch would
* suggest, although not by much. */
ok(vidmem_free2 < vidmem_free,
"Expected free video memory to change, but it did not, test %u.\n", i);
}
IDirectDrawSurface7_Release(surface);
hr = IDirectDraw7_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
"Failed to get available video memory, hr %#lx.\n", hr);
ok(hr == DDERR_NODIRECTDRAWHW || vidmem_free2 == vidmem_free,
"Free video memory changed from %#lx to %#lx, test %u.\n",
vidmem_free, vidmem_free2, i);
}
IDirectDrawSurface7_Release(primary);
HeapFree(GetProcessHeap(), 0, mem);
refcount = IDirectDraw7_Release(ddraw);
ok(!refcount, "Got unexpected refcount %lu.\n", refcount);