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
);
25 WINE_DECLARE_DEBUG_CHANNEL(d3d_bytecode
);
27 #define WINED3D_SM4_INSTRUCTION_MODIFIER (0x1u << 31)
29 #define WINED3D_SM4_MODIFIER_AOFFIMMI 0x1
30 #define WINED3D_SM4_AOFFIMMI_U_SHIFT 9
31 #define WINED3D_SM4_AOFFIMMI_U_MASK (0xfu << WINED3D_SM4_AOFFIMMI_U_SHIFT)
32 #define WINED3D_SM4_AOFFIMMI_V_SHIFT 13
33 #define WINED3D_SM4_AOFFIMMI_V_MASK (0xfu << WINED3D_SM4_AOFFIMMI_V_SHIFT)
34 #define WINED3D_SM4_AOFFIMMI_W_SHIFT 17
35 #define WINED3D_SM4_AOFFIMMI_W_MASK (0xfu << WINED3D_SM4_AOFFIMMI_W_SHIFT)
37 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
38 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0x1fu << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
40 #define WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT 11
41 #define WINED3D_SM4_INSTRUCTION_FLAGS_MASK (0x7u << WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT)
43 #define WINED3D_SM4_RESOURCE_TYPE_SHIFT 11
44 #define WINED3D_SM4_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM4_RESOURCE_TYPE_SHIFT)
46 #define WINED3D_SM4_PRIMITIVE_TYPE_SHIFT 11
47 #define WINED3D_SM4_PRIMITIVE_TYPE_MASK (0x3fu << WINED3D_SM4_PRIMITIVE_TYPE_SHIFT)
49 #define WINED3D_SM4_INDEX_TYPE_SHIFT 11
50 #define WINED3D_SM4_INDEX_TYPE_MASK (0x1u << WINED3D_SM4_INDEX_TYPE_SHIFT)
52 #define WINED3D_SM4_SAMPLER_MODE_SHIFT 11
53 #define WINED3D_SM4_SAMPLER_MODE_MASK (0xfu << WINED3D_SM4_SAMPLER_MODE_SHIFT)
55 #define WINED3D_SM4_SHADER_DATA_TYPE_SHIFT 11
56 #define WINED3D_SM4_SHADER_DATA_TYPE_MASK (0xfu << WINED3D_SM4_SHADER_DATA_TYPE_SHIFT)
58 #define WINED3D_SM4_INTERPOLATION_MODE_SHIFT 11
59 #define WINED3D_SM4_INTERPOLATION_MODE_MASK (0xfu << WINED3D_SM4_INTERPOLATION_MODE_SHIFT)
61 #define WINED3D_SM4_GLOBAL_FLAGS_SHIFT 11
62 #define WINED3D_SM4_GLOBAL_FLAGS_MASK (0xffu << WINED3D_SM4_GLOBAL_FLAGS_SHIFT)
64 #define WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT 11
65 #define WINED3D_SM5_CONTROL_POINT_COUNT_MASK (0xffu << WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT)
67 #define WINED3D_SM5_FP_ARRAY_SIZE_SHIFT 16
68 #define WINED3D_SM5_FP_TABLE_COUNT_MASK 0xffffu
70 #define WINED3D_SM5_UAV_FLAGS_SHIFT 15
71 #define WINED3D_SM5_UAV_FLAGS_MASK (0x1ffu << WINED3D_SM5_UAV_FLAGS_SHIFT)
73 #define WINED3D_SM5_SYNC_FLAGS_SHIFT 11
74 #define WINED3D_SM5_SYNC_FLAGS_MASK (0xffu << WINED3D_SM5_SYNC_FLAGS_SHIFT)
76 #define WINED3D_SM5_TESSELLATOR_SHIFT 11
77 #define WINED3D_SM5_TESSELLATOR_MASK (0xfu << WINED3D_SM5_TESSELLATOR_SHIFT)
79 #define WINED3D_SM4_OPCODE_MASK 0xff
81 #define WINED3D_SM4_REGISTER_MODIFIER (0x1u << 31)
83 #define WINED3D_SM4_ADDRESSING_SHIFT1 25
84 #define WINED3D_SM4_ADDRESSING_MASK1 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT1)
86 #define WINED3D_SM4_ADDRESSING_SHIFT0 22
87 #define WINED3D_SM4_ADDRESSING_MASK0 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT0)
89 #define WINED3D_SM4_REGISTER_ORDER_SHIFT 20
90 #define WINED3D_SM4_REGISTER_ORDER_MASK (0x3u << WINED3D_SM4_REGISTER_ORDER_SHIFT)
92 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
93 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xffu << WINED3D_SM4_REGISTER_TYPE_SHIFT)
95 #define WINED3D_SM4_SWIZZLE_TYPE_SHIFT 2
96 #define WINED3D_SM4_SWIZZLE_TYPE_MASK (0x3u << WINED3D_SM4_SWIZZLE_TYPE_SHIFT)
98 #define WINED3D_SM4_IMMCONST_TYPE_SHIFT 0
99 #define WINED3D_SM4_IMMCONST_TYPE_MASK (0x3u << WINED3D_SM4_IMMCONST_TYPE_SHIFT)
101 #define WINED3D_SM4_WRITEMASK_SHIFT 4
102 #define WINED3D_SM4_WRITEMASK_MASK (0xfu << WINED3D_SM4_WRITEMASK_SHIFT)
104 #define WINED3D_SM4_SWIZZLE_SHIFT 4
105 #define WINED3D_SM4_SWIZZLE_MASK (0xffu << WINED3D_SM4_SWIZZLE_SHIFT)
107 #define WINED3D_SM4_VERSION_MAJOR(version) (((version) >> 4) & 0xf)
108 #define WINED3D_SM4_VERSION_MINOR(version) (((version) >> 0) & 0xf)
110 #define WINED3D_SM4_ADDRESSING_RELATIVE 0x2
111 #define WINED3D_SM4_ADDRESSING_OFFSET 0x1
113 #define WINED3D_SM4_INSTRUCTION_FLAG_SATURATE 0x4
115 #define WINED3D_SM4_CONDITIONAL_NZ (0x1u << 18)
117 enum wined3d_sm4_opcode
119 WINED3D_SM4_OP_ADD
= 0x00,
120 WINED3D_SM4_OP_AND
= 0x01,
121 WINED3D_SM4_OP_BREAK
= 0x02,
122 WINED3D_SM4_OP_BREAKC
= 0x03,
123 WINED3D_SM4_OP_CASE
= 0x06,
124 WINED3D_SM4_OP_CONTINUE
= 0x07,
125 WINED3D_SM4_OP_CONTINUEC
= 0x08,
126 WINED3D_SM4_OP_CUT
= 0x09,
127 WINED3D_SM4_OP_DEFAULT
= 0x0a,
128 WINED3D_SM4_OP_DERIV_RTX
= 0x0b,
129 WINED3D_SM4_OP_DERIV_RTY
= 0x0c,
130 WINED3D_SM4_OP_DISCARD
= 0x0d,
131 WINED3D_SM4_OP_DIV
= 0x0e,
132 WINED3D_SM4_OP_DP2
= 0x0f,
133 WINED3D_SM4_OP_DP3
= 0x10,
134 WINED3D_SM4_OP_DP4
= 0x11,
135 WINED3D_SM4_OP_ELSE
= 0x12,
136 WINED3D_SM4_OP_EMIT
= 0x13,
137 WINED3D_SM4_OP_ENDIF
= 0x15,
138 WINED3D_SM4_OP_ENDLOOP
= 0x16,
139 WINED3D_SM4_OP_ENDSWITCH
= 0x17,
140 WINED3D_SM4_OP_EQ
= 0x18,
141 WINED3D_SM4_OP_EXP
= 0x19,
142 WINED3D_SM4_OP_FRC
= 0x1a,
143 WINED3D_SM4_OP_FTOI
= 0x1b,
144 WINED3D_SM4_OP_FTOU
= 0x1c,
145 WINED3D_SM4_OP_GE
= 0x1d,
146 WINED3D_SM4_OP_IADD
= 0x1e,
147 WINED3D_SM4_OP_IF
= 0x1f,
148 WINED3D_SM4_OP_IEQ
= 0x20,
149 WINED3D_SM4_OP_IGE
= 0x21,
150 WINED3D_SM4_OP_ILT
= 0x22,
151 WINED3D_SM4_OP_IMAD
= 0x23,
152 WINED3D_SM4_OP_IMAX
= 0x24,
153 WINED3D_SM4_OP_IMIN
= 0x25,
154 WINED3D_SM4_OP_IMUL
= 0x26,
155 WINED3D_SM4_OP_INE
= 0x27,
156 WINED3D_SM4_OP_INEG
= 0x28,
157 WINED3D_SM4_OP_ISHL
= 0x29,
158 WINED3D_SM4_OP_ISHR
= 0x2a,
159 WINED3D_SM4_OP_ITOF
= 0x2b,
160 WINED3D_SM4_OP_LABEL
= 0x2c,
161 WINED3D_SM4_OP_LD
= 0x2d,
162 WINED3D_SM4_OP_LD2DMS
= 0x2e,
163 WINED3D_SM4_OP_LOG
= 0x2f,
164 WINED3D_SM4_OP_LOOP
= 0x30,
165 WINED3D_SM4_OP_LT
= 0x31,
166 WINED3D_SM4_OP_MAD
= 0x32,
167 WINED3D_SM4_OP_MIN
= 0x33,
168 WINED3D_SM4_OP_MAX
= 0x34,
169 WINED3D_SM4_OP_SHADER_DATA
= 0x35,
170 WINED3D_SM4_OP_MOV
= 0x36,
171 WINED3D_SM4_OP_MOVC
= 0x37,
172 WINED3D_SM4_OP_MUL
= 0x38,
173 WINED3D_SM4_OP_NE
= 0x39,
174 WINED3D_SM4_OP_NOT
= 0x3b,
175 WINED3D_SM4_OP_OR
= 0x3c,
176 WINED3D_SM4_OP_RESINFO
= 0x3d,
177 WINED3D_SM4_OP_RET
= 0x3e,
178 WINED3D_SM4_OP_RETC
= 0x3f,
179 WINED3D_SM4_OP_ROUND_NE
= 0x40,
180 WINED3D_SM4_OP_ROUND_NI
= 0x41,
181 WINED3D_SM4_OP_ROUND_PI
= 0x42,
182 WINED3D_SM4_OP_ROUND_Z
= 0x43,
183 WINED3D_SM4_OP_RSQ
= 0x44,
184 WINED3D_SM4_OP_SAMPLE
= 0x45,
185 WINED3D_SM4_OP_SAMPLE_C
= 0x46,
186 WINED3D_SM4_OP_SAMPLE_C_LZ
= 0x47,
187 WINED3D_SM4_OP_SAMPLE_LOD
= 0x48,
188 WINED3D_SM4_OP_SAMPLE_GRAD
= 0x49,
189 WINED3D_SM4_OP_SAMPLE_B
= 0x4a,
190 WINED3D_SM4_OP_SQRT
= 0x4b,
191 WINED3D_SM4_OP_SWITCH
= 0x4c,
192 WINED3D_SM4_OP_SINCOS
= 0x4d,
193 WINED3D_SM4_OP_UDIV
= 0x4e,
194 WINED3D_SM4_OP_ULT
= 0x4f,
195 WINED3D_SM4_OP_UGE
= 0x50,
196 WINED3D_SM4_OP_UMUL
= 0x51,
197 WINED3D_SM4_OP_UMAX
= 0x53,
198 WINED3D_SM4_OP_UMIN
= 0x54,
199 WINED3D_SM4_OP_USHR
= 0x55,
200 WINED3D_SM4_OP_UTOF
= 0x56,
201 WINED3D_SM4_OP_XOR
= 0x57,
202 WINED3D_SM4_OP_DCL_RESOURCE
= 0x58,
203 WINED3D_SM4_OP_DCL_CONSTANT_BUFFER
= 0x59,
204 WINED3D_SM4_OP_DCL_SAMPLER
= 0x5a,
205 WINED3D_SM4_OP_DCL_INDEX_RANGE
= 0x5b,
206 WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY
= 0x5c,
207 WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE
= 0x5d,
208 WINED3D_SM4_OP_DCL_VERTICES_OUT
= 0x5e,
209 WINED3D_SM4_OP_DCL_INPUT
= 0x5f,
210 WINED3D_SM4_OP_DCL_INPUT_SGV
= 0x60,
211 WINED3D_SM4_OP_DCL_INPUT_SIV
= 0x61,
212 WINED3D_SM4_OP_DCL_INPUT_PS
= 0x62,
213 WINED3D_SM4_OP_DCL_INPUT_PS_SGV
= 0x63,
214 WINED3D_SM4_OP_DCL_INPUT_PS_SIV
= 0x64,
215 WINED3D_SM4_OP_DCL_OUTPUT
= 0x65,
216 WINED3D_SM4_OP_DCL_OUTPUT_SIV
= 0x67,
217 WINED3D_SM4_OP_DCL_TEMPS
= 0x68,
218 WINED3D_SM4_OP_DCL_INDEXABLE_TEMP
= 0x69,
219 WINED3D_SM4_OP_DCL_GLOBAL_FLAGS
= 0x6a,
220 WINED3D_SM4_OP_LOD
= 0x6c,
221 WINED3D_SM4_OP_GATHER4
= 0x6d,
222 WINED3D_SM4_OP_SAMPLE_POS
= 0x6e,
223 WINED3D_SM4_OP_SAMPLE_INFO
= 0x6f,
224 WINED3D_SM5_OP_HS_DECLS
= 0x71,
225 WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE
= 0x72,
226 WINED3D_SM5_OP_HS_FORK_PHASE
= 0x73,
227 WINED3D_SM5_OP_HS_JOIN_PHASE
= 0x74,
228 WINED3D_SM5_OP_EMIT_STREAM
= 0x75,
229 WINED3D_SM5_OP_CUT_STREAM
= 0x76,
230 WINED3D_SM5_OP_FCALL
= 0x78,
231 WINED3D_SM5_OP_BUFINFO
= 0x79,
232 WINED3D_SM5_OP_DERIV_RTX_COARSE
= 0x7a,
233 WINED3D_SM5_OP_DERIV_RTX_FINE
= 0x7b,
234 WINED3D_SM5_OP_DERIV_RTY_COARSE
= 0x7c,
235 WINED3D_SM5_OP_DERIV_RTY_FINE
= 0x7d,
236 WINED3D_SM5_OP_GATHER4_C
= 0x7e,
237 WINED3D_SM5_OP_GATHER4_PO
= 0x7f,
238 WINED3D_SM5_OP_GATHER4_PO_C
= 0x80,
239 WINED3D_SM5_OP_RCP
= 0x81,
240 WINED3D_SM5_OP_F32TOF16
= 0x82,
241 WINED3D_SM5_OP_F16TOF32
= 0x83,
242 WINED3D_SM5_OP_COUNTBITS
= 0x86,
243 WINED3D_SM5_OP_FIRSTBIT_HI
= 0x87,
244 WINED3D_SM5_OP_FIRSTBIT_LO
= 0x88,
245 WINED3D_SM5_OP_FIRSTBIT_SHI
= 0x89,
246 WINED3D_SM5_OP_UBFE
= 0x8a,
247 WINED3D_SM5_OP_IBFE
= 0x8b,
248 WINED3D_SM5_OP_BFI
= 0x8c,
249 WINED3D_SM5_OP_BFREV
= 0x8d,
250 WINED3D_SM5_OP_SWAPC
= 0x8e,
251 WINED3D_SM5_OP_DCL_STREAM
= 0x8f,
252 WINED3D_SM5_OP_DCL_FUNCTION_BODY
= 0x90,
253 WINED3D_SM5_OP_DCL_FUNCTION_TABLE
= 0x91,
254 WINED3D_SM5_OP_DCL_INTERFACE
= 0x92,
255 WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT
= 0x93,
256 WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT
= 0x94,
257 WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN
= 0x95,
258 WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING
= 0x96,
259 WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
= 0x97,
260 WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR
= 0x98,
261 WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT
= 0x99,
262 WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
= 0x9a,
263 WINED3D_SM5_OP_DCL_THREAD_GROUP
= 0x9b,
264 WINED3D_SM5_OP_DCL_UAV_TYPED
= 0x9c,
265 WINED3D_SM5_OP_DCL_UAV_RAW
= 0x9d,
266 WINED3D_SM5_OP_DCL_UAV_STRUCTURED
= 0x9e,
267 WINED3D_SM5_OP_DCL_TGSM_RAW
= 0x9f,
268 WINED3D_SM5_OP_DCL_TGSM_STRUCTURED
= 0xa0,
269 WINED3D_SM5_OP_DCL_RESOURCE_RAW
= 0xa1,
270 WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED
= 0xa2,
271 WINED3D_SM5_OP_LD_UAV_TYPED
= 0xa3,
272 WINED3D_SM5_OP_STORE_UAV_TYPED
= 0xa4,
273 WINED3D_SM5_OP_LD_RAW
= 0xa5,
274 WINED3D_SM5_OP_STORE_RAW
= 0xa6,
275 WINED3D_SM5_OP_LD_STRUCTURED
= 0xa7,
276 WINED3D_SM5_OP_STORE_STRUCTURED
= 0xa8,
277 WINED3D_SM5_OP_ATOMIC_AND
= 0xa9,
278 WINED3D_SM5_OP_ATOMIC_OR
= 0xaa,
279 WINED3D_SM5_OP_ATOMIC_XOR
= 0xab,
280 WINED3D_SM5_OP_ATOMIC_CMP_STORE
= 0xac,
281 WINED3D_SM5_OP_ATOMIC_IADD
= 0xad,
282 WINED3D_SM5_OP_ATOMIC_IMAX
= 0xae,
283 WINED3D_SM5_OP_ATOMIC_IMIN
= 0xaf,
284 WINED3D_SM5_OP_ATOMIC_UMAX
= 0xb0,
285 WINED3D_SM5_OP_ATOMIC_UMIN
= 0xb1,
286 WINED3D_SM5_OP_IMM_ATOMIC_ALLOC
= 0xb2,
287 WINED3D_SM5_OP_IMM_ATOMIC_CONSUME
= 0xb3,
288 WINED3D_SM5_OP_IMM_ATOMIC_IADD
= 0xb4,
289 WINED3D_SM5_OP_IMM_ATOMIC_AND
= 0xb5,
290 WINED3D_SM5_OP_IMM_ATOMIC_OR
= 0xb6,
291 WINED3D_SM5_OP_IMM_ATOMIC_XOR
= 0xb7,
292 WINED3D_SM5_OP_IMM_ATOMIC_EXCH
= 0xb8,
293 WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH
= 0xb9,
294 WINED3D_SM5_OP_IMM_ATOMIC_IMAX
= 0xba,
295 WINED3D_SM5_OP_IMM_ATOMIC_IMIN
= 0xbb,
296 WINED3D_SM5_OP_IMM_ATOMIC_UMAX
= 0xbc,
297 WINED3D_SM5_OP_IMM_ATOMIC_UMIN
= 0xbd,
298 WINED3D_SM5_OP_SYNC
= 0xbe,
299 WINED3D_SM5_OP_DCL_GS_INSTANCES
= 0xce,
302 enum wined3d_sm4_register_type
304 WINED3D_SM4_RT_TEMP
= 0x00,
305 WINED3D_SM4_RT_INPUT
= 0x01,
306 WINED3D_SM4_RT_OUTPUT
= 0x02,
307 WINED3D_SM4_RT_INDEXABLE_TEMP
= 0x03,
308 WINED3D_SM4_RT_IMMCONST
= 0x04,
309 WINED3D_SM4_RT_SAMPLER
= 0x06,
310 WINED3D_SM4_RT_RESOURCE
= 0x07,
311 WINED3D_SM4_RT_CONSTBUFFER
= 0x08,
312 WINED3D_SM4_RT_IMMCONSTBUFFER
= 0x09,
313 WINED3D_SM4_RT_PRIMID
= 0x0b,
314 WINED3D_SM4_RT_DEPTHOUT
= 0x0c,
315 WINED3D_SM4_RT_NULL
= 0x0d,
316 WINED3D_SM4_RT_OMASK
= 0x0f,
317 WINED3D_SM5_RT_STREAM
= 0x10,
318 WINED3D_SM5_RT_FUNCTION_BODY
= 0x11,
319 WINED3D_SM5_RT_FUNCTION_POINTER
= 0x13,
320 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID
= 0x16,
321 WINED3D_SM5_RT_FORK_INSTANCE_ID
= 0x17,
322 WINED3D_SM5_RT_JOIN_INSTANCE_ID
= 0x18,
323 WINED3D_SM5_RT_INPUT_CONTROL_POINT
= 0x19,
324 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT
= 0x1a,
325 WINED3D_SM5_RT_PATCH_CONSTANT_DATA
= 0x1b,
326 WINED3D_SM5_RT_DOMAIN_LOCATION
= 0x1c,
327 WINED3D_SM5_RT_UAV
= 0x1e,
328 WINED3D_SM5_RT_SHARED_MEMORY
= 0x1f,
329 WINED3D_SM5_RT_THREAD_ID
= 0x20,
330 WINED3D_SM5_RT_THREAD_GROUP_ID
= 0x21,
331 WINED3D_SM5_RT_LOCAL_THREAD_ID
= 0x22,
332 WINED3D_SM5_RT_COVERAGE
= 0x23,
333 WINED3D_SM5_RT_LOCAL_THREAD_INDEX
= 0x24,
334 WINED3D_SM5_RT_GS_INSTANCE_ID
= 0x25,
337 enum wined3d_sm4_output_primitive_type
339 WINED3D_SM4_OUTPUT_PT_POINTLIST
= 0x1,
340 WINED3D_SM4_OUTPUT_PT_LINELIST
= 0x3,
341 WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP
= 0x5,
344 enum wined3d_sm4_input_primitive_type
346 WINED3D_SM4_INPUT_PT_POINT
= 0x01,
347 WINED3D_SM4_INPUT_PT_LINE
= 0x02,
348 WINED3D_SM4_INPUT_PT_TRIANGLE
= 0x03,
349 WINED3D_SM4_INPUT_PT_LINEADJ
= 0x06,
350 WINED3D_SM4_INPUT_PT_TRIANGLEADJ
= 0x07,
351 WINED3D_SM5_INPUT_PT_PATCH1
= 0x08,
352 WINED3D_SM5_INPUT_PT_PATCH2
= 0x09,
353 WINED3D_SM5_INPUT_PT_PATCH3
= 0x0a,
354 WINED3D_SM5_INPUT_PT_PATCH4
= 0x0b,
355 WINED3D_SM5_INPUT_PT_PATCH5
= 0x0c,
356 WINED3D_SM5_INPUT_PT_PATCH6
= 0x0d,
357 WINED3D_SM5_INPUT_PT_PATCH7
= 0x0e,
358 WINED3D_SM5_INPUT_PT_PATCH8
= 0x0f,
359 WINED3D_SM5_INPUT_PT_PATCH9
= 0x10,
360 WINED3D_SM5_INPUT_PT_PATCH10
= 0x11,
361 WINED3D_SM5_INPUT_PT_PATCH11
= 0x12,
362 WINED3D_SM5_INPUT_PT_PATCH12
= 0x13,
363 WINED3D_SM5_INPUT_PT_PATCH13
= 0x14,
364 WINED3D_SM5_INPUT_PT_PATCH14
= 0x15,
365 WINED3D_SM5_INPUT_PT_PATCH15
= 0x16,
366 WINED3D_SM5_INPUT_PT_PATCH16
= 0x17,
367 WINED3D_SM5_INPUT_PT_PATCH17
= 0x18,
368 WINED3D_SM5_INPUT_PT_PATCH18
= 0x19,
369 WINED3D_SM5_INPUT_PT_PATCH19
= 0x1a,
370 WINED3D_SM5_INPUT_PT_PATCH20
= 0x1b,
371 WINED3D_SM5_INPUT_PT_PATCH21
= 0x1c,
372 WINED3D_SM5_INPUT_PT_PATCH22
= 0x1d,
373 WINED3D_SM5_INPUT_PT_PATCH23
= 0x1e,
374 WINED3D_SM5_INPUT_PT_PATCH24
= 0x1f,
375 WINED3D_SM5_INPUT_PT_PATCH25
= 0x20,
376 WINED3D_SM5_INPUT_PT_PATCH26
= 0x21,
377 WINED3D_SM5_INPUT_PT_PATCH27
= 0x22,
378 WINED3D_SM5_INPUT_PT_PATCH28
= 0x23,
379 WINED3D_SM5_INPUT_PT_PATCH29
= 0x24,
380 WINED3D_SM5_INPUT_PT_PATCH30
= 0x25,
381 WINED3D_SM5_INPUT_PT_PATCH31
= 0x26,
382 WINED3D_SM5_INPUT_PT_PATCH32
= 0x27,
385 enum wined3d_sm4_swizzle_type
387 WINED3D_SM4_SWIZZLE_NONE
= 0x0,
388 WINED3D_SM4_SWIZZLE_VEC4
= 0x1,
389 WINED3D_SM4_SWIZZLE_SCALAR
= 0x2,
392 enum wined3d_sm4_immconst_type
394 WINED3D_SM4_IMMCONST_SCALAR
= 0x1,
395 WINED3D_SM4_IMMCONST_VEC4
= 0x2,
398 enum wined3d_sm4_resource_type
400 WINED3D_SM4_RESOURCE_BUFFER
= 0x1,
401 WINED3D_SM4_RESOURCE_TEXTURE_1D
= 0x2,
402 WINED3D_SM4_RESOURCE_TEXTURE_2D
= 0x3,
403 WINED3D_SM4_RESOURCE_TEXTURE_2DMS
= 0x4,
404 WINED3D_SM4_RESOURCE_TEXTURE_3D
= 0x5,
405 WINED3D_SM4_RESOURCE_TEXTURE_CUBE
= 0x6,
406 WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY
= 0x7,
407 WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY
= 0x8,
408 WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY
= 0x9,
409 WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY
= 0xa,
412 enum wined3d_sm4_data_type
414 WINED3D_SM4_DATA_UNORM
= 0x1,
415 WINED3D_SM4_DATA_SNORM
= 0x2,
416 WINED3D_SM4_DATA_INT
= 0x3,
417 WINED3D_SM4_DATA_UINT
= 0x4,
418 WINED3D_SM4_DATA_FLOAT
= 0x5,
421 enum wined3d_sm4_sampler_mode
423 WINED3D_SM4_SAMPLER_DEFAULT
= 0x0,
424 WINED3D_SM4_SAMPLER_COMPARISON
= 0x1,
427 enum wined3d_sm4_shader_data_type
429 WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER
= 0x3,
430 WINED3D_SM4_SHADER_DATA_MESSAGE
= 0x4,
433 struct wined3d_shader_src_param_entry
436 struct wined3d_shader_src_param param
;
439 struct wined3d_sm4_data
441 struct wined3d_shader_version shader_version
;
442 const DWORD
*start
, *end
;
444 unsigned int output_map
[MAX_REG_OUTPUT
];
446 struct wined3d_shader_src_param src_param
[5];
447 struct wined3d_shader_dst_param dst_param
[2];
448 struct list src_free
;
450 struct wined3d_shader_immediate_constant_buffer icb
;
453 struct wined3d_sm4_opcode_info
455 enum wined3d_sm4_opcode opcode
;
456 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
;
457 const char *dst_info
;
458 const char *src_info
;
459 void (*read_opcode_func
)(struct wined3d_shader_instruction
*ins
,
460 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
461 struct wined3d_sm4_data
*priv
);
464 static const enum wined3d_primitive_type output_primitive_type_table
[] =
466 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
467 /* WINED3D_SM4_OUTPUT_PT_POINTLIST */ WINED3D_PT_POINTLIST
,
468 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
469 /* WINED3D_SM4_OUTPUT_PT_LINELIST */ WINED3D_PT_LINELIST
,
470 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
471 /* WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP */ WINED3D_PT_TRIANGLESTRIP
,
474 static const enum wined3d_primitive_type input_primitive_type_table
[] =
476 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
477 /* WINED3D_SM4_INPUT_PT_POINT */ WINED3D_PT_POINTLIST
,
478 /* WINED3D_SM4_INPUT_PT_LINE */ WINED3D_PT_LINELIST
,
479 /* WINED3D_SM4_INPUT_PT_TRIANGLE */ WINED3D_PT_TRIANGLELIST
,
480 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
481 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
482 /* WINED3D_SM4_INPUT_PT_LINEADJ */ WINED3D_PT_LINELIST_ADJ
,
483 /* WINED3D_SM4_INPUT_PT_TRIANGLEADJ */ WINED3D_PT_TRIANGLELIST_ADJ
,
486 static const enum wined3d_shader_resource_type resource_type_table
[] =
488 /* 0 */ WINED3D_SHADER_RESOURCE_NONE
,
489 /* WINED3D_SM4_RESOURCE_BUFFER */ WINED3D_SHADER_RESOURCE_BUFFER
,
490 /* WINED3D_SM4_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D
,
491 /* WINED3D_SM4_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D
,
492 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMS */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
,
493 /* WINED3D_SM4_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D
,
494 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
,
495 /* WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
,
496 /* WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
,
497 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
,
498 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
,
501 static const enum wined3d_data_type data_type_table
[] =
503 /* 0 */ WINED3D_DATA_FLOAT
,
504 /* WINED3D_SM4_DATA_UNORM */ WINED3D_DATA_UNORM
,
505 /* WINED3D_SM4_DATA_SNORM */ WINED3D_DATA_SNORM
,
506 /* WINED3D_SM4_DATA_INT */ WINED3D_DATA_INT
,
507 /* WINED3D_SM4_DATA_UINT */ WINED3D_DATA_UINT
,
508 /* WINED3D_SM4_DATA_FLOAT */ WINED3D_DATA_FLOAT
,
511 static BOOL
shader_sm4_read_src_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
512 enum wined3d_data_type data_type
, struct wined3d_shader_src_param
*src_param
);
513 static BOOL
shader_sm4_read_dst_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
514 enum wined3d_data_type data_type
, struct wined3d_shader_dst_param
*dst_param
);
516 static void shader_sm4_read_conditional_op(struct wined3d_shader_instruction
*ins
,
517 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
518 struct wined3d_sm4_data
*priv
)
520 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UINT
, &priv
->src_param
[0]);
521 ins
->flags
= (opcode_token
& WINED3D_SM4_CONDITIONAL_NZ
) ?
522 WINED3D_SHADER_CONDITIONAL_OP_NZ
: WINED3D_SHADER_CONDITIONAL_OP_Z
;
525 static void shader_sm4_read_shader_data(struct wined3d_shader_instruction
*ins
,
526 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
527 struct wined3d_sm4_data
*priv
)
529 enum wined3d_sm4_shader_data_type type
;
530 unsigned int icb_size
;
532 type
= (opcode_token
& WINED3D_SM4_SHADER_DATA_TYPE_MASK
) >> WINED3D_SM4_SHADER_DATA_TYPE_SHIFT
;
533 if (type
!= WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER
)
535 FIXME("Ignoring shader data type %#x.\n", type
);
536 ins
->handler_idx
= WINED3DSIH_NOP
;
541 icb_size
= token_count
- 1;
542 if (icb_size
% 4 || icb_size
> MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE
)
544 FIXME("Unexpected immediate constant buffer size %u.\n", icb_size
);
545 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
549 priv
->icb
.vec4_count
= icb_size
/ 4;
550 memcpy(priv
->icb
.data
, tokens
, sizeof(*tokens
) * icb_size
);
551 ins
->declaration
.icb
= &priv
->icb
;
554 static void shader_sm4_read_dcl_resource(struct wined3d_shader_instruction
*ins
,
555 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
556 struct wined3d_sm4_data
*priv
)
558 enum wined3d_sm4_resource_type resource_type
;
559 enum wined3d_sm4_data_type data_type
;
560 enum wined3d_data_type reg_data_type
;
563 resource_type
= (opcode_token
& WINED3D_SM4_RESOURCE_TYPE_MASK
) >> WINED3D_SM4_RESOURCE_TYPE_SHIFT
;
564 if (!resource_type
|| (resource_type
>= ARRAY_SIZE(resource_type_table
)))
566 FIXME("Unhandled resource type %#x.\n", resource_type
);
567 ins
->declaration
.semantic
.resource_type
= WINED3D_SHADER_RESOURCE_NONE
;
571 ins
->declaration
.semantic
.resource_type
= resource_type_table
[resource_type
];
573 reg_data_type
= opcode
== WINED3D_SM4_OP_DCL_RESOURCE
? WINED3D_DATA_RESOURCE
: WINED3D_DATA_UAV
;
574 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], reg_data_type
, &ins
->declaration
.semantic
.reg
);
576 components
= *tokens
++;
577 if ((components
& 0xfff0) != (components
& 0xf) * 0x1110)
578 FIXME("Components (%#x) have different data types.\n", components
);
579 data_type
= components
& 0xf;
581 if (!data_type
|| (data_type
>= ARRAY_SIZE(data_type_table
)))
583 FIXME("Unhandled data type %#x.\n", data_type
);
584 ins
->declaration
.semantic
.resource_data_type
= WINED3D_DATA_FLOAT
;
588 ins
->declaration
.semantic
.resource_data_type
= data_type_table
[data_type
];
591 if (reg_data_type
== WINED3D_DATA_UAV
)
592 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
595 static void shader_sm4_read_dcl_constant_buffer(struct wined3d_shader_instruction
*ins
,
596 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
597 struct wined3d_sm4_data
*priv
)
599 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.src
);
600 if (opcode_token
& WINED3D_SM4_INDEX_TYPE_MASK
)
601 ins
->flags
|= WINED3DSI_INDEXED_DYNAMIC
;
604 static void shader_sm4_read_dcl_sampler(struct wined3d_shader_instruction
*ins
,
605 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
606 struct wined3d_sm4_data
*priv
)
608 ins
->flags
= (opcode_token
& WINED3D_SM4_SAMPLER_MODE_MASK
) >> WINED3D_SM4_SAMPLER_MODE_SHIFT
;
609 if (ins
->flags
& ~WINED3D_SM4_SAMPLER_COMPARISON
)
610 FIXME("Unhandled sampler mode %#x.\n", ins
->flags
);
611 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_SAMPLER
, &ins
->declaration
.dst
);
614 static void shader_sm4_read_dcl_index_range(struct wined3d_shader_instruction
*ins
,
615 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
616 struct wined3d_sm4_data
*priv
)
618 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_OPAQUE
,
619 &ins
->declaration
.index_range
.first_register
);
620 ins
->declaration
.index_range
.last_register
= *tokens
;
623 static void shader_sm4_read_dcl_output_topology(struct wined3d_shader_instruction
*ins
,
624 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
625 struct wined3d_sm4_data
*priv
)
627 enum wined3d_sm4_output_primitive_type primitive_type
;
629 primitive_type
= (opcode_token
& WINED3D_SM4_PRIMITIVE_TYPE_MASK
) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT
;
630 if (primitive_type
>= ARRAY_SIZE(output_primitive_type_table
))
631 ins
->declaration
.primitive_type
.type
= WINED3D_PT_UNDEFINED
;
633 ins
->declaration
.primitive_type
.type
= output_primitive_type_table
[primitive_type
];
635 if (ins
->declaration
.primitive_type
.type
== WINED3D_PT_UNDEFINED
)
636 FIXME("Unhandled output primitive type %#x.\n", primitive_type
);
639 static void shader_sm4_read_dcl_input_primitive(struct wined3d_shader_instruction
*ins
,
640 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
641 struct wined3d_sm4_data
*priv
)
643 enum wined3d_sm4_input_primitive_type primitive_type
;
645 primitive_type
= (opcode_token
& WINED3D_SM4_PRIMITIVE_TYPE_MASK
) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT
;
646 if (WINED3D_SM5_INPUT_PT_PATCH1
<= primitive_type
&& primitive_type
<= WINED3D_SM5_INPUT_PT_PATCH32
)
648 ins
->declaration
.primitive_type
.type
= WINED3D_PT_PATCH
;
649 ins
->declaration
.primitive_type
.patch_vertex_count
= primitive_type
- WINED3D_SM5_INPUT_PT_PATCH1
+ 1;
651 else if (primitive_type
>= ARRAY_SIZE(input_primitive_type_table
))
653 ins
->declaration
.primitive_type
.type
= WINED3D_PT_UNDEFINED
;
657 ins
->declaration
.primitive_type
.type
= input_primitive_type_table
[primitive_type
];
660 if (ins
->declaration
.primitive_type
.type
== WINED3D_PT_UNDEFINED
)
661 FIXME("Unhandled input primitive type %#x.\n", primitive_type
);
664 static void shader_sm4_read_declaration_count(struct wined3d_shader_instruction
*ins
,
665 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
666 struct wined3d_sm4_data
*priv
)
668 ins
->declaration
.count
= *tokens
;
671 static void shader_sm4_read_declaration_dst(struct wined3d_shader_instruction
*ins
,
672 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
673 struct wined3d_sm4_data
*priv
)
675 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.dst
);
678 static void shader_sm4_read_declaration_register_semantic(struct wined3d_shader_instruction
*ins
,
679 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
680 struct wined3d_sm4_data
*priv
)
682 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
,
683 &ins
->declaration
.register_semantic
.reg
);
684 ins
->declaration
.register_semantic
.sysval_semantic
= *tokens
;
687 static void shader_sm4_read_dcl_input_ps(struct wined3d_shader_instruction
*ins
,
688 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
689 struct wined3d_sm4_data
*priv
)
691 ins
->flags
= (opcode_token
& WINED3D_SM4_INTERPOLATION_MODE_MASK
) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT
;
692 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.dst
);
695 static void shader_sm4_read_dcl_input_ps_siv(struct wined3d_shader_instruction
*ins
,
696 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
697 struct wined3d_sm4_data
*priv
)
699 ins
->flags
= (opcode_token
& WINED3D_SM4_INTERPOLATION_MODE_MASK
) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT
;
700 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
,
701 &ins
->declaration
.register_semantic
.reg
);
702 ins
->declaration
.register_semantic
.sysval_semantic
= *tokens
;
705 static void shader_sm4_read_dcl_indexable_temp(struct wined3d_shader_instruction
*ins
,
706 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
707 struct wined3d_sm4_data
*priv
)
709 ins
->declaration
.indexable_temp
.register_idx
= *tokens
++;
710 ins
->declaration
.indexable_temp
.register_size
= *tokens
++;
711 ins
->declaration
.indexable_temp
.component_count
= *tokens
;
714 static void shader_sm4_read_dcl_global_flags(struct wined3d_shader_instruction
*ins
,
715 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
716 struct wined3d_sm4_data
*priv
)
718 ins
->flags
= (opcode_token
& WINED3D_SM4_GLOBAL_FLAGS_MASK
) >> WINED3D_SM4_GLOBAL_FLAGS_SHIFT
;
721 static void shader_sm5_read_fcall(struct wined3d_shader_instruction
*ins
,
722 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
723 struct wined3d_sm4_data
*priv
)
725 priv
->src_param
[0].reg
.u
.fp_body_idx
= *tokens
++;
726 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_OPAQUE
, &priv
->src_param
[0]);
729 static void shader_sm5_read_dcl_function_body(struct wined3d_shader_instruction
*ins
,
730 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
731 struct wined3d_sm4_data
*priv
)
733 ins
->declaration
.index
= *tokens
;
736 static void shader_sm5_read_dcl_function_table(struct wined3d_shader_instruction
*ins
,
737 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
738 struct wined3d_sm4_data
*priv
)
740 ins
->declaration
.index
= *tokens
++;
741 FIXME("Ignoring set of function bodies (count %u).\n", *tokens
);
744 static void shader_sm5_read_dcl_interface(struct wined3d_shader_instruction
*ins
,
745 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
746 struct wined3d_sm4_data
*priv
)
748 ins
->declaration
.fp
.index
= *tokens
++;
749 ins
->declaration
.fp
.body_count
= *tokens
++;
750 ins
->declaration
.fp
.array_size
= *tokens
>> WINED3D_SM5_FP_ARRAY_SIZE_SHIFT
;
751 ins
->declaration
.fp
.table_count
= *tokens
++ & WINED3D_SM5_FP_TABLE_COUNT_MASK
;
752 FIXME("Ignoring set of function tables (count %u).\n", ins
->declaration
.fp
.table_count
);
755 static void shader_sm5_read_control_point_count(struct wined3d_shader_instruction
*ins
,
756 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
757 struct wined3d_sm4_data
*priv
)
759 ins
->declaration
.count
= (opcode_token
& WINED3D_SM5_CONTROL_POINT_COUNT_MASK
)
760 >> WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT
;
763 static void shader_sm5_read_dcl_tessellator_domain(struct wined3d_shader_instruction
*ins
,
764 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
765 struct wined3d_sm4_data
*priv
)
767 ins
->declaration
.tessellator_domain
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
768 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
771 static void shader_sm5_read_dcl_tessellator_partitioning(struct wined3d_shader_instruction
*ins
,
772 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
773 struct wined3d_sm4_data
*priv
)
775 ins
->declaration
.tessellator_partitioning
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
776 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
779 static void shader_sm5_read_dcl_tessellator_output_primitive(struct wined3d_shader_instruction
*ins
,
780 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
781 struct wined3d_sm4_data
*priv
)
783 ins
->declaration
.tessellator_output_primitive
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
784 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
787 static void shader_sm5_read_dcl_hs_max_tessfactor(struct wined3d_shader_instruction
*ins
,
788 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
789 struct wined3d_sm4_data
*priv
)
791 ins
->declaration
.max_tessellation_factor
= *(float *)tokens
;
794 static void shader_sm5_read_dcl_thread_group(struct wined3d_shader_instruction
*ins
,
795 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
796 struct wined3d_sm4_data
*priv
)
798 ins
->declaration
.thread_group_size
.x
= *tokens
++;
799 ins
->declaration
.thread_group_size
.y
= *tokens
++;
800 ins
->declaration
.thread_group_size
.z
= *tokens
++;
803 static void shader_sm5_read_dcl_uav_raw(struct wined3d_shader_instruction
*ins
,
804 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
805 struct wined3d_sm4_data
*priv
)
807 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UAV
, &ins
->declaration
.dst
);
808 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
811 static void shader_sm5_read_dcl_uav_structured(struct wined3d_shader_instruction
*ins
,
812 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
813 struct wined3d_sm4_data
*priv
)
815 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UAV
,
816 &ins
->declaration
.structured_resource
.reg
);
817 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
818 ins
->declaration
.structured_resource
.byte_stride
= *tokens
;
819 if (ins
->declaration
.structured_resource
.byte_stride
% 4)
820 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.structured_resource
.byte_stride
);
823 static void shader_sm5_read_dcl_tgsm_raw(struct wined3d_shader_instruction
*ins
,
824 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
825 struct wined3d_sm4_data
*priv
)
827 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.tgsm_raw
.reg
);
828 ins
->declaration
.tgsm_raw
.byte_count
= *tokens
;
829 if (ins
->declaration
.tgsm_raw
.byte_count
% 4)
830 FIXME("Byte count %u is not multiple of 4.\n", ins
->declaration
.tgsm_raw
.byte_count
);
833 static void shader_sm5_read_dcl_tgsm_structured(struct wined3d_shader_instruction
*ins
,
834 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
835 struct wined3d_sm4_data
*priv
)
837 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
,
838 &ins
->declaration
.tgsm_structured
.reg
);
839 ins
->declaration
.tgsm_structured
.byte_stride
= *tokens
++;
840 ins
->declaration
.tgsm_structured
.structure_count
= *tokens
;
841 if (ins
->declaration
.tgsm_structured
.byte_stride
% 4)
842 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.tgsm_structured
.byte_stride
);
845 static void shader_sm5_read_dcl_resource_structured(struct wined3d_shader_instruction
*ins
,
846 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
847 struct wined3d_sm4_data
*priv
)
849 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_RESOURCE
,
850 &ins
->declaration
.structured_resource
.reg
);
851 ins
->declaration
.structured_resource
.byte_stride
= *tokens
;
852 if (ins
->declaration
.structured_resource
.byte_stride
% 4)
853 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.structured_resource
.byte_stride
);
856 static void shader_sm5_read_dcl_resource_raw(struct wined3d_shader_instruction
*ins
,
857 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
858 struct wined3d_sm4_data
*priv
)
860 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_RESOURCE
, &ins
->declaration
.dst
);
863 static void shader_sm5_read_sync(struct wined3d_shader_instruction
*ins
,
864 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
865 struct wined3d_sm4_data
*priv
)
867 ins
->flags
= (opcode_token
& WINED3D_SM5_SYNC_FLAGS_MASK
) >> WINED3D_SM5_SYNC_FLAGS_SHIFT
;
871 * f -> WINED3D_DATA_FLOAT
872 * i -> WINED3D_DATA_INT
873 * u -> WINED3D_DATA_UINT
874 * O -> WINED3D_DATA_OPAQUE
875 * R -> WINED3D_DATA_RESOURCE
876 * S -> WINED3D_DATA_SAMPLER
877 * U -> WINED3D_DATA_UAV
879 static const struct wined3d_sm4_opcode_info opcode_table
[] =
881 {WINED3D_SM4_OP_ADD
, WINED3DSIH_ADD
, "f", "ff"},
882 {WINED3D_SM4_OP_AND
, WINED3DSIH_AND
, "u", "uu"},
883 {WINED3D_SM4_OP_BREAK
, WINED3DSIH_BREAK
, "", ""},
884 {WINED3D_SM4_OP_BREAKC
, WINED3DSIH_BREAKP
, "", "u",
885 shader_sm4_read_conditional_op
},
886 {WINED3D_SM4_OP_CASE
, WINED3DSIH_CASE
, "", "u"},
887 {WINED3D_SM4_OP_CONTINUE
, WINED3DSIH_CONTINUE
, "", ""},
888 {WINED3D_SM4_OP_CONTINUEC
, WINED3DSIH_CONTINUEP
, "", "u",
889 shader_sm4_read_conditional_op
},
890 {WINED3D_SM4_OP_CUT
, WINED3DSIH_CUT
, "", ""},
891 {WINED3D_SM4_OP_DEFAULT
, WINED3DSIH_DEFAULT
, "", ""},
892 {WINED3D_SM4_OP_DERIV_RTX
, WINED3DSIH_DSX
, "f", "f"},
893 {WINED3D_SM4_OP_DERIV_RTY
, WINED3DSIH_DSY
, "f", "f"},
894 {WINED3D_SM4_OP_DISCARD
, WINED3DSIH_TEXKILL
, "", "u"},
895 {WINED3D_SM4_OP_DIV
, WINED3DSIH_DIV
, "f", "ff"},
896 {WINED3D_SM4_OP_DP2
, WINED3DSIH_DP2
, "f", "ff"},
897 {WINED3D_SM4_OP_DP3
, WINED3DSIH_DP3
, "f", "ff"},
898 {WINED3D_SM4_OP_DP4
, WINED3DSIH_DP4
, "f", "ff"},
899 {WINED3D_SM4_OP_ELSE
, WINED3DSIH_ELSE
, "", ""},
900 {WINED3D_SM4_OP_EMIT
, WINED3DSIH_EMIT
, "", ""},
901 {WINED3D_SM4_OP_ENDIF
, WINED3DSIH_ENDIF
, "", ""},
902 {WINED3D_SM4_OP_ENDLOOP
, WINED3DSIH_ENDLOOP
, "", ""},
903 {WINED3D_SM4_OP_ENDSWITCH
, WINED3DSIH_ENDSWITCH
, "", ""},
904 {WINED3D_SM4_OP_EQ
, WINED3DSIH_EQ
, "u", "ff"},
905 {WINED3D_SM4_OP_EXP
, WINED3DSIH_EXP
, "f", "f"},
906 {WINED3D_SM4_OP_FRC
, WINED3DSIH_FRC
, "f", "f"},
907 {WINED3D_SM4_OP_FTOI
, WINED3DSIH_FTOI
, "i", "f"},
908 {WINED3D_SM4_OP_FTOU
, WINED3DSIH_FTOU
, "u", "f"},
909 {WINED3D_SM4_OP_GE
, WINED3DSIH_GE
, "u", "ff"},
910 {WINED3D_SM4_OP_IADD
, WINED3DSIH_IADD
, "i", "ii"},
911 {WINED3D_SM4_OP_IF
, WINED3DSIH_IF
, "", "u",
912 shader_sm4_read_conditional_op
},
913 {WINED3D_SM4_OP_IEQ
, WINED3DSIH_IEQ
, "u", "ii"},
914 {WINED3D_SM4_OP_IGE
, WINED3DSIH_IGE
, "u", "ii"},
915 {WINED3D_SM4_OP_ILT
, WINED3DSIH_ILT
, "u", "ii"},
916 {WINED3D_SM4_OP_IMAD
, WINED3DSIH_IMAD
, "i", "iii"},
917 {WINED3D_SM4_OP_IMAX
, WINED3DSIH_IMAX
, "i", "ii"},
918 {WINED3D_SM4_OP_IMIN
, WINED3DSIH_IMIN
, "i", "ii"},
919 {WINED3D_SM4_OP_IMUL
, WINED3DSIH_IMUL
, "ii", "ii"},
920 {WINED3D_SM4_OP_INE
, WINED3DSIH_INE
, "u", "ii"},
921 {WINED3D_SM4_OP_INEG
, WINED3DSIH_INEG
, "i", "i"},
922 {WINED3D_SM4_OP_ISHL
, WINED3DSIH_ISHL
, "i", "ii"},
923 {WINED3D_SM4_OP_ISHR
, WINED3DSIH_ISHR
, "i", "ii"},
924 {WINED3D_SM4_OP_ITOF
, WINED3DSIH_ITOF
, "f", "i"},
925 {WINED3D_SM4_OP_LABEL
, WINED3DSIH_LABEL
, "", "O"},
926 {WINED3D_SM4_OP_LD
, WINED3DSIH_LD
, "u", "iR"},
927 {WINED3D_SM4_OP_LD2DMS
, WINED3DSIH_LD2DMS
, "u", "iRi"},
928 {WINED3D_SM4_OP_LOG
, WINED3DSIH_LOG
, "f", "f"},
929 {WINED3D_SM4_OP_LOOP
, WINED3DSIH_LOOP
, "", ""},
930 {WINED3D_SM4_OP_LT
, WINED3DSIH_LT
, "u", "ff"},
931 {WINED3D_SM4_OP_MAD
, WINED3DSIH_MAD
, "f", "fff"},
932 {WINED3D_SM4_OP_MIN
, WINED3DSIH_MIN
, "f", "ff"},
933 {WINED3D_SM4_OP_MAX
, WINED3DSIH_MAX
, "f", "ff"},
934 {WINED3D_SM4_OP_SHADER_DATA
, WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
, "", "",
935 shader_sm4_read_shader_data
},
936 {WINED3D_SM4_OP_MOV
, WINED3DSIH_MOV
, "f", "f"},
937 {WINED3D_SM4_OP_MOVC
, WINED3DSIH_MOVC
, "f", "uff"},
938 {WINED3D_SM4_OP_MUL
, WINED3DSIH_MUL
, "f", "ff"},
939 {WINED3D_SM4_OP_NE
, WINED3DSIH_NE
, "u", "ff"},
940 {WINED3D_SM4_OP_NOT
, WINED3DSIH_NOT
, "u", "u"},
941 {WINED3D_SM4_OP_OR
, WINED3DSIH_OR
, "u", "uu"},
942 {WINED3D_SM4_OP_RESINFO
, WINED3DSIH_RESINFO
, "f", "iR"},
943 {WINED3D_SM4_OP_RET
, WINED3DSIH_RET
, "", ""},
944 {WINED3D_SM4_OP_RETC
, WINED3DSIH_RETP
, "", "u",
945 shader_sm4_read_conditional_op
},
946 {WINED3D_SM4_OP_ROUND_NE
, WINED3DSIH_ROUND_NE
, "f", "f"},
947 {WINED3D_SM4_OP_ROUND_NI
, WINED3DSIH_ROUND_NI
, "f", "f"},
948 {WINED3D_SM4_OP_ROUND_PI
, WINED3DSIH_ROUND_PI
, "f", "f"},
949 {WINED3D_SM4_OP_ROUND_Z
, WINED3DSIH_ROUND_Z
, "f", "f"},
950 {WINED3D_SM4_OP_RSQ
, WINED3DSIH_RSQ
, "f", "f"},
951 {WINED3D_SM4_OP_SAMPLE
, WINED3DSIH_SAMPLE
, "u", "fRS"},
952 {WINED3D_SM4_OP_SAMPLE_C
, WINED3DSIH_SAMPLE_C
, "f", "fRSf"},
953 {WINED3D_SM4_OP_SAMPLE_C_LZ
, WINED3DSIH_SAMPLE_C_LZ
, "f", "fRSf"},
954 {WINED3D_SM4_OP_SAMPLE_LOD
, WINED3DSIH_SAMPLE_LOD
, "u", "fRSf"},
955 {WINED3D_SM4_OP_SAMPLE_GRAD
, WINED3DSIH_SAMPLE_GRAD
, "u", "fRSff"},
956 {WINED3D_SM4_OP_SAMPLE_B
, WINED3DSIH_SAMPLE_B
, "u", "fRSf"},
957 {WINED3D_SM4_OP_SQRT
, WINED3DSIH_SQRT
, "f", "f"},
958 {WINED3D_SM4_OP_SWITCH
, WINED3DSIH_SWITCH
, "", "u"},
959 {WINED3D_SM4_OP_SINCOS
, WINED3DSIH_SINCOS
, "ff", "f"},
960 {WINED3D_SM4_OP_UDIV
, WINED3DSIH_UDIV
, "uu", "uu"},
961 {WINED3D_SM4_OP_ULT
, WINED3DSIH_ULT
, "u", "uu"},
962 {WINED3D_SM4_OP_UGE
, WINED3DSIH_UGE
, "u", "uu"},
963 {WINED3D_SM4_OP_UMUL
, WINED3DSIH_UMUL
, "uu", "uu"},
964 {WINED3D_SM4_OP_UMAX
, WINED3DSIH_UMAX
, "u", "uu"},
965 {WINED3D_SM4_OP_UMIN
, WINED3DSIH_UMIN
, "u", "uu"},
966 {WINED3D_SM4_OP_USHR
, WINED3DSIH_USHR
, "u", "uu"},
967 {WINED3D_SM4_OP_UTOF
, WINED3DSIH_UTOF
, "f", "u"},
968 {WINED3D_SM4_OP_XOR
, WINED3DSIH_XOR
, "u", "uu"},
969 {WINED3D_SM4_OP_DCL_RESOURCE
, WINED3DSIH_DCL
, "R", "",
970 shader_sm4_read_dcl_resource
},
971 {WINED3D_SM4_OP_DCL_CONSTANT_BUFFER
, WINED3DSIH_DCL_CONSTANT_BUFFER
, "", "",
972 shader_sm4_read_dcl_constant_buffer
},
973 {WINED3D_SM4_OP_DCL_SAMPLER
, WINED3DSIH_DCL_SAMPLER
, "", "",
974 shader_sm4_read_dcl_sampler
},
975 {WINED3D_SM4_OP_DCL_INDEX_RANGE
, WINED3DSIH_DCL_INDEX_RANGE
, "", "",
976 shader_sm4_read_dcl_index_range
},
977 {WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY
, WINED3DSIH_DCL_OUTPUT_TOPOLOGY
, "", "",
978 shader_sm4_read_dcl_output_topology
},
979 {WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE
, WINED3DSIH_DCL_INPUT_PRIMITIVE
, "", "",
980 shader_sm4_read_dcl_input_primitive
},
981 {WINED3D_SM4_OP_DCL_VERTICES_OUT
, WINED3DSIH_DCL_VERTICES_OUT
, "", "",
982 shader_sm4_read_declaration_count
},
983 {WINED3D_SM4_OP_DCL_INPUT
, WINED3DSIH_DCL_INPUT
, "", "",
984 shader_sm4_read_declaration_dst
},
985 {WINED3D_SM4_OP_DCL_INPUT_SGV
, WINED3DSIH_DCL_INPUT_SGV
, "", "",
986 shader_sm4_read_declaration_register_semantic
},
987 {WINED3D_SM4_OP_DCL_INPUT_SIV
, WINED3DSIH_DCL_INPUT_SIV
, "", "",
988 shader_sm4_read_declaration_register_semantic
},
989 {WINED3D_SM4_OP_DCL_INPUT_PS
, WINED3DSIH_DCL_INPUT_PS
, "", "",
990 shader_sm4_read_dcl_input_ps
},
991 {WINED3D_SM4_OP_DCL_INPUT_PS_SGV
, WINED3DSIH_DCL_INPUT_PS_SGV
, "", "",
992 shader_sm4_read_declaration_register_semantic
},
993 {WINED3D_SM4_OP_DCL_INPUT_PS_SIV
, WINED3DSIH_DCL_INPUT_PS_SIV
, "", "",
994 shader_sm4_read_dcl_input_ps_siv
},
995 {WINED3D_SM4_OP_DCL_OUTPUT
, WINED3DSIH_DCL_OUTPUT
, "", "",
996 shader_sm4_read_declaration_dst
},
997 {WINED3D_SM4_OP_DCL_OUTPUT_SIV
, WINED3DSIH_DCL_OUTPUT_SIV
, "", "",
998 shader_sm4_read_declaration_register_semantic
},
999 {WINED3D_SM4_OP_DCL_TEMPS
, WINED3DSIH_DCL_TEMPS
, "", "",
1000 shader_sm4_read_declaration_count
},
1001 {WINED3D_SM4_OP_DCL_INDEXABLE_TEMP
, WINED3DSIH_DCL_INDEXABLE_TEMP
, "", "",
1002 shader_sm4_read_dcl_indexable_temp
},
1003 {WINED3D_SM4_OP_DCL_GLOBAL_FLAGS
, WINED3DSIH_DCL_GLOBAL_FLAGS
, "", "",
1004 shader_sm4_read_dcl_global_flags
},
1005 {WINED3D_SM4_OP_LOD
, WINED3DSIH_LOD
, "f", "fRS"},
1006 {WINED3D_SM4_OP_GATHER4
, WINED3DSIH_GATHER4
, "u", "fRS"},
1007 {WINED3D_SM4_OP_SAMPLE_POS
, WINED3DSIH_SAMPLE_POS
, "f", "Ru"},
1008 {WINED3D_SM4_OP_SAMPLE_INFO
, WINED3DSIH_SAMPLE_INFO
, "f", "R"},
1009 {WINED3D_SM5_OP_HS_DECLS
, WINED3DSIH_HS_DECLS
, "", ""},
1010 {WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE
, WINED3DSIH_HS_CONTROL_POINT_PHASE
, "", ""},
1011 {WINED3D_SM5_OP_HS_FORK_PHASE
, WINED3DSIH_HS_FORK_PHASE
, "", ""},
1012 {WINED3D_SM5_OP_HS_JOIN_PHASE
, WINED3DSIH_HS_JOIN_PHASE
, "", ""},
1013 {WINED3D_SM5_OP_EMIT_STREAM
, WINED3DSIH_EMIT_STREAM
, "", "f"},
1014 {WINED3D_SM5_OP_CUT_STREAM
, WINED3DSIH_CUT_STREAM
, "", "f"},
1015 {WINED3D_SM5_OP_FCALL
, WINED3DSIH_FCALL
, "", "O",
1016 shader_sm5_read_fcall
},
1017 {WINED3D_SM5_OP_BUFINFO
, WINED3DSIH_BUFINFO
, "i", "U"},
1018 {WINED3D_SM5_OP_DERIV_RTX_COARSE
, WINED3DSIH_DSX_COARSE
, "f", "f"},
1019 {WINED3D_SM5_OP_DERIV_RTX_FINE
, WINED3DSIH_DSX_FINE
, "f", "f"},
1020 {WINED3D_SM5_OP_DERIV_RTY_COARSE
, WINED3DSIH_DSY_COARSE
, "f", "f"},
1021 {WINED3D_SM5_OP_DERIV_RTY_FINE
, WINED3DSIH_DSY_FINE
, "f", "f"},
1022 {WINED3D_SM5_OP_GATHER4_C
, WINED3DSIH_GATHER4_C
, "f", "fRSf"},
1023 {WINED3D_SM5_OP_GATHER4_PO
, WINED3DSIH_GATHER4_PO
, "f", "fiRS"},
1024 {WINED3D_SM5_OP_GATHER4_PO_C
, WINED3DSIH_GATHER4_PO_C
, "f", "fiRSf"},
1025 {WINED3D_SM5_OP_RCP
, WINED3DSIH_RCP
, "f", "f"},
1026 {WINED3D_SM5_OP_F32TOF16
, WINED3DSIH_F32TOF16
, "u", "f"},
1027 {WINED3D_SM5_OP_F16TOF32
, WINED3DSIH_F16TOF32
, "f", "u"},
1028 {WINED3D_SM5_OP_COUNTBITS
, WINED3DSIH_COUNTBITS
, "u", "u"},
1029 {WINED3D_SM5_OP_FIRSTBIT_HI
, WINED3DSIH_FIRSTBIT_HI
, "u", "u"},
1030 {WINED3D_SM5_OP_FIRSTBIT_LO
, WINED3DSIH_FIRSTBIT_LO
, "u", "u"},
1031 {WINED3D_SM5_OP_FIRSTBIT_SHI
, WINED3DSIH_FIRSTBIT_SHI
, "u", "i"},
1032 {WINED3D_SM5_OP_UBFE
, WINED3DSIH_UBFE
, "u", "iiu"},
1033 {WINED3D_SM5_OP_IBFE
, WINED3DSIH_IBFE
, "i", "iii"},
1034 {WINED3D_SM5_OP_BFI
, WINED3DSIH_BFI
, "u", "iiuu"},
1035 {WINED3D_SM5_OP_BFREV
, WINED3DSIH_BFREV
, "u", "u"},
1036 {WINED3D_SM5_OP_SWAPC
, WINED3DSIH_SWAPC
, "ff", "uff"},
1037 {WINED3D_SM5_OP_DCL_STREAM
, WINED3DSIH_DCL_STREAM
, "", "O"},
1038 {WINED3D_SM5_OP_DCL_FUNCTION_BODY
, WINED3DSIH_DCL_FUNCTION_BODY
, "", "",
1039 shader_sm5_read_dcl_function_body
},
1040 {WINED3D_SM5_OP_DCL_FUNCTION_TABLE
, WINED3DSIH_DCL_FUNCTION_TABLE
, "", "",
1041 shader_sm5_read_dcl_function_table
},
1042 {WINED3D_SM5_OP_DCL_INTERFACE
, WINED3DSIH_DCL_INTERFACE
, "", "",
1043 shader_sm5_read_dcl_interface
},
1044 {WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT
, WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
, "", "",
1045 shader_sm5_read_control_point_count
},
1046 {WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT
, WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
, "", "",
1047 shader_sm5_read_control_point_count
},
1048 {WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN
, WINED3DSIH_DCL_TESSELLATOR_DOMAIN
, "", "",
1049 shader_sm5_read_dcl_tessellator_domain
},
1050 {WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING
, WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
, "", "",
1051 shader_sm5_read_dcl_tessellator_partitioning
},
1052 {WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
, WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
, "", "",
1053 shader_sm5_read_dcl_tessellator_output_primitive
},
1054 {WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR
, WINED3DSIH_DCL_HS_MAX_TESSFACTOR
, "", "",
1055 shader_sm5_read_dcl_hs_max_tessfactor
},
1056 {WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT
, WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
, "", "",
1057 shader_sm4_read_declaration_count
},
1058 {WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
, WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
, "", "",
1059 shader_sm4_read_declaration_count
},
1060 {WINED3D_SM5_OP_DCL_THREAD_GROUP
, WINED3DSIH_DCL_THREAD_GROUP
, "", "",
1061 shader_sm5_read_dcl_thread_group
},
1062 {WINED3D_SM5_OP_DCL_UAV_TYPED
, WINED3DSIH_DCL_UAV_TYPED
, "", "",
1063 shader_sm4_read_dcl_resource
},
1064 {WINED3D_SM5_OP_DCL_UAV_RAW
, WINED3DSIH_DCL_UAV_RAW
, "", "",
1065 shader_sm5_read_dcl_uav_raw
},
1066 {WINED3D_SM5_OP_DCL_UAV_STRUCTURED
, WINED3DSIH_DCL_UAV_STRUCTURED
, "", "",
1067 shader_sm5_read_dcl_uav_structured
},
1068 {WINED3D_SM5_OP_DCL_TGSM_RAW
, WINED3DSIH_DCL_TGSM_RAW
, "", "",
1069 shader_sm5_read_dcl_tgsm_raw
},
1070 {WINED3D_SM5_OP_DCL_TGSM_STRUCTURED
, WINED3DSIH_DCL_TGSM_STRUCTURED
, "", "",
1071 shader_sm5_read_dcl_tgsm_structured
},
1072 {WINED3D_SM5_OP_DCL_RESOURCE_RAW
, WINED3DSIH_DCL_RESOURCE_RAW
, "", "",
1073 shader_sm5_read_dcl_resource_raw
},
1074 {WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED
, WINED3DSIH_DCL_RESOURCE_STRUCTURED
, "", "",
1075 shader_sm5_read_dcl_resource_structured
},
1076 {WINED3D_SM5_OP_LD_UAV_TYPED
, WINED3DSIH_LD_UAV_TYPED
, "u", "iU"},
1077 {WINED3D_SM5_OP_STORE_UAV_TYPED
, WINED3DSIH_STORE_UAV_TYPED
, "U", "iu"},
1078 {WINED3D_SM5_OP_LD_RAW
, WINED3DSIH_LD_RAW
, "u", "iU"},
1079 {WINED3D_SM5_OP_STORE_RAW
, WINED3DSIH_STORE_RAW
, "U", "iu"},
1080 {WINED3D_SM5_OP_LD_STRUCTURED
, WINED3DSIH_LD_STRUCTURED
, "u", "iiR"},
1081 {WINED3D_SM5_OP_STORE_STRUCTURED
, WINED3DSIH_STORE_STRUCTURED
, "U", "iiu"},
1082 {WINED3D_SM5_OP_ATOMIC_AND
, WINED3DSIH_ATOMIC_AND
, "U", "iu"},
1083 {WINED3D_SM5_OP_ATOMIC_OR
, WINED3DSIH_ATOMIC_OR
, "U", "iu"},
1084 {WINED3D_SM5_OP_ATOMIC_XOR
, WINED3DSIH_ATOMIC_XOR
, "U", "iu"},
1085 {WINED3D_SM5_OP_ATOMIC_CMP_STORE
, WINED3DSIH_ATOMIC_CMP_STORE
, "U", "iuu"},
1086 {WINED3D_SM5_OP_ATOMIC_IADD
, WINED3DSIH_ATOMIC_IADD
, "U", "ii"},
1087 {WINED3D_SM5_OP_ATOMIC_IMAX
, WINED3DSIH_ATOMIC_IMAX
, "U", "ii"},
1088 {WINED3D_SM5_OP_ATOMIC_IMIN
, WINED3DSIH_ATOMIC_IMIN
, "U", "ii"},
1089 {WINED3D_SM5_OP_ATOMIC_UMAX
, WINED3DSIH_ATOMIC_UMAX
, "U", "iu"},
1090 {WINED3D_SM5_OP_ATOMIC_UMIN
, WINED3DSIH_ATOMIC_UMIN
, "U", "iu"},
1091 {WINED3D_SM5_OP_IMM_ATOMIC_ALLOC
, WINED3DSIH_IMM_ATOMIC_ALLOC
, "u", "U"},
1092 {WINED3D_SM5_OP_IMM_ATOMIC_CONSUME
, WINED3DSIH_IMM_ATOMIC_CONSUME
, "u", "U"},
1093 {WINED3D_SM5_OP_IMM_ATOMIC_IADD
, WINED3DSIH_IMM_ATOMIC_IADD
, "uU", "ii"},
1094 {WINED3D_SM5_OP_IMM_ATOMIC_AND
, WINED3DSIH_IMM_ATOMIC_AND
, "uU", "iu"},
1095 {WINED3D_SM5_OP_IMM_ATOMIC_OR
, WINED3DSIH_IMM_ATOMIC_OR
, "uU", "iu"},
1096 {WINED3D_SM5_OP_IMM_ATOMIC_XOR
, WINED3DSIH_IMM_ATOMIC_XOR
, "uU", "iu"},
1097 {WINED3D_SM5_OP_IMM_ATOMIC_EXCH
, WINED3DSIH_IMM_ATOMIC_EXCH
, "uU", "iu"},
1098 {WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH
, WINED3DSIH_IMM_ATOMIC_CMP_EXCH
, "uU", "iuu"},
1099 {WINED3D_SM5_OP_IMM_ATOMIC_IMAX
, WINED3DSIH_IMM_ATOMIC_IMAX
, "iU", "ii"},
1100 {WINED3D_SM5_OP_IMM_ATOMIC_IMIN
, WINED3DSIH_IMM_ATOMIC_IMIN
, "iU", "ii"},
1101 {WINED3D_SM5_OP_IMM_ATOMIC_UMAX
, WINED3DSIH_IMM_ATOMIC_UMAX
, "uU", "iu"},
1102 {WINED3D_SM5_OP_IMM_ATOMIC_UMIN
, WINED3DSIH_IMM_ATOMIC_UMIN
, "uU", "iu"},
1103 {WINED3D_SM5_OP_SYNC
, WINED3DSIH_SYNC
, "", "",
1104 shader_sm5_read_sync
},
1105 {WINED3D_SM5_OP_DCL_GS_INSTANCES
, WINED3DSIH_DCL_GS_INSTANCES
, "", "",
1106 shader_sm4_read_declaration_count
},
1109 static const enum wined3d_shader_register_type register_type_table
[] =
1111 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP
,
1112 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT
,
1113 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT
,
1114 /* WINED3D_SM4_RT_INDEXABLE_TEMP */ WINED3DSPR_IDXTEMP
,
1115 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST
,
1117 /* WINED3D_SM4_RT_SAMPLER */ WINED3DSPR_SAMPLER
,
1118 /* WINED3D_SM4_RT_RESOURCE */ WINED3DSPR_RESOURCE
,
1119 /* WINED3D_SM4_RT_CONSTBUFFER */ WINED3DSPR_CONSTBUFFER
,
1120 /* WINED3D_SM4_RT_IMMCONSTBUFFER */ WINED3DSPR_IMMCONSTBUFFER
,
1122 /* WINED3D_SM4_RT_PRIMID */ WINED3DSPR_PRIMID
,
1123 /* WINED3D_SM4_RT_DEPTHOUT */ WINED3DSPR_DEPTHOUT
,
1124 /* WINED3D_SM4_RT_NULL */ WINED3DSPR_NULL
,
1126 /* WINED3D_SM4_RT_OMASK */ WINED3DSPR_SAMPLEMASK
,
1127 /* WINED3D_SM5_RT_STREAM */ WINED3DSPR_STREAM
,
1128 /* WINED3D_SM5_RT_FUNCTION_BODY */ WINED3DSPR_FUNCTIONBODY
,
1130 /* WINED3D_SM5_RT_FUNCTION_POINTER */ WINED3DSPR_FUNCTIONPOINTER
,
1133 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID */ WINED3DSPR_OUTPOINTID
,
1134 /* WINED3D_SM5_RT_FORK_INSTANCE_ID */ WINED3DSPR_FORKINSTID
,
1135 /* WINED3D_SM5_RT_JOIN_INSTANCE_ID */ WINED3DSPR_JOININSTID
,
1136 /* WINED3D_SM5_RT_INPUT_CONTROL_POINT */ WINED3DSPR_INCONTROLPOINT
,
1137 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT */ WINED3DSPR_OUTCONTROLPOINT
,
1138 /* WINED3D_SM5_RT_PATCH_CONSTANT_DATA */ WINED3DSPR_PATCHCONST
,
1139 /* WINED3D_SM5_RT_DOMAIN_LOCATION */ WINED3DSPR_TESSCOORD
,
1141 /* WINED3D_SM5_RT_UAV */ WINED3DSPR_UAV
,
1142 /* WINED3D_SM5_RT_SHARED_MEMORY */ WINED3DSPR_GROUPSHAREDMEM
,
1143 /* WINED3D_SM5_RT_THREAD_ID */ WINED3DSPR_THREADID
,
1144 /* WINED3D_SM5_RT_THREAD_GROUP_ID */ WINED3DSPR_THREADGROUPID
,
1145 /* WINED3D_SM5_RT_LOCAL_THREAD_ID */ WINED3DSPR_LOCALTHREADID
,
1146 /* WINED3D_SM5_RT_COVERAGE */ WINED3DSPR_COVERAGE
,
1147 /* WINED3D_SM5_RT_LOCAL_THREAD_INDEX */ WINED3DSPR_LOCALTHREADINDEX
,
1148 /* WINED3D_SM5_RT_GS_INSTANCE_ID */ WINED3DSPR_GSINSTID
,
1151 static const struct wined3d_sm4_opcode_info
*get_opcode_info(enum wined3d_sm4_opcode opcode
)
1155 for (i
= 0; i
< sizeof(opcode_table
) / sizeof(*opcode_table
); ++i
)
1157 if (opcode
== opcode_table
[i
].opcode
) return &opcode_table
[i
];
1163 static void map_register(const struct wined3d_sm4_data
*priv
, struct wined3d_shader_register
*reg
)
1165 switch (priv
->shader_version
.type
)
1167 case WINED3D_SHADER_TYPE_PIXEL
:
1168 if (reg
->type
== WINED3DSPR_OUTPUT
)
1170 unsigned int reg_idx
= reg
->idx
[0].offset
;
1172 if (reg_idx
>= ARRAY_SIZE(priv
->output_map
))
1174 ERR("Invalid output index %u.\n", reg_idx
);
1178 reg
->type
= WINED3DSPR_COLOROUT
;
1179 reg
->idx
[0].offset
= priv
->output_map
[reg_idx
];
1188 static enum wined3d_data_type
map_data_type(char t
)
1193 return WINED3D_DATA_FLOAT
;
1195 return WINED3D_DATA_INT
;
1197 return WINED3D_DATA_UINT
;
1199 return WINED3D_DATA_OPAQUE
;
1201 return WINED3D_DATA_RESOURCE
;
1203 return WINED3D_DATA_SAMPLER
;
1205 return WINED3D_DATA_UAV
;
1207 ERR("Invalid data type '%c'.\n", t
);
1208 return WINED3D_DATA_FLOAT
;
1212 static void *shader_sm4_init(const DWORD
*byte_code
, size_t byte_code_size
,
1213 const struct wined3d_shader_signature
*output_signature
)
1215 DWORD version_token
, token_count
;
1216 struct wined3d_sm4_data
*priv
;
1219 if (byte_code_size
/ sizeof(*byte_code
) < 2)
1221 WARN("Invalid byte code size %lu.\n", (long)byte_code_size
);
1225 version_token
= byte_code
[0];
1226 TRACE("Version: 0x%08x.\n", version_token
);
1227 token_count
= byte_code
[1];
1228 TRACE("Token count: %u.\n", token_count
);
1230 if (token_count
< 2 || byte_code_size
/ sizeof(*byte_code
) < token_count
)
1232 WARN("Invalid token count %u.\n", token_count
);
1236 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
1238 ERR("Failed to allocate private data\n");
1242 priv
->start
= &byte_code
[2];
1243 priv
->end
= &byte_code
[token_count
];
1245 switch (version_token
>> 16)
1247 case WINED3D_SM4_PS
:
1248 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_PIXEL
;
1251 case WINED3D_SM4_VS
:
1252 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_VERTEX
;
1255 case WINED3D_SM4_GS
:
1256 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_GEOMETRY
;
1259 case WINED3D_SM5_HS
:
1260 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_HULL
;
1263 case WINED3D_SM5_DS
:
1264 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_DOMAIN
;
1267 case WINED3D_SM5_CS
:
1268 priv
->shader_version
.type
= WINED3D_SHADER_TYPE_COMPUTE
;
1272 FIXME("Unrecognised shader type %#x.\n", version_token
>> 16);
1274 priv
->shader_version
.major
= WINED3D_SM4_VERSION_MAJOR(version_token
);
1275 priv
->shader_version
.minor
= WINED3D_SM4_VERSION_MINOR(version_token
);
1277 memset(priv
->output_map
, 0xff, sizeof(priv
->output_map
));
1278 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1280 struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1282 if (e
->register_idx
>= ARRAY_SIZE(priv
->output_map
))
1284 WARN("Invalid output index %u.\n", e
->register_idx
);
1288 priv
->output_map
[e
->register_idx
] = e
->semantic_idx
;
1291 list_init(&priv
->src_free
);
1292 list_init(&priv
->src
);
1297 static void shader_sm4_free(void *data
)
1299 struct wined3d_shader_src_param_entry
*e1
, *e2
;
1300 struct wined3d_sm4_data
*priv
= data
;
1302 list_move_head(&priv
->src_free
, &priv
->src
);
1303 LIST_FOR_EACH_ENTRY_SAFE(e1
, e2
, &priv
->src_free
, struct wined3d_shader_src_param_entry
, entry
)
1305 HeapFree(GetProcessHeap(), 0, e1
);
1307 HeapFree(GetProcessHeap(), 0, priv
);
1310 static struct wined3d_shader_src_param
*get_src_param(struct wined3d_sm4_data
*priv
)
1312 struct wined3d_shader_src_param_entry
*e
;
1315 if (!list_empty(&priv
->src_free
))
1317 elem
= list_head(&priv
->src_free
);
1322 if (!(e
= HeapAlloc(GetProcessHeap(), 0, sizeof(*e
))))
1327 list_add_tail(&priv
->src
, elem
);
1328 e
= LIST_ENTRY(elem
, struct wined3d_shader_src_param_entry
, entry
);
1332 static void shader_sm4_read_header(void *data
, const DWORD
**ptr
, struct wined3d_shader_version
*shader_version
)
1334 struct wined3d_sm4_data
*priv
= data
;
1337 *shader_version
= priv
->shader_version
;
1340 static BOOL
shader_sm4_read_reg_idx(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1341 DWORD addressing
, struct wined3d_shader_register_index
*reg_idx
)
1343 if (addressing
& WINED3D_SM4_ADDRESSING_RELATIVE
)
1345 struct wined3d_shader_src_param
*rel_addr
= get_src_param(priv
);
1347 if (!(reg_idx
->rel_addr
= rel_addr
))
1349 ERR("Failed to get src param for relative addressing.\n");
1353 if (addressing
& WINED3D_SM4_ADDRESSING_OFFSET
)
1354 reg_idx
->offset
= *(*ptr
)++;
1356 reg_idx
->offset
= 0;
1357 shader_sm4_read_src_param(priv
, ptr
, end
, WINED3D_DATA_INT
, rel_addr
);
1361 reg_idx
->rel_addr
= NULL
;
1362 reg_idx
->offset
= *(*ptr
)++;
1368 static BOOL
shader_sm4_read_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1369 enum wined3d_data_type data_type
, struct wined3d_shader_register
*param
,
1370 enum wined3d_shader_src_modifier
*modifier
)
1372 enum wined3d_sm4_register_type register_type
;
1377 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1382 register_type
= (token
& WINED3D_SM4_REGISTER_TYPE_MASK
) >> WINED3D_SM4_REGISTER_TYPE_SHIFT
;
1383 if (register_type
>= sizeof(register_type_table
) / sizeof(*register_type_table
)
1384 || register_type_table
[register_type
] == ~0u)
1386 FIXME("Unhandled register type %#x.\n", register_type
);
1387 param
->type
= WINED3DSPR_TEMP
;
1391 param
->type
= register_type_table
[register_type
];
1393 param
->data_type
= data_type
;
1395 if (token
& WINED3D_SM4_REGISTER_MODIFIER
)
1401 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1409 *modifier
= WINED3DSPSM_NEG
;
1413 *modifier
= WINED3DSPSM_ABS
;
1417 *modifier
= WINED3DSPSM_ABSNEG
;
1421 FIXME("Skipping modifier 0x%08x.\n", m
);
1422 *modifier
= WINED3DSPSM_NONE
;
1428 *modifier
= WINED3DSPSM_NONE
;
1431 order
= (token
& WINED3D_SM4_REGISTER_ORDER_MASK
) >> WINED3D_SM4_REGISTER_ORDER_SHIFT
;
1434 param
->idx
[0].offset
= ~0U;
1437 DWORD addressing
= (token
& WINED3D_SM4_ADDRESSING_MASK0
) >> WINED3D_SM4_ADDRESSING_SHIFT0
;
1438 if (!(shader_sm4_read_reg_idx(priv
, ptr
, end
, addressing
, ¶m
->idx
[0])))
1440 ERR("Failed to read register index.\n");
1446 param
->idx
[1].offset
= ~0U;
1449 DWORD addressing
= (token
& WINED3D_SM4_ADDRESSING_MASK1
) >> WINED3D_SM4_ADDRESSING_SHIFT1
;
1450 if (!(shader_sm4_read_reg_idx(priv
, ptr
, end
, addressing
, ¶m
->idx
[1])))
1452 ERR("Failed to read register index.\n");
1458 FIXME("Unhandled order %u.\n", order
);
1460 if (register_type
== WINED3D_SM4_RT_IMMCONST
)
1462 enum wined3d_sm4_immconst_type immconst_type
=
1463 (token
& WINED3D_SM4_IMMCONST_TYPE_MASK
) >> WINED3D_SM4_IMMCONST_TYPE_SHIFT
;
1465 switch (immconst_type
)
1467 case WINED3D_SM4_IMMCONST_SCALAR
:
1468 param
->immconst_type
= WINED3D_IMMCONST_SCALAR
;
1471 WARN("Invalid ptr %p, end %p.\n", *ptr
, end
);
1474 memcpy(param
->u
.immconst_data
, *ptr
, 1 * sizeof(DWORD
));
1478 case WINED3D_SM4_IMMCONST_VEC4
:
1479 param
->immconst_type
= WINED3D_IMMCONST_VEC4
;
1482 WARN("Invalid ptr %p, end %p.\n", *ptr
, end
);
1485 memcpy(param
->u
.immconst_data
, *ptr
, 4 * sizeof(DWORD
));
1490 FIXME("Unhandled immediate constant type %#x.\n", immconst_type
);
1495 map_register(priv
, param
);
1500 static BOOL
shader_sm4_read_src_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1501 enum wined3d_data_type data_type
, struct wined3d_shader_src_param
*src_param
)
1507 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1512 if (!shader_sm4_read_param(priv
, ptr
, end
, data_type
, &src_param
->reg
, &src_param
->modifiers
))
1514 ERR("Failed to read parameter.\n");
1518 if (src_param
->reg
.type
== WINED3DSPR_IMMCONST
)
1520 src_param
->swizzle
= WINED3DSP_NOSWIZZLE
;
1524 enum wined3d_sm4_swizzle_type swizzle_type
=
1525 (token
& WINED3D_SM4_SWIZZLE_TYPE_MASK
) >> WINED3D_SM4_SWIZZLE_TYPE_SHIFT
;
1527 switch (swizzle_type
)
1529 case WINED3D_SM4_SWIZZLE_NONE
:
1530 src_param
->swizzle
= WINED3DSP_NOSWIZZLE
;
1533 case WINED3D_SM4_SWIZZLE_SCALAR
:
1534 src_param
->swizzle
= (token
& WINED3D_SM4_SWIZZLE_MASK
) >> WINED3D_SM4_SWIZZLE_SHIFT
;
1535 src_param
->swizzle
= (src_param
->swizzle
& 0x3) * 0x55;
1538 case WINED3D_SM4_SWIZZLE_VEC4
:
1539 src_param
->swizzle
= (token
& WINED3D_SM4_SWIZZLE_MASK
) >> WINED3D_SM4_SWIZZLE_SHIFT
;
1543 FIXME("Unhandled swizzle type %#x.\n", swizzle_type
);
1551 static BOOL
shader_sm4_read_dst_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1552 enum wined3d_data_type data_type
, struct wined3d_shader_dst_param
*dst_param
)
1554 enum wined3d_shader_src_modifier modifier
;
1559 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1564 if (!shader_sm4_read_param(priv
, ptr
, end
, data_type
, &dst_param
->reg
, &modifier
))
1566 ERR("Failed to read parameter.\n");
1570 if (modifier
!= WINED3DSPSM_NONE
)
1572 ERR("Invalid source modifier %#x on destination register.\n", modifier
);
1576 dst_param
->write_mask
= (token
& WINED3D_SM4_WRITEMASK_MASK
) >> WINED3D_SM4_WRITEMASK_SHIFT
;
1577 dst_param
->modifiers
= 0;
1578 dst_param
->shift
= 0;
1583 static void shader_sm4_read_instruction_modifier(DWORD modifier
, struct wined3d_shader_instruction
*ins
)
1585 static const DWORD recognized_bits
= WINED3D_SM4_INSTRUCTION_MODIFIER
1586 | WINED3D_SM4_MODIFIER_AOFFIMMI
1587 | WINED3D_SM4_AOFFIMMI_U_MASK
1588 | WINED3D_SM4_AOFFIMMI_V_MASK
1589 | WINED3D_SM4_AOFFIMMI_W_MASK
;
1591 if (modifier
& ~recognized_bits
)
1593 FIXME("Unhandled modifier 0x%08x.\n", modifier
);
1597 /* Bit fields are used for sign extension */
1605 aoffimmi
.u
= (modifier
& WINED3D_SM4_AOFFIMMI_U_MASK
) >> WINED3D_SM4_AOFFIMMI_U_SHIFT
;
1606 aoffimmi
.v
= (modifier
& WINED3D_SM4_AOFFIMMI_V_MASK
) >> WINED3D_SM4_AOFFIMMI_V_SHIFT
;
1607 aoffimmi
.w
= (modifier
& WINED3D_SM4_AOFFIMMI_W_MASK
) >> WINED3D_SM4_AOFFIMMI_W_SHIFT
;
1608 ins
->texel_offset
.u
= aoffimmi
.u
;
1609 ins
->texel_offset
.v
= aoffimmi
.v
;
1610 ins
->texel_offset
.w
= aoffimmi
.w
;
1614 static void shader_sm4_read_instruction(void *data
, const DWORD
**ptr
, struct wined3d_shader_instruction
*ins
)
1616 const struct wined3d_sm4_opcode_info
*opcode_info
;
1617 DWORD opcode_token
, opcode
, previous_token
;
1618 struct wined3d_sm4_data
*priv
= data
;
1619 unsigned int i
, len
;
1623 list_move_head(&priv
->src_free
, &priv
->src
);
1625 if (*ptr
>= priv
->end
)
1627 WARN("End of byte-code, failed to read opcode.\n");
1630 remaining
= priv
->end
- *ptr
;
1632 opcode_token
= *(*ptr
)++;
1633 opcode
= opcode_token
& WINED3D_SM4_OPCODE_MASK
;
1635 len
= ((opcode_token
& WINED3D_SM4_INSTRUCTION_LENGTH_MASK
) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT
);
1640 WARN("End of byte-code, failed to read length token.\n");
1645 if (!len
|| remaining
< len
)
1647 WARN("Read invalid length %u (remaining %lu).\n", len
, remaining
);
1652 if (TRACE_ON(d3d_bytecode
))
1654 TRACE_(d3d_bytecode
)("[ %08x ", opcode_token
);
1655 for (i
= 0; i
< len
; ++i
)
1657 TRACE_(d3d_bytecode
)("%08x ", (*ptr
)[i
]);
1659 TRACE_(d3d_bytecode
)("]\n");
1662 if (!(opcode_info
= get_opcode_info(opcode
)))
1664 FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode
, opcode_token
);
1665 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1670 ins
->handler_idx
= opcode_info
->handler_idx
;
1673 ins
->predicate
= NULL
;
1674 ins
->dst_count
= strlen(opcode_info
->dst_info
);
1675 ins
->dst
= priv
->dst_param
;
1676 ins
->src_count
= strlen(opcode_info
->src_info
);
1677 ins
->src
= priv
->src_param
;
1678 memset(&ins
->texel_offset
, 0, sizeof(ins
->texel_offset
));
1683 if (opcode_info
->read_opcode_func
)
1685 opcode_info
->read_opcode_func(ins
, opcode
, opcode_token
, p
, len
, priv
);
1689 enum wined3d_shader_dst_modifier instruction_dst_modifier
= WINED3DSPDM_NONE
;
1691 previous_token
= opcode_token
;
1692 while (previous_token
& WINED3D_SM4_INSTRUCTION_MODIFIER
&& p
!= *ptr
)
1693 shader_sm4_read_instruction_modifier(previous_token
= *p
++, ins
);
1695 ins
->flags
= (opcode_token
& WINED3D_SM4_INSTRUCTION_FLAGS_MASK
) >> WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT
;
1697 if (ins
->flags
& WINED3D_SM4_INSTRUCTION_FLAG_SATURATE
)
1699 ins
->flags
&= ~WINED3D_SM4_INSTRUCTION_FLAG_SATURATE
;
1700 instruction_dst_modifier
= WINED3DSPDM_SATURATE
;
1703 for (i
= 0; i
< ins
->dst_count
; ++i
)
1705 if (!(shader_sm4_read_dst_param(priv
, &p
, *ptr
, map_data_type(opcode_info
->dst_info
[i
]),
1706 &priv
->dst_param
[i
])))
1708 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1711 priv
->dst_param
[i
].modifiers
|= instruction_dst_modifier
;
1714 for (i
= 0; i
< ins
->src_count
; ++i
)
1716 if (!(shader_sm4_read_src_param(priv
, &p
, *ptr
, map_data_type(opcode_info
->src_info
[i
]),
1717 &priv
->src_param
[i
])))
1719 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1729 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1733 static BOOL
shader_sm4_is_end(void *data
, const DWORD
**ptr
)
1735 struct wined3d_sm4_data
*priv
= data
;
1736 return *ptr
== priv
->end
;
1739 const struct wined3d_shader_frontend sm4_shader_frontend
=
1743 shader_sm4_read_header
,
1744 shader_sm4_read_instruction
,