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_VERTICES_OUT
)
1038 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1039 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1041 FIXME("Invalid instruction %#x for shader type %#x.\n",
1042 ins
.handler_idx
, shader_version
.type
);
1044 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1046 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1048 if (!lconst
) return E_OUTOFMEMORY
;
1050 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1051 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1052 value
= (float *)lconst
->value
;
1054 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1055 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1057 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1058 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1059 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1060 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1061 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1062 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1063 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1064 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1067 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1069 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1070 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1072 shader
->lconst_inf_or_nan
= TRUE
;
1075 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1077 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1078 if (!lconst
) return E_OUTOFMEMORY
;
1080 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1081 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1083 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1084 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1086 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1088 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1089 if (!lconst
) return E_OUTOFMEMORY
;
1091 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1092 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1094 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1095 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1097 /* For subroutine prototypes. */
1098 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1100 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1102 /* Set texture, address, temporary registers. */
1105 BOOL color0_mov
= FALSE
;
1108 /* This will loop over all the registers and try to
1109 * make a bitmask of the ones we're interested in.
1111 * Relative addressing tokens are ignored, but that's
1112 * okay, since we'll catch any address registers when
1113 * they are initialized (required by spec). */
1114 for (i
= 0; i
< ins
.dst_count
; ++i
)
1116 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1117 shader_version
.type
, constf_size
))
1118 return WINED3DERR_INVALIDCALL
;
1120 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1122 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1124 switch (ins
.dst
[i
].reg
.type
)
1126 case WINED3DSPR_RASTOUT
:
1127 if (shader_version
.major
>= 3)
1132 reg_maps
->output_registers
|= 1u << 10;
1133 shader_signature_from_usage(&output_signature_elements
[10],
1134 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1138 reg_maps
->output_registers
|= 1u << 11;
1139 shader_signature_from_usage(&output_signature_elements
[11],
1140 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1144 reg_maps
->output_registers
|= 1u << 11;
1145 shader_signature_from_usage(&output_signature_elements
[11],
1146 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1151 case WINED3DSPR_ATTROUT
:
1152 if (shader_version
.major
>= 3)
1157 if (reg_maps
->output_registers
& (1u << idx
))
1159 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1163 reg_maps
->output_registers
|= 1u << idx
;
1164 shader_signature_from_usage(&output_signature_elements
[idx
],
1165 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1170 case WINED3DSPR_TEXCRDOUT
:
1171 if (shader_version
.major
>= 3)
1173 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1176 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1177 if (reg_maps
->output_registers
& (1u << idx
))
1179 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1183 reg_maps
->output_registers
|= 1u << idx
;
1184 shader_signature_from_usage(&output_signature_elements
[idx
],
1185 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1194 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1196 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1198 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1199 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1200 * the mov and perform the sRGB write correction from the source register.
1202 * However, if the mov is only partial, we can't do this, and if the write
1203 * comes from an instruction other than MOV it is hard to do as well. If
1204 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1205 shader
->u
.ps
.color0_mov
= FALSE
;
1206 if (ins
.handler_idx
== WINED3DSIH_MOV
1207 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1209 /* Used later when the source register is read. */
1213 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1216 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1217 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1219 shader
->u
.ps
.color0_mov
= FALSE
;
1223 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1224 if (shader_version
.major
== 1
1225 && (ins
.handler_idx
== WINED3DSIH_TEX
1226 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1227 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1228 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1229 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1230 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1231 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1232 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1233 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1234 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1235 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1237 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1239 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1240 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1241 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1242 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1244 /* texbem is only valid with < 1.4 pixel shaders */
1245 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1246 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1248 reg_maps
->bumpmat
|= 1u << reg_idx
;
1249 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1251 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1255 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1257 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1261 if (ins
.handler_idx
== WINED3DSIH_ATOMIC_IADD
1262 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
)
1264 unsigned int reg_idx
;
1265 if (ins
.handler_idx
== WINED3DSIH_ATOMIC_IADD
)
1266 reg_idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1268 reg_idx
= ins
.src
[1].reg
.idx
[0].offset
;
1269 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1271 ERR("Invalid UAV index %u.\n", reg_idx
);
1274 reg_maps
->uav_read_mask
|= (1u << reg_idx
);
1276 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1278 reg_maps
->usesnrm
= 1;
1280 else if (ins
.handler_idx
== WINED3DSIH_DSY
1281 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1282 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1284 reg_maps
->usesdsy
= 1;
1286 else if (ins
.handler_idx
== WINED3DSIH_DSX
1287 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1288 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1290 reg_maps
->usesdsx
= 1;
1292 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1293 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1294 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1295 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1296 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1297 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1298 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1299 || ins
.handler_idx
== WINED3DSIH_REP
)
1302 if (cur_loop_depth
> max_loop_depth
)
1303 max_loop_depth
= cur_loop_depth
;
1305 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1306 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1310 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1311 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1312 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1313 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1314 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1315 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1317 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1318 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1320 else if (ins
.handler_idx
== WINED3DSIH_LD
1321 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1323 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1324 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1328 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1329 shader_version
.type
, constf_size
))
1330 return WINED3DERR_INVALIDCALL
;
1332 for (i
= 0; i
< ins
.src_count
; ++i
)
1334 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1335 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1337 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1338 shader_version
.type
, constf_size
))
1339 return WINED3DERR_INVALIDCALL
;
1342 ++reg
.idx
[0].offset
;
1343 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1344 shader_version
.type
, constf_size
))
1345 return WINED3DERR_INVALIDCALL
;
1351 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1352 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1354 shader
->u
.ps
.color0_mov
= TRUE
;
1355 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1361 reg_maps
->loop_depth
= max_loop_depth
;
1363 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1364 * R0 is written to the render target. */
1365 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1366 reg_maps
->rt_mask
|= (1u << 0);
1368 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1370 if (input_signature
->elements
)
1372 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1374 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1375 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1377 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1379 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1380 reg_maps
->usesfacing
= 1;
1384 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1386 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1387 struct wined3d_shader_signature_element
*e
;
1390 if (!(input_signature
->elements
= wined3d_calloc(count
, sizeof(*input_signature
->elements
))))
1391 return E_OUTOFMEMORY
;
1392 input_signature
->element_count
= count
;
1394 e
= input_signature
->elements
;
1395 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1397 if (!(reg_maps
->input_registers
& (1u << i
)))
1399 input_signature_elements
[i
].register_idx
= i
;
1400 *e
++ = input_signature_elements
[i
];
1404 if (output_signature
->elements
)
1406 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1408 reg_maps
->output_registers
|= 1u << output_signature
->elements
[i
].register_idx
;
1411 else if (reg_maps
->output_registers
)
1413 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1414 struct wined3d_shader_signature_element
*e
;
1416 if (!(output_signature
->elements
= wined3d_calloc(count
, sizeof(*output_signature
->elements
))))
1417 return E_OUTOFMEMORY
;
1418 output_signature
->element_count
= count
;
1420 e
= output_signature
->elements
;
1421 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1423 if (!(reg_maps
->output_registers
& (1u << i
)))
1425 *e
++ = output_signature_elements
[i
];
1432 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1434 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1436 HeapFree(GetProcessHeap(), 0, reg_maps
->constf
);
1437 HeapFree(GetProcessHeap(), 0, reg_maps
->sampler_map
.entries
);
1439 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1440 HeapFree(GetProcessHeap(), 0, reg
);
1441 list_init(®_maps
->indexable_temps
);
1444 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1446 DWORD map
= 1u << max
;
1448 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1450 return wined3d_log2i(map
);
1453 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1455 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1457 shader_addline(buffer
, "refactoringAllowed");
1458 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1460 shader_addline(buffer
, " | ");
1463 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1465 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1466 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1470 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1473 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1475 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1477 shader_addline(buffer
, "_g");
1478 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1480 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1482 shader_addline(buffer
, "_t");
1483 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1487 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1490 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1492 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1494 shader_addline(buffer
, "_glc");
1495 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1497 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1499 shader_addline(buffer
, "_opc");
1500 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1504 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1507 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1508 enum wined3d_tessellator_domain domain
)
1512 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1513 shader_addline(buffer
, "line");
1515 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1516 shader_addline(buffer
, "triangle");
1518 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1519 shader_addline(buffer
, "quad");
1522 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1527 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1528 enum wined3d_tessellator_output_primitive output_primitive
)
1530 switch (output_primitive
)
1532 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1533 shader_addline(buffer
, "point");
1535 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1536 shader_addline(buffer
, "line");
1538 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1539 shader_addline(buffer
, "triangle_cw");
1541 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1542 shader_addline(buffer
, "triangle_ccw");
1545 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1550 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1551 enum wined3d_tessellator_partitioning partitioning
)
1553 switch (partitioning
)
1555 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1556 shader_addline(buffer
, "integer");
1558 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1559 shader_addline(buffer
, "pow2");
1561 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1562 shader_addline(buffer
, "fractional_odd");
1564 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1565 shader_addline(buffer
, "fractional_even");
1568 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1573 static void shader_dump_sysval_semantic(struct wined3d_string_buffer
*buffer
, enum wined3d_sysval_semantic semantic
)
1577 for (i
= 0; i
< ARRAY_SIZE(sysval_semantic_names
); ++i
)
1579 if (sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1581 shader_addline(buffer
, "%s", sysval_semantic_names
[i
].sysval_name
);
1586 shader_addline(buffer
, "unknown_sysval_semantic(%#x)", semantic
);
1589 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1590 const struct wined3d_shader_semantic
*semantic
, const struct wined3d_shader_version
*shader_version
)
1592 shader_addline(buffer
, "dcl");
1594 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1596 switch (semantic
->resource_type
)
1598 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1599 shader_addline(buffer
, "_2d");
1602 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1603 shader_addline(buffer
, "_3d");
1606 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1607 shader_addline(buffer
, "_cube");
1611 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
1615 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
1617 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1618 shader_addline(buffer
, "_resource_");
1620 shader_addline(buffer
, "_uav_");
1621 switch (semantic
->resource_type
)
1623 case WINED3D_SHADER_RESOURCE_BUFFER
:
1624 shader_addline(buffer
, "buffer");
1627 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1628 shader_addline(buffer
, "texture1d");
1631 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1632 shader_addline(buffer
, "texture2d");
1635 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1636 shader_addline(buffer
, "texture2dms");
1639 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1640 shader_addline(buffer
, "texture3d");
1643 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1644 shader_addline(buffer
, "texturecube");
1647 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1648 shader_addline(buffer
, "texture1darray");
1651 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1652 shader_addline(buffer
, "texture2darray");
1655 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1656 shader_addline(buffer
, "texture2dmsarray");
1660 shader_addline(buffer
, "unknown");
1663 switch (semantic
->resource_data_type
)
1665 case WINED3D_DATA_FLOAT
:
1666 shader_addline(buffer
, " (float)");
1669 case WINED3D_DATA_INT
:
1670 shader_addline(buffer
, " (int)");
1673 case WINED3D_DATA_UINT
:
1674 shader_addline(buffer
, " (uint)");
1677 case WINED3D_DATA_UNORM
:
1678 shader_addline(buffer
, " (unorm)");
1681 case WINED3D_DATA_SNORM
:
1682 shader_addline(buffer
, " (snorm)");
1686 shader_addline(buffer
, " (unknown)");
1692 /* Pixel shaders 3.0 don't have usage semantics. */
1693 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
1696 shader_addline(buffer
, "_");
1698 switch (semantic
->usage
)
1700 case WINED3D_DECL_USAGE_POSITION
:
1701 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
1704 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1705 shader_addline(buffer
, "blend");
1708 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1709 shader_addline(buffer
, "weight");
1712 case WINED3D_DECL_USAGE_NORMAL
:
1713 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
1716 case WINED3D_DECL_USAGE_PSIZE
:
1717 shader_addline(buffer
, "psize");
1720 case WINED3D_DECL_USAGE_COLOR
:
1721 if (!semantic
->usage_idx
)
1722 shader_addline(buffer
, "color");
1724 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
1727 case WINED3D_DECL_USAGE_TEXCOORD
:
1728 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
1731 case WINED3D_DECL_USAGE_TANGENT
:
1732 shader_addline(buffer
, "tangent");
1735 case WINED3D_DECL_USAGE_BINORMAL
:
1736 shader_addline(buffer
, "binormal");
1739 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1740 shader_addline(buffer
, "tessfactor");
1743 case WINED3D_DECL_USAGE_POSITIONT
:
1744 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
1747 case WINED3D_DECL_USAGE_FOG
:
1748 shader_addline(buffer
, "fog");
1751 case WINED3D_DECL_USAGE_DEPTH
:
1752 shader_addline(buffer
, "depth");
1755 case WINED3D_DECL_USAGE_SAMPLE
:
1756 shader_addline(buffer
, "sample");
1760 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
1761 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
1766 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
1767 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
1769 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1770 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1771 UINT offset
= reg
->idx
[0].offset
;
1775 case WINED3DSPR_TEMP
:
1776 shader_addline(buffer
, "r");
1779 case WINED3DSPR_INPUT
:
1780 shader_addline(buffer
, "v");
1783 case WINED3DSPR_CONST
:
1784 case WINED3DSPR_CONST2
:
1785 case WINED3DSPR_CONST3
:
1786 case WINED3DSPR_CONST4
:
1787 shader_addline(buffer
, "c");
1788 offset
= shader_get_float_offset(reg
->type
, offset
);
1791 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1792 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1795 case WINED3DSPR_RASTOUT
:
1796 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
1799 case WINED3DSPR_COLOROUT
:
1800 shader_addline(buffer
, "oC");
1803 case WINED3DSPR_DEPTHOUT
:
1804 shader_addline(buffer
, "oDepth");
1807 case WINED3DSPR_ATTROUT
:
1808 shader_addline(buffer
, "oD");
1811 case WINED3DSPR_TEXCRDOUT
:
1812 /* Vertex shaders >= 3.0 use general purpose output registers
1813 * (WINED3DSPR_OUTPUT), which can include an address token. */
1814 if (shader_version
->major
>= 3)
1815 shader_addline(buffer
, "o");
1817 shader_addline(buffer
, "oT");
1820 case WINED3DSPR_CONSTINT
:
1821 shader_addline(buffer
, "i");
1824 case WINED3DSPR_CONSTBOOL
:
1825 shader_addline(buffer
, "b");
1828 case WINED3DSPR_LABEL
:
1829 shader_addline(buffer
, "l");
1832 case WINED3DSPR_LOOP
:
1833 shader_addline(buffer
, "aL");
1836 case WINED3DSPR_SAMPLER
:
1837 shader_addline(buffer
, "s");
1840 case WINED3DSPR_MISCTYPE
:
1843 FIXME("Unhandled misctype register %u.\n", offset
);
1844 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
1848 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
1852 case WINED3DSPR_PREDICATE
:
1853 shader_addline(buffer
, "p");
1856 case WINED3DSPR_IMMCONST
:
1857 shader_addline(buffer
, "l");
1860 case WINED3DSPR_CONSTBUFFER
:
1861 shader_addline(buffer
, "cb");
1864 case WINED3DSPR_IMMCONSTBUFFER
:
1865 shader_addline(buffer
, "icb");
1868 case WINED3DSPR_PRIMID
:
1869 shader_addline(buffer
, "primID");
1872 case WINED3DSPR_NULL
:
1873 shader_addline(buffer
, "null");
1876 case WINED3DSPR_RESOURCE
:
1877 shader_addline(buffer
, "t");
1880 case WINED3DSPR_UAV
:
1881 shader_addline(buffer
, "u");
1884 case WINED3DSPR_OUTPOINTID
:
1885 shader_addline(buffer
, "vOutputControlPointID");
1888 case WINED3DSPR_FORKINSTID
:
1889 shader_addline(buffer
, "vForkInstanceId");
1892 case WINED3DSPR_INCONTROLPOINT
:
1893 shader_addline(buffer
, "vicp");
1896 case WINED3DSPR_OUTCONTROLPOINT
:
1897 shader_addline(buffer
, "vocp");
1900 case WINED3DSPR_PATCHCONST
:
1901 shader_addline(buffer
, "vpc");
1904 case WINED3DSPR_TESSCOORD
:
1905 shader_addline(buffer
, "vDomainLocation");
1908 case WINED3DSPR_GROUPSHAREDMEM
:
1909 shader_addline(buffer
, "g");
1912 case WINED3DSPR_THREADID
:
1913 shader_addline(buffer
, "vThreadID");
1916 case WINED3DSPR_THREADGROUPID
:
1917 shader_addline(buffer
, "vThreadGroupID");
1920 case WINED3DSPR_LOCALTHREADID
:
1921 shader_addline(buffer
, "vThreadIDInGroup");
1924 case WINED3DSPR_LOCALTHREADINDEX
:
1925 shader_addline(buffer
, "vThreadIDInGroupFlattened");
1928 case WINED3DSPR_IDXTEMP
:
1929 shader_addline(buffer
, "x");
1932 case WINED3DSPR_STREAM
:
1933 shader_addline(buffer
, "m");
1936 case WINED3DSPR_FUNCTIONBODY
:
1937 shader_addline(buffer
, "fb");
1940 case WINED3DSPR_FUNCTIONPOINTER
:
1941 shader_addline(buffer
, "fp");
1944 case WINED3DSPR_COVERAGE
:
1945 shader_addline(buffer
, "vCoverage");
1948 case WINED3DSPR_SAMPLEMASK
:
1949 shader_addline(buffer
, "oMask");
1953 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
1957 if (reg
->type
== WINED3DSPR_IMMCONST
)
1959 shader_addline(buffer
, "(");
1960 switch (reg
->immconst_type
)
1962 case WINED3D_IMMCONST_SCALAR
:
1963 switch (reg
->data_type
)
1965 case WINED3D_DATA_FLOAT
:
1966 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
1968 case WINED3D_DATA_INT
:
1969 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
1971 case WINED3D_DATA_RESOURCE
:
1972 case WINED3D_DATA_SAMPLER
:
1973 case WINED3D_DATA_UINT
:
1974 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
1977 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1982 case WINED3D_IMMCONST_VEC4
:
1983 switch (reg
->data_type
)
1985 case WINED3D_DATA_FLOAT
:
1986 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
1987 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
1988 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
1990 case WINED3D_DATA_INT
:
1991 shader_addline(buffer
, "%d, %d, %d, %d",
1992 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
1993 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
1995 case WINED3D_DATA_RESOURCE
:
1996 case WINED3D_DATA_SAMPLER
:
1997 case WINED3D_DATA_UINT
:
1998 shader_addline(buffer
, "%u, %u, %u, %u",
1999 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2000 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2003 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2009 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2012 shader_addline(buffer
, ")");
2014 else if (reg
->type
!= WINED3DSPR_RASTOUT
2015 && reg
->type
!= WINED3DSPR_MISCTYPE
2016 && reg
->type
!= WINED3DSPR_NULL
)
2020 shader_addline(buffer
, "[");
2021 if (reg
->idx
[0].rel_addr
)
2023 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2024 shader_addline(buffer
, " + ");
2026 shader_addline(buffer
, "%u]", offset
);
2028 if (reg
->idx
[1].offset
!= ~0u)
2030 shader_addline(buffer
, "[");
2031 if (reg
->idx
[1].rel_addr
)
2033 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2034 shader_addline(buffer
, " + ");
2036 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2040 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2041 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2045 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2046 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2048 DWORD write_mask
= param
->write_mask
;
2050 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2052 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2054 static const char write_mask_chars
[] = "xyzw";
2056 shader_addline(buffer
, ".");
2057 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2058 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2059 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2060 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2061 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2062 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2063 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2064 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2068 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2069 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2071 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2072 DWORD swizzle
= param
->swizzle
;
2074 if (src_modifier
== WINED3DSPSM_NEG
2075 || src_modifier
== WINED3DSPSM_BIASNEG
2076 || src_modifier
== WINED3DSPSM_SIGNNEG
2077 || src_modifier
== WINED3DSPSM_X2NEG
2078 || src_modifier
== WINED3DSPSM_ABSNEG
)
2079 shader_addline(buffer
, "-");
2080 else if (src_modifier
== WINED3DSPSM_COMP
)
2081 shader_addline(buffer
, "1-");
2082 else if (src_modifier
== WINED3DSPSM_NOT
)
2083 shader_addline(buffer
, "!");
2085 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2086 shader_addline(buffer
, "abs(");
2088 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2090 switch (src_modifier
)
2092 case WINED3DSPSM_NONE
: break;
2093 case WINED3DSPSM_NEG
: break;
2094 case WINED3DSPSM_NOT
: break;
2095 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2096 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2097 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2098 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2099 case WINED3DSPSM_COMP
: break;
2100 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2101 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2102 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2103 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2104 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2105 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2106 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2109 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2111 static const char swizzle_chars
[] = "xyzw";
2112 DWORD swizzle_x
= swizzle
& 0x03;
2113 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2114 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2115 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2117 if (swizzle_x
== swizzle_y
2118 && swizzle_x
== swizzle_z
2119 && swizzle_x
== swizzle_w
)
2121 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2125 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2126 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2131 /* Shared code in order to generate the bulk of the shader string.
2132 * NOTE: A description of how to parse tokens can be found on MSDN. */
2133 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2134 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
2136 struct wined3d_device
*device
= shader
->device
;
2137 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2138 void *fe_data
= shader
->frontend_data
;
2139 struct wined3d_shader_version shader_version
;
2140 struct wined3d_shader_parser_state state
;
2141 struct wined3d_shader_instruction ins
;
2142 struct wined3d_shader_tex_mx tex_mx
;
2143 struct wined3d_shader_context ctx
;
2144 const DWORD
*ptr
= byte_code
;
2146 /* Initialize current parsing state. */
2147 tex_mx
.current_row
= 0;
2148 state
.current_loop_depth
= 0;
2149 state
.current_loop_reg
= 0;
2150 state
.in_subroutine
= FALSE
;
2152 ctx
.shader
= shader
;
2153 ctx
.gl_info
= &device
->adapter
->gl_info
;
2154 ctx
.reg_maps
= reg_maps
;
2155 ctx
.buffer
= buffer
;
2156 ctx
.tex_mx
= &tex_mx
;
2158 ctx
.backend_data
= backend_ctx
;
2161 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2163 while (!fe
->shader_is_end(fe_data
, &ptr
))
2166 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2168 /* Unknown opcode and its parameters. */
2169 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2171 TRACE("Skipping unrecognized instruction.\n");
2176 FIXME("Predicates not implemented.\n");
2178 /* Call appropriate function for output target */
2179 device
->shader_backend
->shader_handle_instruction(&ins
);
2183 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2184 const struct wined3d_shader_dst_param
*dst
)
2186 DWORD mmask
= dst
->modifiers
;
2191 case 13: shader_addline(buffer
, "_d8"); break;
2192 case 14: shader_addline(buffer
, "_d4"); break;
2193 case 15: shader_addline(buffer
, "_d2"); break;
2194 case 1: shader_addline(buffer
, "_x2"); break;
2195 case 2: shader_addline(buffer
, "_x4"); break;
2196 case 3: shader_addline(buffer
, "_x8"); break;
2197 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2200 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2201 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2202 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2204 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2205 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2208 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2209 enum wined3d_primitive_type primitive_type
)
2211 switch (primitive_type
)
2213 case WINED3D_PT_UNDEFINED
:
2214 shader_addline(buffer
, "undefined");
2216 case WINED3D_PT_POINTLIST
:
2217 shader_addline(buffer
, "pointlist");
2219 case WINED3D_PT_LINELIST
:
2220 shader_addline(buffer
, "linelist");
2222 case WINED3D_PT_LINESTRIP
:
2223 shader_addline(buffer
, "linestrip");
2225 case WINED3D_PT_TRIANGLELIST
:
2226 shader_addline(buffer
, "trianglelist");
2228 case WINED3D_PT_TRIANGLESTRIP
:
2229 shader_addline(buffer
, "trianglestrip");
2231 case WINED3D_PT_TRIANGLEFAN
:
2232 shader_addline(buffer
, "trianglefan");
2234 case WINED3D_PT_LINELIST_ADJ
:
2235 shader_addline(buffer
, "linelist_adj");
2237 case WINED3D_PT_LINESTRIP_ADJ
:
2238 shader_addline(buffer
, "linestrip_adj");
2240 case WINED3D_PT_TRIANGLELIST_ADJ
:
2241 shader_addline(buffer
, "trianglelist_adj");
2243 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2244 shader_addline(buffer
, "trianglestrip_adj");
2247 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
);
2252 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2253 enum wined3d_shader_interpolation_mode interpolation_mode
)
2255 switch (interpolation_mode
)
2257 case WINED3DSIM_CONSTANT
:
2258 shader_addline(buffer
, "constant");
2260 case WINED3DSIM_LINEAR
:
2261 shader_addline(buffer
, "linear");
2263 case WINED3DSIM_LINEAR_CENTROID
:
2264 shader_addline(buffer
, "linear centroid");
2266 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2267 shader_addline(buffer
, "linear noperspective");
2269 case WINED3DSIM_LINEAR_SAMPLE
:
2270 shader_addline(buffer
, "linear sample");
2272 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2273 shader_addline(buffer
, "linear noperspective centroid");
2275 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2276 shader_addline(buffer
, "linear noperspective sample");
2279 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2284 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
2286 struct wined3d_shader_version shader_version
;
2287 struct wined3d_string_buffer buffer
;
2288 const DWORD
*ptr
= byte_code
;
2289 const char *type_prefix
;
2293 if (!string_buffer_init(&buffer
))
2295 ERR("Failed to initialize string buffer.\n");
2299 TRACE("Parsing %p.\n", byte_code
);
2301 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2303 switch (shader_version
.type
)
2305 case WINED3D_SHADER_TYPE_VERTEX
:
2309 case WINED3D_SHADER_TYPE_HULL
:
2313 case WINED3D_SHADER_TYPE_DOMAIN
:
2317 case WINED3D_SHADER_TYPE_GEOMETRY
:
2321 case WINED3D_SHADER_TYPE_PIXEL
:
2325 case WINED3D_SHADER_TYPE_COMPUTE
:
2330 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2331 type_prefix
= "unknown";
2335 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2337 while (!fe
->shader_is_end(fe_data
, &ptr
))
2339 struct wined3d_shader_instruction ins
;
2341 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2342 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2344 WARN("Skipping unrecognized instruction.\n");
2345 shader_addline(&buffer
, "<unrecognized instruction>\n");
2349 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2351 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, &shader_version
);
2352 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2353 shader_addline(&buffer
, " ");
2354 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2356 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2358 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2359 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2360 shader_addline(&buffer
, ", %s",
2361 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2363 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2365 shader_addline(&buffer
, "%s fb%u",
2366 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2368 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2370 shader_addline(&buffer
, "%s ft%u = {...}",
2371 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2373 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2375 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2376 shader_dump_global_flags(&buffer
, ins
.flags
);
2378 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2380 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2381 ins
.declaration
.max_tessellation_factor
);
2383 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2385 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2386 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2388 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2389 ins
.declaration
.icb
->data
[4 * i
+ 0],
2390 ins
.declaration
.icb
->data
[4 * i
+ 1],
2391 ins
.declaration
.icb
->data
[4 * i
+ 2],
2392 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2394 shader_addline(&buffer
, "}");
2396 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2398 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2399 ins
.declaration
.indexable_temp
.register_idx
,
2400 ins
.declaration
.indexable_temp
.register_size
,
2401 ins
.declaration
.indexable_temp
.component_count
);
2403 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2405 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2406 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2407 shader_addline(&buffer
, " ");
2408 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2410 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2411 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2412 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2413 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2415 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2416 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2417 shader_addline(&buffer
, ", ");
2418 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2420 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2422 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2423 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2424 shader_addline(&buffer
, " ");
2425 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2426 shader_addline(&buffer
, ", ");
2427 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2429 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2430 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2432 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2433 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2435 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2436 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2438 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2439 shader_dump_primitive_type(&buffer
, ins
.declaration
.primitive_type
);
2441 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2443 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2444 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2445 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2447 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2449 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2450 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2452 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2454 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2455 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2456 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2458 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2460 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2461 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2462 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2463 shader_addline(&buffer
, ", comparisonMode");
2465 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2466 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
2467 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2468 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2469 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
2471 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2473 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2475 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2476 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2478 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2480 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2481 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2483 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2485 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2486 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2488 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2490 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2491 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2492 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2494 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2496 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2497 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2498 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2499 ins
.declaration
.tgsm_structured
.structure_count
);
2501 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2503 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2504 ins
.declaration
.thread_group_size
.x
,
2505 ins
.declaration
.thread_group_size
.y
,
2506 ins
.declaration
.thread_group_size
.z
);
2508 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2510 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2511 shader_dump_uav_flags(&buffer
, ins
.flags
);
2512 shader_addline(&buffer
, " ");
2513 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2515 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2517 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2518 shader_dump_uav_flags(&buffer
, ins
.flags
);
2519 shader_addline(&buffer
, " ");
2520 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2521 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2523 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2525 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2526 ins
.dst
[0].reg
.idx
[0].offset
),
2527 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
2528 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
2529 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
2530 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
2532 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2534 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2535 ins
.src
[0].reg
.u
.immconst_data
[0],
2536 ins
.src
[0].reg
.u
.immconst_data
[1],
2537 ins
.src
[0].reg
.u
.immconst_data
[2],
2538 ins
.src
[0].reg
.u
.immconst_data
[3]);
2540 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2542 shader_addline(&buffer
, "defb b%u = %s",
2543 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
2549 shader_addline(&buffer
, "(");
2550 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2551 shader_addline(&buffer
, ") ");
2554 /* PixWin marks instructions with the coissue flag with a '+' */
2556 shader_addline(&buffer
, "+");
2558 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2560 if (ins
.handler_idx
== WINED3DSIH_BREAKP
2561 || ins
.handler_idx
== WINED3DSIH_IF
)
2565 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
2566 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
2567 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
2570 else if (ins
.handler_idx
== WINED3DSIH_IFC
2571 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
2575 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
2576 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
2577 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
2578 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
2579 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
2580 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
2581 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
2584 else if (ins
.handler_idx
== WINED3DSIH_TEX
2585 && shader_version
.major
>= 2
2586 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
2588 shader_addline(&buffer
, "p");
2590 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
2594 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
2595 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2596 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2599 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
2603 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2604 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2607 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
2609 shader_dump_sync_flags(&buffer
, ins
.flags
);
2612 if (wined3d_shader_instruction_has_texel_offset(&ins
))
2613 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
2615 for (i
= 0; i
< ins
.dst_count
; ++i
)
2617 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
2618 shader_addline(&buffer
, !i
? " " : ", ");
2619 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
2622 /* Other source tokens */
2623 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
2625 shader_addline(&buffer
, !i
? " " : ", ");
2626 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
2629 shader_addline(&buffer
, "\n");
2632 for (p
= buffer
.buffer
; *p
; p
= q
)
2634 if (!(q
= strstr(p
, "\n")))
2638 TRACE(" %.*s", (int)(q
- p
), p
);
2641 string_buffer_free(&buffer
);
2644 static void shader_cleanup(struct wined3d_shader
*shader
)
2646 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
2647 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2648 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2649 shader
->device
->shader_backend
->shader_destroy(shader
);
2650 shader_cleanup_reg_maps(&shader
->reg_maps
);
2651 HeapFree(GetProcessHeap(), 0, shader
->function
);
2652 shader_delete_constant_list(&shader
->constantsF
);
2653 shader_delete_constant_list(&shader
->constantsB
);
2654 shader_delete_constant_list(&shader
->constantsI
);
2655 list_remove(&shader
->shader_list_entry
);
2657 if (shader
->frontend
&& shader
->frontend_data
)
2658 shader
->frontend
->shader_free(shader
->frontend_data
);
2661 struct shader_none_priv
2663 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
2664 const struct fragment_pipeline
*fragment_pipe
;
2665 BOOL ffp_proj_control
;
2668 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
2669 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
2670 const struct wined3d_state
*state
) {}
2671 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2672 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2673 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
2674 const struct wined3d_state
*state
) {}
2675 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
2676 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
2677 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
2679 /* Context activation is done by the caller. */
2680 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
2681 const struct wined3d_state
*state
)
2683 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2684 struct shader_none_priv
*priv
= shader_priv
;
2686 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
2687 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
2690 /* Context activation is done by the caller. */
2691 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
2693 struct shader_none_priv
*priv
= shader_priv
;
2694 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2696 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
2697 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
2699 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
2700 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
2701 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
2702 | (1u << WINED3D_SHADER_TYPE_HULL
)
2703 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
2704 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
2707 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
2708 const struct fragment_pipeline
*fragment_pipe
)
2710 struct fragment_caps fragment_caps
;
2711 void *vertex_priv
, *fragment_priv
;
2712 struct shader_none_priv
*priv
;
2714 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
2715 return E_OUTOFMEMORY
;
2717 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
2719 ERR("Failed to initialize vertex pipe.\n");
2720 HeapFree(GetProcessHeap(), 0, priv
);
2724 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
2726 ERR("Failed to initialize fragment pipe.\n");
2727 vertex_pipe
->vp_free(device
);
2728 HeapFree(GetProcessHeap(), 0, priv
);
2732 priv
->vertex_pipe
= vertex_pipe
;
2733 priv
->fragment_pipe
= fragment_pipe
;
2734 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
2735 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
2737 device
->vertex_priv
= vertex_priv
;
2738 device
->fragment_priv
= fragment_priv
;
2739 device
->shader_priv
= priv
;
2744 static void shader_none_free(struct wined3d_device
*device
)
2746 struct shader_none_priv
*priv
= device
->shader_priv
;
2748 priv
->fragment_pipe
->free_private(device
);
2749 priv
->vertex_pipe
->vp_free(device
);
2750 HeapFree(GetProcessHeap(), 0, priv
);
2753 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
2758 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
2760 /* Set the shader caps to 0 for the none shader backend */
2761 caps
->vs_version
= 0;
2762 caps
->hs_version
= 0;
2763 caps
->ds_version
= 0;
2764 caps
->gs_version
= 0;
2765 caps
->ps_version
= 0;
2766 caps
->cs_version
= 0;
2767 caps
->vs_uniform_count
= 0;
2768 caps
->ps_uniform_count
= 0;
2769 caps
->ps_1x_max_value
= 0.0f
;
2770 caps
->varying_count
= 0;
2771 caps
->wined3d_caps
= 0;
2774 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2776 /* We "support" every possible fixup, since we don't support any shader
2777 * model, and will never have to actually sample a texture. */
2781 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2783 struct shader_none_priv
*priv
= shader_priv
;
2785 return priv
->ffp_proj_control
;
2788 const struct wined3d_shader_backend_ops none_shader_backend
=
2790 shader_none_handle_instruction
,
2792 shader_none_select_compute
,
2793 shader_none_disable
,
2794 shader_none_update_float_vertex_constants
,
2795 shader_none_update_float_pixel_constants
,
2796 shader_none_load_constants
,
2797 shader_none_destroy
,
2800 shader_none_allocate_context_data
,
2801 shader_none_free_context_data
,
2802 shader_none_init_context_state
,
2803 shader_none_get_caps
,
2804 shader_none_color_fixup_supported
,
2805 shader_none_has_ffp_proj_control
,
2808 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
2809 DWORD float_const_count
, enum wined3d_shader_type type
, unsigned int max_version
)
2811 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2812 const struct wined3d_shader_frontend
*fe
;
2814 unsigned int backend_version
;
2815 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2817 TRACE("shader %p, byte_code %p, float_const_count %u, type %#x, max_version %u.\n",
2818 shader
, byte_code
, float_const_count
, type
, max_version
);
2820 list_init(&shader
->constantsF
);
2821 list_init(&shader
->constantsB
);
2822 list_init(&shader
->constantsI
);
2823 shader
->lconst_inf_or_nan
= FALSE
;
2824 list_init(®_maps
->indexable_temps
);
2826 fe
= shader_select_frontend(*byte_code
);
2829 FIXME("Unable to find frontend for shader.\n");
2830 return WINED3DERR_INVALIDCALL
;
2832 shader
->frontend
= fe
;
2833 shader
->frontend_data
= fe
->shader_init(byte_code
, &shader
->output_signature
);
2834 if (!shader
->frontend_data
)
2836 FIXME("Failed to initialize frontend.\n");
2837 return WINED3DERR_INVALIDCALL
;
2840 /* First pass: trace shader. */
2841 if (TRACE_ON(d3d_shader
))
2842 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
2844 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2845 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2846 &shader
->output_signature
, byte_code
, float_const_count
)))
2849 if (reg_maps
->shader_version
.type
!= type
)
2851 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2852 return WINED3DERR_INVALIDCALL
;
2854 if (reg_maps
->shader_version
.major
> max_version
)
2856 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2857 return WINED3DERR_INVALIDCALL
;
2861 case WINED3D_SHADER_TYPE_VERTEX
:
2862 backend_version
= d3d_info
->limits
.vs_version
;
2864 case WINED3D_SHADER_TYPE_HULL
:
2865 backend_version
= d3d_info
->limits
.hs_version
;
2867 case WINED3D_SHADER_TYPE_DOMAIN
:
2868 backend_version
= d3d_info
->limits
.ds_version
;
2870 case WINED3D_SHADER_TYPE_GEOMETRY
:
2871 backend_version
= d3d_info
->limits
.gs_version
;
2873 case WINED3D_SHADER_TYPE_PIXEL
:
2874 backend_version
= d3d_info
->limits
.ps_version
;
2876 case WINED3D_SHADER_TYPE_COMPUTE
:
2877 backend_version
= d3d_info
->limits
.cs_version
;
2880 FIXME("No backend version-checking for this shader type.\n");
2881 backend_version
= 0;
2883 if (reg_maps
->shader_version
.major
> backend_version
)
2885 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2886 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2887 return WINED3DERR_INVALIDCALL
;
2890 if (!(shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
)))
2891 return E_OUTOFMEMORY
;
2892 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2897 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2899 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2901 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2906 static void wined3d_shader_destroy_object(void *object
)
2908 shader_cleanup(object
);
2909 HeapFree(GetProcessHeap(), 0, object
);
2912 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2914 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2916 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2920 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2921 wined3d_cs_emit_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
2927 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2929 TRACE("shader %p.\n", shader
);
2931 return shader
->parent
;
2934 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2935 void *byte_code
, UINT
*byte_code_size
)
2937 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2941 *byte_code_size
= shader
->functionLength
;
2945 if (*byte_code_size
< shader
->functionLength
)
2947 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2948 * than the required size we should write the required size and
2949 * return D3DERR_MOREDATA. That's not actually true. */
2950 return WINED3DERR_INVALIDCALL
;
2953 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2958 /* Set local constants for d3d8 shaders. */
2959 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2960 UINT start_idx
, const float *src_data
, UINT count
)
2962 UINT end_idx
= start_idx
+ count
;
2965 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2967 if (end_idx
> shader
->limits
->constant_float
)
2969 WARN("end_idx %u > float constants limit %u.\n",
2970 end_idx
, shader
->limits
->constant_float
);
2971 end_idx
= shader
->limits
->constant_float
;
2974 for (i
= start_idx
; i
< end_idx
; ++i
)
2976 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2979 return E_OUTOFMEMORY
;
2982 value
= (float *)lconst
->value
;
2983 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
2984 list_add_head(&shader
->constantsF
, &lconst
->entry
);
2986 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
2987 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
2989 shader
->lconst_inf_or_nan
= TRUE
;
2996 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2997 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_d3d_info
*d3d_info
)
2999 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3000 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3001 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3002 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3003 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
3004 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3005 args
->next_shader_type
= state
->shader
[WINED3D_SHADER_TYPE_HULL
] ? WINED3D_SHADER_TYPE_HULL
3006 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
] ? WINED3D_SHADER_TYPE_GEOMETRY
3007 : WINED3D_SHADER_TYPE_PIXEL
;
3008 if (shader
->reg_maps
.shader_version
.major
>= 4)
3009 args
->next_shader_input_count
= state
->shader
[WINED3D_SHADER_TYPE_HULL
]
3010 ? state
->shader
[WINED3D_SHADER_TYPE_HULL
]->limits
->packed_input
3011 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]
3012 ? state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]->limits
->packed_input
3013 : state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3014 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3016 args
->next_shader_input_count
= 0;
3017 args
->swizzle_map
= swizzle_map
;
3018 if (d3d_info
->emulated_flatshading
)
3019 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3021 args
->flatshading
= 0;
3024 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3026 if (usage_idx1
!= usage_idx2
)
3028 if (usage1
== usage2
)
3030 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3032 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3038 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3039 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3041 WORD map
= shader
->reg_maps
.input_registers
;
3044 for (i
= 0; map
; map
>>= 1, ++i
)
3046 if (!(map
& 1)) continue;
3048 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3049 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3058 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
3059 const struct wined3d_shader_signature
*src
, char **signature_strings
)
3061 struct wined3d_shader_signature_element
*e
;
3066 if (!src
->element_count
)
3069 ptr
= *signature_strings
;
3071 dst
->element_count
= src
->element_count
;
3072 if (!(dst
->elements
= wined3d_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
3073 return E_OUTOFMEMORY
;
3075 for (i
= 0; i
< src
->element_count
; ++i
)
3077 e
= &src
->elements
[i
];
3078 dst
->elements
[i
] = *e
;
3080 len
= strlen(e
->semantic_name
);
3081 memcpy(ptr
, e
->semantic_name
, len
+ 1);
3082 dst
->elements
[i
].semantic_name
= ptr
;
3086 *signature_strings
= ptr
;
3091 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3092 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
3093 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3095 struct wined3d_shader_signature_element
*e
;
3101 if (!desc
->byte_code
)
3102 return WINED3DERR_INVALIDCALL
;
3105 shader
->device
= device
;
3106 shader
->parent
= parent
;
3107 shader
->parent_ops
= parent_ops
;
3110 for (i
= 0; i
< desc
->input_signature
.element_count
; ++i
)
3112 e
= &desc
->input_signature
.elements
[i
];
3113 len
= strlen(e
->semantic_name
);
3114 if (len
>= ~(SIZE_T
)0 - total
)
3115 return E_OUTOFMEMORY
;
3119 for (i
= 0; i
< desc
->output_signature
.element_count
; ++i
)
3121 e
= &desc
->output_signature
.elements
[i
];
3122 len
= strlen(e
->semantic_name
);
3123 if (len
>= ~(SIZE_T
)0 - total
)
3124 return E_OUTOFMEMORY
;
3128 if (total
&& !(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
3129 return E_OUTOFMEMORY
;
3130 ptr
= shader
->signature_strings
;
3132 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
3134 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3137 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
3139 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3140 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3144 list_init(&shader
->linked_programs
);
3145 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3147 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
,
3148 float_const_count
, type
, desc
->max_version
)))
3150 WARN("Failed to set function, hr %#x.\n", hr
);
3151 shader_cleanup(shader
);
3154 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3159 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3160 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3162 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3166 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3167 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3170 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3172 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3174 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3177 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3178 shader_usage_from_semantic_name(input
->semantic_name
);
3179 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3182 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3183 shader
->load_local_constsF
= TRUE
;
3188 static HRESULT
domain_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3189 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3191 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
);
3194 static HRESULT
hull_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3195 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3197 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
);
3200 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3201 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3203 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
);
3206 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3207 struct gs_compile_args
*args
)
3209 args
->ps_input_count
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3210 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3213 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3214 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3216 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3217 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3218 const struct wined3d_texture
*texture
;
3221 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3222 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3224 static unsigned int warned
= 0;
3226 args
->srgb_correction
= 1;
3227 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3228 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3229 "support, expect rendering artifacts.\n");
3232 if (shader
->reg_maps
.shader_version
.major
== 1
3233 && shader
->reg_maps
.shader_version
.minor
<= 3)
3235 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3237 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3239 if (flags
& WINED3D_TTFF_PROJECTED
)
3241 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3243 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3245 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3247 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3248 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3250 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3252 struct wined3d_vertex_declaration_element
*element
=
3253 &state
->vertex_declaration
->elements
[j
];
3255 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3256 && element
->usage_idx
== index
)
3258 max_valid
= element
->format
->component_count
;
3262 if (!tex_transform
|| tex_transform
> max_valid
)
3264 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3265 tex_transform
, max_valid
);
3266 tex_transform
= max_valid
;
3268 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3269 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3270 && tex_transform
> WINED3D_TTFF_COUNT2
)
3271 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3272 && tex_transform
> WINED3D_TTFF_COUNT3
))
3273 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3276 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3277 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3278 i
, tex_transform
, resource_type
);
3282 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3284 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3288 if (shader
->reg_maps
.shader_version
.major
== 1
3289 && shader
->reg_maps
.shader_version
.minor
<= 4)
3291 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3293 const struct wined3d_texture
*texture
= state
->textures
[i
];
3295 if (!shader
->reg_maps
.resource_info
[i
].type
)
3298 /* Treat unbound textures as 2D. The dummy texture will provide
3299 * the proper sample value. The tex_types bitmap defaults to
3300 * 2D because of the memset. */
3304 switch (texture
->target
)
3306 /* RECT textures are distinguished from 2D textures via np2_fixup */
3307 case GL_TEXTURE_RECTANGLE_ARB
:
3312 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3315 case GL_TEXTURE_CUBE_MAP_ARB
:
3316 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3322 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3324 if (!shader
->reg_maps
.resource_info
[i
].type
)
3327 texture
= state
->textures
[i
];
3330 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3333 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3334 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3336 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3338 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3339 args
->shadow
|= 1u << i
;
3341 /* Flag samplers that need NP2 texcoord fixup. */
3342 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3343 args
->np2_fixup
|= (1u << i
);
3346 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3347 if (shader
->reg_maps
.shader_version
.major
>= 4)
3350 if (shader
->reg_maps
.shader_version
.major
>= 3)
3352 if (position_transformed
)
3353 args
->vp_mode
= pretransformed
;
3354 else if (use_vs(state
))
3355 args
->vp_mode
= vertexshader
;
3357 args
->vp_mode
= fixedfunction
;
3358 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3362 args
->vp_mode
= vertexshader
;
3363 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3365 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3367 case WINED3D_FOG_NONE
:
3368 if (position_transformed
|| use_vs(state
))
3370 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3374 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3376 case WINED3D_FOG_NONE
: /* Fall through. */
3377 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3378 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3379 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3383 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3384 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3385 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3390 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3394 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3396 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3398 args
->texcoords_initialized
= 0;
3399 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
3403 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
3404 args
->texcoords_initialized
|= 1u << i
;
3408 const struct wined3d_stream_info
*si
= &context
->stream_info
;
3409 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3411 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
3412 & WINED3D_FFP_TCI_MASK
3413 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
3414 args
->texcoords_initialized
|= 1u << i
;
3420 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
3423 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
3424 && state
->gl_primitive_type
== GL_POINTS
;
3426 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3427 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
3429 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
3430 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
3431 : WINED3D_CMP_ALWAYS
) - 1;
3433 if (d3d_info
->emulated_flatshading
)
3434 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3436 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
3437 ? context
->render_offscreen
: 0;
3440 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3441 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3443 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
3444 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
3447 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
3448 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
3451 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3453 if (shader
->u
.ps
.input_reg_used
[i
])
3456 highest_reg_used
= i
;
3460 /* Don't do any register mapping magic if it is not needed, or if we can't
3461 * achieve anything anyway */
3462 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
3463 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
3464 || shader
->reg_maps
.shader_version
.major
>= 4)
3466 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
3468 /* This happens with relative addressing. The input mapper function
3469 * warns about this if the higher registers are declared too, so
3470 * don't write a FIXME here */
3471 WARN("More varying registers used than supported\n");
3474 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3476 shader
->u
.ps
.input_reg_map
[i
] = i
;
3479 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
3483 shader
->u
.ps
.declared_in_count
= 0;
3484 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3486 if (shader
->u
.ps
.input_reg_used
[i
])
3487 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
3488 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
3495 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
3497 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3498 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
3501 if (reg_maps
->shader_version
.major
!= 1) return;
3503 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3505 /* We don't sample from this sampler. */
3506 if (!resource_info
[i
].type
)
3509 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
3511 case WINED3D_SHADER_TEX_2D
:
3512 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
3515 case WINED3D_SHADER_TEX_3D
:
3516 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
3519 case WINED3D_SHADER_TEX_CUBE
:
3520 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
3526 static HRESULT
compute_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3527 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3529 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
);
3532 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3533 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3535 struct wined3d_shader
*object
;
3538 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3539 device
, desc
, parent
, parent_ops
, shader
);
3541 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3542 return E_OUTOFMEMORY
;
3544 if (FAILED(hr
= compute_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3546 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
3547 HeapFree(GetProcessHeap(), 0, object
);
3551 TRACE("Created compute shader %p.\n", object
);
3557 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3558 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3560 struct wined3d_shader
*object
;
3563 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3564 device
, desc
, parent
, parent_ops
, shader
);
3566 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3567 return E_OUTOFMEMORY
;
3569 if (FAILED(hr
= domain_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3571 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
3572 HeapFree(GetProcessHeap(), 0, object
);
3576 TRACE("Created domain shader %p.\n", object
);
3582 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3583 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3585 struct wined3d_shader
*object
;
3588 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3589 device
, desc
, parent
, parent_ops
, shader
);
3591 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3593 return E_OUTOFMEMORY
;
3595 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3597 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
3598 HeapFree(GetProcessHeap(), 0, object
);
3602 TRACE("Created geometry shader %p.\n", object
);
3608 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3609 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3611 struct wined3d_shader
*object
;
3614 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3615 device
, desc
, parent
, parent_ops
, shader
);
3617 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3618 return E_OUTOFMEMORY
;
3620 if (FAILED(hr
= hull_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3622 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
3623 HeapFree(GetProcessHeap(), 0, object
);
3627 TRACE("Created hull shader %p.\n", object
);
3633 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3634 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3636 struct wined3d_shader
*object
;
3639 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3640 device
, desc
, parent
, parent_ops
, shader
);
3642 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3644 return E_OUTOFMEMORY
;
3646 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3648 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3649 HeapFree(GetProcessHeap(), 0, object
);
3653 TRACE("Created pixel shader %p.\n", object
);
3659 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3660 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3662 struct wined3d_shader
*object
;
3665 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3666 device
, desc
, parent
, parent_ops
, shader
);
3668 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3670 return E_OUTOFMEMORY
;
3672 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3674 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3675 HeapFree(GetProcessHeap(), 0, object
);
3679 TRACE("Created vertex shader %p.\n", object
);