2 * Copyright 2009 Henri Verbeet for CodeWeavers
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
20 #include "wine/port.h"
22 #include "wined3d_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
26 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
27 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0xf << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
29 #define WINED3D_SM4_OPCODE_MASK 0xff
31 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
32 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xf << WINED3D_SM4_REGISTER_TYPE_SHIFT)
34 #define WINED3D_SM4_IMMCONST_TYPE_SHIFT 0
35 #define WINED3D_SM4_IMMCONST_TYPE_MASK (0x3 << WINED3D_SM4_IMMCONST_TYPE_SHIFT)
37 #define WINED3D_SM4_WRITEMASK_SHIFT 4
38 #define WINED3D_SM4_WRITEMASK_MASK (0xf << WINED3D_SM4_WRITEMASK_SHIFT)
40 #define WINED3D_SM4_SWIZZLE_SHIFT 4
41 #define WINED3D_SM4_SWIZZLE_MASK (0xff << WINED3D_SM4_SWIZZLE_SHIFT)
43 enum wined3d_sm4_register_type
45 WINED3D_SM4_RT_TEMP = 0x0,
46 WINED3D_SM4_RT_INPUT = 0x1,
47 WINED3D_SM4_RT_OUTPUT = 0x2,
48 WINED3D_SM4_RT_IMMCONST = 0x4,
51 enum wined3d_sm4_immconst_type
53 WINED3D_SM4_IMMCONST_FLOAT = 0x1,
54 WINED3D_SM4_IMMCONST_FLOAT4 = 0x2,
57 struct wined3d_sm4_data
62 static const WINED3DSHADER_PARAM_REGISTER_TYPE register_type_table[] =
64 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP,
65 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT,
66 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT,
68 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST,
71 static void *shader_sm4_init(const DWORD *byte_code)
73 struct wined3d_sm4_data *priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
76 ERR("Failed to allocate private data\n");
83 static void shader_sm4_free(void *data)
85 HeapFree(GetProcessHeap(), 0, data);
88 static void shader_sm4_read_header(void *data, const DWORD **ptr, DWORD *shader_version)
90 struct wined3d_sm4_data *priv = data;
93 TRACE("version: 0x%08x\n", **ptr);
94 *shader_version = *(*ptr)++;
95 TRACE("token count: %u\n", **ptr);
96 priv->end += *(*ptr)++;
99 static void shader_sm4_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins,
100 UINT *param_size, DWORD shader_version)
102 DWORD token = *(*ptr)++;
103 DWORD opcode = token & WINED3D_SM4_OPCODE_MASK;
105 FIXME("Unrecognized opcode %#x, token 0x%08x\n", opcode, token);
107 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
113 *param_size = ((token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
116 static void shader_sm4_read_src_param(const DWORD **ptr, struct wined3d_shader_src_param *src_param,
117 struct wined3d_shader_src_param *src_rel_addr, DWORD shader_version)
119 DWORD token = *(*ptr)++;
120 enum wined3d_sm4_register_type register_type;
122 register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
123 if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table))
125 FIXME("Unhandled register type %#x\n", register_type);
126 src_param->register_type = WINED3DSPR_TEMP;
130 src_param->register_type = register_type_table[register_type];
133 if (register_type == WINED3D_SM4_RT_IMMCONST)
135 enum wined3d_sm4_immconst_type immconst_type =
136 (token & WINED3D_SM4_IMMCONST_TYPE_MASK) >> WINED3D_SM4_IMMCONST_TYPE_SHIFT;
137 src_param->swizzle = WINED3DSP_NOSWIZZLE;
139 switch(immconst_type)
141 case WINED3D_SM4_IMMCONST_FLOAT:
142 src_param->immconst_type = WINED3D_IMMCONST_FLOAT;
143 memcpy(src_param->immconst_data, *ptr, 1 * sizeof(DWORD));
147 case WINED3D_SM4_IMMCONST_FLOAT4:
148 src_param->immconst_type = WINED3D_IMMCONST_FLOAT4;
149 memcpy(src_param->immconst_data, *ptr, 4 * sizeof(DWORD));
154 FIXME("Unhandled immediate constant type %#x\n", immconst_type);
160 src_param->register_idx = *(*ptr)++;
161 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
164 src_param->modifiers = 0;
165 src_param->rel_addr = NULL;
168 static void shader_sm4_read_dst_param(const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
169 struct wined3d_shader_src_param *dst_rel_addr, DWORD shader_version)
171 DWORD token = *(*ptr)++;
172 UINT register_idx = *(*ptr)++;
173 enum wined3d_sm4_register_type register_type;
175 register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
176 if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table))
178 FIXME("Unhandled register type %#x\n", register_type);
179 dst_param->register_type = WINED3DSPR_TEMP;
183 dst_param->register_type = register_type_table[register_type];
186 dst_param->register_idx = register_idx;
187 dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
188 dst_param->modifiers = 0;
189 dst_param->shift = 0;
190 dst_param->rel_addr = NULL;
193 static void shader_sm4_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
195 FIXME("ptr %p, semantic %p stub!\n", ptr, semantic);
198 static void shader_sm4_read_comment(const DWORD **ptr, const char **comment)
200 FIXME("ptr %p, comment %p stub!\n", ptr, comment);
204 static BOOL shader_sm4_is_end(void *data, const DWORD **ptr)
206 struct wined3d_sm4_data *priv = data;
207 return *ptr == priv->end;
210 const struct wined3d_shader_frontend sm4_shader_frontend =
214 shader_sm4_read_header,
215 shader_sm4_read_opcode,
216 shader_sm4_read_src_param,
217 shader_sm4_read_dst_param,
218 shader_sm4_read_semantic,
219 shader_sm4_read_comment,