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_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
59 /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
60 /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
61 /* WINED3DSIH_DEF */ "def",
62 /* WINED3DSIH_DEFB */ "defb",
63 /* WINED3DSIH_DEFI */ "defi",
64 /* WINED3DSIH_DIV */ "div",
65 /* WINED3DSIH_DP2 */ "dp2",
66 /* WINED3DSIH_DP2ADD */ "dp2add",
67 /* WINED3DSIH_DP3 */ "dp3",
68 /* WINED3DSIH_DP4 */ "dp4",
69 /* WINED3DSIH_DST */ "dst",
70 /* WINED3DSIH_DSX */ "dsx",
71 /* WINED3DSIH_DSY */ "dsy",
72 /* WINED3DSIH_ELSE */ "else",
73 /* WINED3DSIH_EMIT */ "emit",
74 /* WINED3DSIH_ENDIF */ "endif",
75 /* WINED3DSIH_ENDLOOP */ "endloop",
76 /* WINED3DSIH_ENDREP */ "endrep",
77 /* WINED3DSIH_EQ */ "eq",
78 /* WINED3DSIH_EXP */ "exp",
79 /* WINED3DSIH_EXPP */ "expp",
80 /* WINED3DSIH_FRC */ "frc",
81 /* WINED3DSIH_FTOI */ "ftoi",
82 /* WINED3DSIH_GE */ "ge",
83 /* WINED3DSIH_IADD */ "iadd",
84 /* WINED3DSIH_IEQ */ "ieq",
85 /* WINED3DSIH_IF */ "if",
86 /* WINED3DSIH_IFC */ "ifc",
87 /* WINED3DSIH_IGE */ "ige",
88 /* WINED3DSIH_IMUL */ "imul",
89 /* WINED3DSIH_ISHL */ "ishl",
90 /* WINED3DSIH_ITOF */ "itof",
91 /* WINED3DSIH_LABEL */ "label",
92 /* WINED3DSIH_LD */ "ld",
93 /* WINED3DSIH_LIT */ "lit",
94 /* WINED3DSIH_LOG */ "log",
95 /* WINED3DSIH_LOGP */ "logp",
96 /* WINED3DSIH_LOOP */ "loop",
97 /* WINED3DSIH_LRP */ "lrp",
98 /* WINED3DSIH_LT */ "lt",
99 /* WINED3DSIH_M3x2 */ "m3x2",
100 /* WINED3DSIH_M3x3 */ "m3x3",
101 /* WINED3DSIH_M3x4 */ "m3x4",
102 /* WINED3DSIH_M4x3 */ "m4x3",
103 /* WINED3DSIH_M4x4 */ "m4x4",
104 /* WINED3DSIH_MAD */ "mad",
105 /* WINED3DSIH_MAX */ "max",
106 /* WINED3DSIH_MIN */ "min",
107 /* WINED3DSIH_MOV */ "mov",
108 /* WINED3DSIH_MOVA */ "mova",
109 /* WINED3DSIH_MOVC */ "movc",
110 /* WINED3DSIH_MUL */ "mul",
111 /* WINED3DSIH_NE */ "ne",
112 /* WINED3DSIH_NOP */ "nop",
113 /* WINED3DSIH_NRM */ "nrm",
114 /* WINED3DSIH_OR */ "or",
115 /* WINED3DSIH_PHASE */ "phase",
116 /* WINED3DSIH_POW */ "pow",
117 /* WINED3DSIH_RCP */ "rcp",
118 /* WINED3DSIH_REP */ "rep",
119 /* WINED3DSIH_RET */ "ret",
120 /* WINED3DSIH_ROUND_NI */ "round_ni",
121 /* WINED3DSIH_RSQ */ "rsq",
122 /* WINED3DSIH_SAMPLE */ "sample",
123 /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
124 /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
125 /* WINED3DSIH_SETP */ "setp",
126 /* WINED3DSIH_SGE */ "sge",
127 /* WINED3DSIH_SGN */ "sgn",
128 /* WINED3DSIH_SINCOS */ "sincos",
129 /* WINED3DSIH_SLT */ "slt",
130 /* WINED3DSIH_SQRT */ "sqrt",
131 /* WINED3DSIH_SUB */ "sub",
132 /* WINED3DSIH_TEX */ "texld",
133 /* WINED3DSIH_TEXBEM */ "texbem",
134 /* WINED3DSIH_TEXBEML */ "texbeml",
135 /* WINED3DSIH_TEXCOORD */ "texcrd",
136 /* WINED3DSIH_TEXDEPTH */ "texdepth",
137 /* WINED3DSIH_TEXDP3 */ "texdp3",
138 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
139 /* WINED3DSIH_TEXKILL */ "texkill",
140 /* WINED3DSIH_TEXLDD */ "texldd",
141 /* WINED3DSIH_TEXLDL */ "texldl",
142 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
143 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
144 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
145 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
146 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
147 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
148 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
149 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
150 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
151 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
152 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
153 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
154 /* WINED3DSIH_UDIV */ "udiv",
155 /* WINED3DSIH_UGE */ "uge",
156 /* WINED3DSIH_USHR */ "ushr",
157 /* WINED3DSIH_UTOF */ "utof",
158 /* WINED3DSIH_XOR */ "xor",
161 static const char * const semantic_names
[] =
163 /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
164 /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
165 /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
166 /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
167 /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
168 /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
169 /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
170 /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
171 /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
172 /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
173 /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
174 /* WINED3D_DECL_USAGE_FOG */ "FOG",
175 /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
176 /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
179 static const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage
)
181 if (usage
>= sizeof(semantic_names
) / sizeof(*semantic_names
))
183 FIXME("Unrecognized usage %#x.\n", usage
);
184 return "UNRECOGNIZED";
187 return semantic_names
[usage
];
190 static enum wined3d_decl_usage
shader_usage_from_semantic_name(const char *name
)
194 for (i
= 0; i
< sizeof(semantic_names
) / sizeof(*semantic_names
); ++i
)
196 if (!strcmp(name
, semantic_names
[i
])) return i
;
202 BOOL
shader_match_semantic(const char *semantic_name
, enum wined3d_decl_usage usage
)
204 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
207 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
208 const struct wined3d_shader_semantic
*s
)
210 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
211 e
->semantic_idx
= s
->usage_idx
;
212 e
->sysval_semantic
= 0;
213 e
->component_type
= 0;
214 e
->register_idx
= s
->reg
.reg
.idx
[0].offset
;
215 e
->mask
= s
->reg
.write_mask
;
218 static void shader_signature_from_usage(struct wined3d_shader_signature_element
*e
,
219 enum wined3d_decl_usage usage
, UINT usage_idx
, UINT reg_idx
, DWORD write_mask
)
221 e
->semantic_name
= shader_semantic_name_from_usage(usage
);
222 e
->semantic_idx
= usage_idx
;
223 e
->sysval_semantic
= 0;
224 e
->component_type
= 0;
225 e
->register_idx
= reg_idx
;
226 e
->mask
= write_mask
;
229 static const struct wined3d_shader_frontend
*shader_select_frontend(DWORD version_token
)
231 switch (version_token
>> 16)
235 return &sm1_shader_frontend
;
240 return &sm4_shader_frontend
;
243 FIXME("Unrecognised version token %#x\n", version_token
);
248 void shader_buffer_clear(struct wined3d_shader_buffer
*buffer
)
250 buffer
->buffer
[0] = '\0';
251 buffer
->content_size
= 0;
253 buffer
->newline
= TRUE
;
256 BOOL
shader_buffer_init(struct wined3d_shader_buffer
*buffer
)
258 buffer
->buffer_size
= 16384;
259 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
261 ERR("Failed to allocate shader buffer memory.\n");
265 shader_buffer_clear(buffer
);
269 void shader_buffer_free(struct wined3d_shader_buffer
*buffer
)
271 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
274 int shader_vaddline(struct wined3d_shader_buffer
*buffer
, const char *format
, va_list args
)
276 char *base
= buffer
->buffer
+ buffer
->content_size
;
282 rc
= vsnprintf(base
, buffer
->buffer_size
- buffer
->content_size
, format
, args
);
283 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= buffer
->buffer_size
- buffer
->content_size
/* C99 */)
285 new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, buffer
->buffer_size
* 2);
288 ERR("The buffer allocated for the shader program string is too small at %d bytes.\n", buffer
->buffer_size
);
289 buffer
->content_size
= buffer
->buffer_size
- 1;
292 buffer
->buffer
= new_buffer
;
293 buffer
->buffer_size
= buffer
->buffer_size
* 2;
294 base
= buffer
->buffer
+ buffer
->content_size
;
304 TRACE("GL HW (%u, %u) : %s", buffer
->lineNo
+ 1, buffer
->content_size
, base
);
305 buffer
->newline
= FALSE
;
312 buffer
->content_size
+= rc
;
313 if (buffer
->buffer
[buffer
->content_size
-1] == '\n')
316 buffer
->newline
= TRUE
;
322 int shader_addline(struct wined3d_shader_buffer
*buffer
, const char *format
, ...)
327 va_start(args
, format
);
328 ret
= shader_vaddline(buffer
, format
, args
);
334 static void shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
335 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
338 shader
->device
= device
;
339 shader
->parent
= parent
;
340 shader
->parent_ops
= parent_ops
;
341 list_init(&shader
->linked_programs
);
342 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
345 /* Convert floating point offset relative to a register file to an absolute
346 * offset for float constants. */
347 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
349 switch (register_type
)
351 case WINED3DSPR_CONST
: return register_idx
;
352 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
353 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
354 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
356 FIXME("Unsupported register type: %u.\n", register_type
);
361 static void shader_delete_constant_list(struct list
*clist
)
363 struct wined3d_shader_lconst
*constant
;
366 ptr
= list_head(clist
);
369 constant
= LIST_ENTRY(ptr
, struct wined3d_shader_lconst
, entry
);
370 ptr
= list_next(clist
, ptr
);
371 HeapFree(GetProcessHeap(), 0, constant
);
376 static void shader_set_limits(struct wined3d_shader
*shader
)
378 static const struct limits_entry
380 unsigned int min_version
;
381 unsigned int max_version
;
382 struct wined3d_shader_limits limits
;
386 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
387 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
388 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
389 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
390 * even though they are capable of supporting much more (GL
391 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
392 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
394 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
395 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
400 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
401 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
406 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
407 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
408 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
409 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
410 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
411 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 12}},
412 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 0, 32}},
415 const struct limits_entry
*limits_array
;
416 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
417 shader
->reg_maps
.shader_version
.minor
);
420 switch (shader
->reg_maps
.shader_version
.type
)
423 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
425 case WINED3D_SHADER_TYPE_VERTEX
:
426 limits_array
= vs_limits
;
428 case WINED3D_SHADER_TYPE_GEOMETRY
:
429 limits_array
= gs_limits
;
431 case WINED3D_SHADER_TYPE_PIXEL
:
432 limits_array
= ps_limits
;
436 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
438 if (shader_version
<= limits_array
[i
].max_version
)
440 shader
->limits
= &limits_array
[i
].limits
;
447 FIXME("Unexpected shader version \"%u.%u\".\n",
448 shader
->reg_maps
.shader_version
.major
,
449 shader
->reg_maps
.shader_version
.minor
);
450 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
454 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
459 bitmap
[idx
] |= (1 << shift
);
462 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
463 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
467 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
468 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
469 reg_maps
->texcoord
|= 1 << reg
->idx
[0].offset
;
471 reg_maps
->address
|= 1 << reg
->idx
[0].offset
;
474 case WINED3DSPR_TEMP
:
475 reg_maps
->temporary
|= 1 << reg
->idx
[0].offset
;
478 case WINED3DSPR_INPUT
:
479 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
481 if (reg
->idx
[0].rel_addr
)
483 /* If relative addressing is used, we must assume that all registers
484 * are used. Even if it is a construct like v3[aL], we can't assume
485 * that v0, v1 and v2 aren't read because aL can be negative */
487 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
489 shader
->u
.ps
.input_reg_used
[i
] = TRUE
;
494 shader
->u
.ps
.input_reg_used
[reg
->idx
[0].offset
] = TRUE
;
498 reg_maps
->input_registers
|= 1 << reg
->idx
[0].offset
;
501 case WINED3DSPR_RASTOUT
:
502 if (reg
->idx
[0].offset
== 1)
506 case WINED3DSPR_MISCTYPE
:
507 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
509 if (!reg
->idx
[0].offset
)
511 else if (reg
->idx
[0].offset
== 1)
512 reg_maps
->usesfacing
= 1;
516 case WINED3DSPR_CONST
:
517 if (reg
->idx
[0].rel_addr
)
519 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
520 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
521 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
522 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
523 reg_maps
->usesrelconstF
= TRUE
;
527 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
529 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
534 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
539 case WINED3DSPR_CONSTINT
:
540 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
542 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
547 reg_maps
->integer_constants
|= (1 << reg
->idx
[0].offset
);
551 case WINED3DSPR_CONSTBOOL
:
552 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
554 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
559 reg_maps
->boolean_constants
|= (1 << reg
->idx
[0].offset
);
563 case WINED3DSPR_COLOROUT
:
564 reg_maps
->rt_mask
|= (1 << reg
->idx
[0].offset
);
568 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
569 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
575 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
576 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
578 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
579 struct wined3d_shader_sampler_map
*map
;
582 map
= ®_maps
->sampler_map
;
583 entries
= map
->entries
;
584 for (i
= 0; i
< map
->count
; ++i
)
586 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
592 if (!(entries
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entries
) * 4)))
594 ERR("Failed to allocate sampler map entries.\n");
598 map
->entries
= entries
;
600 else if (map
->count
== map
->size
)
602 size_t new_size
= map
->size
* 2;
604 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
605 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
607 ERR("Failed to resize sampler map entries.\n");
610 map
->size
= new_size
;
611 map
->entries
= entries
;
614 entry
= &entries
[map
->count
++];
615 entry
->resource_idx
= resource_idx
;
616 entry
->sampler_idx
= sampler_idx
;
617 entry
->bind_idx
= bind_idx
;
620 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
624 case WINED3DSIH_M4x4
:
625 case WINED3DSIH_M3x4
:
626 return param
== 1 ? 3 : 0;
628 case WINED3DSIH_M4x3
:
629 case WINED3DSIH_M3x3
:
630 return param
== 1 ? 2 : 0;
632 case WINED3DSIH_M3x2
:
633 return param
== 1 ? 1 : 0;
640 /* Note that this does not count the loop register as an address register. */
641 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
642 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature_element
*input_signature
,
643 struct wined3d_shader_signature_element
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
645 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
646 void *fe_data
= shader
->frontend_data
;
647 struct wined3d_shader_version shader_version
;
648 const DWORD
*ptr
= byte_code
;
650 memset(reg_maps
, 0, sizeof(*reg_maps
));
651 reg_maps
->min_rel_offset
= ~0U;
653 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
654 reg_maps
->shader_version
= shader_version
;
656 shader_set_limits(shader
);
658 reg_maps
->constf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
659 sizeof(*reg_maps
->constf
) * ((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32));
660 if (!reg_maps
->constf
)
662 ERR("Failed to allocate constant map memory.\n");
663 return E_OUTOFMEMORY
;
666 while (!fe
->shader_is_end(fe_data
, &ptr
))
668 struct wined3d_shader_instruction ins
;
671 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
673 /* Unhandled opcode, and its parameters. */
674 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
676 TRACE("Skipping unrecognized instruction.\n");
680 /* Handle declarations. */
681 if (ins
.handler_idx
== WINED3DSIH_DCL
)
683 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
684 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
686 switch (semantic
->reg
.reg
.type
)
688 /* Mark input registers used. */
689 case WINED3DSPR_INPUT
:
690 if (reg_idx
>= MAX_REG_INPUT
)
692 ERR("Invalid input register index %u.\n", reg_idx
);
695 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
696 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
697 return WINED3DERR_INVALIDCALL
;
698 reg_maps
->input_registers
|= 1 << reg_idx
;
699 shader_signature_from_semantic(&input_signature
[reg_idx
], semantic
);
702 /* Vertex shader: mark 3.0 output registers used, save token. */
703 case WINED3DSPR_OUTPUT
:
704 if (reg_idx
>= MAX_REG_OUTPUT
)
706 ERR("Invalid output register index %u.\n", reg_idx
);
709 reg_maps
->output_registers
|= 1 << reg_idx
;
710 shader_signature_from_semantic(&output_signature
[reg_idx
], semantic
);
711 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
715 case WINED3DSPR_SAMPLER
:
716 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
717 case WINED3DSPR_RESOURCE
:
718 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
720 ERR("Invalid resource index %u.\n", reg_idx
);
723 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
724 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
728 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
732 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
734 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
735 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
736 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
738 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
740 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
742 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
743 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
745 FIXME("Invalid instruction %#x for shader type %#x.\n",
746 ins
.handler_idx
, shader_version
.type
);
748 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
750 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
751 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
753 FIXME("Invalid instruction %#x for shader type %#x.\n",
754 ins
.handler_idx
, shader_version
.type
);
756 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
758 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
759 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
761 FIXME("Invalid instruction %#x for shader type %#x.\n",
762 ins
.handler_idx
, shader_version
.type
);
764 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
766 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
768 if (!lconst
) return E_OUTOFMEMORY
;
770 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
771 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
772 value
= (float *)lconst
->value
;
774 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
775 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
777 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
778 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
779 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
780 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
781 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
782 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
783 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
784 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
787 list_add_head(&shader
->constantsF
, &lconst
->entry
);
789 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
790 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
792 shader
->lconst_inf_or_nan
= TRUE
;
795 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
797 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
798 if (!lconst
) return E_OUTOFMEMORY
;
800 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
801 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
803 list_add_head(&shader
->constantsI
, &lconst
->entry
);
804 reg_maps
->local_int_consts
|= (1 << lconst
->idx
);
806 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
808 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
809 if (!lconst
) return E_OUTOFMEMORY
;
811 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
812 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, sizeof(DWORD
));
814 list_add_head(&shader
->constantsB
, &lconst
->entry
);
815 reg_maps
->local_bool_consts
|= (1 << lconst
->idx
);
817 /* For subroutine prototypes. */
818 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
820 reg_maps
->labels
|= 1 << ins
.src
[0].reg
.idx
[0].offset
;
822 /* Set texture, address, temporary registers. */
825 BOOL color0_mov
= FALSE
;
828 /* This will loop over all the registers and try to
829 * make a bitmask of the ones we're interested in.
831 * Relative addressing tokens are ignored, but that's
832 * okay, since we'll catch any address registers when
833 * they are initialized (required by spec). */
834 for (i
= 0; i
< ins
.dst_count
; ++i
)
836 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
837 shader_version
.type
, constf_size
))
838 return WINED3DERR_INVALIDCALL
;
840 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
841 * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
842 * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
843 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
&& shader_version
.major
< 3)
845 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
847 switch (ins
.dst
[i
].reg
.type
)
849 case WINED3DSPR_RASTOUT
:
853 reg_maps
->output_registers
|= 1 << 10;
854 shader_signature_from_usage(&output_signature
[10],
855 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
859 reg_maps
->output_registers
|= 1 << 11;
860 shader_signature_from_usage(&output_signature
[11],
861 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
865 reg_maps
->output_registers
|= 1 << 11;
866 shader_signature_from_usage(&output_signature
[11],
867 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
872 case WINED3DSPR_ATTROUT
:
876 if (reg_maps
->output_registers
& (1 << idx
))
878 output_signature
[idx
].mask
|= ins
.dst
[i
].write_mask
;
882 reg_maps
->output_registers
|= 1 << idx
;
883 shader_signature_from_usage(&output_signature
[idx
],
884 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
889 case WINED3DSPR_TEXCRDOUT
:
891 reg_maps
->texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
892 if (reg_maps
->output_registers
& (1 << idx
))
894 output_signature
[idx
].mask
|= ins
.dst
[i
].write_mask
;
898 reg_maps
->output_registers
|= 1 << idx
;
899 shader_signature_from_usage(&output_signature
[idx
],
900 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
909 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
911 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
913 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
914 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
915 * the mov and perform the sRGB write correction from the source register.
917 * However, if the mov is only partial, we can't do this, and if the write
918 * comes from an instruction other than MOV it is hard to do as well. If
919 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
920 shader
->u
.ps
.color0_mov
= FALSE
;
921 if (ins
.handler_idx
== WINED3DSIH_MOV
922 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
924 /* Used later when the source register is read. */
928 /* Also drop the MOV marker if the source register is overwritten prior to the shader
931 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
932 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
934 shader
->u
.ps
.color0_mov
= FALSE
;
938 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
939 if (shader_version
.major
== 1
940 && (ins
.handler_idx
== WINED3DSIH_TEX
941 || ins
.handler_idx
== WINED3DSIH_TEXBEM
942 || ins
.handler_idx
== WINED3DSIH_TEXBEML
943 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
944 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
945 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
946 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
947 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
948 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
949 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
950 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
952 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
954 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
955 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
956 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
957 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
959 /* texbem is only valid with < 1.4 pixel shaders */
960 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
961 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
963 reg_maps
->bumpmat
|= 1 << reg_idx
;
964 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
966 reg_maps
->luminanceparams
|= 1 << reg_idx
;
970 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
972 reg_maps
->bumpmat
|= 1 << ins
.dst
[i
].reg
.idx
[0].offset
;
976 if (ins
.handler_idx
== WINED3DSIH_NRM
) reg_maps
->usesnrm
= 1;
977 else if (ins
.handler_idx
== WINED3DSIH_DSY
) reg_maps
->usesdsy
= 1;
978 else if (ins
.handler_idx
== WINED3DSIH_DSX
) reg_maps
->usesdsx
= 1;
979 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
980 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
981 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
982 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
983 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
984 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
985 else if (ins
.handler_idx
== WINED3DSIH_LOOP
986 || ins
.handler_idx
== WINED3DSIH_REP
)
989 if (cur_loop_depth
> max_loop_depth
)
990 max_loop_depth
= cur_loop_depth
;
992 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
993 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
997 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
998 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
999 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1001 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1002 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1006 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1007 shader_version
.type
, constf_size
))
1008 return WINED3DERR_INVALIDCALL
;
1010 for (i
= 0; i
< ins
.src_count
; ++i
)
1012 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1013 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1015 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1016 shader_version
.type
, constf_size
))
1017 return WINED3DERR_INVALIDCALL
;
1020 ++reg
.idx
[0].offset
;
1021 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1022 shader_version
.type
, constf_size
))
1023 return WINED3DERR_INVALIDCALL
;
1029 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1030 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1032 shader
->u
.ps
.color0_mov
= TRUE
;
1033 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1039 reg_maps
->loop_depth
= max_loop_depth
;
1041 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1042 * R0 is written to the render target. */
1043 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1044 reg_maps
->rt_mask
|= (1 << 0);
1046 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1051 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1053 DWORD map
= 1 << max
;
1055 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1057 return wined3d_log2i(map
);
1060 static void shader_dump_decl_usage(const struct wined3d_shader_semantic
*semantic
,
1061 const struct wined3d_shader_version
*shader_version
)
1065 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1067 switch (semantic
->resource_type
)
1069 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1073 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1077 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1082 TRACE("_unknown_ttype(0x%08x)", semantic
->resource_type
);
1086 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1088 TRACE("_resource_");
1089 switch (semantic
->resource_type
)
1091 case WINED3D_SHADER_RESOURCE_BUFFER
:
1095 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1099 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1103 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1104 TRACE("texture2dms");
1107 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1111 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1112 TRACE("texturecube");
1115 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1116 TRACE("texture1darray");
1119 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1120 TRACE("texture2darray");
1123 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1124 TRACE("texture2dmsarray");
1131 switch (semantic
->resource_data_type
)
1133 case WINED3D_DATA_FLOAT
:
1137 case WINED3D_DATA_INT
:
1141 case WINED3D_DATA_UINT
:
1145 case WINED3D_DATA_UNORM
:
1149 case WINED3D_DATA_SNORM
:
1154 TRACE(" (unknown)");
1160 /* Pixel shaders 3.0 don't have usage semantics. */
1161 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
) return;
1164 switch (semantic
->usage
)
1166 case WINED3D_DECL_USAGE_POSITION
:
1167 TRACE("position%u", semantic
->usage_idx
);
1170 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1174 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1178 case WINED3D_DECL_USAGE_NORMAL
:
1179 TRACE("normal%u", semantic
->usage_idx
);
1182 case WINED3D_DECL_USAGE_PSIZE
:
1186 case WINED3D_DECL_USAGE_COLOR
:
1187 if (!semantic
->usage_idx
) TRACE("color");
1188 else TRACE("specular%u", (semantic
->usage_idx
- 1));
1191 case WINED3D_DECL_USAGE_TEXCOORD
:
1192 TRACE("texture%u", semantic
->usage_idx
);
1195 case WINED3D_DECL_USAGE_TANGENT
:
1199 case WINED3D_DECL_USAGE_BINORMAL
:
1203 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1204 TRACE("tessfactor");
1207 case WINED3D_DECL_USAGE_POSITIONT
:
1208 TRACE("positionT%u", semantic
->usage_idx
);
1211 case WINED3D_DECL_USAGE_FOG
:
1215 case WINED3D_DECL_USAGE_DEPTH
:
1219 case WINED3D_DECL_USAGE_SAMPLE
:
1224 FIXME("unknown_semantics(0x%08x)", semantic
->usage
);
1229 static void shader_dump_register(const struct wined3d_shader_register
*reg
,
1230 const struct wined3d_shader_version
*shader_version
)
1232 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1233 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1234 UINT offset
= reg
->idx
[0].offset
;
1238 case WINED3DSPR_TEMP
:
1242 case WINED3DSPR_INPUT
:
1246 case WINED3DSPR_CONST
:
1247 case WINED3DSPR_CONST2
:
1248 case WINED3DSPR_CONST3
:
1249 case WINED3DSPR_CONST4
:
1251 offset
= shader_get_float_offset(reg
->type
, offset
);
1254 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1255 TRACE("%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1258 case WINED3DSPR_RASTOUT
:
1259 TRACE("%s", rastout_reg_names
[offset
]);
1262 case WINED3DSPR_COLOROUT
:
1266 case WINED3DSPR_DEPTHOUT
:
1270 case WINED3DSPR_ATTROUT
:
1274 case WINED3DSPR_TEXCRDOUT
:
1275 /* Vertex shaders >= 3.0 use general purpose output registers
1276 * (WINED3DSPR_OUTPUT), which can include an address token. */
1277 if (shader_version
->major
>= 3) TRACE("o");
1281 case WINED3DSPR_CONSTINT
:
1285 case WINED3DSPR_CONSTBOOL
:
1289 case WINED3DSPR_LABEL
:
1293 case WINED3DSPR_LOOP
:
1297 case WINED3DSPR_SAMPLER
:
1301 case WINED3DSPR_MISCTYPE
:
1303 FIXME("Unhandled misctype register %u.\n", offset
);
1305 TRACE("%s", misctype_reg_names
[offset
]);
1308 case WINED3DSPR_PREDICATE
:
1312 case WINED3DSPR_IMMCONST
:
1316 case WINED3DSPR_CONSTBUFFER
:
1320 case WINED3DSPR_PRIMID
:
1324 case WINED3DSPR_NULL
:
1328 case WINED3DSPR_RESOURCE
:
1333 TRACE("unhandled_rtype(%#x)", reg
->type
);
1337 if (reg
->type
== WINED3DSPR_IMMCONST
)
1340 switch (reg
->immconst_type
)
1342 case WINED3D_IMMCONST_SCALAR
:
1343 switch (reg
->data_type
)
1345 case WINED3D_DATA_FLOAT
:
1346 TRACE("%.8e", *(const float *)reg
->immconst_data
);
1348 case WINED3D_DATA_INT
:
1349 TRACE("%d", reg
->immconst_data
[0]);
1351 case WINED3D_DATA_RESOURCE
:
1352 case WINED3D_DATA_SAMPLER
:
1353 case WINED3D_DATA_UINT
:
1354 TRACE("%u", reg
->immconst_data
[0]);
1357 TRACE("<unhandled data type %#x>", reg
->data_type
);
1362 case WINED3D_IMMCONST_VEC4
:
1363 switch (reg
->data_type
)
1365 case WINED3D_DATA_FLOAT
:
1366 TRACE("%.8e, %.8e, %.8e, %.8e",
1367 *(const float *)®
->immconst_data
[0], *(const float *)®
->immconst_data
[1],
1368 *(const float *)®
->immconst_data
[2], *(const float *)®
->immconst_data
[3]);
1370 case WINED3D_DATA_INT
:
1371 TRACE("%d, %d, %d, %d",
1372 reg
->immconst_data
[0], reg
->immconst_data
[1],
1373 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1375 case WINED3D_DATA_RESOURCE
:
1376 case WINED3D_DATA_SAMPLER
:
1377 case WINED3D_DATA_UINT
:
1378 TRACE("%u, %u, %u, %u",
1379 reg
->immconst_data
[0], reg
->immconst_data
[1],
1380 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1383 TRACE("<unhandled data type %#x>", reg
->data_type
);
1389 TRACE("<unhandled immconst_type %#x>", reg
->immconst_type
);
1394 else if (reg
->type
!= WINED3DSPR_RASTOUT
1395 && reg
->type
!= WINED3DSPR_MISCTYPE
1396 && reg
->type
!= WINED3DSPR_NULL
)
1401 if (reg
->idx
[0].rel_addr
)
1403 shader_dump_src_param(reg
->idx
[0].rel_addr
, shader_version
);
1406 TRACE("%u]", offset
);
1408 if (reg
->idx
[1].offset
!= ~0U)
1411 if (reg
->idx
[1].rel_addr
)
1413 shader_dump_src_param(reg
->idx
[1].rel_addr
, shader_version
);
1416 TRACE("%u]", reg
->idx
[1].offset
);
1422 void shader_dump_dst_param(const struct wined3d_shader_dst_param
*param
,
1423 const struct wined3d_shader_version
*shader_version
)
1425 DWORD write_mask
= param
->write_mask
;
1427 shader_dump_register(¶m
->reg
, shader_version
);
1429 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
1431 static const char write_mask_chars
[] = "xyzw";
1434 if (write_mask
& WINED3DSP_WRITEMASK_0
) TRACE("%c", write_mask_chars
[0]);
1435 if (write_mask
& WINED3DSP_WRITEMASK_1
) TRACE("%c", write_mask_chars
[1]);
1436 if (write_mask
& WINED3DSP_WRITEMASK_2
) TRACE("%c", write_mask_chars
[2]);
1437 if (write_mask
& WINED3DSP_WRITEMASK_3
) TRACE("%c", write_mask_chars
[3]);
1441 void shader_dump_src_param(const struct wined3d_shader_src_param
*param
,
1442 const struct wined3d_shader_version
*shader_version
)
1444 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
1445 DWORD swizzle
= param
->swizzle
;
1447 if (src_modifier
== WINED3DSPSM_NEG
1448 || src_modifier
== WINED3DSPSM_BIASNEG
1449 || src_modifier
== WINED3DSPSM_SIGNNEG
1450 || src_modifier
== WINED3DSPSM_X2NEG
1451 || src_modifier
== WINED3DSPSM_ABSNEG
)
1453 else if (src_modifier
== WINED3DSPSM_COMP
)
1455 else if (src_modifier
== WINED3DSPSM_NOT
)
1458 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
1461 shader_dump_register(¶m
->reg
, shader_version
);
1465 switch (src_modifier
)
1467 case WINED3DSPSM_NONE
: break;
1468 case WINED3DSPSM_NEG
: break;
1469 case WINED3DSPSM_NOT
: break;
1470 case WINED3DSPSM_BIAS
: TRACE("_bias"); break;
1471 case WINED3DSPSM_BIASNEG
: TRACE("_bias"); break;
1472 case WINED3DSPSM_SIGN
: TRACE("_bx2"); break;
1473 case WINED3DSPSM_SIGNNEG
: TRACE("_bx2"); break;
1474 case WINED3DSPSM_COMP
: break;
1475 case WINED3DSPSM_X2
: TRACE("_x2"); break;
1476 case WINED3DSPSM_X2NEG
: TRACE("_x2"); break;
1477 case WINED3DSPSM_DZ
: TRACE("_dz"); break;
1478 case WINED3DSPSM_DW
: TRACE("_dw"); break;
1479 case WINED3DSPSM_ABSNEG
: TRACE(")"); break;
1480 case WINED3DSPSM_ABS
: TRACE(")"); break;
1481 default: TRACE("_unknown_modifier(%#x)", src_modifier
);
1485 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
1487 static const char swizzle_chars
[] = "xyzw";
1488 DWORD swizzle_x
= swizzle
& 0x03;
1489 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
1490 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
1491 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
1493 if (swizzle_x
== swizzle_y
1494 && swizzle_x
== swizzle_z
1495 && swizzle_x
== swizzle_w
)
1497 TRACE(".%c", swizzle_chars
[swizzle_x
]);
1501 TRACE(".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
1502 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
1507 /* Shared code in order to generate the bulk of the shader string.
1508 * NOTE: A description of how to parse tokens can be found on MSDN. */
1509 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_shader_buffer
*buffer
,
1510 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
1512 struct wined3d_device
*device
= shader
->device
;
1513 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
1514 void *fe_data
= shader
->frontend_data
;
1515 struct wined3d_shader_version shader_version
;
1516 struct wined3d_shader_loop_state loop_state
;
1517 struct wined3d_shader_instruction ins
;
1518 struct wined3d_shader_tex_mx tex_mx
;
1519 struct wined3d_shader_context ctx
;
1520 const DWORD
*ptr
= byte_code
;
1522 /* Initialize current parsing state. */
1523 tex_mx
.current_row
= 0;
1524 loop_state
.current_depth
= 0;
1525 loop_state
.current_reg
= 0;
1527 ctx
.shader
= shader
;
1528 ctx
.gl_info
= &device
->adapter
->gl_info
;
1529 ctx
.reg_maps
= reg_maps
;
1530 ctx
.buffer
= buffer
;
1531 ctx
.tex_mx
= &tex_mx
;
1532 ctx
.loop_state
= &loop_state
;
1533 ctx
.backend_data
= backend_ctx
;
1536 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1538 while (!fe
->shader_is_end(fe_data
, &ptr
))
1541 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1543 /* Unknown opcode and its parameters. */
1544 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1546 TRACE("Skipping unrecognized instruction.\n");
1551 FIXME("Predicates not implemented.\n");
1553 /* Call appropriate function for output target */
1554 device
->shader_backend
->shader_handle_instruction(&ins
);
1558 static void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param
*dst
)
1560 DWORD mmask
= dst
->modifiers
;
1565 case 13: TRACE("_d8"); break;
1566 case 14: TRACE("_d4"); break;
1567 case 15: TRACE("_d2"); break;
1568 case 1: TRACE("_x2"); break;
1569 case 2: TRACE("_x4"); break;
1570 case 3: TRACE("_x8"); break;
1571 default: TRACE("_unhandled_shift(%d)", dst
->shift
); break;
1574 if (mmask
& WINED3DSPDM_SATURATE
) TRACE("_sat");
1575 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) TRACE("_pp");
1576 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) TRACE("_centroid");
1578 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
1579 if (mmask
) FIXME("_unrecognized_modifier(%#x)", mmask
);
1582 static void shader_dump_primitive_type(enum wined3d_primitive_type primitive_type
)
1584 switch (primitive_type
)
1586 case WINED3D_PT_UNDEFINED
:
1589 case WINED3D_PT_POINTLIST
:
1592 case WINED3D_PT_LINELIST
:
1595 case WINED3D_PT_LINESTRIP
:
1598 case WINED3D_PT_TRIANGLELIST
:
1599 TRACE("trianglelist");
1601 case WINED3D_PT_TRIANGLESTRIP
:
1602 TRACE("trianglestrip");
1604 case WINED3D_PT_TRIANGLEFAN
:
1605 TRACE("trianglefan");
1607 case WINED3D_PT_LINELIST_ADJ
:
1608 TRACE("linelist_adj");
1610 case WINED3D_PT_LINESTRIP_ADJ
:
1611 TRACE("linestrip_adj");
1613 case WINED3D_PT_TRIANGLELIST_ADJ
:
1614 TRACE("trianglelist_adj");
1616 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
1617 TRACE("trianglestrip_adj");
1620 TRACE("<unrecognized_primitive_type %#x>", primitive_type
);
1625 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
1627 struct wined3d_shader_version shader_version
;
1628 const DWORD
*ptr
= byte_code
;
1629 const char *type_prefix
;
1632 TRACE("Parsing %p.\n", byte_code
);
1634 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1636 switch (shader_version
.type
)
1638 case WINED3D_SHADER_TYPE_VERTEX
:
1642 case WINED3D_SHADER_TYPE_GEOMETRY
:
1646 case WINED3D_SHADER_TYPE_PIXEL
:
1651 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
1652 type_prefix
= "unknown";
1656 TRACE("%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
1658 while (!fe
->shader_is_end(fe_data
, &ptr
))
1660 struct wined3d_shader_instruction ins
;
1662 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1663 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1665 TRACE("Skipping unrecognized instruction.\n");
1669 if (ins
.handler_idx
== WINED3DSIH_DCL
)
1671 shader_dump_decl_usage(&ins
.declaration
.semantic
, &shader_version
);
1672 shader_dump_ins_modifiers(&ins
.declaration
.semantic
.reg
);
1674 shader_dump_dst_param(&ins
.declaration
.semantic
.reg
, &shader_version
);
1676 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1678 TRACE("%s ", shader_opcode_names
[ins
.handler_idx
]);
1679 shader_dump_src_param(&ins
.declaration
.src
, &shader_version
);
1680 TRACE(", %s", ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
1682 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
1683 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1685 TRACE("%s ", shader_opcode_names
[ins
.handler_idx
]);
1686 shader_dump_primitive_type(ins
.declaration
.primitive_type
);
1688 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1690 TRACE("%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
1692 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1694 TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(ins
.dst
[0].reg
.type
,
1695 ins
.dst
[0].reg
.idx
[0].offset
),
1696 *(const float *)&ins
.src
[0].reg
.immconst_data
[0],
1697 *(const float *)&ins
.src
[0].reg
.immconst_data
[1],
1698 *(const float *)&ins
.src
[0].reg
.immconst_data
[2],
1699 *(const float *)&ins
.src
[0].reg
.immconst_data
[3]);
1701 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1703 TRACE("defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
1704 ins
.src
[0].reg
.immconst_data
[0],
1705 ins
.src
[0].reg
.immconst_data
[1],
1706 ins
.src
[0].reg
.immconst_data
[2],
1707 ins
.src
[0].reg
.immconst_data
[3]);
1709 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1711 TRACE("defb b%u = %s", ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.immconst_data
[0] ? "true" : "false");
1718 shader_dump_src_param(ins
.predicate
, &shader_version
);
1722 /* PixWin marks instructions with the coissue flag with a '+' */
1723 if (ins
.coissue
) TRACE("+");
1725 TRACE("%s", shader_opcode_names
[ins
.handler_idx
]);
1727 if (ins
.handler_idx
== WINED3DSIH_IFC
1728 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
1732 case WINED3D_SHADER_REL_OP_GT
: TRACE("_gt"); break;
1733 case WINED3D_SHADER_REL_OP_EQ
: TRACE("_eq"); break;
1734 case WINED3D_SHADER_REL_OP_GE
: TRACE("_ge"); break;
1735 case WINED3D_SHADER_REL_OP_LT
: TRACE("_lt"); break;
1736 case WINED3D_SHADER_REL_OP_NE
: TRACE("_ne"); break;
1737 case WINED3D_SHADER_REL_OP_LE
: TRACE("_le"); break;
1738 default: TRACE("_(%u)", ins
.flags
);
1741 else if (ins
.handler_idx
== WINED3DSIH_TEX
1742 && shader_version
.major
>= 2
1743 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
1748 for (i
= 0; i
< ins
.dst_count
; ++i
)
1750 shader_dump_ins_modifiers(&ins
.dst
[i
]);
1751 TRACE(!i
? " " : ", ");
1752 shader_dump_dst_param(&ins
.dst
[i
], &shader_version
);
1755 /* Other source tokens */
1756 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
1758 TRACE(!i
? " " : ", ");
1759 shader_dump_src_param(&ins
.src
[i
- ins
.dst_count
], &shader_version
);
1766 static void shader_cleanup(struct wined3d_shader
*shader
)
1768 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
1769 shader
->device
->shader_backend
->shader_destroy(shader
);
1770 HeapFree(GetProcessHeap(), 0, shader
->reg_maps
.constf
);
1771 HeapFree(GetProcessHeap(), 0, shader
->function
);
1772 shader_delete_constant_list(&shader
->constantsF
);
1773 shader_delete_constant_list(&shader
->constantsB
);
1774 shader_delete_constant_list(&shader
->constantsI
);
1775 list_remove(&shader
->shader_list_entry
);
1777 if (shader
->frontend
&& shader
->frontend_data
)
1778 shader
->frontend
->shader_free(shader
->frontend_data
);
1781 struct shader_none_priv
1783 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
1784 const struct fragment_pipeline
*fragment_pipe
;
1785 BOOL ffp_proj_control
;
1788 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
1789 static void shader_none_select_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
,
1790 enum tex_types tex_type
, const SIZE
*ds_mask_size
) {}
1791 static void shader_none_deselect_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
) {}
1792 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
1793 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
1794 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
1795 const struct wined3d_state
*state
) {}
1796 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
1797 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
1799 /* Context activation is done by the caller. */
1800 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
1801 const struct wined3d_state
*state
)
1803 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
1804 struct shader_none_priv
*priv
= shader_priv
;
1806 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
1807 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
1810 /* Context activation is done by the caller. */
1811 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
1813 struct shader_none_priv
*priv
= shader_priv
;
1814 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
1816 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
1817 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
1819 context
->shader_update_mask
= (1 << WINED3D_SHADER_TYPE_PIXEL
)
1820 | (1 << WINED3D_SHADER_TYPE_VERTEX
)
1821 | (1 << WINED3D_SHADER_TYPE_GEOMETRY
);
1824 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
1825 const struct fragment_pipeline
*fragment_pipe
)
1827 struct fragment_caps fragment_caps
;
1828 void *vertex_priv
, *fragment_priv
;
1829 struct shader_none_priv
*priv
;
1831 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
1832 return E_OUTOFMEMORY
;
1834 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
1836 ERR("Failed to initialize vertex pipe.\n");
1837 HeapFree(GetProcessHeap(), 0, priv
);
1841 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
1843 ERR("Failed to initialize fragment pipe.\n");
1844 vertex_pipe
->vp_free(device
);
1845 HeapFree(GetProcessHeap(), 0, priv
);
1849 priv
->vertex_pipe
= vertex_pipe
;
1850 priv
->fragment_pipe
= fragment_pipe
;
1851 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
1852 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
1854 device
->vertex_priv
= vertex_priv
;
1855 device
->fragment_priv
= fragment_priv
;
1856 device
->shader_priv
= priv
;
1861 static void shader_none_free(struct wined3d_device
*device
)
1863 struct shader_none_priv
*priv
= device
->shader_priv
;
1865 priv
->fragment_pipe
->free_private(device
);
1866 priv
->vertex_pipe
->vp_free(device
);
1867 HeapFree(GetProcessHeap(), 0, priv
);
1870 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
1875 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
1877 /* Set the shader caps to 0 for the none shader backend */
1878 caps
->vs_version
= 0;
1879 caps
->gs_version
= 0;
1880 caps
->ps_version
= 0;
1881 caps
->vs_uniform_count
= 0;
1882 caps
->ps_uniform_count
= 0;
1883 caps
->ps_1x_max_value
= 0.0f
;
1884 caps
->wined3d_caps
= 0;
1887 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
1889 /* We "support" every possible fixup, since we don't support any shader
1890 * model, and will never have to actually sample a texture. */
1894 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
1896 struct shader_none_priv
*priv
= shader_priv
;
1898 return priv
->ffp_proj_control
;
1901 const struct wined3d_shader_backend_ops none_shader_backend
=
1903 shader_none_handle_instruction
,
1905 shader_none_disable
,
1906 shader_none_select_depth_blt
,
1907 shader_none_deselect_depth_blt
,
1908 shader_none_update_float_vertex_constants
,
1909 shader_none_update_float_pixel_constants
,
1910 shader_none_load_constants
,
1911 shader_none_destroy
,
1914 shader_none_allocate_context_data
,
1915 shader_none_free_context_data
,
1916 shader_none_get_caps
,
1917 shader_none_color_fixup_supported
,
1918 shader_none_has_ffp_proj_control
,
1921 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
1922 const struct wined3d_shader_signature
*output_signature
, DWORD float_const_count
,
1923 enum wined3d_shader_type type
, unsigned int max_version
)
1925 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
1926 const struct wined3d_shader_frontend
*fe
;
1928 unsigned int backend_version
;
1929 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
1931 TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u.\n",
1932 shader
, byte_code
, output_signature
, float_const_count
);
1934 fe
= shader_select_frontend(*byte_code
);
1937 FIXME("Unable to find frontend for shader.\n");
1938 return WINED3DERR_INVALIDCALL
;
1940 shader
->frontend
= fe
;
1941 shader
->frontend_data
= fe
->shader_init(byte_code
, output_signature
);
1942 if (!shader
->frontend_data
)
1944 FIXME("Failed to initialize frontend.\n");
1945 return WINED3DERR_INVALIDCALL
;
1948 /* First pass: trace shader. */
1949 if (TRACE_ON(d3d_shader
))
1950 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
1952 /* Initialize immediate constant lists. */
1953 list_init(&shader
->constantsF
);
1954 list_init(&shader
->constantsB
);
1955 list_init(&shader
->constantsI
);
1956 shader
->lconst_inf_or_nan
= FALSE
;
1958 /* Second pass: figure out which registers are used, what the semantics are, etc. */
1959 hr
= shader_get_registers_used(shader
, fe
,
1960 reg_maps
, shader
->input_signature
, shader
->output_signature
,
1961 byte_code
, float_const_count
);
1962 if (FAILED(hr
)) return hr
;
1964 if (reg_maps
->shader_version
.type
!= type
)
1966 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
1967 return WINED3DERR_INVALIDCALL
;
1969 if (reg_maps
->shader_version
.major
> max_version
)
1971 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
1972 return WINED3DERR_INVALIDCALL
;
1976 case WINED3D_SHADER_TYPE_VERTEX
:
1977 backend_version
= d3d_info
->limits
.vs_version
;
1979 case WINED3D_SHADER_TYPE_GEOMETRY
:
1980 backend_version
= d3d_info
->limits
.gs_version
;
1982 case WINED3D_SHADER_TYPE_PIXEL
:
1983 backend_version
= d3d_info
->limits
.ps_version
;
1986 FIXME("No backend version-checking for this shader type\n");
1987 backend_version
= 0;
1989 if (reg_maps
->shader_version
.major
> backend_version
)
1991 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
1992 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
1993 return WINED3DERR_INVALIDCALL
;
1996 shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
);
1997 if (!shader
->function
)
1998 return E_OUTOFMEMORY
;
1999 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2004 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2006 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2008 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2013 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2015 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2017 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2021 shader_cleanup(shader
);
2022 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2023 HeapFree(GetProcessHeap(), 0, shader
);
2029 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2031 TRACE("shader %p.\n", shader
);
2033 return shader
->parent
;
2036 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2037 void *byte_code
, UINT
*byte_code_size
)
2039 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2043 *byte_code_size
= shader
->functionLength
;
2047 if (*byte_code_size
< shader
->functionLength
)
2049 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2050 * than the required size we should write the required size and
2051 * return D3DERR_MOREDATA. That's not actually true. */
2052 return WINED3DERR_INVALIDCALL
;
2055 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2060 /* Set local constants for d3d8 shaders. */
2061 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2062 UINT start_idx
, const float *src_data
, UINT count
)
2064 UINT end_idx
= start_idx
+ count
;
2067 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2069 if (end_idx
> shader
->limits
->constant_float
)
2071 WARN("end_idx %u > float constants limit %u.\n",
2072 end_idx
, shader
->limits
->constant_float
);
2073 end_idx
= shader
->limits
->constant_float
;
2076 for (i
= start_idx
; i
< end_idx
; ++i
)
2078 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2081 return E_OUTOFMEMORY
;
2084 value
= (float *)lconst
->value
;
2085 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
2086 list_add_head(&shader
->constantsF
, &lconst
->entry
);
2088 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
2089 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
2091 shader
->lconst_inf_or_nan
= TRUE
;
2098 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2099 WORD swizzle_map
, struct vs_compile_args
*args
)
2101 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
2102 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
2103 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
2104 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
2105 args
->swizzle_map
= swizzle_map
;
2108 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
2110 if (usage_idx1
!= usage_idx2
)
2112 if (usage1
== usage2
)
2114 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
2116 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
2122 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
2123 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
2125 WORD map
= shader
->reg_maps
.input_registers
;
2128 for (i
= 0; map
; map
>>= 1, ++i
)
2130 if (!(map
& 1)) continue;
2132 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
2133 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
2142 static HRESULT
vertexshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2143 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2145 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2149 const DWORD vs_uniform_count
= device
->adapter
->d3d_info
.limits
.vs_uniform_count
;
2151 if (!desc
->byte_code
)
2152 return WINED3DERR_INVALIDCALL
;
2154 shader_init(shader
, device
, parent
, parent_ops
);
2155 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
, desc
->output_signature
,
2156 vs_uniform_count
, WINED3D_SHADER_TYPE_VERTEX
, desc
->max_version
)))
2158 WARN("Failed to set function, hr %#x.\n", hr
);
2159 shader_cleanup(shader
);
2163 map
= reg_maps
->input_registers
;
2164 for (i
= 0; map
; map
>>= 1, ++i
)
2166 if (!(map
& 1) || !shader
->input_signature
[i
].semantic_name
)
2169 shader
->u
.vs
.attributes
[i
].usage
=
2170 shader_usage_from_semantic_name(shader
->input_signature
[i
].semantic_name
);
2171 shader
->u
.vs
.attributes
[i
].usage_idx
= shader
->input_signature
[i
].semantic_idx
;
2174 if (desc
->output_signature
)
2176 struct wined3d_shader_signature_element
*e
;
2181 for (i
= 0; i
< desc
->output_signature
->element_count
; ++i
)
2183 e
= &desc
->output_signature
->elements
[i
];
2184 len
= strlen(e
->semantic_name
);
2185 if (len
>= ~(SIZE_T
)0 - total
)
2187 shader_cleanup(shader
);
2188 return E_OUTOFMEMORY
;
2194 if (!(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
2196 shader_cleanup(shader
);
2197 return E_OUTOFMEMORY
;
2199 ptr
= shader
->signature_strings
;
2201 for (i
= 0; i
< desc
->output_signature
->element_count
; ++i
)
2203 e
= &desc
->output_signature
->elements
[i
];
2204 reg_maps
->output_registers
|= 1 << e
->register_idx
;
2205 shader
->output_signature
[e
->register_idx
] = *e
;
2207 len
= strlen(e
->semantic_name
);
2208 memcpy(ptr
, e
->semantic_name
, len
+ 1);
2209 shader
->output_signature
[e
->register_idx
].semantic_name
= ptr
;
2214 shader
->load_local_constsF
= (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
)) ||
2215 shader
->lconst_inf_or_nan
;
2220 static HRESULT
geometryshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2221 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2225 shader_init(shader
, device
, parent
, parent_ops
);
2226 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
, desc
->output_signature
,
2227 0, WINED3D_SHADER_TYPE_GEOMETRY
, desc
->max_version
)))
2229 WARN("Failed to set function, hr %#x.\n", hr
);
2230 shader_cleanup(shader
);
2234 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2239 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2240 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_gl_info
*gl_info
)
2242 const struct wined3d_texture
*texture
;
2245 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
2246 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && state
->render_states
[WINED3D_RS_SRGBWRITEENABLE
])
2248 const struct wined3d_format
*rt_format
= state
->fb
->render_targets
[0]->format
;
2249 if (rt_format
->flags
& WINED3DFMT_FLAG_SRGB_WRITE
)
2251 static unsigned int warned
= 0;
2253 args
->srgb_correction
= 1;
2254 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
2255 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
2256 "support, expect rendering artifacts.\n");
2260 if (shader
->reg_maps
.shader_version
.major
== 1
2261 && shader
->reg_maps
.shader_version
.minor
<= 3)
2263 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2265 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
2267 if (flags
& WINED3D_TTFF_PROJECTED
)
2269 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
2271 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
2273 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
2275 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
2276 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
2278 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
2280 struct wined3d_vertex_declaration_element
*element
=
2281 &state
->vertex_declaration
->elements
[j
];
2283 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
2284 && element
->usage_idx
== index
)
2286 max_valid
= element
->format
->component_count
;
2290 if (!tex_transform
|| tex_transform
> max_valid
)
2292 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
2293 tex_transform
, max_valid
);
2294 tex_transform
= max_valid
;
2296 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
2297 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
2298 && tex_transform
> WINED3D_TTFF_COUNT2
)
2299 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
2300 && tex_transform
> WINED3D_TTFF_COUNT3
))
2301 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
2304 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
2305 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
2306 i
, tex_transform
, resource_type
);
2310 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
2312 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
2316 if (shader
->reg_maps
.shader_version
.major
== 1
2317 && shader
->reg_maps
.shader_version
.minor
<= 4)
2319 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2321 const struct wined3d_texture
*texture
= state
->textures
[i
];
2323 if (!shader
->reg_maps
.resource_info
[i
].type
)
2326 /* Treat unbound textures as 2D. The dummy texture will provide
2327 * the proper sample value. The tex_types bitmap defaults to
2328 * 2D because of the memset. */
2332 switch (texture
->target
)
2334 /* RECT textures are distinguished from 2D textures via np2_fixup */
2335 case GL_TEXTURE_RECTANGLE_ARB
:
2340 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2343 case GL_TEXTURE_CUBE_MAP_ARB
:
2344 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2350 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
2352 if (!shader
->reg_maps
.resource_info
[i
].type
)
2355 texture
= state
->textures
[i
];
2358 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
2361 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
2363 if (texture
->resource
.format
->flags
& WINED3DFMT_FLAG_SHADOW
)
2364 args
->shadow
|= 1 << i
;
2366 /* Flag samplers that need NP2 texcoord fixup. */
2367 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
2368 args
->np2_fixup
|= (1 << i
);
2370 if (shader
->reg_maps
.shader_version
.major
>= 3)
2372 if (position_transformed
)
2373 args
->vp_mode
= pretransformed
;
2374 else if (use_vs(state
))
2375 args
->vp_mode
= vertexshader
;
2377 args
->vp_mode
= fixedfunction
;
2378 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2382 args
->vp_mode
= vertexshader
;
2383 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
2385 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
2387 case WINED3D_FOG_NONE
:
2388 if (position_transformed
|| use_vs(state
))
2390 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
2394 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
2396 case WINED3D_FOG_NONE
: /* Fall through. */
2397 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2398 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2399 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2403 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2404 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2405 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2410 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2415 static HRESULT
pixelshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2416 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2418 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
2419 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
2421 const DWORD ps_uniform_count
= device
->adapter
->d3d_info
.limits
.ps_uniform_count
;
2423 if (!desc
->byte_code
)
2424 return WINED3DERR_INVALIDCALL
;
2426 shader_init(shader
, device
, parent
, parent_ops
);
2427 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
, desc
->output_signature
,
2428 ps_uniform_count
, WINED3D_SHADER_TYPE_PIXEL
, desc
->max_version
)))
2430 WARN("Failed to set function, hr %#x.\n", hr
);
2431 shader_cleanup(shader
);
2435 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2437 if (shader
->u
.ps
.input_reg_used
[i
])
2440 highest_reg_used
= i
;
2444 /* Don't do any register mapping magic if it is not needed, or if we can't
2445 * achieve anything anyway */
2446 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
2447 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2449 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2451 /* This happens with relative addressing. The input mapper function
2452 * warns about this if the higher registers are declared too, so
2453 * don't write a FIXME here */
2454 WARN("More varying registers used than supported\n");
2457 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2459 shader
->u
.ps
.input_reg_map
[i
] = i
;
2462 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
2466 shader
->u
.ps
.declared_in_count
= 0;
2467 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2469 if (shader
->u
.ps
.input_reg_used
[i
])
2470 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
2471 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
2475 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2477 if (desc
->input_signature
)
2479 struct wined3d_shader_signature_element
*e
;
2484 for (i
= 0; i
< desc
->input_signature
->element_count
; ++i
)
2486 e
= &desc
->input_signature
->elements
[i
];
2487 len
= strlen(e
->semantic_name
);
2488 if (len
>= ~(SIZE_T
)0 - total
)
2490 shader_cleanup(shader
);
2491 return E_OUTOFMEMORY
;
2497 if (!(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
2499 shader_cleanup(shader
);
2500 return E_OUTOFMEMORY
;
2502 ptr
= shader
->signature_strings
;
2504 for (i
= 0; i
< desc
->input_signature
->element_count
; ++i
)
2506 e
= &desc
->input_signature
->elements
[i
];
2507 shader
->reg_maps
.input_registers
|= 1 << e
->register_idx
;
2508 shader
->input_signature
[e
->register_idx
] = *e
;
2510 len
= strlen(e
->semantic_name
);
2511 memcpy(ptr
, e
->semantic_name
, len
+ 1);
2512 shader
->input_signature
[e
->register_idx
].semantic_name
= ptr
;
2515 if (!strcmp(e
->semantic_name
, "SV_POSITION"))
2516 shader
->reg_maps
.vpos
= 1;
2523 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
2525 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2526 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
2529 if (reg_maps
->shader_version
.major
!= 1) return;
2531 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2533 /* We don't sample from this sampler. */
2534 if (!resource_info
[i
].type
)
2537 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
2539 case WINED3D_SHADER_TEX_2D
:
2540 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
2543 case WINED3D_SHADER_TEX_3D
:
2544 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
2547 case WINED3D_SHADER_TEX_CUBE
:
2548 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
2554 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2555 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2557 struct wined3d_shader
*object
;
2560 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2561 device
, desc
, parent
, parent_ops
, shader
);
2563 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2565 return E_OUTOFMEMORY
;
2567 if (FAILED(hr
= geometryshader_init(object
, device
, desc
, parent
, parent_ops
)))
2569 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
2570 HeapFree(GetProcessHeap(), 0, object
);
2574 TRACE("Created geometry shader %p.\n", object
);
2580 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2581 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2583 struct wined3d_shader
*object
;
2586 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2587 device
, desc
, parent
, parent_ops
, shader
);
2589 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2591 return E_OUTOFMEMORY
;
2593 if (FAILED(hr
= pixelshader_init(object
, device
, desc
, parent
, parent_ops
)))
2595 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2596 HeapFree(GetProcessHeap(), 0, object
);
2600 TRACE("Created pixel shader %p.\n", object
);
2606 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2607 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2609 struct wined3d_shader
*object
;
2612 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2613 device
, desc
, parent
, parent_ops
, shader
);
2615 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2617 return E_OUTOFMEMORY
;
2619 if (FAILED(hr
= vertexshader_init(object
, device
, desc
, parent
, parent_ops
)))
2621 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2622 HeapFree(GetProcessHeap(), 0, object
);
2626 TRACE("Created vertex shader %p.\n", object
);