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_BEM */ "bem",
47 /* WINED3DSIH_BFI */ "bfi",
48 /* WINED3DSIH_BFREV */ "bfrev",
49 /* WINED3DSIH_BREAK */ "break",
50 /* WINED3DSIH_BREAKC */ "breakc",
51 /* WINED3DSIH_BREAKP */ "breakp",
52 /* WINED3DSIH_BUFINFO */ "bufinfo",
53 /* WINED3DSIH_CALL */ "call",
54 /* WINED3DSIH_CALLNZ */ "callnz",
55 /* WINED3DSIH_CASE */ "case",
56 /* WINED3DSIH_CMP */ "cmp",
57 /* WINED3DSIH_CND */ "cnd",
58 /* WINED3DSIH_CONTINUE */ "continue",
59 /* WINED3DSIH_CRS */ "crs",
60 /* WINED3DSIH_CUT */ "cut",
61 /* WINED3DSIH_CUT_STREAM */ "cut_stream",
62 /* WINED3DSIH_DCL */ "dcl",
63 /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
64 /* WINED3DSIH_DCL_GLOBAL_FLAGS */ "dcl_globalFlags",
65 /* WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT */ "dcl_hs_fork_phase_instance_count",
66 /* WINED3DSIH_DCL_HS_MAX_TESSFACTOR */ "dcl_hs_max_tessfactor",
67 /* WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER */ "dcl_immediateConstantBuffer",
68 /* WINED3DSIH_DCL_INDEXABLE_TEMP */ "dcl_indexableTemp",
69 /* WINED3DSIH_DCL_INPUT */ "dcl_input",
70 /* WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT */ "dcl_input_control_point_count",
71 /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
72 /* WINED3DSIH_DCL_INPUT_PS */ "dcl_input_ps",
73 /* WINED3DSIH_DCL_INPUT_PS_SGV */ "dcl_input_ps_sgv",
74 /* WINED3DSIH_DCL_INPUT_PS_SIV */ "dcl_input_ps_siv",
75 /* WINED3DSIH_DCL_INPUT_SGV */ "dcl_input_sgv",
76 /* WINED3DSIH_DCL_INPUT_SIV */ "dcl_input_siv",
77 /* WINED3DSIH_DCL_OUTPUT */ "dcl_output",
78 /* WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT */ "dcl_output_control_point_count",
79 /* WINED3DSIH_DCL_OUTPUT_SIV */ "dcl_output_siv",
80 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
81 /* WINED3DSIH_DCL_RESOURCE_STRUCTURED */ "dcl_resource_structured",
82 /* WINED3DSIH_DCL_SAMPLER */ "dcl_sampler",
83 /* WINED3DSIH_DCL_STREAM */ "dcl_stream",
84 /* WINED3DSIH_DCL_TEMPS */ "dcl_temps",
85 /* WINED3DSIH_DCL_TESSELLATOR_DOMAIN */ "dcl_tessellator_domain",
86 /* WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE */ "dcl_tessellator_output_primitive",
87 /* WINED3DSIH_DCL_TESSELLATOR_PARTITIONING */ "dcl_tessellator_partitioning",
88 /* WINED3DSIH_DCL_TGSM_RAW */ "dcl_tgsm_raw",
89 /* WINED3DSIH_DCL_TGSM_STRUCTURED */ "dcl_tgsm_structured",
90 /* WINED3DSIH_DCL_THREAD_GROUP */ "dcl_thread_group",
91 /* WINED3DSIH_DCL_UAV_TYPED */ "dcl_uav_typed",
92 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
93 /* WINED3DSIH_DEF */ "def",
94 /* WINED3DSIH_DEFAULT */ "default",
95 /* WINED3DSIH_DEFB */ "defb",
96 /* WINED3DSIH_DEFI */ "defi",
97 /* WINED3DSIH_DIV */ "div",
98 /* WINED3DSIH_DP2 */ "dp2",
99 /* WINED3DSIH_DP2ADD */ "dp2add",
100 /* WINED3DSIH_DP3 */ "dp3",
101 /* WINED3DSIH_DP4 */ "dp4",
102 /* WINED3DSIH_DST */ "dst",
103 /* WINED3DSIH_DSX */ "dsx",
104 /* WINED3DSIH_DSX_COARSE */ "deriv_rtx_coarse",
105 /* WINED3DSIH_DSX_FINE */ "deriv_rtx_fine",
106 /* WINED3DSIH_DSY */ "dsy",
107 /* WINED3DSIH_DSY_COARSE */ "deriv_rty_coarse",
108 /* WINED3DSIH_DSY_FINE */ "deriv_rty_fine",
109 /* WINED3DSIH_ELSE */ "else",
110 /* WINED3DSIH_EMIT */ "emit",
111 /* WINED3DSIH_EMIT_STREAM */ "emit_stream",
112 /* WINED3DSIH_ENDIF */ "endif",
113 /* WINED3DSIH_ENDLOOP */ "endloop",
114 /* WINED3DSIH_ENDREP */ "endrep",
115 /* WINED3DSIH_ENDSWITCH */ "endswitch",
116 /* WINED3DSIH_EQ */ "eq",
117 /* WINED3DSIH_EXP */ "exp",
118 /* WINED3DSIH_EXPP */ "expp",
119 /* WINED3DSIH_FRC */ "frc",
120 /* WINED3DSIH_FTOI */ "ftoi",
121 /* WINED3DSIH_FTOU */ "ftou",
122 /* WINED3DSIH_GATHER4 */ "gather4",
123 /* WINED3DSIH_GATHER4_C */ "gather4_c",
124 /* WINED3DSIH_GE */ "ge",
125 /* WINED3DSIH_HS_CONTROL_POINT_PHASE */ "hs_control_point_phase",
126 /* WINED3DSIH_HS_DECLS */ "hs_decls",
127 /* WINED3DSIH_HS_FORK_PHASE */ "hs_fork_phase",
128 /* WINED3DSIH_HS_JOIN_PHASE */ "hs_join_phase",
129 /* WINED3DSIH_IADD */ "iadd",
130 /* WINED3DSIH_IEQ */ "ieq",
131 /* WINED3DSIH_IF */ "if",
132 /* WINED3DSIH_IFC */ "ifc",
133 /* WINED3DSIH_IGE */ "ige",
134 /* WINED3DSIH_ILT */ "ilt",
135 /* WINED3DSIH_IMAD */ "imad",
136 /* WINED3DSIH_IMAX */ "imax",
137 /* WINED3DSIH_IMIN */ "imin",
138 /* WINED3DSIH_IMM_ATOMIC_ALLOC */ "imm_atomic_alloc",
139 /* WINED3DSIH_IMM_ATOMIC_CONSUME */ "imm_atomic_consume",
140 /* WINED3DSIH_IMUL */ "imul",
141 /* WINED3DSIH_INE */ "ine",
142 /* WINED3DSIH_INEG */ "ineg",
143 /* WINED3DSIH_ISHL */ "ishl",
144 /* WINED3DSIH_ISHR */ "ishr",
145 /* WINED3DSIH_ITOF */ "itof",
146 /* WINED3DSIH_LABEL */ "label",
147 /* WINED3DSIH_LD */ "ld",
148 /* WINED3DSIH_LD2DMS */ "ld2dms",
149 /* WINED3DSIH_LD_RAW */ "ld_raw",
150 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
151 /* WINED3DSIH_LD_UAV_TYPED */ "ld_uav_typed",
152 /* WINED3DSIH_LIT */ "lit",
153 /* WINED3DSIH_LOD */ "lod",
154 /* WINED3DSIH_LOG */ "log",
155 /* WINED3DSIH_LOGP */ "logp",
156 /* WINED3DSIH_LOOP */ "loop",
157 /* WINED3DSIH_LRP */ "lrp",
158 /* WINED3DSIH_LT */ "lt",
159 /* WINED3DSIH_M3x2 */ "m3x2",
160 /* WINED3DSIH_M3x3 */ "m3x3",
161 /* WINED3DSIH_M3x4 */ "m3x4",
162 /* WINED3DSIH_M4x3 */ "m4x3",
163 /* WINED3DSIH_M4x4 */ "m4x4",
164 /* WINED3DSIH_MAD */ "mad",
165 /* WINED3DSIH_MAX */ "max",
166 /* WINED3DSIH_MIN */ "min",
167 /* WINED3DSIH_MOV */ "mov",
168 /* WINED3DSIH_MOVA */ "mova",
169 /* WINED3DSIH_MOVC */ "movc",
170 /* WINED3DSIH_MUL */ "mul",
171 /* WINED3DSIH_NE */ "ne",
172 /* WINED3DSIH_NOP */ "nop",
173 /* WINED3DSIH_NOT */ "not",
174 /* WINED3DSIH_NRM */ "nrm",
175 /* WINED3DSIH_OR */ "or",
176 /* WINED3DSIH_PHASE */ "phase",
177 /* WINED3DSIH_POW */ "pow",
178 /* WINED3DSIH_RCP */ "rcp",
179 /* WINED3DSIH_REP */ "rep",
180 /* WINED3DSIH_RESINFO */ "resinfo",
181 /* WINED3DSIH_RET */ "ret",
182 /* WINED3DSIH_ROUND_NE */ "round_ne",
183 /* WINED3DSIH_ROUND_NI */ "round_ni",
184 /* WINED3DSIH_ROUND_PI */ "round_pi",
185 /* WINED3DSIH_ROUND_Z */ "round_z",
186 /* WINED3DSIH_RSQ */ "rsq",
187 /* WINED3DSIH_SAMPLE */ "sample",
188 /* WINED3DSIH_SAMPLE_B */ "sample_b",
189 /* WINED3DSIH_SAMPLE_C */ "sample_c",
190 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
191 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
192 /* WINED3DSIH_SAMPLE_INFO */ "sample_info",
193 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
194 /* WINED3DSIH_SAMPLE_POS */ "sample_pos",
195 /* WINED3DSIH_SETP */ "setp",
196 /* WINED3DSIH_SGE */ "sge",
197 /* WINED3DSIH_SGN */ "sgn",
198 /* WINED3DSIH_SINCOS */ "sincos",
199 /* WINED3DSIH_SLT */ "slt",
200 /* WINED3DSIH_SQRT */ "sqrt",
201 /* WINED3DSIH_STORE_RAW */ "store_raw",
202 /* WINED3DSIH_STORE_STRUCTURED */ "store_structured",
203 /* WINED3DSIH_STORE_UAV_TYPED */ "store_uav_typed",
204 /* WINED3DSIH_SUB */ "sub",
205 /* WINED3DSIH_SWAPC */ "swapc",
206 /* WINED3DSIH_SWITCH */ "switch",
207 /* WINED3DSIH_TEX */ "texld",
208 /* WINED3DSIH_TEXBEM */ "texbem",
209 /* WINED3DSIH_TEXBEML */ "texbeml",
210 /* WINED3DSIH_TEXCOORD */ "texcrd",
211 /* WINED3DSIH_TEXDEPTH */ "texdepth",
212 /* WINED3DSIH_TEXDP3 */ "texdp3",
213 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
214 /* WINED3DSIH_TEXKILL */ "texkill",
215 /* WINED3DSIH_TEXLDD */ "texldd",
216 /* WINED3DSIH_TEXLDL */ "texldl",
217 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
218 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
219 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
220 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
221 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
222 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
223 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
224 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
225 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
226 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
227 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
228 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
229 /* WINED3DSIH_UBFE */ "ubfe",
230 /* WINED3DSIH_UDIV */ "udiv",
231 /* WINED3DSIH_UGE */ "uge",
232 /* WINED3DSIH_ULT */ "ult",
233 /* WINED3DSIH_UMAX */ "umax",
234 /* WINED3DSIH_UMIN */ "umin",
235 /* WINED3DSIH_USHR */ "ushr",
236 /* WINED3DSIH_UTOF */ "utof",
237 /* WINED3DSIH_XOR */ "xor",
240 static const char * const semantic_names
[] =
242 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
243 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
244 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
245 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
246 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
247 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
248 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
249 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
250 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
251 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
252 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
253 /* WINED3D_DECL_USAGE_FOG */ "FOG",
254 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
255 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
260 enum wined3d_sysval_semantic sysval_semantic
;
261 const char *sysval_name
;
263 sysval_semantic_names
[] =
265 {WINED3D_SV_POSITION
, "SV_Position"},
266 {WINED3D_SV_CLIP_DISTANCE
, "SV_ClipDistance"},
267 {WINED3D_SV_CULL_DISTANCE
, "SV_CullDistance"},
268 {WINED3D_SV_RENDER_TARGET_ARRAY_INDEX
, "SV_RenderTargetArrayIndex"},
269 {WINED3D_SV_VIEWPORT_ARRAY_INDEX
, "SV_ViewportArrayIndex"},
270 {WINED3D_SV_VERTEX_ID
, "SV_VertexID"},
271 {WINED3D_SV_INSTANCE_ID
, "SV_InstanceID"},
272 {WINED3D_SV_PRIMITIVE_ID
, "SV_PrimitiveID"},
273 {WINED3D_SV_IS_FRONT_FACE
, "SV_IsFrontFace"},
274 {WINED3D_SV_SAMPLE_INDEX
, "SV_SampleIndex"},
275 {WINED3D_SV_QUAD_U0_TESS_FACTOR
, "finalQuadUeq0EdgeTessFactor"},
276 {WINED3D_SV_QUAD_V0_TESS_FACTOR
, "finalQuadVeq0EdgeTessFactor"},
277 {WINED3D_SV_QUAD_U1_TESS_FACTOR
, "finalQuadUeq1EdgeTessFactor"},
278 {WINED3D_SV_QUAD_V1_TESS_FACTOR
, "finalQuadVeq1EdgeTessFactor"},
279 {WINED3D_SV_QUAD_U_INNER_TESS_FACTOR
, "finalQuadUInsideTessFactor"},
280 {WINED3D_SV_QUAD_V_INNER_TESS_FACTOR
, "finalQuadVInsideTessFactor"},
281 {WINED3D_SV_TRIANGLE_U_TESS_FACTOR
, "finalTriUeq0EdgeTessFactor"},
282 {WINED3D_SV_TRIANGLE_V_TESS_FACTOR
, "finalTriVeq0EdgeTessFactor"},
283 {WINED3D_SV_TRIANGLE_W_TESS_FACTOR
, "finalTriWeq0EdgeTessFactor"},
284 {WINED3D_SV_TRIANGLE_INNER_TESS_FACTOR
, "finalTriInsideTessFactor"},
285 {WINED3D_SV_LINE_DETAIL_TESS_FACTOR
, "finalLineDetailTessFactor"},
286 {WINED3D_SV_LINE_DENSITY_TESS_FACTOR
, "finalLineDensityTessFactor"},
289 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
290 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
292 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
294 if (handler_idx
>= ARRAY_SIZE(shader_opcode_names
))
295 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
297 return shader_opcode_names
[handler_idx
];
300 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
302 if (usage
>= ARRAY_SIZE(semantic_names
))
304 FIXME("Unrecognized usage %#x.\n", usage
);
305 return "UNRECOGNIZED";
308 return semantic_names
[usage
];
311 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
315 for (i
= 0; i
< ARRAY_SIZE(semantic_names
); ++i
)
317 if (!strcmp(name
, semantic_names
[i
]))
324 static enum wined3d_sysval_semantic
shader_sysval_semantic_from_usage(enum wined3d_decl_usage usage
)
328 case WINED3D_DECL_USAGE_POSITION
:
329 return WINED3D_SV_POSITION
;
335 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
337 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
340 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
341 const struct wined3d_shader_semantic
*s
)
343 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
344 e
->semantic_idx
= s
->usage_idx
;
345 e
->sysval_semantic
= shader_sysval_semantic_from_usage(s
->usage
);
346 e
->component_type
= WINED3D_TYPE_FLOAT
;
347 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
348 e
->mask
= s
->reg
.write_mask
;
351 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
352 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
354 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
355 e
->semantic_idx
= usage_idx
;
356 e
->sysval_semantic
= shader_sysval_semantic_from_usage(usage
);
357 e
->component_type
= WINED3D_TYPE_FLOAT
;
358 e
->register_idx
= reg_idx
;
359 e
->mask
= write_mask
;
362 static const struct wined3d_shader_frontend
*shader_select_frontend(DWORD version_token
)
364 switch (version_token
>> 16)
368 return &sm1_shader_frontend
;
376 return &sm4_shader_frontend
;
379 FIXME("Unrecognised version token %#x.\n", version_token
);
384 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
386 buffer
->buffer
[0] = '\0';
387 buffer
->content_size
= 0;
390 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
392 buffer
->buffer_size
= 32;
393 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
395 ERR("Failed to allocate shader buffer memory.\n");
399 string_buffer_clear(buffer
);
403 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
405 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
408 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
411 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
413 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
414 new_buffer_size
*= 2;
415 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
417 ERR("Failed to grow buffer.\n");
418 buffer
->buffer
[buffer
->content_size
] = '\0';
421 buffer
->buffer
= new_buffer
;
422 buffer
->buffer_size
= new_buffer_size
;
426 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
431 rem
= buffer
->buffer_size
- buffer
->content_size
;
432 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
433 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
436 buffer
->content_size
+= rc
;
440 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
447 va_start(args
, format
);
448 ret
= shader_vaddline(buffer
, format
, args
);
452 if (!string_buffer_resize(buffer
, ret
))
457 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
459 struct wined3d_string_buffer
*buffer
;
461 if (list_empty(&list
->list
))
463 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
464 if (!buffer
|| !string_buffer_init(buffer
))
466 ERR("Couldn't allocate buffer for temporary string.\n");
467 HeapFree(GetProcessHeap(), 0, buffer
);
473 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
474 list_remove(&buffer
->entry
);
476 string_buffer_clear(buffer
);
480 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
484 string_buffer_clear(buffer
);
485 return shader_vaddline(buffer
, format
, args
);
488 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
495 va_start(args
, format
);
496 ret
= string_buffer_vsprintf(buffer
, format
, args
);
500 if (!string_buffer_resize(buffer
, ret
))
505 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
509 list_add_head(&list
->list
, &buffer
->entry
);
512 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
514 list_init(&list
->list
);
517 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
519 struct wined3d_string_buffer
*buffer
, *buffer_next
;
521 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
523 string_buffer_free(buffer
);
524 HeapFree(GetProcessHeap(), 0, buffer
);
526 list_init(&list
->list
);
529 /* Convert floating point offset relative to a register file to an absolute
530 * offset for float constants. */
531 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
533 switch (register_type
)
535 case WINED3DSPR_CONST
: return register_idx
;
536 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
537 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
538 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
540 FIXME("Unsupported register type: %u.\n", register_type
);
545 static void shader_delete_constant_list(struct list
*clist
)
547 struct wined3d_shader_lconst
*constant
, *constant_next
;
549 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
550 HeapFree(GetProcessHeap(), 0, constant
);
554 static void shader_set_limits(struct wined3d_shader
*shader
)
556 static const struct limits_entry
558 unsigned int min_version
;
559 unsigned int max_version
;
560 struct wined3d_shader_limits limits
;
564 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
565 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
566 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
567 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
568 * even though they are capable of supporting much more (GL
569 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
570 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
572 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
573 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
574 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
579 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
580 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
584 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packet_input */
585 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
589 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
590 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
591 {WINED3D_SHADER_VERSION(4, 1), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
596 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
597 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
598 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
599 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
600 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
601 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
602 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
607 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
608 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
610 const struct limits_entry
*limits_array
;
611 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
612 shader
->reg_maps
.shader_version
.minor
);
615 switch (shader
->reg_maps
.shader_version
.type
)
618 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
620 case WINED3D_SHADER_TYPE_VERTEX
:
621 limits_array
= vs_limits
;
623 case WINED3D_SHADER_TYPE_HULL
:
624 limits_array
= hs_limits
;
626 case WINED3D_SHADER_TYPE_DOMAIN
:
627 limits_array
= ds_limits
;
629 case WINED3D_SHADER_TYPE_GEOMETRY
:
630 limits_array
= gs_limits
;
632 case WINED3D_SHADER_TYPE_PIXEL
:
633 limits_array
= ps_limits
;
635 case WINED3D_SHADER_TYPE_COMPUTE
:
636 limits_array
= cs_limits
;
640 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
642 if (shader_version
<= limits_array
[i
].max_version
)
644 shader
->limits
= &limits_array
[i
].limits
;
651 FIXME("Unexpected shader version \"%u.%u\".\n",
652 shader
->reg_maps
.shader_version
.major
,
653 shader
->reg_maps
.shader_version
.minor
);
654 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
658 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
663 bitmap
[idx
] |= (1u << shift
);
666 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
667 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
671 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
672 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
673 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
675 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
678 case WINED3DSPR_TEMP
:
679 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
682 case WINED3DSPR_INPUT
:
683 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
685 if (reg
->idx
[0].rel_addr
)
687 /* If relative addressing is used, we must assume that all registers
688 * are used. Even if it is a construct like v3[aL], we can't assume
689 * that v0, v1 and v2 aren't read because aL can be negative */
691 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
693 shader
->u
.ps
.input_reg_used
[i
] = TRUE
;
698 shader
->u
.ps
.input_reg_used
[reg
->idx
[0].offset
] = TRUE
;
702 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
705 case WINED3DSPR_RASTOUT
:
706 if (reg
->idx
[0].offset
== 1)
708 if (reg
->idx
[0].offset
== 2)
709 reg_maps
->point_size
= 1;
712 case WINED3DSPR_MISCTYPE
:
713 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
715 if (!reg
->idx
[0].offset
)
717 else if (reg
->idx
[0].offset
== 1)
718 reg_maps
->usesfacing
= 1;
722 case WINED3DSPR_CONST
:
723 if (reg
->idx
[0].rel_addr
)
725 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
726 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
727 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
728 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
729 reg_maps
->usesrelconstF
= TRUE
;
733 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
735 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
740 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
745 case WINED3DSPR_CONSTINT
:
746 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
748 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
753 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
757 case WINED3DSPR_CONSTBOOL
:
758 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
760 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
765 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
769 case WINED3DSPR_COLOROUT
:
770 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
774 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
775 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
781 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
782 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
784 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
785 struct wined3d_shader_sampler_map
*map
;
788 map
= ®_maps
->sampler_map
;
789 entries
= map
->entries
;
790 for (i
= 0; i
< map
->count
; ++i
)
792 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
798 if (!(entries
= wined3d_calloc(4, sizeof(*entries
))))
800 ERR("Failed to allocate sampler map entries.\n");
804 map
->entries
= entries
;
806 else if (map
->count
== map
->size
)
808 size_t new_size
= map
->size
* 2;
810 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
811 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
813 ERR("Failed to resize sampler map entries.\n");
816 map
->size
= new_size
;
817 map
->entries
= entries
;
820 entry
= &entries
[map
->count
++];
821 entry
->resource_idx
= resource_idx
;
822 entry
->sampler_idx
= sampler_idx
;
823 entry
->bind_idx
= bind_idx
;
826 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
830 case WINED3DSIH_M4x4
:
831 case WINED3DSIH_M3x4
:
832 return param
== 1 ? 3 : 0;
834 case WINED3DSIH_M4x3
:
835 case WINED3DSIH_M3x3
:
836 return param
== 1 ? 2 : 0;
838 case WINED3DSIH_M3x2
:
839 return param
== 1 ? 1 : 0;
846 /* Note that this does not count the loop register as an address register. */
847 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
848 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
849 struct wined3d_shader_signature
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
851 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
852 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
853 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
854 void *fe_data
= shader
->frontend_data
;
855 struct wined3d_shader_version shader_version
;
856 const DWORD
*ptr
= byte_code
;
859 memset(reg_maps
, 0, sizeof(*reg_maps
));
860 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
861 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
862 reg_maps
->min_rel_offset
= ~0U;
863 list_init(®_maps
->indexable_temps
);
865 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
866 reg_maps
->shader_version
= shader_version
;
868 shader_set_limits(shader
);
870 if (!(reg_maps
->constf
= wined3d_calloc(((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32),
871 sizeof(*reg_maps
->constf
))))
873 ERR("Failed to allocate constant map memory.\n");
874 return E_OUTOFMEMORY
;
877 while (!fe
->shader_is_end(fe_data
, &ptr
))
879 struct wined3d_shader_instruction ins
;
882 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
884 /* Unhandled opcode, and its parameters. */
885 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
887 TRACE("Skipping unrecognized instruction.\n");
891 /* Handle declarations. */
892 if (ins
.handler_idx
== WINED3DSIH_DCL
)
894 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
895 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
897 switch (semantic
->reg
.reg
.type
)
899 /* Mark input registers used. */
900 case WINED3DSPR_INPUT
:
901 if (reg_idx
>= MAX_REG_INPUT
)
903 ERR("Invalid input register index %u.\n", reg_idx
);
906 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
907 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
908 return WINED3DERR_INVALIDCALL
;
909 reg_maps
->input_registers
|= 1u << reg_idx
;
910 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
913 /* Vertex shader: mark 3.0 output registers used, save token. */
914 case WINED3DSPR_OUTPUT
:
915 if (reg_idx
>= MAX_REG_OUTPUT
)
917 ERR("Invalid output register index %u.\n", reg_idx
);
920 reg_maps
->output_registers
|= 1u << reg_idx
;
921 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
922 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
924 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
925 reg_maps
->point_size
= 1;
928 case WINED3DSPR_SAMPLER
:
929 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
930 case WINED3DSPR_RESOURCE
:
931 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
933 ERR("Invalid resource index %u.\n", reg_idx
);
936 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
937 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
941 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
945 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
947 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
948 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
949 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
951 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
953 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
956 FIXME("Multiple immediate constant buffers.\n");
957 reg_maps
->icb
= ins
.declaration
.icb
;
959 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
961 struct wined3d_shader_indexable_temp
*reg
;
963 if (!(reg
= HeapAlloc(GetProcessHeap(), 0, sizeof(*reg
))))
964 return E_OUTOFMEMORY
;
966 *reg
= ins
.declaration
.indexable_temp
;
967 list_add_tail(®_maps
->indexable_temps
, ®
->entry
);
969 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
971 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
972 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
974 FIXME("Invalid instruction %#x for shader type %#x.\n",
975 ins
.handler_idx
, shader_version
.type
);
977 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
979 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
980 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
982 FIXME("Invalid instruction %#x for shader type %#x.\n",
983 ins
.handler_idx
, shader_version
.type
);
985 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
987 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
988 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
990 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
)
992 reg_maps
->temporary_count
= ins
.declaration
.count
;
994 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
996 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
997 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
999 FIXME("Invalid instruction %#x for shader type %#x.\n",
1000 ins
.handler_idx
, shader_version
.type
);
1002 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1004 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1006 if (!lconst
) return E_OUTOFMEMORY
;
1008 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1009 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
1010 value
= (float *)lconst
->value
;
1012 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
1013 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1015 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
1016 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
1017 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
1018 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
1019 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
1020 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
1021 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
1022 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
1025 list_add_head(&shader
->constantsF
, &lconst
->entry
);
1027 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
1028 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
1030 shader
->lconst_inf_or_nan
= TRUE
;
1033 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1035 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1036 if (!lconst
) return E_OUTOFMEMORY
;
1038 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1039 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
1041 list_add_head(&shader
->constantsI
, &lconst
->entry
);
1042 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
1044 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1046 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
1047 if (!lconst
) return E_OUTOFMEMORY
;
1049 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
1050 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, sizeof(DWORD
));
1052 list_add_head(&shader
->constantsB
, &lconst
->entry
);
1053 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
1055 /* For subroutine prototypes. */
1056 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
1058 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
1060 /* Set texture, address, temporary registers. */
1063 BOOL color0_mov
= FALSE
;
1066 /* This will loop over all the registers and try to
1067 * make a bitmask of the ones we're interested in.
1069 * Relative addressing tokens are ignored, but that's
1070 * okay, since we'll catch any address registers when
1071 * they are initialized (required by spec). */
1072 for (i
= 0; i
< ins
.dst_count
; ++i
)
1074 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
1075 shader_version
.type
, constf_size
))
1076 return WINED3DERR_INVALIDCALL
;
1078 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
1080 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1082 switch (ins
.dst
[i
].reg
.type
)
1084 case WINED3DSPR_RASTOUT
:
1085 if (shader_version
.major
>= 3)
1090 reg_maps
->output_registers
|= 1u << 10;
1091 shader_signature_from_usage(&output_signature_elements
[10],
1092 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
1096 reg_maps
->output_registers
|= 1u << 11;
1097 shader_signature_from_usage(&output_signature_elements
[11],
1098 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
1102 reg_maps
->output_registers
|= 1u << 11;
1103 shader_signature_from_usage(&output_signature_elements
[11],
1104 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
1109 case WINED3DSPR_ATTROUT
:
1110 if (shader_version
.major
>= 3)
1115 if (reg_maps
->output_registers
& (1u << idx
))
1117 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1121 reg_maps
->output_registers
|= 1u << idx
;
1122 shader_signature_from_usage(&output_signature_elements
[idx
],
1123 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1128 case WINED3DSPR_TEXCRDOUT
:
1129 if (shader_version
.major
>= 3)
1131 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1134 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1135 if (reg_maps
->output_registers
& (1u << idx
))
1137 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1141 reg_maps
->output_registers
|= 1u << idx
;
1142 shader_signature_from_usage(&output_signature_elements
[idx
],
1143 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1152 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1154 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1156 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1157 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1158 * the mov and perform the sRGB write correction from the source register.
1160 * However, if the mov is only partial, we can't do this, and if the write
1161 * comes from an instruction other than MOV it is hard to do as well. If
1162 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1163 shader
->u
.ps
.color0_mov
= FALSE
;
1164 if (ins
.handler_idx
== WINED3DSIH_MOV
1165 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1167 /* Used later when the source register is read. */
1171 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1174 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1175 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1177 shader
->u
.ps
.color0_mov
= FALSE
;
1181 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1182 if (shader_version
.major
== 1
1183 && (ins
.handler_idx
== WINED3DSIH_TEX
1184 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1185 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1186 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1187 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1188 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1189 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1190 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1191 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1192 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1193 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1195 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1197 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1198 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1199 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1200 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1202 /* texbem is only valid with < 1.4 pixel shaders */
1203 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1204 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1206 reg_maps
->bumpmat
|= 1u << reg_idx
;
1207 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1209 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1213 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1215 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1219 if (ins
.handler_idx
== WINED3DSIH_NRM
) reg_maps
->usesnrm
= 1;
1220 else if (ins
.handler_idx
== WINED3DSIH_DSY
1221 || ins
.handler_idx
== WINED3DSIH_DSY_COARSE
1222 || ins
.handler_idx
== WINED3DSIH_DSY_FINE
)
1224 reg_maps
->usesdsy
= 1;
1226 else if (ins
.handler_idx
== WINED3DSIH_DSX
1227 || ins
.handler_idx
== WINED3DSIH_DSX_COARSE
1228 || ins
.handler_idx
== WINED3DSIH_DSX_FINE
)
1230 reg_maps
->usesdsx
= 1;
1232 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1233 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1234 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1235 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1236 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1237 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1238 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1239 || ins
.handler_idx
== WINED3DSIH_REP
)
1242 if (cur_loop_depth
> max_loop_depth
)
1243 max_loop_depth
= cur_loop_depth
;
1245 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1246 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1250 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1251 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1252 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1253 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1254 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1256 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1257 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1259 else if (ins
.handler_idx
== WINED3DSIH_LD
1260 || ins
.handler_idx
== WINED3DSIH_RESINFO
)
1262 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1263 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1267 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1268 shader_version
.type
, constf_size
))
1269 return WINED3DERR_INVALIDCALL
;
1271 for (i
= 0; i
< ins
.src_count
; ++i
)
1273 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1274 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1276 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1277 shader_version
.type
, constf_size
))
1278 return WINED3DERR_INVALIDCALL
;
1281 ++reg
.idx
[0].offset
;
1282 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1283 shader_version
.type
, constf_size
))
1284 return WINED3DERR_INVALIDCALL
;
1290 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1291 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1293 shader
->u
.ps
.color0_mov
= TRUE
;
1294 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1300 reg_maps
->loop_depth
= max_loop_depth
;
1302 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1303 * R0 is written to the render target. */
1304 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1305 reg_maps
->rt_mask
|= (1u << 0);
1307 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1309 if (input_signature
->elements
)
1311 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1313 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1314 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1316 if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1318 else if (input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_IS_FRONT_FACE
)
1319 reg_maps
->usesfacing
= 1;
1323 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1325 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1326 struct wined3d_shader_signature_element
*e
;
1329 if (!(input_signature
->elements
= wined3d_calloc(count
, sizeof(*input_signature
->elements
))))
1330 return E_OUTOFMEMORY
;
1331 input_signature
->element_count
= count
;
1333 e
= input_signature
->elements
;
1334 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1336 if (!(reg_maps
->input_registers
& (1u << i
)))
1338 input_signature_elements
[i
].register_idx
= i
;
1339 *e
++ = input_signature_elements
[i
];
1343 if (output_signature
->elements
)
1345 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1347 reg_maps
->output_registers
|= 1u << output_signature
->elements
[i
].register_idx
;
1350 else if (reg_maps
->output_registers
)
1352 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1353 struct wined3d_shader_signature_element
*e
;
1355 if (!(output_signature
->elements
= wined3d_calloc(count
, sizeof(*output_signature
->elements
))))
1356 return E_OUTOFMEMORY
;
1357 output_signature
->element_count
= count
;
1359 e
= output_signature
->elements
;
1360 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1362 if (!(reg_maps
->output_registers
& (1u << i
)))
1364 *e
++ = output_signature_elements
[i
];
1371 static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps
*reg_maps
)
1373 struct wined3d_shader_indexable_temp
*reg
, *reg_next
;
1375 HeapFree(GetProcessHeap(), 0, reg_maps
->constf
);
1376 HeapFree(GetProcessHeap(), 0, reg_maps
->sampler_map
.entries
);
1378 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg_next
, ®_maps
->indexable_temps
, struct wined3d_shader_indexable_temp
, entry
)
1379 HeapFree(GetProcessHeap(), 0, reg
);
1380 list_init(®_maps
->indexable_temps
);
1383 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1385 DWORD map
= 1u << max
;
1387 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1389 return wined3d_log2i(map
);
1392 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1394 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1396 shader_addline(buffer
, "refactoringAllowed");
1397 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1399 shader_addline(buffer
, " | ");
1402 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1404 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1405 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1409 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1412 static void shader_dump_tessellator_domain(struct wined3d_string_buffer
*buffer
,
1413 enum wined3d_tessellator_domain domain
)
1417 case WINED3D_TESSELLATOR_DOMAIN_LINE
:
1418 shader_addline(buffer
, "line");
1420 case WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
:
1421 shader_addline(buffer
, "triangle");
1423 case WINED3D_TESSELLATOR_DOMAIN_QUAD
:
1424 shader_addline(buffer
, "quad");
1427 shader_addline(buffer
, "unknown_tessellator_domain(%#x)", domain
);
1432 static void shader_dump_tessellator_output_primitive(struct wined3d_string_buffer
*buffer
,
1433 enum wined3d_tessellator_output_primitive output_primitive
)
1435 switch (output_primitive
)
1437 case WINED3D_TESSELLATOR_OUTPUT_POINT
:
1438 shader_addline(buffer
, "point");
1440 case WINED3D_TESSELLATOR_OUTPUT_LINE
:
1441 shader_addline(buffer
, "line");
1443 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
:
1444 shader_addline(buffer
, "triangle_cw");
1446 case WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
:
1447 shader_addline(buffer
, "triangle_ccw");
1450 shader_addline(buffer
, "unknown_tessellator_output_primitive(%#x)", output_primitive
);
1455 static void shader_dump_tessellator_partitioning(struct wined3d_string_buffer
*buffer
,
1456 enum wined3d_tessellator_partitioning partitioning
)
1458 switch (partitioning
)
1460 case WINED3D_TESSELLATOR_PARTITIONING_INTEGER
:
1461 shader_addline(buffer
, "integer");
1463 case WINED3D_TESSELLATOR_PARTITIONING_POW2
:
1464 shader_addline(buffer
, "pow2");
1466 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
:
1467 shader_addline(buffer
, "fractional_odd");
1469 case WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
:
1470 shader_addline(buffer
, "fractional_even");
1473 shader_addline(buffer
, "unknown_tessellator_partitioning(%#x)", partitioning
);
1478 static void shader_dump_sysval_semantic(struct wined3d_string_buffer
*buffer
, enum wined3d_sysval_semantic semantic
)
1482 for (i
= 0; i
< ARRAY_SIZE(sysval_semantic_names
); ++i
)
1484 if (sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1486 shader_addline(buffer
, "%s", sysval_semantic_names
[i
].sysval_name
);
1491 shader_addline(buffer
, "unknown_sysval_semantic(%#x)", semantic
);
1494 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1495 const struct wined3d_shader_semantic
*semantic
, const struct wined3d_shader_version
*shader_version
)
1497 shader_addline(buffer
, "dcl");
1499 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1501 switch (semantic
->resource_type
)
1503 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1504 shader_addline(buffer
, "_2d");
1507 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1508 shader_addline(buffer
, "_3d");
1511 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1512 shader_addline(buffer
, "_cube");
1516 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
1520 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
|| semantic
->reg
.reg
.type
== WINED3DSPR_UAV
)
1522 if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1523 shader_addline(buffer
, "_resource_");
1525 shader_addline(buffer
, "_uav_");
1526 switch (semantic
->resource_type
)
1528 case WINED3D_SHADER_RESOURCE_BUFFER
:
1529 shader_addline(buffer
, "buffer");
1532 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1533 shader_addline(buffer
, "texture1d");
1536 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1537 shader_addline(buffer
, "texture2d");
1540 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1541 shader_addline(buffer
, "texture2dms");
1544 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1545 shader_addline(buffer
, "texture3d");
1548 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1549 shader_addline(buffer
, "texturecube");
1552 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1553 shader_addline(buffer
, "texture1darray");
1556 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1557 shader_addline(buffer
, "texture2darray");
1560 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1561 shader_addline(buffer
, "texture2dmsarray");
1565 shader_addline(buffer
, "unknown");
1568 switch (semantic
->resource_data_type
)
1570 case WINED3D_DATA_FLOAT
:
1571 shader_addline(buffer
, " (float)");
1574 case WINED3D_DATA_INT
:
1575 shader_addline(buffer
, " (int)");
1578 case WINED3D_DATA_UINT
:
1579 shader_addline(buffer
, " (uint)");
1582 case WINED3D_DATA_UNORM
:
1583 shader_addline(buffer
, " (unorm)");
1586 case WINED3D_DATA_SNORM
:
1587 shader_addline(buffer
, " (snorm)");
1591 shader_addline(buffer
, " (unknown)");
1597 /* Pixel shaders 3.0 don't have usage semantics. */
1598 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
1601 shader_addline(buffer
, "_");
1603 switch (semantic
->usage
)
1605 case WINED3D_DECL_USAGE_POSITION
:
1606 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
1609 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1610 shader_addline(buffer
, "blend");
1613 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1614 shader_addline(buffer
, "weight");
1617 case WINED3D_DECL_USAGE_NORMAL
:
1618 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
1621 case WINED3D_DECL_USAGE_PSIZE
:
1622 shader_addline(buffer
, "psize");
1625 case WINED3D_DECL_USAGE_COLOR
:
1626 if (!semantic
->usage_idx
)
1627 shader_addline(buffer
, "color");
1629 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
1632 case WINED3D_DECL_USAGE_TEXCOORD
:
1633 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
1636 case WINED3D_DECL_USAGE_TANGENT
:
1637 shader_addline(buffer
, "tangent");
1640 case WINED3D_DECL_USAGE_BINORMAL
:
1641 shader_addline(buffer
, "binormal");
1644 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1645 shader_addline(buffer
, "tessfactor");
1648 case WINED3D_DECL_USAGE_POSITIONT
:
1649 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
1652 case WINED3D_DECL_USAGE_FOG
:
1653 shader_addline(buffer
, "fog");
1656 case WINED3D_DECL_USAGE_DEPTH
:
1657 shader_addline(buffer
, "depth");
1660 case WINED3D_DECL_USAGE_SAMPLE
:
1661 shader_addline(buffer
, "sample");
1665 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
1666 FIXME("Unrecognised semantic usage %#x.\n", semantic
->usage
);
1671 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
1672 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
1674 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1675 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1676 UINT offset
= reg
->idx
[0].offset
;
1680 case WINED3DSPR_TEMP
:
1681 shader_addline(buffer
, "r");
1684 case WINED3DSPR_INPUT
:
1685 shader_addline(buffer
, "v");
1688 case WINED3DSPR_CONST
:
1689 case WINED3DSPR_CONST2
:
1690 case WINED3DSPR_CONST3
:
1691 case WINED3DSPR_CONST4
:
1692 shader_addline(buffer
, "c");
1693 offset
= shader_get_float_offset(reg
->type
, offset
);
1696 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1697 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1700 case WINED3DSPR_RASTOUT
:
1701 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
1704 case WINED3DSPR_COLOROUT
:
1705 shader_addline(buffer
, "oC");
1708 case WINED3DSPR_DEPTHOUT
:
1709 shader_addline(buffer
, "oDepth");
1712 case WINED3DSPR_ATTROUT
:
1713 shader_addline(buffer
, "oD");
1716 case WINED3DSPR_TEXCRDOUT
:
1717 /* Vertex shaders >= 3.0 use general purpose output registers
1718 * (WINED3DSPR_OUTPUT), which can include an address token. */
1719 if (shader_version
->major
>= 3)
1720 shader_addline(buffer
, "o");
1722 shader_addline(buffer
, "oT");
1725 case WINED3DSPR_CONSTINT
:
1726 shader_addline(buffer
, "i");
1729 case WINED3DSPR_CONSTBOOL
:
1730 shader_addline(buffer
, "b");
1733 case WINED3DSPR_LABEL
:
1734 shader_addline(buffer
, "l");
1737 case WINED3DSPR_LOOP
:
1738 shader_addline(buffer
, "aL");
1741 case WINED3DSPR_SAMPLER
:
1742 shader_addline(buffer
, "s");
1745 case WINED3DSPR_MISCTYPE
:
1748 FIXME("Unhandled misctype register %u.\n", offset
);
1749 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
1753 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
1757 case WINED3DSPR_PREDICATE
:
1758 shader_addline(buffer
, "p");
1761 case WINED3DSPR_IMMCONST
:
1762 shader_addline(buffer
, "l");
1765 case WINED3DSPR_CONSTBUFFER
:
1766 shader_addline(buffer
, "cb");
1769 case WINED3DSPR_IMMCONSTBUFFER
:
1770 shader_addline(buffer
, "icb");
1773 case WINED3DSPR_PRIMID
:
1774 shader_addline(buffer
, "primID");
1777 case WINED3DSPR_NULL
:
1778 shader_addline(buffer
, "null");
1781 case WINED3DSPR_RESOURCE
:
1782 shader_addline(buffer
, "t");
1785 case WINED3DSPR_UAV
:
1786 shader_addline(buffer
, "u");
1789 case WINED3DSPR_OUTPOINTID
:
1790 shader_addline(buffer
, "vOutputControlPointID");
1793 case WINED3DSPR_FORKINSTID
:
1794 shader_addline(buffer
, "vForkInstanceId");
1797 case WINED3DSPR_INCONTROLPOINT
:
1798 shader_addline(buffer
, "vicp");
1801 case WINED3DSPR_OUTCONTROLPOINT
:
1802 shader_addline(buffer
, "vocp");
1805 case WINED3DSPR_PATCHCONST
:
1806 shader_addline(buffer
, "vpc");
1809 case WINED3DSPR_TESSCOORD
:
1810 shader_addline(buffer
, "vDomainLocation");
1813 case WINED3DSPR_GROUPSHAREDMEM
:
1814 shader_addline(buffer
, "g");
1817 case WINED3DSPR_THREADID
:
1818 shader_addline(buffer
, "vThreadID");
1821 case WINED3DSPR_THREADGROUPID
:
1822 shader_addline(buffer
, "vThreadGroupID");
1825 case WINED3DSPR_LOCALTHREADID
:
1826 shader_addline(buffer
, "vThreadIDInGroup");
1829 case WINED3DSPR_LOCALTHREADINDEX
:
1830 shader_addline(buffer
, "vThreadIDInGroupFlattened");
1833 case WINED3DSPR_IDXTEMP
:
1834 shader_addline(buffer
, "x");
1837 case WINED3DSPR_STREAM
:
1838 shader_addline(buffer
, "m");
1842 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
1846 if (reg
->type
== WINED3DSPR_IMMCONST
)
1848 shader_addline(buffer
, "(");
1849 switch (reg
->immconst_type
)
1851 case WINED3D_IMMCONST_SCALAR
:
1852 switch (reg
->data_type
)
1854 case WINED3D_DATA_FLOAT
:
1855 shader_addline(buffer
, "%.8e", *(const float *)reg
->immconst_data
);
1857 case WINED3D_DATA_INT
:
1858 shader_addline(buffer
, "%d", reg
->immconst_data
[0]);
1860 case WINED3D_DATA_RESOURCE
:
1861 case WINED3D_DATA_SAMPLER
:
1862 case WINED3D_DATA_UINT
:
1863 shader_addline(buffer
, "%u", reg
->immconst_data
[0]);
1866 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1871 case WINED3D_IMMCONST_VEC4
:
1872 switch (reg
->data_type
)
1874 case WINED3D_DATA_FLOAT
:
1875 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
1876 *(const float *)®
->immconst_data
[0], *(const float *)®
->immconst_data
[1],
1877 *(const float *)®
->immconst_data
[2], *(const float *)®
->immconst_data
[3]);
1879 case WINED3D_DATA_INT
:
1880 shader_addline(buffer
, "%d, %d, %d, %d",
1881 reg
->immconst_data
[0], reg
->immconst_data
[1],
1882 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1884 case WINED3D_DATA_RESOURCE
:
1885 case WINED3D_DATA_SAMPLER
:
1886 case WINED3D_DATA_UINT
:
1887 shader_addline(buffer
, "%u, %u, %u, %u",
1888 reg
->immconst_data
[0], reg
->immconst_data
[1],
1889 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1892 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1898 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
1901 shader_addline(buffer
, ")");
1903 else if (reg
->type
!= WINED3DSPR_RASTOUT
1904 && reg
->type
!= WINED3DSPR_MISCTYPE
1905 && reg
->type
!= WINED3DSPR_NULL
)
1909 shader_addline(buffer
, "[");
1910 if (reg
->idx
[0].rel_addr
)
1912 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
1913 shader_addline(buffer
, " + ");
1915 shader_addline(buffer
, "%u]", offset
);
1917 if (reg
->idx
[1].offset
!= ~0u)
1919 shader_addline(buffer
, "[");
1920 if (reg
->idx
[1].rel_addr
)
1922 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
1923 shader_addline(buffer
, " + ");
1925 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
1931 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
1932 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
1934 DWORD write_mask
= param
->write_mask
;
1936 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
1938 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
1940 static const char write_mask_chars
[] = "xyzw";
1942 shader_addline(buffer
, ".");
1943 if (write_mask
& WINED3DSP_WRITEMASK_0
)
1944 shader_addline(buffer
, "%c", write_mask_chars
[0]);
1945 if (write_mask
& WINED3DSP_WRITEMASK_1
)
1946 shader_addline(buffer
, "%c", write_mask_chars
[1]);
1947 if (write_mask
& WINED3DSP_WRITEMASK_2
)
1948 shader_addline(buffer
, "%c", write_mask_chars
[2]);
1949 if (write_mask
& WINED3DSP_WRITEMASK_3
)
1950 shader_addline(buffer
, "%c", write_mask_chars
[3]);
1954 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
1955 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
1957 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
1958 DWORD swizzle
= param
->swizzle
;
1960 if (src_modifier
== WINED3DSPSM_NEG
1961 || src_modifier
== WINED3DSPSM_BIASNEG
1962 || src_modifier
== WINED3DSPSM_SIGNNEG
1963 || src_modifier
== WINED3DSPSM_X2NEG
1964 || src_modifier
== WINED3DSPSM_ABSNEG
)
1965 shader_addline(buffer
, "-");
1966 else if (src_modifier
== WINED3DSPSM_COMP
)
1967 shader_addline(buffer
, "1-");
1968 else if (src_modifier
== WINED3DSPSM_NOT
)
1969 shader_addline(buffer
, "!");
1971 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
1972 shader_addline(buffer
, "abs(");
1974 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
1976 switch (src_modifier
)
1978 case WINED3DSPSM_NONE
: break;
1979 case WINED3DSPSM_NEG
: break;
1980 case WINED3DSPSM_NOT
: break;
1981 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
1982 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
1983 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
1984 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
1985 case WINED3DSPSM_COMP
: break;
1986 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
1987 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
1988 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
1989 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
1990 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
1991 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
1992 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
1995 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
1997 static const char swizzle_chars
[] = "xyzw";
1998 DWORD swizzle_x
= swizzle
& 0x03;
1999 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
2000 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
2001 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
2003 if (swizzle_x
== swizzle_y
2004 && swizzle_x
== swizzle_z
2005 && swizzle_x
== swizzle_w
)
2007 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
2011 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
2012 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
2017 /* Shared code in order to generate the bulk of the shader string.
2018 * NOTE: A description of how to parse tokens can be found on MSDN. */
2019 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
2020 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
2022 struct wined3d_device
*device
= shader
->device
;
2023 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
2024 void *fe_data
= shader
->frontend_data
;
2025 struct wined3d_shader_version shader_version
;
2026 struct wined3d_shader_loop_state loop_state
;
2027 struct wined3d_shader_instruction ins
;
2028 struct wined3d_shader_tex_mx tex_mx
;
2029 struct wined3d_shader_context ctx
;
2030 const DWORD
*ptr
= byte_code
;
2032 /* Initialize current parsing state. */
2033 tex_mx
.current_row
= 0;
2034 loop_state
.current_depth
= 0;
2035 loop_state
.current_reg
= 0;
2037 ctx
.shader
= shader
;
2038 ctx
.gl_info
= &device
->adapter
->gl_info
;
2039 ctx
.reg_maps
= reg_maps
;
2040 ctx
.buffer
= buffer
;
2041 ctx
.tex_mx
= &tex_mx
;
2042 ctx
.loop_state
= &loop_state
;
2043 ctx
.backend_data
= backend_ctx
;
2046 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2048 while (!fe
->shader_is_end(fe_data
, &ptr
))
2051 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2053 /* Unknown opcode and its parameters. */
2054 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2056 TRACE("Skipping unrecognized instruction.\n");
2061 FIXME("Predicates not implemented.\n");
2063 /* Call appropriate function for output target */
2064 device
->shader_backend
->shader_handle_instruction(&ins
);
2068 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
2069 const struct wined3d_shader_dst_param
*dst
)
2071 DWORD mmask
= dst
->modifiers
;
2076 case 13: shader_addline(buffer
, "_d8"); break;
2077 case 14: shader_addline(buffer
, "_d4"); break;
2078 case 15: shader_addline(buffer
, "_d2"); break;
2079 case 1: shader_addline(buffer
, "_x2"); break;
2080 case 2: shader_addline(buffer
, "_x4"); break;
2081 case 3: shader_addline(buffer
, "_x8"); break;
2082 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
2085 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
2086 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
2087 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
2089 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
2090 if (mmask
) FIXME("Unrecognised modifier %#x.\n", mmask
);
2093 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
2094 enum wined3d_primitive_type primitive_type
)
2096 switch (primitive_type
)
2098 case WINED3D_PT_UNDEFINED
:
2099 shader_addline(buffer
, "undefined");
2101 case WINED3D_PT_POINTLIST
:
2102 shader_addline(buffer
, "pointlist");
2104 case WINED3D_PT_LINELIST
:
2105 shader_addline(buffer
, "linelist");
2107 case WINED3D_PT_LINESTRIP
:
2108 shader_addline(buffer
, "linestrip");
2110 case WINED3D_PT_TRIANGLELIST
:
2111 shader_addline(buffer
, "trianglelist");
2113 case WINED3D_PT_TRIANGLESTRIP
:
2114 shader_addline(buffer
, "trianglestrip");
2116 case WINED3D_PT_TRIANGLEFAN
:
2117 shader_addline(buffer
, "trianglefan");
2119 case WINED3D_PT_LINELIST_ADJ
:
2120 shader_addline(buffer
, "linelist_adj");
2122 case WINED3D_PT_LINESTRIP_ADJ
:
2123 shader_addline(buffer
, "linestrip_adj");
2125 case WINED3D_PT_TRIANGLELIST_ADJ
:
2126 shader_addline(buffer
, "trianglelist_adj");
2128 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
2129 shader_addline(buffer
, "trianglestrip_adj");
2132 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
);
2137 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
2138 enum wined3d_shader_interpolation_mode interpolation_mode
)
2140 switch (interpolation_mode
)
2142 case WINED3DSIM_CONSTANT
:
2143 shader_addline(buffer
, "constant");
2145 case WINED3DSIM_LINEAR
:
2146 shader_addline(buffer
, "linear");
2148 case WINED3DSIM_LINEAR_CENTROID
:
2149 shader_addline(buffer
, "linear centroid");
2151 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
2152 shader_addline(buffer
, "linear noperspective");
2154 case WINED3DSIM_LINEAR_SAMPLE
:
2155 shader_addline(buffer
, "linear sample");
2157 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
2158 shader_addline(buffer
, "linear noperspective centroid");
2160 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
2161 shader_addline(buffer
, "linear noperspective sample");
2164 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
2169 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
2171 struct wined3d_shader_version shader_version
;
2172 struct wined3d_string_buffer buffer
;
2173 const DWORD
*ptr
= byte_code
;
2174 const char *type_prefix
;
2178 if (!string_buffer_init(&buffer
))
2180 ERR("Failed to initialize string buffer.\n");
2184 TRACE("Parsing %p.\n", byte_code
);
2186 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
2188 switch (shader_version
.type
)
2190 case WINED3D_SHADER_TYPE_VERTEX
:
2194 case WINED3D_SHADER_TYPE_HULL
:
2198 case WINED3D_SHADER_TYPE_DOMAIN
:
2202 case WINED3D_SHADER_TYPE_GEOMETRY
:
2206 case WINED3D_SHADER_TYPE_PIXEL
:
2210 case WINED3D_SHADER_TYPE_COMPUTE
:
2215 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
2216 type_prefix
= "unknown";
2220 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
2222 while (!fe
->shader_is_end(fe_data
, &ptr
))
2224 struct wined3d_shader_instruction ins
;
2226 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
2227 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
2229 WARN("Skipping unrecognized instruction.\n");
2230 shader_addline(&buffer
, "<unrecognized instruction>\n");
2234 if (ins
.handler_idx
== WINED3DSIH_DCL
|| ins
.handler_idx
== WINED3DSIH_DCL_UAV_TYPED
)
2236 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, &shader_version
);
2237 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
2238 shader_addline(&buffer
, " ");
2239 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
2241 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
2243 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2244 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
2245 shader_addline(&buffer
, ", %s",
2246 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
2248 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
2250 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2251 shader_dump_global_flags(&buffer
, ins
.flags
);
2253 else if (ins
.handler_idx
== WINED3DSIH_DCL_HS_MAX_TESSFACTOR
)
2255 shader_addline(&buffer
, "%s %.8e", shader_opcode_names
[ins
.handler_idx
],
2256 ins
.declaration
.max_tessellation_factor
);
2258 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
2260 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
2261 for (i
= 0; i
< ins
.declaration
.icb
->vec4_count
; ++i
)
2263 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
2264 ins
.declaration
.icb
->data
[4 * i
+ 0],
2265 ins
.declaration
.icb
->data
[4 * i
+ 1],
2266 ins
.declaration
.icb
->data
[4 * i
+ 2],
2267 ins
.declaration
.icb
->data
[4 * i
+ 3]);
2269 shader_addline(&buffer
, "}");
2271 else if (ins
.handler_idx
== WINED3DSIH_DCL_INDEXABLE_TEMP
)
2273 shader_addline(&buffer
, "%s x[%u][%u], %u", shader_opcode_names
[ins
.handler_idx
],
2274 ins
.declaration
.indexable_temp
.register_idx
,
2275 ins
.declaration
.indexable_temp
.register_size
,
2276 ins
.declaration
.indexable_temp
.component_count
);
2278 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
2280 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2281 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2282 shader_addline(&buffer
, " ");
2283 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2285 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
2286 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
2287 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
2288 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
2290 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2291 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2292 shader_addline(&buffer
, ", ");
2293 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2295 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2297 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2298 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2299 shader_addline(&buffer
, " ");
2300 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2301 shader_addline(&buffer
, ", ");
2302 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2304 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2305 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2307 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2308 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2310 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2311 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2313 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2314 shader_dump_primitive_type(&buffer
, ins
.declaration
.primitive_type
);
2316 else if (ins
.handler_idx
== WINED3DSIH_DCL_RESOURCE_STRUCTURED
)
2318 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2319 shader_dump_dst_param(&buffer
, &ins
.declaration
.structured_resource
.reg
, &shader_version
);
2320 shader_addline(&buffer
, ", %u", ins
.declaration
.structured_resource
.byte_stride
);
2322 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2324 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2325 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2326 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2327 shader_addline(&buffer
, ", comparisonMode");
2329 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2330 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
2331 || ins
.handler_idx
== WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
2332 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
2333 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
)
2335 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2337 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_DOMAIN
)
2339 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2340 shader_dump_tessellator_domain(&buffer
, ins
.declaration
.tessellator_domain
);
2342 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
)
2344 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2345 shader_dump_tessellator_output_primitive(&buffer
, ins
.declaration
.tessellator_output_primitive
);
2347 else if (ins
.handler_idx
== WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
)
2349 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2350 shader_dump_tessellator_partitioning(&buffer
, ins
.declaration
.tessellator_partitioning
);
2352 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_RAW
)
2354 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2355 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_raw
.reg
, &shader_version
);
2356 shader_addline(&buffer
, ", %u", ins
.declaration
.tgsm_raw
.byte_count
);
2358 else if (ins
.handler_idx
== WINED3DSIH_DCL_TGSM_STRUCTURED
)
2360 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2361 shader_dump_dst_param(&buffer
, &ins
.declaration
.tgsm_structured
.reg
, &shader_version
);
2362 shader_addline(&buffer
, ", %u, %u", ins
.declaration
.tgsm_structured
.byte_stride
,
2363 ins
.declaration
.tgsm_structured
.structure_count
);
2365 else if (ins
.handler_idx
== WINED3DSIH_DCL_THREAD_GROUP
)
2367 shader_addline(&buffer
, "%s %u, %u, %u", shader_opcode_names
[ins
.handler_idx
],
2368 ins
.declaration
.thread_group_size
.x
,
2369 ins
.declaration
.thread_group_size
.y
,
2370 ins
.declaration
.thread_group_size
.z
);
2372 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2374 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2375 ins
.dst
[0].reg
.idx
[0].offset
),
2376 *(const float *)&ins
.src
[0].reg
.immconst_data
[0],
2377 *(const float *)&ins
.src
[0].reg
.immconst_data
[1],
2378 *(const float *)&ins
.src
[0].reg
.immconst_data
[2],
2379 *(const float *)&ins
.src
[0].reg
.immconst_data
[3]);
2381 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2383 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2384 ins
.src
[0].reg
.immconst_data
[0],
2385 ins
.src
[0].reg
.immconst_data
[1],
2386 ins
.src
[0].reg
.immconst_data
[2],
2387 ins
.src
[0].reg
.immconst_data
[3]);
2389 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2391 shader_addline(&buffer
, "defb b%u = %s",
2392 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.immconst_data
[0] ? "true" : "false");
2398 shader_addline(&buffer
, "(");
2399 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2400 shader_addline(&buffer
, ") ");
2403 /* PixWin marks instructions with the coissue flag with a '+' */
2405 shader_addline(&buffer
, "+");
2407 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2409 if (ins
.handler_idx
== WINED3DSIH_BREAKP
2410 || ins
.handler_idx
== WINED3DSIH_IF
)
2414 case WINED3D_SHADER_CONDITIONAL_OP_NZ
: shader_addline(&buffer
, "_nz"); break;
2415 case WINED3D_SHADER_CONDITIONAL_OP_Z
: shader_addline(&buffer
, "_z"); break;
2416 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
); break;
2419 else if (ins
.handler_idx
== WINED3DSIH_IFC
2420 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
2424 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
2425 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
2426 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
2427 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
2428 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
2429 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
2430 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
2433 else if (ins
.handler_idx
== WINED3DSIH_TEX
2434 && shader_version
.major
>= 2
2435 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
2437 shader_addline(&buffer
, "p");
2439 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
&& ins
.flags
)
2443 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
2444 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2445 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2448 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE_INFO
&& ins
.flags
)
2452 case WINED3DSI_SAMPLE_INFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2453 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2457 if (wined3d_shader_instruction_has_texel_offset(&ins
))
2458 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
2460 for (i
= 0; i
< ins
.dst_count
; ++i
)
2462 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
2463 shader_addline(&buffer
, !i
? " " : ", ");
2464 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
2467 /* Other source tokens */
2468 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
2470 shader_addline(&buffer
, !i
? " " : ", ");
2471 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
2474 shader_addline(&buffer
, "\n");
2477 for (p
= buffer
.buffer
; *p
; p
= q
)
2479 if (!(q
= strstr(p
, "\n")))
2483 TRACE(" %.*s", (int)(q
- p
), p
);
2486 string_buffer_free(&buffer
);
2489 static void shader_cleanup(struct wined3d_shader
*shader
)
2491 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
2492 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2493 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2494 shader
->device
->shader_backend
->shader_destroy(shader
);
2495 shader_cleanup_reg_maps(&shader
->reg_maps
);
2496 HeapFree(GetProcessHeap(), 0, shader
->function
);
2497 shader_delete_constant_list(&shader
->constantsF
);
2498 shader_delete_constant_list(&shader
->constantsB
);
2499 shader_delete_constant_list(&shader
->constantsI
);
2500 list_remove(&shader
->shader_list_entry
);
2502 if (shader
->frontend
&& shader
->frontend_data
)
2503 shader
->frontend
->shader_free(shader
->frontend_data
);
2506 struct shader_none_priv
2508 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
2509 const struct fragment_pipeline
*fragment_pipe
;
2510 BOOL ffp_proj_control
;
2513 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
2514 static void shader_none_select_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
,
2515 enum wined3d_gl_resource_type tex_type
, const SIZE
*ds_mask_size
) {}
2516 static void shader_none_deselect_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
) {}
2517 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2518 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2519 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
2520 const struct wined3d_state
*state
) {}
2521 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
2522 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
2523 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
2525 /* Context activation is done by the caller. */
2526 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
2527 const struct wined3d_state
*state
)
2529 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2530 struct shader_none_priv
*priv
= shader_priv
;
2532 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
2533 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
2536 /* Context activation is done by the caller. */
2537 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
2539 struct shader_none_priv
*priv
= shader_priv
;
2540 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2542 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
2543 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
2545 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
2546 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
2547 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
)
2548 | (1u << WINED3D_SHADER_TYPE_HULL
)
2549 | (1u << WINED3D_SHADER_TYPE_DOMAIN
)
2550 | (1u << WINED3D_SHADER_TYPE_COMPUTE
);
2553 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
2554 const struct fragment_pipeline
*fragment_pipe
)
2556 struct fragment_caps fragment_caps
;
2557 void *vertex_priv
, *fragment_priv
;
2558 struct shader_none_priv
*priv
;
2560 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
2561 return E_OUTOFMEMORY
;
2563 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
2565 ERR("Failed to initialize vertex pipe.\n");
2566 HeapFree(GetProcessHeap(), 0, priv
);
2570 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
2572 ERR("Failed to initialize fragment pipe.\n");
2573 vertex_pipe
->vp_free(device
);
2574 HeapFree(GetProcessHeap(), 0, priv
);
2578 priv
->vertex_pipe
= vertex_pipe
;
2579 priv
->fragment_pipe
= fragment_pipe
;
2580 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
2581 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
2583 device
->vertex_priv
= vertex_priv
;
2584 device
->fragment_priv
= fragment_priv
;
2585 device
->shader_priv
= priv
;
2590 static void shader_none_free(struct wined3d_device
*device
)
2592 struct shader_none_priv
*priv
= device
->shader_priv
;
2594 priv
->fragment_pipe
->free_private(device
);
2595 priv
->vertex_pipe
->vp_free(device
);
2596 HeapFree(GetProcessHeap(), 0, priv
);
2599 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
2604 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
2606 /* Set the shader caps to 0 for the none shader backend */
2607 caps
->vs_version
= 0;
2608 caps
->hs_version
= 0;
2609 caps
->ds_version
= 0;
2610 caps
->gs_version
= 0;
2611 caps
->ps_version
= 0;
2612 caps
->cs_version
= 0;
2613 caps
->vs_uniform_count
= 0;
2614 caps
->ps_uniform_count
= 0;
2615 caps
->ps_1x_max_value
= 0.0f
;
2616 caps
->varying_count
= 0;
2617 caps
->wined3d_caps
= 0;
2620 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2622 /* We "support" every possible fixup, since we don't support any shader
2623 * model, and will never have to actually sample a texture. */
2627 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2629 struct shader_none_priv
*priv
= shader_priv
;
2631 return priv
->ffp_proj_control
;
2634 const struct wined3d_shader_backend_ops none_shader_backend
=
2636 shader_none_handle_instruction
,
2638 shader_none_disable
,
2639 shader_none_select_depth_blt
,
2640 shader_none_deselect_depth_blt
,
2641 shader_none_update_float_vertex_constants
,
2642 shader_none_update_float_pixel_constants
,
2643 shader_none_load_constants
,
2644 shader_none_destroy
,
2647 shader_none_allocate_context_data
,
2648 shader_none_free_context_data
,
2649 shader_none_init_context_state
,
2650 shader_none_get_caps
,
2651 shader_none_color_fixup_supported
,
2652 shader_none_has_ffp_proj_control
,
2655 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
2656 DWORD float_const_count
, enum wined3d_shader_type type
, unsigned int max_version
)
2658 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2659 const struct wined3d_shader_frontend
*fe
;
2661 unsigned int backend_version
;
2662 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2664 TRACE("shader %p, byte_code %p, float_const_count %u, type %#x, max_version %u.\n",
2665 shader
, byte_code
, float_const_count
, type
, max_version
);
2667 list_init(&shader
->constantsF
);
2668 list_init(&shader
->constantsB
);
2669 list_init(&shader
->constantsI
);
2670 shader
->lconst_inf_or_nan
= FALSE
;
2671 list_init(®_maps
->indexable_temps
);
2673 fe
= shader_select_frontend(*byte_code
);
2676 FIXME("Unable to find frontend for shader.\n");
2677 return WINED3DERR_INVALIDCALL
;
2679 shader
->frontend
= fe
;
2680 shader
->frontend_data
= fe
->shader_init(byte_code
, &shader
->output_signature
);
2681 if (!shader
->frontend_data
)
2683 FIXME("Failed to initialize frontend.\n");
2684 return WINED3DERR_INVALIDCALL
;
2687 /* First pass: trace shader. */
2688 if (TRACE_ON(d3d_shader
))
2689 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
2691 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2692 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2693 &shader
->output_signature
, byte_code
, float_const_count
)))
2696 if (reg_maps
->shader_version
.type
!= type
)
2698 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2699 return WINED3DERR_INVALIDCALL
;
2701 if (reg_maps
->shader_version
.major
> max_version
)
2703 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2704 return WINED3DERR_INVALIDCALL
;
2708 case WINED3D_SHADER_TYPE_VERTEX
:
2709 backend_version
= d3d_info
->limits
.vs_version
;
2711 case WINED3D_SHADER_TYPE_HULL
:
2712 backend_version
= d3d_info
->limits
.hs_version
;
2714 case WINED3D_SHADER_TYPE_DOMAIN
:
2715 backend_version
= d3d_info
->limits
.ds_version
;
2717 case WINED3D_SHADER_TYPE_GEOMETRY
:
2718 backend_version
= d3d_info
->limits
.gs_version
;
2720 case WINED3D_SHADER_TYPE_PIXEL
:
2721 backend_version
= d3d_info
->limits
.ps_version
;
2723 case WINED3D_SHADER_TYPE_COMPUTE
:
2724 backend_version
= d3d_info
->limits
.cs_version
;
2727 FIXME("No backend version-checking for this shader type.\n");
2728 backend_version
= 0;
2730 if (reg_maps
->shader_version
.major
> backend_version
)
2732 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2733 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2734 return WINED3DERR_INVALIDCALL
;
2737 if (!(shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
)))
2738 return E_OUTOFMEMORY
;
2739 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2744 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2746 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2748 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2753 static void wined3d_shader_destroy_object(void *object
)
2755 shader_cleanup(object
);
2756 HeapFree(GetProcessHeap(), 0, object
);
2759 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2761 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2763 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2767 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2768 wined3d_cs_emit_destroy_object(shader
->device
->cs
, wined3d_shader_destroy_object
, shader
);
2774 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2776 TRACE("shader %p.\n", shader
);
2778 return shader
->parent
;
2781 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2782 void *byte_code
, UINT
*byte_code_size
)
2784 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2788 *byte_code_size
= shader
->functionLength
;
2792 if (*byte_code_size
< shader
->functionLength
)
2794 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2795 * than the required size we should write the required size and
2796 * return D3DERR_MOREDATA. That's not actually true. */
2797 return WINED3DERR_INVALIDCALL
;
2800 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2805 /* Set local constants for d3d8 shaders. */
2806 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2807 UINT start_idx
, const float *src_data
, UINT count
)
2809 UINT end_idx
= start_idx
+ count
;
2812 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2814 if (end_idx
> shader
->limits
->constant_float
)
2816 WARN("end_idx %u > float constants limit %u.\n",
2817 end_idx
, shader
->limits
->constant_float
);
2818 end_idx
= shader
->limits
->constant_float
;
2821 for (i
= start_idx
; i
< end_idx
; ++i
)
2823 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2826 return E_OUTOFMEMORY
;
2829 value
= (float *)lconst
->value
;
2830 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
2831 list_add_head(&shader
->constantsF
, &lconst
->entry
);
2833 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
2834 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
2836 shader
->lconst_inf_or_nan
= TRUE
;
2843 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2844 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_d3d_info
*d3d_info
)
2846 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
2847 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
2848 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
2849 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
2850 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
2851 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
2852 args
->next_shader_type
= state
->shader
[WINED3D_SHADER_TYPE_HULL
] ? WINED3D_SHADER_TYPE_HULL
2853 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
] ? WINED3D_SHADER_TYPE_GEOMETRY
2854 : WINED3D_SHADER_TYPE_PIXEL
;
2855 if (shader
->reg_maps
.shader_version
.major
>= 4)
2856 args
->next_shader_input_count
= state
->shader
[WINED3D_SHADER_TYPE_HULL
]
2857 ? state
->shader
[WINED3D_SHADER_TYPE_HULL
]->limits
->packed_input
2858 : state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]
2859 ? state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]->limits
->packed_input
2860 : state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
2861 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
2863 args
->next_shader_input_count
= 0;
2864 args
->swizzle_map
= swizzle_map
;
2865 if (d3d_info
->emulated_flatshading
)
2866 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
2868 args
->flatshading
= 0;
2871 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
2873 if (usage_idx1
!= usage_idx2
)
2875 if (usage1
== usage2
)
2877 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
2879 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
2885 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
2886 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
2888 WORD map
= shader
->reg_maps
.input_registers
;
2891 for (i
= 0; map
; map
>>= 1, ++i
)
2893 if (!(map
& 1)) continue;
2895 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
2896 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
2905 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
2906 const struct wined3d_shader_signature
*src
, char **signature_strings
)
2908 struct wined3d_shader_signature_element
*e
;
2913 if (!src
->element_count
)
2916 ptr
= *signature_strings
;
2918 dst
->element_count
= src
->element_count
;
2919 if (!(dst
->elements
= wined3d_calloc(dst
->element_count
, sizeof(*dst
->elements
))))
2920 return E_OUTOFMEMORY
;
2922 for (i
= 0; i
< src
->element_count
; ++i
)
2924 e
= &src
->elements
[i
];
2925 dst
->elements
[i
] = *e
;
2927 len
= strlen(e
->semantic_name
);
2928 memcpy(ptr
, e
->semantic_name
, len
+ 1);
2929 dst
->elements
[i
].semantic_name
= ptr
;
2933 *signature_strings
= ptr
;
2938 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2939 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
2940 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2942 struct wined3d_shader_signature_element
*e
;
2948 if (!desc
->byte_code
)
2949 return WINED3DERR_INVALIDCALL
;
2952 shader
->device
= device
;
2953 shader
->parent
= parent
;
2954 shader
->parent_ops
= parent_ops
;
2957 for (i
= 0; i
< desc
->input_signature
.element_count
; ++i
)
2959 e
= &desc
->input_signature
.elements
[i
];
2960 len
= strlen(e
->semantic_name
);
2961 if (len
>= ~(SIZE_T
)0 - total
)
2962 return E_OUTOFMEMORY
;
2966 for (i
= 0; i
< desc
->output_signature
.element_count
; ++i
)
2968 e
= &desc
->output_signature
.elements
[i
];
2969 len
= strlen(e
->semantic_name
);
2970 if (len
>= ~(SIZE_T
)0 - total
)
2971 return E_OUTOFMEMORY
;
2975 if (total
&& !(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
2976 return E_OUTOFMEMORY
;
2977 ptr
= shader
->signature_strings
;
2979 if (FAILED(hr
= shader_signature_copy(&shader
->input_signature
, &desc
->input_signature
, &ptr
)))
2981 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2984 if (FAILED(hr
= shader_signature_copy(&shader
->output_signature
, &desc
->output_signature
, &ptr
)))
2986 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2987 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2991 list_init(&shader
->linked_programs
);
2992 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
2994 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
,
2995 float_const_count
, type
, desc
->max_version
)))
2997 WARN("Failed to set function, hr %#x.\n", hr
);
2998 shader_cleanup(shader
);
3001 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
3006 static HRESULT
vertex_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3007 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3009 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3013 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
3014 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
3017 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
3019 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
3021 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
3024 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
3025 shader_usage_from_semantic_name(input
->semantic_name
);
3026 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
3029 if (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
))
3030 shader
->load_local_constsF
= TRUE
;
3035 static HRESULT
domain_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3036 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3038 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_DOMAIN
, parent
, parent_ops
);
3041 static HRESULT
hull_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3042 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3044 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_HULL
, parent
, parent_ops
);
3047 static HRESULT
geometry_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3048 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3050 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
);
3053 void find_gs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3054 struct gs_compile_args
*args
)
3056 args
->ps_input_count
= state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]
3057 ? state
->shader
[WINED3D_SHADER_TYPE_PIXEL
]->limits
->packed_input
: 0;
3060 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
3061 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
3063 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3064 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
3065 const struct wined3d_texture
*texture
;
3068 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
3069 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
3071 static unsigned int warned
= 0;
3073 args
->srgb_correction
= 1;
3074 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
3075 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
3076 "support, expect rendering artifacts.\n");
3079 if (shader
->reg_maps
.shader_version
.major
== 1
3080 && shader
->reg_maps
.shader_version
.minor
<= 3)
3082 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3084 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
3086 if (flags
& WINED3D_TTFF_PROJECTED
)
3088 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
3090 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
3092 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
3094 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3095 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
3097 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
3099 struct wined3d_vertex_declaration_element
*element
=
3100 &state
->vertex_declaration
->elements
[j
];
3102 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
3103 && element
->usage_idx
== index
)
3105 max_valid
= element
->format
->component_count
;
3109 if (!tex_transform
|| tex_transform
> max_valid
)
3111 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
3112 tex_transform
, max_valid
);
3113 tex_transform
= max_valid
;
3115 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
3116 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
3117 && tex_transform
> WINED3D_TTFF_COUNT2
)
3118 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
3119 && tex_transform
> WINED3D_TTFF_COUNT3
))
3120 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
3123 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
3124 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
3125 i
, tex_transform
, resource_type
);
3129 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
3131 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
3135 if (shader
->reg_maps
.shader_version
.major
== 1
3136 && shader
->reg_maps
.shader_version
.minor
<= 4)
3138 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3140 const struct wined3d_texture
*texture
= state
->textures
[i
];
3142 if (!shader
->reg_maps
.resource_info
[i
].type
)
3145 /* Treat unbound textures as 2D. The dummy texture will provide
3146 * the proper sample value. The tex_types bitmap defaults to
3147 * 2D because of the memset. */
3151 switch (texture
->target
)
3153 /* RECT textures are distinguished from 2D textures via np2_fixup */
3154 case GL_TEXTURE_RECTANGLE_ARB
:
3159 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3162 case GL_TEXTURE_CUBE_MAP_ARB
:
3163 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
3169 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
3171 if (!shader
->reg_maps
.resource_info
[i
].type
)
3174 texture
= state
->textures
[i
];
3177 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3180 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
3181 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
3183 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
3185 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
3186 args
->shadow
|= 1u << i
;
3188 /* Flag samplers that need NP2 texcoord fixup. */
3189 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
3190 args
->np2_fixup
|= (1u << i
);
3193 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
3194 if (shader
->reg_maps
.shader_version
.major
>= 4)
3197 if (shader
->reg_maps
.shader_version
.major
>= 3)
3199 if (position_transformed
)
3200 args
->vp_mode
= pretransformed
;
3201 else if (use_vs(state
))
3202 args
->vp_mode
= vertexshader
;
3204 args
->vp_mode
= fixedfunction
;
3205 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3209 args
->vp_mode
= vertexshader
;
3210 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
3212 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
3214 case WINED3D_FOG_NONE
:
3215 if (position_transformed
|| use_vs(state
))
3217 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
3221 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
3223 case WINED3D_FOG_NONE
: /* Fall through. */
3224 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3225 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3226 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3230 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
3231 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
3232 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
3237 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
3241 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
3243 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
3245 args
->texcoords_initialized
= 0;
3246 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
3250 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
3251 args
->texcoords_initialized
|= 1u << i
;
3255 const struct wined3d_stream_info
*si
= &context
->stream_info
;
3256 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
3258 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
3259 & WINED3D_FFP_TCI_MASK
3260 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
3261 args
->texcoords_initialized
|= 1u << i
;
3267 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
3270 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
3271 && state
->gl_primitive_type
== GL_POINTS
;
3273 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3274 args
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
3276 args
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
3277 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
3278 : WINED3D_CMP_ALWAYS
) - 1;
3280 if (d3d_info
->emulated_flatshading
)
3281 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
3283 args
->render_offscreen
= shader
->reg_maps
.vpos
&& gl_info
->supported
[ARB_FRAGMENT_COORD_CONVENTIONS
]
3284 ? context
->render_offscreen
: 0;
3287 static HRESULT
pixel_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3288 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3290 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
3291 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
3294 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
3295 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
3298 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3300 if (shader
->u
.ps
.input_reg_used
[i
])
3303 highest_reg_used
= i
;
3307 /* Don't do any register mapping magic if it is not needed, or if we can't
3308 * achieve anything anyway */
3309 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
3310 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4)
3311 || shader
->reg_maps
.shader_version
.major
>= 4)
3313 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
3315 /* This happens with relative addressing. The input mapper function
3316 * warns about this if the higher registers are declared too, so
3317 * don't write a FIXME here */
3318 WARN("More varying registers used than supported\n");
3321 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3323 shader
->u
.ps
.input_reg_map
[i
] = i
;
3326 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
3330 shader
->u
.ps
.declared_in_count
= 0;
3331 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
3333 if (shader
->u
.ps
.input_reg_used
[i
])
3334 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
3335 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
3342 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
3344 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
3345 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
3348 if (reg_maps
->shader_version
.major
!= 1) return;
3350 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
3352 /* We don't sample from this sampler. */
3353 if (!resource_info
[i
].type
)
3356 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
3358 case WINED3D_SHADER_TEX_2D
:
3359 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
3362 case WINED3D_SHADER_TEX_3D
:
3363 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
3366 case WINED3D_SHADER_TEX_CUBE
:
3367 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
3373 static HRESULT
compute_shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
3374 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
3376 return shader_init(shader
, device
, desc
, 0, WINED3D_SHADER_TYPE_COMPUTE
, parent
, parent_ops
);
3379 HRESULT CDECL
wined3d_shader_create_cs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3380 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3382 struct wined3d_shader
*object
;
3385 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3386 device
, desc
, parent
, parent_ops
, shader
);
3388 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3389 return E_OUTOFMEMORY
;
3391 if (FAILED(hr
= compute_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3393 WARN("Failed to initialize compute shader, hr %#x.\n", hr
);
3394 HeapFree(GetProcessHeap(), 0, object
);
3398 TRACE("Created compute shader %p.\n", object
);
3404 HRESULT CDECL
wined3d_shader_create_ds(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3405 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3407 struct wined3d_shader
*object
;
3410 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3411 device
, desc
, parent
, parent_ops
, shader
);
3413 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3414 return E_OUTOFMEMORY
;
3416 if (FAILED(hr
= domain_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3418 WARN("Failed to initialize domain shader, hr %#x.\n", hr
);
3419 HeapFree(GetProcessHeap(), 0, object
);
3423 TRACE("Created domain shader %p.\n", object
);
3429 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3430 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3432 struct wined3d_shader
*object
;
3435 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3436 device
, desc
, parent
, parent_ops
, shader
);
3438 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3440 return E_OUTOFMEMORY
;
3442 if (FAILED(hr
= geometry_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3444 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
3445 HeapFree(GetProcessHeap(), 0, object
);
3449 TRACE("Created geometry shader %p.\n", object
);
3455 HRESULT CDECL
wined3d_shader_create_hs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3456 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3458 struct wined3d_shader
*object
;
3461 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3462 device
, desc
, parent
, parent_ops
, shader
);
3464 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
3465 return E_OUTOFMEMORY
;
3467 if (FAILED(hr
= hull_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3469 WARN("Failed to initialize hull shader, hr %#x.\n", hr
);
3470 HeapFree(GetProcessHeap(), 0, object
);
3474 TRACE("Created hull shader %p.\n", object
);
3480 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3481 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3483 struct wined3d_shader
*object
;
3486 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3487 device
, desc
, parent
, parent_ops
, shader
);
3489 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3491 return E_OUTOFMEMORY
;
3493 if (FAILED(hr
= pixel_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3495 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3496 HeapFree(GetProcessHeap(), 0, object
);
3500 TRACE("Created pixel shader %p.\n", object
);
3506 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3507 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3509 struct wined3d_shader
*object
;
3512 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3513 device
, desc
, parent
, parent_ops
, shader
);
3515 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3517 return E_OUTOFMEMORY
;
3519 if (FAILED(hr
= vertex_shader_init(object
, device
, desc
, parent
, parent_ops
)))
3521 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3522 HeapFree(GetProcessHeap(), 0, object
);
3526 TRACE("Created vertex shader %p.\n", object
);