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_BREAK */ "break",
48 /* WINED3DSIH_BREAKC */ "breakc",
49 /* WINED3DSIH_BREAKP */ "breakp",
50 /* WINED3DSIH_CALL */ "call",
51 /* WINED3DSIH_CALLNZ */ "callnz",
52 /* WINED3DSIH_CMP */ "cmp",
53 /* WINED3DSIH_CND */ "cnd",
54 /* WINED3DSIH_CRS */ "crs",
55 /* WINED3DSIH_CUT */ "cut",
56 /* WINED3DSIH_DCL */ "dcl",
57 /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
58 /* WINED3DSIH_DCL_GLOBAL_FLAGS */ "dcl_globalFlags",
59 /* WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER */ "dcl_immediateConstantBuffer",
60 /* WINED3DSIH_DCL_INPUT */ "dcl_input",
61 /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
62 /* WINED3DSIH_DCL_INPUT_PS */ "dcl_input_ps",
63 /* WINED3DSIH_DCL_INPUT_PS_SGV */ "dcl_input_ps_sgv",
64 /* WINED3DSIH_DCL_INPUT_PS_SIV */ "dcl_input_ps_siv",
65 /* WINED3DSIH_DCL_INPUT_SGV */ "dcl_input_sgv",
66 /* WINED3DSIH_DCL_INPUT_SIV */ "dcl_input_siv",
67 /* WINED3DSIH_DCL_OUTPUT */ "dcl_output",
68 /* WINED3DSIH_DCL_OUTPUT_SIV */ "dcl_output_siv",
69 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
70 /* WINED3DSIH_DCL_SAMPLER */ "dcl_sampler",
71 /* WINED3DSIH_DCL_TEMPS */ "dcl_temps",
72 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
73 /* WINED3DSIH_DEF */ "def",
74 /* WINED3DSIH_DEFB */ "defb",
75 /* WINED3DSIH_DEFI */ "defi",
76 /* WINED3DSIH_DIV */ "div",
77 /* WINED3DSIH_DP2 */ "dp2",
78 /* WINED3DSIH_DP2ADD */ "dp2add",
79 /* WINED3DSIH_DP3 */ "dp3",
80 /* WINED3DSIH_DP4 */ "dp4",
81 /* WINED3DSIH_DST */ "dst",
82 /* WINED3DSIH_DSX */ "dsx",
83 /* WINED3DSIH_DSX_COARSE */ "deriv_rtx_coarse",
84 /* WINED3DSIH_DSX_FINE */ "deriv_rtx_fine",
85 /* WINED3DSIH_DSY */ "dsy",
86 /* WINED3DSIH_DSY_COARSE */ "deriv_rty_coarse",
87 /* WINED3DSIH_DSY_FINE */ "deriv_rty_fine",
88 /* WINED3DSIH_ELSE */ "else",
89 /* WINED3DSIH_EMIT */ "emit",
90 /* WINED3DSIH_ENDIF */ "endif",
91 /* WINED3DSIH_ENDLOOP */ "endloop",
92 /* WINED3DSIH_ENDREP */ "endrep",
93 /* WINED3DSIH_EQ */ "eq",
94 /* WINED3DSIH_EXP */ "exp",
95 /* WINED3DSIH_EXPP */ "expp",
96 /* WINED3DSIH_FRC */ "frc",
97 /* WINED3DSIH_FTOI */ "ftoi",
98 /* WINED3DSIH_FTOU */ "ftou",
99 /* WINED3DSIH_GE */ "ge",
100 /* WINED3DSIH_IADD */ "iadd",
101 /* WINED3DSIH_IEQ */ "ieq",
102 /* WINED3DSIH_IF */ "if",
103 /* WINED3DSIH_IFC */ "ifc",
104 /* WINED3DSIH_IGE */ "ige",
105 /* WINED3DSIH_ILT */ "ilt",
106 /* WINED3DSIH_IMAD */ "imad",
107 /* WINED3DSIH_IMAX */ "imax",
108 /* WINED3DSIH_IMIN */ "imin",
109 /* WINED3DSIH_IMUL */ "imul",
110 /* WINED3DSIH_INE */ "ine",
111 /* WINED3DSIH_INEG */ "ineg",
112 /* WINED3DSIH_ISHL */ "ishl",
113 /* WINED3DSIH_ITOF */ "itof",
114 /* WINED3DSIH_LABEL */ "label",
115 /* WINED3DSIH_LD */ "ld",
116 /* WINED3DSIH_LD2DMS */ "ld2dms",
117 /* WINED3DSIH_LD_STRUCTURED */ "ld_structured",
118 /* WINED3DSIH_LIT */ "lit",
119 /* WINED3DSIH_LOG */ "log",
120 /* WINED3DSIH_LOGP */ "logp",
121 /* WINED3DSIH_LOOP */ "loop",
122 /* WINED3DSIH_LRP */ "lrp",
123 /* WINED3DSIH_LT */ "lt",
124 /* WINED3DSIH_M3x2 */ "m3x2",
125 /* WINED3DSIH_M3x3 */ "m3x3",
126 /* WINED3DSIH_M3x4 */ "m3x4",
127 /* WINED3DSIH_M4x3 */ "m4x3",
128 /* WINED3DSIH_M4x4 */ "m4x4",
129 /* WINED3DSIH_MAD */ "mad",
130 /* WINED3DSIH_MAX */ "max",
131 /* WINED3DSIH_MIN */ "min",
132 /* WINED3DSIH_MOV */ "mov",
133 /* WINED3DSIH_MOVA */ "mova",
134 /* WINED3DSIH_MOVC */ "movc",
135 /* WINED3DSIH_MUL */ "mul",
136 /* WINED3DSIH_NE */ "ne",
137 /* WINED3DSIH_NOP */ "nop",
138 /* WINED3DSIH_NOT */ "not",
139 /* WINED3DSIH_NRM */ "nrm",
140 /* WINED3DSIH_OR */ "or",
141 /* WINED3DSIH_PHASE */ "phase",
142 /* WINED3DSIH_POW */ "pow",
143 /* WINED3DSIH_RCP */ "rcp",
144 /* WINED3DSIH_REP */ "rep",
145 /* WINED3DSIH_RESINFO */ "resinfo",
146 /* WINED3DSIH_RET */ "ret",
147 /* WINED3DSIH_ROUND_NI */ "round_ni",
148 /* WINED3DSIH_ROUND_PI */ "round_pi",
149 /* WINED3DSIH_ROUND_Z */ "round_z",
150 /* WINED3DSIH_RSQ */ "rsq",
151 /* WINED3DSIH_SAMPLE */ "sample",
152 /* WINED3DSIH_SAMPLE_B */ "sample_b",
153 /* WINED3DSIH_SAMPLE_C */ "sample_c",
154 /* WINED3DSIH_SAMPLE_C_LZ */ "sample_c_lz",
155 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
156 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
157 /* WINED3DSIH_SETP */ "setp",
158 /* WINED3DSIH_SGE */ "sge",
159 /* WINED3DSIH_SGN */ "sgn",
160 /* WINED3DSIH_SINCOS */ "sincos",
161 /* WINED3DSIH_SLT */ "slt",
162 /* WINED3DSIH_SQRT */ "sqrt",
163 /* WINED3DSIH_SUB */ "sub",
164 /* WINED3DSIH_TEX */ "texld",
165 /* WINED3DSIH_TEXBEM */ "texbem",
166 /* WINED3DSIH_TEXBEML */ "texbeml",
167 /* WINED3DSIH_TEXCOORD */ "texcrd",
168 /* WINED3DSIH_TEXDEPTH */ "texdepth",
169 /* WINED3DSIH_TEXDP3 */ "texdp3",
170 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
171 /* WINED3DSIH_TEXKILL */ "texkill",
172 /* WINED3DSIH_TEXLDD */ "texldd",
173 /* WINED3DSIH_TEXLDL */ "texldl",
174 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
175 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
176 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
177 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
178 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
179 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
180 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
181 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
182 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
183 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
184 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
185 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
186 /* WINED3DSIH_UDIV */ "udiv",
187 /* WINED3DSIH_UGE */ "uge",
188 /* WINED3DSIH_USHR */ "ushr",
189 /* WINED3DSIH_UTOF */ "utof",
190 /* WINED3DSIH_XOR */ "xor",
193 static const char * const semantic_names
[] =
195 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
196 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
197 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
198 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
199 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
200 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
201 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
202 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
203 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
204 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
205 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
206 /* WINED3D_DECL_USAGE_FOG */ "FOG",
207 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
208 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
213 enum wined3d_sysval_semantic sysval_semantic
;
214 const char *sysval_name
;
216 sysval_semantic_names
[] =
218 {WINED3D_SV_POSITION
, "SV_Position"},
219 {WINED3D_SV_INSTANCEID
, "SV_InstanceID"},
220 {WINED3D_SV_PRIMITIVEID
, "SV_PrimitiveID"},
221 {WINED3D_SV_ISFRONTFACE
, "SV_IsFrontFace"},
222 {WINED3D_SV_SAMPLEINDEX
, "SV_SampleIndex"},
225 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
226 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
);
228 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
)
230 if (handler_idx
>= sizeof(shader_opcode_names
) / sizeof(*shader_opcode_names
))
231 return wine_dbg_sprintf("UNRECOGNIZED(%#x)", handler_idx
);
233 return shader_opcode_names
[handler_idx
];
236 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
238 if (usage
>= sizeof(semantic_names
) / sizeof(*semantic_names
))
240 FIXME("Unrecognized usage %#x.\n", usage
);
241 return "UNRECOGNIZED";
244 return semantic_names
[usage
];
247 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
251 for (i
= 0; i
< sizeof(semantic_names
) / sizeof(*semantic_names
); ++i
)
253 if (!strcmp(name
, semantic_names
[i
])) return i
;
259 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
261 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
264 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
265 const struct wined3d_shader_semantic
*s
)
267 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
268 e
->semantic_idx
= s
->usage_idx
;
269 e
->sysval_semantic
= 0;
270 e
->component_type
= 0;
271 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
272 e
->mask
= s
->reg
.write_mask
;
275 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
276 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
278 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
279 e
->semantic_idx
= usage_idx
;
280 e
->sysval_semantic
= 0;
281 e
->component_type
= 0;
282 e
->register_idx
= reg_idx
;
283 e
->mask
= write_mask
;
286 static const struct wined3d_shader_frontend
*shader_select_frontend(DWORD version_token
)
288 switch (version_token
>> 16)
292 return &sm1_shader_frontend
;
297 return &sm4_shader_frontend
;
300 FIXME("Unrecognised version token %#x\n", version_token
);
305 void string_buffer_clear(struct wined3d_string_buffer
*buffer
)
307 buffer
->buffer
[0] = '\0';
308 buffer
->content_size
= 0;
311 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
313 buffer
->buffer_size
= 32;
314 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
316 ERR("Failed to allocate shader buffer memory.\n");
320 string_buffer_clear(buffer
);
324 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
326 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
329 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
332 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
334 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
335 new_buffer_size
*= 2;
336 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
338 ERR("Failed to grow buffer.\n");
339 buffer
->buffer
[buffer
->content_size
] = '\0';
342 buffer
->buffer
= new_buffer
;
343 buffer
->buffer_size
= new_buffer_size
;
347 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
352 rem
= buffer
->buffer_size
- buffer
->content_size
;
353 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
354 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
357 buffer
->content_size
+= rc
;
361 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
368 va_start(args
, format
);
369 ret
= shader_vaddline(buffer
, format
, args
);
373 if (!string_buffer_resize(buffer
, ret
))
378 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
380 struct wined3d_string_buffer
*buffer
;
382 if (list_empty(&list
->list
))
384 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
385 if (!buffer
|| !string_buffer_init(buffer
))
387 ERR("Couldn't allocate buffer for temporary string.\n");
389 HeapFree(GetProcessHeap(), 0, buffer
);
395 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
396 list_remove(&buffer
->entry
);
398 string_buffer_clear(buffer
);
402 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
406 string_buffer_clear(buffer
);
407 return shader_vaddline(buffer
, format
, args
);
410 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
417 va_start(args
, format
);
418 ret
= string_buffer_vsprintf(buffer
, format
, args
);
422 if (!string_buffer_resize(buffer
, ret
))
427 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
431 list_add_head(&list
->list
, &buffer
->entry
);
434 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
436 list_init(&list
->list
);
439 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
441 struct wined3d_string_buffer
*buffer
, *buffer_next
;
443 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
445 string_buffer_free(buffer
);
446 HeapFree(GetProcessHeap(), 0, buffer
);
448 list_init(&list
->list
);
451 /* Convert floating point offset relative to a register file to an absolute
452 * offset for float constants. */
453 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
455 switch (register_type
)
457 case WINED3DSPR_CONST
: return register_idx
;
458 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
459 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
460 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
462 FIXME("Unsupported register type: %u.\n", register_type
);
467 static void shader_delete_constant_list(struct list
*clist
)
469 struct wined3d_shader_lconst
*constant
, *constant_next
;
471 LIST_FOR_EACH_ENTRY_SAFE(constant
, constant_next
, clist
, struct wined3d_shader_lconst
, entry
)
472 HeapFree(GetProcessHeap(), 0, constant
);
476 static void shader_set_limits(struct wined3d_shader
*shader
)
478 static const struct limits_entry
480 unsigned int min_version
;
481 unsigned int max_version
;
482 struct wined3d_shader_limits limits
;
486 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
487 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
488 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
489 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
490 * even though they are capable of supporting much more (GL
491 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
492 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
494 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
495 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
496 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
501 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
502 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
503 {WINED3D_SHADER_VERSION(5, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
508 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
509 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
510 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
511 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
512 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
513 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 12}},
514 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
517 const struct limits_entry
*limits_array
;
518 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
519 shader
->reg_maps
.shader_version
.minor
);
522 switch (shader
->reg_maps
.shader_version
.type
)
525 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
527 case WINED3D_SHADER_TYPE_VERTEX
:
528 limits_array
= vs_limits
;
530 case WINED3D_SHADER_TYPE_GEOMETRY
:
531 limits_array
= gs_limits
;
533 case WINED3D_SHADER_TYPE_PIXEL
:
534 limits_array
= ps_limits
;
538 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
540 if (shader_version
<= limits_array
[i
].max_version
)
542 shader
->limits
= &limits_array
[i
].limits
;
549 FIXME("Unexpected shader version \"%u.%u\".\n",
550 shader
->reg_maps
.shader_version
.major
,
551 shader
->reg_maps
.shader_version
.minor
);
552 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
556 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
561 bitmap
[idx
] |= (1u << shift
);
564 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
565 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
569 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
570 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
571 reg_maps
->texcoord
|= 1u << reg
->idx
[0].offset
;
573 reg_maps
->address
|= 1u << reg
->idx
[0].offset
;
576 case WINED3DSPR_TEMP
:
577 reg_maps
->temporary
|= 1u << reg
->idx
[0].offset
;
580 case WINED3DSPR_INPUT
:
581 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
583 if (reg
->idx
[0].rel_addr
)
585 /* If relative addressing is used, we must assume that all registers
586 * are used. Even if it is a construct like v3[aL], we can't assume
587 * that v0, v1 and v2 aren't read because aL can be negative */
589 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
591 shader
->u
.ps
.input_reg_used
[i
] = TRUE
;
596 shader
->u
.ps
.input_reg_used
[reg
->idx
[0].offset
] = TRUE
;
600 reg_maps
->input_registers
|= 1u << reg
->idx
[0].offset
;
603 case WINED3DSPR_RASTOUT
:
604 if (reg
->idx
[0].offset
== 1)
606 if (reg
->idx
[0].offset
== 2)
607 reg_maps
->point_size
= 1;
610 case WINED3DSPR_MISCTYPE
:
611 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
613 if (!reg
->idx
[0].offset
)
615 else if (reg
->idx
[0].offset
== 1)
616 reg_maps
->usesfacing
= 1;
620 case WINED3DSPR_CONST
:
621 if (reg
->idx
[0].rel_addr
)
623 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
624 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
625 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
626 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
627 reg_maps
->usesrelconstF
= TRUE
;
631 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
633 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
638 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
643 case WINED3DSPR_CONSTINT
:
644 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
646 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
651 reg_maps
->integer_constants
|= (1u << reg
->idx
[0].offset
);
655 case WINED3DSPR_CONSTBOOL
:
656 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
658 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
663 reg_maps
->boolean_constants
|= (1u << reg
->idx
[0].offset
);
667 case WINED3DSPR_COLOROUT
:
668 reg_maps
->rt_mask
|= (1u << reg
->idx
[0].offset
);
672 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
673 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
679 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
680 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
682 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
683 struct wined3d_shader_sampler_map
*map
;
686 map
= ®_maps
->sampler_map
;
687 entries
= map
->entries
;
688 for (i
= 0; i
< map
->count
; ++i
)
690 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
696 if (!(entries
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entries
) * 4)))
698 ERR("Failed to allocate sampler map entries.\n");
702 map
->entries
= entries
;
704 else if (map
->count
== map
->size
)
706 size_t new_size
= map
->size
* 2;
708 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
709 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
711 ERR("Failed to resize sampler map entries.\n");
714 map
->size
= new_size
;
715 map
->entries
= entries
;
718 entry
= &entries
[map
->count
++];
719 entry
->resource_idx
= resource_idx
;
720 entry
->sampler_idx
= sampler_idx
;
721 entry
->bind_idx
= bind_idx
;
724 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
728 case WINED3DSIH_M4x4
:
729 case WINED3DSIH_M3x4
:
730 return param
== 1 ? 3 : 0;
732 case WINED3DSIH_M4x3
:
733 case WINED3DSIH_M3x3
:
734 return param
== 1 ? 2 : 0;
736 case WINED3DSIH_M3x2
:
737 return param
== 1 ? 1 : 0;
744 /* Note that this does not count the loop register as an address register. */
745 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
746 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
747 struct wined3d_shader_signature
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
749 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
750 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
751 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
752 void *fe_data
= shader
->frontend_data
;
753 struct wined3d_shader_version shader_version
;
754 const DWORD
*ptr
= byte_code
;
757 memset(reg_maps
, 0, sizeof(*reg_maps
));
758 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
759 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
760 reg_maps
->min_rel_offset
= ~0U;
762 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
763 reg_maps
->shader_version
= shader_version
;
765 shader_set_limits(shader
);
767 reg_maps
->constf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
768 sizeof(*reg_maps
->constf
) * ((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32));
769 if (!reg_maps
->constf
)
771 ERR("Failed to allocate constant map memory.\n");
772 return E_OUTOFMEMORY
;
775 while (!fe
->shader_is_end(fe_data
, &ptr
))
777 struct wined3d_shader_instruction ins
;
780 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
782 /* Unhandled opcode, and its parameters. */
783 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
785 TRACE("Skipping unrecognized instruction.\n");
789 /* Handle declarations. */
790 if (ins
.handler_idx
== WINED3DSIH_DCL
)
792 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
793 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
795 switch (semantic
->reg
.reg
.type
)
797 /* Mark input registers used. */
798 case WINED3DSPR_INPUT
:
799 if (reg_idx
>= MAX_REG_INPUT
)
801 ERR("Invalid input register index %u.\n", reg_idx
);
804 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
805 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
806 return WINED3DERR_INVALIDCALL
;
807 reg_maps
->input_registers
|= 1u << reg_idx
;
808 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
811 /* Vertex shader: mark 3.0 output registers used, save token. */
812 case WINED3DSPR_OUTPUT
:
813 if (reg_idx
>= MAX_REG_OUTPUT
)
815 ERR("Invalid output register index %u.\n", reg_idx
);
818 reg_maps
->output_registers
|= 1u << reg_idx
;
819 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
820 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
822 if (semantic
->usage
== WINED3D_DECL_USAGE_PSIZE
)
823 reg_maps
->point_size
= 1;
826 case WINED3DSPR_SAMPLER
:
827 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
828 case WINED3DSPR_RESOURCE
:
829 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
831 ERR("Invalid resource index %u.\n", reg_idx
);
834 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
835 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
839 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
843 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
845 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
846 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
847 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
849 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
851 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
854 FIXME("Multiple immediate constant buffers.\n");
855 reg_maps
->icb
= ins
.declaration
.icb
;
857 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
859 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
860 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
862 FIXME("Invalid instruction %#x for shader type %#x.\n",
863 ins
.handler_idx
, shader_version
.type
);
865 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
867 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
868 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
870 FIXME("Invalid instruction %#x for shader type %#x.\n",
871 ins
.handler_idx
, shader_version
.type
);
873 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
875 if (ins
.flags
& WINED3DSI_SAMPLER_COMPARISON_MODE
)
876 reg_maps
->sampler_comparison_mode
|= (1u << ins
.declaration
.dst
.reg
.idx
[0].offset
);
878 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
880 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
881 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
883 FIXME("Invalid instruction %#x for shader type %#x.\n",
884 ins
.handler_idx
, shader_version
.type
);
886 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
888 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
890 if (!lconst
) return E_OUTOFMEMORY
;
892 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
893 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
894 value
= (float *)lconst
->value
;
896 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
897 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
899 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
900 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
901 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
902 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
903 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
904 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
905 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
906 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
909 list_add_head(&shader
->constantsF
, &lconst
->entry
);
911 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
912 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
914 shader
->lconst_inf_or_nan
= TRUE
;
917 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
919 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
920 if (!lconst
) return E_OUTOFMEMORY
;
922 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
923 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
925 list_add_head(&shader
->constantsI
, &lconst
->entry
);
926 reg_maps
->local_int_consts
|= (1u << lconst
->idx
);
928 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
930 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
931 if (!lconst
) return E_OUTOFMEMORY
;
933 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
934 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, sizeof(DWORD
));
936 list_add_head(&shader
->constantsB
, &lconst
->entry
);
937 reg_maps
->local_bool_consts
|= (1u << lconst
->idx
);
939 /* For subroutine prototypes. */
940 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
942 reg_maps
->labels
|= 1u << ins
.src
[0].reg
.idx
[0].offset
;
944 /* Set texture, address, temporary registers. */
947 BOOL color0_mov
= FALSE
;
950 /* This will loop over all the registers and try to
951 * make a bitmask of the ones we're interested in.
953 * Relative addressing tokens are ignored, but that's
954 * okay, since we'll catch any address registers when
955 * they are initialized (required by spec). */
956 for (i
= 0; i
< ins
.dst_count
; ++i
)
958 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
959 shader_version
.type
, constf_size
))
960 return WINED3DERR_INVALIDCALL
;
962 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
964 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
966 switch (ins
.dst
[i
].reg
.type
)
968 case WINED3DSPR_RASTOUT
:
969 if (shader_version
.major
>= 3)
974 reg_maps
->output_registers
|= 1u << 10;
975 shader_signature_from_usage(&output_signature_elements
[10],
976 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
980 reg_maps
->output_registers
|= 1u << 11;
981 shader_signature_from_usage(&output_signature_elements
[11],
982 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
986 reg_maps
->output_registers
|= 1u << 11;
987 shader_signature_from_usage(&output_signature_elements
[11],
988 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
993 case WINED3DSPR_ATTROUT
:
994 if (shader_version
.major
>= 3)
999 if (reg_maps
->output_registers
& (1u << idx
))
1001 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1005 reg_maps
->output_registers
|= 1u << idx
;
1006 shader_signature_from_usage(&output_signature_elements
[idx
],
1007 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
1012 case WINED3DSPR_TEXCRDOUT
:
1013 if (shader_version
.major
>= 3)
1015 reg_maps
->u
.output_registers_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1018 reg_maps
->u
.texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
1019 if (reg_maps
->output_registers
& (1u << idx
))
1021 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
1025 reg_maps
->output_registers
|= 1u << idx
;
1026 shader_signature_from_usage(&output_signature_elements
[idx
],
1027 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
1036 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1038 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
1040 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
1041 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
1042 * the mov and perform the sRGB write correction from the source register.
1044 * However, if the mov is only partial, we can't do this, and if the write
1045 * comes from an instruction other than MOV it is hard to do as well. If
1046 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
1047 shader
->u
.ps
.color0_mov
= FALSE
;
1048 if (ins
.handler_idx
== WINED3DSIH_MOV
1049 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
1051 /* Used later when the source register is read. */
1055 /* Also drop the MOV marker if the source register is overwritten prior to the shader
1058 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
1059 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
1061 shader
->u
.ps
.color0_mov
= FALSE
;
1065 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
1066 if (shader_version
.major
== 1
1067 && (ins
.handler_idx
== WINED3DSIH_TEX
1068 || ins
.handler_idx
== WINED3DSIH_TEXBEM
1069 || ins
.handler_idx
== WINED3DSIH_TEXBEML
1070 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
1071 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
1072 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1073 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1074 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1075 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1076 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1077 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1079 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1081 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1082 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1083 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1084 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1086 /* texbem is only valid with < 1.4 pixel shaders */
1087 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1088 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1090 reg_maps
->bumpmat
|= 1u << reg_idx
;
1091 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1093 reg_maps
->luminanceparams
|= 1u << reg_idx
;
1097 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1099 reg_maps
->bumpmat
|= 1u << ins
.dst
[i
].reg
.idx
[0].offset
;
1103 if (ins
.handler_idx
== WINED3DSIH_NRM
) reg_maps
->usesnrm
= 1;
1104 else if (ins
.handler_idx
== WINED3DSIH_DSY
) reg_maps
->usesdsy
= 1;
1105 else if (ins
.handler_idx
== WINED3DSIH_DSX
) reg_maps
->usesdsx
= 1;
1106 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1107 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1108 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1109 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1110 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1111 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1112 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1113 || ins
.handler_idx
== WINED3DSIH_REP
)
1116 if (cur_loop_depth
> max_loop_depth
)
1117 max_loop_depth
= cur_loop_depth
;
1119 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1120 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1124 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1125 || ins
.handler_idx
== WINED3DSIH_SAMPLE_B
1126 || ins
.handler_idx
== WINED3DSIH_SAMPLE_C_LZ
1127 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1128 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1130 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1131 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1133 else if (ins
.handler_idx
== WINED3DSIH_LD
1134 || ins
.handler_idx
== WINED3DSIH_RESINFO
)
1136 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1137 WINED3D_SAMPLER_DEFAULT
, reg_maps
->sampler_map
.count
);
1141 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1142 shader_version
.type
, constf_size
))
1143 return WINED3DERR_INVALIDCALL
;
1145 for (i
= 0; i
< ins
.src_count
; ++i
)
1147 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1148 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1150 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1151 shader_version
.type
, constf_size
))
1152 return WINED3DERR_INVALIDCALL
;
1155 ++reg
.idx
[0].offset
;
1156 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1157 shader_version
.type
, constf_size
))
1158 return WINED3DERR_INVALIDCALL
;
1164 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1165 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1167 shader
->u
.ps
.color0_mov
= TRUE
;
1168 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1174 reg_maps
->loop_depth
= max_loop_depth
;
1176 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1177 * R0 is written to the render target. */
1178 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1179 reg_maps
->rt_mask
|= (1u << 0);
1181 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1183 if (input_signature
->elements
)
1185 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1187 reg_maps
->input_registers
|= 1u << input_signature
->elements
[i
].register_idx
;
1188 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
1189 && input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1193 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1195 unsigned int count
= wined3d_popcount(reg_maps
->input_registers
);
1196 struct wined3d_shader_signature_element
*e
;
1199 if (!(input_signature
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*input_signature
->elements
) * count
)))
1200 return E_OUTOFMEMORY
;
1201 input_signature
->element_count
= count
;
1203 e
= input_signature
->elements
;
1204 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1206 if (!(reg_maps
->input_registers
& (1u << i
)))
1208 input_signature_elements
[i
].register_idx
= i
;
1209 *e
++ = input_signature_elements
[i
];
1213 if (output_signature
->elements
)
1215 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1217 reg_maps
->output_registers
|= 1u << output_signature
->elements
[i
].register_idx
;
1220 else if (reg_maps
->output_registers
)
1222 unsigned int count
= wined3d_popcount(reg_maps
->output_registers
);
1223 struct wined3d_shader_signature_element
*e
;
1225 if (!(output_signature
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*output_signature
->elements
) * count
)))
1226 return E_OUTOFMEMORY
;
1227 output_signature
->element_count
= count
;
1229 e
= output_signature
->elements
;
1230 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1232 if (!(reg_maps
->output_registers
& (1u << i
)))
1234 *e
++ = output_signature_elements
[i
];
1241 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1243 DWORD map
= 1u << max
;
1245 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1247 return wined3d_log2i(map
);
1250 static void shader_dump_global_flags(struct wined3d_string_buffer
*buffer
, DWORD global_flags
)
1252 if (global_flags
& WINED3DSGF_REFACTORING_ALLOWED
)
1254 shader_addline(buffer
, "refactoringAllowed");
1255 global_flags
&= ~WINED3DSGF_REFACTORING_ALLOWED
;
1257 shader_addline(buffer
, " | ");
1260 if (global_flags
& WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
)
1262 shader_addline(buffer
, "enableRawAndStructuredBuffers");
1263 global_flags
&= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS
;
1267 shader_addline(buffer
, "unknown_flags(%#x)", global_flags
);
1270 static void shader_dump_sysval_semantic(struct wined3d_string_buffer
*buffer
, enum wined3d_sysval_semantic semantic
)
1274 for (i
= 0; i
< ARRAY_SIZE(sysval_semantic_names
); ++i
)
1276 if (sysval_semantic_names
[i
].sysval_semantic
== semantic
)
1278 shader_addline(buffer
, "%s", sysval_semantic_names
[i
].sysval_name
);
1283 shader_addline(buffer
, "unknown_sysval_semantic(%#x)", semantic
);
1286 static void shader_dump_decl_usage(struct wined3d_string_buffer
*buffer
,
1287 const struct wined3d_shader_semantic
*semantic
, const struct wined3d_shader_version
*shader_version
)
1289 shader_addline(buffer
, "dcl");
1291 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1293 switch (semantic
->resource_type
)
1295 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1296 shader_addline(buffer
, "_2d");
1299 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1300 shader_addline(buffer
, "_3d");
1303 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1304 shader_addline(buffer
, "_cube");
1308 shader_addline(buffer
, "_unknown_resource_type(%#x)", semantic
->resource_type
);
1312 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1314 shader_addline(buffer
, "_resource_");
1315 switch (semantic
->resource_type
)
1317 case WINED3D_SHADER_RESOURCE_BUFFER
:
1318 shader_addline(buffer
, "buffer");
1321 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1322 shader_addline(buffer
, "texture1d");
1325 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1326 shader_addline(buffer
, "texture2d");
1329 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1330 shader_addline(buffer
, "texture2dms");
1333 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1334 shader_addline(buffer
, "texture3d");
1337 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1338 shader_addline(buffer
, "texturecube");
1341 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1342 shader_addline(buffer
, "texture1darray");
1345 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1346 shader_addline(buffer
, "texture2darray");
1349 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1350 shader_addline(buffer
, "texture2dmsarray");
1354 shader_addline(buffer
, "unknown");
1357 switch (semantic
->resource_data_type
)
1359 case WINED3D_DATA_FLOAT
:
1360 shader_addline(buffer
, " (float)");
1363 case WINED3D_DATA_INT
:
1364 shader_addline(buffer
, " (int)");
1367 case WINED3D_DATA_UINT
:
1368 shader_addline(buffer
, " (uint)");
1371 case WINED3D_DATA_UNORM
:
1372 shader_addline(buffer
, " (unorm)");
1375 case WINED3D_DATA_SNORM
:
1376 shader_addline(buffer
, " (snorm)");
1380 shader_addline(buffer
, " (unknown)");
1386 /* Pixel shaders 3.0 don't have usage semantics. */
1387 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
1390 shader_addline(buffer
, "_");
1392 switch (semantic
->usage
)
1394 case WINED3D_DECL_USAGE_POSITION
:
1395 shader_addline(buffer
, "position%u", semantic
->usage_idx
);
1398 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1399 shader_addline(buffer
, "blend");
1402 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1403 shader_addline(buffer
, "weight");
1406 case WINED3D_DECL_USAGE_NORMAL
:
1407 shader_addline(buffer
, "normal%u", semantic
->usage_idx
);
1410 case WINED3D_DECL_USAGE_PSIZE
:
1411 shader_addline(buffer
, "psize");
1414 case WINED3D_DECL_USAGE_COLOR
:
1415 if (!semantic
->usage_idx
)
1416 shader_addline(buffer
, "color");
1418 shader_addline(buffer
, "specular%u", (semantic
->usage_idx
- 1));
1421 case WINED3D_DECL_USAGE_TEXCOORD
:
1422 shader_addline(buffer
, "texture%u", semantic
->usage_idx
);
1425 case WINED3D_DECL_USAGE_TANGENT
:
1426 shader_addline(buffer
, "tangent");
1429 case WINED3D_DECL_USAGE_BINORMAL
:
1430 shader_addline(buffer
, "binormal");
1433 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1434 shader_addline(buffer
, "tessfactor");
1437 case WINED3D_DECL_USAGE_POSITIONT
:
1438 shader_addline(buffer
, "positionT%u", semantic
->usage_idx
);
1441 case WINED3D_DECL_USAGE_FOG
:
1442 shader_addline(buffer
, "fog");
1445 case WINED3D_DECL_USAGE_DEPTH
:
1446 shader_addline(buffer
, "depth");
1449 case WINED3D_DECL_USAGE_SAMPLE
:
1450 shader_addline(buffer
, "sample");
1454 shader_addline(buffer
, "<unknown_semantic(%#x)>", semantic
->usage
);
1455 FIXME("unknown_semantics(0x%08x)", semantic
->usage
);
1460 static void shader_dump_register(struct wined3d_string_buffer
*buffer
,
1461 const struct wined3d_shader_register
*reg
, const struct wined3d_shader_version
*shader_version
)
1463 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1464 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1465 UINT offset
= reg
->idx
[0].offset
;
1469 case WINED3DSPR_TEMP
:
1470 shader_addline(buffer
, "r");
1473 case WINED3DSPR_INPUT
:
1474 shader_addline(buffer
, "v");
1477 case WINED3DSPR_CONST
:
1478 case WINED3DSPR_CONST2
:
1479 case WINED3DSPR_CONST3
:
1480 case WINED3DSPR_CONST4
:
1481 shader_addline(buffer
, "c");
1482 offset
= shader_get_float_offset(reg
->type
, offset
);
1485 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1486 shader_addline(buffer
, "%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1489 case WINED3DSPR_RASTOUT
:
1490 shader_addline(buffer
, "%s", rastout_reg_names
[offset
]);
1493 case WINED3DSPR_COLOROUT
:
1494 shader_addline(buffer
, "oC");
1497 case WINED3DSPR_DEPTHOUT
:
1498 shader_addline(buffer
, "oDepth");
1501 case WINED3DSPR_ATTROUT
:
1502 shader_addline(buffer
, "oD");
1505 case WINED3DSPR_TEXCRDOUT
:
1506 /* Vertex shaders >= 3.0 use general purpose output registers
1507 * (WINED3DSPR_OUTPUT), which can include an address token. */
1508 if (shader_version
->major
>= 3)
1509 shader_addline(buffer
, "o");
1511 shader_addline(buffer
, "oT");
1514 case WINED3DSPR_CONSTINT
:
1515 shader_addline(buffer
, "i");
1518 case WINED3DSPR_CONSTBOOL
:
1519 shader_addline(buffer
, "b");
1522 case WINED3DSPR_LABEL
:
1523 shader_addline(buffer
, "l");
1526 case WINED3DSPR_LOOP
:
1527 shader_addline(buffer
, "aL");
1530 case WINED3DSPR_SAMPLER
:
1531 shader_addline(buffer
, "s");
1534 case WINED3DSPR_MISCTYPE
:
1537 FIXME("Unhandled misctype register %u.\n", offset
);
1538 shader_addline(buffer
, "<unhandled misctype %#x>", offset
);
1542 shader_addline(buffer
, "%s", misctype_reg_names
[offset
]);
1546 case WINED3DSPR_PREDICATE
:
1547 shader_addline(buffer
, "p");
1550 case WINED3DSPR_IMMCONST
:
1551 shader_addline(buffer
, "l");
1554 case WINED3DSPR_CONSTBUFFER
:
1555 shader_addline(buffer
, "cb");
1558 case WINED3DSPR_IMMCONSTBUFFER
:
1559 shader_addline(buffer
, "icb");
1562 case WINED3DSPR_PRIMID
:
1563 shader_addline(buffer
, "primID");
1566 case WINED3DSPR_NULL
:
1567 shader_addline(buffer
, "null");
1570 case WINED3DSPR_RESOURCE
:
1571 shader_addline(buffer
, "t");
1575 shader_addline(buffer
, "<unhandled_rtype(%#x)>", reg
->type
);
1579 if (reg
->type
== WINED3DSPR_IMMCONST
)
1581 shader_addline(buffer
, "(");
1582 switch (reg
->immconst_type
)
1584 case WINED3D_IMMCONST_SCALAR
:
1585 switch (reg
->data_type
)
1587 case WINED3D_DATA_FLOAT
:
1588 shader_addline(buffer
, "%.8e", *(const float *)reg
->immconst_data
);
1590 case WINED3D_DATA_INT
:
1591 shader_addline(buffer
, "%d", reg
->immconst_data
[0]);
1593 case WINED3D_DATA_RESOURCE
:
1594 case WINED3D_DATA_SAMPLER
:
1595 case WINED3D_DATA_UINT
:
1596 shader_addline(buffer
, "%u", reg
->immconst_data
[0]);
1599 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1604 case WINED3D_IMMCONST_VEC4
:
1605 switch (reg
->data_type
)
1607 case WINED3D_DATA_FLOAT
:
1608 shader_addline(buffer
, "%.8e, %.8e, %.8e, %.8e",
1609 *(const float *)®
->immconst_data
[0], *(const float *)®
->immconst_data
[1],
1610 *(const float *)®
->immconst_data
[2], *(const float *)®
->immconst_data
[3]);
1612 case WINED3D_DATA_INT
:
1613 shader_addline(buffer
, "%d, %d, %d, %d",
1614 reg
->immconst_data
[0], reg
->immconst_data
[1],
1615 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1617 case WINED3D_DATA_RESOURCE
:
1618 case WINED3D_DATA_SAMPLER
:
1619 case WINED3D_DATA_UINT
:
1620 shader_addline(buffer
, "%u, %u, %u, %u",
1621 reg
->immconst_data
[0], reg
->immconst_data
[1],
1622 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1625 shader_addline(buffer
, "<unhandled data type %#x>", reg
->data_type
);
1631 shader_addline(buffer
, "<unhandled immconst_type %#x>", reg
->immconst_type
);
1634 shader_addline(buffer
, ")");
1636 else if (reg
->type
!= WINED3DSPR_RASTOUT
1637 && reg
->type
!= WINED3DSPR_MISCTYPE
1638 && reg
->type
!= WINED3DSPR_NULL
)
1642 shader_addline(buffer
, "[");
1643 if (reg
->idx
[0].rel_addr
)
1645 shader_dump_src_param(buffer
, reg
->idx
[0].rel_addr
, shader_version
);
1646 shader_addline(buffer
, " + ");
1648 shader_addline(buffer
, "%u]", offset
);
1650 if (reg
->idx
[1].offset
!= ~0u)
1652 shader_addline(buffer
, "[");
1653 if (reg
->idx
[1].rel_addr
)
1655 shader_dump_src_param(buffer
, reg
->idx
[1].rel_addr
, shader_version
);
1656 shader_addline(buffer
, " + ");
1658 shader_addline(buffer
, "%u]", reg
->idx
[1].offset
);
1664 static void shader_dump_dst_param(struct wined3d_string_buffer
*buffer
,
1665 const struct wined3d_shader_dst_param
*param
, const struct wined3d_shader_version
*shader_version
)
1667 DWORD write_mask
= param
->write_mask
;
1669 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
1671 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
1673 static const char write_mask_chars
[] = "xyzw";
1675 shader_addline(buffer
, ".");
1676 if (write_mask
& WINED3DSP_WRITEMASK_0
)
1677 shader_addline(buffer
, "%c", write_mask_chars
[0]);
1678 if (write_mask
& WINED3DSP_WRITEMASK_1
)
1679 shader_addline(buffer
, "%c", write_mask_chars
[1]);
1680 if (write_mask
& WINED3DSP_WRITEMASK_2
)
1681 shader_addline(buffer
, "%c", write_mask_chars
[2]);
1682 if (write_mask
& WINED3DSP_WRITEMASK_3
)
1683 shader_addline(buffer
, "%c", write_mask_chars
[3]);
1687 static void shader_dump_src_param(struct wined3d_string_buffer
*buffer
,
1688 const struct wined3d_shader_src_param
*param
, const struct wined3d_shader_version
*shader_version
)
1690 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
1691 DWORD swizzle
= param
->swizzle
;
1693 if (src_modifier
== WINED3DSPSM_NEG
1694 || src_modifier
== WINED3DSPSM_BIASNEG
1695 || src_modifier
== WINED3DSPSM_SIGNNEG
1696 || src_modifier
== WINED3DSPSM_X2NEG
1697 || src_modifier
== WINED3DSPSM_ABSNEG
)
1698 shader_addline(buffer
, "-");
1699 else if (src_modifier
== WINED3DSPSM_COMP
)
1700 shader_addline(buffer
, "1-");
1701 else if (src_modifier
== WINED3DSPSM_NOT
)
1702 shader_addline(buffer
, "!");
1704 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
1705 shader_addline(buffer
, "abs(");
1707 shader_dump_register(buffer
, ¶m
->reg
, shader_version
);
1709 switch (src_modifier
)
1711 case WINED3DSPSM_NONE
: break;
1712 case WINED3DSPSM_NEG
: break;
1713 case WINED3DSPSM_NOT
: break;
1714 case WINED3DSPSM_BIAS
: shader_addline(buffer
, "_bias"); break;
1715 case WINED3DSPSM_BIASNEG
: shader_addline(buffer
, "_bias"); break;
1716 case WINED3DSPSM_SIGN
: shader_addline(buffer
, "_bx2"); break;
1717 case WINED3DSPSM_SIGNNEG
: shader_addline(buffer
, "_bx2"); break;
1718 case WINED3DSPSM_COMP
: break;
1719 case WINED3DSPSM_X2
: shader_addline(buffer
, "_x2"); break;
1720 case WINED3DSPSM_X2NEG
: shader_addline(buffer
, "_x2"); break;
1721 case WINED3DSPSM_DZ
: shader_addline(buffer
, "_dz"); break;
1722 case WINED3DSPSM_DW
: shader_addline(buffer
, "_dw"); break;
1723 case WINED3DSPSM_ABSNEG
: shader_addline(buffer
, ")"); break;
1724 case WINED3DSPSM_ABS
: shader_addline(buffer
, ")"); break;
1725 default: shader_addline(buffer
, "_unknown_modifier(%#x)", src_modifier
);
1728 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
1730 static const char swizzle_chars
[] = "xyzw";
1731 DWORD swizzle_x
= swizzle
& 0x03;
1732 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
1733 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
1734 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
1736 if (swizzle_x
== swizzle_y
1737 && swizzle_x
== swizzle_z
1738 && swizzle_x
== swizzle_w
)
1740 shader_addline(buffer
, ".%c", swizzle_chars
[swizzle_x
]);
1744 shader_addline(buffer
, ".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
1745 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
1750 /* Shared code in order to generate the bulk of the shader string.
1751 * NOTE: A description of how to parse tokens can be found on MSDN. */
1752 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
1753 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
1755 struct wined3d_device
*device
= shader
->device
;
1756 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
1757 void *fe_data
= shader
->frontend_data
;
1758 struct wined3d_shader_version shader_version
;
1759 struct wined3d_shader_loop_state loop_state
;
1760 struct wined3d_shader_instruction ins
;
1761 struct wined3d_shader_tex_mx tex_mx
;
1762 struct wined3d_shader_context ctx
;
1763 const DWORD
*ptr
= byte_code
;
1765 /* Initialize current parsing state. */
1766 tex_mx
.current_row
= 0;
1767 loop_state
.current_depth
= 0;
1768 loop_state
.current_reg
= 0;
1770 ctx
.shader
= shader
;
1771 ctx
.gl_info
= &device
->adapter
->gl_info
;
1772 ctx
.reg_maps
= reg_maps
;
1773 ctx
.buffer
= buffer
;
1774 ctx
.tex_mx
= &tex_mx
;
1775 ctx
.loop_state
= &loop_state
;
1776 ctx
.backend_data
= backend_ctx
;
1779 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1781 while (!fe
->shader_is_end(fe_data
, &ptr
))
1784 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1786 /* Unknown opcode and its parameters. */
1787 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1789 TRACE("Skipping unrecognized instruction.\n");
1794 FIXME("Predicates not implemented.\n");
1796 /* Call appropriate function for output target */
1797 device
->shader_backend
->shader_handle_instruction(&ins
);
1801 static void shader_dump_ins_modifiers(struct wined3d_string_buffer
*buffer
,
1802 const struct wined3d_shader_dst_param
*dst
)
1804 DWORD mmask
= dst
->modifiers
;
1809 case 13: shader_addline(buffer
, "_d8"); break;
1810 case 14: shader_addline(buffer
, "_d4"); break;
1811 case 15: shader_addline(buffer
, "_d2"); break;
1812 case 1: shader_addline(buffer
, "_x2"); break;
1813 case 2: shader_addline(buffer
, "_x4"); break;
1814 case 3: shader_addline(buffer
, "_x8"); break;
1815 default: shader_addline(buffer
, "_unhandled_shift(%d)", dst
->shift
); break;
1818 if (mmask
& WINED3DSPDM_SATURATE
) shader_addline(buffer
, "_sat");
1819 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) shader_addline(buffer
, "_pp");
1820 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) shader_addline(buffer
, "_centroid");
1822 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
1823 if (mmask
) FIXME("_unrecognized_modifier(%#x)", mmask
);
1826 static void shader_dump_primitive_type(struct wined3d_string_buffer
*buffer
,
1827 enum wined3d_primitive_type primitive_type
)
1829 switch (primitive_type
)
1831 case WINED3D_PT_UNDEFINED
:
1832 shader_addline(buffer
, "undefined");
1834 case WINED3D_PT_POINTLIST
:
1835 shader_addline(buffer
, "pointlist");
1837 case WINED3D_PT_LINELIST
:
1838 shader_addline(buffer
, "linelist");
1840 case WINED3D_PT_LINESTRIP
:
1841 shader_addline(buffer
, "linestrip");
1843 case WINED3D_PT_TRIANGLELIST
:
1844 shader_addline(buffer
, "trianglelist");
1846 case WINED3D_PT_TRIANGLESTRIP
:
1847 shader_addline(buffer
, "trianglestrip");
1849 case WINED3D_PT_TRIANGLEFAN
:
1850 shader_addline(buffer
, "trianglefan");
1852 case WINED3D_PT_LINELIST_ADJ
:
1853 shader_addline(buffer
, "linelist_adj");
1855 case WINED3D_PT_LINESTRIP_ADJ
:
1856 shader_addline(buffer
, "linestrip_adj");
1858 case WINED3D_PT_TRIANGLELIST_ADJ
:
1859 shader_addline(buffer
, "trianglelist_adj");
1861 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
1862 shader_addline(buffer
, "trianglestrip_adj");
1865 shader_addline(buffer
, "<unrecognized_primitive_type %#x>", primitive_type
);
1870 static void shader_dump_interpolation_mode(struct wined3d_string_buffer
*buffer
,
1871 enum wined3d_shader_interpolation_mode interpolation_mode
)
1873 switch (interpolation_mode
)
1875 case WINED3DSIM_CONSTANT
:
1876 shader_addline(buffer
, "constant");
1878 case WINED3DSIM_LINEAR
:
1879 shader_addline(buffer
, "linear");
1881 case WINED3DSIM_LINEAR_CENTROID
:
1882 shader_addline(buffer
, "linear centroid");
1884 case WINED3DSIM_LINEAR_NOPERSPECTIVE
:
1885 shader_addline(buffer
, "linear noperspective");
1887 case WINED3DSIM_LINEAR_SAMPLE
:
1888 shader_addline(buffer
, "linear sample");
1890 case WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID
:
1891 shader_addline(buffer
, "linear noperspective centroid");
1893 case WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE
:
1894 shader_addline(buffer
, "linear noperspective sample");
1897 shader_addline(buffer
, "<unrecognized_interpolation_mode %#x>", interpolation_mode
);
1902 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
1904 struct wined3d_shader_version shader_version
;
1905 struct wined3d_string_buffer buffer
;
1906 const DWORD
*ptr
= byte_code
;
1907 const char *type_prefix
;
1911 if (!string_buffer_init(&buffer
))
1913 ERR("Failed to initialize string buffer.\n");
1917 TRACE("Parsing %p.\n", byte_code
);
1919 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1921 switch (shader_version
.type
)
1923 case WINED3D_SHADER_TYPE_VERTEX
:
1927 case WINED3D_SHADER_TYPE_GEOMETRY
:
1931 case WINED3D_SHADER_TYPE_PIXEL
:
1936 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
1937 type_prefix
= "unknown";
1941 shader_addline(&buffer
, "%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
1943 while (!fe
->shader_is_end(fe_data
, &ptr
))
1945 struct wined3d_shader_instruction ins
;
1947 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1948 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1950 WARN("Skipping unrecognized instruction.\n");
1951 shader_addline(&buffer
, "<unrecognized instruction>\n");
1955 if (ins
.handler_idx
== WINED3DSIH_DCL
)
1957 shader_dump_decl_usage(&buffer
, &ins
.declaration
.semantic
, &shader_version
);
1958 shader_dump_ins_modifiers(&buffer
, &ins
.declaration
.semantic
.reg
);
1959 shader_addline(&buffer
, " ");
1960 shader_dump_dst_param(&buffer
, &ins
.declaration
.semantic
.reg
, &shader_version
);
1962 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1964 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
1965 shader_dump_src_param(&buffer
, &ins
.declaration
.src
, &shader_version
);
1966 shader_addline(&buffer
, ", %s",
1967 ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
1969 else if (ins
.handler_idx
== WINED3DSIH_DCL_GLOBAL_FLAGS
)
1971 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
1972 shader_dump_global_flags(&buffer
, ins
.flags
);
1974 else if (ins
.handler_idx
== WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
)
1976 shader_addline(&buffer
, "%s {\n", shader_opcode_names
[ins
.handler_idx
]);
1977 for (i
= 0; i
< ins
.declaration
.icb
->element_count
/ 4; ++i
)
1979 shader_addline(&buffer
, " {0x%08x, 0x%08x, 0x%08x, 0x%08x},\n",
1980 ins
.declaration
.icb
->data
[4 * i
+ 0],
1981 ins
.declaration
.icb
->data
[4 * i
+ 1],
1982 ins
.declaration
.icb
->data
[4 * i
+ 2],
1983 ins
.declaration
.icb
->data
[4 * i
+ 3]);
1985 shader_addline(&buffer
, "}");
1987 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS
)
1989 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
1990 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
1991 shader_addline(&buffer
, " ");
1992 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
1994 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SGV
1995 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SGV
1996 || ins
.handler_idx
== WINED3DSIH_DCL_INPUT_SIV
1997 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_SIV
)
1999 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2000 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2001 shader_addline(&buffer
, ", ");
2002 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2004 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PS_SIV
)
2006 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2007 shader_dump_interpolation_mode(&buffer
, ins
.flags
);
2008 shader_addline(&buffer
, " ");
2009 shader_dump_dst_param(&buffer
, &ins
.declaration
.register_semantic
.reg
, &shader_version
);
2010 shader_addline(&buffer
, ", ");
2011 shader_dump_sysval_semantic(&buffer
, ins
.declaration
.register_semantic
.sysval_semantic
);
2013 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT
2014 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT
)
2016 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2017 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2019 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
2020 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
2022 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2023 shader_dump_primitive_type(&buffer
, ins
.declaration
.primitive_type
);
2025 else if (ins
.handler_idx
== WINED3DSIH_DCL_SAMPLER
)
2027 shader_addline(&buffer
, "%s ", shader_opcode_names
[ins
.handler_idx
]);
2028 shader_dump_dst_param(&buffer
, &ins
.declaration
.dst
, &shader_version
);
2029 if (ins
.flags
== WINED3DSI_SAMPLER_COMPARISON_MODE
)
2030 shader_addline(&buffer
, ", comparisonMode");
2032 else if (ins
.handler_idx
== WINED3DSIH_DCL_TEMPS
2033 || ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
2035 shader_addline(&buffer
, "%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
2037 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
2039 shader_addline(&buffer
, "def c%u = %.8e, %.8e, %.8e, %.8e", shader_get_float_offset(ins
.dst
[0].reg
.type
,
2040 ins
.dst
[0].reg
.idx
[0].offset
),
2041 *(const float *)&ins
.src
[0].reg
.immconst_data
[0],
2042 *(const float *)&ins
.src
[0].reg
.immconst_data
[1],
2043 *(const float *)&ins
.src
[0].reg
.immconst_data
[2],
2044 *(const float *)&ins
.src
[0].reg
.immconst_data
[3]);
2046 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
2048 shader_addline(&buffer
, "defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
2049 ins
.src
[0].reg
.immconst_data
[0],
2050 ins
.src
[0].reg
.immconst_data
[1],
2051 ins
.src
[0].reg
.immconst_data
[2],
2052 ins
.src
[0].reg
.immconst_data
[3]);
2054 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
2056 shader_addline(&buffer
, "defb b%u = %s",
2057 ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.immconst_data
[0] ? "true" : "false");
2063 shader_addline(&buffer
, "(");
2064 shader_dump_src_param(&buffer
, ins
.predicate
, &shader_version
);
2065 shader_addline(&buffer
, ") ");
2068 /* PixWin marks instructions with the coissue flag with a '+' */
2070 shader_addline(&buffer
, "+");
2072 shader_addline(&buffer
, "%s", shader_opcode_names
[ins
.handler_idx
]);
2074 if (ins
.handler_idx
== WINED3DSIH_IFC
2075 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
2079 case WINED3D_SHADER_REL_OP_GT
: shader_addline(&buffer
, "_gt"); break;
2080 case WINED3D_SHADER_REL_OP_EQ
: shader_addline(&buffer
, "_eq"); break;
2081 case WINED3D_SHADER_REL_OP_GE
: shader_addline(&buffer
, "_ge"); break;
2082 case WINED3D_SHADER_REL_OP_LT
: shader_addline(&buffer
, "_lt"); break;
2083 case WINED3D_SHADER_REL_OP_NE
: shader_addline(&buffer
, "_ne"); break;
2084 case WINED3D_SHADER_REL_OP_LE
: shader_addline(&buffer
, "_le"); break;
2085 default: shader_addline(&buffer
, "_(%u)", ins
.flags
);
2088 else if (ins
.handler_idx
== WINED3DSIH_TEX
2089 && shader_version
.major
>= 2
2090 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
2092 shader_addline(&buffer
, "p");
2094 else if (ins
.handler_idx
== WINED3DSIH_RESINFO
2099 case WINED3DSI_RESINFO_RCP_FLOAT
: shader_addline(&buffer
, "_rcpFloat"); break;
2100 case WINED3DSI_RESINFO_UINT
: shader_addline(&buffer
, "_uint"); break;
2101 default: shader_addline(&buffer
, "_unrecognized(%#x)", ins
.flags
);
2105 if (wined3d_shader_instruction_has_texel_offset(&ins
))
2106 shader_addline(&buffer
, "(%d,%d,%d)", ins
.texel_offset
.u
, ins
.texel_offset
.v
, ins
.texel_offset
.w
);
2108 for (i
= 0; i
< ins
.dst_count
; ++i
)
2110 shader_dump_ins_modifiers(&buffer
, &ins
.dst
[i
]);
2111 shader_addline(&buffer
, !i
? " " : ", ");
2112 shader_dump_dst_param(&buffer
, &ins
.dst
[i
], &shader_version
);
2115 /* Other source tokens */
2116 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
2118 shader_addline(&buffer
, !i
? " " : ", ");
2119 shader_dump_src_param(&buffer
, &ins
.src
[i
- ins
.dst_count
], &shader_version
);
2122 shader_addline(&buffer
, "\n");
2125 for (p
= buffer
.buffer
; *p
; p
= q
)
2127 if (!(q
= strstr(p
, "\n")))
2131 TRACE(" %.*s", (int)(q
- p
), p
);
2134 string_buffer_free(&buffer
);
2137 static void shader_cleanup(struct wined3d_shader
*shader
)
2139 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
2140 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2141 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2142 shader
->device
->shader_backend
->shader_destroy(shader
);
2143 HeapFree(GetProcessHeap(), 0, shader
->reg_maps
.constf
);
2144 HeapFree(GetProcessHeap(), 0, shader
->reg_maps
.sampler_map
.entries
);
2145 HeapFree(GetProcessHeap(), 0, shader
->function
);
2146 shader_delete_constant_list(&shader
->constantsF
);
2147 shader_delete_constant_list(&shader
->constantsB
);
2148 shader_delete_constant_list(&shader
->constantsI
);
2149 list_remove(&shader
->shader_list_entry
);
2151 if (shader
->frontend
&& shader
->frontend_data
)
2152 shader
->frontend
->shader_free(shader
->frontend_data
);
2155 struct shader_none_priv
2157 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
2158 const struct fragment_pipeline
*fragment_pipe
;
2159 BOOL ffp_proj_control
;
2162 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
2163 static void shader_none_select_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
,
2164 enum wined3d_gl_resource_type tex_type
, const SIZE
*ds_mask_size
) {}
2165 static void shader_none_deselect_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
) {}
2166 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2167 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
2168 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
2169 const struct wined3d_state
*state
) {}
2170 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
2171 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
2172 static void shader_none_init_context_state(struct wined3d_context
*context
) {}
2174 /* Context activation is done by the caller. */
2175 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
2176 const struct wined3d_state
*state
)
2178 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2179 struct shader_none_priv
*priv
= shader_priv
;
2181 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
2182 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
2185 /* Context activation is done by the caller. */
2186 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
2188 struct shader_none_priv
*priv
= shader_priv
;
2189 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2191 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
2192 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
2194 context
->shader_update_mask
= (1u << WINED3D_SHADER_TYPE_PIXEL
)
2195 | (1u << WINED3D_SHADER_TYPE_VERTEX
)
2196 | (1u << WINED3D_SHADER_TYPE_GEOMETRY
);
2199 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
2200 const struct fragment_pipeline
*fragment_pipe
)
2202 struct fragment_caps fragment_caps
;
2203 void *vertex_priv
, *fragment_priv
;
2204 struct shader_none_priv
*priv
;
2206 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
2207 return E_OUTOFMEMORY
;
2209 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
2211 ERR("Failed to initialize vertex pipe.\n");
2212 HeapFree(GetProcessHeap(), 0, priv
);
2216 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
2218 ERR("Failed to initialize fragment pipe.\n");
2219 vertex_pipe
->vp_free(device
);
2220 HeapFree(GetProcessHeap(), 0, priv
);
2224 priv
->vertex_pipe
= vertex_pipe
;
2225 priv
->fragment_pipe
= fragment_pipe
;
2226 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
2227 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
2229 device
->vertex_priv
= vertex_priv
;
2230 device
->fragment_priv
= fragment_priv
;
2231 device
->shader_priv
= priv
;
2236 static void shader_none_free(struct wined3d_device
*device
)
2238 struct shader_none_priv
*priv
= device
->shader_priv
;
2240 priv
->fragment_pipe
->free_private(device
);
2241 priv
->vertex_pipe
->vp_free(device
);
2242 HeapFree(GetProcessHeap(), 0, priv
);
2245 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
2250 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
2252 /* Set the shader caps to 0 for the none shader backend */
2253 caps
->vs_version
= 0;
2254 caps
->gs_version
= 0;
2255 caps
->ps_version
= 0;
2256 caps
->vs_uniform_count
= 0;
2257 caps
->ps_uniform_count
= 0;
2258 caps
->ps_1x_max_value
= 0.0f
;
2259 caps
->varying_count
= 0;
2260 caps
->wined3d_caps
= 0;
2263 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2265 /* We "support" every possible fixup, since we don't support any shader
2266 * model, and will never have to actually sample a texture. */
2270 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2272 struct shader_none_priv
*priv
= shader_priv
;
2274 return priv
->ffp_proj_control
;
2277 const struct wined3d_shader_backend_ops none_shader_backend
=
2279 shader_none_handle_instruction
,
2281 shader_none_disable
,
2282 shader_none_select_depth_blt
,
2283 shader_none_deselect_depth_blt
,
2284 shader_none_update_float_vertex_constants
,
2285 shader_none_update_float_pixel_constants
,
2286 shader_none_load_constants
,
2287 shader_none_destroy
,
2290 shader_none_allocate_context_data
,
2291 shader_none_free_context_data
,
2292 shader_none_init_context_state
,
2293 shader_none_get_caps
,
2294 shader_none_color_fixup_supported
,
2295 shader_none_has_ffp_proj_control
,
2298 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
2299 const struct wined3d_shader_signature
*output_signature
, DWORD float_const_count
,
2300 enum wined3d_shader_type type
, unsigned int max_version
)
2302 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2303 const struct wined3d_shader_frontend
*fe
;
2305 unsigned int backend_version
;
2306 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2308 TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u, type %#x, max_version %u.\n",
2309 shader
, byte_code
, output_signature
, float_const_count
, type
, max_version
);
2311 list_init(&shader
->constantsF
);
2312 list_init(&shader
->constantsB
);
2313 list_init(&shader
->constantsI
);
2314 shader
->lconst_inf_or_nan
= FALSE
;
2316 fe
= shader_select_frontend(*byte_code
);
2319 FIXME("Unable to find frontend for shader.\n");
2320 return WINED3DERR_INVALIDCALL
;
2322 shader
->frontend
= fe
;
2323 shader
->frontend_data
= fe
->shader_init(byte_code
, output_signature
);
2324 if (!shader
->frontend_data
)
2326 FIXME("Failed to initialize frontend.\n");
2327 return WINED3DERR_INVALIDCALL
;
2330 /* First pass: trace shader. */
2331 if (TRACE_ON(d3d_shader
))
2332 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
2334 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2335 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2336 &shader
->output_signature
, byte_code
, float_const_count
)))
2339 if (reg_maps
->shader_version
.type
!= type
)
2341 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2342 return WINED3DERR_INVALIDCALL
;
2344 if (reg_maps
->shader_version
.major
> max_version
)
2346 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2347 return WINED3DERR_INVALIDCALL
;
2351 case WINED3D_SHADER_TYPE_VERTEX
:
2352 backend_version
= d3d_info
->limits
.vs_version
;
2354 case WINED3D_SHADER_TYPE_GEOMETRY
:
2355 backend_version
= d3d_info
->limits
.gs_version
;
2357 case WINED3D_SHADER_TYPE_PIXEL
:
2358 backend_version
= d3d_info
->limits
.ps_version
;
2361 FIXME("No backend version-checking for this shader type\n");
2362 backend_version
= 0;
2364 if (reg_maps
->shader_version
.major
> backend_version
)
2366 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2367 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2368 return WINED3DERR_INVALIDCALL
;
2371 shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
);
2372 if (!shader
->function
)
2373 return E_OUTOFMEMORY
;
2374 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2379 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2381 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2383 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2388 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2390 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2392 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2396 shader_cleanup(shader
);
2397 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2398 HeapFree(GetProcessHeap(), 0, shader
);
2404 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2406 TRACE("shader %p.\n", shader
);
2408 return shader
->parent
;
2411 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2412 void *byte_code
, UINT
*byte_code_size
)
2414 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2418 *byte_code_size
= shader
->functionLength
;
2422 if (*byte_code_size
< shader
->functionLength
)
2424 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2425 * than the required size we should write the required size and
2426 * return D3DERR_MOREDATA. That's not actually true. */
2427 return WINED3DERR_INVALIDCALL
;
2430 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2435 /* Set local constants for d3d8 shaders. */
2436 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2437 UINT start_idx
, const float *src_data
, UINT count
)
2439 UINT end_idx
= start_idx
+ count
;
2442 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2444 if (end_idx
> shader
->limits
->constant_float
)
2446 WARN("end_idx %u > float constants limit %u.\n",
2447 end_idx
, shader
->limits
->constant_float
);
2448 end_idx
= shader
->limits
->constant_float
;
2451 for (i
= start_idx
; i
< end_idx
; ++i
)
2453 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2456 return E_OUTOFMEMORY
;
2459 value
= (float *)lconst
->value
;
2460 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
2461 list_add_head(&shader
->constantsF
, &lconst
->entry
);
2463 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
2464 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
2466 shader
->lconst_inf_or_nan
= TRUE
;
2473 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2474 WORD swizzle_map
, struct vs_compile_args
*args
, const struct wined3d_d3d_info
*d3d_info
)
2476 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
2477 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
2478 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
2479 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
2480 args
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
2481 args
->per_vertex_point_size
= shader
->reg_maps
.point_size
;
2482 args
->swizzle_map
= swizzle_map
;
2483 if (d3d_info
->emulated_flatshading
)
2484 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
2486 args
->flatshading
= FALSE
;
2489 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
2491 if (usage_idx1
!= usage_idx2
)
2493 if (usage1
== usage2
)
2495 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
2497 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
2503 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
2504 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
2506 WORD map
= shader
->reg_maps
.input_registers
;
2509 for (i
= 0; map
; map
>>= 1, ++i
)
2511 if (!(map
& 1)) continue;
2513 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
2514 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
2523 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
2524 const struct wined3d_shader_signature
*src
, char **signature_strings
)
2526 struct wined3d_shader_signature_element
*e
;
2531 ptr
= *signature_strings
;
2533 dst
->element_count
= src
->element_count
;
2534 if (!(dst
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*dst
->elements
) * dst
->element_count
)))
2535 return E_OUTOFMEMORY
;
2537 for (i
= 0; i
< src
->element_count
; ++i
)
2539 e
= &src
->elements
[i
];
2540 dst
->elements
[i
] = *e
;
2542 len
= strlen(e
->semantic_name
);
2543 memcpy(ptr
, e
->semantic_name
, len
+ 1);
2544 dst
->elements
[i
].semantic_name
= ptr
;
2548 *signature_strings
= ptr
;
2553 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2554 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
2555 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2557 struct wined3d_shader_signature_element
*e
;
2563 if (!desc
->byte_code
)
2564 return WINED3DERR_INVALIDCALL
;
2567 shader
->device
= device
;
2568 shader
->parent
= parent
;
2569 shader
->parent_ops
= parent_ops
;
2572 if (desc
->input_signature
)
2574 for (i
= 0; i
< desc
->input_signature
->element_count
; ++i
)
2576 e
= &desc
->input_signature
->elements
[i
];
2577 len
= strlen(e
->semantic_name
);
2578 if (len
>= ~(SIZE_T
)0 - total
)
2579 return E_OUTOFMEMORY
;
2584 if (desc
->output_signature
)
2586 for (i
= 0; i
< desc
->output_signature
->element_count
; ++i
)
2588 e
= &desc
->output_signature
->elements
[i
];
2589 len
= strlen(e
->semantic_name
);
2590 if (len
>= ~(SIZE_T
)0 - total
)
2591 return E_OUTOFMEMORY
;
2596 if (!(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
2597 return E_OUTOFMEMORY
;
2598 ptr
= shader
->signature_strings
;
2600 if (desc
->input_signature
&& FAILED(hr
= shader_signature_copy(&shader
->input_signature
,
2601 desc
->input_signature
, &ptr
)))
2603 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2606 if (desc
->output_signature
&& FAILED(hr
= shader_signature_copy(&shader
->output_signature
,
2607 desc
->output_signature
, &ptr
)))
2609 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2610 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2614 list_init(&shader
->linked_programs
);
2615 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
2617 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
, desc
->output_signature
,
2618 float_const_count
, type
, desc
->max_version
)))
2620 WARN("Failed to set function, hr %#x.\n", hr
);
2621 shader_cleanup(shader
);
2627 static HRESULT
vertexshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2628 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2630 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2634 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
2635 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
2638 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
2640 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
2642 if (!(reg_maps
->input_registers
& (1u << input
->register_idx
)) || !input
->semantic_name
)
2645 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
2646 shader_usage_from_semantic_name(input
->semantic_name
);
2647 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
2650 shader
->load_local_constsF
= (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
)) ||
2651 shader
->lconst_inf_or_nan
;
2656 static HRESULT
geometryshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2657 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2661 if (FAILED(hr
= shader_init(shader
, device
, desc
, 0,
2662 WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
)))
2665 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2670 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2671 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_context
*context
)
2673 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
2674 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
2675 const struct wined3d_texture
*texture
;
2678 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
2679 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
))
2681 static unsigned int warned
= 0;
2683 args
->srgb_correction
= 1;
2684 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
2685 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
2686 "support, expect rendering artifacts.\n");
2689 if (shader
->reg_maps
.shader_version
.major
== 1
2690 && shader
->reg_maps
.shader_version
.minor
<= 3)
2692 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2694 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
2696 if (flags
& WINED3D_TTFF_PROJECTED
)
2698 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
2700 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
2702 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
2704 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
2705 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
2707 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
2709 struct wined3d_vertex_declaration_element
*element
=
2710 &state
->vertex_declaration
->elements
[j
];
2712 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
2713 && element
->usage_idx
== index
)
2715 max_valid
= element
->format
->component_count
;
2719 if (!tex_transform
|| tex_transform
> max_valid
)
2721 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
2722 tex_transform
, max_valid
);
2723 tex_transform
= max_valid
;
2725 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
2726 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
2727 && tex_transform
> WINED3D_TTFF_COUNT2
)
2728 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
2729 && tex_transform
> WINED3D_TTFF_COUNT3
))
2730 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
2733 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
2734 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
2735 i
, tex_transform
, resource_type
);
2739 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
2741 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
2745 if (shader
->reg_maps
.shader_version
.major
== 1
2746 && shader
->reg_maps
.shader_version
.minor
<= 4)
2748 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2750 const struct wined3d_texture
*texture
= state
->textures
[i
];
2752 if (!shader
->reg_maps
.resource_info
[i
].type
)
2755 /* Treat unbound textures as 2D. The dummy texture will provide
2756 * the proper sample value. The tex_types bitmap defaults to
2757 * 2D because of the memset. */
2761 switch (texture
->target
)
2763 /* RECT textures are distinguished from 2D textures via np2_fixup */
2764 case GL_TEXTURE_RECTANGLE_ARB
:
2769 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2772 case GL_TEXTURE_CUBE_MAP_ARB
:
2773 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2779 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
2781 if (!shader
->reg_maps
.resource_info
[i
].type
)
2784 texture
= state
->textures
[i
];
2787 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
2790 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
2791 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
2793 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
2795 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
2796 args
->shadow
|= 1u << i
;
2798 /* Flag samplers that need NP2 texcoord fixup. */
2799 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
2800 args
->np2_fixup
|= (1u << i
);
2803 /* In SM4+ we use dcl_sampler in order to determine if we should use shadow sampler. */
2804 if (shader
->reg_maps
.shader_version
.major
>= 4)
2807 if (shader
->reg_maps
.shader_version
.major
>= 3)
2809 if (position_transformed
)
2810 args
->vp_mode
= pretransformed
;
2811 else if (use_vs(state
))
2812 args
->vp_mode
= vertexshader
;
2814 args
->vp_mode
= fixedfunction
;
2815 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2819 args
->vp_mode
= vertexshader
;
2820 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
2822 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
2824 case WINED3D_FOG_NONE
:
2825 if (position_transformed
|| use_vs(state
))
2827 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
2831 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
2833 case WINED3D_FOG_NONE
: /* Fall through. */
2834 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2835 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2836 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2840 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2841 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2842 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2847 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2851 if (context
->d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(context
->gl_info
))
2853 const struct wined3d_shader
*vs
= state
->shader
[WINED3D_SHADER_TYPE_VERTEX
];
2855 args
->texcoords_initialized
= 0;
2856 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
2860 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
2861 args
->texcoords_initialized
|= 1u << i
;
2865 const struct wined3d_stream_info
*si
= &context
->stream_info
;
2866 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
2868 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
2869 & WINED3D_FFP_TCI_MASK
2870 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
2871 args
->texcoords_initialized
|= 1u << i
;
2877 args
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
2880 args
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
2881 && state
->gl_primitive_type
== GL_POINTS
;
2883 if (d3d_info
->emulated_flatshading
)
2884 args
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
2887 static HRESULT
pixelshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2888 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2890 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
2891 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
2894 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
2895 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
2898 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2900 if (shader
->u
.ps
.input_reg_used
[i
])
2903 highest_reg_used
= i
;
2907 /* Don't do any register mapping magic if it is not needed, or if we can't
2908 * achieve anything anyway */
2909 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
2910 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2912 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2914 /* This happens with relative addressing. The input mapper function
2915 * warns about this if the higher registers are declared too, so
2916 * don't write a FIXME here */
2917 WARN("More varying registers used than supported\n");
2920 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2922 shader
->u
.ps
.input_reg_map
[i
] = i
;
2925 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
2929 shader
->u
.ps
.declared_in_count
= 0;
2930 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2932 if (shader
->u
.ps
.input_reg_used
[i
])
2933 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
2934 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
2938 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2943 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
2945 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2946 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
2949 if (reg_maps
->shader_version
.major
!= 1) return;
2951 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2953 /* We don't sample from this sampler. */
2954 if (!resource_info
[i
].type
)
2957 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
2959 case WINED3D_SHADER_TEX_2D
:
2960 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
2963 case WINED3D_SHADER_TEX_3D
:
2964 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
2967 case WINED3D_SHADER_TEX_CUBE
:
2968 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
2974 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2975 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2977 struct wined3d_shader
*object
;
2980 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2981 device
, desc
, parent
, parent_ops
, shader
);
2983 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2985 return E_OUTOFMEMORY
;
2987 if (FAILED(hr
= geometryshader_init(object
, device
, desc
, parent
, parent_ops
)))
2989 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
2990 HeapFree(GetProcessHeap(), 0, object
);
2994 TRACE("Created geometry shader %p.\n", object
);
3000 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3001 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3003 struct wined3d_shader
*object
;
3006 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3007 device
, desc
, parent
, parent_ops
, shader
);
3009 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3011 return E_OUTOFMEMORY
;
3013 if (FAILED(hr
= pixelshader_init(object
, device
, desc
, parent
, parent_ops
)))
3015 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3016 HeapFree(GetProcessHeap(), 0, object
);
3020 TRACE("Created pixel shader %p.\n", object
);
3026 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
3027 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
3029 struct wined3d_shader
*object
;
3032 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
3033 device
, desc
, parent
, parent_ops
, shader
);
3035 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3037 return E_OUTOFMEMORY
;
3039 if (FAILED(hr
= vertexshader_init(object
, device
, desc
, parent
, parent_ops
)))
3041 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3042 HeapFree(GetProcessHeap(), 0, object
);
3046 TRACE("Created vertex shader %p.\n", object
);