Commit 740102f3 authored by Gijs Vermeulen's avatar Gijs Vermeulen Committed by Alexandre Julliard

d3d8: Improve ValidatePixelShader().

Based largely on a patch by Sebastian Lackner. Adapted from "Improve ValidateVertexShader()" by Henri Verbeet. Signed-off-by: 's avatarGijs Vermeulen <gijsvrm@gmail.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent c81db565
......@@ -103,41 +103,49 @@ done:
return hr;
}
/***********************************************************************
* ValidatePixelShader (D3D8.@)
*
* PARAMS
* toto result?
*/
HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL boolean, DWORD* toto)
HRESULT WINAPI ValidatePixelShader(const DWORD *ps_code,
const D3DCAPS8 *caps, BOOL return_error, char **errors)
{
HRESULT ret;
static BOOL warned;
if (TRACE_ON(d3d8) || !warned) {
FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, boolean, toto);
warned = TRUE;
}
if (!pixelshader)
return E_FAIL;
if (reserved1)
return E_FAIL;
switch(*pixelshader) {
case 0xFFFF0100:
case 0xFFFF0101:
case 0xFFFF0102:
case 0xFFFF0103:
case 0xFFFF0104:
ret=S_OK;
const char *message = "";
SIZE_T message_size;
HRESULT hr = E_FAIL;
TRACE("ps_code %p, caps %p, return_error %#x, errors %p.\n",
ps_code, caps, return_error, errors);
if (!ps_code)
return E_FAIL;
switch (*ps_code)
{
case D3DPS_VERSION(1, 4):
case D3DPS_VERSION(1, 3):
case D3DPS_VERSION(1, 2):
case D3DPS_VERSION(1, 1):
case D3DPS_VERSION(1, 0):
break;
default:
WARN("Invalid shader version token %#x.\n", *pixelshader);
ret=E_FAIL;
}
return ret;
message = "Unsupported shader version.\n";
goto done;
}
if (caps && *ps_code > caps->PixelShaderVersion)
{
message = "Shader version not supported by caps.\n";
goto done;
}
hr = S_OK;
done:
if (!return_error)
message = "";
message_size = strlen(message) + 1;
if (errors && (*errors = heap_alloc(message_size)))
memcpy(*errors, message, message_size);
return hr;
}
void d3d8_resource_cleanup(struct d3d8_resource *resource)
......
......@@ -53,7 +53,7 @@ struct device_desc
static DEVMODEW registry_mode;
static HRESULT (WINAPI *ValidateVertexShader)(const DWORD *, const DWORD *, const D3DCAPS8 *, BOOL, char **);
static HRESULT (WINAPI *ValidatePixelShader)(DWORD *, DWORD *, int, DWORD *);
static HRESULT (WINAPI *ValidatePixelShader)(const DWORD *, const D3DCAPS8 *, BOOL, char **);
static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
......@@ -4506,43 +4506,80 @@ static void test_validate_vs(void)
static void test_validate_ps(void)
{
static DWORD ps[] =
static DWORD ps_1_1_code[] =
{
0xffff0101, /* ps_1_1 */
0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
0x00000042, 0xb00f0000, /* tex t0 */
0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
0x0000ffff, /* end */
0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
0x0000ffff /* end */
};
static const DWORD ps_2_0_code[] =
{
0xffff0200, /* ps_2_0 */
0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
0x0000ffff /* end */
};
D3DCAPS8 caps;
char *errors;
HRESULT hr;
hr = ValidatePixelShader(0, 0, 0, 0);
hr = ValidatePixelShader(NULL, NULL, FALSE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(NULL, NULL, TRUE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
errors = (void *)0xcafeface;
hr = ValidatePixelShader(NULL, NULL, FALSE, &errors);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(0, 0, 1, 0);
ok(errors == (void *)0xcafeface, "Got unexpected errors %p.\n", errors);
errors = (void *)0xcafeface;
hr = ValidatePixelShader(NULL, NULL, TRUE, &errors);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps, 0, 0, 0);
ok(errors == (void *)0xcafeface, "Got unexpected errors %p.\n", errors);
hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, &errors);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(!*errors, "Got unexpected string \"%s\".\n", errors);
heap_free(errors);
hr = ValidatePixelShader(ps, 0, 1, 0);
memset(&caps, 0, sizeof(caps));
caps.PixelShaderVersion = D3DPS_VERSION(1, 1);
hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
/* Seems to do some version checking. */
*ps = 0xffff0105; /* bogus version */
hr = ValidatePixelShader(ps, 0, 1, 0);
caps.PixelShaderVersion = D3DPS_VERSION(1, 0);
hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
/* I've seen that applications always pass the 2nd parameter as 0.
* Simple test with a non-zero parameter. */
*ps = 0xffff0101; /* ps_1_1 */
hr = ValidatePixelShader(ps, ps, 1, 0);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
/* I've seen the 3rd parameter always passed as either 0 or 1, but passing
* other values doesn't seem to hurt. */
hr = ValidatePixelShader(ps, 0, 12345, 0);
caps.PixelShaderVersion = D3DPS_VERSION(1, 2);
hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
caps.PixelShaderVersion = D3DPS_VERSION(8, 8);
hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
*ps_1_1_code = D3DPS_VERSION(1, 0);
hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
/* What is the 4th parameter? The following seems to work ok. */
hr = ValidatePixelShader(ps, 0, 1, ps);
*ps_1_1_code = D3DPS_VERSION(1, 4);
hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps_2_0_code, NULL, FALSE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
*ps_1_1_code = D3DPS_VERSION(1, 5);
hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, &errors);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
ok(!*errors, "Got unexpected string \"%s\".\n", errors);
heap_free(errors);
hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, &errors);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
ok(!!*errors, "Got unexpected empty string.\n");
heap_free(errors);
}
static void test_volume_get_container(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment