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
26 #include "wine/port.h"
31 #include "wined3d_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
35 /* pow, mul_high, sub_high, mul_low */
36 const float wined3d_srgb_const0
[] = {0.41666f
, 1.055f
, 0.055f
, 12.92f
};
38 const float wined3d_srgb_const1
[] = {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_EVAL_SAMPLE_INDEX */ "eval_sample_index",
129 /* WINED3DSIH_ELSE */ "else",
130 /* WINED3DSIH_EMIT */ "emit",
131 /* WINED3DSIH_EMIT_STREAM */ "emit_stream",
132 /* WINED3DSIH_ENDIF */ "endif",
133 /* WINED3DSIH_ENDLOOP */ "endloop",
134 /* WINED3DSIH_ENDREP */ "endrep",
135 /* WINED3DSIH_ENDSWITCH */ "endswitch",
136 /* WINED3DSIH_EQ */ "eq",
137 /* WINED3DSIH_EXP */ "exp",
138 /* WINED3DSIH_EXPP */ "expp",
139 /* WINED3DSIH_F16TOF32 */ "f16tof32",
140 /* WINED3DSIH_F32TOF16 */ "f32tof16",
141 /* WINED3DSIH_FCALL */ "fcall",
142 /* WINED3DSIH_FIRSTBIT_HI */ "firstbit_hi",
143 /* WINED3DSIH_FIRSTBIT_LO */ "firstbit_lo",
144 /* WINED3DSIH_FIRSTBIT_SHI */ "firstbit_shi",
145 /* WINED3DSIH_FRC */ "frc",
146 /* WINED3DSIH_FTOI */ "ftoi",
147 /* WINED3DSIH_FTOU */ "ftou",
148 /* WINED3DSIH_GATHER4 */ "gather4",
149 /* WINED3DSIH_GATHER4_C */ "gather4_c",
150 /* WINED3DSIH_GATHER4_PO */ "gather4_po",
151 /* WINED3DSIH_GATHER4_PO_C */ "gather4_po_c",
152 /* WINED3DSIH_GE */ "ge",
153 /* WINED3DSIH_HS_CONTROL_POINT_PHASE */ "hs_control_point_phase",
154 /* WINED3DSIH_HS_DECLS */ "hs_decls",
155 /* WINED3DSIH_HS_FORK_PHASE */ "hs_fork_phase",
156 /* WINED3DSIH_HS_JOIN_PHASE */ "hs_join_phase",
157 /* WINED3DSIH_IADD */ "iadd",
158 /* WINED3DSIH_IBFE */ "ibfe",
159 /* WINED3DSIH_IEQ */ "ieq",
160 /* WINED3DSIH_IF */ "if",
161 /* WINED3DSIH_IFC */ "ifc",
162 /* WINED3DSIH_IGE */ "ige",
163 /* WINED3DSIH_ILT */ "ilt",
164 /* WINED3DSIH_IMAD */ "imad",
165 /* WINED3DSIH_IMAX */ "imax",
166 /* WINED3DSIH_IMIN */ "imin",
167 /* WINED3DSIH_IMM_ATOMIC_ALLOC */ "imm_atomic_alloc",
168 /* WINED3DSIH_IMM_ATOMIC_AND */ "imm_atomic_and",
169 /* WINED3DSIH_IMM_ATOMIC_CMP_EXCH */ "imm_atomic_cmp_exch",
170 /* WINED3DSIH_IMM_ATOMIC_CONSUME */ "imm_atomic_consume",
171 /* WINED3DSIH_IMM_ATOMIC_EXCH */ "imm_atomic_exch",
172 /* WINED3DSIH_IMM_ATOMIC_IADD */ "imm_atomic_iadd",
173 /* WINED3DSIH_IMM_ATOMIC_IMAX */ "imm_atomic_imax",
174 /* WINED3DSIH_IMM_ATOMIC_IMIN */ "imm_atomic_imin",
175 /* WINED3DSIH_IMM_ATOMIC_OR */ "imm_atomic_or",
176 /* WINED3DSIH_IMM_ATOMIC_UMAX */ "imm_atomic_umax",
177 /* WINED3DSIH_IMM_ATOMIC_UMIN */ "imm_atomic_umin",
178 /* WINED3DSIH_IMM_ATOMIC_XOR */ "imm_atomic_xor",
179 /* WINED3DSIH_IMUL */ "imul",
180 /* WINED3DSIH_INE */ "ine",
181 /* WINED3DSIH_INEG */ "ineg",
182 /* WINED3DSIH_ISHL */ "ishl",
183 /* WINED3DSIH_ISHR */ "ishr",
184 /* WINED3DSIH_ITOF */ "itof",
185 /* WINED3DSIH_LABEL */ "label",
186 /* WINED3DSIH_LD */ "ld",
187 /* WINED3DSIH_LD2DMS */ "ld2dms",
188 /* WINED3DSIH_LD_RAW */ "ld_raw",
189 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
190 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
191 /* WINED3DSIH_LIT */ "lit",
192 /* WINED3DSIH_LOD */ "lod",
193 /* WINED3DSIH_LOG */ "log",
194 /* WINED3DSIH_LOGP */ "logp",
195 /* WINED3DSIH_LOOP */ "loop",
196 /* WINED3DSIH_LRP */ "lrp",
197 /* WINED3DSIH_LT */ "lt",
198 /* WINED3DSIH_M3x2 */ "m3x2",
199 /* WINED3DSIH_M3x3 */ "m3x3",
200 /* WINED3DSIH_M3x4 */ "m3x4",
201 /* WINED3DSIH_M4x3 */ "m4x3",
202 /* WINED3DSIH_M4x4 */ "m4x4",
203 /* WINED3DSIH_MAD */ "mad",
204 /* WINED3DSIH_MAX */ "max",
205 /* WINED3DSIH_MIN */ "min",
206 /* WINED3DSIH_MOV */ "mov",
207 /* WINED3DSIH_MOVA */ "mova",
208 /* WINED3DSIH_MOVC */ "movc",
209 /* WINED3DSIH_MUL */ "mul",
210 /* WINED3DSIH_NE */ "ne",
211 /* WINED3DSIH_NOP */ "nop",
212 /* WINED3DSIH_NOT */ "not",
213 /* WINED3DSIH_NRM */ "nrm",
214 /* WINED3DSIH_OR */ "or",
215 /* WINED3DSIH_PHASE */ "phase",
216 /* WINED3DSIH_POW */ "pow",
217 /* WINED3DSIH_RCP */ "rcp",
218 /* WINED3DSIH_REP */ "rep",
219 /* WINED3DSIH_RESINFO */ "resinfo",
220 /* WINED3DSIH_RET */ "ret",
221 /* WINED3DSIH_RETP */ "retp",
222 /* WINED3DSIH_ROUND_NE */ "round_ne",
223 /* WINED3DSIH_ROUND_NI */ "round_ni",
224 /* WINED3DSIH_ROUND_PI */ "round_pi",
225 /* WINED3DSIH_ROUND_Z */ "round_z",
226 /* WINED3DSIH_RSQ */ "rsq",
227 /* WINED3DSIH_SAMPLE */ "sample",
228 /* WINED3DSIH_SAMPLE_B */ "sample_b",
229 /* WINED3DSIH_SAMPLE_C */ "sample_c",
230 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
231 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
232 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
233 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
234 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
235 /* WINED3DSIH_SETP */ "setp",
236 /* WINED3DSIH_SGE */ "sge",
237 /* WINED3DSIH_SGN */ "sgn",
238 /* WINED3DSIH_SINCOS */ "sincos",
239 /* WINED3DSIH_SLT */ "slt",
240 /* WINED3DSIH_SQRT */ "sqrt",
241 /* WINED3DSIH_STORE_RAW */ "store_raw",
242 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
243 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
244 /* WINED3DSIH_SUB */ "sub",
245 /* WINED3DSIH_SWAPC */ "swapc",
246 /* WINED3DSIH_SWITCH */ "switch",
247 /* WINED3DSIH_SYNC */ "sync",
248 /* WINED3DSIH_TEX */ "texld",
249 /* WINED3DSIH_TEXBEM */ "texbem",
250 /* WINED3DSIH_TEXBEML */ "texbeml",
251 /* WINED3DSIH_TEXCOORD */ "texcrd",
252 /* WINED3DSIH_TEXDEPTH */ "texdepth",
253 /* WINED3DSIH_TEXDP3 */ "texdp3",
254 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
255 /* WINED3DSIH_TEXKILL */ "texkill",
256 /* WINED3DSIH_TEXLDD */ "texldd",
257 /* WINED3DSIH_TEXLDL */ "texldl",
258 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
259 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
260 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
261 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
262 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
263 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
264 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
265 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
266 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
267 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
268 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
269 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
270 /* WINED3DSIH_UBFE */ "ubfe",
271 /* WINED3DSIH_UDIV */ "udiv",
272 /* WINED3DSIH_UGE */ "uge",
273 /* WINED3DSIH_ULT */ "ult",
274 /* WINED3DSIH_UMAX */ "umax",
275 /* WINED3DSIH_UMIN */ "umin",
276 /* WINED3DSIH_UMUL */ "umul",
277 /* WINED3DSIH_USHR */ "ushr",
278 /* WINED3DSIH_UTOF */ "utof",
279 /* WINED3DSIH_XOR */ "xor",
282 static const char * const semantic_names
[] =
284 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
285 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
286 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
287 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
288 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
289 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
290 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
291 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
292 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
293 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
294 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
295 /* WINED3D_DECL_USAGE_FOG */ "FOG",
296 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
297 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
302 enum wined3d_shader_input_sysval_semantic sysval_semantic
;
303 const char *sysval_name
;
305 shader_input_sysval_semantic_names
[] =
307 {WINED3D_SIV_POSITION
, "position"},
308 {WINED3D_SIV_CLIP_DISTANCE
, "clip_distance"},
309 {WINED3D_SIV_CULL_DISTANCE
, "cull_distance"},
310 {WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX
, "render_target_array_index"},
311 {WINED3D_SIV_VIEWPORT_ARRAY_INDEX
, "viewport_array_index"},
312 {WINED3D_SIV_VERTEX_ID
, "vertex_id"},
313 {WINED3D_SIV_INSTANCE_ID
, "instance_id"},
314 {WINED3D_SIV_PRIMITIVE_ID
, "primitive_id"},
315 {WINED3D_SIV_IS_FRONT_FACE
, "is_front_face"},
316 {WINED3D_SIV_SAMPLE_INDEX
, "sample_index"},
317 {WINED3D_SIV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
318 {WINED3D_SIV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
319 {WINED3D_SIV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
320 {WINED3D_SIV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
321 {WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
322 {WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
323 {WINED3D_SIV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
324 {WINED3D_SIV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
325 {WINED3D_SIV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
326 {WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
327 {WINED3D_SIV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
328 {WINED3D_SIV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
331 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
332 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
334 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
336 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
337 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
339 return shader_opcode_names
[handler_idx
];
342 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
344 if (usage
>= ARRAY_SIZE(semantic_names
))
346 FIXME("Unrecognized usage %#x.\n", usage
);
347 return "UNRECOGNIZED";
350 return semantic_names
[usage
];
353 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
357 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
359 if (!strcmp(name
, semantic_names
[i
]))
366 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
370 case WINED3D_DECL_USAGE_POSITION
:
371 return WINED3D_SV_POSITION
;
377 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
379 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
382 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
383 const struct wined3d_shader_semantic
*s
)
385 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
386 e
->semantic_idx
= s
->usage_idx
;
388 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
389 e
->component_type
= WINED3D_TYPE_FLOAT
;
390 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
391 e
->mask
= s
->reg
.write_mask
;
394 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
395 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
397 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
398 e
->semantic_idx
= usage_idx
;
400 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
401 e
->component_type
= WINED3D_TYPE_FLOAT
;
402 e
->register_idx
= reg_idx
;
403 e
->mask
= write_mask
;
406 static const struct wined3d_shader_frontend
*shader_select_frontend(enum wined3d_shader_byte_code_format format
)
410 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
:
411 return &sm1_shader_frontend
;
413 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
:
414 return &sm4_shader_frontend
;
417 WARN("Invalid byte code format %#x specified.\n", format
);
422 static enum wined3d_shader_type
shader_get_shader_type(const struct wined3d_shader_desc
*desc
)
424 if (desc
->format
== WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
)
425 return wined3d_get_sm4_shader_type(desc
->byte_code
, desc
->byte_code_size
);
427 FIXME("Could not get shader type for byte code format %#x.\n", desc
->format
);
428 return WINED3D_SHADER_TYPE_INVALID
;
431 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
433 buffer
->buffer
[0] = '\0';
434 buffer
->content_size
= 0;
437 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
439 buffer
->buffer_size
= 32;
440 if (!(buffer
->buffer
= heap_alloc(buffer
->buffer_size
)))
442 ERR("Failed to allocate shader buffer memory.\n");
446 string_buffer_clear(buffer
);
450 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
452 heap_free(buffer
->buffer
);
455 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
458 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
460 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
461 new_buffer_size
*= 2;
462 if (!(new_buffer
= heap_realloc(buffer
->buffer
, new_buffer_size
)))
464 ERR("Failed to grow buffer.\n");
465 buffer
->buffer
[buffer
->content_size
] = '\0';
468 buffer
->buffer
= new_buffer
;
469 buffer
->buffer_size
= new_buffer_size
;
473 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
478 rem
= buffer
->buffer_size
- buffer
->content_size
;
479 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
480 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
483 buffer
->content_size
+= rc
;
487 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
494 va_start(args
, format
);
495 ret
= shader_vaddline(buffer
, format
, args
);
499 if (!string_buffer_resize(buffer
, ret
))
504 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
506 struct wined3d_string_buffer
*buffer
;
508 if (list_empty(&list
->list
))
510 buffer
= heap_alloc(sizeof(*buffer
));
511 if (!buffer
|| !string_buffer_init(buffer
))
513 ERR("Couldn't allocate buffer for temporary string.\n");
520 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
521 list_remove(&buffer
->entry
);
523 string_buffer_clear(buffer
);
527 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
531 string_buffer_clear(buffer
);
532 return shader_vaddline(buffer
, format
, args
);
535 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
542 va_start(args
, format
);
543 ret
= string_buffer_vsprintf(buffer
, format
, args
);
547 if (!string_buffer_resize(buffer
, ret
))
552 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
556 list_add_head(&list
->list
, &buffer
->entry
);
559 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
561 list_init(&list
->list
);
564 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
566 struct wined3d_string_buffer
*buffer
, *buffer_next
;
568 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
570 string_buffer_free(buffer
);
573 list_init(&list
->list
);
576 /* Convert floating point offset relative to a register file to an absolute
577 * offset for float constants. */
578 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
580 switch (register_type
)
582 case WINED3DSPR_CONST
: return register_idx
;
583 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
584 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
585 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
587 FIXME("Unsupported register type: %u.\n", register_type
);
592 static void shader_delete_constant_list(struct list
*clist
)
594 struct wined3d_shader_lconst
*constant
, *constant_next
;
596 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
601 static void shader_set_limits(struct wined3d_shader
*shader
)
603 static const struct limits_entry
605 unsigned int min_version
;
606 unsigned int max_version
;
607 struct wined3d_shader_limits limits
;
611 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
612 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
613 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
614 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
615 * even though they are capable of supporting much more (GL
616 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
617 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
619 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
620 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
621 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
626 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
627 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
631 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
632 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
636 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
637 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
638 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
643 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
644 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
645 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
646 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
647 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
648 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
649 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
654 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
655 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
657 const struct limits_entry
*limits_array
;
658 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
659 shader
->reg_maps
.shader_version
.minor
);
662 switch (shader
->reg_maps
.shader_version
.type
)
665 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
667 case WINED3D_SHADER_TYPE_VERTEX
:
668 limits_array
= vs_limits
;
670 case WINED3D_SHADER_TYPE_HULL
:
671 limits_array
= hs_limits
;
673 case WINED3D_SHADER_TYPE_DOMAIN
:
674 limits_array
= ds_limits
;
676 case WINED3D_SHADER_TYPE_GEOMETRY
:
677 limits_array
= gs_limits
;
679 case WINED3D_SHADER_TYPE_PIXEL
:
680 limits_array
= ps_limits
;
682 case WINED3D_SHADER_TYPE_COMPUTE
:
683 limits_array
= cs_limits
;
687 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
689 if (shader_version
<= limits_array
[i
].max_version
)
691 shader
->limits
= &limits_array
[i
].limits
;
698 FIXME("Unexpected shader version \"%u.%u\".\n",
699 shader
->reg_maps
.shader_version
.major
,
700 shader
->reg_maps
.shader_version
.minor
);
701 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
705 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
706 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
710 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
711 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
712 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
714 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
717 case WINED3DSPR_TEMP
:
718 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
721 case WINED3DSPR_INPUT
:
722 if (reg
->idx
[0].rel_addr
)
723 reg_maps
->input_rel_addressing
= 1;
724 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
726 /* If relative addressing is used, we must assume that all
727 * registers are used. Even if it is a construct like v3[aL],
728 * we can't assume that v0, v1 and v2 aren't read because aL
729 * can be negative. */
730 if (reg
->idx
[0].rel_addr
)
731 shader
->u
.ps
.input_reg_used
= ~0u;
733 shader
->u
.ps
.input_reg_used
|= 1u << reg
->idx
[0].offset
;
737 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
741 case WINED3DSPR_RASTOUT
:
742 if (reg
->idx
[0].offset
== 1)
744 if (reg
->idx
[0].offset
== 2)
745 reg_maps
->point_size
= 1;
748 case WINED3DSPR_MISCTYPE
:
749 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
751 if (!reg
->idx
[0].offset
)
753 else if (reg
->idx
[0].offset
== 1)
754 reg_maps
->usesfacing
= 1;
758 case WINED3DSPR_CONST
:
759 if (reg
->idx
[0].rel_addr
)
761 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
762 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
763 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
764 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
765 reg_maps
->usesrelconstF
= TRUE
;
769 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
771 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
776 wined3d_insert_bits(reg_maps
->constf
, reg
->idx
[0].offset
, 1, 0x1);
781 case WINED3DSPR_CONSTINT
:
782 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
784 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
789 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
793 case WINED3DSPR_CONSTBOOL
:
794 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
796 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
801 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
805 case WINED3DSPR_COLOROUT
:
806 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
809 case WINED3DSPR_OUTCONTROLPOINT
:
814 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
815 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
821 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
822 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
824 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
825 struct wined3d_shader_sampler_map
*map
;
828 map
= ®_maps
->sampler_map
;
829 entries
= map
->entries
;
830 for (i
= 0; i
< map
->count
; ++i
)
832 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
838 if (!(entries
= heap_calloc(4, sizeof(*entries
))))
840 ERR("Failed to allocate sampler map entries.\n");
844 map
->entries
= entries
;
846 else if (map
->count
== map
->size
)
848 size_t new_size
= map
->size
* 2;
850 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
851 || !(entries
= heap_realloc(entries
, sizeof(*entries
) * new_size
)))
853 ERR("Failed to resize sampler map entries.\n");
856 map
->size
= new_size
;
857 map
->entries
= entries
;
860 entry
= &entries
[map
->count
++];
861 entry
->resource_idx
= resource_idx
;
862 entry
->sampler_idx
= sampler_idx
;
863 entry
->bind_idx
= bind_idx
;
866 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
870 case WINED3DSIH_M4x4
:
871 case WINED3DSIH_M3x4
:
872 return param
== 1 ? 3 : 0;
874 case WINED3DSIH_M4x3
:
875 case WINED3DSIH_M3x3
:
876 return param
== 1 ? 2 : 0;
878 case WINED3DSIH_M3x2
:
879 return param
== 1 ? 1 : 0;
886 static HRESULT
shader_reg_maps_add_tgsm(struct wined3d_shader_reg_maps
*reg_maps
,
887 unsigned int register_idx
, unsigned int size
, unsigned int stride
)
889 struct wined3d_shader_tgsm
*tgsm
;
891 if (register_idx
>= MAX_TGSM_REGISTERS
)
893 ERR("Invalid TGSM register index %u.\n", register_idx
);
896 if (reg_maps
->shader_version
.type
!= WINED3D_SHADER_TYPE_COMPUTE
)
898 FIXME("TGSM declarations are allowed only in compute shaders.\n");
902 if (!wined3d_array_reserve((void **)®_maps
->tgsm
, ®_maps
->tgsm_capacity
,
903 register_idx
+ 1, sizeof(*reg_maps
->tgsm
)))
904 return E_OUTOFMEMORY
;
906 reg_maps
->tgsm_count
= max(register_idx
+ 1, reg_maps
->tgsm_count
);
907 tgsm
= ®_maps
->tgsm
[register_idx
];
909 tgsm
->stride
= stride
;
913 static HRESULT
shader_record_shader_phase(struct wined3d_shader
*shader
,
914 struct wined3d_shader_phase
**current_phase
, const struct wined3d_shader_instruction
*ins
,
915 const DWORD
*current_instruction_ptr
, const DWORD
*previous_instruction_ptr
)
917 struct wined3d_shader_phase
*phase
;
919 if ((phase
= *current_phase
))
921 phase
->end
= previous_instruction_ptr
;
922 *current_phase
= NULL
;
925 if (shader
->reg_maps
.shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
927 ERR("Unexpected shader type %#x.\n", shader
->reg_maps
.shader_version
.type
);
931 switch (ins
->handler_idx
)
933 case WINED3DSIH_HS_CONTROL_POINT_PHASE
:
934 if (shader
->u
.hs
.phases
.control_point
)
936 FIXME("Multiple control point phases.\n");
937 heap_free(shader
->u
.hs
.phases
.control_point
);
939 if (!(shader
->u
.hs
.phases
.control_point
= heap_alloc_zero(sizeof(*shader
->u
.hs
.phases
.control_point
))))
940 return E_OUTOFMEMORY
;
941 phase
= shader
->u
.hs
.phases
.control_point
;
943 case WINED3DSIH_HS_FORK_PHASE
:
944 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.fork
,
945 &shader
->u
.hs
.phases
.fork_size
, shader
->u
.hs
.phases
.fork_count
+ 1,
946 sizeof(*shader
->u
.hs
.phases
.fork
)))
947 return E_OUTOFMEMORY
;
948 phase
= &shader
->u
.hs
.phases
.fork
[shader
->u
.hs
.phases
.fork_count
++];
950 case WINED3DSIH_HS_JOIN_PHASE
:
951 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.join
,
952 &shader
->u
.hs
.phases
.join_size
, shader
->u
.hs
.phases
.join_count
+ 1,
953 sizeof(*shader
->u
.hs
.phases
.join
)))
954 return E_OUTOFMEMORY
;
955 phase
= &shader
->u
.hs
.phases
.join
[shader
->u
.hs
.phases
.join_count
++];
958 ERR("Unexpected opcode %s.\n", debug_d3dshaderinstructionhandler(ins
->handler_idx
));
962 phase
->start
= current_instruction_ptr
;
963 *current_phase
= phase
;
968 static HRESULT
shader_calculate_clip_or_cull_distance_mask(
969 const struct wined3d_shader_signature_element
*e
, unsigned int *mask
)
971 /* Clip and cull distances are packed in 4 component registers. 0 and 1 are
972 * the only allowed semantic indices.
974 if (e
->semantic_idx
>= MAX_CLIP_DISTANCES
/ 4)
977 WARN("Invalid clip/cull distance index %u.\n", e
->semantic_idx
);
978 return WINED3DERR_INVALIDCALL
;
981 *mask
= (e
->mask
& WINED3DSP_WRITEMASK_ALL
) << (4 * e
->semantic_idx
);
985 static void wined3d_insert_interpolation_mode(DWORD
*packed_interpolation_mode
,
986 unsigned int register_idx
, enum wined3d_shader_interpolation_mode mode
)
988 if (mode
> WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
)
989 FIXME("Unexpected interpolation mode %#x.\n", mode
);
991 wined3d_insert_bits(packed_interpolation_mode
,
992 register_idx
* WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, mode
);
995 /* Note that this does not count the loop register as an address register. */
996 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
997 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
998 struct wined3d_shader_signature
*output_signature
, DWORD constf_size
)
1000 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
1001 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
1002 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
1003 struct wined3d_shader_version shader_version
;
1004 struct wined3d_shader_phase
*phase
= NULL
;
1005 const DWORD
*ptr
, *prev_ins
, *current_ins
;
1006 void *fe_data
= shader
->frontend_data
;
1010 memset(reg_maps
, 0, sizeof(*reg_maps
));
1011 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
1012 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
1013 reg_maps
->min_rel_offset
= ~0U;
1014 list_init(®_maps
->indexable_temps
);
1016 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1017 prev_ins
= current_ins
= ptr
;
1018 reg_maps
->shader_version
= shader_version
;
1020 shader_set_limits(shader
);
1022 if (!(reg_maps
->constf
= heap_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
1023 sizeof(*reg_maps
->constf
))))
1025 ERR("Failed to allocate constant map memory.\n");
1026 return E_OUTOFMEMORY
;
1029 while (!fe
->shader_is_end(fe_data
, &ptr
))
1031 struct wined3d_shader_instruction ins
;
1035 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1037 /* Unhandled opcode, and its parameters. */
1038 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1040 WARN("Encountered unrecognised or invalid instruction.\n");
1041 return WINED3DERR_INVALIDCALL
;
1044 /* Handle declarations. */
1045 if (ins
.handler_idx
== WINED3DSIH_DCL
1046 || ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
1048 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
1049 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
1051 switch (semantic
->reg
.reg
.type
)
1053 /* Mark input registers used. */
1054 case WINED3DSPR_INPUT
:
1055 if (reg_idx
>= MAX_REG_INPUT
)
1057 ERR("Invalid input register index %u.\n", reg_idx
);
1060 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
1061 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
1062 return WINED3DERR_INVALIDCALL
;
1063 reg_maps
->input_registers
|= 1u << reg_idx
;
1064 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
1067 /* Vertex shader: mark 3.0 output registers used, save token. */
1068 case WINED3DSPR_OUTPUT
:
1069 if (reg_idx
>= MAX_REG_OUTPUT
)
1071 ERR("Invalid output register index %u.\n", reg_idx
);
1074 reg_maps
->output_registers
|= 1u << reg_idx
;
1075 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
1076 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
1078 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
1079 reg_maps
->point_size
= 1;
1082 case WINED3DSPR_SAMPLER
:
1083 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1084 case WINED3DSPR_RESOURCE
:
1085 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1087 ERR("Invalid resource index %u.\n", reg_idx
);
1090 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
1091 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1094 case WINED3DSPR_UAV
:
1095 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1097 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1100 reg_maps
->uav_resource_info
[reg_idx
].type
= semantic
->resource_type
;
1101 reg_maps
->uav_resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1103 FIXME("Ignoring typed UAV flags %#x.\n", ins
.flags
);
1107 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
1111 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1113 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
1114 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
1115 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
1117 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
1119 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
1121 if (ins
.flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1123 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1124 shader
->u
.ps
.force_early_depth_stencil
= TRUE
;
1126 FIXME("Invalid instruction %#x for shader type %#x.\n",
1127 ins
.handler_idx
, shader_version
.type
);
1131 WARN("Ignoring global flags %#x.\n", ins
.flags
);
1134 else if (ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
)
1136 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1137 shader
->u
.gs
.instance_count
= ins
.declaration
.count
;
1139 FIXME("Invalid instruction %#x for shader type %#x.\n",
1140 ins
.handler_idx
, shader_version
.type
);
1142 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
1143 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
)
1146 phase
->instance_count
= ins
.declaration
.count
;
1148 FIXME("Instruction %s outside of shader phase.\n",
1149 debug_d3dshaderinstructionhandler(ins
.handler_idx
));
1151 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
1154 FIXME("Multiple immediate constant buffers.\n");
1155 reg_maps
->icb
= ins
.declaration
.icb
;
1157 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
1161 FIXME("Indexable temporary registers not supported.\n");
1165 struct wined3d_shader_indexable_temp
*reg
;
1167 if (!(reg
= heap_alloc(sizeof(*reg
))))
1168 return E_OUTOFMEMORY
;
1170 *reg
= ins
.declaration
.indexable_temp
;
1171 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
1174 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
1176 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1177 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
.type
;
1179 FIXME("Invalid instruction %#x for shader type %#x.\n",
1180 ins
.handler_idx
, shader_version
.type
);
1182 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
1184 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1185 if (reg_idx
>= MAX_REG_INPUT
)
1187 ERR("Invalid register index %u.\n", reg_idx
);
1190 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1191 wined3d_insert_interpolation_mode(shader
->u
.ps
.interpolation_mode
, reg_idx
, ins
.flags
);
1193 FIXME("Invalid instruction %#x for shader type %#x.\n",
1194 ins
.handler_idx
, shader_version
.type
);
1196 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
1198 if (ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUT
1199 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTGE
1200 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTLE
)
1202 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1203 shader
->u
.ps
.depth_output
= ins
.declaration
.dst
.reg
.type
;
1205 FIXME("Invalid instruction %#x for shader type %#x.\n",
1206 ins
.handler_idx
, shader_version
.type
);
1209 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
1211 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1212 shader
->u
.hs
.output_vertex_count
= ins
.declaration
.count
;
1214 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1216 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1218 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1219 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
.type
;
1221 FIXME("Invalid instruction %#x for shader type %#x.\n",
1222 ins
.handler_idx
, shader_version
.type
);
1224 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
1226 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1227 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1229 ERR("Invalid resource index %u.\n", reg_idx
);
1232 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1233 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1234 reg_maps
->resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1236 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
1238 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1239 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1241 ERR("Invalid resource index %u.\n", reg_idx
);
1244 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1245 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1246 reg_maps
->resource_info
[reg_idx
].flags
= 0;
1247 reg_maps
->resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1249 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
1251 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
1252 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
1254 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
1257 phase
->temporary_count
= ins
.declaration
.count
;
1259 reg_maps
->temporary_count
= ins
.declaration
.count
;
1261 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
1263 if (shader_version
.type
== WINED3D_SHADER_TYPE_DOMAIN
)
1264 shader
->u
.ds
.tessellator_domain
= ins
.declaration
.tessellator_domain
;
1265 else if (shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
1266 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1268 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
1270 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1271 shader
->u
.hs
.tessellator_output_primitive
= ins
.declaration
.tessellator_output_primitive
;
1273 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1275 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
1277 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1278 shader
->u
.hs
.tessellator_partitioning
= ins
.declaration
.tessellator_partitioning
;
1280 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1282 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
1284 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
, ins
.declaration
.tgsm_raw
.reg
.reg
.idx
[0].offset
,
1285 ins
.declaration
.tgsm_raw
.byte_count
/ 4, 0)))
1288 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
1290 unsigned int stride
= ins
.declaration
.tgsm_structured
.byte_stride
/ 4;
1291 unsigned int size
= stride
* ins
.declaration
.tgsm_structured
.structure_count
;
1292 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
,
1293 ins
.declaration
.tgsm_structured
.reg
.reg
.idx
[0].offset
, size
, stride
)))
1296 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
1298 if (shader_version
.type
== WINED3D_SHADER_TYPE_COMPUTE
)
1300 shader
->u
.cs
.thread_group_size
= ins
.declaration
.thread_group_size
;
1304 FIXME("Invalid instruction %#x for shader type %#x.\n",
1305 ins
.handler_idx
, shader_version
.type
);
1308 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
1310 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1311 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1313 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1317 FIXME("Ignoring raw UAV flags %#x.\n", ins
.flags
);
1318 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1319 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1320 reg_maps
->uav_resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1322 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
1324 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1325 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1327 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1331 FIXME("Ignoring structured UAV flags %#x.\n", ins
.flags
);
1332 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1333 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1334 reg_maps
->uav_resource_info
[reg_idx
].flags
= 0;
1335 reg_maps
->uav_resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1337 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1339 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1340 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1342 FIXME("Invalid instruction %#x for shader type %#x.\n",
1343 ins
.handler_idx
, shader_version
.type
);
1345 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1347 struct wined3d_shader_lconst
*lconst
;
1350 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1351 return E_OUTOFMEMORY
;
1353 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1354 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1355 value
= (float *)lconst
->value
;
1357 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1358 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1360 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1361 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1362 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1363 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1364 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1365 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1366 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1367 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1370 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1372 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1373 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1375 shader
->lconst_inf_or_nan
= TRUE
;
1378 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1380 struct wined3d_shader_lconst
*lconst
;
1382 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1383 return E_OUTOFMEMORY
;
1385 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1386 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1388 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1389 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1391 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1393 struct wined3d_shader_lconst
*lconst
;
1395 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1396 return E_OUTOFMEMORY
;
1398 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1399 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1401 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1402 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1404 /* Handle shader phases. */
1405 else if (ins
.handler_idx
== WINED3DSIH_HS_CONTROL_POINT_PHASE
1406 || ins
.handler_idx
== WINED3DSIH_HS_FORK_PHASE
1407 || ins
.handler_idx
== WINED3DSIH_HS_JOIN_PHASE
)
1409 if (FAILED(hr
= shader_record_shader_phase(shader
, &phase
, &ins
, current_ins
, prev_ins
)))
1412 /* For subroutine prototypes. */
1413 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1415 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1417 /* Set texture, address, temporary registers. */
1420 BOOL color0_mov
= FALSE
;
1423 /* This will loop over all the registers and try to
1424 * make a bitmask of the ones we're interested in.
1426 * Relative addressing tokens are ignored, but that's
1427 * okay, since we'll catch any address registers when
1428 * they are initialized (required by spec). */
1429 for (i
= 0; i
< ins
.dst_count
; ++i
)
1431 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1432 shader_version
.type
, constf_size
))
1433 return WINED3DERR_INVALIDCALL
;
1435 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1437 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1439 switch (ins
.dst
[i
].reg
.type
)
1441 case WINED3DSPR_RASTOUT
:
1442 if (shader_version
.major
>= 3)
1447 reg_maps
->output_registers
|= 1u << 10;
1448 shader_signature_from_usage(&output_signature_elements
[10],
1449 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1453 reg_maps
->output_registers
|= 1u << 11;
1454 shader_signature_from_usage(&output_signature_elements
[11],
1455 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1459 reg_maps
->output_registers
|= 1u << 11;
1460 shader_signature_from_usage(&output_signature_elements
[11],
1461 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1466 case WINED3DSPR_ATTROUT
:
1467 if (shader_version
.major
>= 3)
1472 if (reg_maps
->output_registers
& (1u << idx
))
1474 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1478 reg_maps
->output_registers
|= 1u << idx
;
1479 shader_signature_from_usage(&output_signature_elements
[idx
],
1480 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1485 case WINED3DSPR_TEXCRDOUT
: /* WINED3DSPR_OUTPUT */
1486 if (shader_version
.major
>= 3)
1488 if (idx
>= ARRAY_SIZE(reg_maps
->u
.output_registers_mask
))
1490 WARN("Invalid output register index %u.\n", idx
);
1493 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1496 if (idx
>= ARRAY_SIZE(reg_maps
->u
.texcoord_mask
))
1498 WARN("Invalid texcoord index %u.\n", idx
);
1501 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1502 if (reg_maps
->output_registers
& (1u << idx
))
1504 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1508 reg_maps
->output_registers
|= 1u << idx
;
1509 shader_signature_from_usage(&output_signature_elements
[idx
],
1510 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1519 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1521 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1523 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1524 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1525 * the mov and perform the sRGB write correction from the source register.
1527 * However, if the mov is only partial, we can't do this, and if the write
1528 * comes from an instruction other than MOV it is hard to do as well. If
1529 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1530 shader
->u
.ps
.color0_mov
= FALSE
;
1531 if (ins
.handler_idx
== WINED3DSIH_MOV
1532 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1534 /* Used later when the source register is read. */
1538 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1541 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1542 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1544 shader
->u
.ps
.color0_mov
= FALSE
;
1548 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1549 if (shader_version
.major
== 1
1550 && (ins
.handler_idx
== WINED3DSIH_TEX
1551 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1552 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1553 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1554 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1555 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1556 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1557 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1558 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1559 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1560 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1562 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1564 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1566 WARN("Invalid 1.x sampler index %u.\n", reg_idx
);
1570 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1571 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1572 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1573 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1575 /* texbem is only valid with < 1.4 pixel shaders */
1576 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1577 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1579 reg_maps
->bumpmat
|= 1u << reg_idx
;
1580 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1582 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1586 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1588 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1592 if (ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_ALLOC
|| ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_CONSUME
)
1594 unsigned int reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1595 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1597 ERR("Invalid UAV index %u.\n", reg_idx
);
1600 reg_maps
->uav_counter_mask
|= (1u << reg_idx
);
1602 else if ((WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1603 || (WINED3DSIH_IMM_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_IMM_ATOMIC_XOR
)
1604 || (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_UAV
)
1605 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
1606 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_UAV
)
1607 || (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
&& ins
.src
[2].reg
.type
== WINED3DSPR_UAV
))
1609 unsigned int reg_idx
;
1610 if (ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
|| ins
.handler_idx
== WINED3DSIH_LD_RAW
)
1611 reg_idx
= ins
.src
[1].reg
.idx
[0].offset
;
1612 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
)
1613 reg_idx
= ins
.src
[2].reg
.idx
[0].offset
;
1614 else if (WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1615 reg_idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1616 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
)
1617 reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1619 reg_idx
= ins
.dst
[1].reg
.idx
[0].offset
;
1620 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1622 ERR("Invalid UAV index %u.\n", reg_idx
);
1625 reg_maps
->uav_read_mask
|= (1u << reg_idx
);
1627 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1629 reg_maps
->usesnrm
= 1;
1631 else if (ins
.handler_idx
== WINED3DSIH_DSY
1632 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1633 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1635 reg_maps
->usesdsy
= 1;
1637 else if (ins
.handler_idx
== WINED3DSIH_DSX
1638 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1639 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1641 reg_maps
->usesdsx
= 1;
1643 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1644 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1645 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1646 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1647 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1648 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1649 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1650 || ins
.handler_idx
== WINED3DSIH_REP
)
1653 if (cur_loop_depth
> max_loop_depth
)
1654 max_loop_depth
= cur_loop_depth
;
1656 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1657 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1661 else if (ins
.handler_idx
== WINED3DSIH_GATHER4
1662 || ins
.handler_idx
== WINED3DSIH_GATHER4_C
1663 || ins
.handler_idx
== WINED3DSIH_SAMPLE
1664 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1665 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1666 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1667 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1668 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1670 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1671 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1673 else if (ins
.handler_idx
== WINED3DSIH_GATHER4_PO
1674 || ins
.handler_idx
== WINED3DSIH_GATHER4_PO_C
)
1676 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1677 ins
.src
[3].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1679 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
)
1681 shader_record_sample(reg_maps
, ins
.src
[0].reg
.idx
[0].offset
,
1682 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1684 else if (ins
.handler_idx
== WINED3DSIH_LD
1685 || ins
.handler_idx
== WINED3DSIH_LD2DMS
1686 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
)
1687 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1689 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1690 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1692 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
1693 && ins
.src
[2].reg
.type
== WINED3DSPR_RESOURCE
)
1695 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1696 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1700 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1701 shader_version
.type
, constf_size
))
1702 return WINED3DERR_INVALIDCALL
;
1704 for (i
= 0; i
< ins
.src_count
; ++i
)
1706 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1707 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1709 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1710 shader_version
.type
, constf_size
))
1711 return WINED3DERR_INVALIDCALL
;
1714 ++reg
.idx
[0].offset
;
1715 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1716 shader_version
.type
, constf_size
))
1717 return WINED3DERR_INVALIDCALL
;
1723 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1724 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1726 shader
->u
.ps
.color0_mov
= TRUE
;
1727 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1733 prev_ins
= current_ins
;
1735 reg_maps
->loop_depth
= max_loop_depth
;
1739 phase
->end
= prev_ins
;
1743 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1744 * R0 is written to the render target. */
1745 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1746 reg_maps
->rt_mask
|= (1u << 0);
1748 if (input_signature
->elements
)
1750 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1752 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1754 if (input_signature
->elements
[i
].register_idx
>= ARRAY_SIZE(shader
->u
.vs
.attributes
))
1756 WARN("Invalid input signature register index %u.\n", input_signature
->elements
[i
].register_idx
);
1757 return WINED3DERR_INVALIDCALL
;
1760 else if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1762 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1764 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1765 reg_maps
->usesfacing
= 1;
1767 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1770 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1772 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1773 struct wined3d_shader_signature_element
*e
;
1776 if (!(input_signature
->elements
= heap_calloc(count
, sizeof(*input_signature
->elements
))))
1777 return E_OUTOFMEMORY
;
1778 input_signature
->element_count
= count
;
1780 e
= input_signature
->elements
;
1781 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1783 if (!(reg_maps
->input_registers
& (1u << i
)))
1785 input_signature_elements
[i
].register_idx
= i
;
1786 *e
++ = input_signature_elements
[i
];
1790 if (output_signature
->elements
)
1792 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1794 const struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1797 reg_maps
->output_registers
|= 1u << e
->register_idx
;
1798 if (e
->sysval_semantic
== WINED3D_SV_CLIP_DISTANCE
)
1800 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1802 reg_maps
->clip_distance_mask
|= mask
;
1804 else if (e
->sysval_semantic
== WINED3D_SV_CULL_DISTANCE
)
1806 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1808 reg_maps
->cull_distance_mask
|= mask
;
1812 else if (reg_maps
->output_registers
)
1814 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1815 struct wined3d_shader_signature_element
*e
;
1817 if (!(output_signature
->elements
= heap_calloc(count
, sizeof(*output_signature
->elements
))))
1818 return E_OUTOFMEMORY
;
1819 output_signature
->element_count
= count
;
1821 e
= output_signature
->elements
;
1822 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1824 if (!(reg_maps
->output_registers
& (1u << i
)))
1826 *e
++ = output_signature_elements
[i
];
1833 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1835 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1837 heap_free(reg_maps
->constf
);
1838 heap_free(reg_maps
->sampler_map
.entries
);
1840 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1842 list_init(®_maps
->indexable_temps
);
1844 heap_free(reg_maps
->tgsm
);
1847 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1849 DWORD map
= 1u << max
;
1851 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1853 return wined3d_log2i(map
);
1856 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1858 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1860 shader_addline(buffer
, "refactoringAllowed");
1861 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1863 shader_addline(buffer
, " | ");
1866 if (global_flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1868 shader_addline(buffer
, "forceEarlyDepthStencil");
1869 global_flags
&= ~WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
;
1871 shader_addline(buffer
, " | ");
1874 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1876 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1877 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1881 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1884 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1886 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1888 shader_addline(buffer
, "_g");
1889 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1891 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1893 shader_addline(buffer
, "_t");
1894 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1898 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1901 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1903 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1905 shader_addline(buffer
, "_glc");
1906 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1908 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1910 shader_addline(buffer
, "_opc");
1911 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1915 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1918 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1919 enum wined3d_tessellator_domain domain
)
1923 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1924 shader_addline(buffer
, "line");
1926 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1927 shader_addline(buffer
, "triangle");
1929 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1930 shader_addline(buffer
, "quad");
1933 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1938 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1939 enum wined3d_tessellator_output_primitive output_primitive
)
1941 switch (output_primitive
)
1943 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1944 shader_addline(buffer
, "point");
1946 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1947 shader_addline(buffer
, "line");
1949 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1950 shader_addline(buffer
, "triangle_cw");
1952 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1953 shader_addline(buffer
, "triangle_ccw");
1956 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1961 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1962 enum wined3d_tessellator_partitioning partitioning
)
1964 switch (partitioning
)
1966 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1967 shader_addline(buffer
, "integer");
1969 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1970 shader_addline(buffer
, "pow2");
1972 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1973 shader_addline(buffer
, "fractional_odd");
1975 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1976 shader_addline(buffer
, "fractional_even");
1979 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1984 static void shader_dump_shader_input_sysval_semantic(struct wined3d_string_buffer
*buffer
,
1985 enum wined3d_shader_input_sysval_semantic semantic
)
1989 for (i
= 0; i
< ARRAY_SIZE(shader_input_sysval_semantic_names
); ++i
)
1991 if (shader_input_sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1993 shader_addline(buffer
, "%s", shader_input_sysval_semantic_names
[i
].sysval_name
);
1998 shader_addline(buffer
, "unknown_shader_input_sysval_semantic(%#x)", semantic
);
2001 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
2002 const struct wined3d_shader_semantic
*semantic
, unsigned int flags
,
2003 const struct wined3d_shader_version
*shader_version
)
2005 shader_addline(buffer
, "dcl");
2007 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
2009 switch (semantic
->resource_type
)
2011 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2012 shader_addline(buffer
, "_2d");
2015 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2016 shader_addline(buffer
, "_3d");
2019 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2020 shader_addline(buffer
, "_cube");
2024 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
2028 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2030 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
2031 shader_addline(buffer
, "_resource_");
2033 shader_addline(buffer
, "_uav_");
2034 switch (semantic
->resource_type
)
2036 case WINED3D_SHADER_RESOURCE_BUFFER
:
2037 shader_addline(buffer
, "buffer");
2040 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
2041 shader_addline(buffer
, "texture1d");
2044 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2045 shader_addline(buffer
, "texture2d");
2048 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
2049 shader_addline(buffer
, "texture2dms");
2052 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2053 shader_addline(buffer
, "texture3d");
2056 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2057 shader_addline(buffer
, "texturecube");
2060 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
2061 shader_addline(buffer
, "texture1darray");
2064 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
2065 shader_addline(buffer
, "texture2darray");
2068 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
2069 shader_addline(buffer
, "texture2dmsarray");
2072 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
:
2073 shader_addline(buffer
, "texturecubearray");
2077 shader_addline(buffer
, "unknown");
2080 if (semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2081 shader_dump_uav_flags(buffer
, flags
);
2082 switch (semantic
->resource_data_type
)
2084 case WINED3D_DATA_FLOAT
:
2085 shader_addline(buffer
, " (float)");
2088 case WINED3D_DATA_INT
:
2089 shader_addline(buffer
, " (int)");
2092 case WINED3D_DATA_UINT
:
2093 shader_addline(buffer
, " (uint)");
2096 case WINED3D_DATA_UNORM
:
2097 shader_addline(buffer
, " (unorm)");
2100 case WINED3D_DATA_SNORM
:
2101 shader_addline(buffer
, " (snorm)");
2105 shader_addline(buffer
, " (unknown)");
2111 /* Pixel shaders 3.0 don't have usage semantics. */
2112 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
2115 shader_addline(buffer
, "_");
2117 switch (semantic
->usage
)
2119 case WINED3D_DECL_USAGE_POSITION
:
2120 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
2123 case WINED3D_DECL_USAGE_BLEND_INDICES
:
2124 shader_addline(buffer
, "blend");
2127 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
2128 shader_addline(buffer
, "weight");
2131 case WINED3D_DECL_USAGE_NORMAL
:
2132 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
2135 case WINED3D_DECL_USAGE_PSIZE
:
2136 shader_addline(buffer
, "psize");
2139 case WINED3D_DECL_USAGE_COLOR
:
2140 if (!semantic
->usage_idx
)
2141 shader_addline(buffer
, "color");
2143 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
2146 case WINED3D_DECL_USAGE_TEXCOORD
:
2147 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
2150 case WINED3D_DECL_USAGE_TANGENT
:
2151 shader_addline(buffer
, "tangent");
2154 case WINED3D_DECL_USAGE_BINORMAL
:
2155 shader_addline(buffer
, "binormal");
2158 case WINED3D_DECL_USAGE_TESS_FACTOR
:
2159 shader_addline(buffer
, "tessfactor");
2162 case WINED3D_DECL_USAGE_POSITIONT
:
2163 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
2166 case WINED3D_DECL_USAGE_FOG
:
2167 shader_addline(buffer
, "fog");
2170 case WINED3D_DECL_USAGE_DEPTH
:
2171 shader_addline(buffer
, "depth");
2174 case WINED3D_DECL_USAGE_SAMPLE
:
2175 shader_addline(buffer
, "sample");
2179 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
2180 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
2185 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
2186 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
2188 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
2189 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
2190 UINT offset
= reg
->idx
[0].offset
;
2194 case WINED3DSPR_TEMP
:
2195 shader_addline(buffer
, "r");
2198 case WINED3DSPR_INPUT
:
2199 shader_addline(buffer
, "v");
2202 case WINED3DSPR_CONST
:
2203 case WINED3DSPR_CONST2
:
2204 case WINED3DSPR_CONST3
:
2205 case WINED3DSPR_CONST4
:
2206 shader_addline(buffer
, "c");
2207 offset
= shader_get_float_offset(reg
->type
, offset
);
2210 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
2211 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
2214 case WINED3DSPR_RASTOUT
:
2215 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
2218 case WINED3DSPR_COLOROUT
:
2219 shader_addline(buffer
, "oC");
2222 case WINED3DSPR_DEPTHOUT
:
2223 shader_addline(buffer
, "oDepth");
2226 case WINED3DSPR_DEPTHOUTGE
:
2227 shader_addline(buffer
, "oDepthGE");
2230 case WINED3DSPR_DEPTHOUTLE
:
2231 shader_addline(buffer
, "oDepthLE");
2234 case WINED3DSPR_ATTROUT
:
2235 shader_addline(buffer
, "oD");
2238 case WINED3DSPR_TEXCRDOUT
:
2239 /* Vertex shaders >= 3.0 use general purpose output registers
2240 * (WINED3DSPR_OUTPUT), which can include an address token. */
2241 if (shader_version
->major
>= 3)
2242 shader_addline(buffer
, "o");
2244 shader_addline(buffer
, "oT");
2247 case WINED3DSPR_CONSTINT
:
2248 shader_addline(buffer
, "i");
2251 case WINED3DSPR_CONSTBOOL
:
2252 shader_addline(buffer
, "b");
2255 case WINED3DSPR_LABEL
:
2256 shader_addline(buffer
, "l");
2259 case WINED3DSPR_LOOP
:
2260 shader_addline(buffer
, "aL");
2263 case WINED3DSPR_SAMPLER
:
2264 shader_addline(buffer
, "s");
2267 case WINED3DSPR_MISCTYPE
:
2270 FIXME("Unhandled misctype register %u.\n", offset
);
2271 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
2275 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
2279 case WINED3DSPR_PREDICATE
:
2280 shader_addline(buffer
, "p");
2283 case WINED3DSPR_IMMCONST
:
2284 shader_addline(buffer
, "l");
2287 case WINED3DSPR_CONSTBUFFER
:
2288 shader_addline(buffer
, "cb");
2291 case WINED3DSPR_IMMCONSTBUFFER
:
2292 shader_addline(buffer
, "icb");
2295 case WINED3DSPR_PRIMID
:
2296 shader_addline(buffer
, "primID");
2299 case WINED3DSPR_NULL
:
2300 shader_addline(buffer
, "null");
2303 case WINED3DSPR_RESOURCE
:
2304 shader_addline(buffer
, "t");
2307 case WINED3DSPR_UAV
:
2308 shader_addline(buffer
, "u");
2311 case WINED3DSPR_OUTPOINTID
:
2312 shader_addline(buffer
, "vOutputControlPointID");
2315 case WINED3DSPR_FORKINSTID
:
2316 shader_addline(buffer
, "vForkInstanceId");
2319 case WINED3DSPR_JOININSTID
:
2320 shader_addline(buffer
, "vJoinInstanceId");
2323 case WINED3DSPR_INCONTROLPOINT
:
2324 shader_addline(buffer
, "vicp");
2327 case WINED3DSPR_OUTCONTROLPOINT
:
2328 shader_addline(buffer
, "vocp");
2331 case WINED3DSPR_PATCHCONST
:
2332 shader_addline(buffer
, "vpc");
2335 case WINED3DSPR_TESSCOORD
:
2336 shader_addline(buffer
, "vDomainLocation");
2339 case WINED3DSPR_GROUPSHAREDMEM
:
2340 shader_addline(buffer
, "g");
2343 case WINED3DSPR_THREADID
:
2344 shader_addline(buffer
, "vThreadID");
2347 case WINED3DSPR_THREADGROUPID
:
2348 shader_addline(buffer
, "vThreadGroupID");
2351 case WINED3DSPR_LOCALTHREADID
:
2352 shader_addline(buffer
, "vThreadIDInGroup");
2355 case WINED3DSPR_LOCALTHREADINDEX
:
2356 shader_addline(buffer
, "vThreadIDInGroupFlattened");
2359 case WINED3DSPR_IDXTEMP
:
2360 shader_addline(buffer
, "x");
2363 case WINED3DSPR_STREAM
:
2364 shader_addline(buffer
, "m");
2367 case WINED3DSPR_FUNCTIONBODY
:
2368 shader_addline(buffer
, "fb");
2371 case WINED3DSPR_FUNCTIONPOINTER
:
2372 shader_addline(buffer
, "fp");
2375 case WINED3DSPR_COVERAGE
:
2376 shader_addline(buffer
, "vCoverage");
2379 case WINED3DSPR_SAMPLEMASK
:
2380 shader_addline(buffer
, "oMask");
2383 case WINED3DSPR_GSINSTID
:
2384 shader_addline(buffer
, "vGSInstanceID");
2388 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
2392 if (reg
->type
== WINED3DSPR_IMMCONST
)
2394 shader_addline(buffer
, "(");
2395 switch (reg
->immconst_type
)
2397 case WINED3D_IMMCONST_SCALAR
:
2398 switch (reg
->data_type
)
2400 case WINED3D_DATA_FLOAT
:
2401 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
2403 case WINED3D_DATA_INT
:
2404 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
2406 case WINED3D_DATA_RESOURCE
:
2407 case WINED3D_DATA_SAMPLER
:
2408 case WINED3D_DATA_UINT
:
2409 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
2412 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2417 case WINED3D_IMMCONST_VEC4
:
2418 switch (reg
->data_type
)
2420 case WINED3D_DATA_FLOAT
:
2421 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2422 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2423 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2425 case WINED3D_DATA_INT
:
2426 shader_addline(buffer
, "%d, %d, %d, %d",
2427 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2428 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2430 case WINED3D_DATA_RESOURCE
:
2431 case WINED3D_DATA_SAMPLER
:
2432 case WINED3D_DATA_UINT
:
2433 shader_addline(buffer
, "%u, %u, %u, %u",
2434 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2435 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2438 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2444 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2447 shader_addline(buffer
, ")");
2449 else if (reg
->type
!= WINED3DSPR_RASTOUT
2450 && reg
->type
!= WINED3DSPR_MISCTYPE
2451 && reg
->type
!= WINED3DSPR_NULL
)
2455 shader_addline(buffer
, "[");
2456 if (reg
->idx
[0].rel_addr
)
2458 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2459 shader_addline(buffer
, " + ");
2461 shader_addline(buffer
, "%u]", offset
);
2463 if (reg
->idx
[1].offset
!= ~0u)
2465 shader_addline(buffer
, "[");
2466 if (reg
->idx
[1].rel_addr
)
2468 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2469 shader_addline(buffer
, " + ");
2471 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2475 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2476 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2480 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2481 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2483 DWORD write_mask
= param
->write_mask
;
2485 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2487 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2489 static const char write_mask_chars
[] = "xyzw";
2491 shader_addline(buffer
, ".");
2492 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2493 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2494 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2495 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2496 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2497 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2498 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2499 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2503 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2504 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2506 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2507 DWORD swizzle
= param
->swizzle
;
2509 if (src_modifier
== WINED3DSPSM_NEG
2510 || src_modifier
== WINED3DSPSM_BIASNEG
2511 || src_modifier
== WINED3DSPSM_SIGNNEG
2512 || src_modifier
== WINED3DSPSM_X2NEG
2513 || src_modifier
== WINED3DSPSM_ABSNEG
)
2514 shader_addline(buffer
, "-");
2515 else if (src_modifier
== WINED3DSPSM_COMP
)
2516 shader_addline(buffer
, "1-");
2517 else if (src_modifier
== WINED3DSPSM_NOT
)
2518 shader_addline(buffer
, "!");
2520 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2521 shader_addline(buffer
, "abs(");
2523 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2525 switch (src_modifier
)
2527 case WINED3DSPSM_NONE
: break;
2528 case WINED3DSPSM_NEG
: break;
2529 case WINED3DSPSM_NOT
: break;
2530 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2531 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2532 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2533 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2534 case WINED3DSPSM_COMP
: break;
2535 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2536 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2537 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2538 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2539 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2540 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2541 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2544 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2546 static const char swizzle_chars
[] = "xyzw";
2547 DWORD swizzle_x
= swizzle
& 0x03;
2548 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2549 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2550 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2552 if (swizzle_x
== swizzle_y
2553 && swizzle_x
== swizzle_z
2554 && swizzle_x
== swizzle_w
)
2556 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2560 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2561 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2566 /* Shared code in order to generate the bulk of the shader string. */
2567 HRESULT
shader_generate_code(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2568 const struct wined3d_shader_reg_maps
*reg_maps
, void *backend_ctx
,
2569 const DWORD
*start
, const DWORD
*end
)
2571 struct wined3d_device
*device
= shader
->device
;
2572 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2573 void *fe_data
= shader
->frontend_data
;
2574 struct wined3d_shader_version shader_version
;
2575 struct wined3d_shader_parser_state state
;
2576 struct wined3d_shader_instruction ins
;
2577 struct wined3d_shader_tex_mx tex_mx
;
2578 struct wined3d_shader_context ctx
;
2581 /* Initialize current parsing state. */
2582 tex_mx
.current_row
= 0;
2583 state
.current_loop_depth
= 0;
2584 state
.current_loop_reg
= 0;
2585 state
.in_subroutine
= FALSE
;
2587 ctx
.shader
= shader
;
2588 ctx
.gl_info
= &device
->adapter
->gl_info
;
2589 ctx
.reg_maps
= reg_maps
;
2590 ctx
.buffer
= buffer
;
2591 ctx
.tex_mx
= &tex_mx
;
2593 ctx
.backend_data
= backend_ctx
;
2596 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2600 while (!fe
->shader_is_end(fe_data
, &ptr
) && ptr
!= end
)
2603 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2605 /* Unknown opcode and its parameters. */
2606 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2608 WARN("Encountered unrecognised or invalid instruction.\n");
2609 return WINED3DERR_INVALIDCALL
;
2613 FIXME("Predicates not implemented.\n");
2615 /* Call appropriate function for output target */
2616 device
->shader_backend
->shader_handle_instruction(&ins
);
2622 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2623 const struct wined3d_shader_dst_param
*dst
)
2625 DWORD mmask
= dst
->modifiers
;
2630 case 13: shader_addline(buffer
, "_d8"); break;
2631 case 14: shader_addline(buffer
, "_d4"); break;
2632 case 15: shader_addline(buffer
, "_d2"); break;
2633 case 1: shader_addline(buffer
, "_x2"); break;
2634 case 2: shader_addline(buffer
, "_x4"); break;
2635 case 3: shader_addline(buffer
, "_x8"); break;
2636 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2639 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2640 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2641 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2643 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2644 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2647 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2648 const struct wined3d_shader_primitive_type
*primitive_type
)
2650 switch (primitive_type
->type
)
2652 case WINED3D_PT_UNDEFINED
:
2653 shader_addline(buffer
, "undefined");
2655 case WINED3D_PT_POINTLIST
:
2656 shader_addline(buffer
, "pointlist");
2658 case WINED3D_PT_LINELIST
:
2659 shader_addline(buffer
, "linelist");
2661 case WINED3D_PT_LINESTRIP
:
2662 shader_addline(buffer
, "linestrip");
2664 case WINED3D_PT_TRIANGLELIST
:
2665 shader_addline(buffer
, "trianglelist");
2667 case WINED3D_PT_TRIANGLESTRIP
:
2668 shader_addline(buffer
, "trianglestrip");
2670 case WINED3D_PT_TRIANGLEFAN
:
2671 shader_addline(buffer
, "trianglefan");
2673 case WINED3D_PT_LINELIST_ADJ
:
2674 shader_addline(buffer
, "linelist_adj");
2676 case WINED3D_PT_LINESTRIP_ADJ
:
2677 shader_addline(buffer
, "linestrip_adj");
2679 case WINED3D_PT_TRIANGLELIST_ADJ
:
2680 shader_addline(buffer
, "trianglelist_adj");
2682 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2683 shader_addline(buffer
, "trianglestrip_adj");
2685 case WINED3D_PT_PATCH
:
2686 shader_addline(buffer
, "patch%u", primitive_type
->patch_vertex_count
);
2689 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
->type
);
2694 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2695 enum wined3d_shader_interpolation_mode interpolation_mode
)
2697 switch (interpolation_mode
)
2699 case WINED3DSIM_CONSTANT
:
2700 shader_addline(buffer
, "constant");
2702 case WINED3DSIM_LINEAR
:
2703 shader_addline(buffer
, "linear");
2705 case WINED3DSIM_LINEAR_CENTROID
:
2706 shader_addline(buffer
, "linear centroid");
2708 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2709 shader_addline(buffer
, "linear noperspective");
2711 case WINED3DSIM_LINEAR_SAMPLE
:
2712 shader_addline(buffer
, "linear sample");
2714 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2715 shader_addline(buffer
, "linear noperspective centroid");
2717 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2718 shader_addline(buffer
, "linear noperspective sample");
2721 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2726 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
)
2728 struct wined3d_shader_version shader_version
;
2729 struct wined3d_string_buffer buffer
;
2730 const char *type_prefix
;
2735 if (!string_buffer_init(&buffer
))
2737 ERR("Failed to initialize string buffer.\n");
2741 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2743 TRACE("Parsing %p.\n", ptr
);
2745 switch (shader_version
.type
)
2747 case WINED3D_SHADER_TYPE_VERTEX
:
2751 case WINED3D_SHADER_TYPE_HULL
:
2755 case WINED3D_SHADER_TYPE_DOMAIN
:
2759 case WINED3D_SHADER_TYPE_GEOMETRY
:
2763 case WINED3D_SHADER_TYPE_PIXEL
:
2767 case WINED3D_SHADER_TYPE_COMPUTE
:
2772 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2773 type_prefix
= "unknown";
2777 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2779 while (!fe
->shader_is_end(fe_data
, &ptr
))
2781 struct wined3d_shader_instruction ins
;
2783 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2784 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2786 WARN("Skipping unrecognized instruction.\n");
2787 shader_addline(&buffer
, "<unrecognized instruction>\n");
2791 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2793 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, ins
.flags
, &shader_version
);
2794 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2795 shader_addline(&buffer
, " ");
2796 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2798 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2800 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2801 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2802 shader_addline(&buffer
, ", %s",
2803 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2805 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2807 shader_addline(&buffer
, "%s fb%u",
2808 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2810 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2812 shader_addline(&buffer
, "%s ft%u = {...}",
2813 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2815 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2817 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2818 shader_dump_global_flags(&buffer
, ins
.flags
);
2820 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2822 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2823 ins
.declaration
.max_tessellation_factor
);
2825 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2827 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2828 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2830 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2831 ins
.declaration
.icb
->data
[4 * i
+ 0],
2832 ins
.declaration
.icb
->data
[4 * i
+ 1],
2833 ins
.declaration
.icb
->data
[4 * i
+ 2],
2834 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2836 shader_addline(&buffer
, "}");
2838 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEX_RANGE
)
2840 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2841 shader_dump_dst_param(&buffer
, &ins
.declaration
.index_range
.first_register
, &shader_version
);
2842 shader_addline(&buffer
, " %u", ins
.declaration
.index_range
.last_register
);
2844 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2846 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2847 ins
.declaration
.indexable_temp
.register_idx
,
2848 ins
.declaration
.indexable_temp
.register_size
,
2849 ins
.declaration
.indexable_temp
.component_count
);
2851 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2853 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2854 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2855 shader_addline(&buffer
, " ");
2856 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2858 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2859 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2860 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2861 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2863 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2864 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2865 shader_addline(&buffer
, ", ");
2866 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2868 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2870 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2871 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2872 shader_addline(&buffer
, " ");
2873 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2874 shader_addline(&buffer
, ", ");
2875 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2877 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2878 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2880 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2881 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2883 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2884 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2886 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2887 shader_dump_primitive_type(&buffer
, &ins
.declaration
.primitive_type
);
2889 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2891 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2892 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2893 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2895 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2897 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2898 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2900 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2902 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2903 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2904 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2906 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2908 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2909 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2910 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2911 shader_addline(&buffer
, ", comparisonMode");
2913 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2914 || ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
2915 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2916 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
2917 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2918 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
2919 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
2921 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2923 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2925 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2926 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2928 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2930 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2931 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2933 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2935 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2936 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2938 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2940 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2941 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2942 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2944 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2946 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2947 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2948 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2949 ins
.declaration
.tgsm_structured
.structure_count
);
2951 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2953 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2954 ins
.declaration
.thread_group_size
.x
,
2955 ins
.declaration
.thread_group_size
.y
,
2956 ins
.declaration
.thread_group_size
.z
);
2958 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2960 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2961 shader_dump_uav_flags(&buffer
, ins
.flags
);
2962 shader_addline(&buffer
, " ");
2963 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2965 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2967 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2968 shader_dump_uav_flags(&buffer
, ins
.flags
);
2969 shader_addline(&buffer
, " ");
2970 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2971 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2973 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2975 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2976 ins
.dst
[0].reg
.idx
[0].offset
),
2977 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
2978 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
2979 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
2980 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
2982 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2984 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2985 ins
.src
[0].reg
.u
.immconst_data
[0],
2986 ins
.src
[0].reg
.u
.immconst_data
[1],
2987 ins
.src
[0].reg
.u
.immconst_data
[2],
2988 ins
.src
[0].reg
.u
.immconst_data
[3]);
2990 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2992 shader_addline(&buffer
, "defb b%u = %s",
2993 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
2999 shader_addline(&buffer
, "(");
3000 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
3001 shader_addline(&buffer
, ") ");
3004 /* PixWin marks instructions with the coissue flag with a '+' */
3006 shader_addline(&buffer
, "+");
3008 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
3010 if (ins
.handler_idx
== WINED3DSIH_BREAKP
3011 || ins
.handler_idx
== WINED3DSIH_CONTINUEP
3012 || ins
.handler_idx
== WINED3DSIH_IF
3013 || ins
.handler_idx
== WINED3DSIH_RETP
3014 || ins
.handler_idx
== WINED3DSIH_TEXKILL
)
3018 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
3019 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
3020 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
3023 else if (ins
.handler_idx
== WINED3DSIH_IFC
3024 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
3028 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
3029 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
3030 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
3031 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
3032 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
3033 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
3034 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
3037 else if (ins
.handler_idx
== WINED3DSIH_TEX
3038 && shader_version
.major
>= 2
3039 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
3041 shader_addline(&buffer
, "p");
3043 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
3047 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
3048 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3049 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3052 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
3056 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3057 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3060 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
3062 shader_dump_sync_flags(&buffer
, ins
.flags
);
3065 if (wined3d_shader_instruction_has_texel_offset(&ins
))
3066 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
3068 for (i
= 0; i
< ins
.dst_count
; ++i
)
3070 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
3071 shader_addline(&buffer
, !i
? " " : ", ");
3072 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
3075 /* Other source tokens */
3076 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
3078 shader_addline(&buffer
, !i
? " " : ", ");
3079 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
3082 shader_addline(&buffer
, "\n");
3085 for (p
= buffer
.buffer
; *p
; p
= q
)
3087 if (!(q
= strstr(p
, "\n")))
3091 TRACE(" %.*s", (int)(q
- p
), p
);
3094 string_buffer_free(&buffer
);
3097 static void shader_cleanup(struct wined3d_shader
*shader
)
3099 if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
3101 heap_free(shader
->u
.hs
.phases
.control_point
);
3102 heap_free(shader
->u
.hs
.phases
.fork
);
3103 heap_free(shader
->u
.hs
.phases
.join
);
3105 else if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
3107 heap_free(shader
->u
.gs
.so_desc
.elements
);
3110 heap_free(shader
->patch_constant_signature
.elements
);
3111 heap_free(shader
->output_signature
.elements
);
3112 heap_free(shader
->input_signature
.elements
);
3113 heap_free(shader
->signature_strings
);
3114 shader
->device
->shader_backend
->shader_destroy(shader
);
3115 shader_cleanup_reg_maps(&shader
->reg_maps
);
3116 heap_free(shader
->function
);
3117 shader_delete_constant_list(&shader
->constantsF
);
3118 shader_delete_constant_list(&shader
->constantsB
);
3119 shader_delete_constant_list(&shader
->constantsI
);
3120 list_remove(&shader
->shader_list_entry
);
3122 if (shader
->frontend
&& shader
->frontend_data
)
3123 shader
->frontend
->shader_free(shader
->frontend_data
);
3126 struct shader_none_priv
3128 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
3129 const struct fragment_pipeline
*fragment_pipe
;
3130 BOOL ffp_proj_control
;
3133 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
3134 static void shader_none_precompile(void *shader_priv
, struct wined3d_shader
*shader
) {}
3135 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
3136 const struct wined3d_state
*state
) {}
3137 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3138 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3139 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
3140 const struct wined3d_state
*state
) {}
3141 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
3142 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
3143 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
3145 /* Context activation is done by the caller. */
3146 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
3147 const struct wined3d_state
*state
)
3149 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3150 struct shader_none_priv
*priv
= shader_priv
;
3152 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
3153 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
3156 /* Context activation is done by the caller. */
3157 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
3159 struct shader_none_priv
*priv
= shader_priv
;
3160 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3162 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
3163 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
3165 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
3166 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
3167 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
3168 | (1u << WINED3D_SHADER_TYPE_HULL
)
3169 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
3170 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
3173 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
3174 const struct fragment_pipeline
*fragment_pipe
)
3176 struct fragment_caps fragment_caps
;
3177 void *vertex_priv
, *fragment_priv
;
3178 struct shader_none_priv
*priv
;
3180 if (!(priv
= heap_alloc(sizeof(*priv
))))
3181 return E_OUTOFMEMORY
;
3183 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
3185 ERR("Failed to initialize vertex pipe.\n");
3190 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
3192 ERR("Failed to initialize fragment pipe.\n");
3193 vertex_pipe
->vp_free(device
);
3198 priv
->vertex_pipe
= vertex_pipe
;
3199 priv
->fragment_pipe
= fragment_pipe
;
3200 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
3201 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
3203 device
->vertex_priv
= vertex_priv
;
3204 device
->fragment_priv
= fragment_priv
;
3205 device
->shader_priv
= priv
;
3210 static void shader_none_free(struct wined3d_device
*device
)
3212 struct shader_none_priv
*priv
= device
->shader_priv
;
3214 priv
->fragment_pipe
->free_private(device
);
3215 priv
->vertex_pipe
->vp_free(device
);
3219 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
3224 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
3226 /* Set the shader caps to 0 for the none shader backend */
3227 caps
->vs_version
= 0;
3228 caps
->hs_version
= 0;
3229 caps
->ds_version
= 0;
3230 caps
->gs_version
= 0;
3231 caps
->ps_version
= 0;
3232 caps
->cs_version
= 0;
3233 caps
->vs_uniform_count
= 0;
3234 caps
->ps_uniform_count
= 0;
3235 caps
->ps_1x_max_value
= 0.0f
;
3236 caps
->varying_count
= 0;
3237 caps
->wined3d_caps
= 0;
3240 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
3242 /* We "support" every possible fixup, since we don't support any shader
3243 * model, and will never have to actually sample a texture. */
3247 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
3249 struct shader_none_priv
*priv
= shader_priv
;
3251 return priv
->ffp_proj_control
;
3254 const struct wined3d_shader_backend_ops none_shader_backend
=
3256 shader_none_handle_instruction
,
3257 shader_none_precompile
,
3259 shader_none_select_compute
,
3260 shader_none_disable
,
3261 shader_none_update_float_vertex_constants
,
3262 shader_none_update_float_pixel_constants
,
3263 shader_none_load_constants
,
3264 shader_none_destroy
,
3267 shader_none_allocate_context_data
,
3268 shader_none_free_context_data
,
3269 shader_none_init_context_state
,
3270 shader_none_get_caps
,
3271 shader_none_color_fixup_supported
,
3272 shader_none_has_ffp_proj_control
,
3275 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, DWORD float_const_count
,
3276 enum wined3d_shader_type type
, unsigned int max_version
)
3278 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3279 const struct wined3d_shader_frontend
*fe
;
3281 unsigned int backend_version
;
3282 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
3284 TRACE("shader %p, float_const_count %u, type %#x, max_version %u.\n",
3285 shader
, float_const_count
, type
, max_version
);
3287 fe
= shader
->frontend
;
3288 if (!(shader
->frontend_data
= fe
->shader_init(shader
->function
,
3289 shader
->functionLength
, &shader
->output_signature
)))
3291 FIXME("Failed to initialize frontend.\n");
3292 return WINED3DERR_INVALIDCALL
;
3295 /* First pass: trace shader. */
3296 if (TRACE_ON(d3d_shader
))
3297 shader_trace_init(fe
, shader
->frontend_data
);
3299 /* Second pass: figure out which registers are used, what the semantics are, etc. */
3300 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
3301 &shader
->output_signature
, float_const_count
)))
3304 if (reg_maps
->shader_version
.type
!= type
)
3306 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
3307 return WINED3DERR_INVALIDCALL
;
3309 if (reg_maps
->shader_version
.major
> max_version
)
3311 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
3312 return WINED3DERR_INVALIDCALL
;
3316 case WINED3D_SHADER_TYPE_VERTEX
:
3317 backend_version
= d3d_info
->limits
.vs_version
;
3319 case WINED3D_SHADER_TYPE_HULL
:
3320 backend_version
= d3d_info
->limits
.hs_version
;
3322 case WINED3D_SHADER_TYPE_DOMAIN
:
3323 backend_version
= d3d_info
->limits
.ds_version
;
3325 case WINED3D_SHADER_TYPE_GEOMETRY
:
3326 backend_version
= d3d_info
->limits
.gs_version
;
3328 case WINED3D_SHADER_TYPE_PIXEL
:
3329 backend_version
= d3d_info
->limits
.ps_version
;
3331 case WINED3D_SHADER_TYPE_COMPUTE
:
3332 backend_version
= d3d_info
->limits
.cs_version
;
3335 FIXME("No backend version-checking for this shader type.\n");
3336 backend_version
= 0;
3338 if (reg_maps
->shader_version
.major
> backend_version
)
3340 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
3341 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
3342 return WINED3DERR_INVALIDCALL
;
3348 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
3350 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
3352 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
3357 static void wined3d_shader_init_object(void *object
)
3359 struct wined3d_shader
*shader
= object
;
3360 struct wined3d_device
*device
= shader
->device
;
3362 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3364 device
->shader_backend
->shader_precompile(device
->shader_priv
, shader
);
3367 static void wined3d_shader_destroy_object(void *object
)
3369 shader_cleanup(object
);
3373 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
3375 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
3377 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
3381 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
3382 wined3d_cs_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
3388 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
3390 TRACE("shader %p.\n", shader
);
3392 return shader
->parent
;
3395 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
3396 void *byte_code
, UINT
*byte_code_size
)
3398 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
3402 *byte_code_size
= shader
->functionLength
;
3406 if (*byte_code_size
< shader
->functionLength
)
3408 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
3409 * than the required size we should write the required size and
3410 * return D3DERR_MOREDATA. That's not actually true. */
3411 return WINED3DERR_INVALIDCALL
;
3414 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
3419 /* Set local constants for d3d8 shaders. */
3420 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
3421 UINT start_idx
, const float *src_data
, UINT count
)
3423 UINT end_idx
= start_idx
+ count
;
3426 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
3428 if (end_idx
> shader
->limits
->constant_float
)
3430 WARN("end_idx %u > float constants limit %u.\n",
3431 end_idx
, shader
->limits
->constant_float
);
3432 end_idx
= shader
->limits
->constant_float
;
3435 for (i
= start_idx
; i
< end_idx
; ++i
)
3437 struct wined3d_shader_lconst
*lconst
;
3440 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
3441 return E_OUTOFMEMORY
;
3444 value
= (float *)lconst
->value
;
3445 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3446 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3448 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3449 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3451 shader
->lconst_inf_or_nan
= TRUE
;
3458 static void init_interpolation_compile_args(DWORD
*interpolation_args
,
3459 const struct wined3d_shader
*pixel_shader
, const struct wined3d_gl_info
*gl_info
)
3461 if (!needs_interpolation_qualifiers_for_shader_outputs(gl_info
)
3462 || !pixel_shader
|| pixel_shader
->reg_maps
.shader_version
.major
< 4)
3464 memset(interpolation_args
, 0, sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3468 memcpy(interpolation_args
, pixel_shader
->u
.ps
.interpolation_mode
,
3469 sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3472 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3473 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_context
*context
)
3475 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3476 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3477 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3478 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3479 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3481 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3482 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3483 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3484 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3485 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
3486 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3487 args
->next_shader_type
= hull_shader
? WINED3D_SHADER_TYPE_HULL
3488 : geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3489 if (shader
->reg_maps
.shader_version
.major
>= 4)
3490 args
->next_shader_input_count
= hull_shader
? hull_shader
->limits
->packed_input
3491 : geometry_shader
? geometry_shader
->limits
->packed_input
3492 : pixel_shader
? pixel_shader
->limits
->packed_input
: 0;
3494 args
->next_shader_input_count
= 0;
3495 args
->swizzle_map
= swizzle_map
;
3496 if (d3d_info
->emulated_flatshading
)
3497 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3499 args
->flatshading
= 0;
3501 init_interpolation_compile_args(args
->interpolation_mode
,
3502 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, gl_info
);
3505 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3507 if (usage_idx1
!= usage_idx2
)
3509 if (usage1
== usage2
)
3511 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3513 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3519 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3520 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3522 WORD map
= shader
->reg_maps
.input_registers
;
3525 for (i
= 0; map
; map
>>= 1, ++i
)
3527 if (!(map
& 1)) continue;
3529 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3530 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3539 static HRESULT
shader_signature_calculate_strings_length(const struct wined3d_shader_signature
*signature
,
3542 struct wined3d_shader_signature_element
*e
;
3546 for (i
= 0; i
< signature
->element_count
; ++i
)
3548 e
= &signature
->elements
[i
];
3549 len
= strlen(e
->semantic_name
);
3550 if (len
>= ~(SIZE_T
)0 - *total
)
3551 return E_OUTOFMEMORY
;
3558 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
3559 const struct wined3d_shader_signature
*src
, char **signature_strings
)
3561 struct wined3d_shader_signature_element
*e
;
3566 if (!src
->element_count
)
3569 ptr
= *signature_strings
;
3571 dst
->element_count
= src
->element_count
;
3572 if (!(dst
->elements
= heap_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
3573 return E_OUTOFMEMORY
;
3575 for (i
= 0; i
< src
->element_count
; ++i
)
3577 e
= &src
->elements
[i
];
3578 dst
->elements
[i
] = *e
;
3580 len
= strlen(e
->semantic_name
);
3581 memcpy(ptr
, e
->semantic_name
, len
+ 1);
3582 dst
->elements
[i
].semantic_name
= ptr
;
3586 *signature_strings
= ptr
;
3591 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3592 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
3593 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3595 size_t byte_code_size
;
3600 TRACE("byte_code %p, byte_code_size %#lx, format %#x, max_version %#x.\n",
3601 desc
->byte_code
, (long)desc
->byte_code_size
, desc
->format
, desc
->max_version
);
3603 if (!desc
->byte_code
)
3604 return WINED3DERR_INVALIDCALL
;
3606 if (!(shader
->frontend
= shader_select_frontend(desc
->format
)))
3608 FIXME("Unable to find frontend for shader.\n");
3609 return WINED3DERR_INVALIDCALL
;
3613 shader
->device
= device
;
3614 shader
->parent
= parent
;
3615 shader
->parent_ops
= parent_ops
;
3618 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->input_signature
, &total
)))
3620 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->output_signature
, &total
)))
3622 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->patch_constant_signature
, &total
)))
3624 if (total
&& !(shader
->signature_strings
= heap_alloc(total
)))
3625 return E_OUTOFMEMORY
;
3626 ptr
= shader
->signature_strings
;
3628 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
3630 heap_free(shader
->signature_strings
);
3633 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
3635 heap_free(shader
->input_signature
.elements
);
3636 heap_free(shader
->signature_strings
);
3639 if (FAILED(hr
= shader_signature_copy(&shader
->patch_constant_signature
, &desc
->patch_constant_signature
, &ptr
)))
3641 heap_free(shader
->output_signature
.elements
);
3642 heap_free(shader
->input_signature
.elements
);
3643 heap_free(shader
->signature_strings
);
3647 list_init(&shader
->linked_programs
);
3648 list_init(&shader
->constantsF
);
3649 list_init(&shader
->constantsB
);
3650 list_init(&shader
->constantsI
);
3651 shader
->lconst_inf_or_nan
= FALSE
;
3652 list_init(&shader
->reg_maps
.indexable_temps
);
3653 list_init(&shader
->shader_list_entry
);
3655 byte_code_size
= desc
->byte_code_size
;
3656 if (byte_code_size
== ~(size_t)0)
3658 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
3659 struct wined3d_shader_version shader_version
;
3660 struct wined3d_shader_instruction ins
;
3664 if (!(fe_data
= fe
->shader_init(desc
->byte_code
, byte_code_size
, &shader
->output_signature
)))
3666 WARN("Failed to initialise frontend data.\n");
3667 shader_cleanup(shader
);
3668 return WINED3DERR_INVALIDCALL
;
3671 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3672 while (!fe
->shader_is_end(fe_data
, &ptr
))
3673 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
3675 fe
->shader_free(fe_data
);
3677 byte_code_size
= (ptr
- desc
->byte_code
) * sizeof(*ptr
);
3680 if (!(shader
->function
= heap_alloc(byte_code_size
)))
3682 shader_cleanup(shader
);
3683 return E_OUTOFMEMORY
;
3685 memcpy(shader
->function
, desc
->byte_code
, byte_code_size
);
3686 shader
->functionLength
= byte_code_size
;
3688 if (FAILED(hr
= shader_set_function(shader
, float_const_count
, type
, desc
->max_version
)))
3690 WARN("Failed to set function, hr %#x.\n", hr
);
3691 shader_cleanup(shader
);
3695 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3700 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3701 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3703 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3707 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3708 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3711 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3713 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3715 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3718 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3719 shader_usage_from_semantic_name(input
->semantic_name
);
3720 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3723 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3724 shader
->load_local_constsF
= TRUE
;
3729 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3730 const struct wined3d_shader_desc
*desc
, const struct wined3d_stream_output_desc
*so_desc
,
3731 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3733 struct wined3d_stream_output_element
*elements
= NULL
;
3734 enum wined3d_shader_type shader_type
;
3739 shader_type
= shader_get_shader_type(desc
);
3740 switch (shader_type
)
3742 case WINED3D_SHADER_TYPE_VERTEX
:
3743 case WINED3D_SHADER_TYPE_DOMAIN
:
3744 FIXME("Stream output not supported for %s.\n", debug_shader_type(shader_type
));
3751 if (so_desc
&& !(elements
= heap_calloc(so_desc
->element_count
, sizeof(*elements
))))
3752 return E_OUTOFMEMORY
;
3754 if (FAILED(hr
= shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
)))
3756 heap_free(elements
);
3762 shader
->u
.gs
.so_desc
= *so_desc
;
3763 shader
->u
.gs
.so_desc
.elements
= elements
;
3764 memcpy(elements
, so_desc
->elements
, so_desc
->element_count
* sizeof(*elements
));
3770 void find_ds_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3771 struct ds_compile_args
*args
, const struct wined3d_context
*context
)
3773 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3774 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3775 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3776 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3778 args
->tessellator_output_primitive
= hull_shader
->u
.hs
.tessellator_output_primitive
;
3779 args
->tessellator_partitioning
= hull_shader
->u
.hs
.tessellator_partitioning
;
3781 args
->output_count
= geometry_shader
? geometry_shader
->limits
->packed_input
3782 : pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3783 args
->next_shader_type
= geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3785 args
->render_offscreen
= context
->render_offscreen
;
3787 init_interpolation_compile_args(args
->interpolation_mode
,
3788 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, gl_info
);
3793 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3794 struct gs_compile_args
*args
, const struct wined3d_context
*context
)
3796 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3797 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3799 args
->output_count
= pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3801 init_interpolation_compile_args(args
->interpolation_mode
, pixel_shader
, gl_info
);
3804 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3805 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3807 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3808 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3809 const struct wined3d_texture
*texture
;
3812 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3813 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3815 static unsigned int warned
= 0;
3817 args
->srgb_correction
= 1;
3818 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3819 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3820 "support, expect rendering artifacts.\n");
3823 if (shader
->reg_maps
.shader_version
.major
== 1
3824 && shader
->reg_maps
.shader_version
.minor
<= 3)
3826 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3828 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3830 if (flags
& WINED3D_TTFF_PROJECTED
)
3832 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3834 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3836 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3838 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3839 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3841 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3843 struct wined3d_vertex_declaration_element
*element
=
3844 &state
->vertex_declaration
->elements
[j
];
3846 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3847 && element
->usage_idx
== index
)
3849 max_valid
= element
->format
->component_count
;
3853 if (!tex_transform
|| tex_transform
> max_valid
)
3855 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3856 tex_transform
, max_valid
);
3857 tex_transform
= max_valid
;
3859 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3860 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3861 && tex_transform
> WINED3D_TTFF_COUNT2
)
3862 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3863 && tex_transform
> WINED3D_TTFF_COUNT3
))
3864 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3867 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3868 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3869 i
, tex_transform
, resource_type
);
3873 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3875 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3879 if (shader
->reg_maps
.shader_version
.major
== 1
3880 && shader
->reg_maps
.shader_version
.minor
<= 4)
3882 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3884 const struct wined3d_texture
*texture
= state
->textures
[i
];
3886 if (!shader
->reg_maps
.resource_info
[i
].type
)
3889 /* Treat unbound textures as 2D. The dummy texture will provide
3890 * the proper sample value. The tex_types bitmap defaults to
3891 * 2D because of the memset. */
3895 switch (texture
->target
)
3897 /* RECT textures are distinguished from 2D textures via np2_fixup */
3902 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3905 case GL_TEXTURE_CUBE_MAP_ARB
:
3906 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3912 if (shader
->reg_maps
.shader_version
.major
>= 4)
3914 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3916 for (i
= 0 ; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3917 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3918 args
->np2_fixup
= 0;
3922 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3924 if (!shader
->reg_maps
.resource_info
[i
].type
)
3927 texture
= state
->textures
[i
];
3930 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3933 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3934 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3936 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3938 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3939 args
->shadow
|= 1u << i
;
3941 /* Flag samplers that need NP2 texcoord fixup. */
3942 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3943 args
->np2_fixup
|= (1u << i
);
3947 if (shader
->reg_maps
.shader_version
.major
>= 3)
3949 if (position_transformed
)
3950 args
->vp_mode
= WINED3D_VP_MODE_NONE
;
3951 else if (use_vs(state
))
3952 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
3954 args
->vp_mode
= WINED3D_VP_MODE_FF
;
3955 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3959 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
3960 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3962 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3964 case WINED3D_FOG_NONE
:
3965 if (position_transformed
|| use_vs(state
))
3967 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3971 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3973 case WINED3D_FOG_NONE
: /* Fall through. */
3974 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3975 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3976 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3980 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3981 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3982 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3987 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3991 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3993 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3995 args
->texcoords_initialized
= 0;
3996 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4000 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
4001 args
->texcoords_initialized
|= 1u << i
;
4005 const struct wined3d_stream_info
*si
= &context
->stream_info
;
4006 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4008 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
4009 & WINED3D_FFP_TCI_MASK
4010 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
4011 args
->texcoords_initialized
|= 1u << i
;
4017 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
4020 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
4021 && state
->gl_primitive_type
== GL_POINTS
;
4023 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
4024 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
4026 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
4027 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
4028 : WINED3D_CMP_ALWAYS
) - 1;
4030 if (d3d_info
->emulated_flatshading
)
4031 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4033 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
4034 ? context
->render_offscreen
: 0;
4037 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
4038 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
4040 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
4041 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
4044 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
4045 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
4048 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4050 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4053 highest_reg_used
= i
;
4057 /* Don't do any register mapping magic if it is not needed, or if we can't
4058 * achieve anything anyway */
4059 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
4060 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
4061 || shader
->reg_maps
.shader_version
.major
>= 4)
4063 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
4065 /* This happens with relative addressing. The input mapper function
4066 * warns about this if the higher registers are declared too, so
4067 * don't write a FIXME here */
4068 WARN("More varying registers used than supported\n");
4071 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4073 shader
->u
.ps
.input_reg_map
[i
] = i
;
4076 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
4080 shader
->u
.ps
.declared_in_count
= 0;
4081 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4083 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4084 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
4085 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
4092 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
4094 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
4095 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
4098 if (reg_maps
->shader_version
.major
!= 1) return;
4100 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4102 /* We don't sample from this sampler. */
4103 if (!resource_info
[i
].type
)
4106 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
4108 case WINED3D_SHADER_TEX_2D
:
4109 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
4112 case WINED3D_SHADER_TEX_3D
:
4113 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
4116 case WINED3D_SHADER_TEX_CUBE
:
4117 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
4123 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4124 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4126 struct wined3d_shader
*object
;
4129 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4130 device
, desc
, parent
, parent_ops
, shader
);
4132 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4133 return E_OUTOFMEMORY
;
4135 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
)))
4137 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
4142 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4144 TRACE("Created compute shader %p.\n", object
);
4150 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4151 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4153 struct wined3d_shader
*object
;
4156 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4157 device
, desc
, parent
, parent_ops
, shader
);
4159 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4160 return E_OUTOFMEMORY
;
4162 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
)))
4164 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
4169 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4171 TRACE("Created domain shader %p.\n", object
);
4177 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4178 const struct wined3d_stream_output_desc
*so_desc
, void *parent
,
4179 const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4181 struct wined3d_shader
*object
;
4184 TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
4185 device
, desc
, so_desc
, parent
, parent_ops
, shader
);
4187 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4188 return E_OUTOFMEMORY
;
4190 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, so_desc
, parent
, parent_ops
)))
4192 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
4197 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4199 TRACE("Created geometry shader %p.\n", object
);
4205 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4206 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4208 struct wined3d_shader
*object
;
4211 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4212 device
, desc
, parent
, parent_ops
, shader
);
4214 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4215 return E_OUTOFMEMORY
;
4217 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
)))
4219 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
4224 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4226 TRACE("Created hull shader %p.\n", object
);
4232 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4233 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4235 struct wined3d_shader
*object
;
4238 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4239 device
, desc
, parent
, parent_ops
, shader
);
4241 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4242 return E_OUTOFMEMORY
;
4244 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4246 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
4251 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4253 TRACE("Created pixel shader %p.\n", object
);
4259 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4260 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4262 struct wined3d_shader
*object
;
4265 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4266 device
, desc
, parent
, parent_ops
, shader
);
4268 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4269 return E_OUTOFMEMORY
;
4271 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4273 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
4278 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4280 TRACE("Created vertex shader %p.\n", object
);