Signed-off-by: Paul Gofman gofmanp@gmail.com --- v2: - increase tolerance for some checks (those checks were falling out of tolerance when using fallback srgb read mode in Wine).
dlls/d3d9/tests/visual.c | 395 ++++++++++++++++++++++----------------- 1 file changed, 227 insertions(+), 168 deletions(-)
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c index 3d3597bdd1..196c3fa85f 100644 --- a/dlls/d3d9/tests/visual.c +++ b/dlls/d3d9/tests/visual.c @@ -3767,26 +3767,49 @@ done:
static void fill_surface(IDirect3DSurface9 *surface, DWORD color, DWORD flags) { + unsigned int byte_count; D3DSURFACE_DESC desc; + unsigned int x, y; D3DLOCKED_RECT l; HRESULT hr; - unsigned int x, y; - DWORD *mem; + void *mem;
memset(&desc, 0, sizeof(desc)); memset(&l, 0, sizeof(l)); hr = IDirect3DSurface9_GetDesc(surface, &desc); ok(hr == D3D_OK, "IDirect3DSurface9_GetDesc failed with %08x\n", hr); + + switch(desc.Format) + { + case D3DFMT_A8R8G8B8: + case D3DFMT_X8R8G8B8: + byte_count = 4; + break; + + case D3DFMT_A1R5G5B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_R5G6B5: + byte_count = 2; + break; + + default: + ok(0, "Unsupported format %#x.\n", desc.Format); + return; + } + hr = IDirect3DSurface9_LockRect(surface, &l, NULL, flags); ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed with %08x\n", hr); if(FAILED(hr)) return;
for(y = 0; y < desc.Height; y++) { - mem = (DWORD *) ((BYTE *) l.pBits + y * l.Pitch); - for(x = 0; x < l.Pitch / sizeof(DWORD); x++) + mem = (BYTE *)l.pBits + y * l.Pitch; + for(x = 0; x < l.Pitch / byte_count; ++x) { - mem[x] = color; + if (byte_count == 4) + ((DWORD *)mem)[x] = color; + else + ((WORD *)mem)[x] = color; } } hr = IDirect3DSurface9_UnlockRect(surface); @@ -8964,7 +8987,8 @@ static void srgbtexture_test(void) struct IDirect3DSurface9 *surface; IDirect3DDevice9 *device; IDirect3D9 *d3d; - D3DCOLOR color; + D3DCOLOR colour; + unsigned int i; ULONG refcount; HWND window; DWORD value; @@ -8977,6 +9001,25 @@ static void srgbtexture_test(void) 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, }; + static const struct + { + D3DFORMAT format; + const char *format_name; + DWORD fill_colour1, fill_colour2; + DWORD fill_colour_rb1, fill_colour_rb2; + DWORD conv_colour1, conv_colour2; + } + tests[] = + { + {D3DFMT_A8R8G8B8, "A8R8G8B8", + 0xff7f7f7f, 0xff3f3f3f, 0x007f7f7f, 0x003f3f3f, 0x00363636, 0x000d0d0d}, + {D3DFMT_R5G6B5, "R5G6R5", + 0x7bef, 0x39e7, 0x007b7d7b, 0x003a3d3a, 0x00333433, 0x000a0c0a}, + {D3DFMT_A1R5G5B5, "A1R5G5R5", + 0xbdef, 0x9ce7, 0x007b7b7b, 0x003a3a3a, 0x00333433, 0x000a0a0a}, + {D3DFMT_X1R5G5B5, "X1R5G5R5", + 0x3def, 0x1ce7, 0x007b7b7b, 0x003a3a3a, 0x00333433, 0x000a0a0a}, + };
window = create_window(); d3d = Direct3DCreate9(D3D_SDK_VERSION); @@ -8987,179 +9030,195 @@ static void srgbtexture_test(void) goto done; }
- if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, - D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8) != D3D_OK) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - skip("D3DFMT_A8R8G8B8 textures with SRGBREAD not supported.\n"); - IDirect3DDevice9_Release(device); - goto done; - } + if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, + D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, tests[i].format) != D3D_OK) + { + skip("%s textures with SRGBREAD are not supported.\n", tests[i].format_name); + continue; + }
- hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 2, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - fill_surface(surface, 0xff7f7f7f, 0); - IDirect3DSurface9_Release(surface); - hr = IDirect3DTexture9_GetSurfaceLevel(texture, 1, &surface); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - fill_surface(surface, 0xff3f3f3f, 0); - IDirect3DSurface9_Release(surface); + hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 2, 0, tests[i].format, D3DPOOL_MANAGED, &texture, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + fill_surface(surface, tests[i].fill_colour1, 0); + IDirect3DSurface9_Release(surface); + hr = IDirect3DTexture9_GetSurfaceLevel(texture, 1, &surface); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + fill_surface(surface, tests[i].fill_colour2, 0); + IDirect3DSurface9_Release(surface);
- hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- /* AMD uses the LSB of the D3DSAMP_SRGBTEXTURE value. - * NVIDIA ignores any values other than 0 and 1, leaving the previous - * D3DSAMP_SRGBTEXTURE state. - * Intel, WARP treat the value as boolean. */ - hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x007f7f7f, 1) || broken(color_match(color, 0x00363636, 1)), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + /* AMD uses the LSB of the D3DSAMP_SRGBTEXTURE value. + * NVIDIA ignores any values other than 0 and 1, leaving the previous + * D3DSAMP_SRGBTEXTURE state. + * Intel, WARP treat the value as boolean. */ + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb1, 2) + || broken(color_match(colour, tests[i].conv_colour1, 1)), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 100); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 100, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x007f7f7f, 1) || broken(color_match(color, 0x00363636, 1)), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 100); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 100, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb1, 2) + || broken(color_match(colour, tests[i].conv_colour1, 1)), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 2); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 2, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x007f7f7f, 1) || broken(color_match(color, 0x00363636, 1)), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 2, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb1, 2) + || broken(color_match(colour, tests[i].conv_colour1, 1)), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 3); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 3, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x007f7f7f, 1) || color_match(color, 0x00363636, 1), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 3); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 3, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb1, 2) + || color_match(colour, tests[i].conv_colour1, 3), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, TRUE); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == TRUE, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x00363636, 1), "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == TRUE, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].conv_colour1, 3), "Format %s, got unexpected colour 0x%08x.\n", + tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - /* Set the other state to verify that the sampler just inherits old - * D3DSAMP_SRGBTEXTURE but * the old sampler is not preserved entirely on - * NVIDIA. */ - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x000d0d0d, 1) || color_match(color, 0x003f3f3f, 1), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + /* Set the other state to verify that the sampler just inherits old + * D3DSAMP_SRGBTEXTURE but the old sampler is not preserved entirely on + * NVIDIA. */ + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].conv_colour2, 1) + || color_match(colour, tests[i].fill_colour_rb2, 2), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 0, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x003f3f3f, 1), "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 0, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb2, 2), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].fill_colour_rb2, 2) + || broken(color_match(colour, tests[i].conv_colour2, 1)), + "Format %s, got unexpected colour 0x%08x.\n", tests[i].format_name, colour); + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + IDirect3DTexture9_Release(texture); + + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + }
- hr = IDirect3DDevice9_BeginScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, 0x7e41882a); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, &value); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(value == 0x7e41882a, "Got unexpected value %#x.\n", value); - hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float)); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - hr = IDirect3DDevice9_EndScene(device); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x003f3f3f, 1) || broken(color_match(color, 0x000d0d0d, 1)), - "Got unexpected color 0x%08x.\n", color); - hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - IDirect3DTexture9_Release(texture); refcount = IDirect3DDevice9_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); done:
Nvidia and Intel support that and Warhammer Online relies on that if detects GPU as Nvidia.
The patch introduces a forced fallback to code path without EXT_TEXTURE_SRGB_DECODE for specified formats. Otherwise 16 bit d3d formats with SRGB reads supported would always use 24 or 32 bit internal GL format.
Spotted in https://bugs.winehq.org/show_bug.cgi?id=48302.
Signed-off-by: Paul Gofman gofmanp@gmail.com --- v2: - introduce WINED3DFMT_FLAG_SEPARATE_SRGB to avoid always using 24 bit internal format for WINED3DFMT_B5G6R5_UNORM when EXT_TEXTURE_SRGB_DECODE is present.
dlls/wined3d/texture.c | 7 +++++-- dlls/wined3d/utils.c | 24 ++++++++++++++---------- dlls/wined3d/wined3d_private.h | 9 +++++++-- 3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index c191e2423a..e970c13d7a 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -876,7 +876,8 @@ void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl, gl_tex->sampler_desc.max_anisotropy = 1; gl_tex->sampler_desc.compare = FALSE; gl_tex->sampler_desc.comparison_func = WINED3D_CMP_LESSEQUAL; - if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_SEPARATE_SRGB)) gl_tex->sampler_desc.srgb_decode = TRUE; else gl_tex->sampler_desc.srgb_decode = srgb; @@ -1045,7 +1046,8 @@ void wined3d_texture_gl_apply_sampler_desc(struct wined3d_texture_gl *texture_gl
if (!sampler_desc->srgb_decode != !gl_tex->sampler_desc.srgb_decode && (context_gl->c.d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL) - && gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + && gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_SEPARATE_SRGB)) { gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, sampler_desc->srgb_decode ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT); @@ -2750,6 +2752,7 @@ static BOOL wined3d_texture_gl_load_texture(struct wined3d_texture_gl *texture_g
if (!depth && sub_resource->locations & (WINED3D_LOCATION_TEXTURE_SRGB | WINED3D_LOCATION_TEXTURE_RGB) && (texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB) + && !(texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_SEPARATE_SRGB) && fbo_blitter_supported(WINED3D_BLIT_OP_COLOR_BLIT, gl_info, &texture_gl->t.resource, WINED3D_LOCATION_TEXTURE_RGB, &texture_gl->t.resource, WINED3D_LOCATION_TEXTURE_SRGB)) diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 820a4c7d80..59a571c997 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -1535,15 +1535,15 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE, WINED3D_GL_EXT_NONE, NULL}, - {WINED3DFMT_B5G6R5_UNORM, GL_RGB5, GL_RGB5, GL_RGB8, + {WINED3DFMT_B5G6R5_UNORM, GL_RGB5, GL_SRGB8_EXT, GL_RGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING - | WINED3DFMT_FLAG_RENDERTARGET, + | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, WINED3D_GL_EXT_NONE, NULL}, - {WINED3DFMT_B5G6R5_UNORM, GL_RGB565, GL_RGB565, GL_RGB8, + {WINED3DFMT_B5G6R5_UNORM, GL_RGB565, GL_SRGB8_EXT, GL_RGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING - | WINED3DFMT_FLAG_RENDERTARGET, + | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, ARB_ES2_COMPATIBILITY, NULL}, {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_RGB5, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0, @@ -2756,7 +2756,8 @@ static void check_fbo_compat(struct wined3d_caps_gl_ctx *ctx, struct wined3d_for TRACE("Format %s's sRGB format is FBO attachable, type %u.\n", debug_d3dformat(format->f.id), type); format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB; - if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SEPARATE_SRGB)) format->internal = format->srgb_internal; } else @@ -2891,7 +2892,6 @@ static void init_format_fbo_compat_info(const struct wined3d_adapter *adapter, } } } - if (format->internal != format->srgb_internal) { gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type), @@ -2901,7 +2901,8 @@ static void init_format_fbo_compat_info(const struct wined3d_adapter *adapter, TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n", debug_d3dformat(format->f.id), type); format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB; - if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SEPARATE_SRGB)) format->internal = format->srgb_internal; } else @@ -3114,7 +3115,8 @@ static void query_internal_format(struct wined3d_adapter *adapter, query_format_flag(gl_info, format, format->srgb_internal, GL_SRGB_READ, WINED3DFMT_FLAG_SRGB_READ, "sRGB read");
- if (srgb_write_supported) + if (srgb_write_supported + && !(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SEPARATE_SRGB)) query_format_flag(gl_info, format, format->srgb_internal, GL_SRGB_WRITE, WINED3DFMT_FLAG_SRGB_WRITE, "sRGB write"); else @@ -3123,7 +3125,8 @@ static void query_internal_format(struct wined3d_adapter *adapter, if (!(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE))) format->srgb_internal = format->internal; - else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SEPARATE_SRGB)) format->internal = format->srgb_internal; } } @@ -3145,7 +3148,8 @@ static void query_internal_format(struct wined3d_adapter *adapter, format->srgb_internal = format->internal; format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE); } - else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + && !(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SEPARATE_SRGB)) { format->internal = format->srgb_internal; } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 1f3808a7f1..62791c8d96 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4919,6 +4919,7 @@ extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN #define WINED3DFMT_FLAG_VERTEX_ATTRIBUTE 0x01000000 #define WINED3DFMT_FLAG_BLIT 0x02000000 #define WINED3DFMT_FLAG_MAPPABLE 0x04000000 +#define WINED3DFMT_FLAG_SEPARATE_SRGB 0x08000000
struct wined3d_rational { @@ -5069,15 +5070,19 @@ static inline BOOL is_srgb_enabled(const DWORD *sampler_states) static inline BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context, const struct wined3d_texture *texture) { + BOOL format_separate_srgb; + if (!(context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)) return FALSE;
- if (!context->d3d_info->srgb_read_control + format_separate_srgb = texture->resource.format_flags & WINED3DFMT_FLAG_SEPARATE_SRGB; + + if ((!context->d3d_info->srgb_read_control || format_separate_srgb) && (texture->resource.bind_flags & WINED3D_BIND_SHADER_RESOURCE) && (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_READ)) return TRUE;
- if (!context->d3d_info->srgb_write_control + if ((!context->d3d_info->srgb_write_control || format_separate_srgb) && (texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET) && (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)) return TRUE;
Signed-off-by: Paul Gofman gofmanp@gmail.com --- v2: - use WINED3DFMT_FLAG_SEPARATE_SRGB.
dlls/wined3d/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 59a571c997..03fb190307 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -1545,10 +1545,10 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, ARB_ES2_COMPATIBILITY, NULL}, - {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_RGB5, 0, + {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_SRGB8_EXT, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING - | WINED3DFMT_FLAG_RENDERTARGET, + | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_RGB5_A1, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
Signed-off-by: Paul Gofman gofmanp@gmail.com --- v2: - use WINED3DFMT_FLAG_SEPARATE_SRGB.
dlls/wined3d/utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 03fb190307..5a85d651f7 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -1550,9 +1550,10 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, WINED3D_GL_EXT_NONE, NULL}, - {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_RGB5_A1, 0, + {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_SRGB8_EXT, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0, - WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, + WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING + | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SEPARATE_SRGB, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_B4G4R4A4_UNORM, GL_RGBA4, GL_SRGB8_ALPHA8_EXT, 0, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=63561
Your paranoid android.
=== w1064v1809_ja (32 bit report) ===
Report errors: d3d9:visual crashed (c0000409)