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_IMAX */ "imm_atomic_imax",
167 /* WINED3DSIH_IMM_ATOMIC_IMIN */ "imm_atomic_imin",
168 /* WINED3DSIH_IMM_ATOMIC_OR */ "imm_atomic_or",
169 /* WINED3DSIH_IMM_ATOMIC_UMAX */ "imm_atomic_umax",
170 /* WINED3DSIH_IMM_ATOMIC_UMIN */ "imm_atomic_umin",
171 /* WINED3DSIH_IMM_ATOMIC_XOR */ "imm_atomic_xor",
172 /* WINED3DSIH_IMUL */ "imul",
173 /* WINED3DSIH_INE */ "ine",
174 /* WINED3DSIH_INEG */ "ineg",
175 /* WINED3DSIH_ISHL */ "ishl",
176 /* WINED3DSIH_ISHR */ "ishr",
177 /* WINED3DSIH_ITOF */ "itof",
178 /* WINED3DSIH_LABEL */ "label",
179 /* WINED3DSIH_LD */ "ld",
180 /* WINED3DSIH_LD2DMS */ "ld2dms",
181 /* WINED3DSIH_LD_RAW */ "ld_raw",
182 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
183 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
184 /* WINED3DSIH_LIT */ "lit",
185 /* WINED3DSIH_LOD */ "lod",
186 /* WINED3DSIH_LOG */ "log",
187 /* WINED3DSIH_LOGP */ "logp",
188 /* WINED3DSIH_LOOP */ "loop",
189 /* WINED3DSIH_LRP */ "lrp",
190 /* WINED3DSIH_LT */ "lt",
191 /* WINED3DSIH_M3x2 */ "m3x2",
192 /* WINED3DSIH_M3x3 */ "m3x3",
193 /* WINED3DSIH_M3x4 */ "m3x4",
194 /* WINED3DSIH_M4x3 */ "m4x3",
195 /* WINED3DSIH_M4x4 */ "m4x4",
196 /* WINED3DSIH_MAD */ "mad",
197 /* WINED3DSIH_MAX */ "max",
198 /* WINED3DSIH_MIN */ "min",
199 /* WINED3DSIH_MOV */ "mov",
200 /* WINED3DSIH_MOVA */ "mova",
201 /* WINED3DSIH_MOVC */ "movc",
202 /* WINED3DSIH_MUL */ "mul",
203 /* WINED3DSIH_NE */ "ne",
204 /* WINED3DSIH_NOP */ "nop",
205 /* WINED3DSIH_NOT */ "not",
206 /* WINED3DSIH_NRM */ "nrm",
207 /* WINED3DSIH_OR */ "or",
208 /* WINED3DSIH_PHASE */ "phase",
209 /* WINED3DSIH_POW */ "pow",
210 /* WINED3DSIH_RCP */ "rcp",
211 /* WINED3DSIH_REP */ "rep",
212 /* WINED3DSIH_RESINFO */ "resinfo",
213 /* WINED3DSIH_RET */ "ret",
214 /* WINED3DSIH_ROUND_NE */ "round_ne",
215 /* WINED3DSIH_ROUND_NI */ "round_ni",
216 /* WINED3DSIH_ROUND_PI */ "round_pi",
217 /* WINED3DSIH_ROUND_Z */ "round_z",
218 /* WINED3DSIH_RSQ */ "rsq",
219 /* WINED3DSIH_SAMPLE */ "sample",
220 /* WINED3DSIH_SAMPLE_B */ "sample_b",
221 /* WINED3DSIH_SAMPLE_C */ "sample_c",
222 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
223 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
224 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
225 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
226 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
227 /* WINED3DSIH_SETP */ "setp",
228 /* WINED3DSIH_SGE */ "sge",
229 /* WINED3DSIH_SGN */ "sgn",
230 /* WINED3DSIH_SINCOS */ "sincos",
231 /* WINED3DSIH_SLT */ "slt",
232 /* WINED3DSIH_SQRT */ "sqrt",
233 /* WINED3DSIH_STORE_RAW */ "store_raw",
234 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
235 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
236 /* WINED3DSIH_SUB */ "sub",
237 /* WINED3DSIH_SWAPC */ "swapc",
238 /* WINED3DSIH_SWITCH */ "switch",
239 /* WINED3DSIH_SYNC */ "sync",
240 /* WINED3DSIH_TEX */ "texld",
241 /* WINED3DSIH_TEXBEM */ "texbem",
242 /* WINED3DSIH_TEXBEML */ "texbeml",
243 /* WINED3DSIH_TEXCOORD */ "texcrd",
244 /* WINED3DSIH_TEXDEPTH */ "texdepth",
245 /* WINED3DSIH_TEXDP3 */ "texdp3",
246 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
247 /* WINED3DSIH_TEXKILL */ "texkill",
248 /* WINED3DSIH_TEXLDD */ "texldd",
249 /* WINED3DSIH_TEXLDL */ "texldl",
250 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
251 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
252 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
253 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
254 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
255 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
256 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
257 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
258 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
259 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
260 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
261 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
262 /* WINED3DSIH_UBFE */ "ubfe",
263 /* WINED3DSIH_UDIV */ "udiv",
264 /* WINED3DSIH_UGE */ "uge",
265 /* WINED3DSIH_ULT */ "ult",
266 /* WINED3DSIH_UMAX */ "umax",
267 /* WINED3DSIH_UMIN */ "umin",
268 /* WINED3DSIH_USHR */ "ushr",
269 /* WINED3DSIH_UTOF */ "utof",
270 /* WINED3DSIH_XOR */ "xor",
273 static const char * const semantic_names
[] =
275 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
276 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
277 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
278 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
279 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
280 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
281 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
282 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
283 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
284 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
285 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
286 /* WINED3D_DECL_USAGE_FOG */ "FOG",
287 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
288 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
293 enum wined3d_sysval_semantic sysval_semantic
;
294 const char *sysval_name
;
296 sysval_semantic_names
[] =
298 {WINED3D_SV_POSITION
, "SV_Position"},
299 {WINED3D_SV_CLIP_DISTANCE
, "SV_ClipDistance"},
300 {WINED3D_SV_CULL_DISTANCE
, "SV_CullDistance"},
301 {WINED3D_SV_RENDER_TARGET_ARRAY_INDEX
, "SV_RenderTargetArrayIndex"},
302 {WINED3D_SV_VIEWPORT_ARRAY_INDEX
, "SV_ViewportArrayIndex"},
303 {WINED3D_SV_VERTEX_ID
, "SV_VertexID"},
304 {WINED3D_SV_INSTANCE_ID
, "SV_InstanceID"},
305 {WINED3D_SV_PRIMITIVE_ID
, "SV_PrimitiveID"},
306 {WINED3D_SV_IS_FRONT_FACE
, "SV_IsFrontFace"},
307 {WINED3D_SV_SAMPLE_INDEX
, "SV_SampleIndex"},
308 {WINED3D_SV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
309 {WINED3D_SV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
310 {WINED3D_SV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
311 {WINED3D_SV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
312 {WINED3D_SV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
313 {WINED3D_SV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
314 {WINED3D_SV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
315 {WINED3D_SV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
316 {WINED3D_SV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
317 {WINED3D_SV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
318 {WINED3D_SV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
319 {WINED3D_SV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
322 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
323 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
325 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
327 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
328 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
330 return shader_opcode_names
[handler_idx
];
333 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
335 if (usage
>= ARRAY_SIZE(semantic_names
))
337 FIXME("Unrecognized usage %#x.\n", usage
);
338 return "UNRECOGNIZED";
341 return semantic_names
[usage
];
344 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
348 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
350 if (!strcmp(name
, semantic_names
[i
]))
357 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
361 case WINED3D_DECL_USAGE_POSITION
:
362 return WINED3D_SV_POSITION
;
368 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
370 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
373 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
374 const struct wined3d_shader_semantic
*s
)
376 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
377 e
->semantic_idx
= s
->usage_idx
;
378 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
379 e
->component_type
= WINED3D_TYPE_FLOAT
;
380 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
381 e
->mask
= s
->reg
.write_mask
;
384 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
385 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
387 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
388 e
->semantic_idx
= usage_idx
;
389 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
390 e
->component_type
= WINED3D_TYPE_FLOAT
;
391 e
->register_idx
= reg_idx
;
392 e
->mask
= write_mask
;
395 static const struct wined3d_shader_frontend
*shader_select_frontend(enum wined3d_shader_byte_code_format format
)
399 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
:
400 return &sm1_shader_frontend
;
402 case WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
:
403 return &sm4_shader_frontend
;
406 WARN("Invalid byte code format %#x specified.\n", format
);
411 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
413 buffer
->buffer
[0] = '\0';
414 buffer
->content_size
= 0;
417 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
419 buffer
->buffer_size
= 32;
420 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
422 ERR("Failed to allocate shader buffer memory.\n");
426 string_buffer_clear(buffer
);
430 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
432 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
435 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
438 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
440 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
441 new_buffer_size
*= 2;
442 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
444 ERR("Failed to grow buffer.\n");
445 buffer
->buffer
[buffer
->content_size
] = '\0';
448 buffer
->buffer
= new_buffer
;
449 buffer
->buffer_size
= new_buffer_size
;
453 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
458 rem
= buffer
->buffer_size
- buffer
->content_size
;
459 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
460 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
463 buffer
->content_size
+= rc
;
467 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
474 va_start(args
, format
);
475 ret
= shader_vaddline(buffer
, format
, args
);
479 if (!string_buffer_resize(buffer
, ret
))
484 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
486 struct wined3d_string_buffer
*buffer
;
488 if (list_empty(&list
->list
))
490 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
491 if (!buffer
|| !string_buffer_init(buffer
))
493 ERR("Couldn't allocate buffer for temporary string.\n");
494 HeapFree(GetProcessHeap(), 0, buffer
);
500 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
501 list_remove(&buffer
->entry
);
503 string_buffer_clear(buffer
);
507 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
511 string_buffer_clear(buffer
);
512 return shader_vaddline(buffer
, format
, args
);
515 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
522 va_start(args
, format
);
523 ret
= string_buffer_vsprintf(buffer
, format
, args
);
527 if (!string_buffer_resize(buffer
, ret
))
532 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
536 list_add_head(&list
->list
, &buffer
->entry
);
539 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
541 list_init(&list
->list
);
544 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
546 struct wined3d_string_buffer
*buffer
, *buffer_next
;
548 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
550 string_buffer_free(buffer
);
551 HeapFree(GetProcessHeap(), 0, buffer
);
553 list_init(&list
->list
);
556 /* Convert floating point offset relative to a register file to an absolute
557 * offset for float constants. */
558 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
560 switch (register_type
)
562 case WINED3DSPR_CONST
: return register_idx
;
563 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
564 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
565 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
567 FIXME("Unsupported register type: %u.\n", register_type
);
572 static void shader_delete_constant_list(struct list
*clist
)
574 struct wined3d_shader_lconst
*constant
, *constant_next
;
576 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
577 HeapFree(GetProcessHeap(), 0, constant
);
581 static void shader_set_limits(struct wined3d_shader
*shader
)
583 static const struct limits_entry
585 unsigned int min_version
;
586 unsigned int max_version
;
587 struct wined3d_shader_limits limits
;
591 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
592 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
593 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
594 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
595 * even though they are capable of supporting much more (GL
596 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
597 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
599 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
600 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
601 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
606 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
607 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
611 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
612 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
616 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
617 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
618 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
623 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
624 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
625 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
626 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
627 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
628 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
629 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
634 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
635 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
637 const struct limits_entry
*limits_array
;
638 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
639 shader
->reg_maps
.shader_version
.minor
);
642 switch (shader
->reg_maps
.shader_version
.type
)
645 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
647 case WINED3D_SHADER_TYPE_VERTEX
:
648 limits_array
= vs_limits
;
650 case WINED3D_SHADER_TYPE_HULL
:
651 limits_array
= hs_limits
;
653 case WINED3D_SHADER_TYPE_DOMAIN
:
654 limits_array
= ds_limits
;
656 case WINED3D_SHADER_TYPE_GEOMETRY
:
657 limits_array
= gs_limits
;
659 case WINED3D_SHADER_TYPE_PIXEL
:
660 limits_array
= ps_limits
;
662 case WINED3D_SHADER_TYPE_COMPUTE
:
663 limits_array
= cs_limits
;
667 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
669 if (shader_version
<= limits_array
[i
].max_version
)
671 shader
->limits
= &limits_array
[i
].limits
;
678 FIXME("Unexpected shader version \"%u.%u\".\n",
679 shader
->reg_maps
.shader_version
.major
,
680 shader
->reg_maps
.shader_version
.minor
);
681 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
685 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
690 bitmap
[idx
] |= (1u << shift
);
693 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
694 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
698 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
699 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
700 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
702 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
705 case WINED3DSPR_TEMP
:
706 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
709 case WINED3DSPR_INPUT
:
710 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
712 /* If relative addressing is used, we must assume that all
713 * registers are used. Even if it is a construct like v3[aL],
714 * we can't assume that v0, v1 and v2 aren't read because aL
715 * can be negative. */
716 if (reg
->idx
[0].rel_addr
)
717 shader
->u
.ps
.input_reg_used
= ~0u;
719 shader
->u
.ps
.input_reg_used
|= 1u << reg
->idx
[0].offset
;
722 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
725 case WINED3DSPR_RASTOUT
:
726 if (reg
->idx
[0].offset
== 1)
728 if (reg
->idx
[0].offset
== 2)
729 reg_maps
->point_size
= 1;
732 case WINED3DSPR_MISCTYPE
:
733 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
735 if (!reg
->idx
[0].offset
)
737 else if (reg
->idx
[0].offset
== 1)
738 reg_maps
->usesfacing
= 1;
742 case WINED3DSPR_CONST
:
743 if (reg
->idx
[0].rel_addr
)
745 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
746 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
747 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
748 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
749 reg_maps
->usesrelconstF
= TRUE
;
753 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
755 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
760 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
765 case WINED3DSPR_CONSTINT
:
766 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
768 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
773 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
777 case WINED3DSPR_CONSTBOOL
:
778 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
780 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
785 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
789 case WINED3DSPR_COLOROUT
:
790 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
794 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
795 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
801 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
802 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
804 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
805 struct wined3d_shader_sampler_map
*map
;
808 map
= ®_maps
->sampler_map
;
809 entries
= map
->entries
;
810 for (i
= 0; i
< map
->count
; ++i
)
812 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
818 if (!(entries
= wined3d_calloc(4, sizeof(*entries
))))
820 ERR("Failed to allocate sampler map entries.\n");
824 map
->entries
= entries
;
826 else if (map
->count
== map
->size
)
828 size_t new_size
= map
->size
* 2;
830 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
831 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
833 ERR("Failed to resize sampler map entries.\n");
836 map
->size
= new_size
;
837 map
->entries
= entries
;
840 entry
= &entries
[map
->count
++];
841 entry
->resource_idx
= resource_idx
;
842 entry
->sampler_idx
= sampler_idx
;
843 entry
->bind_idx
= bind_idx
;
846 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
850 case WINED3DSIH_M4x4
:
851 case WINED3DSIH_M3x4
:
852 return param
== 1 ? 3 : 0;
854 case WINED3DSIH_M4x3
:
855 case WINED3DSIH_M3x3
:
856 return param
== 1 ? 2 : 0;
858 case WINED3DSIH_M3x2
:
859 return param
== 1 ? 1 : 0;
866 /* Note that this does not count the loop register as an address register. */
867 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
868 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
869 struct wined3d_shader_signature
*output_signature
, DWORD constf_size
)
871 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
872 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
873 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
874 void *fe_data
= shader
->frontend_data
;
875 struct wined3d_shader_version shader_version
;
879 memset(reg_maps
, 0, sizeof(*reg_maps
));
880 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
881 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
882 reg_maps
->min_rel_offset
= ~0U;
883 list_init(®_maps
->indexable_temps
);
885 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
886 reg_maps
->shader_version
= shader_version
;
888 shader_set_limits(shader
);
890 if (!(reg_maps
->constf
= wined3d_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
891 sizeof(*reg_maps
->constf
))))
893 ERR("Failed to allocate constant map memory.\n");
894 return E_OUTOFMEMORY
;
897 while (!fe
->shader_is_end(fe_data
, &ptr
))
899 struct wined3d_shader_instruction ins
;
902 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
904 /* Unhandled opcode, and its parameters. */
905 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
907 TRACE("Skipping unrecognized instruction.\n");
911 /* Handle declarations. */
912 if (ins
.handler_idx
== WINED3DSIH_DCL
913 || ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
915 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
916 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
918 switch (semantic
->reg
.reg
.type
)
920 /* Mark input registers used. */
921 case WINED3DSPR_INPUT
:
922 if (reg_idx
>= MAX_REG_INPUT
)
924 ERR("Invalid input register index %u.\n", reg_idx
);
927 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
928 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
929 return WINED3DERR_INVALIDCALL
;
930 reg_maps
->input_registers
|= 1u << reg_idx
;
931 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
934 /* Vertex shader: mark 3.0 output registers used, save token. */
935 case WINED3DSPR_OUTPUT
:
936 if (reg_idx
>= MAX_REG_OUTPUT
)
938 ERR("Invalid output register index %u.\n", reg_idx
);
941 reg_maps
->output_registers
|= 1u << reg_idx
;
942 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
943 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
945 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
946 reg_maps
->point_size
= 1;
949 case WINED3DSPR_SAMPLER
:
950 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
951 case WINED3DSPR_RESOURCE
:
952 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
954 ERR("Invalid resource index %u.\n", reg_idx
);
957 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
958 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
962 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
964 ERR("Invalid UAV resource index %u.\n", reg_idx
);
967 reg_maps
->uav_resource_info
[reg_idx
].type
= semantic
->resource_type
;
968 reg_maps
->uav_resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
972 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
976 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
978 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
979 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
980 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
982 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
984 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
987 FIXME("Multiple immediate constant buffers.\n");
988 reg_maps
->icb
= ins
.declaration
.icb
;
990 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
992 struct wined3d_shader_indexable_temp
*reg
;
994 if (!(reg
= HeapAlloc(GetProcessHeap(), 0, sizeof(*reg
))))
995 return E_OUTOFMEMORY
;
997 *reg
= ins
.declaration
.indexable_temp
;
998 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
1000 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
1002 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1003 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
1005 FIXME("Invalid instruction %#x for shader type %#x.\n",
1006 ins
.handler_idx
, shader_version
.type
);
1008 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1010 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1011 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
1013 FIXME("Invalid instruction %#x for shader type %#x.\n",
1014 ins
.handler_idx
, shader_version
.type
);
1016 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
1018 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1019 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1021 ERR("Invalid resource index %u.\n", reg_idx
);
1024 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1025 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1026 reg_maps
->resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1028 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
1030 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
1031 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
1033 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
1035 reg_maps
->temporary_count
= ins
.declaration
.count
;
1037 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
1039 if (shader_version
.type
== WINED3D_SHADER_TYPE_COMPUTE
)
1041 shader
->u
.cs
.thread_group_size
= ins
.declaration
.thread_group_size
;
1045 FIXME("Invalid instruction %#x for shader type %#x.\n",
1046 ins
.handler_idx
, shader_version
.type
);
1049 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
1051 unsigned int reg_idx
= ins
.declaration
.dst
.reg
.idx
[0].offset
;
1052 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1054 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1057 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1058 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1059 reg_maps
->uav_resource_info
[reg_idx
].flags
= WINED3D_VIEW_BUFFER_RAW
;
1061 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
1063 unsigned int reg_idx
= ins
.declaration
.structured_resource
.reg
.reg
.idx
[0].offset
;
1064 if (reg_idx
>= ARRAY_SIZE(reg_maps
->uav_resource_info
))
1066 ERR("Invalid UAV resource index %u.\n", reg_idx
);
1070 FIXME("Ignoring structured UAV flags %#x.\n", ins
.flags
);
1071 reg_maps
->uav_resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_BUFFER
;
1072 reg_maps
->uav_resource_info
[reg_idx
].data_type
= WINED3D_DATA_UINT
;
1073 reg_maps
->uav_resource_info
[reg_idx
].flags
= 0;
1074 reg_maps
->uav_resource_info
[reg_idx
].stride
= ins
.declaration
.structured_resource
.byte_stride
/ 4;
1076 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1078 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
1079 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
1081 FIXME("Invalid instruction %#x for shader type %#x.\n",
1082 ins
.handler_idx
, shader_version
.type
);
1084 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1086 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1088 if (!lconst
) return E_OUTOFMEMORY
;
1090 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1091 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1092 value
= (float *)lconst
->value
;
1094 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1095 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1097 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1098 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1099 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1100 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1101 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1102 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1103 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1104 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1107 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1109 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1110 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1112 shader
->lconst_inf_or_nan
= TRUE
;
1115 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1117 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1118 if (!lconst
) return E_OUTOFMEMORY
;
1120 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1121 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, 4 * sizeof(DWORD
));
1123 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1124 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1126 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1128 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1129 if (!lconst
) return E_OUTOFMEMORY
;
1131 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1132 memcpy(lconst
->value
, ins
.src
[0].reg
.u
.immconst_data
, sizeof(DWORD
));
1134 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1135 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1137 /* For subroutine prototypes. */
1138 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1140 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1142 /* Set texture, address, temporary registers. */
1145 BOOL color0_mov
= FALSE
;
1148 /* This will loop over all the registers and try to
1149 * make a bitmask of the ones we're interested in.
1151 * Relative addressing tokens are ignored, but that's
1152 * okay, since we'll catch any address registers when
1153 * they are initialized (required by spec). */
1154 for (i
= 0; i
< ins
.dst_count
; ++i
)
1156 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1157 shader_version
.type
, constf_size
))
1158 return WINED3DERR_INVALIDCALL
;
1160 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1162 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1164 switch (ins
.dst
[i
].reg
.type
)
1166 case WINED3DSPR_RASTOUT
:
1167 if (shader_version
.major
>= 3)
1172 reg_maps
->output_registers
|= 1u << 10;
1173 shader_signature_from_usage(&output_signature_elements
[10],
1174 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1178 reg_maps
->output_registers
|= 1u << 11;
1179 shader_signature_from_usage(&output_signature_elements
[11],
1180 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1184 reg_maps
->output_registers
|= 1u << 11;
1185 shader_signature_from_usage(&output_signature_elements
[11],
1186 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1191 case WINED3DSPR_ATTROUT
:
1192 if (shader_version
.major
>= 3)
1197 if (reg_maps
->output_registers
& (1u << idx
))
1199 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1203 reg_maps
->output_registers
|= 1u << idx
;
1204 shader_signature_from_usage(&output_signature_elements
[idx
],
1205 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1210 case WINED3DSPR_TEXCRDOUT
:
1211 if (shader_version
.major
>= 3)
1213 if (idx
>= ARRAY_SIZE(reg_maps
->u
.output_registers_mask
))
1215 WARN("Invalid output register index %u.\n", idx
);
1218 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1221 if (idx
>= ARRAY_SIZE(reg_maps
->u
.texcoord_mask
))
1223 WARN("Invalid texcoord index %u.\n", idx
);
1226 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1227 if (reg_maps
->output_registers
& (1u << idx
))
1229 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1233 reg_maps
->output_registers
|= 1u << idx
;
1234 shader_signature_from_usage(&output_signature_elements
[idx
],
1235 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1244 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1246 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1248 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1249 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1250 * the mov and perform the sRGB write correction from the source register.
1252 * However, if the mov is only partial, we can't do this, and if the write
1253 * comes from an instruction other than MOV it is hard to do as well. If
1254 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1255 shader
->u
.ps
.color0_mov
= FALSE
;
1256 if (ins
.handler_idx
== WINED3DSIH_MOV
1257 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1259 /* Used later when the source register is read. */
1263 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1266 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1267 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1269 shader
->u
.ps
.color0_mov
= FALSE
;
1273 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1274 if (shader_version
.major
== 1
1275 && (ins
.handler_idx
== WINED3DSIH_TEX
1276 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1277 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1278 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1279 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1280 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1281 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1282 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1283 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1284 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1285 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1287 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1289 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
1291 WARN("Invalid 1.x sampler index %u.\n", reg_idx
);
1295 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1296 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1297 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1298 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1300 /* texbem is only valid with < 1.4 pixel shaders */
1301 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1302 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1304 reg_maps
->bumpmat
|= 1u << reg_idx
;
1305 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1307 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1311 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1313 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1317 if ((WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1318 || (WINED3DSIH_IMM_ATOMIC_AND
<= ins
.handler_idx
1319 && ins
.handler_idx
<= WINED3DSIH_IMM_ATOMIC_XOR
1320 && ins
.handler_idx
!= WINED3DSIH_IMM_ATOMIC_CONSUME
)
1321 || ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
)
1323 unsigned int reg_idx
;
1324 if (ins
.handler_idx
== WINED3DSIH_LD_UAV_TYPED
)
1325 reg_idx
= ins
.src
[1].reg
.idx
[0].offset
;
1326 else if (WINED3DSIH_ATOMIC_AND
<= ins
.handler_idx
&& ins
.handler_idx
<= WINED3DSIH_ATOMIC_XOR
)
1327 reg_idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1329 reg_idx
= ins
.dst
[1].reg
.idx
[0].offset
;
1330 if (reg_idx
>= MAX_UNORDERED_ACCESS_VIEWS
)
1332 ERR("Invalid UAV index %u.\n", reg_idx
);
1335 reg_maps
->uav_read_mask
|= (1u << reg_idx
);
1337 else if (ins
.handler_idx
== WINED3DSIH_NRM
)
1339 reg_maps
->usesnrm
= 1;
1341 else if (ins
.handler_idx
== WINED3DSIH_DSY
1342 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1343 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1345 reg_maps
->usesdsy
= 1;
1347 else if (ins
.handler_idx
== WINED3DSIH_DSX
1348 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1349 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1351 reg_maps
->usesdsx
= 1;
1353 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1354 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1355 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1356 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1357 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1358 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1359 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1360 || ins
.handler_idx
== WINED3DSIH_REP
)
1363 if (cur_loop_depth
> max_loop_depth
)
1364 max_loop_depth
= cur_loop_depth
;
1366 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1367 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1371 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1372 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1373 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C
1374 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1375 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1376 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1378 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1379 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1381 else if (ins
.handler_idx
== WINED3DSIH_LD
1382 || (ins
.handler_idx
== WINED3DSIH_LD_RAW
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
)
1383 || (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.src
[1].reg
.type
== WINED3DSPR_RESOURCE
))
1385 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1386 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1390 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1391 shader_version
.type
, constf_size
))
1392 return WINED3DERR_INVALIDCALL
;
1394 for (i
= 0; i
< ins
.src_count
; ++i
)
1396 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1397 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1399 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1400 shader_version
.type
, constf_size
))
1401 return WINED3DERR_INVALIDCALL
;
1404 ++reg
.idx
[0].offset
;
1405 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1406 shader_version
.type
, constf_size
))
1407 return WINED3DERR_INVALIDCALL
;
1413 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1414 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1416 shader
->u
.ps
.color0_mov
= TRUE
;
1417 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1423 reg_maps
->loop_depth
= max_loop_depth
;
1425 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1426 * R0 is written to the render target. */
1427 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1428 reg_maps
->rt_mask
|= (1u << 0);
1430 if (input_signature
->elements
)
1432 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1434 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1435 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1437 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1439 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1440 reg_maps
->usesfacing
= 1;
1444 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1446 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1447 struct wined3d_shader_signature_element
*e
;
1450 if (!(input_signature
->elements
= wined3d_calloc(count
, sizeof(*input_signature
->elements
))))
1451 return E_OUTOFMEMORY
;
1452 input_signature
->element_count
= count
;
1454 e
= input_signature
->elements
;
1455 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1457 if (!(reg_maps
->input_registers
& (1u << i
)))
1459 input_signature_elements
[i
].register_idx
= i
;
1460 *e
++ = input_signature_elements
[i
];
1464 if (output_signature
->elements
)
1466 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1468 reg_maps
->output_registers
|= 1u << output_signature
->elements
[i
].register_idx
;
1471 else if (reg_maps
->output_registers
)
1473 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1474 struct wined3d_shader_signature_element
*e
;
1476 if (!(output_signature
->elements
= wined3d_calloc(count
, sizeof(*output_signature
->elements
))))
1477 return E_OUTOFMEMORY
;
1478 output_signature
->element_count
= count
;
1480 e
= output_signature
->elements
;
1481 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1483 if (!(reg_maps
->output_registers
& (1u << i
)))
1485 *e
++ = output_signature_elements
[i
];
1492 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1494 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1496 HeapFree(GetProcessHeap(), 0, reg_maps
->constf
);
1497 HeapFree(GetProcessHeap(), 0, reg_maps
->sampler_map
.entries
);
1499 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1500 HeapFree(GetProcessHeap(), 0, reg
);
1501 list_init(®_maps
->indexable_temps
);
1504 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1506 DWORD map
= 1u << max
;
1508 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1510 return wined3d_log2i(map
);
1513 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1515 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1517 shader_addline(buffer
, "refactoringAllowed");
1518 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1520 shader_addline(buffer
, " | ");
1523 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1525 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1526 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1530 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1533 static void shader_dump_sync_flags(struct wined3d_string_buffer
*buffer
, DWORD sync_flags
)
1535 if (sync_flags
& WINED3DSSF_GROUP_SHARED_MEMORY
)
1537 shader_addline(buffer
, "_g");
1538 sync_flags
&= ~WINED3DSSF_GROUP_SHARED_MEMORY
;
1540 if (sync_flags
& WINED3DSSF_THREAD_GROUP
)
1542 shader_addline(buffer
, "_t");
1543 sync_flags
&= ~WINED3DSSF_THREAD_GROUP
;
1547 shader_addline(buffer
, "_unknown_flags(%#x)", sync_flags
);
1550 static void shader_dump_uav_flags(struct wined3d_string_buffer
*buffer
, DWORD uav_flags
)
1552 if (uav_flags
& WINED3DSUF_GLOBALLY_COHERENT
)
1554 shader_addline(buffer
, "_glc");
1555 uav_flags
&= ~WINED3DSUF_GLOBALLY_COHERENT
;
1557 if (uav_flags
& WINED3DSUF_ORDER_PRESERVING_COUNTER
)
1559 shader_addline(buffer
, "_opc");
1560 uav_flags
&= ~WINED3DSUF_ORDER_PRESERVING_COUNTER
;
1564 shader_addline(buffer
, "_unknown_flags(%#x)", uav_flags
);
1567 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1568 enum wined3d_tessellator_domain domain
)
1572 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1573 shader_addline(buffer
, "line");
1575 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1576 shader_addline(buffer
, "triangle");
1578 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1579 shader_addline(buffer
, "quad");
1582 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1587 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1588 enum wined3d_tessellator_output_primitive output_primitive
)
1590 switch (output_primitive
)
1592 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1593 shader_addline(buffer
, "point");
1595 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1596 shader_addline(buffer
, "line");
1598 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1599 shader_addline(buffer
, "triangle_cw");
1601 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1602 shader_addline(buffer
, "triangle_ccw");
1605 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1610 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1611 enum wined3d_tessellator_partitioning partitioning
)
1613 switch (partitioning
)
1615 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1616 shader_addline(buffer
, "integer");
1618 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1619 shader_addline(buffer
, "pow2");
1621 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1622 shader_addline(buffer
, "fractional_odd");
1624 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1625 shader_addline(buffer
, "fractional_even");
1628 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1633 static void shader_dump_sysval_semantic(struct wined3d_string_buffer
*buffer
, enum wined3d_sysval_semantic semantic
)
1637 for (i
= 0; i
< ARRAY_SIZE(sysval_semantic_names
); ++i
)
1639 if (sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1641 shader_addline(buffer
, "%s", sysval_semantic_names
[i
].sysval_name
);
1646 shader_addline(buffer
, "unknown_sysval_semantic(%#x)", semantic
);
1649 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1650 const struct wined3d_shader_semantic
*semantic
, const struct wined3d_shader_version
*shader_version
)
1652 shader_addline(buffer
, "dcl");
1654 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1656 switch (semantic
->resource_type
)
1658 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1659 shader_addline(buffer
, "_2d");
1662 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1663 shader_addline(buffer
, "_3d");
1666 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1667 shader_addline(buffer
, "_cube");
1671 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
1675 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
1677 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1678 shader_addline(buffer
, "_resource_");
1680 shader_addline(buffer
, "_uav_");
1681 switch (semantic
->resource_type
)
1683 case WINED3D_SHADER_RESOURCE_BUFFER
:
1684 shader_addline(buffer
, "buffer");
1687 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1688 shader_addline(buffer
, "texture1d");
1691 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1692 shader_addline(buffer
, "texture2d");
1695 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1696 shader_addline(buffer
, "texture2dms");
1699 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1700 shader_addline(buffer
, "texture3d");
1703 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1704 shader_addline(buffer
, "texturecube");
1707 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1708 shader_addline(buffer
, "texture1darray");
1711 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1712 shader_addline(buffer
, "texture2darray");
1715 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1716 shader_addline(buffer
, "texture2dmsarray");
1719 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
:
1720 shader_addline(buffer
, "texturecubearray");
1724 shader_addline(buffer
, "unknown");
1727 switch (semantic
->resource_data_type
)
1729 case WINED3D_DATA_FLOAT
:
1730 shader_addline(buffer
, " (float)");
1733 case WINED3D_DATA_INT
:
1734 shader_addline(buffer
, " (int)");
1737 case WINED3D_DATA_UINT
:
1738 shader_addline(buffer
, " (uint)");
1741 case WINED3D_DATA_UNORM
:
1742 shader_addline(buffer
, " (unorm)");
1745 case WINED3D_DATA_SNORM
:
1746 shader_addline(buffer
, " (snorm)");
1750 shader_addline(buffer
, " (unknown)");
1756 /* Pixel shaders 3.0 don't have usage semantics. */
1757 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
1760 shader_addline(buffer
, "_");
1762 switch (semantic
->usage
)
1764 case WINED3D_DECL_USAGE_POSITION
:
1765 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
1768 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1769 shader_addline(buffer
, "blend");
1772 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1773 shader_addline(buffer
, "weight");
1776 case WINED3D_DECL_USAGE_NORMAL
:
1777 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
1780 case WINED3D_DECL_USAGE_PSIZE
:
1781 shader_addline(buffer
, "psize");
1784 case WINED3D_DECL_USAGE_COLOR
:
1785 if (!semantic
->usage_idx
)
1786 shader_addline(buffer
, "color");
1788 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
1791 case WINED3D_DECL_USAGE_TEXCOORD
:
1792 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
1795 case WINED3D_DECL_USAGE_TANGENT
:
1796 shader_addline(buffer
, "tangent");
1799 case WINED3D_DECL_USAGE_BINORMAL
:
1800 shader_addline(buffer
, "binormal");
1803 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1804 shader_addline(buffer
, "tessfactor");
1807 case WINED3D_DECL_USAGE_POSITIONT
:
1808 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
1811 case WINED3D_DECL_USAGE_FOG
:
1812 shader_addline(buffer
, "fog");
1815 case WINED3D_DECL_USAGE_DEPTH
:
1816 shader_addline(buffer
, "depth");
1819 case WINED3D_DECL_USAGE_SAMPLE
:
1820 shader_addline(buffer
, "sample");
1824 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
1825 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
1830 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
1831 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
1833 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1834 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1835 UINT offset
= reg
->idx
[0].offset
;
1839 case WINED3DSPR_TEMP
:
1840 shader_addline(buffer
, "r");
1843 case WINED3DSPR_INPUT
:
1844 shader_addline(buffer
, "v");
1847 case WINED3DSPR_CONST
:
1848 case WINED3DSPR_CONST2
:
1849 case WINED3DSPR_CONST3
:
1850 case WINED3DSPR_CONST4
:
1851 shader_addline(buffer
, "c");
1852 offset
= shader_get_float_offset(reg
->type
, offset
);
1855 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1856 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1859 case WINED3DSPR_RASTOUT
:
1860 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
1863 case WINED3DSPR_COLOROUT
:
1864 shader_addline(buffer
, "oC");
1867 case WINED3DSPR_DEPTHOUT
:
1868 shader_addline(buffer
, "oDepth");
1871 case WINED3DSPR_ATTROUT
:
1872 shader_addline(buffer
, "oD");
1875 case WINED3DSPR_TEXCRDOUT
:
1876 /* Vertex shaders >= 3.0 use general purpose output registers
1877 * (WINED3DSPR_OUTPUT), which can include an address token. */
1878 if (shader_version
->major
>= 3)
1879 shader_addline(buffer
, "o");
1881 shader_addline(buffer
, "oT");
1884 case WINED3DSPR_CONSTINT
:
1885 shader_addline(buffer
, "i");
1888 case WINED3DSPR_CONSTBOOL
:
1889 shader_addline(buffer
, "b");
1892 case WINED3DSPR_LABEL
:
1893 shader_addline(buffer
, "l");
1896 case WINED3DSPR_LOOP
:
1897 shader_addline(buffer
, "aL");
1900 case WINED3DSPR_SAMPLER
:
1901 shader_addline(buffer
, "s");
1904 case WINED3DSPR_MISCTYPE
:
1907 FIXME("Unhandled misctype register %u.\n", offset
);
1908 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
1912 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
1916 case WINED3DSPR_PREDICATE
:
1917 shader_addline(buffer
, "p");
1920 case WINED3DSPR_IMMCONST
:
1921 shader_addline(buffer
, "l");
1924 case WINED3DSPR_CONSTBUFFER
:
1925 shader_addline(buffer
, "cb");
1928 case WINED3DSPR_IMMCONSTBUFFER
:
1929 shader_addline(buffer
, "icb");
1932 case WINED3DSPR_PRIMID
:
1933 shader_addline(buffer
, "primID");
1936 case WINED3DSPR_NULL
:
1937 shader_addline(buffer
, "null");
1940 case WINED3DSPR_RESOURCE
:
1941 shader_addline(buffer
, "t");
1944 case WINED3DSPR_UAV
:
1945 shader_addline(buffer
, "u");
1948 case WINED3DSPR_OUTPOINTID
:
1949 shader_addline(buffer
, "vOutputControlPointID");
1952 case WINED3DSPR_FORKINSTID
:
1953 shader_addline(buffer
, "vForkInstanceId");
1956 case WINED3DSPR_INCONTROLPOINT
:
1957 shader_addline(buffer
, "vicp");
1960 case WINED3DSPR_OUTCONTROLPOINT
:
1961 shader_addline(buffer
, "vocp");
1964 case WINED3DSPR_PATCHCONST
:
1965 shader_addline(buffer
, "vpc");
1968 case WINED3DSPR_TESSCOORD
:
1969 shader_addline(buffer
, "vDomainLocation");
1972 case WINED3DSPR_GROUPSHAREDMEM
:
1973 shader_addline(buffer
, "g");
1976 case WINED3DSPR_THREADID
:
1977 shader_addline(buffer
, "vThreadID");
1980 case WINED3DSPR_THREADGROUPID
:
1981 shader_addline(buffer
, "vThreadGroupID");
1984 case WINED3DSPR_LOCALTHREADID
:
1985 shader_addline(buffer
, "vThreadIDInGroup");
1988 case WINED3DSPR_LOCALTHREADINDEX
:
1989 shader_addline(buffer
, "vThreadIDInGroupFlattened");
1992 case WINED3DSPR_IDXTEMP
:
1993 shader_addline(buffer
, "x");
1996 case WINED3DSPR_STREAM
:
1997 shader_addline(buffer
, "m");
2000 case WINED3DSPR_FUNCTIONBODY
:
2001 shader_addline(buffer
, "fb");
2004 case WINED3DSPR_FUNCTIONPOINTER
:
2005 shader_addline(buffer
, "fp");
2008 case WINED3DSPR_COVERAGE
:
2009 shader_addline(buffer
, "vCoverage");
2012 case WINED3DSPR_SAMPLEMASK
:
2013 shader_addline(buffer
, "oMask");
2017 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
2021 if (reg
->type
== WINED3DSPR_IMMCONST
)
2023 shader_addline(buffer
, "(");
2024 switch (reg
->immconst_type
)
2026 case WINED3D_IMMCONST_SCALAR
:
2027 switch (reg
->data_type
)
2029 case WINED3D_DATA_FLOAT
:
2030 shader_addline(buffer
, "%.8e", *(const float *)reg
->u
.immconst_data
);
2032 case WINED3D_DATA_INT
:
2033 shader_addline(buffer
, "%d", reg
->u
.immconst_data
[0]);
2035 case WINED3D_DATA_RESOURCE
:
2036 case WINED3D_DATA_SAMPLER
:
2037 case WINED3D_DATA_UINT
:
2038 shader_addline(buffer
, "%u", reg
->u
.immconst_data
[0]);
2041 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2046 case WINED3D_IMMCONST_VEC4
:
2047 switch (reg
->data_type
)
2049 case WINED3D_DATA_FLOAT
:
2050 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
2051 *(const float *)®
->u
.immconst_data
[0], *(const float *)®
->u
.immconst_data
[1],
2052 *(const float *)®
->u
.immconst_data
[2], *(const float *)®
->u
.immconst_data
[3]);
2054 case WINED3D_DATA_INT
:
2055 shader_addline(buffer
, "%d, %d, %d, %d",
2056 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2057 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2059 case WINED3D_DATA_RESOURCE
:
2060 case WINED3D_DATA_SAMPLER
:
2061 case WINED3D_DATA_UINT
:
2062 shader_addline(buffer
, "%u, %u, %u, %u",
2063 reg
->u
.immconst_data
[0], reg
->u
.immconst_data
[1],
2064 reg
->u
.immconst_data
[2], reg
->u
.immconst_data
[3]);
2067 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
2073 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
2076 shader_addline(buffer
, ")");
2078 else if (reg
->type
!= WINED3DSPR_RASTOUT
2079 && reg
->type
!= WINED3DSPR_MISCTYPE
2080 && reg
->type
!= WINED3DSPR_NULL
)
2084 shader_addline(buffer
, "[");
2085 if (reg
->idx
[0].rel_addr
)
2087 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
2088 shader_addline(buffer
, " + ");
2090 shader_addline(buffer
, "%u]", offset
);
2092 if (reg
->idx
[1].offset
!= ~0u)
2094 shader_addline(buffer
, "[");
2095 if (reg
->idx
[1].rel_addr
)
2097 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
2098 shader_addline(buffer
, " + ");
2100 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
2104 if (reg
->type
== WINED3DSPR_FUNCTIONPOINTER
)
2105 shader_addline(buffer
, "[%u]", reg
->u
.fp_body_idx
);
2109 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
2110 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
2112 DWORD write_mask
= param
->write_mask
;
2114 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2116 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
2118 static const char write_mask_chars
[] = "xyzw";
2120 shader_addline(buffer
, ".");
2121 if (write_mask
& WINED3DSP_WRITEMASK_0
)
2122 shader_addline(buffer
, "%c", write_mask_chars
[0]);
2123 if (write_mask
& WINED3DSP_WRITEMASK_1
)
2124 shader_addline(buffer
, "%c", write_mask_chars
[1]);
2125 if (write_mask
& WINED3DSP_WRITEMASK_2
)
2126 shader_addline(buffer
, "%c", write_mask_chars
[2]);
2127 if (write_mask
& WINED3DSP_WRITEMASK_3
)
2128 shader_addline(buffer
, "%c", write_mask_chars
[3]);
2132 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
2133 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
2135 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
2136 DWORD swizzle
= param
->swizzle
;
2138 if (src_modifier
== WINED3DSPSM_NEG
2139 || src_modifier
== WINED3DSPSM_BIASNEG
2140 || src_modifier
== WINED3DSPSM_SIGNNEG
2141 || src_modifier
== WINED3DSPSM_X2NEG
2142 || src_modifier
== WINED3DSPSM_ABSNEG
)
2143 shader_addline(buffer
, "-");
2144 else if (src_modifier
== WINED3DSPSM_COMP
)
2145 shader_addline(buffer
, "1-");
2146 else if (src_modifier
== WINED3DSPSM_NOT
)
2147 shader_addline(buffer
, "!");
2149 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
2150 shader_addline(buffer
, "abs(");
2152 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
2154 switch (src_modifier
)
2156 case WINED3DSPSM_NONE
: break;
2157 case WINED3DSPSM_NEG
: break;
2158 case WINED3DSPSM_NOT
: break;
2159 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
2160 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
2161 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
2162 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
2163 case WINED3DSPSM_COMP
: break;
2164 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
2165 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
2166 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
2167 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
2168 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
2169 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
2170 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
2173 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
2175 static const char swizzle_chars
[] = "xyzw";
2176 DWORD swizzle_x
= swizzle
& 0x03;
2177 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2178 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2179 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2181 if (swizzle_x
== swizzle_y
2182 && swizzle_x
== swizzle_z
2183 && swizzle_x
== swizzle_w
)
2185 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2189 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2190 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2195 /* Shared code in order to generate the bulk of the shader string.
2196 * NOTE: A description of how to parse tokens can be found on MSDN. */
2197 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2198 const struct wined3d_shader_reg_maps
*reg_maps
, void *backend_ctx
)
2200 struct wined3d_device
*device
= shader
->device
;
2201 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2202 void *fe_data
= shader
->frontend_data
;
2203 struct wined3d_shader_version shader_version
;
2204 struct wined3d_shader_parser_state state
;
2205 struct wined3d_shader_instruction ins
;
2206 struct wined3d_shader_tex_mx tex_mx
;
2207 struct wined3d_shader_context ctx
;
2210 /* Initialize current parsing state. */
2211 tex_mx
.current_row
= 0;
2212 state
.current_loop_depth
= 0;
2213 state
.current_loop_reg
= 0;
2214 state
.in_subroutine
= FALSE
;
2216 ctx
.shader
= shader
;
2217 ctx
.gl_info
= &device
->adapter
->gl_info
;
2218 ctx
.reg_maps
= reg_maps
;
2219 ctx
.buffer
= buffer
;
2220 ctx
.tex_mx
= &tex_mx
;
2222 ctx
.backend_data
= backend_ctx
;
2225 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2227 while (!fe
->shader_is_end(fe_data
, &ptr
))
2230 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2232 /* Unknown opcode and its parameters. */
2233 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2235 TRACE("Skipping unrecognized instruction.\n");
2240 FIXME("Predicates not implemented.\n");
2242 /* Call appropriate function for output target */
2243 device
->shader_backend
->shader_handle_instruction(&ins
);
2247 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2248 const struct wined3d_shader_dst_param
*dst
)
2250 DWORD mmask
= dst
->modifiers
;
2255 case 13: shader_addline(buffer
, "_d8"); break;
2256 case 14: shader_addline(buffer
, "_d4"); break;
2257 case 15: shader_addline(buffer
, "_d2"); break;
2258 case 1: shader_addline(buffer
, "_x2"); break;
2259 case 2: shader_addline(buffer
, "_x4"); break;
2260 case 3: shader_addline(buffer
, "_x8"); break;
2261 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2264 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2265 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2266 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2268 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2269 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2272 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2273 enum wined3d_primitive_type primitive_type
)
2275 switch (primitive_type
)
2277 case WINED3D_PT_UNDEFINED
:
2278 shader_addline(buffer
, "undefined");
2280 case WINED3D_PT_POINTLIST
:
2281 shader_addline(buffer
, "pointlist");
2283 case WINED3D_PT_LINELIST
:
2284 shader_addline(buffer
, "linelist");
2286 case WINED3D_PT_LINESTRIP
:
2287 shader_addline(buffer
, "linestrip");
2289 case WINED3D_PT_TRIANGLELIST
:
2290 shader_addline(buffer
, "trianglelist");
2292 case WINED3D_PT_TRIANGLESTRIP
:
2293 shader_addline(buffer
, "trianglestrip");
2295 case WINED3D_PT_TRIANGLEFAN
:
2296 shader_addline(buffer
, "trianglefan");
2298 case WINED3D_PT_LINELIST_ADJ
:
2299 shader_addline(buffer
, "linelist_adj");
2301 case WINED3D_PT_LINESTRIP_ADJ
:
2302 shader_addline(buffer
, "linestrip_adj");
2304 case WINED3D_PT_TRIANGLELIST_ADJ
:
2305 shader_addline(buffer
, "trianglelist_adj");
2307 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2308 shader_addline(buffer
, "trianglestrip_adj");
2311 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
);
2316 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2317 enum wined3d_shader_interpolation_mode interpolation_mode
)
2319 switch (interpolation_mode
)
2321 case WINED3DSIM_CONSTANT
:
2322 shader_addline(buffer
, "constant");
2324 case WINED3DSIM_LINEAR
:
2325 shader_addline(buffer
, "linear");
2327 case WINED3DSIM_LINEAR_CENTROID
:
2328 shader_addline(buffer
, "linear centroid");
2330 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2331 shader_addline(buffer
, "linear noperspective");
2333 case WINED3DSIM_LINEAR_SAMPLE
:
2334 shader_addline(buffer
, "linear sample");
2336 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2337 shader_addline(buffer
, "linear noperspective centroid");
2339 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2340 shader_addline(buffer
, "linear noperspective sample");
2343 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2348 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
)
2350 struct wined3d_shader_version shader_version
;
2351 struct wined3d_string_buffer buffer
;
2352 const char *type_prefix
;
2357 if (!string_buffer_init(&buffer
))
2359 ERR("Failed to initialize string buffer.\n");
2363 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2365 TRACE("Parsing %p.\n", ptr
);
2367 switch (shader_version
.type
)
2369 case WINED3D_SHADER_TYPE_VERTEX
:
2373 case WINED3D_SHADER_TYPE_HULL
:
2377 case WINED3D_SHADER_TYPE_DOMAIN
:
2381 case WINED3D_SHADER_TYPE_GEOMETRY
:
2385 case WINED3D_SHADER_TYPE_PIXEL
:
2389 case WINED3D_SHADER_TYPE_COMPUTE
:
2394 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2395 type_prefix
= "unknown";
2399 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2401 while (!fe
->shader_is_end(fe_data
, &ptr
))
2403 struct wined3d_shader_instruction ins
;
2405 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2406 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2408 WARN("Skipping unrecognized instruction.\n");
2409 shader_addline(&buffer
, "<unrecognized instruction>\n");
2413 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2415 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, &shader_version
);
2416 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2417 shader_addline(&buffer
, " ");
2418 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2420 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2422 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2423 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2424 shader_addline(&buffer
, ", %s",
2425 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2427 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_BODY
)
2429 shader_addline(&buffer
, "%s fb%u",
2430 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2432 else if (ins
.handler_idx
== WINED3DSIH_DCL_FUNCTION_TABLE
)
2434 shader_addline(&buffer
, "%s ft%u = {...}",
2435 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.index
);
2437 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2439 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2440 shader_dump_global_flags(&buffer
, ins
.flags
);
2442 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2444 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2445 ins
.declaration
.max_tessellation_factor
);
2447 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2449 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2450 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2452 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2453 ins
.declaration
.icb
->data
[4 * i
+ 0],
2454 ins
.declaration
.icb
->data
[4 * i
+ 1],
2455 ins
.declaration
.icb
->data
[4 * i
+ 2],
2456 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2458 shader_addline(&buffer
, "}");
2460 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2462 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2463 ins
.declaration
.indexable_temp
.register_idx
,
2464 ins
.declaration
.indexable_temp
.register_size
,
2465 ins
.declaration
.indexable_temp
.component_count
);
2467 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2469 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2470 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2471 shader_addline(&buffer
, " ");
2472 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2474 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2475 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2476 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2477 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2479 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2480 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2481 shader_addline(&buffer
, ", ");
2482 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2484 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2486 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2487 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2488 shader_addline(&buffer
, " ");
2489 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2490 shader_addline(&buffer
, ", ");
2491 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2493 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2494 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2496 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2497 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2499 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2500 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2502 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2503 shader_dump_primitive_type(&buffer
, ins
.declaration
.primitive_type
);
2505 else if (ins
.handler_idx
== WINED3DSIH_DCL_INTERFACE
)
2507 shader_addline(&buffer
, "%s fp[%u][%u][%u] = {...}",
2508 shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.fp
.index
,
2509 ins
.declaration
.fp
.array_size
, ins
.declaration
.fp
.body_count
);
2511 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_RAW
)
2513 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2514 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2516 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2518 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2519 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2520 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2522 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2524 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2525 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2526 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2527 shader_addline(&buffer
, ", comparisonMode");
2529 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2530 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
2531 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2532 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2533 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
2535 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2537 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2539 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2540 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2542 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2544 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2545 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2547 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2549 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2550 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2552 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2554 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2555 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2556 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2558 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2560 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2561 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2562 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2563 ins
.declaration
.tgsm_structured
.structure_count
);
2565 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2567 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2568 ins
.declaration
.thread_group_size
.x
,
2569 ins
.declaration
.thread_group_size
.y
,
2570 ins
.declaration
.thread_group_size
.z
);
2572 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_RAW
)
2574 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2575 shader_dump_uav_flags(&buffer
, ins
.flags
);
2576 shader_addline(&buffer
, " ");
2577 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2579 else if (ins
.handler_idx
== WINED3DSIH_DCL_UAV_STRUCTURED
)
2581 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2582 shader_dump_uav_flags(&buffer
, ins
.flags
);
2583 shader_addline(&buffer
, " ");
2584 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2585 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2587 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2589 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2590 ins
.dst
[0].reg
.idx
[0].offset
),
2591 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[0],
2592 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[1],
2593 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[2],
2594 *(const float *)&ins
.src
[0].reg
.u
.immconst_data
[3]);
2596 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2598 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2599 ins
.src
[0].reg
.u
.immconst_data
[0],
2600 ins
.src
[0].reg
.u
.immconst_data
[1],
2601 ins
.src
[0].reg
.u
.immconst_data
[2],
2602 ins
.src
[0].reg
.u
.immconst_data
[3]);
2604 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2606 shader_addline(&buffer
, "defb b%u = %s",
2607 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.u
.immconst_data
[0] ? "true" : "false");
2613 shader_addline(&buffer
, "(");
2614 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2615 shader_addline(&buffer
, ") ");
2618 /* PixWin marks instructions with the coissue flag with a '+' */
2620 shader_addline(&buffer
, "+");
2622 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2624 if (ins
.handler_idx
== WINED3DSIH_BREAKP
2625 || ins
.handler_idx
== WINED3DSIH_IF
)
2629 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
2630 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
2631 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
2634 else if (ins
.handler_idx
== WINED3DSIH_IFC
2635 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
2639 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
2640 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
2641 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
2642 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
2643 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
2644 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
2645 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
2648 else if (ins
.handler_idx
== WINED3DSIH_TEX
2649 && shader_version
.major
>= 2
2650 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
2652 shader_addline(&buffer
, "p");
2654 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
2658 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
2659 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2660 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2663 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
2667 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2668 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2671 else if (ins
.handler_idx
== WINED3DSIH_SYNC
)
2673 shader_dump_sync_flags(&buffer
, ins
.flags
);
2676 if (wined3d_shader_instruction_has_texel_offset(&ins
))
2677 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
2679 for (i
= 0; i
< ins
.dst_count
; ++i
)
2681 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
2682 shader_addline(&buffer
, !i
? " " : ", ");
2683 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
2686 /* Other source tokens */
2687 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
2689 shader_addline(&buffer
, !i
? " " : ", ");
2690 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
2693 shader_addline(&buffer
, "\n");
2696 for (p
= buffer
.buffer
; *p
; p
= q
)
2698 if (!(q
= strstr(p
, "\n")))
2702 TRACE(" %.*s", (int)(q
- p
), p
);
2705 string_buffer_free(&buffer
);
2708 static void shader_cleanup(struct wined3d_shader
*shader
)
2710 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
2711 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2712 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2713 shader
->device
->shader_backend
->shader_destroy(shader
);
2714 shader_cleanup_reg_maps(&shader
->reg_maps
);
2715 HeapFree(GetProcessHeap(), 0, shader
->function
);
2716 shader_delete_constant_list(&shader
->constantsF
);
2717 shader_delete_constant_list(&shader
->constantsB
);
2718 shader_delete_constant_list(&shader
->constantsI
);
2719 list_remove(&shader
->shader_list_entry
);
2721 if (shader
->frontend
&& shader
->frontend_data
)
2722 shader
->frontend
->shader_free(shader
->frontend_data
);
2725 struct shader_none_priv
2727 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
2728 const struct fragment_pipeline
*fragment_pipe
;
2729 BOOL ffp_proj_control
;
2732 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
2733 static void shader_none_select_compute(void *shader_priv
, struct wined3d_context
*context
,
2734 const struct wined3d_state
*state
) {}
2735 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2736 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2737 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
2738 const struct wined3d_state
*state
) {}
2739 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
2740 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
2741 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
2743 /* Context activation is done by the caller. */
2744 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
2745 const struct wined3d_state
*state
)
2747 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2748 struct shader_none_priv
*priv
= shader_priv
;
2750 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
2751 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
2754 /* Context activation is done by the caller. */
2755 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
2757 struct shader_none_priv
*priv
= shader_priv
;
2758 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2760 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
2761 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
2763 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
2764 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
2765 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
2766 | (1u << WINED3D_SHADER_TYPE_HULL
)
2767 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
2768 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
2771 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
2772 const struct fragment_pipeline
*fragment_pipe
)
2774 struct fragment_caps fragment_caps
;
2775 void *vertex_priv
, *fragment_priv
;
2776 struct shader_none_priv
*priv
;
2778 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
2779 return E_OUTOFMEMORY
;
2781 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
2783 ERR("Failed to initialize vertex pipe.\n");
2784 HeapFree(GetProcessHeap(), 0, priv
);
2788 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
2790 ERR("Failed to initialize fragment pipe.\n");
2791 vertex_pipe
->vp_free(device
);
2792 HeapFree(GetProcessHeap(), 0, priv
);
2796 priv
->vertex_pipe
= vertex_pipe
;
2797 priv
->fragment_pipe
= fragment_pipe
;
2798 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
2799 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
2801 device
->vertex_priv
= vertex_priv
;
2802 device
->fragment_priv
= fragment_priv
;
2803 device
->shader_priv
= priv
;
2808 static void shader_none_free(struct wined3d_device
*device
)
2810 struct shader_none_priv
*priv
= device
->shader_priv
;
2812 priv
->fragment_pipe
->free_private(device
);
2813 priv
->vertex_pipe
->vp_free(device
);
2814 HeapFree(GetProcessHeap(), 0, priv
);
2817 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
2822 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
2824 /* Set the shader caps to 0 for the none shader backend */
2825 caps
->vs_version
= 0;
2826 caps
->hs_version
= 0;
2827 caps
->ds_version
= 0;
2828 caps
->gs_version
= 0;
2829 caps
->ps_version
= 0;
2830 caps
->cs_version
= 0;
2831 caps
->vs_uniform_count
= 0;
2832 caps
->ps_uniform_count
= 0;
2833 caps
->ps_1x_max_value
= 0.0f
;
2834 caps
->varying_count
= 0;
2835 caps
->wined3d_caps
= 0;
2838 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2840 /* We "support" every possible fixup, since we don't support any shader
2841 * model, and will never have to actually sample a texture. */
2845 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2847 struct shader_none_priv
*priv
= shader_priv
;
2849 return priv
->ffp_proj_control
;
2852 const struct wined3d_shader_backend_ops none_shader_backend
=
2854 shader_none_handle_instruction
,
2856 shader_none_select_compute
,
2857 shader_none_disable
,
2858 shader_none_update_float_vertex_constants
,
2859 shader_none_update_float_pixel_constants
,
2860 shader_none_load_constants
,
2861 shader_none_destroy
,
2864 shader_none_allocate_context_data
,
2865 shader_none_free_context_data
,
2866 shader_none_init_context_state
,
2867 shader_none_get_caps
,
2868 shader_none_color_fixup_supported
,
2869 shader_none_has_ffp_proj_control
,
2872 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, DWORD float_const_count
,
2873 enum wined3d_shader_type type
, unsigned int max_version
)
2875 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2876 const struct wined3d_shader_frontend
*fe
;
2878 unsigned int backend_version
;
2879 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2881 TRACE("shader %p, float_const_count %u, type %#x, max_version %u.\n",
2882 shader
, float_const_count
, type
, max_version
);
2884 fe
= shader
->frontend
;
2885 if (!(shader
->frontend_data
= fe
->shader_init(shader
->function
,
2886 shader
->functionLength
, &shader
->output_signature
)))
2888 FIXME("Failed to initialize frontend.\n");
2889 return WINED3DERR_INVALIDCALL
;
2892 /* First pass: trace shader. */
2893 if (TRACE_ON(d3d_shader
))
2894 shader_trace_init(fe
, shader
->frontend_data
);
2896 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2897 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2898 &shader
->output_signature
, float_const_count
)))
2901 if (reg_maps
->shader_version
.type
!= type
)
2903 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2904 return WINED3DERR_INVALIDCALL
;
2906 if (reg_maps
->shader_version
.major
> max_version
)
2908 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2909 return WINED3DERR_INVALIDCALL
;
2913 case WINED3D_SHADER_TYPE_VERTEX
:
2914 backend_version
= d3d_info
->limits
.vs_version
;
2916 case WINED3D_SHADER_TYPE_HULL
:
2917 backend_version
= d3d_info
->limits
.hs_version
;
2919 case WINED3D_SHADER_TYPE_DOMAIN
:
2920 backend_version
= d3d_info
->limits
.ds_version
;
2922 case WINED3D_SHADER_TYPE_GEOMETRY
:
2923 backend_version
= d3d_info
->limits
.gs_version
;
2925 case WINED3D_SHADER_TYPE_PIXEL
:
2926 backend_version
= d3d_info
->limits
.ps_version
;
2928 case WINED3D_SHADER_TYPE_COMPUTE
:
2929 backend_version
= d3d_info
->limits
.cs_version
;
2932 FIXME("No backend version-checking for this shader type.\n");
2933 backend_version
= 0;
2935 if (reg_maps
->shader_version
.major
> backend_version
)
2937 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2938 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2939 return WINED3DERR_INVALIDCALL
;
2945 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2947 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2949 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2954 static void wined3d_shader_destroy_object(void *object
)
2956 shader_cleanup(object
);
2957 HeapFree(GetProcessHeap(), 0, object
);
2960 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2962 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2964 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2968 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2969 wined3d_cs_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
2975 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2977 TRACE("shader %p.\n", shader
);
2979 return shader
->parent
;
2982 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2983 void *byte_code
, UINT
*byte_code_size
)
2985 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2989 *byte_code_size
= shader
->functionLength
;
2993 if (*byte_code_size
< shader
->functionLength
)
2995 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2996 * than the required size we should write the required size and
2997 * return D3DERR_MOREDATA. That's not actually true. */
2998 return WINED3DERR_INVALIDCALL
;
3001 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
3006 /* Set local constants for d3d8 shaders. */
3007 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
3008 UINT start_idx
, const float *src_data
, UINT count
)
3010 UINT end_idx
= start_idx
+ count
;
3013 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
3015 if (end_idx
> shader
->limits
->constant_float
)
3017 WARN("end_idx %u > float constants limit %u.\n",
3018 end_idx
, shader
->limits
->constant_float
);
3019 end_idx
= shader
->limits
->constant_float
;
3022 for (i
= start_idx
; i
< end_idx
; ++i
)
3024 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
3027 return E_OUTOFMEMORY
;
3030 value
= (float *)lconst
->value
;
3031 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
3032 list_add_head(&shader
->constantsF
, &lconst
->entry
);
3034 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
3035 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
3037 shader
->lconst_inf_or_nan
= TRUE
;
3044 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3045 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_d3d_info
*d3d_info
)
3047 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
3048 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
3049 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
3050 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
3051 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
3052 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
3053 args
->next_shader_type
= state
->shader
[WINED3D_SHADER_TYPE_HULL
] ? WINED3D_SHADER_TYPE_HULL
3054 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
] ? WINED3D_SHADER_TYPE_GEOMETRY
3055 : WINED3D_SHADER_TYPE_PIXEL
;
3056 if (shader
->reg_maps
.shader_version
.major
>= 4)
3057 args
->next_shader_input_count
= state
->shader
[WINED3D_SHADER_TYPE_HULL
]
3058 ? state
->shader
[WINED3D_SHADER_TYPE_HULL
]->limits
->packed_input
3059 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]
3060 ? state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]->limits
->packed_input
3061 : state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3062 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3064 args
->next_shader_input_count
= 0;
3065 args
->swizzle_map
= swizzle_map
;
3066 if (d3d_info
->emulated_flatshading
)
3067 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3069 args
->flatshading
= 0;
3072 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
3074 if (usage_idx1
!= usage_idx2
)
3076 if (usage1
== usage2
)
3078 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
3080 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
3086 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
3087 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
3089 WORD map
= shader
->reg_maps
.input_registers
;
3092 for (i
= 0; map
; map
>>= 1, ++i
)
3094 if (!(map
& 1)) continue;
3096 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
3097 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
3106 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
3107 const struct wined3d_shader_signature
*src
, char **signature_strings
)
3109 struct wined3d_shader_signature_element
*e
;
3114 if (!src
->element_count
)
3117 ptr
= *signature_strings
;
3119 dst
->element_count
= src
->element_count
;
3120 if (!(dst
->elements
= wined3d_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
3121 return E_OUTOFMEMORY
;
3123 for (i
= 0; i
< src
->element_count
; ++i
)
3125 e
= &src
->elements
[i
];
3126 dst
->elements
[i
] = *e
;
3128 len
= strlen(e
->semantic_name
);
3129 memcpy(ptr
, e
->semantic_name
, len
+ 1);
3130 dst
->elements
[i
].semantic_name
= ptr
;
3134 *signature_strings
= ptr
;
3139 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3140 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
3141 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3143 struct wined3d_shader_signature_element
*e
;
3144 size_t byte_code_size
;
3150 TRACE("byte_code %p, byte_code_size %#lx, format %#x, max_version %#x.\n",
3151 desc
->byte_code
, (long)desc
->byte_code_size
, desc
->format
, desc
->max_version
);
3153 if (!desc
->byte_code
)
3154 return WINED3DERR_INVALIDCALL
;
3156 if (!(shader
->frontend
= shader_select_frontend(desc
->format
)))
3158 FIXME("Unable to find frontend for shader.\n");
3159 return WINED3DERR_INVALIDCALL
;
3163 shader
->device
= device
;
3164 shader
->parent
= parent
;
3165 shader
->parent_ops
= parent_ops
;
3168 for (i
= 0; i
< desc
->input_signature
.element_count
; ++i
)
3170 e
= &desc
->input_signature
.elements
[i
];
3171 len
= strlen(e
->semantic_name
);
3172 if (len
>= ~(SIZE_T
)0 - total
)
3173 return E_OUTOFMEMORY
;
3177 for (i
= 0; i
< desc
->output_signature
.element_count
; ++i
)
3179 e
= &desc
->output_signature
.elements
[i
];
3180 len
= strlen(e
->semantic_name
);
3181 if (len
>= ~(SIZE_T
)0 - total
)
3182 return E_OUTOFMEMORY
;
3186 if (total
&& !(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
3187 return E_OUTOFMEMORY
;
3188 ptr
= shader
->signature_strings
;
3190 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
3192 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3195 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
3197 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
3198 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
3202 list_init(&shader
->linked_programs
);
3203 list_init(&shader
->constantsF
);
3204 list_init(&shader
->constantsB
);
3205 list_init(&shader
->constantsI
);
3206 shader
->lconst_inf_or_nan
= FALSE
;
3207 list_init(&shader
->reg_maps
.indexable_temps
);
3208 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
3210 byte_code_size
= desc
->byte_code_size
;
3211 if (byte_code_size
== ~(size_t)0)
3213 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
3214 struct wined3d_shader_version shader_version
;
3215 struct wined3d_shader_instruction ins
;
3219 if (!(fe_data
= fe
->shader_init(desc
->byte_code
, byte_code_size
, &shader
->output_signature
)))
3221 WARN("Failed to initialise frontend data.\n");
3222 shader_cleanup(shader
);
3223 return WINED3DERR_INVALIDCALL
;
3226 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
3227 while (!fe
->shader_is_end(fe_data
, &ptr
))
3228 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
3230 fe
->shader_free(fe_data
);
3232 byte_code_size
= (ptr
- desc
->byte_code
) * sizeof(*ptr
);
3235 if (!(shader
->function
= HeapAlloc(GetProcessHeap(), 0, byte_code_size
)))
3237 shader_cleanup(shader
);
3238 return E_OUTOFMEMORY
;
3240 memcpy(shader
->function
, desc
->byte_code
, byte_code_size
);
3241 shader
->functionLength
= byte_code_size
;
3243 if (FAILED(hr
= shader_set_function(shader
, float_const_count
, type
, desc
->max_version
)))
3245 WARN("Failed to set function, hr %#x.\n", hr
);
3246 shader_cleanup(shader
);
3249 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3254 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3255 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3257 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3261 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3262 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3265 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3267 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3269 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3272 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3273 shader_usage_from_semantic_name(input
->semantic_name
);
3274 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3277 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3278 shader
->load_local_constsF
= TRUE
;
3283 static HRESULT
domain_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3284 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3286 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
);
3289 static HRESULT
hull_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3290 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3292 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
);
3295 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3296 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3298 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
);
3301 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3302 struct gs_compile_args
*args
)
3304 args
->ps_input_count
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3305 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3308 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3309 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3311 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3312 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3313 const struct wined3d_texture
*texture
;
3316 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3317 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3319 static unsigned int warned
= 0;
3321 args
->srgb_correction
= 1;
3322 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3323 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3324 "support, expect rendering artifacts.\n");
3327 if (shader
->reg_maps
.shader_version
.major
== 1
3328 && shader
->reg_maps
.shader_version
.minor
<= 3)
3330 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3332 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3334 if (flags
& WINED3D_TTFF_PROJECTED
)
3336 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3338 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3340 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3342 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3343 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3345 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3347 struct wined3d_vertex_declaration_element
*element
=
3348 &state
->vertex_declaration
->elements
[j
];
3350 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3351 && element
->usage_idx
== index
)
3353 max_valid
= element
->format
->component_count
;
3357 if (!tex_transform
|| tex_transform
> max_valid
)
3359 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3360 tex_transform
, max_valid
);
3361 tex_transform
= max_valid
;
3363 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3364 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3365 && tex_transform
> WINED3D_TTFF_COUNT2
)
3366 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3367 && tex_transform
> WINED3D_TTFF_COUNT3
))
3368 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3371 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3372 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3373 i
, tex_transform
, resource_type
);
3377 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3379 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3383 if (shader
->reg_maps
.shader_version
.major
== 1
3384 && shader
->reg_maps
.shader_version
.minor
<= 4)
3386 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3388 const struct wined3d_texture
*texture
= state
->textures
[i
];
3390 if (!shader
->reg_maps
.resource_info
[i
].type
)
3393 /* Treat unbound textures as 2D. The dummy texture will provide
3394 * the proper sample value. The tex_types bitmap defaults to
3395 * 2D because of the memset. */
3399 switch (texture
->target
)
3401 /* RECT textures are distinguished from 2D textures via np2_fixup */
3402 case GL_TEXTURE_RECTANGLE_ARB
:
3407 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3410 case GL_TEXTURE_CUBE_MAP_ARB
:
3411 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3417 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3419 if (!shader
->reg_maps
.resource_info
[i
].type
)
3422 texture
= state
->textures
[i
];
3425 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3428 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3429 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3431 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3433 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3434 args
->shadow
|= 1u << i
;
3436 /* Flag samplers that need NP2 texcoord fixup. */
3437 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3438 args
->np2_fixup
|= (1u << i
);
3441 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3442 if (shader
->reg_maps
.shader_version
.major
>= 4)
3445 if (shader
->reg_maps
.shader_version
.major
>= 3)
3447 if (position_transformed
)
3448 args
->vp_mode
= pretransformed
;
3449 else if (use_vs(state
))
3450 args
->vp_mode
= vertexshader
;
3452 args
->vp_mode
= fixedfunction
;
3453 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3457 args
->vp_mode
= vertexshader
;
3458 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3460 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3462 case WINED3D_FOG_NONE
:
3463 if (position_transformed
|| use_vs(state
))
3465 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3469 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3471 case WINED3D_FOG_NONE
: /* Fall through. */
3472 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3473 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3474 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3478 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3479 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3480 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3485 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3489 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3491 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3493 args
->texcoords_initialized
= 0;
3494 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
3498 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
3499 args
->texcoords_initialized
|= 1u << i
;
3503 const struct wined3d_stream_info
*si
= &context
->stream_info
;
3504 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3506 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
3507 & WINED3D_FFP_TCI_MASK
3508 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
3509 args
->texcoords_initialized
|= 1u << i
;
3515 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
3518 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
3519 && state
->gl_primitive_type
== GL_POINTS
;
3521 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3522 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
3524 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
3525 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
3526 : WINED3D_CMP_ALWAYS
) - 1;
3528 if (d3d_info
->emulated_flatshading
)
3529 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3531 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
3532 ? context
->render_offscreen
: 0;
3535 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3536 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3538 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
3539 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
3542 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
3543 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
3546 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3548 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
3551 highest_reg_used
= i
;
3555 /* Don't do any register mapping magic if it is not needed, or if we can't
3556 * achieve anything anyway */
3557 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
3558 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
3559 || shader
->reg_maps
.shader_version
.major
>= 4)
3561 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
3563 /* This happens with relative addressing. The input mapper function
3564 * warns about this if the higher registers are declared too, so
3565 * don't write a FIXME here */
3566 WARN("More varying registers used than supported\n");
3569 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3571 shader
->u
.ps
.input_reg_map
[i
] = i
;
3574 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
3578 shader
->u
.ps
.declared_in_count
= 0;
3579 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3581 if (shader
->u
.ps
.input_reg_used
& (1u << i
))
3582 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
3583 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
3590 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
3592 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3593 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
3596 if (reg_maps
->shader_version
.major
!= 1) return;
3598 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3600 /* We don't sample from this sampler. */
3601 if (!resource_info
[i
].type
)
3604 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
3606 case WINED3D_SHADER_TEX_2D
:
3607 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
3610 case WINED3D_SHADER_TEX_3D
:
3611 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
3614 case WINED3D_SHADER_TEX_CUBE
:
3615 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
3621 static HRESULT
compute_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3622 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3624 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
);
3627 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3628 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3630 struct wined3d_shader
*object
;
3633 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3634 device
, desc
, parent
, parent_ops
, shader
);
3636 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3637 return E_OUTOFMEMORY
;
3639 if (FAILED(hr
= compute_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3641 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
3642 HeapFree(GetProcessHeap(), 0, object
);
3646 TRACE("Created compute shader %p.\n", object
);
3652 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3653 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3655 struct wined3d_shader
*object
;
3658 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3659 device
, desc
, parent
, parent_ops
, shader
);
3661 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3662 return E_OUTOFMEMORY
;
3664 if (FAILED(hr
= domain_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3666 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
3667 HeapFree(GetProcessHeap(), 0, object
);
3671 TRACE("Created domain shader %p.\n", object
);
3677 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3678 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3680 struct wined3d_shader
*object
;
3683 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3684 device
, desc
, parent
, parent_ops
, shader
);
3686 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3688 return E_OUTOFMEMORY
;
3690 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3692 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
3693 HeapFree(GetProcessHeap(), 0, object
);
3697 TRACE("Created geometry shader %p.\n", object
);
3703 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3704 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3706 struct wined3d_shader
*object
;
3709 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3710 device
, desc
, parent
, parent_ops
, shader
);
3712 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3713 return E_OUTOFMEMORY
;
3715 if (FAILED(hr
= hull_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3717 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
3718 HeapFree(GetProcessHeap(), 0, object
);
3722 TRACE("Created hull shader %p.\n", object
);
3728 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3729 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3731 struct wined3d_shader
*object
;
3734 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3735 device
, desc
, parent
, parent_ops
, shader
);
3737 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3739 return E_OUTOFMEMORY
;
3741 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3743 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3744 HeapFree(GetProcessHeap(), 0, object
);
3748 TRACE("Created pixel shader %p.\n", object
);
3754 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3755 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3757 struct wined3d_shader
*object
;
3760 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3761 device
, desc
, parent
, parent_ops
, shader
);
3763 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3765 return E_OUTOFMEMORY
;
3767 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3769 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3770 HeapFree(GetProcessHeap(), 0, object
);
3774 TRACE("Created vertex shader %p.\n", object
);