2 * Copyright 2002-2003 Jason Edmeades
3 * Copyright 2002-2003 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2006 Ivan Gyurdiev
7 * Copyright 2007-2008, 2013 Stefan Dösinger for CodeWeavers
8 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #include "wined3d_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
36 /* pow, mul_high, sub_high, mul_low */
37 const float wined3d_srgb_const0
[] = {0.41666f
, 1.055f
, 0.055f
, 12.92f
};
39 const float wined3d_srgb_const1
[] = {0.0031308f
, 0.0f
, 0.0f
, 0.0f
};
41 static const char * const shader_opcode_names
[] =
43 /* WINED3DSIH_ABS */ "abs",
44 /* WINED3DSIH_ADD */ "add",
45 /* WINED3DSIH_AND */ "and",
46 /* WINED3DSIH_ATOMIC_AND */ "atomic_and",
47 /* WINED3DSIH_ATOMIC_CMP_STORE */ "atomic_cmp_store",
48 /* WINED3DSIH_ATOMIC_IADD */ "atomic_iadd",
49 /* WINED3DSIH_ATOMIC_IMAX */ "atomic_imax",
50 /* WINED3DSIH_ATOMIC_IMIN */ "atomic_imin",
51 /* WINED3DSIH_ATOMIC_OR */ "atomic_or",
52 /* WINED3DSIH_ATOMIC_UMAX */ "atomic_umax",
53 /* WINED3DSIH_ATOMIC_UMIN */ "atomic_umin",
54 /* WINED3DSIH_ATOMIC_XOR */ "atomic_xor",
55 /* WINED3DSIH_BEM */ "bem",
56 /* WINED3DSIH_BFI */ "bfi",
57 /* WINED3DSIH_BFREV */ "bfrev",
58 /* WINED3DSIH_BREAK */ "break",
59 /* WINED3DSIH_BREAKC */ "breakc",
60 /* WINED3DSIH_BREAKP */ "breakp",
61 /* WINED3DSIH_BUFINFO */ "bufinfo",
62 /* WINED3DSIH_CALL */ "call",
63 /* WINED3DSIH_CALLNZ */ "callnz",
64 /* WINED3DSIH_CASE */ "case",
65 /* WINED3DSIH_CMP */ "cmp",
66 /* WINED3DSIH_CND */ "cnd",
67 /* WINED3DSIH_CONTINUE */ "continue",
68 /* WINED3DSIH_COUNTBITS */ "countbits",
69 /* WINED3DSIH_CRS */ "crs",
70 /* WINED3DSIH_CUT */ "cut",
71 /* WINED3DSIH_CUT_STREAM */ "cut_stream",
72 /* WINED3DSIH_DCL */ "dcl",
73 /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
74 /* WINED3DSIH_DCL_FUNCTION_BODY */ "dcl_function_body",
75 /* WINED3DSIH_DCL_FUNCTION_TABLE */ "dcl_function_table",
76 /* WINED3DSIH_DCL_GLOBAL_FLAGS */ "dcl_globalFlags",
77 /* WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT */ "dcl_hs_fork_phase_instance_count",
78 /* WINED3DSIH_DCL_HS_MAX_TESSFACTOR */ "dcl_hs_max_tessfactor",
79 /* WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER */ "dcl_immediateConstantBuffer",
80 /* WINED3DSIH_DCL_INDEXABLE_TEMP */ "dcl_indexableTemp",
81 /* WINED3DSIH_DCL_INPUT */ "dcl_input",
82 /* WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT */ "dcl_input_control_point_count",
83 /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
84 /* WINED3DSIH_DCL_INPUT_PS */ "dcl_input_ps",
85 /* WINED3DSIH_DCL_INPUT_PS_SGV */ "dcl_input_ps_sgv",
86 /* WINED3DSIH_DCL_INPUT_PS_SIV */ "dcl_input_ps_siv",
87 /* WINED3DSIH_DCL_INPUT_SGV */ "dcl_input_sgv",
88 /* WINED3DSIH_DCL_INPUT_SIV */ "dcl_input_siv",
89 /* WINED3DSIH_DCL_INTERFACE */ "dcl_interface",
90 /* WINED3DSIH_DCL_OUTPUT */ "dcl_output",
91 /* WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT */ "dcl_output_control_point_count",
92 /* WINED3DSIH_DCL_OUTPUT_SIV */ "dcl_output_siv",
93 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
94 /* WINED3DSIH_DCL_RESOURCE_RAW */ "dcl_resource_raw",
95 /* WINED3DSIH_DCL_RESOURCE_STRUCTURED */ "dcl_resource_structured",
96 /* WINED3DSIH_DCL_SAMPLER */ "dcl_sampler",
97 /* WINED3DSIH_DCL_STREAM */ "dcl_stream",
98 /* WINED3DSIH_DCL_TEMPS */ "dcl_temps",
99 /* WINED3DSIH_DCL_TESSELLATOR_DOMAIN */ "dcl_tessellator_domain",
100 /* WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE */ "dcl_tessellator_output_primitive",
101 /* WINED3DSIH_DCL_TESSELLATOR_PARTITIONING */ "dcl_tessellator_partitioning",
102 /* WINED3DSIH_DCL_TGSM_RAW */ "dcl_tgsm_raw",
103 /* WINED3DSIH_DCL_TGSM_STRUCTURED */ "dcl_tgsm_structured",
104 /* WINED3DSIH_DCL_THREAD_GROUP */ "dcl_thread_group",
105 /* WINED3DSIH_DCL_UAV_RAW */ "dcl_uav_raw",
106 /* WINED3DSIH_DCL_UAV_STRUCTURED */ "dcl_uav_structured",
107 /* WINED3DSIH_DCL_UAV_TYPED */ "dcl_uav_typed",
108 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
109 /* WINED3DSIH_DEF */ "def",
110 /* WINED3DSIH_DEFAULT */ "default",
111 /* WINED3DSIH_DEFB */ "defb",
112 /* WINED3DSIH_DEFI */ "defi",
113 /* WINED3DSIH_DIV */ "div",
114 /* WINED3DSIH_DP2 */ "dp2",
115 /* WINED3DSIH_DP2ADD */ "dp2add",
116 /* WINED3DSIH_DP3 */ "dp3",
117 /* WINED3DSIH_DP4 */ "dp4",
118 /* WINED3DSIH_DST */ "dst",
119 /* WINED3DSIH_DSX */ "dsx",
120 /* WINED3DSIH_DSX_COARSE */ "deriv_rtx_coarse",
121 /* WINED3DSIH_DSX_FINE */ "deriv_rtx_fine",
122 /* WINED3DSIH_DSY */ "dsy",
123 /* WINED3DSIH_DSY_COARSE */ "deriv_rty_coarse",
124 /* WINED3DSIH_DSY_FINE */ "deriv_rty_fine",
125 /* WINED3DSIH_ELSE */ "else",
126 /* WINED3DSIH_EMIT */ "emit",
127 /* WINED3DSIH_EMIT_STREAM */ "emit_stream",
128 /* WINED3DSIH_ENDIF */ "endif",
129 /* WINED3DSIH_ENDLOOP */ "endloop",
130 /* WINED3DSIH_ENDREP */ "endrep",
131 /* WINED3DSIH_ENDSWITCH */ "endswitch",
132 /* WINED3DSIH_EQ */ "eq",
133 /* WINED3DSIH_EXP */ "exp",
134 /* WINED3DSIH_EXPP */ "expp",
135 /* WINED3DSIH_F16TOF32 */ "f16tof32",
136 /* WINED3DSIH_F32TOF16 */ "f32tof16",
137 /* WINED3DSIH_FCALL */ "fcall",
138 /* WINED3DSIH_FIRSTBIT_HI */ "firstbit_hi",
139 /* WINED3DSIH_FIRSTBIT_LO */ "firstbit_lo",
140 /* WINED3DSIH_FIRSTBIT_SHI */ "firstbit_shi",
141 /* WINED3DSIH_FRC */ "frc",
142 /* WINED3DSIH_FTOI */ "ftoi",
143 /* WINED3DSIH_FTOU */ "ftou",
144 /* WINED3DSIH_GATHER4 */ "gather4",
145 /* WINED3DSIH_GATHER4_C */ "gather4_c",
146 /* WINED3DSIH_GE */ "ge",
147 /* WINED3DSIH_HS_CONTROL_POINT_PHASE */ "hs_control_point_phase",
148 /* WINED3DSIH_HS_DECLS */ "hs_decls",
149 /* WINED3DSIH_HS_FORK_PHASE */ "hs_fork_phase",
150 /* WINED3DSIH_HS_JOIN_PHASE */ "hs_join_phase",
151 /* WINED3DSIH_IADD */ "iadd",
152 /* WINED3DSIH_IEQ */ "ieq",
153 /* WINED3DSIH_IF */ "if",
154 /* WINED3DSIH_IFC */ "ifc",
155 /* WINED3DSIH_IGE */ "ige",
156 /* WINED3DSIH_ILT */ "ilt",
157 /* WINED3DSIH_IMAD */ "imad",
158 /* WINED3DSIH_IMAX */ "imax",
159 /* WINED3DSIH_IMIN */ "imin",
160 /* WINED3DSIH_IMM_ATOMIC_ALLOC */ "imm_atomic_alloc",
161 /* WINED3DSIH_IMM_ATOMIC_AND */ "imm_atomic_and",
162 /* WINED3DSIH_IMM_ATOMIC_CMP_EXCH */ "imm_atomic_cmp_exch",
163 /* WINED3DSIH_IMM_ATOMIC_CONSUME */ "imm_atomic_consume",
164 /* WINED3DSIH_IMM_ATOMIC_EXCH */ "imm_atomic_exch",
165 /* WINED3DSIH_IMM_ATOMIC_IADD */ "imm_atomic_iadd",
166 /* WINED3DSIH_IMM_ATOMIC_OR */ "imm_atomic_or",
167 /* WINED3DSIH_IMM_ATOMIC_UMAX */ "imm_atomic_umax",
168 /* WINED3DSIH_IMM_ATOMIC_UMIN */ "imm_atomic_umin",
169 /* WINED3DSIH_IMM_ATOMIC_XOR */ "imm_atomic_xor",
170 /* WINED3DSIH_IMUL */ "imul",
171 /* WINED3DSIH_INE */ "ine",
172 /* WINED3DSIH_INEG */ "ineg",
173 /* WINED3DSIH_ISHL */ "ishl",
174 /* WINED3DSIH_ISHR */ "ishr",
175 /* WINED3DSIH_ITOF */ "itof",
176 /* WINED3DSIH_LABEL */ "label",
177 /* WINED3DSIH_LD */ "ld",
178 /* WINED3DSIH_LD2DMS */ "ld2dms",
179 /* WINED3DSIH_LD_RAW */ "ld_raw",
180 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
181 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
182 /* WINED3DSIH_LIT */ "lit",
183 /* WINED3DSIH_LOD */ "lod",
184 /* WINED3DSIH_LOG */ "log",
185 /* WINED3DSIH_LOGP */ "logp",
186 /* WINED3DSIH_LOOP */ "loop",
187 /* WINED3DSIH_LRP */ "lrp",
188 /* WINED3DSIH_LT */ "lt",
189 /* WINED3DSIH_M3x2 */ "m3x2",
190 /* WINED3DSIH_M3x3 */ "m3x3",
191 /* WINED3DSIH_M3x4 */ "m3x4",
192 /* WINED3DSIH_M4x3 */ "m4x3",
193 /* WINED3DSIH_M4x4 */ "m4x4",
194 /* WINED3DSIH_MAD */ "mad",
195 /* WINED3DSIH_MAX */ "max",
196 /* WINED3DSIH_MIN */ "min",
197 /* WINED3DSIH_MOV */ "mov",
198 /* WINED3DSIH_MOVA */ "mova",
199 /* WINED3DSIH_MOVC */ "movc",
200 /* WINED3DSIH_MUL */ "mul",
201 /* WINED3DSIH_NE */ "ne",
202 /* WINED3DSIH_NOP */ "nop",
203 /* WINED3DSIH_NOT */ "not",
204 /* WINED3DSIH_NRM */ "nrm",
205 /* WINED3DSIH_OR */ "or",
206 /* WINED3DSIH_PHASE */ "phase",
207 /* WINED3DSIH_POW */ "pow",
208 /* WINED3DSIH_RCP */ "rcp",
209 /* WINED3DSIH_REP */ "rep",
210 /* WINED3DSIH_RESINFO */ "resinfo",
211 /* WINED3DSIH_RET */ "ret",
212 /* WINED3DSIH_ROUND_NE */ "round_ne",
213 /* WINED3DSIH_ROUND_NI */ "round_ni",
214 /* WINED3DSIH_ROUND_PI */ "round_pi",
215 /* WINED3DSIH_ROUND_Z */ "round_z",
216 /* WINED3DSIH_RSQ */ "rsq",
217 /* WINED3DSIH_SAMPLE */ "sample",
218 /* WINED3DSIH_SAMPLE_B */ "sample_b",
219 /* WINED3DSIH_SAMPLE_C */ "sample_c",
220 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
221 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
222 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
223 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
224 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
225 /* WINED3DSIH_SETP */ "setp",
226 /* WINED3DSIH_SGE */ "sge",
227 /* WINED3DSIH_SGN */ "sgn",
228 /* WINED3DSIH_SINCOS */ "sincos",
229 /* WINED3DSIH_SLT */ "slt",
230 /* WINED3DSIH_SQRT */ "sqrt",
231 /* WINED3DSIH_STORE_RAW */ "store_raw",
232 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
233 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
234 /* WINED3DSIH_SUB */ "sub",
235 /* WINED3DSIH_SWAPC */ "swapc",
236 /* WINED3DSIH_SWITCH */ "switch",
237 /* WINED3DSIH_SYNC */ "sync",
238 /* WINED3DSIH_TEX */ "texld",
239 /* WINED3DSIH_TEXBEM */ "texbem",
240 /* WINED3DSIH_TEXBEML */ "texbeml",
241 /* WINED3DSIH_TEXCOORD */ "texcrd",
242 /* WINED3DSIH_TEXDEPTH */ "texdepth",
243 /* WINED3DSIH_TEXDP3 */ "texdp3",
244 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
245 /* WINED3DSIH_TEXKILL */ "texkill",
246 /* WINED3DSIH_TEXLDD */ "texldd",
247 /* WINED3DSIH_TEXLDL */ "texldl",
248 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
249 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
250 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
251 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
252 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
253 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
254 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
255 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
256 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
257 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
258 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
259 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
260 /* WINED3DSIH_UBFE */ "ubfe",
261 /* WINED3DSIH_UDIV */ "udiv",
262 /* WINED3DSIH_UGE */ "uge",
263 /* WINED3DSIH_ULT */ "ult",
264 /* WINED3DSIH_UMAX */ "umax",
265 /* WINED3DSIH_UMIN */ "umin",
266 /* WINED3DSIH_USHR */ "ushr",
267 /* WINED3DSIH_UTOF */ "utof",
268 /* WINED3DSIH_XOR */ "xor",
271 static const char * const semantic_names
[] =
273 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
274 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
275 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
276 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
277 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
278 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
279 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
280 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
281 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
282 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
283 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
284 /* WINED3D_DECL_USAGE_FOG */ "FOG",
285 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
286 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
291 enum wined3d_sysval_semantic sysval_semantic
;
292 const char *sysval_name
;
294 sysval_semantic_names
[] =
296 {WINED3D_SV_POSITION
, "SV_Position"},
297 {WINED3D_SV_CLIP_DISTANCE
, "SV_ClipDistance"},
298 {WINED3D_SV_CULL_DISTANCE
, "SV_CullDistance"},
299 {WINED3D_SV_RENDER_TARGET_ARRAY_INDEX
, "SV_RenderTargetArrayIndex"},
300 {WINED3D_SV_VIEWPORT_ARRAY_INDEX
, "SV_ViewportArrayIndex"},
301 {WINED3D_SV_VERTEX_ID
, "SV_VertexID"},
302 {WINED3D_SV_INSTANCE_ID
, "SV_InstanceID"},
303 {WINED3D_SV_PRIMITIVE_ID
, "SV_PrimitiveID"},
304 {WINED3D_SV_IS_FRONT_FACE
, "SV_IsFrontFace"},
305 {WINED3D_SV_SAMPLE_INDEX
, "SV_SampleIndex"},
306 {WINED3D_SV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
307 {WINED3D_SV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
308 {WINED3D_SV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
309 {WINED3D_SV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
310 {WINED3D_SV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
311 {WINED3D_SV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
312 {WINED3D_SV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
313 {WINED3D_SV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
314 {WINED3D_SV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
315 {WINED3D_SV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
316 {WINED3D_SV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
317 {WINED3D_SV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
320 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
321 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
323 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
325 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
326 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
328 return shader_opcode_names
[handler_idx
];
331 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
333 if (usage
>= ARRAY_SIZE(semantic_names
))
335 FIXME("Unrecognized usage %#x.\n", usage
);
336 return "UNRECOGNIZED";
339 return semantic_names
[usage
];
342 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
346 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
348 if (!strcmp(name
, semantic_names
[i
]))
355 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
359 case WINED3D_DECL_USAGE_POSITION
:
360 return WINED3D_SV_POSITION
;
366 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
368 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
371 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
372 const struct wined3d_shader_semantic
*s
)
374 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
375 e
->semantic_idx
= s
->usage_idx
;
376 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
377 e
->component_type
= WINED3D_TYPE_FLOAT
;
378 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
379 e
->mask
= s
->reg
.write_mask
;
382 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
383 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
385 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
386 e
->semantic_idx
= usage_idx
;
387 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
388 e
->component_type
= WINED3D_TYPE_FLOAT
;
389 e
->register_idx
= reg_idx
;
390 e
->mask
= write_mask
;
393 static const struct wined3d_shader_frontend
*shader_select_frontend(DWORD version_token
)
395 switch (version_token
>> 16)
399 return &sm1_shader_frontend
;
407 return &sm4_shader_frontend
;
410 FIXME("Unrecognised version token %#x.\n", version_token
);
415 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
417 buffer
->buffer
[0] = '\0';
418 buffer
->content_size
= 0;
421 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
423 buffer
->buffer_size
= 32;
424 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
426 ERR("Failed to allocate shader buffer memory.\n");
430 string_buffer_clear(buffer
);
434 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
436 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
439 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
442 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
444 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
445 new_buffer_size
*= 2;
446 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
448 ERR("Failed to grow buffer.\n");
449 buffer
->buffer
[buffer
->content_size
] = '\0';
452 buffer
->buffer
= new_buffer
;
453 buffer
->buffer_size
= new_buffer_size
;
457 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
462 rem
= buffer
->buffer_size
- buffer
->content_size
;
463 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
464 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
467 buffer
->content_size
+= rc
;
471 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
478 va_start(args
, format
);
479 ret
= shader_vaddline(buffer
, format
, args
);
483 if (!string_buffer_resize(buffer
, ret
))
488 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
490 struct wined3d_string_buffer
*buffer
;
492 if (list_empty(&list
->list
))
494 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
495 if (!buffer
|| !string_buffer_init(buffer
))
497 ERR("Couldn't allocate buffer for temporary string.\n");
498 HeapFree(GetProcessHeap(), 0, buffer
);
504 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
505 list_remove(&buffer
->entry
);
507 string_buffer_clear(buffer
);
511 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
515 string_buffer_clear(buffer
);
516 return shader_vaddline(buffer
, format
, args
);
519 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
526 va_start(args
, format
);
527 ret
= string_buffer_vsprintf(buffer
, format
, args
);
531 if (!string_buffer_resize(buffer
, ret
))
536 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
540 list_add_head(&list
->list
, &buffer
->entry
);
543 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
545 list_init(&list
->list
);
548 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
550 struct wined3d_string_buffer
*buffer
, *buffer_next
;
552 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
554 string_buffer_free(buffer
);
555 HeapFree(GetProcessHeap(), 0, buffer
);
557 list_init(&list
->list
);
560 /* Convert floating point offset relative to a register file to an absolute
561 * offset for float constants. */
562 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
564 switch (register_type
)
566 case WINED3DSPR_CONST
: return register_idx
;
567 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
568 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
569 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
571 FIXME("Unsupported register type: %u.\n", register_type
);
576 static void shader_delete_constant_list(struct list
*clist
)
578 struct wined3d_shader_lconst
*constant
, *constant_next
;
580 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
581 HeapFree(GetProcessHeap(), 0, constant
);
585 static void shader_set_limits(struct wined3d_shader
*shader
)
587 static const struct limits_entry
589 unsigned int min_version
;
590 unsigned int max_version
;
591 struct wined3d_shader_limits limits
;
595 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
596 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
597 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
598 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
599 * even though they are capable of supporting much more (GL
600 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
601 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
603 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
604 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
605 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
610 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
611 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
615 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
616 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
620 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
621 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
622 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
627 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
628 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
629 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
630 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
631 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
632 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
633 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
638 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
639 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
641 const struct limits_entry
*limits_array
;
642 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
643 shader
->reg_maps
.shader_version
.minor
);
646 switch (shader
->reg_maps
.shader_version
.type
)
649 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
651 case WINED3D_SHADER_TYPE_VERTEX
:
652 limits_array
= vs_limits
;
654 case WINED3D_SHADER_TYPE_HULL
:
655 limits_array
= hs_limits
;
657 case WINED3D_SHADER_TYPE_DOMAIN
:
658 limits_array
= ds_limits
;
660 case WINED3D_SHADER_TYPE_GEOMETRY
:
661 limits_array
= gs_limits
;
663 case WINED3D_SHADER_TYPE_PIXEL
:
664 limits_array
= ps_limits
;
666 case WINED3D_SHADER_TYPE_COMPUTE
:
667 limits_array
= cs_limits
;
671 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
673 if (shader_version
<= limits_array
[i
].max_version
)
675 shader
->limits
= &limits_array
[i
].limits
;
682 FIXME("Unexpected shader version \"%u.%u\".\n",
683 shader
->reg_maps
.shader_version
.major
,
684 shader
->reg_maps
.shader_version
.minor
);
685 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
689 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
694 bitmap
[idx
] |= (1u << shift
);
697 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
698 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
702 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
703 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
704 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
706 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
709 case WINED3DSPR_TEMP
:
710 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
713 case WINED3DSPR_INPUT
:
714 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
716 if (reg
->idx
[0].rel_addr
)
718 /* If relative addressing is used, we must assume that all registers
719 * are used. Even if it is a construct like v3[aL], we can't assume
720 * that v0, v1 and v2 aren't read because aL can be negative */
722 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
724 shader
->u
.ps
.input_reg_used
[i
] = TRUE
;
729 shader
->u
.ps
.input_reg_used
[reg
->idx
[0].offset
] = TRUE
;
733 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
736 case WINED3DSPR_RASTOUT
:
737 if (reg
->idx
[0].offset
== 1)
739 if (reg
->idx
[0].offset
== 2)
740 reg_maps
->point_size
= 1;
743 case WINED3DSPR_MISCTYPE
:
744 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
746 if (!reg
->idx
[0].offset
)
748 else if (reg
->idx
[0].offset
== 1)
749 reg_maps
->usesfacing
= 1;
753 case WINED3DSPR_CONST
:
754 if (reg
->idx
[0].rel_addr
)
756 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
757 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
758 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
759 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
760 reg_maps
->usesrelconstF
= TRUE
;
764 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
766 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
771 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
776 case WINED3DSPR_CONSTINT
:
777 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
779 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
784 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
788 case WINED3DSPR_CONSTBOOL
:
789 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
791 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
796 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
800 case WINED3DSPR_COLOROUT
:
801 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
805 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
806 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
812 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
813 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
815 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
816 struct wined3d_shader_sampler_map
*map
;
819 map
= ®_maps
->sampler_map
;
820 entries
= map
->entries
;
821 for (i
= 0; i
< map
->count
; ++i
)
823 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
829 if (!(entries
= wined3d_calloc(4, sizeof(*entries
))))
831 ERR("Failed to allocate sampler map entries.\n");
835 map
->entries
= entries
;
837 else if (map
->count
== map
->size
)
839 size_t new_size
= map
->size
* 2;
841 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
842 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
844 ERR("Failed to resize sampler map entries.\n");
847 map
->size
= new_size
;
848 map
->entries
= entries
;
851 entry
= &entries
[map
->count
++];
852 entry
->resource_idx
= resource_idx
;
853 entry
->sampler_idx
= sampler_idx
;
854 entry
->bind_idx
= bind_idx
;
857 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
861 case WINED3DSIH_M4x4
:
862 case WINED3DSIH_M3x4
:
863 return param
== 1 ? 3 : 0;
865 case WINED3DSIH_M4x3
:
866 case WINED3DSIH_M3x3
:
867 return param
== 1 ? 2 : 0;
869 case WINED3DSIH_M3x2
:
870 return param
== 1 ? 1 : 0;
877 /* Note that this does not count the loop register as an address register. */
878 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
879 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
880 struct wined3d_shader_signature
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
882 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
883 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
884 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
885 void *fe_data
= shader
->frontend_data
;
886 struct wined3d_shader_version shader_version
;
887 const DWORD
*ptr
= byte_code
;
890 memset(reg_maps
, 0, sizeof(*reg_maps
));
891 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
892 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
893 reg_maps
->min_rel_offset
= ~0U;
894 list_init(®_maps
->indexable_temps
);
896 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
897 reg_maps
->shader_version
= shader_version
;
899 shader_set_limits(shader
);
901 if (!(reg_maps
->constf
= wined3d_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
902 sizeof(*reg_maps
->constf
))))
904 ERR("Failed to allocate constant map memory.\n");
905 return E_OUTOFMEMORY
;
908 while (!fe
->shader_is_end(fe_data
, &ptr
))
910 struct wined3d_shader_instruction ins
;
913 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
915 /* Unhandled opcode, and its parameters. */
916 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
918 TRACE("Skipping unrecognized instruction.\n");
922 /* Handle declarations. */
923 if (ins
.handler_idx
== WINED3DSIH_DCL
924 || ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
926 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
927 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
929 switch (semantic
->reg
.reg
.type
)
931 /* Mark input registers used. */
932 case WINED3DSPR_INPUT
:
933 if (reg_idx
>= MAX_REG_INPUT
)
935 ERR("Invalid input register index %u.\n", reg_idx
);
938 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
939 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
940 return WINED3DERR_INVALIDCALL
;
941 reg_maps
->input_registers
|= 1u << reg_idx
;
942 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
945 /* Vertex shader: mark 3.0 output registers used, save token. */
946 case WINED3DSPR_OUTPUT
:
947 if (reg_idx
>= MAX_REG_OUTPUT
)
949 ERR("Invalid output register index %u.\n", reg_idx
);
952 reg_maps
->output_registers
|= 1u << reg_idx
;
953 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
954 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
956 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
957 reg_maps
->point_size
= 1;
960 case WINED3DSPR_SAMPLER
:
961 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
962 case WINED3DSPR_RESOURCE
:
963 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
965 ERR("Invalid resource index %u.\n", reg_idx
);
968 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
969 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
973 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
975 ERR("Invalid UAV resource index %u.\n", reg_idx
);
978 reg_maps
->uav_resource_info
[reg_idx
].type
= semantic
->resource_type
;
979 reg_maps
->uav_resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
983 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
987 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
989 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
990 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
991 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
993 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
995 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
998 FIXME("Multiple immediate constant buffers.\n");
999 reg_maps
->icb
= ins
.declaration
.icb
;
1001 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
1003 struct wined3d_shader_indexable_temp
*reg
;
1005 if (!(reg
= HeapAlloc(GetProcessHeap(), 0, sizeof(*reg
))))
1006 return E_OUTOFMEMORY
;
1008 *reg
= ins
.declaration
.indexable_temp
;
1009 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
1011 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
1013 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1014 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
1016 FIXME("Invalid instruction %#x for shader type %#x.\n",
1017 ins
.handler_idx
, shader_version
.type
);
1019 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1021 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1022 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
1024 FIXME("Invalid instruction %#x for shader type %#x.\n",
1025 ins
.handler_idx
, shader_version
.type
);
1027 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
1029 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
1030 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
1032 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
1034 reg_maps
->temporary_count
= ins
.declaration
.count
;
1036 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
1038 if (shader_version
.type
== WINED3D_SHADER_TYPE_COMPUTE
)
1040 shader
->u
.cs
.thread_group_size
= ins
.declaration
.thread_group_size
;
1044 FIXME("Invalid instruction %#x for shader type %#x.\n",
1045 ins
.handler_idx
, shader_version
.type
);
1048 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1050 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1051 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1053 FIXME("Invalid instruction %#x for shader type %#x.\n",
1054 ins
.handler_idx
, shader_version
.type
);
1056 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1058 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1060 if (!lconst
) return E_OUTOFMEMORY
;
1062 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1063 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1064 value
= (float *)lconst
->value
;
1066 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1067 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1069 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1070 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1071 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1072 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1073 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1074 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1075 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1076 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1079 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1081 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1082 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1084 shader
->lconst_inf_or_nan
= TRUE
;
1087 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1089 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1090 if (!lconst
) return E_OUTOFMEMORY
;
1092 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1093 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1095 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1096 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1098 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1100 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1101 if (!lconst
) return E_OUTOFMEMORY
;
1103 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1104 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1106 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1107 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1109 /* For subroutine prototypes. */
1110 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1112 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1114 /* Set texture, address, temporary registers. */
1117 BOOL color0_mov
= FALSE
;
1120 /* This will loop over all the registers and try to
1121 * make a bitmask of the ones we're interested in.
1123 * Relative addressing tokens are ignored, but that's
1124 * okay, since we'll catch any address registers when
1125 * they are initialized (required by spec). */
1126 for (i
= 0; i
< ins
.dst_count
; ++i
)
1128 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1129 shader_version
.type
, constf_size
))
1130 return WINED3DERR_INVALIDCALL
;
1132 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1134 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1136 switch (ins
.dst
[i
].reg
.type
)
1138 case WINED3DSPR_RASTOUT
:
1139 if (shader_version
.major
>= 3)
1144 reg_maps
->output_registers
|= 1u << 10;
1145 shader_signature_from_usage(&output_signature_elements
[10],
1146 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1150 reg_maps
->output_registers
|= 1u << 11;
1151 shader_signature_from_usage(&output_signature_elements
[11],
1152 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1156 reg_maps
->output_registers
|= 1u << 11;
1157 shader_signature_from_usage(&output_signature_elements
[11],
1158 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1163 case WINED3DSPR_ATTROUT
:
1164 if (shader_version
.major
>= 3)
1169 if (reg_maps
->output_registers
& (1u << idx
))
1171 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1175 reg_maps
->output_registers
|= 1u << idx
;
1176 shader_signature_from_usage(&output_signature_elements
[idx
],
1177 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1182 case WINED3DSPR_TEXCRDOUT
:
1183 if (shader_version
.major
>= 3)
1185 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1188 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1189 if (reg_maps
->output_registers
& (1u << idx
))
1191 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1195 reg_maps
->output_registers
|= 1u << idx
;
1196 shader_signature_from_usage(&output_signature_elements
[idx
],
1197 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1206 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1208 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1210 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1211 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1212 * the mov and perform the sRGB write correction from the source register.
1214 * However, if the mov is only partial, we can't do this, and if the write
1215 * comes from an instruction other than MOV it is hard to do as well. If
1216 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1217 shader
->u
.ps
.color0_mov
= FALSE
;
1218 if (ins
.handler_idx
== WINED3DSIH_MOV
1219 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1221 /* Used later when the source register is read. */
1225 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1228 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1229 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1231 shader
->u
.ps
.color0_mov
= FALSE
;
1235 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1236 if (shader_version
.major
== 1
1237 && (ins
.handler_idx
== WINED3DSIH_TEX
1238 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1239 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1240 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1241 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1242 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1243 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1244 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1245 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1246 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1247 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1249 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1251 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1252 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1253 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1254 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1256 /* texbem is only valid with < 1.4 pixel shaders */
1257 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1258 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1260 reg_maps
->bumpmat
|= 1u << reg_idx
;
1261 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1263 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1267 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1269 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1273 if (ins
.handler_idx
== WINED3DSIH_ATOMIC_IADD
1274 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
)
1276 unsigned int reg_idx
;
1277 if (ins
.handler_idx
== WINED3DSIH_ATOMIC_IADD
)
1278 reg_idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1280 reg_idx
= ins
.src
[1].reg
.idx
[0].offset
;
1281 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1283 ERR("Invalid UAV index %u.\n", reg_idx
);
1286 reg_maps
->uav_read_mask
|= (1u << reg_idx
);
1288 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1290 reg_maps
->usesnrm
= 1;
1292 else if (ins
.handler_idx
== WINED3DSIH_DSY
1293 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1294 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1296 reg_maps
->usesdsy
= 1;
1298 else if (ins
.handler_idx
== WINED3DSIH_DSX
1299 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1300 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1302 reg_maps
->usesdsx
= 1;
1304 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1305 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1306 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1307 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1308 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1309 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1310 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1311 || ins
.handler_idx
== WINED3DSIH_REP
)
1314 if (cur_loop_depth
> max_loop_depth
)
1315 max_loop_depth
= cur_loop_depth
;
1317 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1318 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1322 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1323 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1324 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1325 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1326 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1327 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1329 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1330 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1332 else if (ins
.handler_idx
== WINED3DSIH_LD
1333 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1335 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1336 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1340 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1341 shader_version
.type
, constf_size
))
1342 return WINED3DERR_INVALIDCALL
;
1344 for (i
= 0; i
< ins
.src_count
; ++i
)
1346 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1347 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1349 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1350 shader_version
.type
, constf_size
))
1351 return WINED3DERR_INVALIDCALL
;
1354 ++reg
.idx
[0].offset
;
1355 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1356 shader_version
.type
, constf_size
))
1357 return WINED3DERR_INVALIDCALL
;
1363 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1364 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1366 shader
->u
.ps
.color0_mov
= TRUE
;
1367 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1373 reg_maps
->loop_depth
= max_loop_depth
;
1375 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1376 * R0 is written to the render target. */
1377 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1378 reg_maps
->rt_mask
|= (1u << 0);
1380 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1382 if (input_signature
->elements
)
1384 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1386 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1387 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1389 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1391 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1392 reg_maps
->usesfacing
= 1;
1396 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1398 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1399 struct wined3d_shader_signature_element
*e
;
1402 if (!(input_signature
->elements
= wined3d_calloc(count
, sizeof(*input_signature
->elements
))))
1403 return E_OUTOFMEMORY
;
1404 input_signature
->element_count
= count
;
1406 e
= input_signature
->elements
;
1407 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1409 if (!(reg_maps
->input_registers
& (1u << i
)))
1411 input_signature_elements
[i
].register_idx
= i
;
1412 *e
++ = input_signature_elements
[i
];
1416 if (output_signature
->elements
)
1418 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1420 reg_maps
->output_registers
|= 1u << output_signature
->elements
[i
].register_idx
;
1423 else if (reg_maps
->output_registers
)
1425 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1426 struct wined3d_shader_signature_element
*e
;
1428 if (!(output_signature
->elements
= wined3d_calloc(count
, sizeof(*output_signature
->elements
))))
1429 return E_OUTOFMEMORY
;
1430 output_signature
->element_count
= count
;
1432 e
= output_signature
->elements
;
1433 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1435 if (!(reg_maps
->output_registers
& (1u << i
)))
1437 *e
++ = output_signature_elements
[i
];
1444 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1446 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1448 HeapFree(GetProcessHeap(), 0, reg_maps
->constf
);
1449 HeapFree(GetProcessHeap(), 0, reg_maps
->sampler_map
.entries
);
1451 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1452 HeapFree(GetProcessHeap(), 0, reg
);
1453 list_init(®_maps
->indexable_temps
);
1456 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1458 DWORD map
= 1u << max
;
1460 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1462 return wined3d_log2i(map
);
1465 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1467 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1469 shader_addline(buffer
, "refactoringAllowed");
1470 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1472 shader_addline(buffer
, " | ");
1475 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1477 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1478 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1482 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1485 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1487 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1489 shader_addline(buffer
, "_g");
1490 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1492 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1494 shader_addline(buffer
, "_t");
1495 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1499 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1502 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1504 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1506 shader_addline(buffer
, "_glc");
1507 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1509 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1511 shader_addline(buffer
, "_opc");
1512 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1516 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1519 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1520 enum wined3d_tessellator_domain domain
)
1524 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1525 shader_addline(buffer
, "line");
1527 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1528 shader_addline(buffer
, "triangle");
1530 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1531 shader_addline(buffer
, "quad");
1534 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1539 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1540 enum wined3d_tessellator_output_primitive output_primitive
)
1542 switch (output_primitive
)
1544 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1545 shader_addline(buffer
, "point");
1547 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1548 shader_addline(buffer
, "line");
1550 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1551 shader_addline(buffer
, "triangle_cw");
1553 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1554 shader_addline(buffer
, "triangle_ccw");
1557 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1562 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1563 enum wined3d_tessellator_partitioning partitioning
)
1565 switch (partitioning
)
1567 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1568 shader_addline(buffer
, "integer");
1570 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1571 shader_addline(buffer
, "pow2");
1573 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1574 shader_addline(buffer
, "fractional_odd");
1576 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1577 shader_addline(buffer
, "fractional_even");
1580 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1585 static void shader_dump_sysval_semantic(struct wined3d_string_buffer
*buffer
, enum wined3d_sysval_semantic semantic
)
1589 for (i
= 0; i
< ARRAY_SIZE(sysval_semantic_names
); ++i
)
1591 if (sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1593 shader_addline(buffer
, "%s", sysval_semantic_names
[i
].sysval_name
);
1598 shader_addline(buffer
, "unknown_sysval_semantic(%#x)", semantic
);
1601 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1602 const struct wined3d_shader_semantic
*semantic
, const struct wined3d_shader_version
*shader_version
)
1604 shader_addline(buffer
, "dcl");
1606 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1608 switch (semantic
->resource_type
)
1610 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1611 shader_addline(buffer
, "_2d");
1614 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1615 shader_addline(buffer
, "_3d");
1618 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1619 shader_addline(buffer
, "_cube");
1623 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
1627 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
1629 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1630 shader_addline(buffer
, "_resource_");
1632 shader_addline(buffer
, "_uav_");
1633 switch (semantic
->resource_type
)
1635 case WINED3D_SHADER_RESOURCE_BUFFER
:
1636 shader_addline(buffer
, "buffer");
1639 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1640 shader_addline(buffer
, "texture1d");
1643 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1644 shader_addline(buffer
, "texture2d");
1647 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1648 shader_addline(buffer
, "texture2dms");
1651 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1652 shader_addline(buffer
, "texture3d");
1655 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1656 shader_addline(buffer
, "texturecube");
1659 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1660 shader_addline(buffer
, "texture1darray");
1663 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1664 shader_addline(buffer
, "texture2darray");
1667 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1668 shader_addline(buffer
, "texture2dmsarray");
1671 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
:
1672 shader_addline(buffer
, "texturecubearray");
1676 shader_addline(buffer
, "unknown");
1679 switch (semantic
->resource_data_type
)
1681 case WINED3D_DATA_FLOAT
:
1682 shader_addline(buffer
, " (float)");
1685 case WINED3D_DATA_INT
:
1686 shader_addline(buffer
, " (int)");
1689 case WINED3D_DATA_UINT
:
1690 shader_addline(buffer
, " (uint)");
1693 case WINED3D_DATA_UNORM
:
1694 shader_addline(buffer
, " (unorm)");
1697 case WINED3D_DATA_SNORM
:
1698 shader_addline(buffer
, " (snorm)");
1702 shader_addline(buffer
, " (unknown)");
1708 /* Pixel shaders 3.0 don't have usage semantics. */
1709 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
1712 shader_addline(buffer
, "_");
1714 switch (semantic
->usage
)
1716 case WINED3D_DECL_USAGE_POSITION
:
1717 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
1720 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1721 shader_addline(buffer
, "blend");
1724 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1725 shader_addline(buffer
, "weight");
1728 case WINED3D_DECL_USAGE_NORMAL
:
1729 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
1732 case WINED3D_DECL_USAGE_PSIZE
:
1733 shader_addline(buffer
, "psize");
1736 case WINED3D_DECL_USAGE_COLOR
:
1737 if (!semantic
->usage_idx
)
1738 shader_addline(buffer
, "color");
1740 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
1743 case WINED3D_DECL_USAGE_TEXCOORD
:
1744 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
1747 case WINED3D_DECL_USAGE_TANGENT
:
1748 shader_addline(buffer
, "tangent");
1751 case WINED3D_DECL_USAGE_BINORMAL
:
1752 shader_addline(buffer
, "binormal");
1755 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1756 shader_addline(buffer
, "tessfactor");
1759 case WINED3D_DECL_USAGE_POSITIONT
:
1760 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
1763 case WINED3D_DECL_USAGE_FOG
:
1764 shader_addline(buffer
, "fog");
1767 case WINED3D_DECL_USAGE_DEPTH
:
1768 shader_addline(buffer
, "depth");
1771 case WINED3D_DECL_USAGE_SAMPLE
:
1772 shader_addline(buffer
, "sample");
1776 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
1777 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
1782 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
1783 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
1785 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1786 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1787 UINT offset
= reg
->idx
[0].offset
;
1791 case WINED3DSPR_TEMP
:
1792 shader_addline(buffer
, "r");
1795 case WINED3DSPR_INPUT
:
1796 shader_addline(buffer
, "v");
1799 case WINED3DSPR_CONST
:
1800 case WINED3DSPR_CONST2
:
1801 case WINED3DSPR_CONST3
:
1802 case WINED3DSPR_CONST4
:
1803 shader_addline(buffer
, "c");
1804 offset
= shader_get_float_offset(reg
->type
, offset
);
1807 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1808 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1811 case WINED3DSPR_RASTOUT
:
1812 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
1815 case WINED3DSPR_COLOROUT
:
1816 shader_addline(buffer
, "oC");
1819 case WINED3DSPR_DEPTHOUT
:
1820 shader_addline(buffer
, "oDepth");
1823 case WINED3DSPR_ATTROUT
:
1824 shader_addline(buffer
, "oD");
1827 case WINED3DSPR_TEXCRDOUT
:
1828 /* Vertex shaders >= 3.0 use general purpose output registers
1829 * (WINED3DSPR_OUTPUT), which can include an address token. */
1830 if (shader_version
->major
>= 3)
1831 shader_addline(buffer
, "o");
1833 shader_addline(buffer
, "oT");
1836 case WINED3DSPR_CONSTINT
:
1837 shader_addline(buffer
, "i");
1840 case WINED3DSPR_CONSTBOOL
:
1841 shader_addline(buffer
, "b");
1844 case WINED3DSPR_LABEL
:
1845 shader_addline(buffer
, "l");
1848 case WINED3DSPR_LOOP
:
1849 shader_addline(buffer
, "aL");
1852 case WINED3DSPR_SAMPLER
:
1853 shader_addline(buffer
, "s");
1856 case WINED3DSPR_MISCTYPE
:
1859 FIXME("Unhandled misctype register %u.\n", offset
);
1860 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
1864 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
1868 case WINED3DSPR_PREDICATE
:
1869 shader_addline(buffer
, "p");
1872 case WINED3DSPR_IMMCONST
:
1873 shader_addline(buffer
, "l");
1876 case WINED3DSPR_CONSTBUFFER
:
1877 shader_addline(buffer
, "cb");
1880 case WINED3DSPR_IMMCONSTBUFFER
:
1881 shader_addline(buffer
, "icb");
1884 case WINED3DSPR_PRIMID
:
1885 shader_addline(buffer
, "primID");
1888 case WINED3DSPR_NULL
:
1889 shader_addline(buffer
, "null");
1892 case WINED3DSPR_RESOURCE
:
1893 shader_addline(buffer
, "t");
1896 case WINED3DSPR_UAV
:
1897 shader_addline(buffer
, "u");
1900 case WINED3DSPR_OUTPOINTID
:
1901 shader_addline(buffer
, "vOutputControlPointID");
1904 case WINED3DSPR_FORKINSTID
:
1905 shader_addline(buffer
, "vForkInstanceId");
1908 case WINED3DSPR_INCONTROLPOINT
:
1909 shader_addline(buffer
, "vicp");
1912 case WINED3DSPR_OUTCONTROLPOINT
:
1913 shader_addline(buffer
, "vocp");
1916 case WINED3DSPR_PATCHCONST
:
1917 shader_addline(buffer
, "vpc");
1920 case WINED3DSPR_TESSCOORD
:
1921 shader_addline(buffer
, "vDomainLocation");
1924 case WINED3DSPR_GROUPSHAREDMEM
:
1925 shader_addline(buffer
, "g");
1928 case WINED3DSPR_THREADID
:
1929 shader_addline(buffer
, "vThreadID");
1932 case WINED3DSPR_THREADGROUPID
:
1933 shader_addline(buffer
, "vThreadGroupID");
1936 case WINED3DSPR_LOCALTHREADID
:
1937 shader_addline(buffer
, "vThreadIDInGroup");
1940 case WINED3DSPR_LOCALTHREADINDEX
:
1941 shader_addline(buffer
, "vThreadIDInGroupFlattened");
1944 case WINED3DSPR_IDXTEMP
:
1945 shader_addline(buffer
, "x");
1948 case WINED3DSPR_STREAM
:
1949 shader_addline(buffer
, "m");
1952 case WINED3DSPR_FUNCTIONBODY
:
1953 shader_addline(buffer
, "fb");
1956 case WINED3DSPR_FUNCTIONPOINTER
:
1957 shader_addline(buffer
, "fp");
1960 case WINED3DSPR_COVERAGE
:
1961 shader_addline(buffer
, "vCoverage");
1964 case WINED3DSPR_SAMPLEMASK
:
1965 shader_addline(buffer
, "oMask");
1969 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
1973 if (reg
->type
== WINED3DSPR_IMMCONST
)
1975 shader_addline(buffer
, "(");
1976 switch (reg
->immconst_type
)
1978 case WINED3D_IMMCONST_SCALAR
:
1979 switch (reg
->data_type
)
1981 case WINED3D_DATA_FLOAT
:
1982 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
1984 case WINED3D_DATA_INT
:
1985 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
1987 case WINED3D_DATA_RESOURCE
:
1988 case WINED3D_DATA_SAMPLER
:
1989 case WINED3D_DATA_UINT
:
1990 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
1993 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1998 case WINED3D_IMMCONST_VEC4
:
1999 switch (reg
->data_type
)
2001 case WINED3D_DATA_FLOAT
:
2002 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2003 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2004 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2006 case WINED3D_DATA_INT
:
2007 shader_addline(buffer
, "%d, %d, %d, %d",
2008 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2009 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2011 case WINED3D_DATA_RESOURCE
:
2012 case WINED3D_DATA_SAMPLER
:
2013 case WINED3D_DATA_UINT
:
2014 shader_addline(buffer
, "%u, %u, %u, %u",
2015 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2016 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2019 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2025 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2028 shader_addline(buffer
, ")");
2030 else if (reg
->type
!= WINED3DSPR_RASTOUT
2031 && reg
->type
!= WINED3DSPR_MISCTYPE
2032 && reg
->type
!= WINED3DSPR_NULL
)
2036 shader_addline(buffer
, "[");
2037 if (reg
->idx
[0].rel_addr
)
2039 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2040 shader_addline(buffer
, " + ");
2042 shader_addline(buffer
, "%u]", offset
);
2044 if (reg
->idx
[1].offset
!= ~0u)
2046 shader_addline(buffer
, "[");
2047 if (reg
->idx
[1].rel_addr
)
2049 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2050 shader_addline(buffer
, " + ");
2052 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2056 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2057 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2061 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2062 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2064 DWORD write_mask
= param
->write_mask
;
2066 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2068 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2070 static const char write_mask_chars
[] = "xyzw";
2072 shader_addline(buffer
, ".");
2073 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2074 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2075 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2076 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2077 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2078 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2079 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2080 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2084 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2085 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2087 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2088 DWORD swizzle
= param
->swizzle
;
2090 if (src_modifier
== WINED3DSPSM_NEG
2091 || src_modifier
== WINED3DSPSM_BIASNEG
2092 || src_modifier
== WINED3DSPSM_SIGNNEG
2093 || src_modifier
== WINED3DSPSM_X2NEG
2094 || src_modifier
== WINED3DSPSM_ABSNEG
)
2095 shader_addline(buffer
, "-");
2096 else if (src_modifier
== WINED3DSPSM_COMP
)
2097 shader_addline(buffer
, "1-");
2098 else if (src_modifier
== WINED3DSPSM_NOT
)
2099 shader_addline(buffer
, "!");
2101 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2102 shader_addline(buffer
, "abs(");
2104 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2106 switch (src_modifier
)
2108 case WINED3DSPSM_NONE
: break;
2109 case WINED3DSPSM_NEG
: break;
2110 case WINED3DSPSM_NOT
: break;
2111 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2112 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2113 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2114 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2115 case WINED3DSPSM_COMP
: break;
2116 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2117 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2118 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2119 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2120 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2121 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2122 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2125 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2127 static const char swizzle_chars
[] = "xyzw";
2128 DWORD swizzle_x
= swizzle
& 0x03;
2129 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2130 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2131 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2133 if (swizzle_x
== swizzle_y
2134 && swizzle_x
== swizzle_z
2135 && swizzle_x
== swizzle_w
)
2137 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2141 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2142 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2147 /* Shared code in order to generate the bulk of the shader string.
2148 * NOTE: A description of how to parse tokens can be found on MSDN. */
2149 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2150 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
2152 struct wined3d_device
*device
= shader
->device
;
2153 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2154 void *fe_data
= shader
->frontend_data
;
2155 struct wined3d_shader_version shader_version
;
2156 struct wined3d_shader_parser_state state
;
2157 struct wined3d_shader_instruction ins
;
2158 struct wined3d_shader_tex_mx tex_mx
;
2159 struct wined3d_shader_context ctx
;
2160 const DWORD
*ptr
= byte_code
;
2162 /* Initialize current parsing state. */
2163 tex_mx
.current_row
= 0;
2164 state
.current_loop_depth
= 0;
2165 state
.current_loop_reg
= 0;
2166 state
.in_subroutine
= FALSE
;
2168 ctx
.shader
= shader
;
2169 ctx
.gl_info
= &device
->adapter
->gl_info
;
2170 ctx
.reg_maps
= reg_maps
;
2171 ctx
.buffer
= buffer
;
2172 ctx
.tex_mx
= &tex_mx
;
2174 ctx
.backend_data
= backend_ctx
;
2177 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2179 while (!fe
->shader_is_end(fe_data
, &ptr
))
2182 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2184 /* Unknown opcode and its parameters. */
2185 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2187 TRACE("Skipping unrecognized instruction.\n");
2192 FIXME("Predicates not implemented.\n");
2194 /* Call appropriate function for output target */
2195 device
->shader_backend
->shader_handle_instruction(&ins
);
2199 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2200 const struct wined3d_shader_dst_param
*dst
)
2202 DWORD mmask
= dst
->modifiers
;
2207 case 13: shader_addline(buffer
, "_d8"); break;
2208 case 14: shader_addline(buffer
, "_d4"); break;
2209 case 15: shader_addline(buffer
, "_d2"); break;
2210 case 1: shader_addline(buffer
, "_x2"); break;
2211 case 2: shader_addline(buffer
, "_x4"); break;
2212 case 3: shader_addline(buffer
, "_x8"); break;
2213 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2216 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2217 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2218 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2220 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2221 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2224 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2225 enum wined3d_primitive_type primitive_type
)
2227 switch (primitive_type
)
2229 case WINED3D_PT_UNDEFINED
:
2230 shader_addline(buffer
, "undefined");
2232 case WINED3D_PT_POINTLIST
:
2233 shader_addline(buffer
, "pointlist");
2235 case WINED3D_PT_LINELIST
:
2236 shader_addline(buffer
, "linelist");
2238 case WINED3D_PT_LINESTRIP
:
2239 shader_addline(buffer
, "linestrip");
2241 case WINED3D_PT_TRIANGLELIST
:
2242 shader_addline(buffer
, "trianglelist");
2244 case WINED3D_PT_TRIANGLESTRIP
:
2245 shader_addline(buffer
, "trianglestrip");
2247 case WINED3D_PT_TRIANGLEFAN
:
2248 shader_addline(buffer
, "trianglefan");
2250 case WINED3D_PT_LINELIST_ADJ
:
2251 shader_addline(buffer
, "linelist_adj");
2253 case WINED3D_PT_LINESTRIP_ADJ
:
2254 shader_addline(buffer
, "linestrip_adj");
2256 case WINED3D_PT_TRIANGLELIST_ADJ
:
2257 shader_addline(buffer
, "trianglelist_adj");
2259 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2260 shader_addline(buffer
, "trianglestrip_adj");
2263 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
);
2268 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2269 enum wined3d_shader_interpolation_mode interpolation_mode
)
2271 switch (interpolation_mode
)
2273 case WINED3DSIM_CONSTANT
:
2274 shader_addline(buffer
, "constant");
2276 case WINED3DSIM_LINEAR
:
2277 shader_addline(buffer
, "linear");
2279 case WINED3DSIM_LINEAR_CENTROID
:
2280 shader_addline(buffer
, "linear centroid");
2282 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2283 shader_addline(buffer
, "linear noperspective");
2285 case WINED3DSIM_LINEAR_SAMPLE
:
2286 shader_addline(buffer
, "linear sample");
2288 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2289 shader_addline(buffer
, "linear noperspective centroid");
2291 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2292 shader_addline(buffer
, "linear noperspective sample");
2295 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2300 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
2302 struct wined3d_shader_version shader_version
;
2303 struct wined3d_string_buffer buffer
;
2304 const DWORD
*ptr
= byte_code
;
2305 const char *type_prefix
;
2309 if (!string_buffer_init(&buffer
))
2311 ERR("Failed to initialize string buffer.\n");
2315 TRACE("Parsing %p.\n", byte_code
);
2317 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2319 switch (shader_version
.type
)
2321 case WINED3D_SHADER_TYPE_VERTEX
:
2325 case WINED3D_SHADER_TYPE_HULL
:
2329 case WINED3D_SHADER_TYPE_DOMAIN
:
2333 case WINED3D_SHADER_TYPE_GEOMETRY
:
2337 case WINED3D_SHADER_TYPE_PIXEL
:
2341 case WINED3D_SHADER_TYPE_COMPUTE
:
2346 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2347 type_prefix
= "unknown";
2351 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2353 while (!fe
->shader_is_end(fe_data
, &ptr
))
2355 struct wined3d_shader_instruction ins
;
2357 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2358 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2360 WARN("Skipping unrecognized instruction.\n");
2361 shader_addline(&buffer
, "<unrecognized instruction>\n");
2365 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2367 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, &shader_version
);
2368 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2369 shader_addline(&buffer
, " ");
2370 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2372 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2374 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2375 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2376 shader_addline(&buffer
, ", %s",
2377 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2379 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2381 shader_addline(&buffer
, "%s fb%u",
2382 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2384 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2386 shader_addline(&buffer
, "%s ft%u = {...}",
2387 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2389 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2391 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2392 shader_dump_global_flags(&buffer
, ins
.flags
);
2394 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2396 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2397 ins
.declaration
.max_tessellation_factor
);
2399 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2401 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2402 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2404 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2405 ins
.declaration
.icb
->data
[4 * i
+ 0],
2406 ins
.declaration
.icb
->data
[4 * i
+ 1],
2407 ins
.declaration
.icb
->data
[4 * i
+ 2],
2408 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2410 shader_addline(&buffer
, "}");
2412 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2414 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2415 ins
.declaration
.indexable_temp
.register_idx
,
2416 ins
.declaration
.indexable_temp
.register_size
,
2417 ins
.declaration
.indexable_temp
.component_count
);
2419 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2421 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2422 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2423 shader_addline(&buffer
, " ");
2424 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2426 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2427 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2428 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2429 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2431 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2432 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2433 shader_addline(&buffer
, ", ");
2434 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2436 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2438 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2439 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2440 shader_addline(&buffer
, " ");
2441 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2442 shader_addline(&buffer
, ", ");
2443 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2445 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2446 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2448 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2449 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2451 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2452 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2454 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2455 shader_dump_primitive_type(&buffer
, ins
.declaration
.primitive_type
);
2457 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2459 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2460 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2461 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2463 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2465 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2466 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2468 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2470 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2471 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2472 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2474 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2476 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2477 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2478 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2479 shader_addline(&buffer
, ", comparisonMode");
2481 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2482 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
2483 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2484 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2485 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
2487 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2489 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2491 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2492 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2494 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2496 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2497 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2499 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2501 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2502 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2504 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2506 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2507 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2508 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2510 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2512 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2513 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2514 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2515 ins
.declaration
.tgsm_structured
.structure_count
);
2517 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2519 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2520 ins
.declaration
.thread_group_size
.x
,
2521 ins
.declaration
.thread_group_size
.y
,
2522 ins
.declaration
.thread_group_size
.z
);
2524 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2526 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2527 shader_dump_uav_flags(&buffer
, ins
.flags
);
2528 shader_addline(&buffer
, " ");
2529 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2531 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2533 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2534 shader_dump_uav_flags(&buffer
, ins
.flags
);
2535 shader_addline(&buffer
, " ");
2536 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2537 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2539 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2541 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2542 ins
.dst
[0].reg
.idx
[0].offset
),
2543 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
2544 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
2545 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
2546 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
2548 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2550 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2551 ins
.src
[0].reg
.u
.immconst_data
[0],
2552 ins
.src
[0].reg
.u
.immconst_data
[1],
2553 ins
.src
[0].reg
.u
.immconst_data
[2],
2554 ins
.src
[0].reg
.u
.immconst_data
[3]);
2556 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2558 shader_addline(&buffer
, "defb b%u = %s",
2559 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
2565 shader_addline(&buffer
, "(");
2566 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2567 shader_addline(&buffer
, ") ");
2570 /* PixWin marks instructions with the coissue flag with a '+' */
2572 shader_addline(&buffer
, "+");
2574 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2576 if (ins
.handler_idx
== WINED3DSIH_BREAKP
2577 || ins
.handler_idx
== WINED3DSIH_IF
)
2581 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
2582 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
2583 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
2586 else if (ins
.handler_idx
== WINED3DSIH_IFC
2587 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
2591 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
2592 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
2593 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
2594 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
2595 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
2596 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
2597 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
2600 else if (ins
.handler_idx
== WINED3DSIH_TEX
2601 && shader_version
.major
>= 2
2602 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
2604 shader_addline(&buffer
, "p");
2606 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
2610 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
2611 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2612 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2615 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
2619 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2620 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2623 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
2625 shader_dump_sync_flags(&buffer
, ins
.flags
);
2628 if (wined3d_shader_instruction_has_texel_offset(&ins
))
2629 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
2631 for (i
= 0; i
< ins
.dst_count
; ++i
)
2633 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
2634 shader_addline(&buffer
, !i
? " " : ", ");
2635 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
2638 /* Other source tokens */
2639 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
2641 shader_addline(&buffer
, !i
? " " : ", ");
2642 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
2645 shader_addline(&buffer
, "\n");
2648 for (p
= buffer
.buffer
; *p
; p
= q
)
2650 if (!(q
= strstr(p
, "\n")))
2654 TRACE(" %.*s", (int)(q
- p
), p
);
2657 string_buffer_free(&buffer
);
2660 static void shader_cleanup(struct wined3d_shader
*shader
)
2662 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
2663 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2664 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2665 shader
->device
->shader_backend
->shader_destroy(shader
);
2666 shader_cleanup_reg_maps(&shader
->reg_maps
);
2667 HeapFree(GetProcessHeap(), 0, shader
->function
);
2668 shader_delete_constant_list(&shader
->constantsF
);
2669 shader_delete_constant_list(&shader
->constantsB
);
2670 shader_delete_constant_list(&shader
->constantsI
);
2671 list_remove(&shader
->shader_list_entry
);
2673 if (shader
->frontend
&& shader
->frontend_data
)
2674 shader
->frontend
->shader_free(shader
->frontend_data
);
2677 struct shader_none_priv
2679 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
2680 const struct fragment_pipeline
*fragment_pipe
;
2681 BOOL ffp_proj_control
;
2684 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
2685 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
2686 const struct wined3d_state
*state
) {}
2687 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2688 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2689 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
2690 const struct wined3d_state
*state
) {}
2691 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
2692 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
2693 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
2695 /* Context activation is done by the caller. */
2696 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
2697 const struct wined3d_state
*state
)
2699 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2700 struct shader_none_priv
*priv
= shader_priv
;
2702 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
2703 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
2706 /* Context activation is done by the caller. */
2707 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
2709 struct shader_none_priv
*priv
= shader_priv
;
2710 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2712 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
2713 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
2715 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
2716 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
2717 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
2718 | (1u << WINED3D_SHADER_TYPE_HULL
)
2719 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
2720 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
2723 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
2724 const struct fragment_pipeline
*fragment_pipe
)
2726 struct fragment_caps fragment_caps
;
2727 void *vertex_priv
, *fragment_priv
;
2728 struct shader_none_priv
*priv
;
2730 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
2731 return E_OUTOFMEMORY
;
2733 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
2735 ERR("Failed to initialize vertex pipe.\n");
2736 HeapFree(GetProcessHeap(), 0, priv
);
2740 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
2742 ERR("Failed to initialize fragment pipe.\n");
2743 vertex_pipe
->vp_free(device
);
2744 HeapFree(GetProcessHeap(), 0, priv
);
2748 priv
->vertex_pipe
= vertex_pipe
;
2749 priv
->fragment_pipe
= fragment_pipe
;
2750 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
2751 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
2753 device
->vertex_priv
= vertex_priv
;
2754 device
->fragment_priv
= fragment_priv
;
2755 device
->shader_priv
= priv
;
2760 static void shader_none_free(struct wined3d_device
*device
)
2762 struct shader_none_priv
*priv
= device
->shader_priv
;
2764 priv
->fragment_pipe
->free_private(device
);
2765 priv
->vertex_pipe
->vp_free(device
);
2766 HeapFree(GetProcessHeap(), 0, priv
);
2769 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
2774 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
2776 /* Set the shader caps to 0 for the none shader backend */
2777 caps
->vs_version
= 0;
2778 caps
->hs_version
= 0;
2779 caps
->ds_version
= 0;
2780 caps
->gs_version
= 0;
2781 caps
->ps_version
= 0;
2782 caps
->cs_version
= 0;
2783 caps
->vs_uniform_count
= 0;
2784 caps
->ps_uniform_count
= 0;
2785 caps
->ps_1x_max_value
= 0.0f
;
2786 caps
->varying_count
= 0;
2787 caps
->wined3d_caps
= 0;
2790 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2792 /* We "support" every possible fixup, since we don't support any shader
2793 * model, and will never have to actually sample a texture. */
2797 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2799 struct shader_none_priv
*priv
= shader_priv
;
2801 return priv
->ffp_proj_control
;
2804 const struct wined3d_shader_backend_ops none_shader_backend
=
2806 shader_none_handle_instruction
,
2808 shader_none_select_compute
,
2809 shader_none_disable
,
2810 shader_none_update_float_vertex_constants
,
2811 shader_none_update_float_pixel_constants
,
2812 shader_none_load_constants
,
2813 shader_none_destroy
,
2816 shader_none_allocate_context_data
,
2817 shader_none_free_context_data
,
2818 shader_none_init_context_state
,
2819 shader_none_get_caps
,
2820 shader_none_color_fixup_supported
,
2821 shader_none_has_ffp_proj_control
,
2824 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
2825 DWORD float_const_count
, enum wined3d_shader_type type
, unsigned int max_version
)
2827 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2828 const struct wined3d_shader_frontend
*fe
;
2830 unsigned int backend_version
;
2831 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2833 TRACE("shader %p, byte_code %p, float_const_count %u, type %#x, max_version %u.\n",
2834 shader
, byte_code
, float_const_count
, type
, max_version
);
2836 list_init(&shader
->constantsF
);
2837 list_init(&shader
->constantsB
);
2838 list_init(&shader
->constantsI
);
2839 shader
->lconst_inf_or_nan
= FALSE
;
2840 list_init(®_maps
->indexable_temps
);
2842 fe
= shader_select_frontend(*byte_code
);
2845 FIXME("Unable to find frontend for shader.\n");
2846 return WINED3DERR_INVALIDCALL
;
2848 shader
->frontend
= fe
;
2849 shader
->frontend_data
= fe
->shader_init(byte_code
, &shader
->output_signature
);
2850 if (!shader
->frontend_data
)
2852 FIXME("Failed to initialize frontend.\n");
2853 return WINED3DERR_INVALIDCALL
;
2856 /* First pass: trace shader. */
2857 if (TRACE_ON(d3d_shader
))
2858 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
2860 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2861 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2862 &shader
->output_signature
, byte_code
, float_const_count
)))
2865 if (reg_maps
->shader_version
.type
!= type
)
2867 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2868 return WINED3DERR_INVALIDCALL
;
2870 if (reg_maps
->shader_version
.major
> max_version
)
2872 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2873 return WINED3DERR_INVALIDCALL
;
2877 case WINED3D_SHADER_TYPE_VERTEX
:
2878 backend_version
= d3d_info
->limits
.vs_version
;
2880 case WINED3D_SHADER_TYPE_HULL
:
2881 backend_version
= d3d_info
->limits
.hs_version
;
2883 case WINED3D_SHADER_TYPE_DOMAIN
:
2884 backend_version
= d3d_info
->limits
.ds_version
;
2886 case WINED3D_SHADER_TYPE_GEOMETRY
:
2887 backend_version
= d3d_info
->limits
.gs_version
;
2889 case WINED3D_SHADER_TYPE_PIXEL
:
2890 backend_version
= d3d_info
->limits
.ps_version
;
2892 case WINED3D_SHADER_TYPE_COMPUTE
:
2893 backend_version
= d3d_info
->limits
.cs_version
;
2896 FIXME("No backend version-checking for this shader type.\n");
2897 backend_version
= 0;
2899 if (reg_maps
->shader_version
.major
> backend_version
)
2901 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2902 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2903 return WINED3DERR_INVALIDCALL
;
2906 if (!(shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
)))
2907 return E_OUTOFMEMORY
;
2908 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2913 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2915 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2917 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2922 static void wined3d_shader_destroy_object(void *object
)
2924 shader_cleanup(object
);
2925 HeapFree(GetProcessHeap(), 0, object
);
2928 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2930 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2932 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2936 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2937 wined3d_cs_emit_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
2943 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2945 TRACE("shader %p.\n", shader
);
2947 return shader
->parent
;
2950 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2951 void *byte_code
, UINT
*byte_code_size
)
2953 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2957 *byte_code_size
= shader
->functionLength
;
2961 if (*byte_code_size
< shader
->functionLength
)
2963 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2964 * than the required size we should write the required size and
2965 * return D3DERR_MOREDATA. That's not actually true. */
2966 return WINED3DERR_INVALIDCALL
;
2969 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2974 /* Set local constants for d3d8 shaders. */
2975 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2976 UINT start_idx
, const float *src_data
, UINT count
)
2978 UINT end_idx
= start_idx
+ count
;
2981 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2983 if (end_idx
> shader
->limits
->constant_float
)
2985 WARN("end_idx %u > float constants limit %u.\n",
2986 end_idx
, shader
->limits
->constant_float
);
2987 end_idx
= shader
->limits
->constant_float
;
2990 for (i
= start_idx
; i
< end_idx
; ++i
)
2992 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2995 return E_OUTOFMEMORY
;
2998 value
= (float *)lconst
->value
;
2999 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3000 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3002 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3003 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3005 shader
->lconst_inf_or_nan
= TRUE
;
3012 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3013 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_d3d_info
*d3d_info
)
3015 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3016 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3017 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3018 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3019 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
3020 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3021 args
->next_shader_type
= state
->shader
[WINED3D_SHADER_TYPE_HULL
] ? WINED3D_SHADER_TYPE_HULL
3022 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
] ? WINED3D_SHADER_TYPE_GEOMETRY
3023 : WINED3D_SHADER_TYPE_PIXEL
;
3024 if (shader
->reg_maps
.shader_version
.major
>= 4)
3025 args
->next_shader_input_count
= state
->shader
[WINED3D_SHADER_TYPE_HULL
]
3026 ? state
->shader
[WINED3D_SHADER_TYPE_HULL
]->limits
->packed_input
3027 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]
3028 ? state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]->limits
->packed_input
3029 : state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3030 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3032 args
->next_shader_input_count
= 0;
3033 args
->swizzle_map
= swizzle_map
;
3034 if (d3d_info
->emulated_flatshading
)
3035 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3037 args
->flatshading
= 0;
3040 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3042 if (usage_idx1
!= usage_idx2
)
3044 if (usage1
== usage2
)
3046 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3048 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3054 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3055 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3057 WORD map
= shader
->reg_maps
.input_registers
;
3060 for (i
= 0; map
; map
>>= 1, ++i
)
3062 if (!(map
& 1)) continue;
3064 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3065 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3074 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
3075 const struct wined3d_shader_signature
*src
, char **signature_strings
)
3077 struct wined3d_shader_signature_element
*e
;
3082 if (!src
->element_count
)
3085 ptr
= *signature_strings
;
3087 dst
->element_count
= src
->element_count
;
3088 if (!(dst
->elements
= wined3d_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
3089 return E_OUTOFMEMORY
;
3091 for (i
= 0; i
< src
->element_count
; ++i
)
3093 e
= &src
->elements
[i
];
3094 dst
->elements
[i
] = *e
;
3096 len
= strlen(e
->semantic_name
);
3097 memcpy(ptr
, e
->semantic_name
, len
+ 1);
3098 dst
->elements
[i
].semantic_name
= ptr
;
3102 *signature_strings
= ptr
;
3107 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3108 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
3109 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3111 struct wined3d_shader_signature_element
*e
;
3117 if (!desc
->byte_code
)
3118 return WINED3DERR_INVALIDCALL
;
3121 shader
->device
= device
;
3122 shader
->parent
= parent
;
3123 shader
->parent_ops
= parent_ops
;
3126 for (i
= 0; i
< desc
->input_signature
.element_count
; ++i
)
3128 e
= &desc
->input_signature
.elements
[i
];
3129 len
= strlen(e
->semantic_name
);
3130 if (len
>= ~(SIZE_T
)0 - total
)
3131 return E_OUTOFMEMORY
;
3135 for (i
= 0; i
< desc
->output_signature
.element_count
; ++i
)
3137 e
= &desc
->output_signature
.elements
[i
];
3138 len
= strlen(e
->semantic_name
);
3139 if (len
>= ~(SIZE_T
)0 - total
)
3140 return E_OUTOFMEMORY
;
3144 if (total
&& !(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
3145 return E_OUTOFMEMORY
;
3146 ptr
= shader
->signature_strings
;
3148 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
3150 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3153 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
3155 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3156 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3160 list_init(&shader
->linked_programs
);
3161 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3163 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
,
3164 float_const_count
, type
, desc
->max_version
)))
3166 WARN("Failed to set function, hr %#x.\n", hr
);
3167 shader_cleanup(shader
);
3170 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3175 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3176 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3178 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3182 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3183 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3186 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3188 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3190 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3193 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3194 shader_usage_from_semantic_name(input
->semantic_name
);
3195 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3198 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3199 shader
->load_local_constsF
= TRUE
;
3204 static HRESULT
domain_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3205 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3207 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
);
3210 static HRESULT
hull_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3211 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3213 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
);
3216 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3217 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3219 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
);
3222 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3223 struct gs_compile_args
*args
)
3225 args
->ps_input_count
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3226 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3229 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3230 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3232 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3233 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3234 const struct wined3d_texture
*texture
;
3237 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3238 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3240 static unsigned int warned
= 0;
3242 args
->srgb_correction
= 1;
3243 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3244 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3245 "support, expect rendering artifacts.\n");
3248 if (shader
->reg_maps
.shader_version
.major
== 1
3249 && shader
->reg_maps
.shader_version
.minor
<= 3)
3251 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3253 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3255 if (flags
& WINED3D_TTFF_PROJECTED
)
3257 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3259 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3261 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3263 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3264 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3266 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3268 struct wined3d_vertex_declaration_element
*element
=
3269 &state
->vertex_declaration
->elements
[j
];
3271 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3272 && element
->usage_idx
== index
)
3274 max_valid
= element
->format
->component_count
;
3278 if (!tex_transform
|| tex_transform
> max_valid
)
3280 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3281 tex_transform
, max_valid
);
3282 tex_transform
= max_valid
;
3284 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3285 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3286 && tex_transform
> WINED3D_TTFF_COUNT2
)
3287 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3288 && tex_transform
> WINED3D_TTFF_COUNT3
))
3289 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3292 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3293 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3294 i
, tex_transform
, resource_type
);
3298 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3300 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3304 if (shader
->reg_maps
.shader_version
.major
== 1
3305 && shader
->reg_maps
.shader_version
.minor
<= 4)
3307 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3309 const struct wined3d_texture
*texture
= state
->textures
[i
];
3311 if (!shader
->reg_maps
.resource_info
[i
].type
)
3314 /* Treat unbound textures as 2D. The dummy texture will provide
3315 * the proper sample value. The tex_types bitmap defaults to
3316 * 2D because of the memset. */
3320 switch (texture
->target
)
3322 /* RECT textures are distinguished from 2D textures via np2_fixup */
3323 case GL_TEXTURE_RECTANGLE_ARB
:
3328 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3331 case GL_TEXTURE_CUBE_MAP_ARB
:
3332 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3338 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3340 if (!shader
->reg_maps
.resource_info
[i
].type
)
3343 texture
= state
->textures
[i
];
3346 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3349 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3350 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3352 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3354 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3355 args
->shadow
|= 1u << i
;
3357 /* Flag samplers that need NP2 texcoord fixup. */
3358 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3359 args
->np2_fixup
|= (1u << i
);
3362 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3363 if (shader
->reg_maps
.shader_version
.major
>= 4)
3366 if (shader
->reg_maps
.shader_version
.major
>= 3)
3368 if (position_transformed
)
3369 args
->vp_mode
= pretransformed
;
3370 else if (use_vs(state
))
3371 args
->vp_mode
= vertexshader
;
3373 args
->vp_mode
= fixedfunction
;
3374 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3378 args
->vp_mode
= vertexshader
;
3379 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3381 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3383 case WINED3D_FOG_NONE
:
3384 if (position_transformed
|| use_vs(state
))
3386 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3390 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3392 case WINED3D_FOG_NONE
: /* Fall through. */
3393 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3394 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3395 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3399 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3400 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3401 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3406 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3410 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3412 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3414 args
->texcoords_initialized
= 0;
3415 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
3419 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
3420 args
->texcoords_initialized
|= 1u << i
;
3424 const struct wined3d_stream_info
*si
= &context
->stream_info
;
3425 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3427 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
3428 & WINED3D_FFP_TCI_MASK
3429 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
3430 args
->texcoords_initialized
|= 1u << i
;
3436 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
3439 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
3440 && state
->gl_primitive_type
== GL_POINTS
;
3442 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3443 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
3445 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
3446 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
3447 : WINED3D_CMP_ALWAYS
) - 1;
3449 if (d3d_info
->emulated_flatshading
)
3450 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3452 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
3453 ? context
->render_offscreen
: 0;
3456 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3457 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3459 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
3460 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
3463 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
3464 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
3467 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3469 if (shader
->u
.ps
.input_reg_used
[i
])
3472 highest_reg_used
= i
;
3476 /* Don't do any register mapping magic if it is not needed, or if we can't
3477 * achieve anything anyway */
3478 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
3479 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
3480 || shader
->reg_maps
.shader_version
.major
>= 4)
3482 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
3484 /* This happens with relative addressing. The input mapper function
3485 * warns about this if the higher registers are declared too, so
3486 * don't write a FIXME here */
3487 WARN("More varying registers used than supported\n");
3490 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3492 shader
->u
.ps
.input_reg_map
[i
] = i
;
3495 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
3499 shader
->u
.ps
.declared_in_count
= 0;
3500 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3502 if (shader
->u
.ps
.input_reg_used
[i
])
3503 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
3504 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
3511 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
3513 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3514 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
3517 if (reg_maps
->shader_version
.major
!= 1) return;
3519 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3521 /* We don't sample from this sampler. */
3522 if (!resource_info
[i
].type
)
3525 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
3527 case WINED3D_SHADER_TEX_2D
:
3528 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
3531 case WINED3D_SHADER_TEX_3D
:
3532 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
3535 case WINED3D_SHADER_TEX_CUBE
:
3536 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
3542 static HRESULT
compute_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3543 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3545 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
);
3548 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3549 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3551 struct wined3d_shader
*object
;
3554 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3555 device
, desc
, parent
, parent_ops
, shader
);
3557 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3558 return E_OUTOFMEMORY
;
3560 if (FAILED(hr
= compute_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3562 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
3563 HeapFree(GetProcessHeap(), 0, object
);
3567 TRACE("Created compute shader %p.\n", object
);
3573 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3574 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3576 struct wined3d_shader
*object
;
3579 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3580 device
, desc
, parent
, parent_ops
, shader
);
3582 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3583 return E_OUTOFMEMORY
;
3585 if (FAILED(hr
= domain_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3587 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
3588 HeapFree(GetProcessHeap(), 0, object
);
3592 TRACE("Created domain shader %p.\n", object
);
3598 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3599 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3601 struct wined3d_shader
*object
;
3604 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3605 device
, desc
, parent
, parent_ops
, shader
);
3607 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3609 return E_OUTOFMEMORY
;
3611 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3613 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
3614 HeapFree(GetProcessHeap(), 0, object
);
3618 TRACE("Created geometry shader %p.\n", object
);
3624 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3625 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3627 struct wined3d_shader
*object
;
3630 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3631 device
, desc
, parent
, parent_ops
, shader
);
3633 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3634 return E_OUTOFMEMORY
;
3636 if (FAILED(hr
= hull_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3638 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
3639 HeapFree(GetProcessHeap(), 0, object
);
3643 TRACE("Created hull shader %p.\n", object
);
3649 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3650 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3652 struct wined3d_shader
*object
;
3655 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3656 device
, desc
, parent
, parent_ops
, shader
);
3658 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3660 return E_OUTOFMEMORY
;
3662 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3664 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3665 HeapFree(GetProcessHeap(), 0, object
);
3669 TRACE("Created pixel shader %p.\n", object
);
3675 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3676 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3678 struct wined3d_shader
*object
;
3681 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3682 device
, desc
, parent
, parent_ops
, shader
);
3684 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3686 return E_OUTOFMEMORY
;
3688 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3690 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3691 HeapFree(GetProcessHeap(), 0, object
);
3695 TRACE("Created vertex shader %p.\n", object
);