[PATCH 2/2] wined3d: Fix calculation of pitch for ATI2N format

Stefan Dösinger stefandoesinger at gmx.at
Sun Feb 21 15:21:16 CST 2010

On the big picture I am not sure if the test conclusively shows what is going on. If your test's offset of 2160 bytes is correct something odd is going on.  Please add a test explicitly testing the pitch returned in D3DLOCKED_RECT.Pitch.

> +    hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, MAKEFOURCC('A','T','I','2'), D3DPOOL_SCRATCH, &surface, 0);
> +    ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (%08x)\n", hr);
I am not sure if ATI2N surfaces are available everywhere. Please call CheckDeviceFormat to see if it is supported before trying to create a surface, and if it is not available call skip() and skip the test.

+    todo_wine ok(offset == 2160, "Got offset %u, expected offset 2160 for format ATI2N\n", offset);
I may be a bit dizzy from playing games for 2 days, but I don't understand how you get to an offset of 2160 with the normal surface calculation. According to our table in utils.c ATI2N has 1 byte per pixel, so the offset would be * 1(bpp) * (128(width) * 60(yoffset) + 60(xoffset)) = 7740 bytes.

Following the formula given in the GL_EXT_texture_compression_latc spec I'd get
16[blocksize in bytes] * (128[width]/4 * 60[y] / 4 + 60[x] / 4) = 7920

From patch 2:
> @@ -330,7 +330,7 @@ DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) {
>     DWORD ret;
>     TRACE("(%p)\n", This);

> -    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
> +    if ((format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED) && (format_desc->format != WINED3DFMT_ATI2N))
IwineD3DBaseSurfaceImpl_LockRect assumes that the pitch gives the number of bytes to the next line of blocks rather than the next line in the surface, so LockRect will need some changes as well.

Hardcoding ATI2N is ugly, a new flag for this behavior would be better(or something entirely different depending on what more detailed tests on windows reveal)

More information about the wine-devel mailing list