d3d8: Improve ValidatePixelShader().

Based largely on a patch by Sebastian Lackner.
Adapted from "Improve ValidateVertexShader()" by Henri Verbeet.

Signed-off-by: Gijs Vermeulen <gijsvrm@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gijs Vermeulen 2019-03-04 22:00:06 +03:30 committed by Alexandre Julliard
parent c81db565a7
commit 740102f332
2 changed files with 100 additions and 55 deletions

View File

@ -103,41 +103,49 @@ done:
return hr; return hr;
} }
/*********************************************************************** HRESULT WINAPI ValidatePixelShader(const DWORD *ps_code,
* ValidatePixelShader (D3D8.@) const D3DCAPS8 *caps, BOOL return_error, char **errors)
*
* PARAMS
* toto result?
*/
HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL boolean, DWORD* toto)
{ {
HRESULT ret; const char *message = "";
static BOOL warned; SIZE_T message_size;
HRESULT hr = E_FAIL;
if (TRACE_ON(d3d8) || !warned) { TRACE("ps_code %p, caps %p, return_error %#x, errors %p.\n",
FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, boolean, toto); ps_code, caps, return_error, errors);
warned = TRUE;
}
if (!pixelshader) if (!ps_code)
return E_FAIL; return E_FAIL;
if (reserved1) switch (*ps_code)
return E_FAIL; {
case D3DPS_VERSION(1, 4):
switch(*pixelshader) { case D3DPS_VERSION(1, 3):
case 0xFFFF0100: case D3DPS_VERSION(1, 2):
case 0xFFFF0101: case D3DPS_VERSION(1, 1):
case 0xFFFF0102: case D3DPS_VERSION(1, 0):
case 0xFFFF0103:
case 0xFFFF0104:
ret=S_OK;
break; break;
default: default:
WARN("Invalid shader version token %#x.\n", *pixelshader); message = "Unsupported shader version.\n";
ret=E_FAIL; goto done;
} }
return ret;
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) void d3d8_resource_cleanup(struct d3d8_resource *resource)

View File

@ -53,7 +53,7 @@ struct device_desc
static DEVMODEW registry_mode; static DEVMODEW registry_mode;
static HRESULT (WINAPI *ValidateVertexShader)(const DWORD *, const DWORD *, const D3DCAPS8 *, BOOL, char **); 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); static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
@ -4506,43 +4506,80 @@ static void test_validate_vs(void)
static void test_validate_ps(void) static void test_validate_ps(void)
{ {
static DWORD ps[] = static DWORD ps_1_1_code[] =
{ {
0xffff0101, /* ps_1_1 */ 0xffff0101, /* ps_1_1 */
0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */ 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
0x00000042, 0xb00f0000, /* tex t0 */ 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */ 0x0000ffff /* end */
0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
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; HRESULT hr;
hr = ValidatePixelShader(0, 0, 0, 0); hr = ValidatePixelShader(NULL, NULL, FALSE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(0, 0, 1, 0); hr = ValidatePixelShader(NULL, NULL, TRUE, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps, 0, 0, 0); errors = (void *)0xcafeface;
hr = ValidatePixelShader(NULL, NULL, FALSE, &errors);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
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);
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);
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);
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);
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); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps, 0, 1, 0); *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); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
/* Seems to do some version checking. */ *ps_1_1_code = D3DPS_VERSION(1, 4);
*ps = 0xffff0105; /* bogus version */ hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
hr = ValidatePixelShader(ps, 0, 1, 0); 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); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
/* I've seen that applications always pass the 2nd parameter as 0. *ps_1_1_code = D3DPS_VERSION(1, 5);
* Simple test with a non-zero parameter. */ hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, NULL);
*ps = 0xffff0101; /* ps_1_1 */
hr = ValidatePixelShader(ps, ps, 1, 0);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); 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 hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, &errors);
* other values doesn't seem to hurt. */ ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = ValidatePixelShader(ps, 0, 12345, 0); ok(!*errors, "Got unexpected string \"%s\".\n", errors);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); heap_free(errors);
/* What is the 4th parameter? The following seems to work ok. */ hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, &errors);
hr = ValidatePixelShader(ps, 0, 1, ps); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ok(!!*errors, "Got unexpected empty string.\n");
heap_free(errors);
} }
static void test_volume_get_container(void) static void test_volume_get_container(void)