2 * Copyright 2002-2003 Jason Edmeades
3 * Copyright 2002-2003 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2006 Ivan Gyurdiev
7 * Copyright 2007-2008, 2013 Stefan Dösinger for CodeWeavers
8 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wined3d_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
32 const struct wined3d_vec4 wined3d_srgb_const
[] =
34 /* pow, mul_high, sub_high, mul_low */
35 {0.41666f
, 1.055f
, 0.055f
, 12.92f
},
37 {0.0031308f
, 0.0f
, 0.0f
, 0.0f
},
40 static const char * const shader_opcode_names
[] =
42 /* WINED3DSIH_ABS */ "abs",
43 /* WINED3DSIH_ADD */ "add",
44 /* WINED3DSIH_AND */ "and",
45 /* WINED3DSIH_ATOMIC_AND */ "atomic_and",
46 /* WINED3DSIH_ATOMIC_CMP_STORE */ "atomic_cmp_store",
47 /* WINED3DSIH_ATOMIC_IADD */ "atomic_iadd",
48 /* WINED3DSIH_ATOMIC_IMAX */ "atomic_imax",
49 /* WINED3DSIH_ATOMIC_IMIN */ "atomic_imin",
50 /* WINED3DSIH_ATOMIC_OR */ "atomic_or",
51 /* WINED3DSIH_ATOMIC_UMAX */ "atomic_umax",
52 /* WINED3DSIH_ATOMIC_UMIN */ "atomic_umin",
53 /* WINED3DSIH_ATOMIC_XOR */ "atomic_xor",
54 /* WINED3DSIH_BEM */ "bem",
55 /* WINED3DSIH_BFI */ "bfi",
56 /* WINED3DSIH_BFREV */ "bfrev",
57 /* WINED3DSIH_BREAK */ "break",
58 /* WINED3DSIH_BREAKC */ "breakc",
59 /* WINED3DSIH_BREAKP */ "breakp",
60 /* WINED3DSIH_BUFINFO */ "bufinfo",
61 /* WINED3DSIH_CALL */ "call",
62 /* WINED3DSIH_CALLNZ */ "callnz",
63 /* WINED3DSIH_CASE */ "case",
64 /* WINED3DSIH_CMP */ "cmp",
65 /* WINED3DSIH_CND */ "cnd",
66 /* WINED3DSIH_CONTINUE */ "continue",
67 /* WINED3DSIH_CONTINUEP */ "continuec",
68 /* WINED3DSIH_COUNTBITS */ "countbits",
69 /* WINED3DSIH_CRS */ "crs",
70 /* WINED3DSIH_CUT */ "cut",
71 /* WINED3DSIH_CUT_STREAM */ "cut_stream",
72 /* WINED3DSIH_DCL */ "dcl",
73 /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
74 /* WINED3DSIH_DCL_FUNCTION_BODY */ "dcl_function_body",
75 /* WINED3DSIH_DCL_FUNCTION_TABLE */ "dcl_function_table",
76 /* WINED3DSIH_DCL_GLOBAL_FLAGS */ "dcl_globalFlags",
77 /* WINED3DSIH_DCL_GS_INSTANCES */ "dcl_gs_instances",
78 /* WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT */ "dcl_hs_fork_phase_instance_count",
79 /* WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT */ "dcl_hs_join_phase_instance_count",
80 /* WINED3DSIH_DCL_HS_MAX_TESSFACTOR */ "dcl_hs_max_tessfactor",
81 /* WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER */ "dcl_immediateConstantBuffer",
82 /* WINED3DSIH_DCL_INDEX_RANGE */ "dcl_index_range",
83 /* WINED3DSIH_DCL_INDEXABLE_TEMP */ "dcl_indexableTemp",
84 /* WINED3DSIH_DCL_INPUT */ "dcl_input",
85 /* WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT */ "dcl_input_control_point_count",
86 /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
87 /* WINED3DSIH_DCL_INPUT_PS */ "dcl_input_ps",
88 /* WINED3DSIH_DCL_INPUT_PS_SGV */ "dcl_input_ps_sgv",
89 /* WINED3DSIH_DCL_INPUT_PS_SIV */ "dcl_input_ps_siv",
90 /* WINED3DSIH_DCL_INPUT_SGV */ "dcl_input_sgv",
91 /* WINED3DSIH_DCL_INPUT_SIV */ "dcl_input_siv",
92 /* WINED3DSIH_DCL_INTERFACE */ "dcl_interface",
93 /* WINED3DSIH_DCL_OUTPUT */ "dcl_output",
94 /* WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT */ "dcl_output_control_point_count",
95 /* WINED3DSIH_DCL_OUTPUT_SIV */ "dcl_output_siv",
96 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
97 /* WINED3DSIH_DCL_RESOURCE_RAW */ "dcl_resource_raw",
98 /* WINED3DSIH_DCL_RESOURCE_STRUCTURED */ "dcl_resource_structured",
99 /* WINED3DSIH_DCL_SAMPLER */ "dcl_sampler",
100 /* WINED3DSIH_DCL_STREAM */ "dcl_stream",
101 /* WINED3DSIH_DCL_TEMPS */ "dcl_temps",
102 /* WINED3DSIH_DCL_TESSELLATOR_DOMAIN */ "dcl_tessellator_domain",
103 /* WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE */ "dcl_tessellator_output_primitive",
104 /* WINED3DSIH_DCL_TESSELLATOR_PARTITIONING */ "dcl_tessellator_partitioning",
105 /* WINED3DSIH_DCL_TGSM_RAW */ "dcl_tgsm_raw",
106 /* WINED3DSIH_DCL_TGSM_STRUCTURED */ "dcl_tgsm_structured",
107 /* WINED3DSIH_DCL_THREAD_GROUP */ "dcl_thread_group",
108 /* WINED3DSIH_DCL_UAV_RAW */ "dcl_uav_raw",
109 /* WINED3DSIH_DCL_UAV_STRUCTURED */ "dcl_uav_structured",
110 /* WINED3DSIH_DCL_UAV_TYPED */ "dcl_uav_typed",
111 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
112 /* WINED3DSIH_DEF */ "def",
113 /* WINED3DSIH_DEFAULT */ "default",
114 /* WINED3DSIH_DEFB */ "defb",
115 /* WINED3DSIH_DEFI */ "defi",
116 /* WINED3DSIH_DIV */ "div",
117 /* WINED3DSIH_DP2 */ "dp2",
118 /* WINED3DSIH_DP2ADD */ "dp2add",
119 /* WINED3DSIH_DP3 */ "dp3",
120 /* WINED3DSIH_DP4 */ "dp4",
121 /* WINED3DSIH_DST */ "dst",
122 /* WINED3DSIH_DSX */ "dsx",
123 /* WINED3DSIH_DSX_COARSE */ "deriv_rtx_coarse",
124 /* WINED3DSIH_DSX_FINE */ "deriv_rtx_fine",
125 /* WINED3DSIH_DSY */ "dsy",
126 /* WINED3DSIH_DSY_COARSE */ "deriv_rty_coarse",
127 /* WINED3DSIH_DSY_FINE */ "deriv_rty_fine",
128 /* WINED3DSIH_ELSE */ "else",
129 /* WINED3DSIH_EMIT */ "emit",
130 /* WINED3DSIH_EMIT_STREAM */ "emit_stream",
131 /* WINED3DSIH_ENDIF */ "endif",
132 /* WINED3DSIH_ENDLOOP */ "endloop",
133 /* WINED3DSIH_ENDREP */ "endrep",
134 /* WINED3DSIH_ENDSWITCH */ "endswitch",
135 /* WINED3DSIH_EQ */ "eq",
136 /* WINED3DSIH_EVAL_CENTROID */ "eval_centroid",
137 /* WINED3DSIH_EVAL_SAMPLE_INDEX */ "eval_sample_index",
138 /* WINED3DSIH_EXP */ "exp",
139 /* WINED3DSIH_EXPP */ "expp",
140 /* WINED3DSIH_F16TOF32 */ "f16tof32",
141 /* WINED3DSIH_F32TOF16 */ "f32tof16",
142 /* WINED3DSIH_FCALL */ "fcall",
143 /* WINED3DSIH_FIRSTBIT_HI */ "firstbit_hi",
144 /* WINED3DSIH_FIRSTBIT_LO */ "firstbit_lo",
145 /* WINED3DSIH_FIRSTBIT_SHI */ "firstbit_shi",
146 /* WINED3DSIH_FRC */ "frc",
147 /* WINED3DSIH_FTOI */ "ftoi",
148 /* WINED3DSIH_FTOU */ "ftou",
149 /* WINED3DSIH_GATHER4 */ "gather4",
150 /* WINED3DSIH_GATHER4_C */ "gather4_c",
151 /* WINED3DSIH_GATHER4_PO */ "gather4_po",
152 /* WINED3DSIH_GATHER4_PO_C */ "gather4_po_c",
153 /* WINED3DSIH_GE */ "ge",
154 /* WINED3DSIH_HS_CONTROL_POINT_PHASE */ "hs_control_point_phase",
155 /* WINED3DSIH_HS_DECLS */ "hs_decls",
156 /* WINED3DSIH_HS_FORK_PHASE */ "hs_fork_phase",
157 /* WINED3DSIH_HS_JOIN_PHASE */ "hs_join_phase",
158 /* WINED3DSIH_IADD */ "iadd",
159 /* WINED3DSIH_IBFE */ "ibfe",
160 /* WINED3DSIH_IEQ */ "ieq",
161 /* WINED3DSIH_IF */ "if",
162 /* WINED3DSIH_IFC */ "ifc",
163 /* WINED3DSIH_IGE */ "ige",
164 /* WINED3DSIH_ILT */ "ilt",
165 /* WINED3DSIH_IMAD */ "imad",
166 /* WINED3DSIH_IMAX */ "imax",
167 /* WINED3DSIH_IMIN */ "imin",
168 /* WINED3DSIH_IMM_ATOMIC_ALLOC */ "imm_atomic_alloc",
169 /* WINED3DSIH_IMM_ATOMIC_AND */ "imm_atomic_and",
170 /* WINED3DSIH_IMM_ATOMIC_CMP_EXCH */ "imm_atomic_cmp_exch",
171 /* WINED3DSIH_IMM_ATOMIC_CONSUME */ "imm_atomic_consume",
172 /* WINED3DSIH_IMM_ATOMIC_EXCH */ "imm_atomic_exch",
173 /* WINED3DSIH_IMM_ATOMIC_IADD */ "imm_atomic_iadd",
174 /* WINED3DSIH_IMM_ATOMIC_IMAX */ "imm_atomic_imax",
175 /* WINED3DSIH_IMM_ATOMIC_IMIN */ "imm_atomic_imin",
176 /* WINED3DSIH_IMM_ATOMIC_OR */ "imm_atomic_or",
177 /* WINED3DSIH_IMM_ATOMIC_UMAX */ "imm_atomic_umax",
178 /* WINED3DSIH_IMM_ATOMIC_UMIN */ "imm_atomic_umin",
179 /* WINED3DSIH_IMM_ATOMIC_XOR */ "imm_atomic_xor",
180 /* WINED3DSIH_IMUL */ "imul",
181 /* WINED3DSIH_INE */ "ine",
182 /* WINED3DSIH_INEG */ "ineg",
183 /* WINED3DSIH_ISHL */ "ishl",
184 /* WINED3DSIH_ISHR */ "ishr",
185 /* WINED3DSIH_ITOF */ "itof",
186 /* WINED3DSIH_LABEL */ "label",
187 /* WINED3DSIH_LD */ "ld",
188 /* WINED3DSIH_LD2DMS */ "ld2dms",
189 /* WINED3DSIH_LD_RAW */ "ld_raw",
190 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
191 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
192 /* WINED3DSIH_LIT */ "lit",
193 /* WINED3DSIH_LOD */ "lod",
194 /* WINED3DSIH_LOG */ "log",
195 /* WINED3DSIH_LOGP */ "logp",
196 /* WINED3DSIH_LOOP */ "loop",
197 /* WINED3DSIH_LRP */ "lrp",
198 /* WINED3DSIH_LT */ "lt",
199 /* WINED3DSIH_M3x2 */ "m3x2",
200 /* WINED3DSIH_M3x3 */ "m3x3",
201 /* WINED3DSIH_M3x4 */ "m3x4",
202 /* WINED3DSIH_M4x3 */ "m4x3",
203 /* WINED3DSIH_M4x4 */ "m4x4",
204 /* WINED3DSIH_MAD */ "mad",
205 /* WINED3DSIH_MAX */ "max",
206 /* WINED3DSIH_MIN */ "min",
207 /* WINED3DSIH_MOV */ "mov",
208 /* WINED3DSIH_MOVA */ "mova",
209 /* WINED3DSIH_MOVC */ "movc",
210 /* WINED3DSIH_MUL */ "mul",
211 /* WINED3DSIH_NE */ "ne",
212 /* WINED3DSIH_NOP */ "nop",
213 /* WINED3DSIH_NOT */ "not",
214 /* WINED3DSIH_NRM */ "nrm",
215 /* WINED3DSIH_OR */ "or",
216 /* WINED3DSIH_PHASE */ "phase",
217 /* WINED3DSIH_POW */ "pow",
218 /* WINED3DSIH_RCP */ "rcp",
219 /* WINED3DSIH_REP */ "rep",
220 /* WINED3DSIH_RESINFO */ "resinfo",
221 /* WINED3DSIH_RET */ "ret",
222 /* WINED3DSIH_RETP */ "retp",
223 /* WINED3DSIH_ROUND_NE */ "round_ne",
224 /* WINED3DSIH_ROUND_NI */ "round_ni",
225 /* WINED3DSIH_ROUND_PI */ "round_pi",
226 /* WINED3DSIH_ROUND_Z */ "round_z",
227 /* WINED3DSIH_RSQ */ "rsq",
228 /* WINED3DSIH_SAMPLE */ "sample",
229 /* WINED3DSIH_SAMPLE_B */ "sample_b",
230 /* WINED3DSIH_SAMPLE_C */ "sample_c",
231 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
232 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
233 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
234 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
235 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
236 /* WINED3DSIH_SETP */ "setp",
237 /* WINED3DSIH_SGE */ "sge",
238 /* WINED3DSIH_SGN */ "sgn",
239 /* WINED3DSIH_SINCOS */ "sincos",
240 /* WINED3DSIH_SLT */ "slt",
241 /* WINED3DSIH_SQRT */ "sqrt",
242 /* WINED3DSIH_STORE_RAW */ "store_raw",
243 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
244 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
245 /* WINED3DSIH_SUB */ "sub",
246 /* WINED3DSIH_SWAPC */ "swapc",
247 /* WINED3DSIH_SWITCH */ "switch",
248 /* WINED3DSIH_SYNC */ "sync",
249 /* WINED3DSIH_TEX */ "texld",
250 /* WINED3DSIH_TEXBEM */ "texbem",
251 /* WINED3DSIH_TEXBEML */ "texbeml",
252 /* WINED3DSIH_TEXCOORD */ "texcrd",
253 /* WINED3DSIH_TEXDEPTH */ "texdepth",
254 /* WINED3DSIH_TEXDP3 */ "texdp3",
255 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
256 /* WINED3DSIH_TEXKILL */ "texkill",
257 /* WINED3DSIH_TEXLDD */ "texldd",
258 /* WINED3DSIH_TEXLDL */ "texldl",
259 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
260 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
261 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
262 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
263 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
264 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
265 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
266 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
267 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
268 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
269 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
270 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
271 /* WINED3DSIH_UBFE */ "ubfe",
272 /* WINED3DSIH_UDIV */ "udiv",
273 /* WINED3DSIH_UGE */ "uge",
274 /* WINED3DSIH_ULT */ "ult",
275 /* WINED3DSIH_UMAX */ "umax",
276 /* WINED3DSIH_UMIN */ "umin",
277 /* WINED3DSIH_UMUL */ "umul",
278 /* WINED3DSIH_USHR */ "ushr",
279 /* WINED3DSIH_UTOF */ "utof",
280 /* WINED3DSIH_XOR */ "xor",
283 static const char * const semantic_names
[] =
285 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
286 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
287 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
288 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
289 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
290 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
291 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
292 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
293 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
294 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
295 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
296 /* WINED3D_DECL_USAGE_FOG */ "FOG",
297 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
298 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
303 enum wined3d_shader_input_sysval_semantic sysval_semantic
;
304 const char *sysval_name
;
306 shader_input_sysval_semantic_names
[] =
308 {WINED3D_SIV_POSITION
, "position"},
309 {WINED3D_SIV_CLIP_DISTANCE
, "clip_distance"},
310 {WINED3D_SIV_CULL_DISTANCE
, "cull_distance"},
311 {WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX
, "render_target_array_index"},
312 {WINED3D_SIV_VIEWPORT_ARRAY_INDEX
, "viewport_array_index"},
313 {WINED3D_SIV_VERTEX_ID
, "vertex_id"},
314 {WINED3D_SIV_INSTANCE_ID
, "instance_id"},
315 {WINED3D_SIV_PRIMITIVE_ID
, "primitive_id"},
316 {WINED3D_SIV_IS_FRONT_FACE
, "is_front_face"},
317 {WINED3D_SIV_SAMPLE_INDEX
, "sample_index"},
318 {WINED3D_SIV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
319 {WINED3D_SIV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
320 {WINED3D_SIV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
321 {WINED3D_SIV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
322 {WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
323 {WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
324 {WINED3D_SIV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
325 {WINED3D_SIV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
326 {WINED3D_SIV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
327 {WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
328 {WINED3D_SIV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
329 {WINED3D_SIV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
332 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
333 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
335 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
337 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
338 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
340 return shader_opcode_names
[handler_idx
];
343 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
345 if (usage
>= ARRAY_SIZE(semantic_names
))
347 FIXME("Unrecognized usage %#x.\n", usage
);
348 return "UNRECOGNIZED";
351 return semantic_names
[usage
];
354 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
358 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
360 if (!strcmp(name
, semantic_names
[i
]))
367 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
371 case WINED3D_DECL_USAGE_POSITION
:
372 return WINED3D_SV_POSITION
;
378 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
380 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
383 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
384 const struct wined3d_shader_semantic
*s
)
386 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
387 e
->semantic_idx
= s
->usage_idx
;
389 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
390 e
->component_type
= WINED3D_TYPE_FLOAT
;
391 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
392 e
->mask
= s
->reg
.write_mask
;
395 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
396 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
398 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
399 e
->semantic_idx
= usage_idx
;
401 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
402 e
->component_type
= WINED3D_TYPE_FLOAT
;
403 e
->register_idx
= reg_idx
;
404 e
->mask
= write_mask
;
407 static const struct wined3d_shader_frontend
*shader_select_frontend(enum wined3d_shader_byte_code_format format
)
411 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
:
412 return &sm1_shader_frontend
;
414 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
:
415 return &sm4_shader_frontend
;
418 WARN("Invalid byte code format %#x specified.\n", format
);
423 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
425 buffer
->buffer
[0] = '\0';
426 buffer
->content_size
= 0;
429 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
431 buffer
->buffer_size
= 32;
432 if (!(buffer
->buffer
= heap_alloc(buffer
->buffer_size
)))
434 ERR("Failed to allocate shader buffer memory.\n");
438 string_buffer_clear(buffer
);
442 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
444 heap_free(buffer
->buffer
);
447 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
450 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
452 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
453 new_buffer_size
*= 2;
454 if (!(new_buffer
= heap_realloc(buffer
->buffer
, new_buffer_size
)))
456 ERR("Failed to grow buffer.\n");
457 buffer
->buffer
[buffer
->content_size
] = '\0';
460 buffer
->buffer
= new_buffer
;
461 buffer
->buffer_size
= new_buffer_size
;
465 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
470 rem
= buffer
->buffer_size
- buffer
->content_size
;
471 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
472 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
475 buffer
->content_size
+= rc
;
479 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
486 va_start(args
, format
);
487 ret
= shader_vaddline(buffer
, format
, args
);
491 if (!string_buffer_resize(buffer
, ret
))
496 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
498 struct wined3d_string_buffer
*buffer
;
500 if (list_empty(&list
->list
))
502 buffer
= heap_alloc(sizeof(*buffer
));
503 if (!buffer
|| !string_buffer_init(buffer
))
505 ERR("Couldn't allocate buffer for temporary string.\n");
512 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
513 list_remove(&buffer
->entry
);
515 string_buffer_clear(buffer
);
519 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
523 string_buffer_clear(buffer
);
524 return shader_vaddline(buffer
, format
, args
);
527 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
534 va_start(args
, format
);
535 ret
= string_buffer_vsprintf(buffer
, format
, args
);
539 if (!string_buffer_resize(buffer
, ret
))
544 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
548 list_add_head(&list
->list
, &buffer
->entry
);
551 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
553 list_init(&list
->list
);
556 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
558 struct wined3d_string_buffer
*buffer
, *buffer_next
;
560 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
562 string_buffer_free(buffer
);
565 list_init(&list
->list
);
568 /* Convert floating point offset relative to a register file to an absolute
569 * offset for float constants. */
570 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
572 switch (register_type
)
574 case WINED3DSPR_CONST
: return register_idx
;
575 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
576 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
577 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
579 FIXME("Unsupported register type: %u.\n", register_type
);
584 static void shader_delete_constant_list(struct list
*clist
)
586 struct wined3d_shader_lconst
*constant
, *constant_next
;
588 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
593 static void shader_set_limits(struct wined3d_shader
*shader
)
595 static const struct limits_entry
597 unsigned int min_version
;
598 unsigned int max_version
;
599 struct wined3d_shader_limits limits
;
603 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
604 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
605 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
606 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
607 * even though they are capable of supporting much more (GL
608 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
609 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
611 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
612 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
613 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
618 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
619 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
623 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
624 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
628 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
629 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
630 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
635 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
636 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
637 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
638 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
639 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
640 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
641 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
646 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
647 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
649 const struct limits_entry
*limits_array
;
650 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
651 shader
->reg_maps
.shader_version
.minor
);
654 switch (shader
->reg_maps
.shader_version
.type
)
657 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
659 case WINED3D_SHADER_TYPE_VERTEX
:
660 limits_array
= vs_limits
;
662 case WINED3D_SHADER_TYPE_HULL
:
663 limits_array
= hs_limits
;
665 case WINED3D_SHADER_TYPE_DOMAIN
:
666 limits_array
= ds_limits
;
668 case WINED3D_SHADER_TYPE_GEOMETRY
:
669 limits_array
= gs_limits
;
671 case WINED3D_SHADER_TYPE_PIXEL
:
672 limits_array
= ps_limits
;
674 case WINED3D_SHADER_TYPE_COMPUTE
:
675 limits_array
= cs_limits
;
679 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
681 if (shader_version
<= limits_array
[i
].max_version
)
683 shader
->limits
= &limits_array
[i
].limits
;
690 FIXME("Unexpected shader version \"%u.%u\".\n",
691 shader
->reg_maps
.shader_version
.major
,
692 shader
->reg_maps
.shader_version
.minor
);
693 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
697 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
698 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
702 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
703 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
704 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
706 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
709 case WINED3DSPR_TEMP
:
710 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
713 case WINED3DSPR_INPUT
:
714 if (reg
->idx
[0].rel_addr
)
715 reg_maps
->input_rel_addressing
= 1;
716 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
718 /* If relative addressing is used, we must assume that all
719 * registers are used. Even if it is a construct like v3[aL],
720 * we can't assume that v0, v1 and v2 aren't read because aL
721 * can be negative. */
722 if (reg
->idx
[0].rel_addr
)
723 shader
->u
.ps
.input_reg_used
= ~0u;
725 shader
->u
.ps
.input_reg_used
|= 1u << reg
->idx
[0].offset
;
729 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
733 case WINED3DSPR_RASTOUT
:
734 if (reg
->idx
[0].offset
== 1)
736 if (reg
->idx
[0].offset
== 2)
737 reg_maps
->point_size
= 1;
740 case WINED3DSPR_MISCTYPE
:
741 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
743 if (!reg
->idx
[0].offset
)
745 else if (reg
->idx
[0].offset
== 1)
746 reg_maps
->usesfacing
= 1;
750 case WINED3DSPR_CONST
:
751 if (reg
->idx
[0].rel_addr
)
753 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
754 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
755 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
756 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
757 reg_maps
->usesrelconstF
= TRUE
;
761 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
763 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
768 wined3d_insert_bits(reg_maps
->constf
, reg
->idx
[0].offset
, 1, 0x1);
773 case WINED3DSPR_CONSTINT
:
774 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
776 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
781 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
785 case WINED3DSPR_CONSTBOOL
:
786 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
788 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
793 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
797 case WINED3DSPR_COLOROUT
:
798 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
801 case WINED3DSPR_OUTCONTROLPOINT
:
805 case WINED3DSPR_SAMPLEMASK
:
806 reg_maps
->sample_mask
= 1;
810 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
811 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
817 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
818 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
820 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
821 struct wined3d_shader_sampler_map
*map
;
824 map
= ®_maps
->sampler_map
;
825 entries
= map
->entries
;
826 for (i
= 0; i
< map
->count
; ++i
)
828 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
834 if (!(entries
= heap_calloc(4, sizeof(*entries
))))
836 ERR("Failed to allocate sampler map entries.\n");
840 map
->entries
= entries
;
842 else if (map
->count
== map
->size
)
844 size_t new_size
= map
->size
* 2;
846 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
847 || !(entries
= heap_realloc(entries
, sizeof(*entries
) * new_size
)))
849 ERR("Failed to resize sampler map entries.\n");
852 map
->size
= new_size
;
853 map
->entries
= entries
;
856 entry
= &entries
[map
->count
++];
857 entry
->resource_idx
= resource_idx
;
858 entry
->sampler_idx
= sampler_idx
;
859 entry
->bind_idx
= bind_idx
;
862 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
866 case WINED3DSIH_M4x4
:
867 case WINED3DSIH_M3x4
:
868 return param
== 1 ? 3 : 0;
870 case WINED3DSIH_M4x3
:
871 case WINED3DSIH_M3x3
:
872 return param
== 1 ? 2 : 0;
874 case WINED3DSIH_M3x2
:
875 return param
== 1 ? 1 : 0;
882 static HRESULT
shader_reg_maps_add_tgsm(struct wined3d_shader_reg_maps
*reg_maps
,
883 unsigned int register_idx
, unsigned int size
, unsigned int stride
)
885 struct wined3d_shader_tgsm
*tgsm
;
887 if (register_idx
>= MAX_TGSM_REGISTERS
)
889 ERR("Invalid TGSM register index %u.\n", register_idx
);
892 if (reg_maps
->shader_version
.type
!= WINED3D_SHADER_TYPE_COMPUTE
)
894 FIXME("TGSM declarations are allowed only in compute shaders.\n");
898 if (!wined3d_array_reserve((void **)®_maps
->tgsm
, ®_maps
->tgsm_capacity
,
899 register_idx
+ 1, sizeof(*reg_maps
->tgsm
)))
900 return E_OUTOFMEMORY
;
902 reg_maps
->tgsm_count
= max(register_idx
+ 1, reg_maps
->tgsm_count
);
903 tgsm
= ®_maps
->tgsm
[register_idx
];
905 tgsm
->stride
= stride
;
909 static HRESULT
shader_record_shader_phase(struct wined3d_shader
*shader
,
910 struct wined3d_shader_phase
**current_phase
, const struct wined3d_shader_instruction
*ins
,
911 const DWORD
*current_instruction_ptr
, const DWORD
*previous_instruction_ptr
)
913 struct wined3d_shader_phase
*phase
;
915 if ((phase
= *current_phase
))
917 phase
->end
= previous_instruction_ptr
;
918 *current_phase
= NULL
;
921 if (shader
->reg_maps
.shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
923 ERR("Unexpected shader type %s.\n", debug_shader_type(shader
->reg_maps
.shader_version
.type
));
927 switch (ins
->handler_idx
)
929 case WINED3DSIH_HS_CONTROL_POINT_PHASE
:
930 if (shader
->u
.hs
.phases
.control_point
)
932 FIXME("Multiple control point phases.\n");
933 heap_free(shader
->u
.hs
.phases
.control_point
);
935 if (!(shader
->u
.hs
.phases
.control_point
= heap_alloc_zero(sizeof(*shader
->u
.hs
.phases
.control_point
))))
936 return E_OUTOFMEMORY
;
937 phase
= shader
->u
.hs
.phases
.control_point
;
939 case WINED3DSIH_HS_FORK_PHASE
:
940 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.fork
,
941 &shader
->u
.hs
.phases
.fork_size
, shader
->u
.hs
.phases
.fork_count
+ 1,
942 sizeof(*shader
->u
.hs
.phases
.fork
)))
943 return E_OUTOFMEMORY
;
944 phase
= &shader
->u
.hs
.phases
.fork
[shader
->u
.hs
.phases
.fork_count
++];
946 case WINED3DSIH_HS_JOIN_PHASE
:
947 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.join
,
948 &shader
->u
.hs
.phases
.join_size
, shader
->u
.hs
.phases
.join_count
+ 1,
949 sizeof(*shader
->u
.hs
.phases
.join
)))
950 return E_OUTOFMEMORY
;
951 phase
= &shader
->u
.hs
.phases
.join
[shader
->u
.hs
.phases
.join_count
++];
954 ERR("Unexpected opcode %s.\n", debug_d3dshaderinstructionhandler(ins
->handler_idx
));
958 phase
->start
= current_instruction_ptr
;
959 *current_phase
= phase
;
964 static HRESULT
shader_calculate_clip_or_cull_distance_mask(
965 const struct wined3d_shader_signature_element
*e
, unsigned int *mask
)
967 /* Clip and cull distances are packed in 4 component registers. 0 and 1 are
968 * the only allowed semantic indices.
970 if (e
->semantic_idx
>= WINED3D_MAX_CLIP_DISTANCES
/ 4)
973 WARN("Invalid clip/cull distance index %u.\n", e
->semantic_idx
);
974 return WINED3DERR_INVALIDCALL
;
977 *mask
= (e
->mask
& WINED3DSP_WRITEMASK_ALL
) << (4 * e
->semantic_idx
);
981 static void wined3d_insert_interpolation_mode(DWORD
*packed_interpolation_mode
,
982 unsigned int register_idx
, enum wined3d_shader_interpolation_mode mode
)
984 if (mode
> WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
)
985 FIXME("Unexpected interpolation mode %#x.\n", mode
);
987 wined3d_insert_bits(packed_interpolation_mode
,
988 register_idx
* WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, mode
);
991 static HRESULT
shader_scan_output_signature(struct wined3d_shader
*shader
)
993 const struct wined3d_shader_signature
*output_signature
= &shader
->output_signature
;
994 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
998 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1000 const struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1003 reg_maps
->output_registers
|= 1u << e
->register_idx
;
1004 if (e
->sysval_semantic
== WINED3D_SV_CLIP_DISTANCE
)
1006 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1008 reg_maps
->clip_distance_mask
|= mask
;
1010 else if (e
->sysval_semantic
== WINED3D_SV_CULL_DISTANCE
)
1012 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1014 reg_maps
->cull_distance_mask
|= mask
;
1016 else if (e
->sysval_semantic
== WINED3D_SV_VIEWPORT_ARRAY_INDEX
)
1018 reg_maps
->viewport_array
= 1;
1025 /* Note that this does not count the loop register as an address register. */
1026 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, DWORD constf_size
)
1028 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
1029 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
1030 struct wined3d_shader_signature
*output_signature
= &shader
->output_signature
;
1031 struct wined3d_shader_signature
*input_signature
= &shader
->input_signature
;
1032 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
1033 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
1034 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
1035 struct wined3d_shader_version shader_version
;
1036 struct wined3d_shader_phase
*phase
= NULL
;
1037 const DWORD
*ptr
, *prev_ins
, *current_ins
;
1038 void *fe_data
= shader
->frontend_data
;
1042 memset(reg_maps
, 0, sizeof(*reg_maps
));
1043 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
1044 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
1045 reg_maps
->min_rel_offset
= ~0U;
1046 list_init(®_maps
->indexable_temps
);
1048 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1049 prev_ins
= current_ins
= ptr
;
1050 reg_maps
->shader_version
= shader_version
;
1052 shader_set_limits(shader
);
1054 if (!(reg_maps
->constf
= heap_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
1055 sizeof(*reg_maps
->constf
))))
1057 ERR("Failed to allocate constant map memory.\n");
1058 return E_OUTOFMEMORY
;
1061 while (!fe
->shader_is_end(fe_data
, &ptr
))
1063 struct wined3d_shader_instruction ins
;
1067 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1069 /* Unhandled opcode, and its parameters. */
1070 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1072 WARN("Encountered unrecognised or invalid instruction.\n");
1073 return WINED3DERR_INVALIDCALL
;
1076 /* Handle declarations. */
1077 if (ins
.handler_idx
== WINED3DSIH_DCL
1078 || ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
1080 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
1081 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
1083 switch (semantic
->reg
.reg
.type
)
1085 /* Mark input registers used. */
1086 case WINED3DSPR_INPUT
:
1087 if (reg_idx
>= MAX_REG_INPUT
)
1089 ERR("Invalid input register index %u.\n", reg_idx
);
1092 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
1093 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
1094 return WINED3DERR_INVALIDCALL
;
1095 reg_maps
->input_registers
|= 1u << reg_idx
;
1096 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
1099 /* Vertex shader: mark 3.0 output registers used, save token. */
1100 case WINED3DSPR_OUTPUT
:
1101 if (reg_idx
>= MAX_REG_OUTPUT
)
1103 ERR("Invalid output register index %u.\n", reg_idx
);
1106 reg_maps
->output_registers
|= 1u << reg_idx
;
1107 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
1108 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
1110 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
1111 reg_maps
->point_size
= 1;
1114 case WINED3DSPR_SAMPLER
:
1115 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1116 case WINED3DSPR_RESOURCE
:
1117 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1119 ERR("Invalid resource index %u.\n", reg_idx
);
1122 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
1123 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1124 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1127 case WINED3DSPR_UAV
:
1128 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1130 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1133 reg_maps
->uav_resource_info
[reg_idx
].type
= semantic
->resource_type
;
1134 reg_maps
->uav_resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1136 FIXME("Ignoring typed UAV flags %#x.\n", ins
.flags
);
1140 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
1144 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1146 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
1147 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
1149 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
1153 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
1154 wined3d_bitmap_set(®_maps
->cb_map
, reg
->idx
[0].offset
);
1157 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
1159 if (ins
.flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1161 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1162 shader
->u
.ps
.force_early_depth_stencil
= TRUE
;
1164 FIXME("Invalid instruction %#x for shader type %#x.\n",
1165 ins
.handler_idx
, shader_version
.type
);
1169 WARN("Ignoring global flags %#x.\n", ins
.flags
);
1172 else if (ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
)
1174 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1175 shader
->u
.gs
.instance_count
= ins
.declaration
.count
;
1177 FIXME("Invalid instruction %#x for shader type %#x.\n",
1178 ins
.handler_idx
, shader_version
.type
);
1180 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
1181 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
)
1184 phase
->instance_count
= ins
.declaration
.count
;
1186 FIXME("Instruction %s outside of shader phase.\n",
1187 debug_d3dshaderinstructionhandler(ins
.handler_idx
));
1189 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
1192 FIXME("Multiple immediate constant buffers.\n");
1193 reg_maps
->icb
= ins
.declaration
.icb
;
1195 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
1199 FIXME("Indexable temporary registers not supported.\n");
1203 struct wined3d_shader_indexable_temp
*reg
;
1205 if (!(reg
= heap_alloc(sizeof(*reg
))))
1206 return E_OUTOFMEMORY
;
1208 *reg
= ins
.declaration
.indexable_temp
;
1209 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
1212 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
1214 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1215 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
.type
;
1217 FIXME("Invalid instruction %#x for shader type %#x.\n",
1218 ins
.handler_idx
, shader_version
.type
);
1220 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
1222 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1223 if (reg_idx
>= MAX_REG_INPUT
)
1225 ERR("Invalid register index %u.\n", reg_idx
);
1228 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1229 wined3d_insert_interpolation_mode(shader
->u
.ps
.interpolation_mode
, reg_idx
, ins
.flags
);
1231 FIXME("Invalid instruction %#x for shader type %#x.\n",
1232 ins
.handler_idx
, shader_version
.type
);
1234 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
1236 if (ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUT
1237 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTGE
1238 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTLE
)
1240 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1241 shader
->u
.ps
.depth_output
= ins
.declaration
.dst
.reg
.type
;
1243 FIXME("Invalid instruction %#x for shader type %#x.\n",
1244 ins
.handler_idx
, shader_version
.type
);
1247 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
1249 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1250 shader
->u
.hs
.output_vertex_count
= ins
.declaration
.count
;
1252 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1254 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1256 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1257 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
.type
;
1259 FIXME("Invalid instruction %#x for shader type %#x.\n",
1260 ins
.handler_idx
, shader_version
.type
);
1262 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
1264 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1265 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1267 ERR("Invalid resource index %u.\n", reg_idx
);
1270 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1271 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1272 reg_maps
->resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1273 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1275 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
1277 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1278 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1280 ERR("Invalid resource index %u.\n", reg_idx
);
1283 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1284 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1285 reg_maps
->resource_info
[reg_idx
].flags
= 0;
1286 reg_maps
->resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1287 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1289 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
1291 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
1292 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
1294 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
1297 phase
->temporary_count
= ins
.declaration
.count
;
1299 reg_maps
->temporary_count
= ins
.declaration
.count
;
1301 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
1303 if (shader_version
.type
== WINED3D_SHADER_TYPE_DOMAIN
)
1304 shader
->u
.ds
.tessellator_domain
= ins
.declaration
.tessellator_domain
;
1305 else if (shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
1306 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1308 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
1310 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1311 shader
->u
.hs
.tessellator_output_primitive
= ins
.declaration
.tessellator_output_primitive
;
1313 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1315 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
1317 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1318 shader
->u
.hs
.tessellator_partitioning
= ins
.declaration
.tessellator_partitioning
;
1320 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1322 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
1324 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
, ins
.declaration
.tgsm_raw
.reg
.reg
.idx
[0].offset
,
1325 ins
.declaration
.tgsm_raw
.byte_count
/ 4, 0)))
1328 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
1330 unsigned int stride
= ins
.declaration
.tgsm_structured
.byte_stride
/ 4;
1331 unsigned int size
= stride
* ins
.declaration
.tgsm_structured
.structure_count
;
1332 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
,
1333 ins
.declaration
.tgsm_structured
.reg
.reg
.idx
[0].offset
, size
, stride
)))
1336 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
1338 if (shader_version
.type
== WINED3D_SHADER_TYPE_COMPUTE
)
1340 shader
->u
.cs
.thread_group_size
= ins
.declaration
.thread_group_size
;
1344 FIXME("Invalid instruction %#x for shader type %#x.\n",
1345 ins
.handler_idx
, shader_version
.type
);
1348 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
1350 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1351 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1353 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1357 FIXME("Ignoring raw UAV flags %#x.\n", ins
.flags
);
1358 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1359 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1360 reg_maps
->uav_resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1362 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
1364 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1365 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1367 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1371 FIXME("Ignoring structured UAV flags %#x.\n", ins
.flags
);
1372 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1373 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1374 reg_maps
->uav_resource_info
[reg_idx
].flags
= 0;
1375 reg_maps
->uav_resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1377 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1379 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1380 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1382 FIXME("Invalid instruction %#x for shader type %#x.\n",
1383 ins
.handler_idx
, shader_version
.type
);
1385 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1387 struct wined3d_shader_lconst
*lconst
;
1390 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1391 return E_OUTOFMEMORY
;
1393 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1394 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1395 value
= (float *)lconst
->value
;
1397 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1398 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1400 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1401 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1402 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1403 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1404 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1405 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1406 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1407 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1410 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1412 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1413 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1415 shader
->lconst_inf_or_nan
= TRUE
;
1418 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1420 struct wined3d_shader_lconst
*lconst
;
1422 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1423 return E_OUTOFMEMORY
;
1425 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1426 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1428 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1429 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1431 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1433 struct wined3d_shader_lconst
*lconst
;
1435 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1436 return E_OUTOFMEMORY
;
1438 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1439 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1441 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1442 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1444 /* Handle shader phases. */
1445 else if (ins
.handler_idx
== WINED3DSIH_HS_CONTROL_POINT_PHASE
1446 || ins
.handler_idx
== WINED3DSIH_HS_FORK_PHASE
1447 || ins
.handler_idx
== WINED3DSIH_HS_JOIN_PHASE
)
1449 if (FAILED(hr
= shader_record_shader_phase(shader
, &phase
, &ins
, current_ins
, prev_ins
)))
1452 /* For subroutine prototypes. */
1453 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1455 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1457 /* Set texture, address, temporary registers. */
1460 BOOL color0_mov
= FALSE
;
1463 /* This will loop over all the registers and try to
1464 * make a bitmask of the ones we're interested in.
1466 * Relative addressing tokens are ignored, but that's
1467 * okay, since we'll catch any address registers when
1468 * they are initialized (required by spec). */
1469 for (i
= 0; i
< ins
.dst_count
; ++i
)
1471 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1472 shader_version
.type
, constf_size
))
1473 return WINED3DERR_INVALIDCALL
;
1475 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1477 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1479 switch (ins
.dst
[i
].reg
.type
)
1481 case WINED3DSPR_RASTOUT
:
1482 if (shader_version
.major
>= 3)
1487 reg_maps
->output_registers
|= 1u << 10;
1488 shader_signature_from_usage(&output_signature_elements
[10],
1489 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1493 reg_maps
->output_registers
|= 1u << 11;
1494 shader_signature_from_usage(&output_signature_elements
[11],
1495 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1499 reg_maps
->output_registers
|= 1u << 11;
1500 shader_signature_from_usage(&output_signature_elements
[11],
1501 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1506 case WINED3DSPR_ATTROUT
:
1507 if (shader_version
.major
>= 3)
1512 if (reg_maps
->output_registers
& (1u << idx
))
1514 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1518 reg_maps
->output_registers
|= 1u << idx
;
1519 shader_signature_from_usage(&output_signature_elements
[idx
],
1520 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1525 case WINED3DSPR_TEXCRDOUT
: /* WINED3DSPR_OUTPUT */
1526 if (shader_version
.major
>= 3)
1528 if (idx
>= ARRAY_SIZE(reg_maps
->u
.output_registers_mask
))
1530 WARN("Invalid output register index %u.\n", idx
);
1533 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1536 if (idx
>= ARRAY_SIZE(reg_maps
->u
.texcoord_mask
))
1538 WARN("Invalid texcoord index %u.\n", idx
);
1541 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1542 if (reg_maps
->output_registers
& (1u << idx
))
1544 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1548 reg_maps
->output_registers
|= 1u << idx
;
1549 shader_signature_from_usage(&output_signature_elements
[idx
],
1550 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1559 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1561 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1563 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1564 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1565 * the mov and perform the sRGB write correction from the source register.
1567 * However, if the mov is only partial, we can't do this, and if the write
1568 * comes from an instruction other than MOV it is hard to do as well. If
1569 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1570 shader
->u
.ps
.color0_mov
= FALSE
;
1571 if (ins
.handler_idx
== WINED3DSIH_MOV
1572 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1574 /* Used later when the source register is read. */
1578 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1581 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1582 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1584 shader
->u
.ps
.color0_mov
= FALSE
;
1588 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1589 if (shader_version
.major
== 1
1590 && (ins
.handler_idx
== WINED3DSIH_TEX
1591 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1592 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1593 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1594 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1595 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1596 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1597 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1598 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1599 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1600 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1602 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1604 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1606 WARN("Invalid 1.x sampler index %u.\n", reg_idx
);
1610 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1611 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1612 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1613 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1614 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1616 /* texbem is only valid with < 1.4 pixel shaders */
1617 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1618 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1620 reg_maps
->bumpmat
|= 1u << reg_idx
;
1621 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1623 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1627 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1629 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1633 if (ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_ALLOC
|| ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_CONSUME
)
1635 unsigned int reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1636 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1638 ERR("Invalid UAV index %u.\n", reg_idx
);
1641 reg_maps
->uav_counter_mask
|= (1u << reg_idx
);
1643 else if ((WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1644 || (WINED3DSIH_IMM_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_IMM_ATOMIC_XOR
)
1645 || (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_UAV
)
1646 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
1647 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_UAV
)
1648 || (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
&& ins
.src
[2].reg
.type
== WINED3DSPR_UAV
))
1650 const struct wined3d_shader_register
*reg
;
1652 if (ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
|| ins
.handler_idx
== WINED3DSIH_LD_RAW
)
1653 reg
= &ins
.src
[1].reg
;
1654 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
)
1655 reg
= &ins
.src
[2].reg
;
1656 else if (WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1657 reg
= &ins
.dst
[0].reg
;
1658 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
)
1659 reg
= &ins
.src
[0].reg
;
1661 reg
= &ins
.dst
[1].reg
;
1663 if (reg
->type
== WINED3DSPR_UAV
)
1665 if (reg
->idx
[0].offset
>= MAX_UNORDERED_ACCESS_VIEWS
)
1667 ERR("Invalid UAV index %u.\n", reg
->idx
[0].offset
);
1670 reg_maps
->uav_read_mask
|= (1u << reg
->idx
[0].offset
);
1673 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1675 reg_maps
->usesnrm
= 1;
1677 else if (ins
.handler_idx
== WINED3DSIH_DSY
1678 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1679 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1681 reg_maps
->usesdsy
= 1;
1683 else if (ins
.handler_idx
== WINED3DSIH_DSX
1684 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1685 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1687 reg_maps
->usesdsx
= 1;
1689 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1690 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1691 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1692 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1693 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1694 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1695 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1696 || ins
.handler_idx
== WINED3DSIH_REP
)
1699 if (cur_loop_depth
> max_loop_depth
)
1700 max_loop_depth
= cur_loop_depth
;
1702 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1703 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1707 else if (ins
.handler_idx
== WINED3DSIH_GATHER4
1708 || ins
.handler_idx
== WINED3DSIH_GATHER4_C
1709 || ins
.handler_idx
== WINED3DSIH_SAMPLE
1710 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1711 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1712 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1713 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1714 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1716 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1717 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1719 else if (ins
.handler_idx
== WINED3DSIH_GATHER4_PO
1720 || ins
.handler_idx
== WINED3DSIH_GATHER4_PO_C
)
1722 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1723 ins
.src
[3].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1725 else if ((ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
)
1726 || (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
))
1728 shader_record_sample(reg_maps
, ins
.src
[0].reg
.idx
[0].offset
,
1729 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1731 else if (ins
.handler_idx
== WINED3DSIH_LD
1732 || ins
.handler_idx
== WINED3DSIH_LD2DMS
1733 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
)
1734 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1736 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1737 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1739 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
1740 && ins
.src
[2].reg
.type
== WINED3DSPR_RESOURCE
)
1742 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1743 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1747 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1748 shader_version
.type
, constf_size
))
1749 return WINED3DERR_INVALIDCALL
;
1751 for (i
= 0; i
< ins
.src_count
; ++i
)
1753 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1754 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1756 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1757 shader_version
.type
, constf_size
))
1758 return WINED3DERR_INVALIDCALL
;
1761 ++reg
.idx
[0].offset
;
1762 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1763 shader_version
.type
, constf_size
))
1764 return WINED3DERR_INVALIDCALL
;
1770 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1771 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1773 shader
->u
.ps
.color0_mov
= TRUE
;
1774 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1780 prev_ins
= current_ins
;
1782 reg_maps
->loop_depth
= max_loop_depth
;
1786 phase
->end
= prev_ins
;
1790 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1791 * R0 is written to the render target. */
1792 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1793 reg_maps
->rt_mask
|= (1u << 0);
1795 if (input_signature
->elements
)
1797 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1799 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1801 if (input_signature
->elements
[i
].register_idx
>= ARRAY_SIZE(shader
->u
.vs
.attributes
))
1803 WARN("Invalid input signature register index %u.\n", input_signature
->elements
[i
].register_idx
);
1804 return WINED3DERR_INVALIDCALL
;
1807 else if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1809 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1811 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1812 reg_maps
->usesfacing
= 1;
1814 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1817 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1819 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1820 struct wined3d_shader_signature_element
*e
;
1823 if (!(input_signature
->elements
= heap_calloc(count
, sizeof(*input_signature
->elements
))))
1824 return E_OUTOFMEMORY
;
1825 input_signature
->element_count
= count
;
1827 e
= input_signature
->elements
;
1828 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1830 if (!(reg_maps
->input_registers
& (1u << i
)))
1832 input_signature_elements
[i
].register_idx
= i
;
1833 *e
++ = input_signature_elements
[i
];
1837 if (output_signature
->elements
)
1839 if (FAILED(hr
= shader_scan_output_signature(shader
)))
1842 else if (reg_maps
->output_registers
)
1844 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1845 struct wined3d_shader_signature_element
*e
;
1847 if (!(output_signature
->elements
= heap_calloc(count
, sizeof(*output_signature
->elements
))))
1848 return E_OUTOFMEMORY
;
1849 output_signature
->element_count
= count
;
1851 e
= output_signature
->elements
;
1852 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1854 if (!(reg_maps
->output_registers
& (1u << i
)))
1856 *e
++ = output_signature_elements
[i
];
1863 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1865 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1867 heap_free(reg_maps
->constf
);
1868 heap_free(reg_maps
->sampler_map
.entries
);
1870 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1872 list_init(®_maps
->indexable_temps
);
1874 heap_free(reg_maps
->tgsm
);
1877 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1879 DWORD map
= 1u << max
;
1881 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1883 return wined3d_log2i(map
);
1886 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1888 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1890 shader_addline(buffer
, "refactoringAllowed");
1891 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1893 shader_addline(buffer
, " | ");
1896 if (global_flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1898 shader_addline(buffer
, "forceEarlyDepthStencil");
1899 global_flags
&= ~WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
;
1901 shader_addline(buffer
, " | ");
1904 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1906 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1907 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1911 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1914 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1916 if (sync_flags
& WINED3DSSF_GLOBAL_UAV
)
1918 shader_addline(buffer
, "_uglobal");
1919 sync_flags
&= ~WINED3DSSF_GLOBAL_UAV
;
1921 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1923 shader_addline(buffer
, "_g");
1924 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1926 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1928 shader_addline(buffer
, "_t");
1929 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1933 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1936 static void shader_dump_precise_flags(struct wined3d_string_buffer
*buffer
, DWORD flags
)
1938 if (!(flags
& WINED3DSI_PRECISE_XYZW
))
1941 shader_addline(buffer
, " [precise");
1942 if (flags
!= WINED3DSI_PRECISE_XYZW
)
1944 shader_addline(buffer
, "(%s%s%s%s)",
1945 flags
& WINED3DSI_PRECISE_X
? "x" : "",
1946 flags
& WINED3DSI_PRECISE_Y
? "y" : "",
1947 flags
& WINED3DSI_PRECISE_Z
? "z" : "",
1948 flags
& WINED3DSI_PRECISE_W
? "w" : "");
1950 shader_addline(buffer
, "]");
1953 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1955 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1957 shader_addline(buffer
, "_glc");
1958 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1960 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1962 shader_addline(buffer
, "_opc");
1963 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1967 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1970 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1971 enum wined3d_tessellator_domain domain
)
1975 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1976 shader_addline(buffer
, "line");
1978 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1979 shader_addline(buffer
, "triangle");
1981 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1982 shader_addline(buffer
, "quad");
1985 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1990 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1991 enum wined3d_tessellator_output_primitive output_primitive
)
1993 switch (output_primitive
)
1995 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1996 shader_addline(buffer
, "point");
1998 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1999 shader_addline(buffer
, "line");
2001 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
2002 shader_addline(buffer
, "triangle_cw");
2004 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
2005 shader_addline(buffer
, "triangle_ccw");
2008 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
2013 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
2014 enum wined3d_tessellator_partitioning partitioning
)
2016 switch (partitioning
)
2018 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
2019 shader_addline(buffer
, "integer");
2021 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
2022 shader_addline(buffer
, "pow2");
2024 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
2025 shader_addline(buffer
, "fractional_odd");
2027 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
2028 shader_addline(buffer
, "fractional_even");
2031 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
2036 static void shader_dump_shader_input_sysval_semantic(struct wined3d_string_buffer
*buffer
,
2037 enum wined3d_shader_input_sysval_semantic semantic
)
2041 for (i
= 0; i
< ARRAY_SIZE(shader_input_sysval_semantic_names
); ++i
)
2043 if (shader_input_sysval_semantic_names
[i
].sysval_semantic
== semantic
)
2045 shader_addline(buffer
, "%s", shader_input_sysval_semantic_names
[i
].sysval_name
);
2050 shader_addline(buffer
, "unknown_shader_input_sysval_semantic(%#x)", semantic
);
2053 static void shader_dump_resource_type(struct wined3d_string_buffer
*buffer
, enum wined3d_shader_resource_type type
)
2055 static const char *const resource_type_names
[] =
2057 /* WINED3D_SHADER_RESOURCE_NONE */ "none",
2058 /* WINED3D_SHADER_RESOURCE_BUFFER */ "buffer",
2059 /* WINED3D_SHADER_RESOURCE_TEXTURE_1D */ "texture1d",
2060 /* WINED3D_SHADER_RESOURCE_TEXTURE_2D */ "texture2d",
2061 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DMS */ "texture2dms",
2062 /* WINED3D_SHADER_RESOURCE_TEXTURE_3D */ "texture3d",
2063 /* WINED3D_SHADER_RESOURCE_TEXTURE_CUBE */ "texturecube",
2064 /* WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY */ "texture1darray",
2065 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY */ "texture2darray",
2066 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY */ "texture2dmsarray",
2067 /* WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY */ "texturecubearray",
2070 if (type
< ARRAY_SIZE(resource_type_names
))
2071 shader_addline(buffer
, "%s", resource_type_names
[type
]);
2073 shader_addline(buffer
, "unknown");
2076 static void shader_dump_data_type(struct wined3d_string_buffer
*buffer
, enum wined3d_data_type type
)
2078 static const char *const data_type_names
[] =
2080 /* WINED3D_DATA_FLOAT */ "(float)",
2081 /* WINED3D_DATA_INT */ "(int)",
2082 /* WINED3D_DATA_RESOURCE */ "(resource)",
2083 /* WINED3D_DATA_SAMPLER */ "(sampler)",
2084 /* WINED3D_DATA_UAV */ "(uav)",
2085 /* WINED3D_DATA_UINT */ "(uint)",
2086 /* WINED3D_DATA_UNORM */ "(unorm)",
2087 /* WINED3D_DATA_SNORM */ "(snorm)",
2088 /* WINED3D_DATA_OPAQUE */ "(opaque)",
2091 if (type
< ARRAY_SIZE(data_type_names
))
2092 shader_addline(buffer
, "%s", data_type_names
[type
]);
2094 shader_addline(buffer
, "(unknown)");
2097 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
2098 const struct wined3d_shader_semantic
*semantic
, unsigned int flags
,
2099 const struct wined3d_shader_version
*shader_version
)
2101 shader_addline(buffer
, "dcl");
2103 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
2105 switch (semantic
->resource_type
)
2107 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2108 shader_addline(buffer
, "_2d");
2111 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2112 shader_addline(buffer
, "_3d");
2115 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2116 shader_addline(buffer
, "_cube");
2120 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
2124 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2126 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
2127 shader_addline(buffer
, "_resource_");
2129 shader_addline(buffer
, "_uav_");
2130 shader_dump_resource_type(buffer
, semantic
->resource_type
);
2131 if (semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2132 shader_dump_uav_flags(buffer
, flags
);
2133 shader_dump_data_type(buffer
, semantic
->resource_data_type
);
2137 /* Pixel shaders 3.0 don't have usage semantics. */
2138 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
2141 shader_addline(buffer
, "_");
2143 switch (semantic
->usage
)
2145 case WINED3D_DECL_USAGE_POSITION
:
2146 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
2149 case WINED3D_DECL_USAGE_BLEND_INDICES
:
2150 shader_addline(buffer
, "blend");
2153 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
2154 shader_addline(buffer
, "weight");
2157 case WINED3D_DECL_USAGE_NORMAL
:
2158 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
2161 case WINED3D_DECL_USAGE_PSIZE
:
2162 shader_addline(buffer
, "psize");
2165 case WINED3D_DECL_USAGE_COLOR
:
2166 if (!semantic
->usage_idx
)
2167 shader_addline(buffer
, "color");
2169 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
2172 case WINED3D_DECL_USAGE_TEXCOORD
:
2173 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
2176 case WINED3D_DECL_USAGE_TANGENT
:
2177 shader_addline(buffer
, "tangent");
2180 case WINED3D_DECL_USAGE_BINORMAL
:
2181 shader_addline(buffer
, "binormal");
2184 case WINED3D_DECL_USAGE_TESS_FACTOR
:
2185 shader_addline(buffer
, "tessfactor");
2188 case WINED3D_DECL_USAGE_POSITIONT
:
2189 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
2192 case WINED3D_DECL_USAGE_FOG
:
2193 shader_addline(buffer
, "fog");
2196 case WINED3D_DECL_USAGE_DEPTH
:
2197 shader_addline(buffer
, "depth");
2200 case WINED3D_DECL_USAGE_SAMPLE
:
2201 shader_addline(buffer
, "sample");
2205 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
2206 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
2211 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
2212 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
2214 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
2215 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
2216 UINT offset
= reg
->idx
[0].offset
;
2220 case WINED3DSPR_TEMP
:
2221 shader_addline(buffer
, "r");
2224 case WINED3DSPR_INPUT
:
2225 shader_addline(buffer
, "v");
2228 case WINED3DSPR_CONST
:
2229 case WINED3DSPR_CONST2
:
2230 case WINED3DSPR_CONST3
:
2231 case WINED3DSPR_CONST4
:
2232 shader_addline(buffer
, "c");
2233 offset
= shader_get_float_offset(reg
->type
, offset
);
2236 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
2237 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
2240 case WINED3DSPR_RASTOUT
:
2241 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
2244 case WINED3DSPR_COLOROUT
:
2245 shader_addline(buffer
, "oC");
2248 case WINED3DSPR_DEPTHOUT
:
2249 shader_addline(buffer
, "oDepth");
2252 case WINED3DSPR_DEPTHOUTGE
:
2253 shader_addline(buffer
, "oDepthGE");
2256 case WINED3DSPR_DEPTHOUTLE
:
2257 shader_addline(buffer
, "oDepthLE");
2260 case WINED3DSPR_ATTROUT
:
2261 shader_addline(buffer
, "oD");
2264 case WINED3DSPR_TEXCRDOUT
:
2265 /* Vertex shaders >= 3.0 use general purpose output registers
2266 * (WINED3DSPR_OUTPUT), which can include an address token. */
2267 if (shader_version
->major
>= 3)
2268 shader_addline(buffer
, "o");
2270 shader_addline(buffer
, "oT");
2273 case WINED3DSPR_CONSTINT
:
2274 shader_addline(buffer
, "i");
2277 case WINED3DSPR_CONSTBOOL
:
2278 shader_addline(buffer
, "b");
2281 case WINED3DSPR_LABEL
:
2282 shader_addline(buffer
, "l");
2285 case WINED3DSPR_LOOP
:
2286 shader_addline(buffer
, "aL");
2289 case WINED3DSPR_SAMPLER
:
2290 shader_addline(buffer
, "s");
2293 case WINED3DSPR_MISCTYPE
:
2296 FIXME("Unhandled misctype register %u.\n", offset
);
2297 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
2301 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
2305 case WINED3DSPR_PREDICATE
:
2306 shader_addline(buffer
, "p");
2309 case WINED3DSPR_IMMCONST
:
2310 shader_addline(buffer
, "l");
2313 case WINED3DSPR_CONSTBUFFER
:
2314 shader_addline(buffer
, "cb");
2317 case WINED3DSPR_IMMCONSTBUFFER
:
2318 shader_addline(buffer
, "icb");
2321 case WINED3DSPR_PRIMID
:
2322 shader_addline(buffer
, "primID");
2325 case WINED3DSPR_NULL
:
2326 shader_addline(buffer
, "null");
2329 case WINED3DSPR_RASTERIZER
:
2330 shader_addline(buffer
, "rasterizer");
2333 case WINED3DSPR_RESOURCE
:
2334 shader_addline(buffer
, "t");
2337 case WINED3DSPR_UAV
:
2338 shader_addline(buffer
, "u");
2341 case WINED3DSPR_OUTPOINTID
:
2342 shader_addline(buffer
, "vOutputControlPointID");
2345 case WINED3DSPR_FORKINSTID
:
2346 shader_addline(buffer
, "vForkInstanceId");
2349 case WINED3DSPR_JOININSTID
:
2350 shader_addline(buffer
, "vJoinInstanceId");
2353 case WINED3DSPR_INCONTROLPOINT
:
2354 shader_addline(buffer
, "vicp");
2357 case WINED3DSPR_OUTCONTROLPOINT
:
2358 shader_addline(buffer
, "vocp");
2361 case WINED3DSPR_PATCHCONST
:
2362 shader_addline(buffer
, "vpc");
2365 case WINED3DSPR_TESSCOORD
:
2366 shader_addline(buffer
, "vDomainLocation");
2369 case WINED3DSPR_GROUPSHAREDMEM
:
2370 shader_addline(buffer
, "g");
2373 case WINED3DSPR_THREADID
:
2374 shader_addline(buffer
, "vThreadID");
2377 case WINED3DSPR_THREADGROUPID
:
2378 shader_addline(buffer
, "vThreadGroupID");
2381 case WINED3DSPR_LOCALTHREADID
:
2382 shader_addline(buffer
, "vThreadIDInGroup");
2385 case WINED3DSPR_LOCALTHREADINDEX
:
2386 shader_addline(buffer
, "vThreadIDInGroupFlattened");
2389 case WINED3DSPR_IDXTEMP
:
2390 shader_addline(buffer
, "x");
2393 case WINED3DSPR_STREAM
:
2394 shader_addline(buffer
, "m");
2397 case WINED3DSPR_FUNCTIONBODY
:
2398 shader_addline(buffer
, "fb");
2401 case WINED3DSPR_FUNCTIONPOINTER
:
2402 shader_addline(buffer
, "fp");
2405 case WINED3DSPR_COVERAGE
:
2406 shader_addline(buffer
, "vCoverage");
2409 case WINED3DSPR_SAMPLEMASK
:
2410 shader_addline(buffer
, "oMask");
2413 case WINED3DSPR_GSINSTID
:
2414 shader_addline(buffer
, "vGSInstanceID");
2418 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
2422 if (reg
->type
== WINED3DSPR_IMMCONST
)
2424 shader_addline(buffer
, "(");
2425 switch (reg
->immconst_type
)
2427 case WINED3D_IMMCONST_SCALAR
:
2428 switch (reg
->data_type
)
2430 case WINED3D_DATA_FLOAT
:
2431 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
2433 case WINED3D_DATA_INT
:
2434 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
2436 case WINED3D_DATA_RESOURCE
:
2437 case WINED3D_DATA_SAMPLER
:
2438 case WINED3D_DATA_UINT
:
2439 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
2442 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2447 case WINED3D_IMMCONST_VEC4
:
2448 switch (reg
->data_type
)
2450 case WINED3D_DATA_FLOAT
:
2451 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2452 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2453 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2455 case WINED3D_DATA_INT
:
2456 shader_addline(buffer
, "%d, %d, %d, %d",
2457 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2458 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2460 case WINED3D_DATA_RESOURCE
:
2461 case WINED3D_DATA_SAMPLER
:
2462 case WINED3D_DATA_UINT
:
2463 shader_addline(buffer
, "%u, %u, %u, %u",
2464 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2465 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2468 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2474 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2477 shader_addline(buffer
, ")");
2479 else if (reg
->type
!= WINED3DSPR_RASTOUT
2480 && reg
->type
!= WINED3DSPR_MISCTYPE
2481 && reg
->type
!= WINED3DSPR_NULL
)
2485 shader_addline(buffer
, "[");
2486 if (reg
->idx
[0].rel_addr
)
2488 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2489 shader_addline(buffer
, " + ");
2491 shader_addline(buffer
, "%u]", offset
);
2493 if (reg
->idx
[1].offset
!= ~0u)
2495 shader_addline(buffer
, "[");
2496 if (reg
->idx
[1].rel_addr
)
2498 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2499 shader_addline(buffer
, " + ");
2501 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2505 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2506 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2510 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2511 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2513 DWORD write_mask
= param
->write_mask
;
2515 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2517 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2519 static const char write_mask_chars
[] = "xyzw";
2521 shader_addline(buffer
, ".");
2522 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2523 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2524 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2525 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2526 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2527 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2528 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2529 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2533 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2534 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2536 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2537 DWORD swizzle
= param
->swizzle
;
2539 if (src_modifier
== WINED3DSPSM_NEG
2540 || src_modifier
== WINED3DSPSM_BIASNEG
2541 || src_modifier
== WINED3DSPSM_SIGNNEG
2542 || src_modifier
== WINED3DSPSM_X2NEG
2543 || src_modifier
== WINED3DSPSM_ABSNEG
)
2544 shader_addline(buffer
, "-");
2545 else if (src_modifier
== WINED3DSPSM_COMP
)
2546 shader_addline(buffer
, "1-");
2547 else if (src_modifier
== WINED3DSPSM_NOT
)
2548 shader_addline(buffer
, "!");
2550 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2551 shader_addline(buffer
, "abs(");
2553 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2555 switch (src_modifier
)
2557 case WINED3DSPSM_NONE
: break;
2558 case WINED3DSPSM_NEG
: break;
2559 case WINED3DSPSM_NOT
: break;
2560 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2561 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2562 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2563 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2564 case WINED3DSPSM_COMP
: break;
2565 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2566 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2567 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2568 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2569 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2570 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2571 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2574 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2576 static const char swizzle_chars
[] = "xyzw";
2577 DWORD swizzle_x
= swizzle
& 0x03;
2578 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2579 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2580 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2582 if (swizzle_x
== swizzle_y
2583 && swizzle_x
== swizzle_z
2584 && swizzle_x
== swizzle_w
)
2586 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2590 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2591 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2596 /* Shared code in order to generate the bulk of the shader string. */
2597 HRESULT
shader_generate_code(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2598 const struct wined3d_shader_reg_maps
*reg_maps
, void *backend_ctx
,
2599 const DWORD
*start
, const DWORD
*end
)
2601 struct wined3d_device
*device
= shader
->device
;
2602 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2603 void *fe_data
= shader
->frontend_data
;
2604 struct wined3d_shader_version shader_version
;
2605 struct wined3d_shader_parser_state state
;
2606 struct wined3d_shader_instruction ins
;
2607 struct wined3d_shader_tex_mx tex_mx
;
2608 struct wined3d_shader_context ctx
;
2611 /* Initialize current parsing state. */
2612 tex_mx
.current_row
= 0;
2613 state
.current_loop_depth
= 0;
2614 state
.current_loop_reg
= 0;
2615 state
.in_subroutine
= FALSE
;
2617 ctx
.shader
= shader
;
2618 ctx
.reg_maps
= reg_maps
;
2619 ctx
.buffer
= buffer
;
2620 ctx
.tex_mx
= &tex_mx
;
2622 ctx
.backend_data
= backend_ctx
;
2625 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2629 while (!fe
->shader_is_end(fe_data
, &ptr
) && ptr
!= end
)
2632 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2634 /* Unknown opcode and its parameters. */
2635 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2637 WARN("Encountered unrecognised or invalid instruction.\n");
2638 return WINED3DERR_INVALIDCALL
;
2642 FIXME("Predicates not implemented.\n");
2644 /* Call appropriate function for output target */
2645 device
->shader_backend
->shader_handle_instruction(&ins
);
2651 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2652 const struct wined3d_shader_dst_param
*dst
)
2654 DWORD mmask
= dst
->modifiers
;
2659 case 13: shader_addline(buffer
, "_d8"); break;
2660 case 14: shader_addline(buffer
, "_d4"); break;
2661 case 15: shader_addline(buffer
, "_d2"); break;
2662 case 1: shader_addline(buffer
, "_x2"); break;
2663 case 2: shader_addline(buffer
, "_x4"); break;
2664 case 3: shader_addline(buffer
, "_x8"); break;
2665 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2668 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2669 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2670 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2672 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2673 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2676 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2677 const struct wined3d_shader_primitive_type
*primitive_type
)
2679 switch (primitive_type
->type
)
2681 case WINED3D_PT_UNDEFINED
:
2682 shader_addline(buffer
, "undefined");
2684 case WINED3D_PT_POINTLIST
:
2685 shader_addline(buffer
, "pointlist");
2687 case WINED3D_PT_LINELIST
:
2688 shader_addline(buffer
, "linelist");
2690 case WINED3D_PT_LINESTRIP
:
2691 shader_addline(buffer
, "linestrip");
2693 case WINED3D_PT_TRIANGLELIST
:
2694 shader_addline(buffer
, "trianglelist");
2696 case WINED3D_PT_TRIANGLESTRIP
:
2697 shader_addline(buffer
, "trianglestrip");
2699 case WINED3D_PT_TRIANGLEFAN
:
2700 shader_addline(buffer
, "trianglefan");
2702 case WINED3D_PT_LINELIST_ADJ
:
2703 shader_addline(buffer
, "linelist_adj");
2705 case WINED3D_PT_LINESTRIP_ADJ
:
2706 shader_addline(buffer
, "linestrip_adj");
2708 case WINED3D_PT_TRIANGLELIST_ADJ
:
2709 shader_addline(buffer
, "trianglelist_adj");
2711 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2712 shader_addline(buffer
, "trianglestrip_adj");
2714 case WINED3D_PT_PATCH
:
2715 shader_addline(buffer
, "patch%u", primitive_type
->patch_vertex_count
);
2718 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
->type
);
2723 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2724 enum wined3d_shader_interpolation_mode interpolation_mode
)
2726 switch (interpolation_mode
)
2728 case WINED3DSIM_CONSTANT
:
2729 shader_addline(buffer
, "constant");
2731 case WINED3DSIM_LINEAR
:
2732 shader_addline(buffer
, "linear");
2734 case WINED3DSIM_LINEAR_CENTROID
:
2735 shader_addline(buffer
, "linear centroid");
2737 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2738 shader_addline(buffer
, "linear noperspective");
2740 case WINED3DSIM_LINEAR_SAMPLE
:
2741 shader_addline(buffer
, "linear sample");
2743 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2744 shader_addline(buffer
, "linear noperspective centroid");
2746 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2747 shader_addline(buffer
, "linear noperspective sample");
2750 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2755 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
)
2757 struct wined3d_shader_version shader_version
;
2758 struct wined3d_string_buffer buffer
;
2759 const char *type_prefix
;
2764 if (!string_buffer_init(&buffer
))
2766 ERR("Failed to initialize string buffer.\n");
2770 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2772 TRACE("Parsing %p.\n", ptr
);
2774 switch (shader_version
.type
)
2776 case WINED3D_SHADER_TYPE_VERTEX
:
2780 case WINED3D_SHADER_TYPE_HULL
:
2784 case WINED3D_SHADER_TYPE_DOMAIN
:
2788 case WINED3D_SHADER_TYPE_GEOMETRY
:
2792 case WINED3D_SHADER_TYPE_PIXEL
:
2796 case WINED3D_SHADER_TYPE_COMPUTE
:
2801 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2802 type_prefix
= "unknown";
2806 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2808 while (!fe
->shader_is_end(fe_data
, &ptr
))
2810 struct wined3d_shader_instruction ins
;
2812 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2813 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2815 WARN("Skipping unrecognized instruction.\n");
2816 shader_addline(&buffer
, "<unrecognized instruction>\n");
2820 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2822 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, ins
.flags
, &shader_version
);
2823 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2824 shader_addline(&buffer
, " ");
2825 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2827 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2829 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2830 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2831 shader_addline(&buffer
, ", %s",
2832 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2834 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2836 shader_addline(&buffer
, "%s fb%u",
2837 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2839 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2841 shader_addline(&buffer
, "%s ft%u = {...}",
2842 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2844 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2846 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2847 shader_dump_global_flags(&buffer
, ins
.flags
);
2849 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2851 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2852 ins
.declaration
.max_tessellation_factor
);
2854 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2856 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2857 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2859 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2860 ins
.declaration
.icb
->data
[4 * i
+ 0],
2861 ins
.declaration
.icb
->data
[4 * i
+ 1],
2862 ins
.declaration
.icb
->data
[4 * i
+ 2],
2863 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2865 shader_addline(&buffer
, "}");
2867 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEX_RANGE
)
2869 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2870 shader_dump_dst_param(&buffer
, &ins
.declaration
.index_range
.first_register
, &shader_version
);
2871 shader_addline(&buffer
, " %u", ins
.declaration
.index_range
.last_register
);
2873 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2875 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2876 ins
.declaration
.indexable_temp
.register_idx
,
2877 ins
.declaration
.indexable_temp
.register_size
,
2878 ins
.declaration
.indexable_temp
.component_count
);
2880 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2882 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2883 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2884 shader_addline(&buffer
, " ");
2885 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2887 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2888 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2889 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2890 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2892 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2893 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2894 shader_addline(&buffer
, ", ");
2895 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2897 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2899 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2900 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2901 shader_addline(&buffer
, " ");
2902 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2903 shader_addline(&buffer
, ", ");
2904 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2906 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2907 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2909 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2910 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2912 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2913 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2915 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2916 shader_dump_primitive_type(&buffer
, &ins
.declaration
.primitive_type
);
2918 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2920 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2921 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2922 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2924 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2926 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2927 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2929 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2931 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2932 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2933 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2935 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2937 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2938 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2939 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2940 shader_addline(&buffer
, ", comparisonMode");
2942 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2943 || ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
2944 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2945 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
2946 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2947 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
2948 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
2950 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2952 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2954 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2955 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2957 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2959 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2960 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2962 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2964 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2965 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2967 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2969 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2970 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2971 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2973 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2975 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2976 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2977 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2978 ins
.declaration
.tgsm_structured
.structure_count
);
2980 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2982 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2983 ins
.declaration
.thread_group_size
.x
,
2984 ins
.declaration
.thread_group_size
.y
,
2985 ins
.declaration
.thread_group_size
.z
);
2987 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2989 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2990 shader_dump_uav_flags(&buffer
, ins
.flags
);
2991 shader_addline(&buffer
, " ");
2992 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2994 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2996 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2997 shader_dump_uav_flags(&buffer
, ins
.flags
);
2998 shader_addline(&buffer
, " ");
2999 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
3000 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
3002 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
3004 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
3005 ins
.dst
[0].reg
.idx
[0].offset
),
3006 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
3007 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
3008 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
3009 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
3011 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
3013 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
3014 ins
.src
[0].reg
.u
.immconst_data
[0],
3015 ins
.src
[0].reg
.u
.immconst_data
[1],
3016 ins
.src
[0].reg
.u
.immconst_data
[2],
3017 ins
.src
[0].reg
.u
.immconst_data
[3]);
3019 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
3021 shader_addline(&buffer
, "defb b%u = %s",
3022 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
3028 shader_addline(&buffer
, "(");
3029 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
3030 shader_addline(&buffer
, ") ");
3033 /* PixWin marks instructions with the coissue flag with a '+' */
3035 shader_addline(&buffer
, "+");
3037 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
3039 if (ins
.handler_idx
== WINED3DSIH_BREAKP
3040 || ins
.handler_idx
== WINED3DSIH_CONTINUEP
3041 || ins
.handler_idx
== WINED3DSIH_IF
3042 || ins
.handler_idx
== WINED3DSIH_RETP
3043 || ins
.handler_idx
== WINED3DSIH_TEXKILL
)
3047 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
3048 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
3049 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
3052 else if (ins
.handler_idx
== WINED3DSIH_IFC
3053 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
3057 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
3058 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
3059 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
3060 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
3061 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
3062 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
3063 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
3066 else if (ins
.handler_idx
== WINED3DSIH_TEX
3067 && shader_version
.major
>= 2
3068 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
3070 shader_addline(&buffer
, "p");
3072 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
3076 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
3077 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3078 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3081 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
3085 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3086 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3089 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
3091 shader_dump_sync_flags(&buffer
, ins
.flags
);
3095 shader_dump_precise_flags(&buffer
, ins
.flags
);
3098 if (wined3d_shader_instruction_has_texel_offset(&ins
))
3099 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
3101 if (ins
.resource_type
!= WINED3D_SHADER_RESOURCE_NONE
)
3103 shader_addline(&buffer
, "(");
3104 shader_dump_resource_type(&buffer
, ins
.resource_type
);
3105 shader_addline(&buffer
, ")");
3108 if (ins
.resource_data_type
!= WINED3D_DATA_FLOAT
)
3109 shader_dump_data_type(&buffer
, ins
.resource_data_type
);
3111 for (i
= 0; i
< ins
.dst_count
; ++i
)
3113 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
3114 shader_addline(&buffer
, !i
? " " : ", ");
3115 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
3118 /* Other source tokens */
3119 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
3121 shader_addline(&buffer
, !i
? " " : ", ");
3122 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
3125 shader_addline(&buffer
, "\n");
3128 for (p
= buffer
.buffer
; *p
; p
= q
)
3130 if (!(q
= strstr(p
, "\n")))
3134 TRACE(" %.*s", (int)(q
- p
), p
);
3137 string_buffer_free(&buffer
);
3140 static void shader_cleanup(struct wined3d_shader
*shader
)
3142 if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
3144 heap_free(shader
->u
.hs
.phases
.control_point
);
3145 heap_free(shader
->u
.hs
.phases
.fork
);
3146 heap_free(shader
->u
.hs
.phases
.join
);
3149 heap_free(shader
->patch_constant_signature
.elements
);
3150 heap_free(shader
->output_signature
.elements
);
3151 heap_free(shader
->input_signature
.elements
);
3152 shader
->device
->shader_backend
->shader_destroy(shader
);
3153 shader_cleanup_reg_maps(&shader
->reg_maps
);
3154 heap_free(shader
->byte_code
);
3155 shader_delete_constant_list(&shader
->constantsF
);
3156 shader_delete_constant_list(&shader
->constantsB
);
3157 shader_delete_constant_list(&shader
->constantsI
);
3158 list_remove(&shader
->shader_list_entry
);
3160 if (shader
->frontend
&& shader
->frontend_data
)
3161 shader
->frontend
->shader_free(shader
->frontend_data
);
3164 struct shader_none_priv
3166 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
3167 const struct wined3d_fragment_pipe_ops
*fragment_pipe
;
3168 BOOL ffp_proj_control
;
3171 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
3172 static void shader_none_precompile(void *shader_priv
, struct wined3d_shader
*shader
) {}
3173 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
3174 const struct wined3d_state
*state
) {}
3175 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3176 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3177 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
3178 const struct wined3d_state
*state
) {}
3179 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
3180 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
3181 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
3183 /* Context activation is done by the caller. */
3184 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
3185 const struct wined3d_state
*state
)
3187 struct shader_none_priv
*priv
= shader_priv
;
3189 priv
->vertex_pipe
->vp_enable(context
, !use_vs(state
));
3190 priv
->fragment_pipe
->fp_enable(context
, !use_ps(state
));
3193 /* Context activation is done by the caller. */
3194 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
3196 struct shader_none_priv
*priv
= shader_priv
;
3198 priv
->vertex_pipe
->vp_enable(context
, FALSE
);
3199 priv
->fragment_pipe
->fp_enable(context
, FALSE
);
3201 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
3202 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
3203 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
3204 | (1u << WINED3D_SHADER_TYPE_HULL
)
3205 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
3206 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
3209 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
3210 const struct wined3d_fragment_pipe_ops
*fragment_pipe
)
3212 struct fragment_caps fragment_caps
;
3213 void *vertex_priv
, *fragment_priv
;
3214 struct shader_none_priv
*priv
;
3216 if (!(priv
= heap_alloc(sizeof(*priv
))))
3217 return E_OUTOFMEMORY
;
3219 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
3221 ERR("Failed to initialize vertex pipe.\n");
3226 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
3228 ERR("Failed to initialize fragment pipe.\n");
3229 vertex_pipe
->vp_free(device
, NULL
);
3234 priv
->vertex_pipe
= vertex_pipe
;
3235 priv
->fragment_pipe
= fragment_pipe
;
3236 fragment_pipe
->get_caps(device
->adapter
, &fragment_caps
);
3237 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
3239 device
->vertex_priv
= vertex_priv
;
3240 device
->fragment_priv
= fragment_priv
;
3241 device
->shader_priv
= priv
;
3246 static void shader_none_free(struct wined3d_device
*device
, struct wined3d_context
*context
)
3248 struct shader_none_priv
*priv
= device
->shader_priv
;
3250 priv
->fragment_pipe
->free_private(device
, context
);
3251 priv
->vertex_pipe
->vp_free(device
, context
);
3255 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
3260 static void shader_none_get_caps(const struct wined3d_adapter
*adapter
, struct shader_caps
*caps
)
3262 /* Set the shader caps to 0 for the none shader backend */
3263 memset(caps
, 0, sizeof(*caps
));
3266 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
3268 /* We "support" every possible fixup, since we don't support any shader
3269 * model, and will never have to actually sample a texture. */
3273 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
3275 struct shader_none_priv
*priv
= shader_priv
;
3277 return priv
->ffp_proj_control
;
3280 static uint64_t shader_none_shader_compile(struct wined3d_context
*context
, const struct wined3d_shader_desc
*shader_desc
,
3281 enum wined3d_shader_type shader_type
)
3286 const struct wined3d_shader_backend_ops none_shader_backend
=
3288 shader_none_handle_instruction
,
3289 shader_none_precompile
,
3291 shader_none_select_compute
,
3292 shader_none_disable
,
3293 shader_none_update_float_vertex_constants
,
3294 shader_none_update_float_pixel_constants
,
3295 shader_none_load_constants
,
3296 shader_none_destroy
,
3299 shader_none_allocate_context_data
,
3300 shader_none_free_context_data
,
3301 shader_none_init_context_state
,
3302 shader_none_get_caps
,
3303 shader_none_color_fixup_supported
,
3304 shader_none_has_ffp_proj_control
,
3305 shader_none_shader_compile
,
3308 static unsigned int shader_max_version_from_feature_level(enum wined3d_feature_level level
)
3312 case WINED3D_FEATURE_LEVEL_11_1
:
3313 case WINED3D_FEATURE_LEVEL_11
:
3315 case WINED3D_FEATURE_LEVEL_10_1
:
3316 case WINED3D_FEATURE_LEVEL_10
:
3318 case WINED3D_FEATURE_LEVEL_9_3
:
3320 case WINED3D_FEATURE_LEVEL_9_2
:
3321 case WINED3D_FEATURE_LEVEL_9_1
:
3328 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3329 enum wined3d_shader_type type
, unsigned int float_const_count
)
3331 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
3332 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3333 const struct wined3d_shader_version
*version
= ®_maps
->shader_version
;
3334 const struct wined3d_shader_frontend
*fe
;
3335 unsigned int backend_version
;
3338 TRACE("shader %p, device %p, type %s, float_const_count %u.\n",
3339 shader
, device
, debug_shader_type(type
), float_const_count
);
3341 fe
= shader
->frontend
;
3342 if (!(shader
->frontend_data
= fe
->shader_init(shader
->function
,
3343 shader
->functionLength
, &shader
->output_signature
)))
3345 FIXME("Failed to initialize frontend.\n");
3346 return WINED3DERR_INVALIDCALL
;
3349 /* First pass: trace shader. */
3350 if (TRACE_ON(d3d_shader
))
3351 shader_trace_init(fe
, shader
->frontend_data
);
3353 /* Second pass: figure out which registers are used, what the semantics are, etc. */
3354 if (FAILED(hr
= shader_get_registers_used(shader
, float_const_count
)))
3357 if (version
->type
!= type
)
3359 WARN("Wrong shader type %s.\n", debug_shader_type(reg_maps
->shader_version
.type
));
3360 return WINED3DERR_INVALIDCALL
;
3362 if (version
->major
> shader_max_version_from_feature_level(device
->cs
->c
.state
->feature_level
))
3364 WARN("Shader version %u not supported by this device.\n", version
->major
);
3365 return WINED3DERR_INVALIDCALL
;
3369 case WINED3D_SHADER_TYPE_VERTEX
:
3370 backend_version
= d3d_info
->limits
.vs_version
;
3372 case WINED3D_SHADER_TYPE_HULL
:
3373 backend_version
= d3d_info
->limits
.hs_version
;
3375 case WINED3D_SHADER_TYPE_DOMAIN
:
3376 backend_version
= d3d_info
->limits
.ds_version
;
3378 case WINED3D_SHADER_TYPE_GEOMETRY
:
3379 backend_version
= d3d_info
->limits
.gs_version
;
3381 case WINED3D_SHADER_TYPE_PIXEL
:
3382 backend_version
= d3d_info
->limits
.ps_version
;
3384 case WINED3D_SHADER_TYPE_COMPUTE
:
3385 backend_version
= d3d_info
->limits
.cs_version
;
3388 FIXME("No backend version-checking for this shader type.\n");
3389 backend_version
= 0;
3391 if (version
->major
> backend_version
)
3393 WARN("Shader version %u.%u not supported by the current shader backend.\n",
3394 version
->major
, version
->minor
);
3395 return WINED3DERR_INVALIDCALL
;
3398 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3403 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
3405 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
3407 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
3412 static void wined3d_shader_init_object(void *object
)
3414 struct wined3d_shader
*shader
= object
;
3415 struct wined3d_device
*device
= shader
->device
;
3417 TRACE("shader %p.\n", shader
);
3419 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3421 device
->shader_backend
->shader_precompile(device
->shader_priv
, shader
);
3424 static void wined3d_shader_destroy_object(void *object
)
3426 TRACE("object %p.\n", object
);
3428 shader_cleanup(object
);
3432 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
3434 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
3436 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
3440 wined3d_mutex_lock();
3441 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
3442 wined3d_cs_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
3443 wined3d_mutex_unlock();
3449 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
3451 TRACE("shader %p.\n", shader
);
3453 return shader
->parent
;
3456 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
3457 void *byte_code
, UINT
*byte_code_size
)
3459 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
3463 *byte_code_size
= shader
->byte_code_size
;
3467 if (*byte_code_size
< shader
->byte_code_size
)
3469 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
3470 * than the required size we should write the required size and
3471 * return D3DERR_MOREDATA. That's not actually true. */
3472 return WINED3DERR_INVALIDCALL
;
3475 memcpy(byte_code
, shader
->byte_code
, shader
->byte_code_size
);
3480 /* Set local constants for d3d8 shaders. */
3481 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
3482 UINT start_idx
, const float *src_data
, UINT count
)
3484 UINT end_idx
= start_idx
+ count
;
3487 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
3489 if (end_idx
> shader
->limits
->constant_float
)
3491 WARN("end_idx %u > float constants limit %u.\n",
3492 end_idx
, shader
->limits
->constant_float
);
3493 end_idx
= shader
->limits
->constant_float
;
3496 for (i
= start_idx
; i
< end_idx
; ++i
)
3498 struct wined3d_shader_lconst
*lconst
;
3501 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
3502 return E_OUTOFMEMORY
;
3505 value
= (float *)lconst
->value
;
3506 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3507 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3509 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3510 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3512 shader
->lconst_inf_or_nan
= TRUE
;
3519 static void init_interpolation_compile_args(DWORD
*interpolation_args
,
3520 const struct wined3d_shader
*pixel_shader
, const struct wined3d_d3d_info
*d3d_info
)
3522 if (!d3d_info
->shader_output_interpolation
|| !pixel_shader
3523 || pixel_shader
->reg_maps
.shader_version
.major
< 4)
3525 memset(interpolation_args
, 0, sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3529 memcpy(interpolation_args
, pixel_shader
->u
.ps
.interpolation_mode
,
3530 sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3533 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3534 struct vs_compile_args
*args
, const struct wined3d_context
*context
)
3536 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3537 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3538 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3539 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3540 WORD swizzle_map
= context
->stream_info
.swizzle_map
;
3542 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3543 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3544 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3545 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3546 args
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
3547 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3548 args
->next_shader_type
= hull_shader
? WINED3D_SHADER_TYPE_HULL
3549 : geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3550 if (shader
->reg_maps
.shader_version
.major
>= 4)
3551 args
->next_shader_input_count
= hull_shader
? hull_shader
->limits
->packed_input
3552 : geometry_shader
? geometry_shader
->limits
->packed_input
3553 : pixel_shader
? pixel_shader
->limits
->packed_input
: 0;
3555 args
->next_shader_input_count
= 0;
3556 args
->swizzle_map
= swizzle_map
;
3557 if (d3d_info
->emulated_flatshading
)
3558 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3560 args
->flatshading
= 0;
3562 init_interpolation_compile_args(args
->interpolation_mode
,
3563 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, d3d_info
);
3566 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3568 if (usage_idx1
!= usage_idx2
)
3570 if (usage1
== usage2
)
3572 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3574 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3580 bool vshader_get_input(const struct wined3d_shader
*shader
,
3581 uint8_t usage_req
, uint8_t usage_idx_req
, unsigned int *regnum
)
3583 uint32_t map
= shader
->reg_maps
.input_registers
& 0xffff;
3588 i
= wined3d_bit_scan(&map
);
3589 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3590 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3600 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3601 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3605 TRACE("byte_code %p, byte_code_size %#lx.\n", desc
->byte_code
, (long)desc
->byte_code_size
);
3607 if (!desc
->byte_code
)
3608 return WINED3DERR_INVALIDCALL
;
3611 shader
->device
= device
;
3612 shader
->parent
= parent
;
3613 shader
->parent_ops
= parent_ops
;
3615 list_init(&shader
->linked_programs
);
3616 list_init(&shader
->constantsF
);
3617 list_init(&shader
->constantsB
);
3618 list_init(&shader
->constantsI
);
3619 shader
->lconst_inf_or_nan
= FALSE
;
3620 list_init(&shader
->reg_maps
.indexable_temps
);
3621 list_init(&shader
->shader_list_entry
);
3623 if (desc
->byte_code_size
== ~(size_t)0)
3625 struct wined3d_shader_version shader_version
;
3626 const struct wined3d_shader_frontend
*fe
;
3627 struct wined3d_shader_instruction ins
;
3631 if (!(shader
->frontend
= shader_select_frontend(WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
)))
3633 FIXME("Unable to find frontend for shader.\n");
3634 hr
= WINED3DERR_INVALIDCALL
;
3638 fe
= shader
->frontend
;
3639 if (!(fe_data
= fe
->shader_init(desc
->byte_code
, desc
->byte_code_size
, &shader
->output_signature
)))
3641 WARN("Failed to initialise frontend data.\n");
3642 hr
= WINED3DERR_INVALIDCALL
;
3646 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3647 while (!fe
->shader_is_end(fe_data
, &ptr
))
3648 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
3650 fe
->shader_free(fe_data
);
3652 shader
->byte_code_size
= (ptr
- desc
->byte_code
) * sizeof(*ptr
);
3654 if (!(shader
->byte_code
= heap_alloc(shader
->byte_code_size
)))
3659 memcpy(shader
->byte_code
, desc
->byte_code
, shader
->byte_code_size
);
3661 shader
->function
= shader
->byte_code
;
3662 shader
->functionLength
= shader
->byte_code_size
;
3666 enum wined3d_shader_byte_code_format format
;
3667 unsigned int max_version
;
3669 if (!(shader
->byte_code
= heap_alloc(desc
->byte_code_size
)))
3674 memcpy(shader
->byte_code
, desc
->byte_code
, desc
->byte_code_size
);
3675 shader
->byte_code_size
= desc
->byte_code_size
;
3677 max_version
= shader_max_version_from_feature_level(device
->cs
->c
.state
->feature_level
);
3678 if (FAILED(hr
= shader_extract_from_dxbc(shader
, max_version
, &format
)))
3681 if (!(shader
->frontend
= shader_select_frontend(format
)))
3683 FIXME("Unable to find frontend for shader.\n");
3684 hr
= WINED3DERR_INVALIDCALL
;
3692 shader_cleanup(shader
);
3696 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3697 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3699 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3703 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
3706 if (FAILED(hr
= shader_set_function(shader
, device
,
3707 WINED3D_SHADER_TYPE_VERTEX
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
)))
3709 shader_cleanup(shader
);
3713 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3715 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3717 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3720 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3721 shader_usage_from_semantic_name(input
->semantic_name
);
3722 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3725 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3726 shader
->load_local_constsF
= TRUE
;
3731 static struct wined3d_shader_signature_element
*shader_find_signature_element(const struct wined3d_shader_signature
*s
,
3732 unsigned int stream_idx
, const char *semantic_name
, unsigned int semantic_idx
)
3734 struct wined3d_shader_signature_element
*e
= s
->elements
;
3737 for (i
= 0; i
< s
->element_count
; ++i
)
3739 if (e
[i
].stream_idx
== stream_idx
3740 && !stricmp(e
[i
].semantic_name
, semantic_name
)
3741 && e
[i
].semantic_idx
== semantic_idx
)
3748 BOOL
shader_get_stream_output_register_info(const struct wined3d_shader
*shader
,
3749 const struct wined3d_stream_output_element
*so_element
, unsigned int *register_idx
, unsigned int *component_idx
)
3751 const struct wined3d_shader_signature_element
*output
;
3754 if (!(output
= shader_find_signature_element(&shader
->output_signature
,
3755 so_element
->stream_idx
, so_element
->semantic_name
, so_element
->semantic_idx
)))
3758 for (idx
= 0; idx
< 4; ++idx
)
3760 if (output
->mask
& (1u << idx
))
3763 idx
+= so_element
->component_idx
;
3765 *register_idx
= output
->register_idx
;
3766 *component_idx
= idx
;
3770 static HRESULT
geometry_shader_init_so_desc(struct wined3d_geometry_shader
*gs
, struct wined3d_device
*device
,
3771 const struct wined3d_stream_output_desc
*so_desc
)
3773 struct wined3d_so_desc_entry
*s
;
3774 struct wine_rb_entry
*entry
;
3779 if ((entry
= wine_rb_get(&device
->so_descs
, so_desc
)))
3781 gs
->so_desc
= &WINE_RB_ENTRY_VALUE(entry
, struct wined3d_so_desc_entry
, entry
)->desc
;
3785 size
= FIELD_OFFSET(struct wined3d_so_desc_entry
, elements
[so_desc
->element_count
]);
3786 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3788 const char *n
= so_desc
->elements
[i
].semantic_name
;
3791 size
+= strlen(n
) + 1;
3793 if (!(s
= heap_alloc(size
)))
3794 return E_OUTOFMEMORY
;
3798 memcpy(s
->elements
, so_desc
->elements
, so_desc
->element_count
* sizeof(*s
->elements
));
3799 s
->desc
.elements
= s
->elements
;
3801 name
= (char *)&s
->elements
[s
->desc
.element_count
];
3802 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3804 struct wined3d_stream_output_element
*e
= &s
->elements
[i
];
3806 if (!e
->semantic_name
)
3809 size
= strlen(e
->semantic_name
) + 1;
3810 memcpy(name
, e
->semantic_name
, size
);
3811 e
->semantic_name
= name
;
3815 if (wine_rb_put(&device
->so_descs
, &s
->desc
, &s
->entry
) == -1)
3820 gs
->so_desc
= &s
->desc
;
3825 static HRESULT
geometry_shader_init_stream_output(struct wined3d_shader
*shader
,
3826 const struct wined3d_stream_output_desc
*so_desc
)
3828 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
3829 const struct wined3d_shader_signature_element
*output
;
3830 unsigned int i
, component_idx
, register_idx
, mask
;
3831 struct wined3d_shader_version shader_version
;
3839 if (!(fe_data
= fe
->shader_init(shader
->function
, shader
->functionLength
, &shader
->output_signature
)))
3841 WARN("Failed to initialise frontend data.\n");
3842 return WINED3DERR_INVALIDCALL
;
3844 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3845 fe
->shader_free(fe_data
);
3847 switch (shader_version
.type
)
3849 case WINED3D_SHADER_TYPE_VERTEX
:
3850 case WINED3D_SHADER_TYPE_DOMAIN
:
3851 shader
->function
= NULL
;
3852 shader
->functionLength
= 0;
3854 case WINED3D_SHADER_TYPE_GEOMETRY
:
3857 WARN("Wrong shader type %s.\n", debug_shader_type(shader_version
.type
));
3858 return E_INVALIDARG
;
3861 if (!shader
->function
)
3863 shader
->reg_maps
.shader_version
= shader_version
;
3864 shader
->reg_maps
.shader_version
.type
= WINED3D_SHADER_TYPE_GEOMETRY
;
3865 shader_set_limits(shader
);
3866 if (FAILED(hr
= shader_scan_output_signature(shader
)))
3870 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3872 const struct wined3d_stream_output_element
*e
= &so_desc
->elements
[i
];
3874 if (!e
->semantic_name
)
3876 if (!(output
= shader_find_signature_element(&shader
->output_signature
,
3877 e
->stream_idx
, e
->semantic_name
, e
->semantic_idx
))
3878 || !shader_get_stream_output_register_info(shader
, e
, ®ister_idx
, &component_idx
))
3880 WARN("Failed to find output signature element for stream output entry.\n");
3881 return E_INVALIDARG
;
3884 mask
= wined3d_mask_from_size(e
->component_count
) << component_idx
;
3885 if ((output
->mask
& 0xff & mask
) != mask
)
3887 WARN("Invalid component range %u-%u (mask %#x), output mask %#x.\n",
3888 component_idx
, e
->component_count
, mask
, output
->mask
& 0xff);
3889 return E_INVALIDARG
;
3893 if (FAILED(hr
= geometry_shader_init_so_desc(&shader
->u
.gs
, shader
->device
, so_desc
)))
3895 WARN("Failed to initialise stream output description, hr %#x.\n", hr
);
3902 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3903 const struct wined3d_shader_desc
*desc
, const struct wined3d_stream_output_desc
*so_desc
,
3904 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3908 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
3911 if (FAILED(hr
= geometry_shader_init_stream_output(shader
, so_desc
)))
3914 if (shader
->function
3915 && FAILED(hr
= shader_set_function(shader
, device
, WINED3D_SHADER_TYPE_GEOMETRY
, 0)))
3921 shader_cleanup(shader
);
3925 void find_ds_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3926 struct ds_compile_args
*args
, const struct wined3d_context
*context
)
3928 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3929 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3930 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3932 args
->tessellator_output_primitive
= hull_shader
->u
.hs
.tessellator_output_primitive
;
3933 args
->tessellator_partitioning
= hull_shader
->u
.hs
.tessellator_partitioning
;
3935 args
->output_count
= geometry_shader
? geometry_shader
->limits
->packed_input
3936 : pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3937 args
->next_shader_type
= geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3939 args
->render_offscreen
= context
->render_offscreen
;
3941 init_interpolation_compile_args(args
->interpolation_mode
,
3942 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, context
->d3d_info
);
3947 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3948 struct gs_compile_args
*args
, const struct wined3d_context
*context
)
3950 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3952 args
->output_count
= pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3954 if (!(args
->primitive_type
= shader
->u
.gs
.input_type
))
3955 args
->primitive_type
= state
->primitive_type
;
3957 init_interpolation_compile_args(args
->interpolation_mode
, pixel_shader
, context
->d3d_info
);
3960 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3961 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3963 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3964 struct wined3d_texture
*texture
;
3967 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3968 if (!d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
))
3970 static unsigned int warned
= 0;
3972 args
->srgb_correction
= 1;
3973 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
&& !warned
++)
3974 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3975 "support, expect rendering artifacts.\n");
3978 if (shader
->reg_maps
.shader_version
.major
== 1
3979 && shader
->reg_maps
.shader_version
.minor
<= 3)
3981 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3983 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3985 if (flags
& WINED3D_TTFF_PROJECTED
)
3987 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3989 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3991 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3993 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3994 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3996 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3998 struct wined3d_vertex_declaration_element
*element
=
3999 &state
->vertex_declaration
->elements
[j
];
4001 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
4002 && element
->usage_idx
== index
)
4004 max_valid
= element
->format
->component_count
;
4008 if (!tex_transform
|| tex_transform
> max_valid
)
4010 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
4011 tex_transform
, max_valid
);
4012 tex_transform
= max_valid
;
4014 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
4015 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
4016 && tex_transform
> WINED3D_TTFF_COUNT2
)
4017 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
4018 && tex_transform
> WINED3D_TTFF_COUNT3
))
4019 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
4022 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
4023 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
4024 i
, tex_transform
, resource_type
);
4028 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
4030 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
4034 if (shader
->reg_maps
.shader_version
.major
== 1
4035 && shader
->reg_maps
.shader_version
.minor
<= 4)
4037 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4039 if (!shader
->reg_maps
.resource_info
[i
].type
)
4042 /* Treat unbound textures as 2D. The dummy texture will provide
4043 * the proper sample value. The tex_types bitmap defaults to
4044 * 2D because of the memset. */
4045 if (!(texture
= state
->textures
[i
]))
4048 switch (wined3d_texture_gl(texture
)->target
)
4050 /* RECT textures are distinguished from 2D textures via np2_fixup */
4055 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4058 case GL_TEXTURE_CUBE_MAP_ARB
:
4059 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4064 else if (shader
->reg_maps
.shader_version
.major
<= 3)
4066 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4068 enum wined3d_shader_resource_type resource_type
;
4069 enum wined3d_shader_tex_types tex_type
;
4071 if (!(resource_type
= shader
->reg_maps
.resource_info
[i
].type
))
4074 switch (resource_type
)
4076 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
4077 tex_type
= WINED3D_SHADER_TEX_3D
;
4079 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
4080 tex_type
= WINED3D_SHADER_TEX_CUBE
;
4083 tex_type
= WINED3D_SHADER_TEX_2D
;
4087 if ((texture
= state
->textures
[i
]))
4089 if (texture
->resource
.type
== WINED3D_RTYPE_TEXTURE_2D
4090 && resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
4091 && !(texture
->resource
.usage
& WINED3DUSAGE_LEGACY_CUBEMAP
))
4092 tex_type
= WINED3D_SHADER_TEX_2D
;
4093 else if (texture
->resource
.type
== WINED3D_RTYPE_TEXTURE_3D
4094 && resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
)
4095 tex_type
= WINED3D_SHADER_TEX_3D
;
4097 args
->tex_types
|= tex_type
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4101 if (shader
->reg_maps
.shader_version
.major
>= 4)
4103 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
4105 for (i
= 0 ; i
< WINED3D_MAX_FRAGMENT_SAMPLERS
; ++i
)
4106 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4107 args
->np2_fixup
= 0;
4111 for (i
= 0; i
< WINED3D_MAX_FRAGMENT_SAMPLERS
; ++i
)
4113 if (!shader
->reg_maps
.resource_info
[i
].type
)
4116 texture
= state
->textures
[i
];
4119 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4122 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
4123 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4125 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
4127 if (texture
->resource
.format_caps
& WINED3D_FORMAT_CAP_SHADOW
)
4128 args
->shadow
|= 1u << i
;
4130 /* Flag samplers that need NP2 texcoord fixup. */
4131 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
4132 args
->np2_fixup
|= (1u << i
);
4136 if (shader
->reg_maps
.shader_version
.major
>= 3)
4138 if (position_transformed
)
4139 args
->vp_mode
= WINED3D_VP_MODE_NONE
;
4140 else if (use_vs(state
))
4141 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
4143 args
->vp_mode
= WINED3D_VP_MODE_FF
;
4144 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4148 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
4149 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
4151 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
4153 case WINED3D_FOG_NONE
:
4154 if (position_transformed
|| use_vs(state
))
4156 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4160 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
4162 case WINED3D_FOG_NONE
: /* Fall through. */
4163 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
4164 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
4165 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
4169 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
4170 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
4171 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
4176 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4180 if (!d3d_info
->full_ffp_varyings
)
4182 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
4184 args
->texcoords_initialized
= 0;
4185 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
4189 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
4190 args
->texcoords_initialized
|= 1u << i
;
4194 const struct wined3d_stream_info
*si
= &context
->stream_info
;
4195 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4197 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
4198 & WINED3D_FFP_TCI_MASK
4199 || (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
4200 args
->texcoords_initialized
|= 1u << i
;
4206 args
->texcoords_initialized
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
4209 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
4210 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
4212 if (d3d_info
->ffp_alpha_test
)
4213 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
4215 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
4216 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
4217 : WINED3D_CMP_ALWAYS
) - 1;
4219 if (d3d_info
->emulated_flatshading
)
4220 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4222 args
->y_correction
= (shader
->reg_maps
.vpos
&& d3d_info
->frag_coord_correction
)
4223 || (shader
->reg_maps
.usesdsy
&& wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
4224 ? !context
->render_offscreen
: 0;
4226 for (i
= 0; i
< ARRAY_SIZE(state
->fb
.render_targets
); ++i
)
4228 struct wined3d_rendertarget_view
*rtv
= state
->fb
.render_targets
[i
];
4229 if (rtv
&& rtv
->format
->id
== WINED3DFMT_A8_UNORM
&& !is_identity_fixup(rtv
->format
->color_fixup
))
4230 args
->rt_alpha_swizzle
|= 1u << i
;
4233 args
->dual_source_blend
= state
->blend_state
&& state
->blend_state
->dual_source
;
4236 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
4237 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
4239 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
4240 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
4243 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
4246 if (FAILED(hr
= shader_set_function(shader
, device
,
4247 WINED3D_SHADER_TYPE_PIXEL
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
)))
4249 shader_cleanup(shader
);
4253 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4255 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4258 highest_reg_used
= i
;
4262 /* Don't do any register mapping magic if it is not needed, or if we can't
4263 * achieve anything anyway */
4264 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
4265 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
4266 || shader
->reg_maps
.shader_version
.major
>= 4)
4268 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
4270 /* This happens with relative addressing. The input mapper function
4271 * warns about this if the higher registers are declared too, so
4272 * don't write a FIXME here */
4273 WARN("More varying registers used than supported\n");
4276 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4278 shader
->u
.ps
.input_reg_map
[i
] = i
;
4281 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
4285 shader
->u
.ps
.declared_in_count
= 0;
4286 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4288 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4289 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
4290 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
4297 enum wined3d_shader_resource_type
pixelshader_get_resource_type(const struct wined3d_shader_reg_maps
*reg_maps
,
4298 unsigned int resource_idx
, DWORD tex_types
)
4300 static enum wined3d_shader_resource_type shader_resource_type_from_shader_tex_types
[] =
4302 WINED3D_SHADER_RESOURCE_TEXTURE_2D
, /* WINED3D_SHADER_TEX_2D */
4303 WINED3D_SHADER_RESOURCE_TEXTURE_3D
, /* WINED3D_SHADER_TEX_3D */
4304 WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
, /* WINED3D_SHADER_TEX_CUBE */
4309 if (reg_maps
->shader_version
.major
> 3)
4310 return reg_maps
->resource_info
[resource_idx
].type
;
4312 if (!reg_maps
->resource_info
[resource_idx
].type
)
4315 idx
= (tex_types
>> resource_idx
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
;
4316 assert(idx
< ARRAY_SIZE(shader_resource_type_from_shader_tex_types
));
4317 return shader_resource_type_from_shader_tex_types
[idx
];
4320 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4321 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4323 struct wined3d_shader
*object
;
4326 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4327 device
, desc
, parent
, parent_ops
, shader
);
4329 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4330 return E_OUTOFMEMORY
;
4332 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4334 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
4339 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_COMPUTE
, 0)))
4341 shader_cleanup(object
);
4346 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4348 TRACE("Created compute shader %p.\n", object
);
4354 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4355 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4357 struct wined3d_shader
*object
;
4360 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4361 device
, desc
, parent
, parent_ops
, shader
);
4363 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4364 return E_OUTOFMEMORY
;
4366 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4368 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
4373 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_DOMAIN
, 0)))
4375 shader_cleanup(object
);
4380 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4382 TRACE("Created domain shader %p.\n", object
);
4388 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4389 const struct wined3d_stream_output_desc
*so_desc
, void *parent
,
4390 const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4392 struct wined3d_shader
*object
;
4395 TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
4396 device
, desc
, so_desc
, parent
, parent_ops
, shader
);
4398 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4399 return E_OUTOFMEMORY
;
4401 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, so_desc
, parent
, parent_ops
)))
4403 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
4408 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4410 TRACE("Created geometry shader %p.\n", object
);
4416 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4417 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4419 struct wined3d_shader
*object
;
4422 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4423 device
, desc
, parent
, parent_ops
, shader
);
4425 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4426 return E_OUTOFMEMORY
;
4428 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4430 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
4435 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_HULL
, 0)))
4437 shader_cleanup(object
);
4442 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4444 TRACE("Created hull shader %p.\n", object
);
4450 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4451 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4453 struct wined3d_shader
*object
;
4456 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4457 device
, desc
, parent
, parent_ops
, shader
);
4459 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4460 return E_OUTOFMEMORY
;
4462 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4464 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
4469 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4471 TRACE("Created pixel shader %p.\n", object
);
4477 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4478 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4480 struct wined3d_shader
*object
;
4483 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4484 device
, desc
, parent
, parent_ops
, shader
);
4486 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4487 return E_OUTOFMEMORY
;
4489 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4491 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
4496 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4498 TRACE("Created vertex shader %p.\n", object
);