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 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
424 buffer
->buffer
[0] = '\0';
425 buffer
->content_size
= 0;
428 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
430 buffer
->buffer_size
= 32;
431 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
433 ERR("Failed to allocate shader buffer memory.\n");
437 string_buffer_clear(buffer
);
441 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
443 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
446 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
449 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
451 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
452 new_buffer_size
*= 2;
453 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
455 ERR("Failed to grow buffer.\n");
456 buffer
->buffer
[buffer
->content_size
] = '\0';
459 buffer
->buffer
= new_buffer
;
460 buffer
->buffer_size
= new_buffer_size
;
464 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
469 rem
= buffer
->buffer_size
- buffer
->content_size
;
470 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
471 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
474 buffer
->content_size
+= rc
;
478 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
485 va_start(args
, format
);
486 ret
= shader_vaddline(buffer
, format
, args
);
490 if (!string_buffer_resize(buffer
, ret
))
495 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
497 struct wined3d_string_buffer
*buffer
;
499 if (list_empty(&list
->list
))
501 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
502 if (!buffer
|| !string_buffer_init(buffer
))
504 ERR("Couldn't allocate buffer for temporary string.\n");
505 HeapFree(GetProcessHeap(), 0, buffer
);
511 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
512 list_remove(&buffer
->entry
);
514 string_buffer_clear(buffer
);
518 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
522 string_buffer_clear(buffer
);
523 return shader_vaddline(buffer
, format
, args
);
526 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
533 va_start(args
, format
);
534 ret
= string_buffer_vsprintf(buffer
, format
, args
);
538 if (!string_buffer_resize(buffer
, ret
))
543 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
547 list_add_head(&list
->list
, &buffer
->entry
);
550 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
552 list_init(&list
->list
);
555 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
557 struct wined3d_string_buffer
*buffer
, *buffer_next
;
559 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
561 string_buffer_free(buffer
);
562 HeapFree(GetProcessHeap(), 0, buffer
);
564 list_init(&list
->list
);
567 /* Convert floating point offset relative to a register file to an absolute
568 * offset for float constants. */
569 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
571 switch (register_type
)
573 case WINED3DSPR_CONST
: return register_idx
;
574 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
575 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
576 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
578 FIXME("Unsupported register type: %u.\n", register_type
);
583 static void shader_delete_constant_list(struct list
*clist
)
585 struct wined3d_shader_lconst
*constant
, *constant_next
;
587 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
588 HeapFree(GetProcessHeap(), 0, constant
);
592 static void shader_set_limits(struct wined3d_shader
*shader
)
594 static const struct limits_entry
596 unsigned int min_version
;
597 unsigned int max_version
;
598 struct wined3d_shader_limits limits
;
602 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
603 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
604 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
605 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
606 * even though they are capable of supporting much more (GL
607 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
608 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
610 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
611 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
612 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
617 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
618 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
622 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
623 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
627 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
628 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
629 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
634 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
635 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
636 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
637 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
638 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
639 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
640 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
645 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
646 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
648 const struct limits_entry
*limits_array
;
649 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
650 shader
->reg_maps
.shader_version
.minor
);
653 switch (shader
->reg_maps
.shader_version
.type
)
656 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
658 case WINED3D_SHADER_TYPE_VERTEX
:
659 limits_array
= vs_limits
;
661 case WINED3D_SHADER_TYPE_HULL
:
662 limits_array
= hs_limits
;
664 case WINED3D_SHADER_TYPE_DOMAIN
:
665 limits_array
= ds_limits
;
667 case WINED3D_SHADER_TYPE_GEOMETRY
:
668 limits_array
= gs_limits
;
670 case WINED3D_SHADER_TYPE_PIXEL
:
671 limits_array
= ps_limits
;
673 case WINED3D_SHADER_TYPE_COMPUTE
:
674 limits_array
= cs_limits
;
678 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
680 if (shader_version
<= limits_array
[i
].max_version
)
682 shader
->limits
= &limits_array
[i
].limits
;
689 FIXME("Unexpected shader version \"%u.%u\".\n",
690 shader
->reg_maps
.shader_version
.major
,
691 shader
->reg_maps
.shader_version
.minor
);
692 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
696 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
697 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
701 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
702 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
703 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
705 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
708 case WINED3DSPR_TEMP
:
709 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
712 case WINED3DSPR_INPUT
:
713 if (reg
->idx
[0].rel_addr
)
714 reg_maps
->input_rel_addressing
= 1;
715 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
717 /* If relative addressing is used, we must assume that all
718 * registers are used. Even if it is a construct like v3[aL],
719 * we can't assume that v0, v1 and v2 aren't read because aL
720 * can be negative. */
721 if (reg
->idx
[0].rel_addr
)
722 shader
->u
.ps
.input_reg_used
= ~0u;
724 shader
->u
.ps
.input_reg_used
|= 1u << reg
->idx
[0].offset
;
728 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
732 case WINED3DSPR_RASTOUT
:
733 if (reg
->idx
[0].offset
== 1)
735 if (reg
->idx
[0].offset
== 2)
736 reg_maps
->point_size
= 1;
739 case WINED3DSPR_MISCTYPE
:
740 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
742 if (!reg
->idx
[0].offset
)
744 else if (reg
->idx
[0].offset
== 1)
745 reg_maps
->usesfacing
= 1;
749 case WINED3DSPR_CONST
:
750 if (reg
->idx
[0].rel_addr
)
752 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
753 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
754 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
755 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
756 reg_maps
->usesrelconstF
= TRUE
;
760 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
762 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
767 wined3d_insert_bits(reg_maps
->constf
, reg
->idx
[0].offset
, 1, 0x1);
772 case WINED3DSPR_CONSTINT
:
773 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
775 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
780 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
784 case WINED3DSPR_CONSTBOOL
:
785 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
787 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
792 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
796 case WINED3DSPR_COLOROUT
:
797 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
800 case WINED3DSPR_OUTCONTROLPOINT
:
805 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
806 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
812 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
813 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
815 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
816 struct wined3d_shader_sampler_map
*map
;
819 map
= ®_maps
->sampler_map
;
820 entries
= map
->entries
;
821 for (i
= 0; i
< map
->count
; ++i
)
823 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
829 if (!(entries
= wined3d_calloc(4, sizeof(*entries
))))
831 ERR("Failed to allocate sampler map entries.\n");
835 map
->entries
= entries
;
837 else if (map
->count
== map
->size
)
839 size_t new_size
= map
->size
* 2;
841 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
842 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
844 ERR("Failed to resize sampler map entries.\n");
847 map
->size
= new_size
;
848 map
->entries
= entries
;
851 entry
= &entries
[map
->count
++];
852 entry
->resource_idx
= resource_idx
;
853 entry
->sampler_idx
= sampler_idx
;
854 entry
->bind_idx
= bind_idx
;
857 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
861 case WINED3DSIH_M4x4
:
862 case WINED3DSIH_M3x4
:
863 return param
== 1 ? 3 : 0;
865 case WINED3DSIH_M4x3
:
866 case WINED3DSIH_M3x3
:
867 return param
== 1 ? 2 : 0;
869 case WINED3DSIH_M3x2
:
870 return param
== 1 ? 1 : 0;
877 static HRESULT
shader_reg_maps_add_tgsm(struct wined3d_shader_reg_maps
*reg_maps
,
878 unsigned int register_idx
, unsigned int size
, unsigned int stride
)
880 struct wined3d_shader_tgsm
*tgsm
;
882 if (register_idx
>= MAX_TGSM_REGISTERS
)
884 ERR("Invalid TGSM register index %u.\n", register_idx
);
887 if (reg_maps
->shader_version
.type
!= WINED3D_SHADER_TYPE_COMPUTE
)
889 FIXME("TGSM declarations are allowed only in compute shaders.\n");
893 if (!wined3d_array_reserve((void **)®_maps
->tgsm
, ®_maps
->tgsm_capacity
,
894 register_idx
+ 1, sizeof(*reg_maps
->tgsm
)))
895 return E_OUTOFMEMORY
;
897 reg_maps
->tgsm_count
= max(register_idx
+ 1, reg_maps
->tgsm_count
);
898 tgsm
= ®_maps
->tgsm
[register_idx
];
900 tgsm
->stride
= stride
;
904 static HRESULT
shader_record_shader_phase(struct wined3d_shader
*shader
,
905 struct wined3d_shader_phase
**current_phase
, const struct wined3d_shader_instruction
*ins
,
906 const DWORD
*current_instruction_ptr
, const DWORD
*previous_instruction_ptr
)
908 struct wined3d_shader_phase
*phase
;
910 if ((phase
= *current_phase
))
912 phase
->end
= previous_instruction_ptr
;
913 *current_phase
= NULL
;
916 if (shader
->reg_maps
.shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
918 ERR("Unexpected shader type %#x.\n", shader
->reg_maps
.shader_version
.type
);
922 switch (ins
->handler_idx
)
924 case WINED3DSIH_HS_CONTROL_POINT_PHASE
:
925 if (shader
->u
.hs
.phases
.control_point
)
927 FIXME("Multiple control point phases.\n");
928 HeapFree(GetProcessHeap(), 0, shader
->u
.hs
.phases
.control_point
);
930 if (!(shader
->u
.hs
.phases
.control_point
= HeapAlloc(GetProcessHeap(),
931 HEAP_ZERO_MEMORY
, sizeof(*shader
->u
.hs
.phases
.control_point
))))
932 return E_OUTOFMEMORY
;
933 phase
= shader
->u
.hs
.phases
.control_point
;
935 case WINED3DSIH_HS_FORK_PHASE
:
936 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.fork
,
937 &shader
->u
.hs
.phases
.fork_size
, shader
->u
.hs
.phases
.fork_count
+ 1,
938 sizeof(*shader
->u
.hs
.phases
.fork
)))
939 return E_OUTOFMEMORY
;
940 phase
= &shader
->u
.hs
.phases
.fork
[shader
->u
.hs
.phases
.fork_count
++];
942 case WINED3DSIH_HS_JOIN_PHASE
:
943 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.join
,
944 &shader
->u
.hs
.phases
.join_size
, shader
->u
.hs
.phases
.join_count
+ 1,
945 sizeof(*shader
->u
.hs
.phases
.join
)))
946 return E_OUTOFMEMORY
;
947 phase
= &shader
->u
.hs
.phases
.join
[shader
->u
.hs
.phases
.join_count
++];
950 ERR("Unexpected opcode %s.\n", debug_d3dshaderinstructionhandler(ins
->handler_idx
));
954 phase
->start
= current_instruction_ptr
;
955 *current_phase
= phase
;
960 static HRESULT
shader_calculate_clip_or_cull_distance_mask(
961 const struct wined3d_shader_signature_element
*e
, DWORD
*mask
)
967 /* Cull and clip distances are packed in 4 component registers. 0 and 1 are
968 * the only allowed semantic indices.
970 if (e
->semantic_idx
>= MAX_CLIP_DISTANCES
/ 4)
972 WARN("Invalid clip/cull distance index %u.\n", e
->semantic_idx
);
973 return WINED3DERR_INVALIDCALL
;
976 for (i
= 0; i
< 4; ++i
)
978 if (e
->mask
& (WINED3DSP_WRITEMASK_0
<< i
))
979 *mask
|= 1u << (4 * e
->semantic_idx
+ i
);
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
= wined3d_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
= HeapAlloc(GetProcessHeap(), 0, 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
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1349 if (!lconst
) return E_OUTOFMEMORY
;
1351 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1352 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1353 value
= (float *)lconst
->value
;
1355 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1356 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1358 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1359 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1360 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1361 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1362 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1363 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1364 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1365 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1368 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1370 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1371 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1373 shader
->lconst_inf_or_nan
= TRUE
;
1376 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1378 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1379 if (!lconst
) return E_OUTOFMEMORY
;
1381 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1382 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1384 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1385 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1387 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1389 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1390 if (!lconst
) return E_OUTOFMEMORY
;
1392 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1393 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1395 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1396 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1398 /* Handle shader phases. */
1399 else if (ins
.handler_idx
== WINED3DSIH_HS_CONTROL_POINT_PHASE
1400 || ins
.handler_idx
== WINED3DSIH_HS_FORK_PHASE
1401 || ins
.handler_idx
== WINED3DSIH_HS_JOIN_PHASE
)
1403 if (FAILED(hr
= shader_record_shader_phase(shader
, &phase
, &ins
, current_ins
, prev_ins
)))
1406 /* For subroutine prototypes. */
1407 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1409 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1411 /* Set texture, address, temporary registers. */
1414 BOOL color0_mov
= FALSE
;
1417 /* This will loop over all the registers and try to
1418 * make a bitmask of the ones we're interested in.
1420 * Relative addressing tokens are ignored, but that's
1421 * okay, since we'll catch any address registers when
1422 * they are initialized (required by spec). */
1423 for (i
= 0; i
< ins
.dst_count
; ++i
)
1425 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1426 shader_version
.type
, constf_size
))
1427 return WINED3DERR_INVALIDCALL
;
1429 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1431 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1433 switch (ins
.dst
[i
].reg
.type
)
1435 case WINED3DSPR_RASTOUT
:
1436 if (shader_version
.major
>= 3)
1441 reg_maps
->output_registers
|= 1u << 10;
1442 shader_signature_from_usage(&output_signature_elements
[10],
1443 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1447 reg_maps
->output_registers
|= 1u << 11;
1448 shader_signature_from_usage(&output_signature_elements
[11],
1449 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1453 reg_maps
->output_registers
|= 1u << 11;
1454 shader_signature_from_usage(&output_signature_elements
[11],
1455 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1460 case WINED3DSPR_ATTROUT
:
1461 if (shader_version
.major
>= 3)
1466 if (reg_maps
->output_registers
& (1u << idx
))
1468 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1472 reg_maps
->output_registers
|= 1u << idx
;
1473 shader_signature_from_usage(&output_signature_elements
[idx
],
1474 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1479 case WINED3DSPR_TEXCRDOUT
: /* WINED3DSPR_OUTPUT */
1480 if (shader_version
.major
>= 3)
1482 if (idx
>= ARRAY_SIZE(reg_maps
->u
.output_registers_mask
))
1484 WARN("Invalid output register index %u.\n", idx
);
1487 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1490 if (idx
>= ARRAY_SIZE(reg_maps
->u
.texcoord_mask
))
1492 WARN("Invalid texcoord index %u.\n", idx
);
1495 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1496 if (reg_maps
->output_registers
& (1u << idx
))
1498 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1502 reg_maps
->output_registers
|= 1u << idx
;
1503 shader_signature_from_usage(&output_signature_elements
[idx
],
1504 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1513 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1515 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1517 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1518 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1519 * the mov and perform the sRGB write correction from the source register.
1521 * However, if the mov is only partial, we can't do this, and if the write
1522 * comes from an instruction other than MOV it is hard to do as well. If
1523 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1524 shader
->u
.ps
.color0_mov
= FALSE
;
1525 if (ins
.handler_idx
== WINED3DSIH_MOV
1526 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1528 /* Used later when the source register is read. */
1532 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1535 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1536 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1538 shader
->u
.ps
.color0_mov
= FALSE
;
1542 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1543 if (shader_version
.major
== 1
1544 && (ins
.handler_idx
== WINED3DSIH_TEX
1545 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1546 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1547 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1548 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1549 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1550 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1551 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1552 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1553 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1554 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1556 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1558 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1560 WARN("Invalid 1.x sampler index %u.\n", reg_idx
);
1564 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1565 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1566 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1567 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1569 /* texbem is only valid with < 1.4 pixel shaders */
1570 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1571 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1573 reg_maps
->bumpmat
|= 1u << reg_idx
;
1574 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1576 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1580 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1582 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1586 if (ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_ALLOC
|| ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_CONSUME
)
1588 unsigned int reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1589 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1591 ERR("Invalid UAV index %u.\n", reg_idx
);
1594 reg_maps
->uav_counter_mask
|= (1u << reg_idx
);
1596 else if ((WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1597 || (WINED3DSIH_IMM_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_IMM_ATOMIC_XOR
)
1598 || (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_UAV
)
1599 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
1600 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_UAV
)
1601 || (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
&& ins
.src
[2].reg
.type
== WINED3DSPR_UAV
))
1603 unsigned int reg_idx
;
1604 if (ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
|| ins
.handler_idx
== WINED3DSIH_LD_RAW
)
1605 reg_idx
= ins
.src
[1].reg
.idx
[0].offset
;
1606 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
)
1607 reg_idx
= ins
.src
[2].reg
.idx
[0].offset
;
1608 else if (WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1609 reg_idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1610 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
)
1611 reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1613 reg_idx
= ins
.dst
[1].reg
.idx
[0].offset
;
1614 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1616 ERR("Invalid UAV index %u.\n", reg_idx
);
1619 reg_maps
->uav_read_mask
|= (1u << reg_idx
);
1621 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1623 reg_maps
->usesnrm
= 1;
1625 else if (ins
.handler_idx
== WINED3DSIH_DSY
1626 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1627 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1629 reg_maps
->usesdsy
= 1;
1631 else if (ins
.handler_idx
== WINED3DSIH_DSX
1632 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1633 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1635 reg_maps
->usesdsx
= 1;
1637 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1638 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1639 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1640 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1641 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1642 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1643 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1644 || ins
.handler_idx
== WINED3DSIH_REP
)
1647 if (cur_loop_depth
> max_loop_depth
)
1648 max_loop_depth
= cur_loop_depth
;
1650 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1651 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1655 else if (ins
.handler_idx
== WINED3DSIH_GATHER4
1656 || ins
.handler_idx
== WINED3DSIH_GATHER4_C
1657 || ins
.handler_idx
== WINED3DSIH_SAMPLE
1658 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1659 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1660 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1661 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1662 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1664 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1665 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1667 else if (ins
.handler_idx
== WINED3DSIH_GATHER4_PO
1668 || ins
.handler_idx
== WINED3DSIH_GATHER4_PO_C
)
1670 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1671 ins
.src
[3].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1673 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
)
1675 shader_record_sample(reg_maps
, ins
.src
[0].reg
.idx
[0].offset
,
1676 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1678 else if (ins
.handler_idx
== WINED3DSIH_LD
1679 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
)
1680 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1682 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1683 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1685 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
1686 && ins
.src
[2].reg
.type
== WINED3DSPR_RESOURCE
)
1688 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1689 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1693 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1694 shader_version
.type
, constf_size
))
1695 return WINED3DERR_INVALIDCALL
;
1697 for (i
= 0; i
< ins
.src_count
; ++i
)
1699 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1700 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1702 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1703 shader_version
.type
, constf_size
))
1704 return WINED3DERR_INVALIDCALL
;
1707 ++reg
.idx
[0].offset
;
1708 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1709 shader_version
.type
, constf_size
))
1710 return WINED3DERR_INVALIDCALL
;
1716 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1717 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1719 shader
->u
.ps
.color0_mov
= TRUE
;
1720 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1726 prev_ins
= current_ins
;
1728 reg_maps
->loop_depth
= max_loop_depth
;
1732 phase
->end
= prev_ins
;
1736 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1737 * R0 is written to the render target. */
1738 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1739 reg_maps
->rt_mask
|= (1u << 0);
1741 if (input_signature
->elements
)
1743 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1745 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1747 if (input_signature
->elements
[i
].register_idx
>= ARRAY_SIZE(shader
->u
.vs
.attributes
))
1749 WARN("Invalid input signature register index %u.\n", input_signature
->elements
[i
].register_idx
);
1750 return WINED3DERR_INVALIDCALL
;
1753 else if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1755 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1757 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1758 reg_maps
->usesfacing
= 1;
1760 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1763 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1765 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1766 struct wined3d_shader_signature_element
*e
;
1769 if (!(input_signature
->elements
= wined3d_calloc(count
, sizeof(*input_signature
->elements
))))
1770 return E_OUTOFMEMORY
;
1771 input_signature
->element_count
= count
;
1773 e
= input_signature
->elements
;
1774 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1776 if (!(reg_maps
->input_registers
& (1u << i
)))
1778 input_signature_elements
[i
].register_idx
= i
;
1779 *e
++ = input_signature_elements
[i
];
1783 if (output_signature
->elements
)
1785 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1787 const struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1790 reg_maps
->output_registers
|= 1u << e
->register_idx
;
1791 if (e
->sysval_semantic
== WINED3D_SV_CLIP_DISTANCE
)
1793 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1795 reg_maps
->clip_distance_mask
|= mask
;
1797 else if (e
->sysval_semantic
== WINED3D_SV_CULL_DISTANCE
)
1799 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1801 reg_maps
->cull_distance_mask
|= mask
;
1805 else if (reg_maps
->output_registers
)
1807 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1808 struct wined3d_shader_signature_element
*e
;
1810 if (!(output_signature
->elements
= wined3d_calloc(count
, sizeof(*output_signature
->elements
))))
1811 return E_OUTOFMEMORY
;
1812 output_signature
->element_count
= count
;
1814 e
= output_signature
->elements
;
1815 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1817 if (!(reg_maps
->output_registers
& (1u << i
)))
1819 *e
++ = output_signature_elements
[i
];
1826 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1828 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1830 HeapFree(GetProcessHeap(), 0, reg_maps
->constf
);
1831 HeapFree(GetProcessHeap(), 0, reg_maps
->sampler_map
.entries
);
1833 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1834 HeapFree(GetProcessHeap(), 0, reg
);
1835 list_init(®_maps
->indexable_temps
);
1837 HeapFree(GetProcessHeap(), 0, reg_maps
->tgsm
);
1840 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1842 DWORD map
= 1u << max
;
1844 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1846 return wined3d_log2i(map
);
1849 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1851 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1853 shader_addline(buffer
, "refactoringAllowed");
1854 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1856 shader_addline(buffer
, " | ");
1859 if (global_flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1861 shader_addline(buffer
, "forceEarlyDepthStencil");
1862 global_flags
&= ~WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
;
1864 shader_addline(buffer
, " | ");
1867 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1869 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1870 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1874 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1877 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1879 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1881 shader_addline(buffer
, "_g");
1882 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1884 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1886 shader_addline(buffer
, "_t");
1887 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1891 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1894 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1896 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1898 shader_addline(buffer
, "_glc");
1899 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1901 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1903 shader_addline(buffer
, "_opc");
1904 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1908 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1911 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1912 enum wined3d_tessellator_domain domain
)
1916 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1917 shader_addline(buffer
, "line");
1919 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1920 shader_addline(buffer
, "triangle");
1922 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1923 shader_addline(buffer
, "quad");
1926 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1931 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1932 enum wined3d_tessellator_output_primitive output_primitive
)
1934 switch (output_primitive
)
1936 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1937 shader_addline(buffer
, "point");
1939 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1940 shader_addline(buffer
, "line");
1942 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1943 shader_addline(buffer
, "triangle_cw");
1945 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1946 shader_addline(buffer
, "triangle_ccw");
1949 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1954 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1955 enum wined3d_tessellator_partitioning partitioning
)
1957 switch (partitioning
)
1959 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1960 shader_addline(buffer
, "integer");
1962 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1963 shader_addline(buffer
, "pow2");
1965 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1966 shader_addline(buffer
, "fractional_odd");
1968 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1969 shader_addline(buffer
, "fractional_even");
1972 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1977 static void shader_dump_shader_input_sysval_semantic(struct wined3d_string_buffer
*buffer
,
1978 enum wined3d_shader_input_sysval_semantic semantic
)
1982 for (i
= 0; i
< ARRAY_SIZE(shader_input_sysval_semantic_names
); ++i
)
1984 if (shader_input_sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1986 shader_addline(buffer
, "%s", shader_input_sysval_semantic_names
[i
].sysval_name
);
1991 shader_addline(buffer
, "unknown_shader_input_sysval_semantic(%#x)", semantic
);
1994 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1995 const struct wined3d_shader_semantic
*semantic
, unsigned int flags
,
1996 const struct wined3d_shader_version
*shader_version
)
1998 shader_addline(buffer
, "dcl");
2000 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
2002 switch (semantic
->resource_type
)
2004 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2005 shader_addline(buffer
, "_2d");
2008 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2009 shader_addline(buffer
, "_3d");
2012 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2013 shader_addline(buffer
, "_cube");
2017 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
2021 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2023 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
2024 shader_addline(buffer
, "_resource_");
2026 shader_addline(buffer
, "_uav_");
2027 switch (semantic
->resource_type
)
2029 case WINED3D_SHADER_RESOURCE_BUFFER
:
2030 shader_addline(buffer
, "buffer");
2033 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
2034 shader_addline(buffer
, "texture1d");
2037 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2038 shader_addline(buffer
, "texture2d");
2041 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
2042 shader_addline(buffer
, "texture2dms");
2045 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2046 shader_addline(buffer
, "texture3d");
2049 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2050 shader_addline(buffer
, "texturecube");
2053 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
2054 shader_addline(buffer
, "texture1darray");
2057 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
2058 shader_addline(buffer
, "texture2darray");
2061 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
2062 shader_addline(buffer
, "texture2dmsarray");
2065 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
:
2066 shader_addline(buffer
, "texturecubearray");
2070 shader_addline(buffer
, "unknown");
2073 if (semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2074 shader_dump_uav_flags(buffer
, flags
);
2075 switch (semantic
->resource_data_type
)
2077 case WINED3D_DATA_FLOAT
:
2078 shader_addline(buffer
, " (float)");
2081 case WINED3D_DATA_INT
:
2082 shader_addline(buffer
, " (int)");
2085 case WINED3D_DATA_UINT
:
2086 shader_addline(buffer
, " (uint)");
2089 case WINED3D_DATA_UNORM
:
2090 shader_addline(buffer
, " (unorm)");
2093 case WINED3D_DATA_SNORM
:
2094 shader_addline(buffer
, " (snorm)");
2098 shader_addline(buffer
, " (unknown)");
2104 /* Pixel shaders 3.0 don't have usage semantics. */
2105 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
2108 shader_addline(buffer
, "_");
2110 switch (semantic
->usage
)
2112 case WINED3D_DECL_USAGE_POSITION
:
2113 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
2116 case WINED3D_DECL_USAGE_BLEND_INDICES
:
2117 shader_addline(buffer
, "blend");
2120 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
2121 shader_addline(buffer
, "weight");
2124 case WINED3D_DECL_USAGE_NORMAL
:
2125 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
2128 case WINED3D_DECL_USAGE_PSIZE
:
2129 shader_addline(buffer
, "psize");
2132 case WINED3D_DECL_USAGE_COLOR
:
2133 if (!semantic
->usage_idx
)
2134 shader_addline(buffer
, "color");
2136 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
2139 case WINED3D_DECL_USAGE_TEXCOORD
:
2140 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
2143 case WINED3D_DECL_USAGE_TANGENT
:
2144 shader_addline(buffer
, "tangent");
2147 case WINED3D_DECL_USAGE_BINORMAL
:
2148 shader_addline(buffer
, "binormal");
2151 case WINED3D_DECL_USAGE_TESS_FACTOR
:
2152 shader_addline(buffer
, "tessfactor");
2155 case WINED3D_DECL_USAGE_POSITIONT
:
2156 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
2159 case WINED3D_DECL_USAGE_FOG
:
2160 shader_addline(buffer
, "fog");
2163 case WINED3D_DECL_USAGE_DEPTH
:
2164 shader_addline(buffer
, "depth");
2167 case WINED3D_DECL_USAGE_SAMPLE
:
2168 shader_addline(buffer
, "sample");
2172 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
2173 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
2178 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
2179 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
2181 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
2182 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
2183 UINT offset
= reg
->idx
[0].offset
;
2187 case WINED3DSPR_TEMP
:
2188 shader_addline(buffer
, "r");
2191 case WINED3DSPR_INPUT
:
2192 shader_addline(buffer
, "v");
2195 case WINED3DSPR_CONST
:
2196 case WINED3DSPR_CONST2
:
2197 case WINED3DSPR_CONST3
:
2198 case WINED3DSPR_CONST4
:
2199 shader_addline(buffer
, "c");
2200 offset
= shader_get_float_offset(reg
->type
, offset
);
2203 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
2204 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
2207 case WINED3DSPR_RASTOUT
:
2208 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
2211 case WINED3DSPR_COLOROUT
:
2212 shader_addline(buffer
, "oC");
2215 case WINED3DSPR_DEPTHOUT
:
2216 shader_addline(buffer
, "oDepth");
2219 case WINED3DSPR_DEPTHOUTGE
:
2220 shader_addline(buffer
, "oDepthGE");
2223 case WINED3DSPR_DEPTHOUTLE
:
2224 shader_addline(buffer
, "oDepthLE");
2227 case WINED3DSPR_ATTROUT
:
2228 shader_addline(buffer
, "oD");
2231 case WINED3DSPR_TEXCRDOUT
:
2232 /* Vertex shaders >= 3.0 use general purpose output registers
2233 * (WINED3DSPR_OUTPUT), which can include an address token. */
2234 if (shader_version
->major
>= 3)
2235 shader_addline(buffer
, "o");
2237 shader_addline(buffer
, "oT");
2240 case WINED3DSPR_CONSTINT
:
2241 shader_addline(buffer
, "i");
2244 case WINED3DSPR_CONSTBOOL
:
2245 shader_addline(buffer
, "b");
2248 case WINED3DSPR_LABEL
:
2249 shader_addline(buffer
, "l");
2252 case WINED3DSPR_LOOP
:
2253 shader_addline(buffer
, "aL");
2256 case WINED3DSPR_SAMPLER
:
2257 shader_addline(buffer
, "s");
2260 case WINED3DSPR_MISCTYPE
:
2263 FIXME("Unhandled misctype register %u.\n", offset
);
2264 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
2268 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
2272 case WINED3DSPR_PREDICATE
:
2273 shader_addline(buffer
, "p");
2276 case WINED3DSPR_IMMCONST
:
2277 shader_addline(buffer
, "l");
2280 case WINED3DSPR_CONSTBUFFER
:
2281 shader_addline(buffer
, "cb");
2284 case WINED3DSPR_IMMCONSTBUFFER
:
2285 shader_addline(buffer
, "icb");
2288 case WINED3DSPR_PRIMID
:
2289 shader_addline(buffer
, "primID");
2292 case WINED3DSPR_NULL
:
2293 shader_addline(buffer
, "null");
2296 case WINED3DSPR_RESOURCE
:
2297 shader_addline(buffer
, "t");
2300 case WINED3DSPR_UAV
:
2301 shader_addline(buffer
, "u");
2304 case WINED3DSPR_OUTPOINTID
:
2305 shader_addline(buffer
, "vOutputControlPointID");
2308 case WINED3DSPR_FORKINSTID
:
2309 shader_addline(buffer
, "vForkInstanceId");
2312 case WINED3DSPR_JOININSTID
:
2313 shader_addline(buffer
, "vJoinInstanceId");
2316 case WINED3DSPR_INCONTROLPOINT
:
2317 shader_addline(buffer
, "vicp");
2320 case WINED3DSPR_OUTCONTROLPOINT
:
2321 shader_addline(buffer
, "vocp");
2324 case WINED3DSPR_PATCHCONST
:
2325 shader_addline(buffer
, "vpc");
2328 case WINED3DSPR_TESSCOORD
:
2329 shader_addline(buffer
, "vDomainLocation");
2332 case WINED3DSPR_GROUPSHAREDMEM
:
2333 shader_addline(buffer
, "g");
2336 case WINED3DSPR_THREADID
:
2337 shader_addline(buffer
, "vThreadID");
2340 case WINED3DSPR_THREADGROUPID
:
2341 shader_addline(buffer
, "vThreadGroupID");
2344 case WINED3DSPR_LOCALTHREADID
:
2345 shader_addline(buffer
, "vThreadIDInGroup");
2348 case WINED3DSPR_LOCALTHREADINDEX
:
2349 shader_addline(buffer
, "vThreadIDInGroupFlattened");
2352 case WINED3DSPR_IDXTEMP
:
2353 shader_addline(buffer
, "x");
2356 case WINED3DSPR_STREAM
:
2357 shader_addline(buffer
, "m");
2360 case WINED3DSPR_FUNCTIONBODY
:
2361 shader_addline(buffer
, "fb");
2364 case WINED3DSPR_FUNCTIONPOINTER
:
2365 shader_addline(buffer
, "fp");
2368 case WINED3DSPR_COVERAGE
:
2369 shader_addline(buffer
, "vCoverage");
2372 case WINED3DSPR_SAMPLEMASK
:
2373 shader_addline(buffer
, "oMask");
2376 case WINED3DSPR_GSINSTID
:
2377 shader_addline(buffer
, "vGSInstanceID");
2381 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
2385 if (reg
->type
== WINED3DSPR_IMMCONST
)
2387 shader_addline(buffer
, "(");
2388 switch (reg
->immconst_type
)
2390 case WINED3D_IMMCONST_SCALAR
:
2391 switch (reg
->data_type
)
2393 case WINED3D_DATA_FLOAT
:
2394 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
2396 case WINED3D_DATA_INT
:
2397 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
2399 case WINED3D_DATA_RESOURCE
:
2400 case WINED3D_DATA_SAMPLER
:
2401 case WINED3D_DATA_UINT
:
2402 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
2405 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2410 case WINED3D_IMMCONST_VEC4
:
2411 switch (reg
->data_type
)
2413 case WINED3D_DATA_FLOAT
:
2414 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2415 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2416 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2418 case WINED3D_DATA_INT
:
2419 shader_addline(buffer
, "%d, %d, %d, %d",
2420 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2421 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2423 case WINED3D_DATA_RESOURCE
:
2424 case WINED3D_DATA_SAMPLER
:
2425 case WINED3D_DATA_UINT
:
2426 shader_addline(buffer
, "%u, %u, %u, %u",
2427 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2428 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2431 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2437 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2440 shader_addline(buffer
, ")");
2442 else if (reg
->type
!= WINED3DSPR_RASTOUT
2443 && reg
->type
!= WINED3DSPR_MISCTYPE
2444 && reg
->type
!= WINED3DSPR_NULL
)
2448 shader_addline(buffer
, "[");
2449 if (reg
->idx
[0].rel_addr
)
2451 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2452 shader_addline(buffer
, " + ");
2454 shader_addline(buffer
, "%u]", offset
);
2456 if (reg
->idx
[1].offset
!= ~0u)
2458 shader_addline(buffer
, "[");
2459 if (reg
->idx
[1].rel_addr
)
2461 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2462 shader_addline(buffer
, " + ");
2464 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2468 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2469 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2473 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2474 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2476 DWORD write_mask
= param
->write_mask
;
2478 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2480 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2482 static const char write_mask_chars
[] = "xyzw";
2484 shader_addline(buffer
, ".");
2485 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2486 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2487 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2488 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2489 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2490 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2491 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2492 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2496 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2497 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2499 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2500 DWORD swizzle
= param
->swizzle
;
2502 if (src_modifier
== WINED3DSPSM_NEG
2503 || src_modifier
== WINED3DSPSM_BIASNEG
2504 || src_modifier
== WINED3DSPSM_SIGNNEG
2505 || src_modifier
== WINED3DSPSM_X2NEG
2506 || src_modifier
== WINED3DSPSM_ABSNEG
)
2507 shader_addline(buffer
, "-");
2508 else if (src_modifier
== WINED3DSPSM_COMP
)
2509 shader_addline(buffer
, "1-");
2510 else if (src_modifier
== WINED3DSPSM_NOT
)
2511 shader_addline(buffer
, "!");
2513 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2514 shader_addline(buffer
, "abs(");
2516 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2518 switch (src_modifier
)
2520 case WINED3DSPSM_NONE
: break;
2521 case WINED3DSPSM_NEG
: break;
2522 case WINED3DSPSM_NOT
: break;
2523 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2524 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2525 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2526 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2527 case WINED3DSPSM_COMP
: break;
2528 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2529 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2530 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2531 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2532 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2533 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2534 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2537 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2539 static const char swizzle_chars
[] = "xyzw";
2540 DWORD swizzle_x
= swizzle
& 0x03;
2541 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2542 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2543 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2545 if (swizzle_x
== swizzle_y
2546 && swizzle_x
== swizzle_z
2547 && swizzle_x
== swizzle_w
)
2549 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2553 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2554 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2559 /* Shared code in order to generate the bulk of the shader string. */
2560 HRESULT
shader_generate_code(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2561 const struct wined3d_shader_reg_maps
*reg_maps
, void *backend_ctx
,
2562 const DWORD
*start
, const DWORD
*end
)
2564 struct wined3d_device
*device
= shader
->device
;
2565 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2566 void *fe_data
= shader
->frontend_data
;
2567 struct wined3d_shader_version shader_version
;
2568 struct wined3d_shader_parser_state state
;
2569 struct wined3d_shader_instruction ins
;
2570 struct wined3d_shader_tex_mx tex_mx
;
2571 struct wined3d_shader_context ctx
;
2574 /* Initialize current parsing state. */
2575 tex_mx
.current_row
= 0;
2576 state
.current_loop_depth
= 0;
2577 state
.current_loop_reg
= 0;
2578 state
.in_subroutine
= FALSE
;
2580 ctx
.shader
= shader
;
2581 ctx
.gl_info
= &device
->adapter
->gl_info
;
2582 ctx
.reg_maps
= reg_maps
;
2583 ctx
.buffer
= buffer
;
2584 ctx
.tex_mx
= &tex_mx
;
2586 ctx
.backend_data
= backend_ctx
;
2589 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2593 while (!fe
->shader_is_end(fe_data
, &ptr
) && ptr
!= end
)
2596 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2598 /* Unknown opcode and its parameters. */
2599 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2601 WARN("Encountered unrecognised or invalid instruction.\n");
2602 return WINED3DERR_INVALIDCALL
;
2606 FIXME("Predicates not implemented.\n");
2608 /* Call appropriate function for output target */
2609 device
->shader_backend
->shader_handle_instruction(&ins
);
2615 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2616 const struct wined3d_shader_dst_param
*dst
)
2618 DWORD mmask
= dst
->modifiers
;
2623 case 13: shader_addline(buffer
, "_d8"); break;
2624 case 14: shader_addline(buffer
, "_d4"); break;
2625 case 15: shader_addline(buffer
, "_d2"); break;
2626 case 1: shader_addline(buffer
, "_x2"); break;
2627 case 2: shader_addline(buffer
, "_x4"); break;
2628 case 3: shader_addline(buffer
, "_x8"); break;
2629 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2632 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2633 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2634 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2636 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2637 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2640 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2641 const struct wined3d_shader_primitive_type
*primitive_type
)
2643 switch (primitive_type
->type
)
2645 case WINED3D_PT_UNDEFINED
:
2646 shader_addline(buffer
, "undefined");
2648 case WINED3D_PT_POINTLIST
:
2649 shader_addline(buffer
, "pointlist");
2651 case WINED3D_PT_LINELIST
:
2652 shader_addline(buffer
, "linelist");
2654 case WINED3D_PT_LINESTRIP
:
2655 shader_addline(buffer
, "linestrip");
2657 case WINED3D_PT_TRIANGLELIST
:
2658 shader_addline(buffer
, "trianglelist");
2660 case WINED3D_PT_TRIANGLESTRIP
:
2661 shader_addline(buffer
, "trianglestrip");
2663 case WINED3D_PT_TRIANGLEFAN
:
2664 shader_addline(buffer
, "trianglefan");
2666 case WINED3D_PT_LINELIST_ADJ
:
2667 shader_addline(buffer
, "linelist_adj");
2669 case WINED3D_PT_LINESTRIP_ADJ
:
2670 shader_addline(buffer
, "linestrip_adj");
2672 case WINED3D_PT_TRIANGLELIST_ADJ
:
2673 shader_addline(buffer
, "trianglelist_adj");
2675 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2676 shader_addline(buffer
, "trianglestrip_adj");
2678 case WINED3D_PT_PATCH
:
2679 shader_addline(buffer
, "patch%u", primitive_type
->patch_vertex_count
);
2682 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
->type
);
2687 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2688 enum wined3d_shader_interpolation_mode interpolation_mode
)
2690 switch (interpolation_mode
)
2692 case WINED3DSIM_CONSTANT
:
2693 shader_addline(buffer
, "constant");
2695 case WINED3DSIM_LINEAR
:
2696 shader_addline(buffer
, "linear");
2698 case WINED3DSIM_LINEAR_CENTROID
:
2699 shader_addline(buffer
, "linear centroid");
2701 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2702 shader_addline(buffer
, "linear noperspective");
2704 case WINED3DSIM_LINEAR_SAMPLE
:
2705 shader_addline(buffer
, "linear sample");
2707 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2708 shader_addline(buffer
, "linear noperspective centroid");
2710 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2711 shader_addline(buffer
, "linear noperspective sample");
2714 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2719 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
)
2721 struct wined3d_shader_version shader_version
;
2722 struct wined3d_string_buffer buffer
;
2723 const char *type_prefix
;
2728 if (!string_buffer_init(&buffer
))
2730 ERR("Failed to initialize string buffer.\n");
2734 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2736 TRACE("Parsing %p.\n", ptr
);
2738 switch (shader_version
.type
)
2740 case WINED3D_SHADER_TYPE_VERTEX
:
2744 case WINED3D_SHADER_TYPE_HULL
:
2748 case WINED3D_SHADER_TYPE_DOMAIN
:
2752 case WINED3D_SHADER_TYPE_GEOMETRY
:
2756 case WINED3D_SHADER_TYPE_PIXEL
:
2760 case WINED3D_SHADER_TYPE_COMPUTE
:
2765 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2766 type_prefix
= "unknown";
2770 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2772 while (!fe
->shader_is_end(fe_data
, &ptr
))
2774 struct wined3d_shader_instruction ins
;
2776 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2777 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2779 WARN("Skipping unrecognized instruction.\n");
2780 shader_addline(&buffer
, "<unrecognized instruction>\n");
2784 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2786 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, ins
.flags
, &shader_version
);
2787 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2788 shader_addline(&buffer
, " ");
2789 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2791 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2793 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2794 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2795 shader_addline(&buffer
, ", %s",
2796 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2798 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2800 shader_addline(&buffer
, "%s fb%u",
2801 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2803 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2805 shader_addline(&buffer
, "%s ft%u = {...}",
2806 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2808 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2810 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2811 shader_dump_global_flags(&buffer
, ins
.flags
);
2813 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2815 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2816 ins
.declaration
.max_tessellation_factor
);
2818 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2820 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2821 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2823 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2824 ins
.declaration
.icb
->data
[4 * i
+ 0],
2825 ins
.declaration
.icb
->data
[4 * i
+ 1],
2826 ins
.declaration
.icb
->data
[4 * i
+ 2],
2827 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2829 shader_addline(&buffer
, "}");
2831 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEX_RANGE
)
2833 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2834 shader_dump_dst_param(&buffer
, &ins
.declaration
.index_range
.first_register
, &shader_version
);
2835 shader_addline(&buffer
, " %u", ins
.declaration
.index_range
.last_register
);
2837 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2839 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2840 ins
.declaration
.indexable_temp
.register_idx
,
2841 ins
.declaration
.indexable_temp
.register_size
,
2842 ins
.declaration
.indexable_temp
.component_count
);
2844 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2846 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2847 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2848 shader_addline(&buffer
, " ");
2849 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2851 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2852 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2853 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2854 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2856 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2857 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2858 shader_addline(&buffer
, ", ");
2859 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2861 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2863 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2864 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2865 shader_addline(&buffer
, " ");
2866 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2867 shader_addline(&buffer
, ", ");
2868 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2870 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2871 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2873 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2874 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2876 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2877 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2879 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2880 shader_dump_primitive_type(&buffer
, &ins
.declaration
.primitive_type
);
2882 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2884 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2885 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2886 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2888 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2890 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2891 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2893 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2895 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2896 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2897 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2899 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2901 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2902 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2903 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2904 shader_addline(&buffer
, ", comparisonMode");
2906 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2907 || ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
2908 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2909 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
2910 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2911 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
2912 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
2914 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2916 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2918 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2919 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2921 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2923 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2924 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2926 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2928 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2929 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2931 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2933 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2934 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2935 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2937 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2939 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2940 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2941 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2942 ins
.declaration
.tgsm_structured
.structure_count
);
2944 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2946 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2947 ins
.declaration
.thread_group_size
.x
,
2948 ins
.declaration
.thread_group_size
.y
,
2949 ins
.declaration
.thread_group_size
.z
);
2951 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2953 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2954 shader_dump_uav_flags(&buffer
, ins
.flags
);
2955 shader_addline(&buffer
, " ");
2956 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2958 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
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
.structured_resource
.reg
, &shader_version
);
2964 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2966 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2968 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2969 ins
.dst
[0].reg
.idx
[0].offset
),
2970 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
2971 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
2972 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
2973 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
2975 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2977 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2978 ins
.src
[0].reg
.u
.immconst_data
[0],
2979 ins
.src
[0].reg
.u
.immconst_data
[1],
2980 ins
.src
[0].reg
.u
.immconst_data
[2],
2981 ins
.src
[0].reg
.u
.immconst_data
[3]);
2983 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2985 shader_addline(&buffer
, "defb b%u = %s",
2986 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
2992 shader_addline(&buffer
, "(");
2993 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2994 shader_addline(&buffer
, ") ");
2997 /* PixWin marks instructions with the coissue flag with a '+' */
2999 shader_addline(&buffer
, "+");
3001 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
3003 if (ins
.handler_idx
== WINED3DSIH_BREAKP
3004 || ins
.handler_idx
== WINED3DSIH_CONTINUEP
3005 || ins
.handler_idx
== WINED3DSIH_IF
3006 || ins
.handler_idx
== WINED3DSIH_RETP
3007 || ins
.handler_idx
== WINED3DSIH_TEXKILL
)
3011 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
3012 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
3013 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
3016 else if (ins
.handler_idx
== WINED3DSIH_IFC
3017 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
3021 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
3022 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
3023 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
3024 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
3025 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
3026 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
3027 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
3030 else if (ins
.handler_idx
== WINED3DSIH_TEX
3031 && shader_version
.major
>= 2
3032 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
3034 shader_addline(&buffer
, "p");
3036 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
3040 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
3041 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3042 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3045 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
3049 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3050 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3053 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
3055 shader_dump_sync_flags(&buffer
, ins
.flags
);
3058 if (wined3d_shader_instruction_has_texel_offset(&ins
))
3059 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
3061 for (i
= 0; i
< ins
.dst_count
; ++i
)
3063 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
3064 shader_addline(&buffer
, !i
? " " : ", ");
3065 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
3068 /* Other source tokens */
3069 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
3071 shader_addline(&buffer
, !i
? " " : ", ");
3072 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
3075 shader_addline(&buffer
, "\n");
3078 for (p
= buffer
.buffer
; *p
; p
= q
)
3080 if (!(q
= strstr(p
, "\n")))
3084 TRACE(" %.*s", (int)(q
- p
), p
);
3087 string_buffer_free(&buffer
);
3090 static void shader_cleanup(struct wined3d_shader
*shader
)
3092 if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
3094 HeapFree(GetProcessHeap(), 0, shader
->u
.hs
.phases
.control_point
);
3095 HeapFree(GetProcessHeap(), 0, shader
->u
.hs
.phases
.fork
);
3096 HeapFree(GetProcessHeap(), 0, shader
->u
.hs
.phases
.join
);
3098 else if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
3100 HeapFree(GetProcessHeap(), 0, shader
->u
.gs
.so_desc
.elements
);
3103 HeapFree(GetProcessHeap(), 0, shader
->patch_constant_signature
.elements
);
3104 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
3105 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3106 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3107 shader
->device
->shader_backend
->shader_destroy(shader
);
3108 shader_cleanup_reg_maps(&shader
->reg_maps
);
3109 HeapFree(GetProcessHeap(), 0, shader
->function
);
3110 shader_delete_constant_list(&shader
->constantsF
);
3111 shader_delete_constant_list(&shader
->constantsB
);
3112 shader_delete_constant_list(&shader
->constantsI
);
3113 list_remove(&shader
->shader_list_entry
);
3115 if (shader
->frontend
&& shader
->frontend_data
)
3116 shader
->frontend
->shader_free(shader
->frontend_data
);
3119 struct shader_none_priv
3121 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
3122 const struct fragment_pipeline
*fragment_pipe
;
3123 BOOL ffp_proj_control
;
3126 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
3127 static void shader_none_precompile(void *shader_priv
, struct wined3d_shader
*shader
) {}
3128 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
3129 const struct wined3d_state
*state
) {}
3130 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3131 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3132 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
3133 const struct wined3d_state
*state
) {}
3134 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
3135 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
3136 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
3138 /* Context activation is done by the caller. */
3139 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
3140 const struct wined3d_state
*state
)
3142 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3143 struct shader_none_priv
*priv
= shader_priv
;
3145 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
3146 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
3149 /* Context activation is done by the caller. */
3150 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
3152 struct shader_none_priv
*priv
= shader_priv
;
3153 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3155 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
3156 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
3158 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
3159 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
3160 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
3161 | (1u << WINED3D_SHADER_TYPE_HULL
)
3162 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
3163 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
3166 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
3167 const struct fragment_pipeline
*fragment_pipe
)
3169 struct fragment_caps fragment_caps
;
3170 void *vertex_priv
, *fragment_priv
;
3171 struct shader_none_priv
*priv
;
3173 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
3174 return E_OUTOFMEMORY
;
3176 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
3178 ERR("Failed to initialize vertex pipe.\n");
3179 HeapFree(GetProcessHeap(), 0, priv
);
3183 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
3185 ERR("Failed to initialize fragment pipe.\n");
3186 vertex_pipe
->vp_free(device
);
3187 HeapFree(GetProcessHeap(), 0, priv
);
3191 priv
->vertex_pipe
= vertex_pipe
;
3192 priv
->fragment_pipe
= fragment_pipe
;
3193 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
3194 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
3196 device
->vertex_priv
= vertex_priv
;
3197 device
->fragment_priv
= fragment_priv
;
3198 device
->shader_priv
= priv
;
3203 static void shader_none_free(struct wined3d_device
*device
)
3205 struct shader_none_priv
*priv
= device
->shader_priv
;
3207 priv
->fragment_pipe
->free_private(device
);
3208 priv
->vertex_pipe
->vp_free(device
);
3209 HeapFree(GetProcessHeap(), 0, priv
);
3212 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
3217 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
3219 /* Set the shader caps to 0 for the none shader backend */
3220 caps
->vs_version
= 0;
3221 caps
->hs_version
= 0;
3222 caps
->ds_version
= 0;
3223 caps
->gs_version
= 0;
3224 caps
->ps_version
= 0;
3225 caps
->cs_version
= 0;
3226 caps
->vs_uniform_count
= 0;
3227 caps
->ps_uniform_count
= 0;
3228 caps
->ps_1x_max_value
= 0.0f
;
3229 caps
->varying_count
= 0;
3230 caps
->wined3d_caps
= 0;
3233 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
3235 /* We "support" every possible fixup, since we don't support any shader
3236 * model, and will never have to actually sample a texture. */
3240 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
3242 struct shader_none_priv
*priv
= shader_priv
;
3244 return priv
->ffp_proj_control
;
3247 const struct wined3d_shader_backend_ops none_shader_backend
=
3249 shader_none_handle_instruction
,
3250 shader_none_precompile
,
3252 shader_none_select_compute
,
3253 shader_none_disable
,
3254 shader_none_update_float_vertex_constants
,
3255 shader_none_update_float_pixel_constants
,
3256 shader_none_load_constants
,
3257 shader_none_destroy
,
3260 shader_none_allocate_context_data
,
3261 shader_none_free_context_data
,
3262 shader_none_init_context_state
,
3263 shader_none_get_caps
,
3264 shader_none_color_fixup_supported
,
3265 shader_none_has_ffp_proj_control
,
3268 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, DWORD float_const_count
,
3269 enum wined3d_shader_type type
, unsigned int max_version
)
3271 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3272 const struct wined3d_shader_frontend
*fe
;
3274 unsigned int backend_version
;
3275 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
3277 TRACE("shader %p, float_const_count %u, type %#x, max_version %u.\n",
3278 shader
, float_const_count
, type
, max_version
);
3280 fe
= shader
->frontend
;
3281 if (!(shader
->frontend_data
= fe
->shader_init(shader
->function
,
3282 shader
->functionLength
, &shader
->output_signature
)))
3284 FIXME("Failed to initialize frontend.\n");
3285 return WINED3DERR_INVALIDCALL
;
3288 /* First pass: trace shader. */
3289 if (TRACE_ON(d3d_shader
))
3290 shader_trace_init(fe
, shader
->frontend_data
);
3292 /* Second pass: figure out which registers are used, what the semantics are, etc. */
3293 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
3294 &shader
->output_signature
, float_const_count
)))
3297 if (reg_maps
->shader_version
.type
!= type
)
3299 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
3300 return WINED3DERR_INVALIDCALL
;
3302 if (reg_maps
->shader_version
.major
> max_version
)
3304 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
3305 return WINED3DERR_INVALIDCALL
;
3309 case WINED3D_SHADER_TYPE_VERTEX
:
3310 backend_version
= d3d_info
->limits
.vs_version
;
3312 case WINED3D_SHADER_TYPE_HULL
:
3313 backend_version
= d3d_info
->limits
.hs_version
;
3315 case WINED3D_SHADER_TYPE_DOMAIN
:
3316 backend_version
= d3d_info
->limits
.ds_version
;
3318 case WINED3D_SHADER_TYPE_GEOMETRY
:
3319 backend_version
= d3d_info
->limits
.gs_version
;
3321 case WINED3D_SHADER_TYPE_PIXEL
:
3322 backend_version
= d3d_info
->limits
.ps_version
;
3324 case WINED3D_SHADER_TYPE_COMPUTE
:
3325 backend_version
= d3d_info
->limits
.cs_version
;
3328 FIXME("No backend version-checking for this shader type.\n");
3329 backend_version
= 0;
3331 if (reg_maps
->shader_version
.major
> backend_version
)
3333 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
3334 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
3335 return WINED3DERR_INVALIDCALL
;
3341 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
3343 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
3345 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
3350 static void wined3d_shader_init_object(void *object
)
3352 struct wined3d_shader
*shader
= object
;
3353 struct wined3d_device
*device
= shader
->device
;
3355 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3357 device
->shader_backend
->shader_precompile(device
->shader_priv
, shader
);
3360 static void wined3d_shader_destroy_object(void *object
)
3362 shader_cleanup(object
);
3363 HeapFree(GetProcessHeap(), 0, object
);
3366 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
3368 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
3370 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
3374 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
3375 wined3d_cs_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
3381 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
3383 TRACE("shader %p.\n", shader
);
3385 return shader
->parent
;
3388 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
3389 void *byte_code
, UINT
*byte_code_size
)
3391 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
3395 *byte_code_size
= shader
->functionLength
;
3399 if (*byte_code_size
< shader
->functionLength
)
3401 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
3402 * than the required size we should write the required size and
3403 * return D3DERR_MOREDATA. That's not actually true. */
3404 return WINED3DERR_INVALIDCALL
;
3407 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
3412 /* Set local constants for d3d8 shaders. */
3413 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
3414 UINT start_idx
, const float *src_data
, UINT count
)
3416 UINT end_idx
= start_idx
+ count
;
3419 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
3421 if (end_idx
> shader
->limits
->constant_float
)
3423 WARN("end_idx %u > float constants limit %u.\n",
3424 end_idx
, shader
->limits
->constant_float
);
3425 end_idx
= shader
->limits
->constant_float
;
3428 for (i
= start_idx
; i
< end_idx
; ++i
)
3430 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
3433 return E_OUTOFMEMORY
;
3436 value
= (float *)lconst
->value
;
3437 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3438 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3440 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3441 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3443 shader
->lconst_inf_or_nan
= TRUE
;
3450 static void init_interpolation_compile_args(DWORD
*interpolation_args
,
3451 const struct wined3d_shader
*pixel_shader
, const struct wined3d_gl_info
*gl_info
)
3453 if (!needs_interpolation_qualifiers_for_shader_outputs(gl_info
)
3454 || !pixel_shader
|| pixel_shader
->reg_maps
.shader_version
.major
< 4)
3456 memset(interpolation_args
, 0, sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3460 memcpy(interpolation_args
, pixel_shader
->u
.ps
.interpolation_mode
,
3461 sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3464 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3465 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_context
*context
)
3467 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3468 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3469 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3470 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3471 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3473 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3474 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3475 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3476 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3477 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
3478 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3479 args
->next_shader_type
= hull_shader
? WINED3D_SHADER_TYPE_HULL
3480 : geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3481 if (shader
->reg_maps
.shader_version
.major
>= 4)
3482 args
->next_shader_input_count
= hull_shader
? hull_shader
->limits
->packed_input
3483 : geometry_shader
? geometry_shader
->limits
->packed_input
3484 : pixel_shader
? pixel_shader
->limits
->packed_input
: 0;
3486 args
->next_shader_input_count
= 0;
3487 args
->swizzle_map
= swizzle_map
;
3488 if (d3d_info
->emulated_flatshading
)
3489 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3491 args
->flatshading
= 0;
3493 init_interpolation_compile_args(args
->interpolation_mode
,
3494 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, gl_info
);
3497 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3499 if (usage_idx1
!= usage_idx2
)
3501 if (usage1
== usage2
)
3503 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3505 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3511 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3512 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3514 WORD map
= shader
->reg_maps
.input_registers
;
3517 for (i
= 0; map
; map
>>= 1, ++i
)
3519 if (!(map
& 1)) continue;
3521 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3522 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3531 static HRESULT
shader_signature_calculate_strings_length(const struct wined3d_shader_signature
*signature
,
3534 struct wined3d_shader_signature_element
*e
;
3538 for (i
= 0; i
< signature
->element_count
; ++i
)
3540 e
= &signature
->elements
[i
];
3541 len
= strlen(e
->semantic_name
);
3542 if (len
>= ~(SIZE_T
)0 - *total
)
3543 return E_OUTOFMEMORY
;
3550 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
3551 const struct wined3d_shader_signature
*src
, char **signature_strings
)
3553 struct wined3d_shader_signature_element
*e
;
3558 if (!src
->element_count
)
3561 ptr
= *signature_strings
;
3563 dst
->element_count
= src
->element_count
;
3564 if (!(dst
->elements
= wined3d_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
3565 return E_OUTOFMEMORY
;
3567 for (i
= 0; i
< src
->element_count
; ++i
)
3569 e
= &src
->elements
[i
];
3570 dst
->elements
[i
] = *e
;
3572 len
= strlen(e
->semantic_name
);
3573 memcpy(ptr
, e
->semantic_name
, len
+ 1);
3574 dst
->elements
[i
].semantic_name
= ptr
;
3578 *signature_strings
= ptr
;
3583 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3584 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
3585 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3587 size_t byte_code_size
;
3592 TRACE("byte_code %p, byte_code_size %#lx, format %#x, max_version %#x.\n",
3593 desc
->byte_code
, (long)desc
->byte_code_size
, desc
->format
, desc
->max_version
);
3595 if (!desc
->byte_code
)
3596 return WINED3DERR_INVALIDCALL
;
3598 if (!(shader
->frontend
= shader_select_frontend(desc
->format
)))
3600 FIXME("Unable to find frontend for shader.\n");
3601 return WINED3DERR_INVALIDCALL
;
3605 shader
->device
= device
;
3606 shader
->parent
= parent
;
3607 shader
->parent_ops
= parent_ops
;
3610 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->input_signature
, &total
)))
3612 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->output_signature
, &total
)))
3614 if (FAILED(hr
= shader_signature_calculate_strings_length(&desc
->patch_constant_signature
, &total
)))
3616 if (total
&& !(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
3617 return E_OUTOFMEMORY
;
3618 ptr
= shader
->signature_strings
;
3620 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
3622 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3625 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
3627 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3628 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3631 if (FAILED(hr
= shader_signature_copy(&shader
->patch_constant_signature
, &desc
->patch_constant_signature
, &ptr
)))
3633 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
3634 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3635 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3639 list_init(&shader
->linked_programs
);
3640 list_init(&shader
->constantsF
);
3641 list_init(&shader
->constantsB
);
3642 list_init(&shader
->constantsI
);
3643 shader
->lconst_inf_or_nan
= FALSE
;
3644 list_init(&shader
->reg_maps
.indexable_temps
);
3645 list_init(&shader
->shader_list_entry
);
3647 byte_code_size
= desc
->byte_code_size
;
3648 if (byte_code_size
== ~(size_t)0)
3650 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
3651 struct wined3d_shader_version shader_version
;
3652 struct wined3d_shader_instruction ins
;
3656 if (!(fe_data
= fe
->shader_init(desc
->byte_code
, byte_code_size
, &shader
->output_signature
)))
3658 WARN("Failed to initialise frontend data.\n");
3659 shader_cleanup(shader
);
3660 return WINED3DERR_INVALIDCALL
;
3663 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3664 while (!fe
->shader_is_end(fe_data
, &ptr
))
3665 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
3667 fe
->shader_free(fe_data
);
3669 byte_code_size
= (ptr
- desc
->byte_code
) * sizeof(*ptr
);
3672 if (!(shader
->function
= HeapAlloc(GetProcessHeap(), 0, byte_code_size
)))
3674 shader_cleanup(shader
);
3675 return E_OUTOFMEMORY
;
3677 memcpy(shader
->function
, desc
->byte_code
, byte_code_size
);
3678 shader
->functionLength
= byte_code_size
;
3680 if (FAILED(hr
= shader_set_function(shader
, float_const_count
, type
, desc
->max_version
)))
3682 WARN("Failed to set function, hr %#x.\n", hr
);
3683 shader_cleanup(shader
);
3687 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3689 wined3d_cs_init_object(shader
->device
->cs
, wined3d_shader_init_object
, shader
);
3694 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3695 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3697 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3701 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3702 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3705 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3707 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3709 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3712 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3713 shader_usage_from_semantic_name(input
->semantic_name
);
3714 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3717 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3718 shader
->load_local_constsF
= TRUE
;
3723 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3724 const struct wined3d_shader_desc
*desc
, const struct wined3d_stream_output_desc
*so_desc
,
3725 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3727 struct wined3d_stream_output_element
*elements
= NULL
;
3730 if (so_desc
&& !(elements
= wined3d_calloc(so_desc
->element_count
, sizeof(*elements
))))
3731 return E_OUTOFMEMORY
;
3733 if (FAILED(hr
= shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
)))
3735 HeapFree(GetProcessHeap(), 0, elements
);
3741 shader
->u
.gs
.so_desc
= *so_desc
;
3742 shader
->u
.gs
.so_desc
.elements
= elements
;
3743 memcpy(elements
, so_desc
->elements
, so_desc
->element_count
* sizeof(*elements
));
3749 void find_ds_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3750 struct ds_compile_args
*args
, const struct wined3d_context
*context
)
3752 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3753 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3754 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3755 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3757 args
->tessellator_output_primitive
= hull_shader
->u
.hs
.tessellator_output_primitive
;
3758 args
->tessellator_partitioning
= hull_shader
->u
.hs
.tessellator_partitioning
;
3760 args
->output_count
= geometry_shader
? geometry_shader
->limits
->packed_input
3761 : pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3762 args
->next_shader_type
= geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3764 args
->render_offscreen
= context
->render_offscreen
;
3766 init_interpolation_compile_args(args
->interpolation_mode
,
3767 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, gl_info
);
3772 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3773 struct gs_compile_args
*args
, const struct wined3d_context
*context
)
3775 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3776 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3778 args
->output_count
= pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3780 init_interpolation_compile_args(args
->interpolation_mode
, pixel_shader
, gl_info
);
3783 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3784 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3786 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3787 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3788 const struct wined3d_texture
*texture
;
3791 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3792 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3794 static unsigned int warned
= 0;
3796 args
->srgb_correction
= 1;
3797 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3798 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3799 "support, expect rendering artifacts.\n");
3802 if (shader
->reg_maps
.shader_version
.major
== 1
3803 && shader
->reg_maps
.shader_version
.minor
<= 3)
3805 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3807 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3809 if (flags
& WINED3D_TTFF_PROJECTED
)
3811 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3813 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3815 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3817 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3818 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3820 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3822 struct wined3d_vertex_declaration_element
*element
=
3823 &state
->vertex_declaration
->elements
[j
];
3825 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3826 && element
->usage_idx
== index
)
3828 max_valid
= element
->format
->component_count
;
3832 if (!tex_transform
|| tex_transform
> max_valid
)
3834 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3835 tex_transform
, max_valid
);
3836 tex_transform
= max_valid
;
3838 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3839 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3840 && tex_transform
> WINED3D_TTFF_COUNT2
)
3841 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3842 && tex_transform
> WINED3D_TTFF_COUNT3
))
3843 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3846 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3847 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3848 i
, tex_transform
, resource_type
);
3852 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3854 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3858 if (shader
->reg_maps
.shader_version
.major
== 1
3859 && shader
->reg_maps
.shader_version
.minor
<= 4)
3861 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3863 const struct wined3d_texture
*texture
= state
->textures
[i
];
3865 if (!shader
->reg_maps
.resource_info
[i
].type
)
3868 /* Treat unbound textures as 2D. The dummy texture will provide
3869 * the proper sample value. The tex_types bitmap defaults to
3870 * 2D because of the memset. */
3874 switch (texture
->target
)
3876 /* RECT textures are distinguished from 2D textures via np2_fixup */
3877 case GL_TEXTURE_RECTANGLE_ARB
:
3882 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3885 case GL_TEXTURE_CUBE_MAP_ARB
:
3886 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3892 if (shader
->reg_maps
.shader_version
.major
>= 4)
3894 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3896 for (i
= 0 ; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3897 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3898 args
->np2_fixup
= 0;
3902 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3904 if (!shader
->reg_maps
.resource_info
[i
].type
)
3907 texture
= state
->textures
[i
];
3910 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3913 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3914 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3916 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3918 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3919 args
->shadow
|= 1u << i
;
3921 /* Flag samplers that need NP2 texcoord fixup. */
3922 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3923 args
->np2_fixup
|= (1u << i
);
3927 if (shader
->reg_maps
.shader_version
.major
>= 3)
3929 if (position_transformed
)
3930 args
->vp_mode
= pretransformed
;
3931 else if (use_vs(state
))
3932 args
->vp_mode
= vertexshader
;
3934 args
->vp_mode
= fixedfunction
;
3935 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3939 args
->vp_mode
= vertexshader
;
3940 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3942 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3944 case WINED3D_FOG_NONE
:
3945 if (position_transformed
|| use_vs(state
))
3947 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3951 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3953 case WINED3D_FOG_NONE
: /* Fall through. */
3954 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3955 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3956 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3960 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3961 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3962 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3967 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3971 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3973 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3975 args
->texcoords_initialized
= 0;
3976 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
3980 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
3981 args
->texcoords_initialized
|= 1u << i
;
3985 const struct wined3d_stream_info
*si
= &context
->stream_info
;
3986 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3988 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
3989 & WINED3D_FFP_TCI_MASK
3990 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
3991 args
->texcoords_initialized
|= 1u << i
;
3997 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
4000 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
4001 && state
->gl_primitive_type
== GL_POINTS
;
4003 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
4004 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
4006 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
4007 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
4008 : WINED3D_CMP_ALWAYS
) - 1;
4010 if (d3d_info
->emulated_flatshading
)
4011 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4013 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
4014 ? context
->render_offscreen
: 0;
4017 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
4018 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
4020 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
4021 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
4024 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
4025 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
4028 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4030 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4033 highest_reg_used
= i
;
4037 /* Don't do any register mapping magic if it is not needed, or if we can't
4038 * achieve anything anyway */
4039 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
4040 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
4041 || shader
->reg_maps
.shader_version
.major
>= 4)
4043 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
4045 /* This happens with relative addressing. The input mapper function
4046 * warns about this if the higher registers are declared too, so
4047 * don't write a FIXME here */
4048 WARN("More varying registers used than supported\n");
4051 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4053 shader
->u
.ps
.input_reg_map
[i
] = i
;
4056 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
4060 shader
->u
.ps
.declared_in_count
= 0;
4061 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4063 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4064 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
4065 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
4072 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
4074 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
4075 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
4078 if (reg_maps
->shader_version
.major
!= 1) return;
4080 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4082 /* We don't sample from this sampler. */
4083 if (!resource_info
[i
].type
)
4086 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
4088 case WINED3D_SHADER_TEX_2D
:
4089 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
4092 case WINED3D_SHADER_TEX_3D
:
4093 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
4096 case WINED3D_SHADER_TEX_CUBE
:
4097 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
4103 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4104 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4106 struct wined3d_shader
*object
;
4109 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4110 device
, desc
, parent
, parent_ops
, shader
);
4112 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
4113 return E_OUTOFMEMORY
;
4115 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
)))
4117 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
4118 HeapFree(GetProcessHeap(), 0, object
);
4122 TRACE("Created compute shader %p.\n", object
);
4128 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4129 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4131 struct wined3d_shader
*object
;
4134 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4135 device
, desc
, parent
, parent_ops
, shader
);
4137 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
4138 return E_OUTOFMEMORY
;
4140 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
)))
4142 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
4143 HeapFree(GetProcessHeap(), 0, object
);
4147 TRACE("Created domain shader %p.\n", object
);
4153 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4154 const struct wined3d_stream_output_desc
*so_desc
, void *parent
,
4155 const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4157 struct wined3d_shader
*object
;
4160 TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
4161 device
, desc
, so_desc
, parent
, parent_ops
, shader
);
4163 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
4164 return E_OUTOFMEMORY
;
4166 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, so_desc
, parent
, parent_ops
)))
4168 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
4169 HeapFree(GetProcessHeap(), 0, object
);
4173 TRACE("Created geometry shader %p.\n", object
);
4179 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4180 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4182 struct wined3d_shader
*object
;
4185 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4186 device
, desc
, parent
, parent_ops
, shader
);
4188 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
4189 return E_OUTOFMEMORY
;
4191 if (FAILED(hr
= shader_init(object
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
)))
4193 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
4194 HeapFree(GetProcessHeap(), 0, object
);
4198 TRACE("Created hull shader %p.\n", object
);
4204 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4205 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4207 struct wined3d_shader
*object
;
4210 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4211 device
, desc
, parent
, parent_ops
, shader
);
4213 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4215 return E_OUTOFMEMORY
;
4217 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4219 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
4220 HeapFree(GetProcessHeap(), 0, object
);
4224 TRACE("Created pixel shader %p.\n", object
);
4230 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4231 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4233 struct wined3d_shader
*object
;
4236 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4237 device
, desc
, parent
, parent_ops
, shader
);
4239 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4241 return E_OUTOFMEMORY
;
4243 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4245 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
4246 HeapFree(GetProcessHeap(), 0, object
);
4250 TRACE("Created vertex shader %p.\n", object
);