d3dx9_36: Find, store and enable retreival of CTAB comment data in shader (based...
[wine/hacks.git] / dlls / d3dx9_36 / tests / shader.c
blob8a2a5b1d809d736582dcb563893287870315580e
1 /*
2 * Copyright 2008 Luis Busquets
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
20 #include "d3dx9.h"
22 static const DWORD simple_vs[] = {
23 0xfffe0101, /* vs_1_1 */
24 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
25 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
26 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
27 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
28 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
29 0x0000ffff}; /* END */
31 static const DWORD simple_ps[] = {
32 0xffff0101, /* ps_1_1 */
33 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
34 0x00000042, 0xb00f0000, /* tex t0 */
35 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
36 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
37 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
38 0x0000ffff}; /* END */
40 #define FCC_TEXT MAKEFOURCC('T','E','X','T')
41 #define FCC_CTAB MAKEFOURCC('C','T','A','B')
43 static const DWORD shader_with_ctab[] = {
44 0xfffe0300, /* vs_3_0 */
45 0x0002fffe, FCC_TEXT, 0x00000000, /* TEXT comment */
46 0x0006fffe, FCC_CTAB, 0x0000001c, 0x00000000, 0xfffe0300, 0x00000000, /* CTAB comment */
47 0x00000000,
48 0x0004fffe, FCC_TEXT, 0x00000000, 0x00000000, 0x00000000, /* TEXT comment */
49 0x0000ffff}; /* END */
51 static const DWORD shader_with_invalid_ctab[] = {
52 0xfffe0300, /* vs_3_0 */
53 0x0005fffe, FCC_CTAB, /* CTAB comment */
54 0x0000001c, 0x000000a9, 0xfffe0300,
55 0x00000000, 0x00000000,
56 0x0000ffff}; /* END */
58 static void test_get_shader_size(void)
60 UINT shader_size, expected;
62 shader_size = D3DXGetShaderSize(simple_vs);
63 expected = sizeof(simple_vs);
64 ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
66 shader_size = D3DXGetShaderSize(simple_ps);
67 expected = sizeof(simple_ps);
68 ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
70 shader_size = D3DXGetShaderSize(NULL);
71 ok(shader_size == 0, "Got shader size %u, expected 0\n", shader_size);
74 static void test_get_shader_version(void)
76 DWORD shader_version;
78 shader_version = D3DXGetShaderVersion(simple_vs);
79 ok(shader_version == D3DVS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
80 shader_version, D3DVS_VERSION(1, 1));
82 shader_version = D3DXGetShaderVersion(simple_ps);
83 ok(shader_version == D3DPS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
84 shader_version, D3DPS_VERSION(1, 1));
86 shader_version = D3DXGetShaderVersion(NULL);
87 ok(shader_version == 0, "Got shader version 0x%08x, expected 0\n", shader_version);
90 static void test_find_shader_comment(void)
92 HRESULT hr;
93 LPCVOID data;
94 UINT size;
96 hr = D3DXFindShaderComment(NULL, MAKEFOURCC('C','T','A','B'), &data, &size);
97 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
99 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), NULL, &size);
100 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
102 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, NULL);
103 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
105 hr = D3DXFindShaderComment(shader_with_ctab, 0, &data, &size);
106 ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
108 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('X','X','X','X'), &data, &size);
109 ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
111 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, &size);
112 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
113 ok(data == (LPCVOID)(shader_with_ctab + 6), "Got result %p, expected %p\n", data, shader_with_ctab + 6);
114 ok(size == 20, "Got result %d, expected 20\n", size);
117 static void test_get_shader_constant_table_ex(void)
119 LPD3DXCONSTANTTABLE constant_table = NULL;
120 HRESULT hr;
121 LPVOID data;
122 DWORD size;
124 hr = D3DXGetShaderConstantTableEx(NULL, 0, &constant_table);
125 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
127 /* No CTAB data */
128 hr = D3DXGetShaderConstantTableEx(simple_ps, 0, &constant_table);
129 ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DXERR_INVALIDDATA);
131 /* With invalid CTAB data */
132 hr = D3DXGetShaderConstantTableEx(shader_with_invalid_ctab, 0, &constant_table);
133 todo_wine ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
134 if (constant_table) ID3DXConstantTable_Release(constant_table);
136 hr = D3DXGetShaderConstantTableEx(shader_with_ctab, 0, &constant_table);
137 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
139 if (constant_table)
141 size = ID3DXConstantTable_GetBufferSize(constant_table);
142 ok(size == 20, "Got result %x, expected 20\n", size);
144 data = ID3DXConstantTable_GetBufferPointer(constant_table);
145 ok(!memcmp(data, shader_with_ctab + 6, size), "Retreived wrong CTAB data\n");
147 ID3DXConstantTable_Release(constant_table);
151 START_TEST(shader)
153 test_get_shader_size();
154 test_get_shader_version();
155 test_find_shader_comment();
156 test_get_shader_constant_table_ex();