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
30 #include "wined3d_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
34 const struct wined3d_vec4 wined3d_srgb_const
[] =
36 /* pow, mul_high, sub_high, mul_low */
37 {0.41666f
, 1.055f
, 0.055f
, 12.92f
},
39 {0.0031308f
, 0.0f
, 0.0f
, 0.0f
},
42 static const char * const shader_opcode_names
[] =
44 /* WINED3DSIH_ABS */ "abs",
45 /* WINED3DSIH_ADD */ "add",
46 /* WINED3DSIH_AND */ "and",
47 /* WINED3DSIH_ATOMIC_AND */ "atomic_and",
48 /* WINED3DSIH_ATOMIC_CMP_STORE */ "atomic_cmp_store",
49 /* WINED3DSIH_ATOMIC_IADD */ "atomic_iadd",
50 /* WINED3DSIH_ATOMIC_IMAX */ "atomic_imax",
51 /* WINED3DSIH_ATOMIC_IMIN */ "atomic_imin",
52 /* WINED3DSIH_ATOMIC_OR */ "atomic_or",
53 /* WINED3DSIH_ATOMIC_UMAX */ "atomic_umax",
54 /* WINED3DSIH_ATOMIC_UMIN */ "atomic_umin",
55 /* WINED3DSIH_ATOMIC_XOR */ "atomic_xor",
56 /* WINED3DSIH_BEM */ "bem",
57 /* WINED3DSIH_BFI */ "bfi",
58 /* WINED3DSIH_BFREV */ "bfrev",
59 /* WINED3DSIH_BREAK */ "break",
60 /* WINED3DSIH_BREAKC */ "breakc",
61 /* WINED3DSIH_BREAKP */ "breakp",
62 /* WINED3DSIH_BUFINFO */ "bufinfo",
63 /* WINED3DSIH_CALL */ "call",
64 /* WINED3DSIH_CALLNZ */ "callnz",
65 /* WINED3DSIH_CASE */ "case",
66 /* WINED3DSIH_CMP */ "cmp",
67 /* WINED3DSIH_CND */ "cnd",
68 /* WINED3DSIH_CONTINUE */ "continue",
69 /* WINED3DSIH_CONTINUEP */ "continuec",
70 /* WINED3DSIH_COUNTBITS */ "countbits",
71 /* WINED3DSIH_CRS */ "crs",
72 /* WINED3DSIH_CUT */ "cut",
73 /* WINED3DSIH_CUT_STREAM */ "cut_stream",
74 /* WINED3DSIH_DCL */ "dcl",
75 /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
76 /* WINED3DSIH_DCL_FUNCTION_BODY */ "dcl_function_body",
77 /* WINED3DSIH_DCL_FUNCTION_TABLE */ "dcl_function_table",
78 /* WINED3DSIH_DCL_GLOBAL_FLAGS */ "dcl_globalFlags",
79 /* WINED3DSIH_DCL_GS_INSTANCES */ "dcl_gs_instances",
80 /* WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT */ "dcl_hs_fork_phase_instance_count",
81 /* WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT */ "dcl_hs_join_phase_instance_count",
82 /* WINED3DSIH_DCL_HS_MAX_TESSFACTOR */ "dcl_hs_max_tessfactor",
83 /* WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER */ "dcl_immediateConstantBuffer",
84 /* WINED3DSIH_DCL_INDEX_RANGE */ "dcl_index_range",
85 /* WINED3DSIH_DCL_INDEXABLE_TEMP */ "dcl_indexableTemp",
86 /* WINED3DSIH_DCL_INPUT */ "dcl_input",
87 /* WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT */ "dcl_input_control_point_count",
88 /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
89 /* WINED3DSIH_DCL_INPUT_PS */ "dcl_input_ps",
90 /* WINED3DSIH_DCL_INPUT_PS_SGV */ "dcl_input_ps_sgv",
91 /* WINED3DSIH_DCL_INPUT_PS_SIV */ "dcl_input_ps_siv",
92 /* WINED3DSIH_DCL_INPUT_SGV */ "dcl_input_sgv",
93 /* WINED3DSIH_DCL_INPUT_SIV */ "dcl_input_siv",
94 /* WINED3DSIH_DCL_INTERFACE */ "dcl_interface",
95 /* WINED3DSIH_DCL_OUTPUT */ "dcl_output",
96 /* WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT */ "dcl_output_control_point_count",
97 /* WINED3DSIH_DCL_OUTPUT_SIV */ "dcl_output_siv",
98 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
99 /* WINED3DSIH_DCL_RESOURCE_RAW */ "dcl_resource_raw",
100 /* WINED3DSIH_DCL_RESOURCE_STRUCTURED */ "dcl_resource_structured",
101 /* WINED3DSIH_DCL_SAMPLER */ "dcl_sampler",
102 /* WINED3DSIH_DCL_STREAM */ "dcl_stream",
103 /* WINED3DSIH_DCL_TEMPS */ "dcl_temps",
104 /* WINED3DSIH_DCL_TESSELLATOR_DOMAIN */ "dcl_tessellator_domain",
105 /* WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE */ "dcl_tessellator_output_primitive",
106 /* WINED3DSIH_DCL_TESSELLATOR_PARTITIONING */ "dcl_tessellator_partitioning",
107 /* WINED3DSIH_DCL_TGSM_RAW */ "dcl_tgsm_raw",
108 /* WINED3DSIH_DCL_TGSM_STRUCTURED */ "dcl_tgsm_structured",
109 /* WINED3DSIH_DCL_THREAD_GROUP */ "dcl_thread_group",
110 /* WINED3DSIH_DCL_UAV_RAW */ "dcl_uav_raw",
111 /* WINED3DSIH_DCL_UAV_STRUCTURED */ "dcl_uav_structured",
112 /* WINED3DSIH_DCL_UAV_TYPED */ "dcl_uav_typed",
113 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
114 /* WINED3DSIH_DEF */ "def",
115 /* WINED3DSIH_DEFAULT */ "default",
116 /* WINED3DSIH_DEFB */ "defb",
117 /* WINED3DSIH_DEFI */ "defi",
118 /* WINED3DSIH_DIV */ "div",
119 /* WINED3DSIH_DP2 */ "dp2",
120 /* WINED3DSIH_DP2ADD */ "dp2add",
121 /* WINED3DSIH_DP3 */ "dp3",
122 /* WINED3DSIH_DP4 */ "dp4",
123 /* WINED3DSIH_DST */ "dst",
124 /* WINED3DSIH_DSX */ "dsx",
125 /* WINED3DSIH_DSX_COARSE */ "deriv_rtx_coarse",
126 /* WINED3DSIH_DSX_FINE */ "deriv_rtx_fine",
127 /* WINED3DSIH_DSY */ "dsy",
128 /* WINED3DSIH_DSY_COARSE */ "deriv_rty_coarse",
129 /* WINED3DSIH_DSY_FINE */ "deriv_rty_fine",
130 /* WINED3DSIH_ELSE */ "else",
131 /* WINED3DSIH_EMIT */ "emit",
132 /* WINED3DSIH_EMIT_STREAM */ "emit_stream",
133 /* WINED3DSIH_ENDIF */ "endif",
134 /* WINED3DSIH_ENDLOOP */ "endloop",
135 /* WINED3DSIH_ENDREP */ "endrep",
136 /* WINED3DSIH_ENDSWITCH */ "endswitch",
137 /* WINED3DSIH_EQ */ "eq",
138 /* WINED3DSIH_EVAL_SAMPLE_INDEX */ "eval_sample_index",
139 /* WINED3DSIH_EXP */ "exp",
140 /* WINED3DSIH_EXPP */ "expp",
141 /* WINED3DSIH_F16TOF32 */ "f16tof32",
142 /* WINED3DSIH_F32TOF16 */ "f32tof16",
143 /* WINED3DSIH_FCALL */ "fcall",
144 /* WINED3DSIH_FIRSTBIT_HI */ "firstbit_hi",
145 /* WINED3DSIH_FIRSTBIT_LO */ "firstbit_lo",
146 /* WINED3DSIH_FIRSTBIT_SHI */ "firstbit_shi",
147 /* WINED3DSIH_FRC */ "frc",
148 /* WINED3DSIH_FTOI */ "ftoi",
149 /* WINED3DSIH_FTOU */ "ftou",
150 /* WINED3DSIH_GATHER4 */ "gather4",
151 /* WINED3DSIH_GATHER4_C */ "gather4_c",
152 /* WINED3DSIH_GATHER4_PO */ "gather4_po",
153 /* WINED3DSIH_GATHER4_PO_C */ "gather4_po_c",
154 /* WINED3DSIH_GE */ "ge",
155 /* WINED3DSIH_HS_CONTROL_POINT_PHASE */ "hs_control_point_phase",
156 /* WINED3DSIH_HS_DECLS */ "hs_decls",
157 /* WINED3DSIH_HS_FORK_PHASE */ "hs_fork_phase",
158 /* WINED3DSIH_HS_JOIN_PHASE */ "hs_join_phase",
159 /* WINED3DSIH_IADD */ "iadd",
160 /* WINED3DSIH_IBFE */ "ibfe",
161 /* WINED3DSIH_IEQ */ "ieq",
162 /* WINED3DSIH_IF */ "if",
163 /* WINED3DSIH_IFC */ "ifc",
164 /* WINED3DSIH_IGE */ "ige",
165 /* WINED3DSIH_ILT */ "ilt",
166 /* WINED3DSIH_IMAD */ "imad",
167 /* WINED3DSIH_IMAX */ "imax",
168 /* WINED3DSIH_IMIN */ "imin",
169 /* WINED3DSIH_IMM_ATOMIC_ALLOC */ "imm_atomic_alloc",
170 /* WINED3DSIH_IMM_ATOMIC_AND */ "imm_atomic_and",
171 /* WINED3DSIH_IMM_ATOMIC_CMP_EXCH */ "imm_atomic_cmp_exch",
172 /* WINED3DSIH_IMM_ATOMIC_CONSUME */ "imm_atomic_consume",
173 /* WINED3DSIH_IMM_ATOMIC_EXCH */ "imm_atomic_exch",
174 /* WINED3DSIH_IMM_ATOMIC_IADD */ "imm_atomic_iadd",
175 /* WINED3DSIH_IMM_ATOMIC_IMAX */ "imm_atomic_imax",
176 /* WINED3DSIH_IMM_ATOMIC_IMIN */ "imm_atomic_imin",
177 /* WINED3DSIH_IMM_ATOMIC_OR */ "imm_atomic_or",
178 /* WINED3DSIH_IMM_ATOMIC_UMAX */ "imm_atomic_umax",
179 /* WINED3DSIH_IMM_ATOMIC_UMIN */ "imm_atomic_umin",
180 /* WINED3DSIH_IMM_ATOMIC_XOR */ "imm_atomic_xor",
181 /* WINED3DSIH_IMUL */ "imul",
182 /* WINED3DSIH_INE */ "ine",
183 /* WINED3DSIH_INEG */ "ineg",
184 /* WINED3DSIH_ISHL */ "ishl",
185 /* WINED3DSIH_ISHR */ "ishr",
186 /* WINED3DSIH_ITOF */ "itof",
187 /* WINED3DSIH_LABEL */ "label",
188 /* WINED3DSIH_LD */ "ld",
189 /* WINED3DSIH_LD2DMS */ "ld2dms",
190 /* WINED3DSIH_LD_RAW */ "ld_raw",
191 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
192 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
193 /* WINED3DSIH_LIT */ "lit",
194 /* WINED3DSIH_LOD */ "lod",
195 /* WINED3DSIH_LOG */ "log",
196 /* WINED3DSIH_LOGP */ "logp",
197 /* WINED3DSIH_LOOP */ "loop",
198 /* WINED3DSIH_LRP */ "lrp",
199 /* WINED3DSIH_LT */ "lt",
200 /* WINED3DSIH_M3x2 */ "m3x2",
201 /* WINED3DSIH_M3x3 */ "m3x3",
202 /* WINED3DSIH_M3x4 */ "m3x4",
203 /* WINED3DSIH_M4x3 */ "m4x3",
204 /* WINED3DSIH_M4x4 */ "m4x4",
205 /* WINED3DSIH_MAD */ "mad",
206 /* WINED3DSIH_MAX */ "max",
207 /* WINED3DSIH_MIN */ "min",
208 /* WINED3DSIH_MOV */ "mov",
209 /* WINED3DSIH_MOVA */ "mova",
210 /* WINED3DSIH_MOVC */ "movc",
211 /* WINED3DSIH_MUL */ "mul",
212 /* WINED3DSIH_NE */ "ne",
213 /* WINED3DSIH_NOP */ "nop",
214 /* WINED3DSIH_NOT */ "not",
215 /* WINED3DSIH_NRM */ "nrm",
216 /* WINED3DSIH_OR */ "or",
217 /* WINED3DSIH_PHASE */ "phase",
218 /* WINED3DSIH_POW */ "pow",
219 /* WINED3DSIH_RCP */ "rcp",
220 /* WINED3DSIH_REP */ "rep",
221 /* WINED3DSIH_RESINFO */ "resinfo",
222 /* WINED3DSIH_RET */ "ret",
223 /* WINED3DSIH_RETP */ "retp",
224 /* WINED3DSIH_ROUND_NE */ "round_ne",
225 /* WINED3DSIH_ROUND_NI */ "round_ni",
226 /* WINED3DSIH_ROUND_PI */ "round_pi",
227 /* WINED3DSIH_ROUND_Z */ "round_z",
228 /* WINED3DSIH_RSQ */ "rsq",
229 /* WINED3DSIH_SAMPLE */ "sample",
230 /* WINED3DSIH_SAMPLE_B */ "sample_b",
231 /* WINED3DSIH_SAMPLE_C */ "sample_c",
232 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
233 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
234 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
235 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
236 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
237 /* WINED3DSIH_SETP */ "setp",
238 /* WINED3DSIH_SGE */ "sge",
239 /* WINED3DSIH_SGN */ "sgn",
240 /* WINED3DSIH_SINCOS */ "sincos",
241 /* WINED3DSIH_SLT */ "slt",
242 /* WINED3DSIH_SQRT */ "sqrt",
243 /* WINED3DSIH_STORE_RAW */ "store_raw",
244 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
245 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
246 /* WINED3DSIH_SUB */ "sub",
247 /* WINED3DSIH_SWAPC */ "swapc",
248 /* WINED3DSIH_SWITCH */ "switch",
249 /* WINED3DSIH_SYNC */ "sync",
250 /* WINED3DSIH_TEX */ "texld",
251 /* WINED3DSIH_TEXBEM */ "texbem",
252 /* WINED3DSIH_TEXBEML */ "texbeml",
253 /* WINED3DSIH_TEXCOORD */ "texcrd",
254 /* WINED3DSIH_TEXDEPTH */ "texdepth",
255 /* WINED3DSIH_TEXDP3 */ "texdp3",
256 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
257 /* WINED3DSIH_TEXKILL */ "texkill",
258 /* WINED3DSIH_TEXLDD */ "texldd",
259 /* WINED3DSIH_TEXLDL */ "texldl",
260 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
261 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
262 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
263 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
264 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
265 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
266 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
267 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
268 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
269 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
270 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
271 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
272 /* WINED3DSIH_UBFE */ "ubfe",
273 /* WINED3DSIH_UDIV */ "udiv",
274 /* WINED3DSIH_UGE */ "uge",
275 /* WINED3DSIH_ULT */ "ult",
276 /* WINED3DSIH_UMAX */ "umax",
277 /* WINED3DSIH_UMIN */ "umin",
278 /* WINED3DSIH_UMUL */ "umul",
279 /* WINED3DSIH_USHR */ "ushr",
280 /* WINED3DSIH_UTOF */ "utof",
281 /* WINED3DSIH_XOR */ "xor",
284 static const char * const semantic_names
[] =
286 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
287 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
288 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
289 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
290 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
291 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
292 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
293 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
294 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
295 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
296 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
297 /* WINED3D_DECL_USAGE_FOG */ "FOG",
298 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
299 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
304 enum wined3d_shader_input_sysval_semantic sysval_semantic
;
305 const char *sysval_name
;
307 shader_input_sysval_semantic_names
[] =
309 {WINED3D_SIV_POSITION
, "position"},
310 {WINED3D_SIV_CLIP_DISTANCE
, "clip_distance"},
311 {WINED3D_SIV_CULL_DISTANCE
, "cull_distance"},
312 {WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX
, "render_target_array_index"},
313 {WINED3D_SIV_VIEWPORT_ARRAY_INDEX
, "viewport_array_index"},
314 {WINED3D_SIV_VERTEX_ID
, "vertex_id"},
315 {WINED3D_SIV_INSTANCE_ID
, "instance_id"},
316 {WINED3D_SIV_PRIMITIVE_ID
, "primitive_id"},
317 {WINED3D_SIV_IS_FRONT_FACE
, "is_front_face"},
318 {WINED3D_SIV_SAMPLE_INDEX
, "sample_index"},
319 {WINED3D_SIV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
320 {WINED3D_SIV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
321 {WINED3D_SIV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
322 {WINED3D_SIV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
323 {WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
324 {WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
325 {WINED3D_SIV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
326 {WINED3D_SIV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
327 {WINED3D_SIV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
328 {WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
329 {WINED3D_SIV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
330 {WINED3D_SIV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
333 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
334 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
336 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
338 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
339 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
341 return shader_opcode_names
[handler_idx
];
344 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
346 if (usage
>= ARRAY_SIZE(semantic_names
))
348 FIXME("Unrecognized usage %#x.\n", usage
);
349 return "UNRECOGNIZED";
352 return semantic_names
[usage
];
355 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
359 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
361 if (!strcmp(name
, semantic_names
[i
]))
368 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
372 case WINED3D_DECL_USAGE_POSITION
:
373 return WINED3D_SV_POSITION
;
379 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
381 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
384 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
385 const struct wined3d_shader_semantic
*s
)
387 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
388 e
->semantic_idx
= s
->usage_idx
;
390 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
391 e
->component_type
= WINED3D_TYPE_FLOAT
;
392 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
393 e
->mask
= s
->reg
.write_mask
;
396 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
397 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
399 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
400 e
->semantic_idx
= usage_idx
;
402 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
403 e
->component_type
= WINED3D_TYPE_FLOAT
;
404 e
->register_idx
= reg_idx
;
405 e
->mask
= write_mask
;
408 static const struct wined3d_shader_frontend
*shader_select_frontend(enum wined3d_shader_byte_code_format format
)
412 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
:
413 return &sm1_shader_frontend
;
415 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
:
416 return &sm4_shader_frontend
;
419 WARN("Invalid byte code format %#x specified.\n", format
);
424 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
426 buffer
->buffer
[0] = '\0';
427 buffer
->content_size
= 0;
430 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
432 buffer
->buffer_size
= 32;
433 if (!(buffer
->buffer
= heap_alloc(buffer
->buffer_size
)))
435 ERR("Failed to allocate shader buffer memory.\n");
439 string_buffer_clear(buffer
);
443 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
445 heap_free(buffer
->buffer
);
448 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
451 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
453 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
454 new_buffer_size
*= 2;
455 if (!(new_buffer
= heap_realloc(buffer
->buffer
, new_buffer_size
)))
457 ERR("Failed to grow buffer.\n");
458 buffer
->buffer
[buffer
->content_size
] = '\0';
461 buffer
->buffer
= new_buffer
;
462 buffer
->buffer_size
= new_buffer_size
;
466 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
471 rem
= buffer
->buffer_size
- buffer
->content_size
;
472 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
473 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
476 buffer
->content_size
+= rc
;
480 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
487 va_start(args
, format
);
488 ret
= shader_vaddline(buffer
, format
, args
);
492 if (!string_buffer_resize(buffer
, ret
))
497 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
499 struct wined3d_string_buffer
*buffer
;
501 if (list_empty(&list
->list
))
503 buffer
= heap_alloc(sizeof(*buffer
));
504 if (!buffer
|| !string_buffer_init(buffer
))
506 ERR("Couldn't allocate buffer for temporary string.\n");
513 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
514 list_remove(&buffer
->entry
);
516 string_buffer_clear(buffer
);
520 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
524 string_buffer_clear(buffer
);
525 return shader_vaddline(buffer
, format
, args
);
528 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
535 va_start(args
, format
);
536 ret
= string_buffer_vsprintf(buffer
, format
, args
);
540 if (!string_buffer_resize(buffer
, ret
))
545 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
549 list_add_head(&list
->list
, &buffer
->entry
);
552 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
554 list_init(&list
->list
);
557 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
559 struct wined3d_string_buffer
*buffer
, *buffer_next
;
561 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
563 string_buffer_free(buffer
);
566 list_init(&list
->list
);
569 /* Convert floating point offset relative to a register file to an absolute
570 * offset for float constants. */
571 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
573 switch (register_type
)
575 case WINED3DSPR_CONST
: return register_idx
;
576 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
577 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
578 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
580 FIXME("Unsupported register type: %u.\n", register_type
);
585 static void shader_delete_constant_list(struct list
*clist
)
587 struct wined3d_shader_lconst
*constant
, *constant_next
;
589 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
594 static void shader_set_limits(struct wined3d_shader
*shader
)
596 static const struct limits_entry
598 unsigned int min_version
;
599 unsigned int max_version
;
600 struct wined3d_shader_limits limits
;
604 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
605 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
606 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
607 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
608 * even though they are capable of supporting much more (GL
609 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
610 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
612 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
613 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
614 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
619 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
620 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
624 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
625 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
629 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
630 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
631 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
636 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
637 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
638 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
639 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
640 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
641 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
642 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
647 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
648 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
650 const struct limits_entry
*limits_array
;
651 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
652 shader
->reg_maps
.shader_version
.minor
);
655 switch (shader
->reg_maps
.shader_version
.type
)
658 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
660 case WINED3D_SHADER_TYPE_VERTEX
:
661 limits_array
= vs_limits
;
663 case WINED3D_SHADER_TYPE_HULL
:
664 limits_array
= hs_limits
;
666 case WINED3D_SHADER_TYPE_DOMAIN
:
667 limits_array
= ds_limits
;
669 case WINED3D_SHADER_TYPE_GEOMETRY
:
670 limits_array
= gs_limits
;
672 case WINED3D_SHADER_TYPE_PIXEL
:
673 limits_array
= ps_limits
;
675 case WINED3D_SHADER_TYPE_COMPUTE
:
676 limits_array
= cs_limits
;
680 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
682 if (shader_version
<= limits_array
[i
].max_version
)
684 shader
->limits
= &limits_array
[i
].limits
;
691 FIXME("Unexpected shader version \"%u.%u\".\n",
692 shader
->reg_maps
.shader_version
.major
,
693 shader
->reg_maps
.shader_version
.minor
);
694 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
698 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
699 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
703 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
704 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
705 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
707 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
710 case WINED3DSPR_TEMP
:
711 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
714 case WINED3DSPR_INPUT
:
715 if (reg
->idx
[0].rel_addr
)
716 reg_maps
->input_rel_addressing
= 1;
717 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
719 /* If relative addressing is used, we must assume that all
720 * registers are used. Even if it is a construct like v3[aL],
721 * we can't assume that v0, v1 and v2 aren't read because aL
722 * can be negative. */
723 if (reg
->idx
[0].rel_addr
)
724 shader
->u
.ps
.input_reg_used
= ~0u;
726 shader
->u
.ps
.input_reg_used
|= 1u << reg
->idx
[0].offset
;
730 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
734 case WINED3DSPR_RASTOUT
:
735 if (reg
->idx
[0].offset
== 1)
737 if (reg
->idx
[0].offset
== 2)
738 reg_maps
->point_size
= 1;
741 case WINED3DSPR_MISCTYPE
:
742 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
744 if (!reg
->idx
[0].offset
)
746 else if (reg
->idx
[0].offset
== 1)
747 reg_maps
->usesfacing
= 1;
751 case WINED3DSPR_CONST
:
752 if (reg
->idx
[0].rel_addr
)
754 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
755 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
756 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
757 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
758 reg_maps
->usesrelconstF
= TRUE
;
762 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
764 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
769 wined3d_insert_bits(reg_maps
->constf
, reg
->idx
[0].offset
, 1, 0x1);
774 case WINED3DSPR_CONSTINT
:
775 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
777 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
782 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
786 case WINED3DSPR_CONSTBOOL
:
787 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
789 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
794 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
798 case WINED3DSPR_COLOROUT
:
799 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
802 case WINED3DSPR_OUTCONTROLPOINT
:
806 case WINED3DSPR_SAMPLEMASK
:
807 reg_maps
->sample_mask
= 1;
811 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
812 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
818 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
819 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
821 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
822 struct wined3d_shader_sampler_map
*map
;
825 map
= ®_maps
->sampler_map
;
826 entries
= map
->entries
;
827 for (i
= 0; i
< map
->count
; ++i
)
829 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
835 if (!(entries
= heap_calloc(4, sizeof(*entries
))))
837 ERR("Failed to allocate sampler map entries.\n");
841 map
->entries
= entries
;
843 else if (map
->count
== map
->size
)
845 size_t new_size
= map
->size
* 2;
847 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
848 || !(entries
= heap_realloc(entries
, sizeof(*entries
) * new_size
)))
850 ERR("Failed to resize sampler map entries.\n");
853 map
->size
= new_size
;
854 map
->entries
= entries
;
857 entry
= &entries
[map
->count
++];
858 entry
->resource_idx
= resource_idx
;
859 entry
->sampler_idx
= sampler_idx
;
860 entry
->bind_idx
= bind_idx
;
863 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
867 case WINED3DSIH_M4x4
:
868 case WINED3DSIH_M3x4
:
869 return param
== 1 ? 3 : 0;
871 case WINED3DSIH_M4x3
:
872 case WINED3DSIH_M3x3
:
873 return param
== 1 ? 2 : 0;
875 case WINED3DSIH_M3x2
:
876 return param
== 1 ? 1 : 0;
883 static HRESULT
shader_reg_maps_add_tgsm(struct wined3d_shader_reg_maps
*reg_maps
,
884 unsigned int register_idx
, unsigned int size
, unsigned int stride
)
886 struct wined3d_shader_tgsm
*tgsm
;
888 if (register_idx
>= MAX_TGSM_REGISTERS
)
890 ERR("Invalid TGSM register index %u.\n", register_idx
);
893 if (reg_maps
->shader_version
.type
!= WINED3D_SHADER_TYPE_COMPUTE
)
895 FIXME("TGSM declarations are allowed only in compute shaders.\n");
899 if (!wined3d_array_reserve((void **)®_maps
->tgsm
, ®_maps
->tgsm_capacity
,
900 register_idx
+ 1, sizeof(*reg_maps
->tgsm
)))
901 return E_OUTOFMEMORY
;
903 reg_maps
->tgsm_count
= max(register_idx
+ 1, reg_maps
->tgsm_count
);
904 tgsm
= ®_maps
->tgsm
[register_idx
];
906 tgsm
->stride
= stride
;
910 static HRESULT
shader_record_shader_phase(struct wined3d_shader
*shader
,
911 struct wined3d_shader_phase
**current_phase
, const struct wined3d_shader_instruction
*ins
,
912 const DWORD
*current_instruction_ptr
, const DWORD
*previous_instruction_ptr
)
914 struct wined3d_shader_phase
*phase
;
916 if ((phase
= *current_phase
))
918 phase
->end
= previous_instruction_ptr
;
919 *current_phase
= NULL
;
922 if (shader
->reg_maps
.shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
924 ERR("Unexpected shader type %s.\n", debug_shader_type(shader
->reg_maps
.shader_version
.type
));
928 switch (ins
->handler_idx
)
930 case WINED3DSIH_HS_CONTROL_POINT_PHASE
:
931 if (shader
->u
.hs
.phases
.control_point
)
933 FIXME("Multiple control point phases.\n");
934 heap_free(shader
->u
.hs
.phases
.control_point
);
936 if (!(shader
->u
.hs
.phases
.control_point
= heap_alloc_zero(sizeof(*shader
->u
.hs
.phases
.control_point
))))
937 return E_OUTOFMEMORY
;
938 phase
= shader
->u
.hs
.phases
.control_point
;
940 case WINED3DSIH_HS_FORK_PHASE
:
941 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.fork
,
942 &shader
->u
.hs
.phases
.fork_size
, shader
->u
.hs
.phases
.fork_count
+ 1,
943 sizeof(*shader
->u
.hs
.phases
.fork
)))
944 return E_OUTOFMEMORY
;
945 phase
= &shader
->u
.hs
.phases
.fork
[shader
->u
.hs
.phases
.fork_count
++];
947 case WINED3DSIH_HS_JOIN_PHASE
:
948 if (!wined3d_array_reserve((void **)&shader
->u
.hs
.phases
.join
,
949 &shader
->u
.hs
.phases
.join_size
, shader
->u
.hs
.phases
.join_count
+ 1,
950 sizeof(*shader
->u
.hs
.phases
.join
)))
951 return E_OUTOFMEMORY
;
952 phase
= &shader
->u
.hs
.phases
.join
[shader
->u
.hs
.phases
.join_count
++];
955 ERR("Unexpected opcode %s.\n", debug_d3dshaderinstructionhandler(ins
->handler_idx
));
959 phase
->start
= current_instruction_ptr
;
960 *current_phase
= phase
;
965 static HRESULT
shader_calculate_clip_or_cull_distance_mask(
966 const struct wined3d_shader_signature_element
*e
, unsigned int *mask
)
968 /* Clip and cull distances are packed in 4 component registers. 0 and 1 are
969 * the only allowed semantic indices.
971 if (e
->semantic_idx
>= WINED3D_MAX_CLIP_DISTANCES
/ 4)
974 WARN("Invalid clip/cull distance index %u.\n", e
->semantic_idx
);
975 return WINED3DERR_INVALIDCALL
;
978 *mask
= (e
->mask
& WINED3DSP_WRITEMASK_ALL
) << (4 * e
->semantic_idx
);
982 static void wined3d_insert_interpolation_mode(DWORD
*packed_interpolation_mode
,
983 unsigned int register_idx
, enum wined3d_shader_interpolation_mode mode
)
985 if (mode
> WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
)
986 FIXME("Unexpected interpolation mode %#x.\n", mode
);
988 wined3d_insert_bits(packed_interpolation_mode
,
989 register_idx
* WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, WINED3D_PACKED_INTERPOLATION_BIT_COUNT
, mode
);
992 static HRESULT
shader_scan_output_signature(struct wined3d_shader
*shader
)
994 const struct wined3d_shader_signature
*output_signature
= &shader
->output_signature
;
995 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
999 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1001 const struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1004 reg_maps
->output_registers
|= 1u << e
->register_idx
;
1005 if (e
->sysval_semantic
== WINED3D_SV_CLIP_DISTANCE
)
1007 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1009 reg_maps
->clip_distance_mask
|= mask
;
1011 else if (e
->sysval_semantic
== WINED3D_SV_CULL_DISTANCE
)
1013 if (FAILED(hr
= shader_calculate_clip_or_cull_distance_mask(e
, &mask
)))
1015 reg_maps
->cull_distance_mask
|= mask
;
1017 else if (e
->sysval_semantic
== WINED3D_SV_VIEWPORT_ARRAY_INDEX
)
1019 reg_maps
->viewport_array
= 1;
1026 /* Note that this does not count the loop register as an address register. */
1027 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, DWORD constf_size
)
1029 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
1030 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
1031 struct wined3d_shader_signature
*output_signature
= &shader
->output_signature
;
1032 struct wined3d_shader_signature
*input_signature
= &shader
->input_signature
;
1033 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
1034 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
1035 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
1036 struct wined3d_shader_version shader_version
;
1037 struct wined3d_shader_phase
*phase
= NULL
;
1038 const DWORD
*ptr
, *prev_ins
, *current_ins
;
1039 void *fe_data
= shader
->frontend_data
;
1043 memset(reg_maps
, 0, sizeof(*reg_maps
));
1044 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
1045 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
1046 reg_maps
->min_rel_offset
= ~0U;
1047 list_init(®_maps
->indexable_temps
);
1049 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1050 prev_ins
= current_ins
= ptr
;
1051 reg_maps
->shader_version
= shader_version
;
1053 shader_set_limits(shader
);
1055 if (!(reg_maps
->constf
= heap_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
1056 sizeof(*reg_maps
->constf
))))
1058 ERR("Failed to allocate constant map memory.\n");
1059 return E_OUTOFMEMORY
;
1062 while (!fe
->shader_is_end(fe_data
, &ptr
))
1064 struct wined3d_shader_instruction ins
;
1068 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1070 /* Unhandled opcode, and its parameters. */
1071 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1073 WARN("Encountered unrecognised or invalid instruction.\n");
1074 return WINED3DERR_INVALIDCALL
;
1077 /* Handle declarations. */
1078 if (ins
.handler_idx
== WINED3DSIH_DCL
1079 || ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
1081 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
1082 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
1084 switch (semantic
->reg
.reg
.type
)
1086 /* Mark input registers used. */
1087 case WINED3DSPR_INPUT
:
1088 if (reg_idx
>= MAX_REG_INPUT
)
1090 ERR("Invalid input register index %u.\n", reg_idx
);
1093 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
1094 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
1095 return WINED3DERR_INVALIDCALL
;
1096 reg_maps
->input_registers
|= 1u << reg_idx
;
1097 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
1100 /* Vertex shader: mark 3.0 output registers used, save token. */
1101 case WINED3DSPR_OUTPUT
:
1102 if (reg_idx
>= MAX_REG_OUTPUT
)
1104 ERR("Invalid output register index %u.\n", reg_idx
);
1107 reg_maps
->output_registers
|= 1u << reg_idx
;
1108 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
1109 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
1111 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
1112 reg_maps
->point_size
= 1;
1115 case WINED3DSPR_SAMPLER
:
1116 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1117 case WINED3DSPR_RESOURCE
:
1118 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1120 ERR("Invalid resource index %u.\n", reg_idx
);
1123 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
1124 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1125 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1128 case WINED3DSPR_UAV
:
1129 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1131 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1134 reg_maps
->uav_resource_info
[reg_idx
].type
= semantic
->resource_type
;
1135 reg_maps
->uav_resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
1137 FIXME("Ignoring typed UAV flags %#x.\n", ins
.flags
);
1141 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
1145 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1147 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
1148 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
1150 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
1154 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
1155 wined3d_bitmap_set(®_maps
->cb_map
, reg
->idx
[0].offset
);
1158 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
1160 if (ins
.flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1162 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1163 shader
->u
.ps
.force_early_depth_stencil
= TRUE
;
1165 FIXME("Invalid instruction %#x for shader type %#x.\n",
1166 ins
.handler_idx
, shader_version
.type
);
1170 WARN("Ignoring global flags %#x.\n", ins
.flags
);
1173 else if (ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
)
1175 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1176 shader
->u
.gs
.instance_count
= ins
.declaration
.count
;
1178 FIXME("Invalid instruction %#x for shader type %#x.\n",
1179 ins
.handler_idx
, shader_version
.type
);
1181 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
1182 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
)
1185 phase
->instance_count
= ins
.declaration
.count
;
1187 FIXME("Instruction %s outside of shader phase.\n",
1188 debug_d3dshaderinstructionhandler(ins
.handler_idx
));
1190 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
1193 FIXME("Multiple immediate constant buffers.\n");
1194 reg_maps
->icb
= ins
.declaration
.icb
;
1196 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
1200 FIXME("Indexable temporary registers not supported.\n");
1204 struct wined3d_shader_indexable_temp
*reg
;
1206 if (!(reg
= heap_alloc(sizeof(*reg
))))
1207 return E_OUTOFMEMORY
;
1209 *reg
= ins
.declaration
.indexable_temp
;
1210 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
1213 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
1215 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1216 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
.type
;
1218 FIXME("Invalid instruction %#x for shader type %#x.\n",
1219 ins
.handler_idx
, shader_version
.type
);
1221 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
1223 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1224 if (reg_idx
>= MAX_REG_INPUT
)
1226 ERR("Invalid register index %u.\n", reg_idx
);
1229 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1230 wined3d_insert_interpolation_mode(shader
->u
.ps
.interpolation_mode
, reg_idx
, ins
.flags
);
1232 FIXME("Invalid instruction %#x for shader type %#x.\n",
1233 ins
.handler_idx
, shader_version
.type
);
1235 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
1237 if (ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUT
1238 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTGE
1239 || ins
.declaration
.dst
.reg
.type
== WINED3DSPR_DEPTHOUTLE
)
1241 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1242 shader
->u
.ps
.depth_output
= ins
.declaration
.dst
.reg
.type
;
1244 FIXME("Invalid instruction %#x for shader type %#x.\n",
1245 ins
.handler_idx
, shader_version
.type
);
1248 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
1250 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1251 shader
->u
.hs
.output_vertex_count
= ins
.declaration
.count
;
1253 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1255 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1257 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1258 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
.type
;
1260 FIXME("Invalid instruction %#x for shader type %#x.\n",
1261 ins
.handler_idx
, shader_version
.type
);
1263 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
1265 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1266 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1268 ERR("Invalid resource index %u.\n", reg_idx
);
1271 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1272 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1273 reg_maps
->resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1274 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1276 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
1278 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1279 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1281 ERR("Invalid resource index %u.\n", reg_idx
);
1284 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1285 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1286 reg_maps
->resource_info
[reg_idx
].flags
= 0;
1287 reg_maps
->resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1288 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1290 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
1292 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
1293 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
1295 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
1298 phase
->temporary_count
= ins
.declaration
.count
;
1300 reg_maps
->temporary_count
= ins
.declaration
.count
;
1302 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
1304 if (shader_version
.type
== WINED3D_SHADER_TYPE_DOMAIN
)
1305 shader
->u
.ds
.tessellator_domain
= ins
.declaration
.tessellator_domain
;
1306 else if (shader_version
.type
!= WINED3D_SHADER_TYPE_HULL
)
1307 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1309 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
1311 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1312 shader
->u
.hs
.tessellator_output_primitive
= ins
.declaration
.tessellator_output_primitive
;
1314 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1316 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
1318 if (shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
1319 shader
->u
.hs
.tessellator_partitioning
= ins
.declaration
.tessellator_partitioning
;
1321 FIXME("Invalid instruction %#x for shader type %#x.\n", ins
.handler_idx
, shader_version
.type
);
1323 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
1325 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
, ins
.declaration
.tgsm_raw
.reg
.reg
.idx
[0].offset
,
1326 ins
.declaration
.tgsm_raw
.byte_count
/ 4, 0)))
1329 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
1331 unsigned int stride
= ins
.declaration
.tgsm_structured
.byte_stride
/ 4;
1332 unsigned int size
= stride
* ins
.declaration
.tgsm_structured
.structure_count
;
1333 if (FAILED(hr
= shader_reg_maps_add_tgsm(reg_maps
,
1334 ins
.declaration
.tgsm_structured
.reg
.reg
.idx
[0].offset
, size
, stride
)))
1337 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
1339 if (shader_version
.type
== WINED3D_SHADER_TYPE_COMPUTE
)
1341 shader
->u
.cs
.thread_group_size
= ins
.declaration
.thread_group_size
;
1345 FIXME("Invalid instruction %#x for shader type %#x.\n",
1346 ins
.handler_idx
, shader_version
.type
);
1349 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
1351 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1352 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1354 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1358 FIXME("Ignoring raw UAV flags %#x.\n", ins
.flags
);
1359 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1360 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1361 reg_maps
->uav_resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1363 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
1365 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1366 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1368 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1372 FIXME("Ignoring structured UAV flags %#x.\n", ins
.flags
);
1373 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1374 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1375 reg_maps
->uav_resource_info
[reg_idx
].flags
= 0;
1376 reg_maps
->uav_resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1378 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1380 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1381 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1383 FIXME("Invalid instruction %#x for shader type %#x.\n",
1384 ins
.handler_idx
, shader_version
.type
);
1386 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1388 struct wined3d_shader_lconst
*lconst
;
1391 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1392 return E_OUTOFMEMORY
;
1394 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1395 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1396 value
= (float *)lconst
->value
;
1398 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1399 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1401 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1402 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1403 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1404 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1405 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1406 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1407 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1408 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1411 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1413 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1414 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1416 shader
->lconst_inf_or_nan
= TRUE
;
1419 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1421 struct wined3d_shader_lconst
*lconst
;
1423 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1424 return E_OUTOFMEMORY
;
1426 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1427 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1429 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1430 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1432 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1434 struct wined3d_shader_lconst
*lconst
;
1436 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
1437 return E_OUTOFMEMORY
;
1439 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1440 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1442 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1443 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1445 /* Handle shader phases. */
1446 else if (ins
.handler_idx
== WINED3DSIH_HS_CONTROL_POINT_PHASE
1447 || ins
.handler_idx
== WINED3DSIH_HS_FORK_PHASE
1448 || ins
.handler_idx
== WINED3DSIH_HS_JOIN_PHASE
)
1450 if (FAILED(hr
= shader_record_shader_phase(shader
, &phase
, &ins
, current_ins
, prev_ins
)))
1453 /* For subroutine prototypes. */
1454 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1456 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1458 /* Set texture, address, temporary registers. */
1461 BOOL color0_mov
= FALSE
;
1464 /* This will loop over all the registers and try to
1465 * make a bitmask of the ones we're interested in.
1467 * Relative addressing tokens are ignored, but that's
1468 * okay, since we'll catch any address registers when
1469 * they are initialized (required by spec). */
1470 for (i
= 0; i
< ins
.dst_count
; ++i
)
1472 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1473 shader_version
.type
, constf_size
))
1474 return WINED3DERR_INVALIDCALL
;
1476 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1478 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1480 switch (ins
.dst
[i
].reg
.type
)
1482 case WINED3DSPR_RASTOUT
:
1483 if (shader_version
.major
>= 3)
1488 reg_maps
->output_registers
|= 1u << 10;
1489 shader_signature_from_usage(&output_signature_elements
[10],
1490 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1494 reg_maps
->output_registers
|= 1u << 11;
1495 shader_signature_from_usage(&output_signature_elements
[11],
1496 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1500 reg_maps
->output_registers
|= 1u << 11;
1501 shader_signature_from_usage(&output_signature_elements
[11],
1502 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1507 case WINED3DSPR_ATTROUT
:
1508 if (shader_version
.major
>= 3)
1513 if (reg_maps
->output_registers
& (1u << idx
))
1515 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1519 reg_maps
->output_registers
|= 1u << idx
;
1520 shader_signature_from_usage(&output_signature_elements
[idx
],
1521 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1526 case WINED3DSPR_TEXCRDOUT
: /* WINED3DSPR_OUTPUT */
1527 if (shader_version
.major
>= 3)
1529 if (idx
>= ARRAY_SIZE(reg_maps
->u
.output_registers_mask
))
1531 WARN("Invalid output register index %u.\n", idx
);
1534 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1537 if (idx
>= ARRAY_SIZE(reg_maps
->u
.texcoord_mask
))
1539 WARN("Invalid texcoord index %u.\n", idx
);
1542 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1543 if (reg_maps
->output_registers
& (1u << idx
))
1545 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1549 reg_maps
->output_registers
|= 1u << idx
;
1550 shader_signature_from_usage(&output_signature_elements
[idx
],
1551 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1560 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1562 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1564 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1565 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1566 * the mov and perform the sRGB write correction from the source register.
1568 * However, if the mov is only partial, we can't do this, and if the write
1569 * comes from an instruction other than MOV it is hard to do as well. If
1570 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1571 shader
->u
.ps
.color0_mov
= FALSE
;
1572 if (ins
.handler_idx
== WINED3DSIH_MOV
1573 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1575 /* Used later when the source register is read. */
1579 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1582 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1583 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1585 shader
->u
.ps
.color0_mov
= FALSE
;
1589 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1590 if (shader_version
.major
== 1
1591 && (ins
.handler_idx
== WINED3DSIH_TEX
1592 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1593 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1594 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1595 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1596 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1597 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1598 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1599 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1600 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1601 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1603 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1605 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1607 WARN("Invalid 1.x sampler index %u.\n", reg_idx
);
1611 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1612 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1613 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1614 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1615 wined3d_bitmap_set(reg_maps
->resource_map
, reg_idx
);
1617 /* texbem is only valid with < 1.4 pixel shaders */
1618 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1619 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1621 reg_maps
->bumpmat
|= 1u << reg_idx
;
1622 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1624 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1628 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1630 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1634 if (ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_ALLOC
|| ins
.handler_idx
== WINED3DSIH_IMM_ATOMIC_CONSUME
)
1636 unsigned int reg_idx
= ins
.src
[0].reg
.idx
[0].offset
;
1637 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1639 ERR("Invalid UAV index %u.\n", reg_idx
);
1642 reg_maps
->uav_counter_mask
|= (1u << reg_idx
);
1644 else if ((WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1645 || (WINED3DSIH_IMM_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_IMM_ATOMIC_XOR
)
1646 || (ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_UAV
)
1647 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
1648 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_UAV
)
1649 || (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
&& ins
.src
[2].reg
.type
== WINED3DSPR_UAV
))
1651 const struct wined3d_shader_register
*reg
;
1653 if (ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
|| ins
.handler_idx
== WINED3DSIH_LD_RAW
)
1654 reg
= &ins
.src
[1].reg
;
1655 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
)
1656 reg
= &ins
.src
[2].reg
;
1657 else if (WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1658 reg
= &ins
.dst
[0].reg
;
1659 else if (ins
.handler_idx
== WINED3DSIH_BUFINFO
)
1660 reg
= &ins
.src
[0].reg
;
1662 reg
= &ins
.dst
[1].reg
;
1664 if (reg
->type
== WINED3DSPR_UAV
)
1666 if (reg
->idx
[0].offset
>= MAX_UNORDERED_ACCESS_VIEWS
)
1668 ERR("Invalid UAV index %u.\n", reg
->idx
[0].offset
);
1671 reg_maps
->uav_read_mask
|= (1u << reg
->idx
[0].offset
);
1674 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1676 reg_maps
->usesnrm
= 1;
1678 else if (ins
.handler_idx
== WINED3DSIH_DSY
1679 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1680 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1682 reg_maps
->usesdsy
= 1;
1684 else if (ins
.handler_idx
== WINED3DSIH_DSX
1685 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1686 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1688 reg_maps
->usesdsx
= 1;
1690 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1691 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1692 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1693 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1694 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1695 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1696 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1697 || ins
.handler_idx
== WINED3DSIH_REP
)
1700 if (cur_loop_depth
> max_loop_depth
)
1701 max_loop_depth
= cur_loop_depth
;
1703 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1704 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1708 else if (ins
.handler_idx
== WINED3DSIH_GATHER4
1709 || ins
.handler_idx
== WINED3DSIH_GATHER4_C
1710 || ins
.handler_idx
== WINED3DSIH_SAMPLE
1711 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1712 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1713 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1714 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1715 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1717 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1718 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1720 else if (ins
.handler_idx
== WINED3DSIH_GATHER4_PO
1721 || ins
.handler_idx
== WINED3DSIH_GATHER4_PO_C
)
1723 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1724 ins
.src
[3].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1726 else if ((ins
.handler_idx
== WINED3DSIH_BUFINFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
)
1727 || (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.src
[0].reg
.type
== WINED3DSPR_RESOURCE
))
1729 shader_record_sample(reg_maps
, ins
.src
[0].reg
.idx
[0].offset
,
1730 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1732 else if (ins
.handler_idx
== WINED3DSIH_LD
1733 || ins
.handler_idx
== WINED3DSIH_LD2DMS
1734 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
)
1735 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1737 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1738 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1740 else if (ins
.handler_idx
== WINED3DSIH_LD_STRUCTURED
1741 && ins
.src
[2].reg
.type
== WINED3DSPR_RESOURCE
)
1743 shader_record_sample(reg_maps
, ins
.src
[2].reg
.idx
[0].offset
,
1744 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1748 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1749 shader_version
.type
, constf_size
))
1750 return WINED3DERR_INVALIDCALL
;
1752 for (i
= 0; i
< ins
.src_count
; ++i
)
1754 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1755 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1757 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1758 shader_version
.type
, constf_size
))
1759 return WINED3DERR_INVALIDCALL
;
1762 ++reg
.idx
[0].offset
;
1763 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1764 shader_version
.type
, constf_size
))
1765 return WINED3DERR_INVALIDCALL
;
1771 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1772 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1774 shader
->u
.ps
.color0_mov
= TRUE
;
1775 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1781 prev_ins
= current_ins
;
1783 reg_maps
->loop_depth
= max_loop_depth
;
1787 phase
->end
= prev_ins
;
1791 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1792 * R0 is written to the render target. */
1793 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1794 reg_maps
->rt_mask
|= (1u << 0);
1796 if (input_signature
->elements
)
1798 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1800 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1802 if (input_signature
->elements
[i
].register_idx
>= ARRAY_SIZE(shader
->u
.vs
.attributes
))
1804 WARN("Invalid input signature register index %u.\n", input_signature
->elements
[i
].register_idx
);
1805 return WINED3DERR_INVALIDCALL
;
1808 else if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1810 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1812 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1813 reg_maps
->usesfacing
= 1;
1815 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1818 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1820 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1821 struct wined3d_shader_signature_element
*e
;
1824 if (!(input_signature
->elements
= heap_calloc(count
, sizeof(*input_signature
->elements
))))
1825 return E_OUTOFMEMORY
;
1826 input_signature
->element_count
= count
;
1828 e
= input_signature
->elements
;
1829 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1831 if (!(reg_maps
->input_registers
& (1u << i
)))
1833 input_signature_elements
[i
].register_idx
= i
;
1834 *e
++ = input_signature_elements
[i
];
1838 if (output_signature
->elements
)
1840 if (FAILED(hr
= shader_scan_output_signature(shader
)))
1843 else if (reg_maps
->output_registers
)
1845 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1846 struct wined3d_shader_signature_element
*e
;
1848 if (!(output_signature
->elements
= heap_calloc(count
, sizeof(*output_signature
->elements
))))
1849 return E_OUTOFMEMORY
;
1850 output_signature
->element_count
= count
;
1852 e
= output_signature
->elements
;
1853 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1855 if (!(reg_maps
->output_registers
& (1u << i
)))
1857 *e
++ = output_signature_elements
[i
];
1864 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1866 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1868 heap_free(reg_maps
->constf
);
1869 heap_free(reg_maps
->sampler_map
.entries
);
1871 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1873 list_init(®_maps
->indexable_temps
);
1875 heap_free(reg_maps
->tgsm
);
1878 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1880 DWORD map
= 1u << max
;
1882 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1884 return wined3d_log2i(map
);
1887 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1889 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1891 shader_addline(buffer
, "refactoringAllowed");
1892 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1894 shader_addline(buffer
, " | ");
1897 if (global_flags
& WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
)
1899 shader_addline(buffer
, "forceEarlyDepthStencil");
1900 global_flags
&= ~WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL
;
1902 shader_addline(buffer
, " | ");
1905 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1907 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1908 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1912 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1915 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1917 if (sync_flags
& WINED3DSSF_GLOBAL_UAV
)
1919 shader_addline(buffer
, "_uglobal");
1920 sync_flags
&= ~WINED3DSSF_GLOBAL_UAV
;
1922 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1924 shader_addline(buffer
, "_g");
1925 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1927 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1929 shader_addline(buffer
, "_t");
1930 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1934 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1937 static void shader_dump_precise_flags(struct wined3d_string_buffer
*buffer
, DWORD flags
)
1939 if (!(flags
& WINED3DSI_PRECISE_XYZW
))
1942 shader_addline(buffer
, " [precise");
1943 if (flags
!= WINED3DSI_PRECISE_XYZW
)
1945 shader_addline(buffer
, "(%s%s%s%s)",
1946 flags
& WINED3DSI_PRECISE_X
? "x" : "",
1947 flags
& WINED3DSI_PRECISE_Y
? "y" : "",
1948 flags
& WINED3DSI_PRECISE_Z
? "z" : "",
1949 flags
& WINED3DSI_PRECISE_W
? "w" : "");
1951 shader_addline(buffer
, "]");
1954 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1956 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1958 shader_addline(buffer
, "_glc");
1959 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1961 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1963 shader_addline(buffer
, "_opc");
1964 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1968 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1971 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1972 enum wined3d_tessellator_domain domain
)
1976 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1977 shader_addline(buffer
, "line");
1979 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1980 shader_addline(buffer
, "triangle");
1982 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1983 shader_addline(buffer
, "quad");
1986 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1991 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1992 enum wined3d_tessellator_output_primitive output_primitive
)
1994 switch (output_primitive
)
1996 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1997 shader_addline(buffer
, "point");
1999 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
2000 shader_addline(buffer
, "line");
2002 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
2003 shader_addline(buffer
, "triangle_cw");
2005 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
2006 shader_addline(buffer
, "triangle_ccw");
2009 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
2014 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
2015 enum wined3d_tessellator_partitioning partitioning
)
2017 switch (partitioning
)
2019 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
2020 shader_addline(buffer
, "integer");
2022 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
2023 shader_addline(buffer
, "pow2");
2025 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
2026 shader_addline(buffer
, "fractional_odd");
2028 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
2029 shader_addline(buffer
, "fractional_even");
2032 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
2037 static void shader_dump_shader_input_sysval_semantic(struct wined3d_string_buffer
*buffer
,
2038 enum wined3d_shader_input_sysval_semantic semantic
)
2042 for (i
= 0; i
< ARRAY_SIZE(shader_input_sysval_semantic_names
); ++i
)
2044 if (shader_input_sysval_semantic_names
[i
].sysval_semantic
== semantic
)
2046 shader_addline(buffer
, "%s", shader_input_sysval_semantic_names
[i
].sysval_name
);
2051 shader_addline(buffer
, "unknown_shader_input_sysval_semantic(%#x)", semantic
);
2054 static void shader_dump_resource_type(struct wined3d_string_buffer
*buffer
, enum wined3d_shader_resource_type type
)
2056 static const char *const resource_type_names
[] =
2058 /* WINED3D_SHADER_RESOURCE_NONE */ "none",
2059 /* WINED3D_SHADER_RESOURCE_BUFFER */ "buffer",
2060 /* WINED3D_SHADER_RESOURCE_TEXTURE_1D */ "texture1d",
2061 /* WINED3D_SHADER_RESOURCE_TEXTURE_2D */ "texture2d",
2062 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DMS */ "texture2dms",
2063 /* WINED3D_SHADER_RESOURCE_TEXTURE_3D */ "texture3d",
2064 /* WINED3D_SHADER_RESOURCE_TEXTURE_CUBE */ "texturecube",
2065 /* WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY */ "texture1darray",
2066 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY */ "texture2darray",
2067 /* WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY */ "texture2dmsarray",
2068 /* WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY */ "texturecubearray",
2071 if (type
< ARRAY_SIZE(resource_type_names
))
2072 shader_addline(buffer
, "%s", resource_type_names
[type
]);
2074 shader_addline(buffer
, "unknown");
2077 static void shader_dump_data_type(struct wined3d_string_buffer
*buffer
, enum wined3d_data_type type
)
2079 static const char *const data_type_names
[] =
2081 /* WINED3D_DATA_FLOAT */ "(float)",
2082 /* WINED3D_DATA_INT */ "(int)",
2083 /* WINED3D_DATA_RESOURCE */ "(resource)",
2084 /* WINED3D_DATA_SAMPLER */ "(sampler)",
2085 /* WINED3D_DATA_UAV */ "(uav)",
2086 /* WINED3D_DATA_UINT */ "(uint)",
2087 /* WINED3D_DATA_UNORM */ "(unorm)",
2088 /* WINED3D_DATA_SNORM */ "(snorm)",
2089 /* WINED3D_DATA_OPAQUE */ "(opaque)",
2092 if (type
< ARRAY_SIZE(data_type_names
))
2093 shader_addline(buffer
, "%s", data_type_names
[type
]);
2095 shader_addline(buffer
, "(unknown)");
2098 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
2099 const struct wined3d_shader_semantic
*semantic
, unsigned int flags
,
2100 const struct wined3d_shader_version
*shader_version
)
2102 shader_addline(buffer
, "dcl");
2104 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
2106 switch (semantic
->resource_type
)
2108 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
2109 shader_addline(buffer
, "_2d");
2112 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
2113 shader_addline(buffer
, "_3d");
2116 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
2117 shader_addline(buffer
, "_cube");
2121 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
2125 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2127 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
2128 shader_addline(buffer
, "_resource_");
2130 shader_addline(buffer
, "_uav_");
2131 shader_dump_resource_type(buffer
, semantic
->resource_type
);
2132 if (semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
2133 shader_dump_uav_flags(buffer
, flags
);
2134 shader_dump_data_type(buffer
, semantic
->resource_data_type
);
2138 /* Pixel shaders 3.0 don't have usage semantics. */
2139 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
2142 shader_addline(buffer
, "_");
2144 switch (semantic
->usage
)
2146 case WINED3D_DECL_USAGE_POSITION
:
2147 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
2150 case WINED3D_DECL_USAGE_BLEND_INDICES
:
2151 shader_addline(buffer
, "blend");
2154 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
2155 shader_addline(buffer
, "weight");
2158 case WINED3D_DECL_USAGE_NORMAL
:
2159 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
2162 case WINED3D_DECL_USAGE_PSIZE
:
2163 shader_addline(buffer
, "psize");
2166 case WINED3D_DECL_USAGE_COLOR
:
2167 if (!semantic
->usage_idx
)
2168 shader_addline(buffer
, "color");
2170 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
2173 case WINED3D_DECL_USAGE_TEXCOORD
:
2174 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
2177 case WINED3D_DECL_USAGE_TANGENT
:
2178 shader_addline(buffer
, "tangent");
2181 case WINED3D_DECL_USAGE_BINORMAL
:
2182 shader_addline(buffer
, "binormal");
2185 case WINED3D_DECL_USAGE_TESS_FACTOR
:
2186 shader_addline(buffer
, "tessfactor");
2189 case WINED3D_DECL_USAGE_POSITIONT
:
2190 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
2193 case WINED3D_DECL_USAGE_FOG
:
2194 shader_addline(buffer
, "fog");
2197 case WINED3D_DECL_USAGE_DEPTH
:
2198 shader_addline(buffer
, "depth");
2201 case WINED3D_DECL_USAGE_SAMPLE
:
2202 shader_addline(buffer
, "sample");
2206 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
2207 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
2212 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
2213 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
2215 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
2216 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
2217 UINT offset
= reg
->idx
[0].offset
;
2221 case WINED3DSPR_TEMP
:
2222 shader_addline(buffer
, "r");
2225 case WINED3DSPR_INPUT
:
2226 shader_addline(buffer
, "v");
2229 case WINED3DSPR_CONST
:
2230 case WINED3DSPR_CONST2
:
2231 case WINED3DSPR_CONST3
:
2232 case WINED3DSPR_CONST4
:
2233 shader_addline(buffer
, "c");
2234 offset
= shader_get_float_offset(reg
->type
, offset
);
2237 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
2238 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
2241 case WINED3DSPR_RASTOUT
:
2242 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
2245 case WINED3DSPR_COLOROUT
:
2246 shader_addline(buffer
, "oC");
2249 case WINED3DSPR_DEPTHOUT
:
2250 shader_addline(buffer
, "oDepth");
2253 case WINED3DSPR_DEPTHOUTGE
:
2254 shader_addline(buffer
, "oDepthGE");
2257 case WINED3DSPR_DEPTHOUTLE
:
2258 shader_addline(buffer
, "oDepthLE");
2261 case WINED3DSPR_ATTROUT
:
2262 shader_addline(buffer
, "oD");
2265 case WINED3DSPR_TEXCRDOUT
:
2266 /* Vertex shaders >= 3.0 use general purpose output registers
2267 * (WINED3DSPR_OUTPUT), which can include an address token. */
2268 if (shader_version
->major
>= 3)
2269 shader_addline(buffer
, "o");
2271 shader_addline(buffer
, "oT");
2274 case WINED3DSPR_CONSTINT
:
2275 shader_addline(buffer
, "i");
2278 case WINED3DSPR_CONSTBOOL
:
2279 shader_addline(buffer
, "b");
2282 case WINED3DSPR_LABEL
:
2283 shader_addline(buffer
, "l");
2286 case WINED3DSPR_LOOP
:
2287 shader_addline(buffer
, "aL");
2290 case WINED3DSPR_SAMPLER
:
2291 shader_addline(buffer
, "s");
2294 case WINED3DSPR_MISCTYPE
:
2297 FIXME("Unhandled misctype register %u.\n", offset
);
2298 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
2302 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
2306 case WINED3DSPR_PREDICATE
:
2307 shader_addline(buffer
, "p");
2310 case WINED3DSPR_IMMCONST
:
2311 shader_addline(buffer
, "l");
2314 case WINED3DSPR_CONSTBUFFER
:
2315 shader_addline(buffer
, "cb");
2318 case WINED3DSPR_IMMCONSTBUFFER
:
2319 shader_addline(buffer
, "icb");
2322 case WINED3DSPR_PRIMID
:
2323 shader_addline(buffer
, "primID");
2326 case WINED3DSPR_NULL
:
2327 shader_addline(buffer
, "null");
2330 case WINED3DSPR_RASTERIZER
:
2331 shader_addline(buffer
, "rasterizer");
2334 case WINED3DSPR_RESOURCE
:
2335 shader_addline(buffer
, "t");
2338 case WINED3DSPR_UAV
:
2339 shader_addline(buffer
, "u");
2342 case WINED3DSPR_OUTPOINTID
:
2343 shader_addline(buffer
, "vOutputControlPointID");
2346 case WINED3DSPR_FORKINSTID
:
2347 shader_addline(buffer
, "vForkInstanceId");
2350 case WINED3DSPR_JOININSTID
:
2351 shader_addline(buffer
, "vJoinInstanceId");
2354 case WINED3DSPR_INCONTROLPOINT
:
2355 shader_addline(buffer
, "vicp");
2358 case WINED3DSPR_OUTCONTROLPOINT
:
2359 shader_addline(buffer
, "vocp");
2362 case WINED3DSPR_PATCHCONST
:
2363 shader_addline(buffer
, "vpc");
2366 case WINED3DSPR_TESSCOORD
:
2367 shader_addline(buffer
, "vDomainLocation");
2370 case WINED3DSPR_GROUPSHAREDMEM
:
2371 shader_addline(buffer
, "g");
2374 case WINED3DSPR_THREADID
:
2375 shader_addline(buffer
, "vThreadID");
2378 case WINED3DSPR_THREADGROUPID
:
2379 shader_addline(buffer
, "vThreadGroupID");
2382 case WINED3DSPR_LOCALTHREADID
:
2383 shader_addline(buffer
, "vThreadIDInGroup");
2386 case WINED3DSPR_LOCALTHREADINDEX
:
2387 shader_addline(buffer
, "vThreadIDInGroupFlattened");
2390 case WINED3DSPR_IDXTEMP
:
2391 shader_addline(buffer
, "x");
2394 case WINED3DSPR_STREAM
:
2395 shader_addline(buffer
, "m");
2398 case WINED3DSPR_FUNCTIONBODY
:
2399 shader_addline(buffer
, "fb");
2402 case WINED3DSPR_FUNCTIONPOINTER
:
2403 shader_addline(buffer
, "fp");
2406 case WINED3DSPR_COVERAGE
:
2407 shader_addline(buffer
, "vCoverage");
2410 case WINED3DSPR_SAMPLEMASK
:
2411 shader_addline(buffer
, "oMask");
2414 case WINED3DSPR_GSINSTID
:
2415 shader_addline(buffer
, "vGSInstanceID");
2419 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
2423 if (reg
->type
== WINED3DSPR_IMMCONST
)
2425 shader_addline(buffer
, "(");
2426 switch (reg
->immconst_type
)
2428 case WINED3D_IMMCONST_SCALAR
:
2429 switch (reg
->data_type
)
2431 case WINED3D_DATA_FLOAT
:
2432 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
2434 case WINED3D_DATA_INT
:
2435 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
2437 case WINED3D_DATA_RESOURCE
:
2438 case WINED3D_DATA_SAMPLER
:
2439 case WINED3D_DATA_UINT
:
2440 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
2443 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2448 case WINED3D_IMMCONST_VEC4
:
2449 switch (reg
->data_type
)
2451 case WINED3D_DATA_FLOAT
:
2452 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2453 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2454 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2456 case WINED3D_DATA_INT
:
2457 shader_addline(buffer
, "%d, %d, %d, %d",
2458 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2459 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2461 case WINED3D_DATA_RESOURCE
:
2462 case WINED3D_DATA_SAMPLER
:
2463 case WINED3D_DATA_UINT
:
2464 shader_addline(buffer
, "%u, %u, %u, %u",
2465 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2466 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2469 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2475 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2478 shader_addline(buffer
, ")");
2480 else if (reg
->type
!= WINED3DSPR_RASTOUT
2481 && reg
->type
!= WINED3DSPR_MISCTYPE
2482 && reg
->type
!= WINED3DSPR_NULL
)
2486 shader_addline(buffer
, "[");
2487 if (reg
->idx
[0].rel_addr
)
2489 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2490 shader_addline(buffer
, " + ");
2492 shader_addline(buffer
, "%u]", offset
);
2494 if (reg
->idx
[1].offset
!= ~0u)
2496 shader_addline(buffer
, "[");
2497 if (reg
->idx
[1].rel_addr
)
2499 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2500 shader_addline(buffer
, " + ");
2502 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2506 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2507 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2511 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2512 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2514 DWORD write_mask
= param
->write_mask
;
2516 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2518 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2520 static const char write_mask_chars
[] = "xyzw";
2522 shader_addline(buffer
, ".");
2523 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2524 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2525 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2526 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2527 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2528 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2529 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2530 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2534 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2535 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2537 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2538 DWORD swizzle
= param
->swizzle
;
2540 if (src_modifier
== WINED3DSPSM_NEG
2541 || src_modifier
== WINED3DSPSM_BIASNEG
2542 || src_modifier
== WINED3DSPSM_SIGNNEG
2543 || src_modifier
== WINED3DSPSM_X2NEG
2544 || src_modifier
== WINED3DSPSM_ABSNEG
)
2545 shader_addline(buffer
, "-");
2546 else if (src_modifier
== WINED3DSPSM_COMP
)
2547 shader_addline(buffer
, "1-");
2548 else if (src_modifier
== WINED3DSPSM_NOT
)
2549 shader_addline(buffer
, "!");
2551 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2552 shader_addline(buffer
, "abs(");
2554 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2556 switch (src_modifier
)
2558 case WINED3DSPSM_NONE
: break;
2559 case WINED3DSPSM_NEG
: break;
2560 case WINED3DSPSM_NOT
: break;
2561 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2562 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2563 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2564 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2565 case WINED3DSPSM_COMP
: break;
2566 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2567 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2568 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2569 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2570 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2571 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2572 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2575 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2577 static const char swizzle_chars
[] = "xyzw";
2578 DWORD swizzle_x
= swizzle
& 0x03;
2579 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2580 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2581 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2583 if (swizzle_x
== swizzle_y
2584 && swizzle_x
== swizzle_z
2585 && swizzle_x
== swizzle_w
)
2587 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2591 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2592 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2597 /* Shared code in order to generate the bulk of the shader string. */
2598 HRESULT
shader_generate_code(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2599 const struct wined3d_shader_reg_maps
*reg_maps
, void *backend_ctx
,
2600 const DWORD
*start
, const DWORD
*end
)
2602 struct wined3d_device
*device
= shader
->device
;
2603 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2604 void *fe_data
= shader
->frontend_data
;
2605 struct wined3d_shader_version shader_version
;
2606 struct wined3d_shader_parser_state state
;
2607 struct wined3d_shader_instruction ins
;
2608 struct wined3d_shader_tex_mx tex_mx
;
2609 struct wined3d_shader_context ctx
;
2612 /* Initialize current parsing state. */
2613 tex_mx
.current_row
= 0;
2614 state
.current_loop_depth
= 0;
2615 state
.current_loop_reg
= 0;
2616 state
.in_subroutine
= FALSE
;
2618 ctx
.shader
= shader
;
2619 ctx
.reg_maps
= reg_maps
;
2620 ctx
.buffer
= buffer
;
2621 ctx
.tex_mx
= &tex_mx
;
2623 ctx
.backend_data
= backend_ctx
;
2626 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2630 while (!fe
->shader_is_end(fe_data
, &ptr
) && ptr
!= end
)
2633 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2635 /* Unknown opcode and its parameters. */
2636 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2638 WARN("Encountered unrecognised or invalid instruction.\n");
2639 return WINED3DERR_INVALIDCALL
;
2643 FIXME("Predicates not implemented.\n");
2645 /* Call appropriate function for output target */
2646 device
->shader_backend
->shader_handle_instruction(&ins
);
2652 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2653 const struct wined3d_shader_dst_param
*dst
)
2655 DWORD mmask
= dst
->modifiers
;
2660 case 13: shader_addline(buffer
, "_d8"); break;
2661 case 14: shader_addline(buffer
, "_d4"); break;
2662 case 15: shader_addline(buffer
, "_d2"); break;
2663 case 1: shader_addline(buffer
, "_x2"); break;
2664 case 2: shader_addline(buffer
, "_x4"); break;
2665 case 3: shader_addline(buffer
, "_x8"); break;
2666 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2669 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2670 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2671 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2673 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2674 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2677 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2678 const struct wined3d_shader_primitive_type
*primitive_type
)
2680 switch (primitive_type
->type
)
2682 case WINED3D_PT_UNDEFINED
:
2683 shader_addline(buffer
, "undefined");
2685 case WINED3D_PT_POINTLIST
:
2686 shader_addline(buffer
, "pointlist");
2688 case WINED3D_PT_LINELIST
:
2689 shader_addline(buffer
, "linelist");
2691 case WINED3D_PT_LINESTRIP
:
2692 shader_addline(buffer
, "linestrip");
2694 case WINED3D_PT_TRIANGLELIST
:
2695 shader_addline(buffer
, "trianglelist");
2697 case WINED3D_PT_TRIANGLESTRIP
:
2698 shader_addline(buffer
, "trianglestrip");
2700 case WINED3D_PT_TRIANGLEFAN
:
2701 shader_addline(buffer
, "trianglefan");
2703 case WINED3D_PT_LINELIST_ADJ
:
2704 shader_addline(buffer
, "linelist_adj");
2706 case WINED3D_PT_LINESTRIP_ADJ
:
2707 shader_addline(buffer
, "linestrip_adj");
2709 case WINED3D_PT_TRIANGLELIST_ADJ
:
2710 shader_addline(buffer
, "trianglelist_adj");
2712 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2713 shader_addline(buffer
, "trianglestrip_adj");
2715 case WINED3D_PT_PATCH
:
2716 shader_addline(buffer
, "patch%u", primitive_type
->patch_vertex_count
);
2719 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
->type
);
2724 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2725 enum wined3d_shader_interpolation_mode interpolation_mode
)
2727 switch (interpolation_mode
)
2729 case WINED3DSIM_CONSTANT
:
2730 shader_addline(buffer
, "constant");
2732 case WINED3DSIM_LINEAR
:
2733 shader_addline(buffer
, "linear");
2735 case WINED3DSIM_LINEAR_CENTROID
:
2736 shader_addline(buffer
, "linear centroid");
2738 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2739 shader_addline(buffer
, "linear noperspective");
2741 case WINED3DSIM_LINEAR_SAMPLE
:
2742 shader_addline(buffer
, "linear sample");
2744 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2745 shader_addline(buffer
, "linear noperspective centroid");
2747 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2748 shader_addline(buffer
, "linear noperspective sample");
2751 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2756 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
)
2758 struct wined3d_shader_version shader_version
;
2759 struct wined3d_string_buffer buffer
;
2760 const char *type_prefix
;
2765 if (!string_buffer_init(&buffer
))
2767 ERR("Failed to initialize string buffer.\n");
2771 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2773 TRACE("Parsing %p.\n", ptr
);
2775 switch (shader_version
.type
)
2777 case WINED3D_SHADER_TYPE_VERTEX
:
2781 case WINED3D_SHADER_TYPE_HULL
:
2785 case WINED3D_SHADER_TYPE_DOMAIN
:
2789 case WINED3D_SHADER_TYPE_GEOMETRY
:
2793 case WINED3D_SHADER_TYPE_PIXEL
:
2797 case WINED3D_SHADER_TYPE_COMPUTE
:
2802 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2803 type_prefix
= "unknown";
2807 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2809 while (!fe
->shader_is_end(fe_data
, &ptr
))
2811 struct wined3d_shader_instruction ins
;
2813 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2814 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2816 WARN("Skipping unrecognized instruction.\n");
2817 shader_addline(&buffer
, "<unrecognized instruction>\n");
2821 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2823 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, ins
.flags
, &shader_version
);
2824 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2825 shader_addline(&buffer
, " ");
2826 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2828 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2830 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2831 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2832 shader_addline(&buffer
, ", %s",
2833 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2835 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2837 shader_addline(&buffer
, "%s fb%u",
2838 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2840 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2842 shader_addline(&buffer
, "%s ft%u = {...}",
2843 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2845 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2847 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2848 shader_dump_global_flags(&buffer
, ins
.flags
);
2850 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2852 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2853 ins
.declaration
.max_tessellation_factor
);
2855 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2857 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2858 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2860 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2861 ins
.declaration
.icb
->data
[4 * i
+ 0],
2862 ins
.declaration
.icb
->data
[4 * i
+ 1],
2863 ins
.declaration
.icb
->data
[4 * i
+ 2],
2864 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2866 shader_addline(&buffer
, "}");
2868 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEX_RANGE
)
2870 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2871 shader_dump_dst_param(&buffer
, &ins
.declaration
.index_range
.first_register
, &shader_version
);
2872 shader_addline(&buffer
, " %u", ins
.declaration
.index_range
.last_register
);
2874 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2876 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2877 ins
.declaration
.indexable_temp
.register_idx
,
2878 ins
.declaration
.indexable_temp
.register_size
,
2879 ins
.declaration
.indexable_temp
.component_count
);
2881 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2883 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2884 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2885 shader_addline(&buffer
, " ");
2886 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2888 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2889 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2890 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2891 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2893 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2894 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2895 shader_addline(&buffer
, ", ");
2896 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2898 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2900 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2901 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2902 shader_addline(&buffer
, " ");
2903 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2904 shader_addline(&buffer
, ", ");
2905 shader_dump_shader_input_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2907 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2908 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2910 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2911 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2913 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2914 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2916 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2917 shader_dump_primitive_type(&buffer
, &ins
.declaration
.primitive_type
);
2919 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2921 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2922 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2923 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2925 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2927 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2928 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2930 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2932 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2933 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2934 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2936 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2938 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2939 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2940 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2941 shader_addline(&buffer
, ", comparisonMode");
2943 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2944 || ins
.handler_idx
== WINED3DSIH_DCL_GS_INSTANCES
2945 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2946 || ins
.handler_idx
== WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
2947 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2948 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
2949 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
2951 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2953 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2955 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2956 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2958 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2960 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2961 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2963 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2965 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2966 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2968 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2970 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2971 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2972 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2974 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2976 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2977 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2978 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2979 ins
.declaration
.tgsm_structured
.structure_count
);
2981 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2983 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2984 ins
.declaration
.thread_group_size
.x
,
2985 ins
.declaration
.thread_group_size
.y
,
2986 ins
.declaration
.thread_group_size
.z
);
2988 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2990 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2991 shader_dump_uav_flags(&buffer
, ins
.flags
);
2992 shader_addline(&buffer
, " ");
2993 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2995 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2997 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2998 shader_dump_uav_flags(&buffer
, ins
.flags
);
2999 shader_addline(&buffer
, " ");
3000 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
3001 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
3003 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
3005 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
3006 ins
.dst
[0].reg
.idx
[0].offset
),
3007 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
3008 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
3009 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
3010 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
3012 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
3014 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
3015 ins
.src
[0].reg
.u
.immconst_data
[0],
3016 ins
.src
[0].reg
.u
.immconst_data
[1],
3017 ins
.src
[0].reg
.u
.immconst_data
[2],
3018 ins
.src
[0].reg
.u
.immconst_data
[3]);
3020 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
3022 shader_addline(&buffer
, "defb b%u = %s",
3023 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
3029 shader_addline(&buffer
, "(");
3030 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
3031 shader_addline(&buffer
, ") ");
3034 /* PixWin marks instructions with the coissue flag with a '+' */
3036 shader_addline(&buffer
, "+");
3038 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
3040 if (ins
.handler_idx
== WINED3DSIH_BREAKP
3041 || ins
.handler_idx
== WINED3DSIH_CONTINUEP
3042 || ins
.handler_idx
== WINED3DSIH_IF
3043 || ins
.handler_idx
== WINED3DSIH_RETP
3044 || ins
.handler_idx
== WINED3DSIH_TEXKILL
)
3048 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
3049 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
3050 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
3053 else if (ins
.handler_idx
== WINED3DSIH_IFC
3054 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
3058 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
3059 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
3060 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
3061 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
3062 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
3063 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
3064 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
3067 else if (ins
.handler_idx
== WINED3DSIH_TEX
3068 && shader_version
.major
>= 2
3069 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
3071 shader_addline(&buffer
, "p");
3073 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
3077 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
3078 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3079 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3082 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
3086 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
3087 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
3090 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
3092 shader_dump_sync_flags(&buffer
, ins
.flags
);
3096 shader_dump_precise_flags(&buffer
, ins
.flags
);
3099 if (wined3d_shader_instruction_has_texel_offset(&ins
))
3100 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
3102 if (ins
.resource_type
!= WINED3D_SHADER_RESOURCE_NONE
)
3104 shader_addline(&buffer
, "(");
3105 shader_dump_resource_type(&buffer
, ins
.resource_type
);
3106 shader_addline(&buffer
, ")");
3109 if (ins
.resource_data_type
!= WINED3D_DATA_FLOAT
)
3110 shader_dump_data_type(&buffer
, ins
.resource_data_type
);
3112 for (i
= 0; i
< ins
.dst_count
; ++i
)
3114 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
3115 shader_addline(&buffer
, !i
? " " : ", ");
3116 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
3119 /* Other source tokens */
3120 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
3122 shader_addline(&buffer
, !i
? " " : ", ");
3123 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
3126 shader_addline(&buffer
, "\n");
3129 for (p
= buffer
.buffer
; *p
; p
= q
)
3131 if (!(q
= strstr(p
, "\n")))
3135 TRACE(" %.*s", (int)(q
- p
), p
);
3138 string_buffer_free(&buffer
);
3141 static void shader_cleanup(struct wined3d_shader
*shader
)
3143 if (shader
->reg_maps
.shader_version
.type
== WINED3D_SHADER_TYPE_HULL
)
3145 heap_free(shader
->u
.hs
.phases
.control_point
);
3146 heap_free(shader
->u
.hs
.phases
.fork
);
3147 heap_free(shader
->u
.hs
.phases
.join
);
3150 heap_free(shader
->patch_constant_signature
.elements
);
3151 heap_free(shader
->output_signature
.elements
);
3152 heap_free(shader
->input_signature
.elements
);
3153 shader
->device
->shader_backend
->shader_destroy(shader
);
3154 shader_cleanup_reg_maps(&shader
->reg_maps
);
3155 heap_free(shader
->byte_code
);
3156 shader_delete_constant_list(&shader
->constantsF
);
3157 shader_delete_constant_list(&shader
->constantsB
);
3158 shader_delete_constant_list(&shader
->constantsI
);
3159 list_remove(&shader
->shader_list_entry
);
3161 if (shader
->frontend
&& shader
->frontend_data
)
3162 shader
->frontend
->shader_free(shader
->frontend_data
);
3165 struct shader_none_priv
3167 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
3168 const struct wined3d_fragment_pipe_ops
*fragment_pipe
;
3169 BOOL ffp_proj_control
;
3172 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
3173 static void shader_none_precompile(void *shader_priv
, struct wined3d_shader
*shader
) {}
3174 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
3175 const struct wined3d_state
*state
) {}
3176 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3177 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
3178 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
3179 const struct wined3d_state
*state
) {}
3180 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
3181 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
3182 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
3184 /* Context activation is done by the caller. */
3185 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
3186 const struct wined3d_state
*state
)
3188 struct shader_none_priv
*priv
= shader_priv
;
3190 priv
->vertex_pipe
->vp_enable(context
, !use_vs(state
));
3191 priv
->fragment_pipe
->fp_enable(context
, !use_ps(state
));
3194 /* Context activation is done by the caller. */
3195 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
3197 struct shader_none_priv
*priv
= shader_priv
;
3199 priv
->vertex_pipe
->vp_enable(context
, FALSE
);
3200 priv
->fragment_pipe
->fp_enable(context
, FALSE
);
3202 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
3203 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
3204 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
3205 | (1u << WINED3D_SHADER_TYPE_HULL
)
3206 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
3207 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
3210 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
3211 const struct wined3d_fragment_pipe_ops
*fragment_pipe
)
3213 struct fragment_caps fragment_caps
;
3214 void *vertex_priv
, *fragment_priv
;
3215 struct shader_none_priv
*priv
;
3217 if (!(priv
= heap_alloc(sizeof(*priv
))))
3218 return E_OUTOFMEMORY
;
3220 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
3222 ERR("Failed to initialize vertex pipe.\n");
3227 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
3229 ERR("Failed to initialize fragment pipe.\n");
3230 vertex_pipe
->vp_free(device
, NULL
);
3235 priv
->vertex_pipe
= vertex_pipe
;
3236 priv
->fragment_pipe
= fragment_pipe
;
3237 fragment_pipe
->get_caps(device
->adapter
, &fragment_caps
);
3238 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
3240 device
->vertex_priv
= vertex_priv
;
3241 device
->fragment_priv
= fragment_priv
;
3242 device
->shader_priv
= priv
;
3247 static void shader_none_free(struct wined3d_device
*device
, struct wined3d_context
*context
)
3249 struct shader_none_priv
*priv
= device
->shader_priv
;
3251 priv
->fragment_pipe
->free_private(device
, context
);
3252 priv
->vertex_pipe
->vp_free(device
, context
);
3256 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
3261 static void shader_none_get_caps(const struct wined3d_adapter
*adapter
, struct shader_caps
*caps
)
3263 /* Set the shader caps to 0 for the none shader backend */
3264 memset(caps
, 0, sizeof(*caps
));
3267 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
3269 /* We "support" every possible fixup, since we don't support any shader
3270 * model, and will never have to actually sample a texture. */
3274 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
3276 struct shader_none_priv
*priv
= shader_priv
;
3278 return priv
->ffp_proj_control
;
3281 static uint64_t shader_none_shader_compile(struct wined3d_context
*context
, const struct wined3d_shader_desc
*shader_desc
,
3282 enum wined3d_shader_type shader_type
)
3287 const struct wined3d_shader_backend_ops none_shader_backend
=
3289 shader_none_handle_instruction
,
3290 shader_none_precompile
,
3292 shader_none_select_compute
,
3293 shader_none_disable
,
3294 shader_none_update_float_vertex_constants
,
3295 shader_none_update_float_pixel_constants
,
3296 shader_none_load_constants
,
3297 shader_none_destroy
,
3300 shader_none_allocate_context_data
,
3301 shader_none_free_context_data
,
3302 shader_none_init_context_state
,
3303 shader_none_get_caps
,
3304 shader_none_color_fixup_supported
,
3305 shader_none_has_ffp_proj_control
,
3306 shader_none_shader_compile
,
3309 static unsigned int shader_max_version_from_feature_level(enum wined3d_feature_level level
)
3313 case WINED3D_FEATURE_LEVEL_11_1
:
3314 case WINED3D_FEATURE_LEVEL_11
:
3316 case WINED3D_FEATURE_LEVEL_10_1
:
3317 case WINED3D_FEATURE_LEVEL_10
:
3319 case WINED3D_FEATURE_LEVEL_9_3
:
3321 case WINED3D_FEATURE_LEVEL_9_2
:
3322 case WINED3D_FEATURE_LEVEL_9_1
:
3329 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3330 enum wined3d_shader_type type
, unsigned int float_const_count
)
3332 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
3333 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3334 const struct wined3d_shader_version
*version
= ®_maps
->shader_version
;
3335 const struct wined3d_shader_frontend
*fe
;
3336 unsigned int backend_version
;
3339 TRACE("shader %p, device %p, type %s, float_const_count %u.\n",
3340 shader
, device
, debug_shader_type(type
), float_const_count
);
3342 fe
= shader
->frontend
;
3343 if (!(shader
->frontend_data
= fe
->shader_init(shader
->function
,
3344 shader
->functionLength
, &shader
->output_signature
)))
3346 FIXME("Failed to initialize frontend.\n");
3347 return WINED3DERR_INVALIDCALL
;
3350 /* First pass: trace shader. */
3351 if (TRACE_ON(d3d_shader
))
3352 shader_trace_init(fe
, shader
->frontend_data
);
3354 /* Second pass: figure out which registers are used, what the semantics are, etc. */
3355 if (FAILED(hr
= shader_get_registers_used(shader
, float_const_count
)))
3358 if (version
->type
!= type
)
3360 WARN("Wrong shader type %s.\n", debug_shader_type(reg_maps
->shader_version
.type
));
3361 return WINED3DERR_INVALIDCALL
;
3363 if (version
->major
> shader_max_version_from_feature_level(device
->cs
->c
.state
->feature_level
))
3365 WARN("Shader version %u not supported by this device.\n", version
->major
);
3366 return WINED3DERR_INVALIDCALL
;
3370 case WINED3D_SHADER_TYPE_VERTEX
:
3371 backend_version
= d3d_info
->limits
.vs_version
;
3373 case WINED3D_SHADER_TYPE_HULL
:
3374 backend_version
= d3d_info
->limits
.hs_version
;
3376 case WINED3D_SHADER_TYPE_DOMAIN
:
3377 backend_version
= d3d_info
->limits
.ds_version
;
3379 case WINED3D_SHADER_TYPE_GEOMETRY
:
3380 backend_version
= d3d_info
->limits
.gs_version
;
3382 case WINED3D_SHADER_TYPE_PIXEL
:
3383 backend_version
= d3d_info
->limits
.ps_version
;
3385 case WINED3D_SHADER_TYPE_COMPUTE
:
3386 backend_version
= d3d_info
->limits
.cs_version
;
3389 FIXME("No backend version-checking for this shader type.\n");
3390 backend_version
= 0;
3392 if (version
->major
> backend_version
)
3394 WARN("Shader version %u.%u not supported by the current shader backend.\n",
3395 version
->major
, version
->minor
);
3396 return WINED3DERR_INVALIDCALL
;
3399 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3404 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
3406 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
3408 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
3413 static void wined3d_shader_init_object(void *object
)
3415 struct wined3d_shader
*shader
= object
;
3416 struct wined3d_device
*device
= shader
->device
;
3418 TRACE("shader %p.\n", shader
);
3420 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3422 device
->shader_backend
->shader_precompile(device
->shader_priv
, shader
);
3425 static void wined3d_shader_destroy_object(void *object
)
3427 TRACE("object %p.\n", object
);
3429 shader_cleanup(object
);
3433 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
3435 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
3437 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
3441 wined3d_mutex_lock();
3442 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
3443 wined3d_cs_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
3444 wined3d_mutex_unlock();
3450 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
3452 TRACE("shader %p.\n", shader
);
3454 return shader
->parent
;
3457 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
3458 void *byte_code
, UINT
*byte_code_size
)
3460 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
3464 *byte_code_size
= shader
->byte_code_size
;
3468 if (*byte_code_size
< shader
->byte_code_size
)
3470 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
3471 * than the required size we should write the required size and
3472 * return D3DERR_MOREDATA. That's not actually true. */
3473 return WINED3DERR_INVALIDCALL
;
3476 memcpy(byte_code
, shader
->byte_code
, shader
->byte_code_size
);
3481 /* Set local constants for d3d8 shaders. */
3482 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
3483 UINT start_idx
, const float *src_data
, UINT count
)
3485 UINT end_idx
= start_idx
+ count
;
3488 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
3490 if (end_idx
> shader
->limits
->constant_float
)
3492 WARN("end_idx %u > float constants limit %u.\n",
3493 end_idx
, shader
->limits
->constant_float
);
3494 end_idx
= shader
->limits
->constant_float
;
3497 for (i
= start_idx
; i
< end_idx
; ++i
)
3499 struct wined3d_shader_lconst
*lconst
;
3502 if (!(lconst
= heap_alloc(sizeof(*lconst
))))
3503 return E_OUTOFMEMORY
;
3506 value
= (float *)lconst
->value
;
3507 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3508 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3510 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3511 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3513 shader
->lconst_inf_or_nan
= TRUE
;
3520 static void init_interpolation_compile_args(DWORD
*interpolation_args
,
3521 const struct wined3d_shader
*pixel_shader
, const struct wined3d_d3d_info
*d3d_info
)
3523 if (!d3d_info
->shader_output_interpolation
|| !pixel_shader
3524 || pixel_shader
->reg_maps
.shader_version
.major
< 4)
3526 memset(interpolation_args
, 0, sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3530 memcpy(interpolation_args
, pixel_shader
->u
.ps
.interpolation_mode
,
3531 sizeof(pixel_shader
->u
.ps
.interpolation_mode
));
3534 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3535 struct vs_compile_args
*args
, const struct wined3d_context
*context
)
3537 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3538 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3539 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3540 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3541 WORD swizzle_map
= context
->stream_info
.swizzle_map
;
3543 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3544 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3545 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3546 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3547 args
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
3548 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3549 args
->next_shader_type
= hull_shader
? WINED3D_SHADER_TYPE_HULL
3550 : geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3551 if (shader
->reg_maps
.shader_version
.major
>= 4)
3552 args
->next_shader_input_count
= hull_shader
? hull_shader
->limits
->packed_input
3553 : geometry_shader
? geometry_shader
->limits
->packed_input
3554 : pixel_shader
? pixel_shader
->limits
->packed_input
: 0;
3556 args
->next_shader_input_count
= 0;
3557 args
->swizzle_map
= swizzle_map
;
3558 if (d3d_info
->emulated_flatshading
)
3559 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3561 args
->flatshading
= 0;
3563 init_interpolation_compile_args(args
->interpolation_mode
,
3564 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, d3d_info
);
3567 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3569 if (usage_idx1
!= usage_idx2
)
3571 if (usage1
== usage2
)
3573 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3575 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3581 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3582 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3584 WORD map
= shader
->reg_maps
.input_registers
;
3587 for (i
= 0; map
; map
>>= 1, ++i
)
3589 if (!(map
& 1)) continue;
3591 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3592 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3601 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3602 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3606 TRACE("byte_code %p, byte_code_size %#lx.\n", desc
->byte_code
, (long)desc
->byte_code_size
);
3608 if (!desc
->byte_code
)
3609 return WINED3DERR_INVALIDCALL
;
3612 shader
->device
= device
;
3613 shader
->parent
= parent
;
3614 shader
->parent_ops
= parent_ops
;
3616 list_init(&shader
->linked_programs
);
3617 list_init(&shader
->constantsF
);
3618 list_init(&shader
->constantsB
);
3619 list_init(&shader
->constantsI
);
3620 shader
->lconst_inf_or_nan
= FALSE
;
3621 list_init(&shader
->reg_maps
.indexable_temps
);
3622 list_init(&shader
->shader_list_entry
);
3624 if (desc
->byte_code_size
== ~(size_t)0)
3626 struct wined3d_shader_version shader_version
;
3627 const struct wined3d_shader_frontend
*fe
;
3628 struct wined3d_shader_instruction ins
;
3632 if (!(shader
->frontend
= shader_select_frontend(WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
)))
3634 FIXME("Unable to find frontend for shader.\n");
3635 hr
= WINED3DERR_INVALIDCALL
;
3639 fe
= shader
->frontend
;
3640 if (!(fe_data
= fe
->shader_init(desc
->byte_code
, desc
->byte_code_size
, &shader
->output_signature
)))
3642 WARN("Failed to initialise frontend data.\n");
3643 hr
= WINED3DERR_INVALIDCALL
;
3647 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3648 while (!fe
->shader_is_end(fe_data
, &ptr
))
3649 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
3651 fe
->shader_free(fe_data
);
3653 shader
->byte_code_size
= (ptr
- desc
->byte_code
) * sizeof(*ptr
);
3655 if (!(shader
->byte_code
= heap_alloc(shader
->byte_code_size
)))
3660 memcpy(shader
->byte_code
, desc
->byte_code
, shader
->byte_code_size
);
3662 shader
->function
= shader
->byte_code
;
3663 shader
->functionLength
= shader
->byte_code_size
;
3667 enum wined3d_shader_byte_code_format format
;
3668 unsigned int max_version
;
3670 if (!(shader
->byte_code
= heap_alloc(desc
->byte_code_size
)))
3675 memcpy(shader
->byte_code
, desc
->byte_code
, desc
->byte_code_size
);
3676 shader
->byte_code_size
= desc
->byte_code_size
;
3678 max_version
= shader_max_version_from_feature_level(device
->cs
->c
.state
->feature_level
);
3679 if (FAILED(hr
= shader_extract_from_dxbc(shader
, max_version
, &format
)))
3682 if (!(shader
->frontend
= shader_select_frontend(format
)))
3684 FIXME("Unable to find frontend for shader.\n");
3685 hr
= WINED3DERR_INVALIDCALL
;
3693 shader_cleanup(shader
);
3697 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3698 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3700 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3704 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
3707 if (FAILED(hr
= shader_set_function(shader
, device
,
3708 WINED3D_SHADER_TYPE_VERTEX
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
)))
3710 shader_cleanup(shader
);
3714 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3716 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3718 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3721 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3722 shader_usage_from_semantic_name(input
->semantic_name
);
3723 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3726 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3727 shader
->load_local_constsF
= TRUE
;
3732 static struct wined3d_shader_signature_element
*shader_find_signature_element(const struct wined3d_shader_signature
*s
,
3733 unsigned int stream_idx
, const char *semantic_name
, unsigned int semantic_idx
)
3735 struct wined3d_shader_signature_element
*e
= s
->elements
;
3738 for (i
= 0; i
< s
->element_count
; ++i
)
3740 if (e
[i
].stream_idx
== stream_idx
3741 && !_strnicmp(e
[i
].semantic_name
, semantic_name
, -1)
3742 && e
[i
].semantic_idx
== semantic_idx
)
3749 BOOL
shader_get_stream_output_register_info(const struct wined3d_shader
*shader
,
3750 const struct wined3d_stream_output_element
*so_element
, unsigned int *register_idx
, unsigned int *component_idx
)
3752 const struct wined3d_shader_signature_element
*output
;
3755 if (!(output
= shader_find_signature_element(&shader
->output_signature
,
3756 so_element
->stream_idx
, so_element
->semantic_name
, so_element
->semantic_idx
)))
3759 for (idx
= 0; idx
< 4; ++idx
)
3761 if (output
->mask
& (1u << idx
))
3764 idx
+= so_element
->component_idx
;
3766 *register_idx
= output
->register_idx
;
3767 *component_idx
= idx
;
3771 static HRESULT
geometry_shader_init_so_desc(struct wined3d_geometry_shader
*gs
, struct wined3d_device
*device
,
3772 const struct wined3d_stream_output_desc
*so_desc
)
3774 struct wined3d_so_desc_entry
*s
;
3775 struct wine_rb_entry
*entry
;
3780 if ((entry
= wine_rb_get(&device
->so_descs
, so_desc
)))
3782 gs
->so_desc
= &WINE_RB_ENTRY_VALUE(entry
, struct wined3d_so_desc_entry
, entry
)->desc
;
3786 size
= FIELD_OFFSET(struct wined3d_so_desc_entry
, elements
[so_desc
->element_count
]);
3787 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3789 const char *n
= so_desc
->elements
[i
].semantic_name
;
3792 size
+= strlen(n
) + 1;
3794 if (!(s
= heap_alloc(size
)))
3795 return E_OUTOFMEMORY
;
3799 memcpy(s
->elements
, so_desc
->elements
, so_desc
->element_count
* sizeof(*s
->elements
));
3800 s
->desc
.elements
= s
->elements
;
3802 name
= (char *)&s
->elements
[s
->desc
.element_count
];
3803 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3805 struct wined3d_stream_output_element
*e
= &s
->elements
[i
];
3807 if (!e
->semantic_name
)
3810 size
= strlen(e
->semantic_name
) + 1;
3811 memcpy(name
, e
->semantic_name
, size
);
3812 e
->semantic_name
= name
;
3816 if (wine_rb_put(&device
->so_descs
, &s
->desc
, &s
->entry
) == -1)
3821 gs
->so_desc
= &s
->desc
;
3826 static HRESULT
geometry_shader_init_stream_output(struct wined3d_shader
*shader
,
3827 const struct wined3d_stream_output_desc
*so_desc
)
3829 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
3830 const struct wined3d_shader_signature_element
*output
;
3831 unsigned int i
, component_idx
, register_idx
, mask
;
3832 struct wined3d_shader_version shader_version
;
3840 if (!(fe_data
= fe
->shader_init(shader
->function
, shader
->functionLength
, &shader
->output_signature
)))
3842 WARN("Failed to initialise frontend data.\n");
3843 return WINED3DERR_INVALIDCALL
;
3845 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3846 fe
->shader_free(fe_data
);
3848 switch (shader_version
.type
)
3850 case WINED3D_SHADER_TYPE_VERTEX
:
3851 case WINED3D_SHADER_TYPE_DOMAIN
:
3852 shader
->function
= NULL
;
3853 shader
->functionLength
= 0;
3855 case WINED3D_SHADER_TYPE_GEOMETRY
:
3858 WARN("Wrong shader type %s.\n", debug_shader_type(shader_version
.type
));
3859 return E_INVALIDARG
;
3862 if (!shader
->function
)
3864 shader
->reg_maps
.shader_version
= shader_version
;
3865 shader
->reg_maps
.shader_version
.type
= WINED3D_SHADER_TYPE_GEOMETRY
;
3866 shader_set_limits(shader
);
3867 if (FAILED(hr
= shader_scan_output_signature(shader
)))
3871 for (i
= 0; i
< so_desc
->element_count
; ++i
)
3873 const struct wined3d_stream_output_element
*e
= &so_desc
->elements
[i
];
3875 if (!e
->semantic_name
)
3877 if (!(output
= shader_find_signature_element(&shader
->output_signature
,
3878 e
->stream_idx
, e
->semantic_name
, e
->semantic_idx
))
3879 || !shader_get_stream_output_register_info(shader
, e
, ®ister_idx
, &component_idx
))
3881 WARN("Failed to find output signature element for stream output entry.\n");
3882 return E_INVALIDARG
;
3885 mask
= wined3d_mask_from_size(e
->component_count
) << component_idx
;
3886 if ((output
->mask
& 0xff & mask
) != mask
)
3888 WARN("Invalid component range %u-%u (mask %#x), output mask %#x.\n",
3889 component_idx
, e
->component_count
, mask
, output
->mask
& 0xff);
3890 return E_INVALIDARG
;
3894 if (FAILED(hr
= geometry_shader_init_so_desc(&shader
->u
.gs
, shader
->device
, so_desc
)))
3896 WARN("Failed to initialise stream output description, hr %#x.\n", hr
);
3903 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3904 const struct wined3d_shader_desc
*desc
, const struct wined3d_stream_output_desc
*so_desc
,
3905 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3909 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
3912 if (FAILED(hr
= geometry_shader_init_stream_output(shader
, so_desc
)))
3915 if (shader
->function
3916 && FAILED(hr
= shader_set_function(shader
, device
, WINED3D_SHADER_TYPE_GEOMETRY
, 0)))
3922 shader_cleanup(shader
);
3926 void find_ds_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3927 struct ds_compile_args
*args
, const struct wined3d_context
*context
)
3929 const struct wined3d_shader
*geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
];
3930 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3931 const struct wined3d_shader
*hull_shader
= state
->shader
[WINED3D_SHADER_TYPE_HULL
];
3933 args
->tessellator_output_primitive
= hull_shader
->u
.hs
.tessellator_output_primitive
;
3934 args
->tessellator_partitioning
= hull_shader
->u
.hs
.tessellator_partitioning
;
3936 args
->output_count
= geometry_shader
? geometry_shader
->limits
->packed_input
3937 : pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3938 args
->next_shader_type
= geometry_shader
? WINED3D_SHADER_TYPE_GEOMETRY
: WINED3D_SHADER_TYPE_PIXEL
;
3940 args
->render_offscreen
= context
->render_offscreen
;
3942 init_interpolation_compile_args(args
->interpolation_mode
,
3943 args
->next_shader_type
== WINED3D_SHADER_TYPE_PIXEL
? pixel_shader
: NULL
, context
->d3d_info
);
3948 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3949 struct gs_compile_args
*args
, const struct wined3d_context
*context
)
3951 const struct wined3d_shader
*pixel_shader
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
];
3953 args
->output_count
= pixel_shader
? pixel_shader
->limits
->packed_input
: shader
->limits
->packed_output
;
3955 if (!(args
->primitive_type
= shader
->u
.gs
.input_type
))
3956 args
->primitive_type
= state
->primitive_type
;
3958 init_interpolation_compile_args(args
->interpolation_mode
, pixel_shader
, context
->d3d_info
);
3961 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3962 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3964 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3965 struct wined3d_texture
*texture
;
3968 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3969 if (!d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
))
3971 static unsigned int warned
= 0;
3973 args
->srgb_correction
= 1;
3974 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
&& !warned
++)
3975 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3976 "support, expect rendering artifacts.\n");
3979 if (shader
->reg_maps
.shader_version
.major
== 1
3980 && shader
->reg_maps
.shader_version
.minor
<= 3)
3982 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3984 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3986 if (flags
& WINED3D_TTFF_PROJECTED
)
3988 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3990 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3992 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3994 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3995 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3997 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3999 struct wined3d_vertex_declaration_element
*element
=
4000 &state
->vertex_declaration
->elements
[j
];
4002 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
4003 && element
->usage_idx
== index
)
4005 max_valid
= element
->format
->component_count
;
4009 if (!tex_transform
|| tex_transform
> max_valid
)
4011 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
4012 tex_transform
, max_valid
);
4013 tex_transform
= max_valid
;
4015 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
4016 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
4017 && tex_transform
> WINED3D_TTFF_COUNT2
)
4018 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
4019 && tex_transform
> WINED3D_TTFF_COUNT3
))
4020 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
4023 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
4024 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
4025 i
, tex_transform
, resource_type
);
4029 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
4031 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
4035 if (shader
->reg_maps
.shader_version
.major
== 1
4036 && shader
->reg_maps
.shader_version
.minor
<= 4)
4038 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4040 if (!shader
->reg_maps
.resource_info
[i
].type
)
4043 /* Treat unbound textures as 2D. The dummy texture will provide
4044 * the proper sample value. The tex_types bitmap defaults to
4045 * 2D because of the memset. */
4046 if (!(texture
= state
->textures
[i
]))
4049 switch (wined3d_texture_gl(texture
)->target
)
4051 /* RECT textures are distinguished from 2D textures via np2_fixup */
4056 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4059 case GL_TEXTURE_CUBE_MAP_ARB
:
4060 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4065 else if (shader
->reg_maps
.shader_version
.major
<= 3)
4067 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
4069 enum wined3d_shader_resource_type resource_type
;
4070 enum wined3d_shader_tex_types tex_type
;
4072 if (!(resource_type
= shader
->reg_maps
.resource_info
[i
].type
))
4075 switch (resource_type
)
4077 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
4078 tex_type
= WINED3D_SHADER_TEX_3D
;
4080 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
4081 tex_type
= WINED3D_SHADER_TEX_CUBE
;
4084 tex_type
= WINED3D_SHADER_TEX_2D
;
4088 if ((texture
= state
->textures
[i
]))
4090 if (texture
->resource
.type
== WINED3D_RTYPE_TEXTURE_2D
4091 && resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
4092 && !(texture
->resource
.usage
& WINED3DUSAGE_LEGACY_CUBEMAP
))
4093 tex_type
= WINED3D_SHADER_TEX_2D
;
4094 else if (texture
->resource
.type
== WINED3D_RTYPE_TEXTURE_3D
4095 && resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
)
4096 tex_type
= WINED3D_SHADER_TEX_3D
;
4098 args
->tex_types
|= tex_type
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
4102 if (shader
->reg_maps
.shader_version
.major
>= 4)
4104 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
4106 for (i
= 0 ; i
< WINED3D_MAX_FRAGMENT_SAMPLERS
; ++i
)
4107 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4108 args
->np2_fixup
= 0;
4112 for (i
= 0; i
< WINED3D_MAX_FRAGMENT_SAMPLERS
; ++i
)
4114 if (!shader
->reg_maps
.resource_info
[i
].type
)
4117 texture
= state
->textures
[i
];
4120 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4123 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
4124 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
4126 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
4128 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
4129 args
->shadow
|= 1u << i
;
4131 /* Flag samplers that need NP2 texcoord fixup. */
4132 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
4133 args
->np2_fixup
|= (1u << i
);
4137 if (shader
->reg_maps
.shader_version
.major
>= 3)
4139 if (position_transformed
)
4140 args
->vp_mode
= WINED3D_VP_MODE_NONE
;
4141 else if (use_vs(state
))
4142 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
4144 args
->vp_mode
= WINED3D_VP_MODE_FF
;
4145 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4149 args
->vp_mode
= WINED3D_VP_MODE_SHADER
;
4150 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
4152 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
4154 case WINED3D_FOG_NONE
:
4155 if (position_transformed
|| use_vs(state
))
4157 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4161 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
4163 case WINED3D_FOG_NONE
: /* Fall through. */
4164 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
4165 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
4166 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
4170 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
4171 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
4172 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
4177 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4181 if (!d3d_info
->full_ffp_varyings
)
4183 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
4185 args
->texcoords_initialized
= 0;
4186 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
4190 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
4191 args
->texcoords_initialized
|= 1u << i
;
4195 const struct wined3d_stream_info
*si
= &context
->stream_info
;
4196 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4198 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
4199 & WINED3D_FFP_TCI_MASK
4200 || (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
4201 args
->texcoords_initialized
|= 1u << i
;
4207 args
->texcoords_initialized
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
4210 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
4211 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
4213 if (d3d_info
->ffp_alpha_test
)
4214 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
4216 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
4217 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
4218 : WINED3D_CMP_ALWAYS
) - 1;
4220 if (d3d_info
->emulated_flatshading
)
4221 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4223 args
->y_correction
= (shader
->reg_maps
.vpos
&& d3d_info
->frag_coord_correction
)
4224 || (shader
->reg_maps
.usesdsy
&& wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
4225 ? !context
->render_offscreen
: 0;
4227 for (i
= 0; i
< ARRAY_SIZE(state
->fb
.render_targets
); ++i
)
4229 struct wined3d_rendertarget_view
*rtv
= state
->fb
.render_targets
[i
];
4230 if (rtv
&& rtv
->format
->id
== WINED3DFMT_A8_UNORM
&& !is_identity_fixup(rtv
->format
->color_fixup
))
4231 args
->rt_alpha_swizzle
|= 1u << i
;
4234 args
->dual_source_blend
= state
->blend_state
&& state
->blend_state
->dual_source
;
4237 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
4238 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
4240 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
4241 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
4244 if (FAILED(hr
= shader_init(shader
, device
, desc
, parent
, parent_ops
)))
4247 if (FAILED(hr
= shader_set_function(shader
, device
,
4248 WINED3D_SHADER_TYPE_PIXEL
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
)))
4250 shader_cleanup(shader
);
4254 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4256 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4259 highest_reg_used
= i
;
4263 /* Don't do any register mapping magic if it is not needed, or if we can't
4264 * achieve anything anyway */
4265 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
4266 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
4267 || shader
->reg_maps
.shader_version
.major
>= 4)
4269 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
4271 /* This happens with relative addressing. The input mapper function
4272 * warns about this if the higher registers are declared too, so
4273 * don't write a FIXME here */
4274 WARN("More varying registers used than supported\n");
4277 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4279 shader
->u
.ps
.input_reg_map
[i
] = i
;
4282 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
4286 shader
->u
.ps
.declared_in_count
= 0;
4287 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
4289 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
4290 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
4291 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
4298 enum wined3d_shader_resource_type
pixelshader_get_resource_type(const struct wined3d_shader_reg_maps
*reg_maps
,
4299 unsigned int resource_idx
, DWORD tex_types
)
4301 static enum wined3d_shader_resource_type shader_resource_type_from_shader_tex_types
[] =
4303 WINED3D_SHADER_RESOURCE_TEXTURE_2D
, /* WINED3D_SHADER_TEX_2D */
4304 WINED3D_SHADER_RESOURCE_TEXTURE_3D
, /* WINED3D_SHADER_TEX_3D */
4305 WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
, /* WINED3D_SHADER_TEX_CUBE */
4310 if (reg_maps
->shader_version
.major
> 3)
4311 return reg_maps
->resource_info
[resource_idx
].type
;
4313 if (!reg_maps
->resource_info
[resource_idx
].type
)
4316 idx
= (tex_types
>> resource_idx
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
;
4317 assert(idx
< ARRAY_SIZE(shader_resource_type_from_shader_tex_types
));
4318 return shader_resource_type_from_shader_tex_types
[idx
];
4321 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4322 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4324 struct wined3d_shader
*object
;
4327 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4328 device
, desc
, parent
, parent_ops
, shader
);
4330 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4331 return E_OUTOFMEMORY
;
4333 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4335 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
4340 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_COMPUTE
, 0)))
4342 shader_cleanup(object
);
4347 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4349 TRACE("Created compute shader %p.\n", object
);
4355 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4356 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4358 struct wined3d_shader
*object
;
4361 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4362 device
, desc
, parent
, parent_ops
, shader
);
4364 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4365 return E_OUTOFMEMORY
;
4367 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4369 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
4374 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_DOMAIN
, 0)))
4376 shader_cleanup(object
);
4381 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4383 TRACE("Created domain shader %p.\n", object
);
4389 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4390 const struct wined3d_stream_output_desc
*so_desc
, void *parent
,
4391 const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4393 struct wined3d_shader
*object
;
4396 TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
4397 device
, desc
, so_desc
, parent
, parent_ops
, shader
);
4399 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4400 return E_OUTOFMEMORY
;
4402 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, so_desc
, parent
, parent_ops
)))
4404 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
4409 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4411 TRACE("Created geometry shader %p.\n", object
);
4417 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4418 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4420 struct wined3d_shader
*object
;
4423 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4424 device
, desc
, parent
, parent_ops
, shader
);
4426 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4427 return E_OUTOFMEMORY
;
4429 if (FAILED(hr
= shader_init(object
, device
, desc
, parent
, parent_ops
)))
4431 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
4436 if (FAILED(hr
= shader_set_function(object
, device
, WINED3D_SHADER_TYPE_HULL
, 0)))
4438 shader_cleanup(object
);
4443 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4445 TRACE("Created hull shader %p.\n", object
);
4451 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4452 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4454 struct wined3d_shader
*object
;
4457 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4458 device
, desc
, parent
, parent_ops
, shader
);
4460 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4461 return E_OUTOFMEMORY
;
4463 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4465 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
4470 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4472 TRACE("Created pixel shader %p.\n", object
);
4478 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
4479 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
4481 struct wined3d_shader
*object
;
4484 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
4485 device
, desc
, parent
, parent_ops
, shader
);
4487 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4488 return E_OUTOFMEMORY
;
4490 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
4492 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
4497 wined3d_cs_init_object(device
->cs
, wined3d_shader_init_object
, object
);
4499 TRACE("Created vertex shader %p.\n", object
);