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 string_buffer_clear(struct wined3d_string_buffer
*buffer
)
250 buffer
->buffer
[0] = '\0';
251 buffer
->content_size
= 0;
254 BOOL
string_buffer_init(struct wined3d_string_buffer
*buffer
)
256 buffer
->buffer_size
= 32;
257 if (!(buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, buffer
->buffer_size
)))
259 ERR("Failed to allocate shader buffer memory.\n");
263 string_buffer_clear(buffer
);
267 void string_buffer_free(struct wined3d_string_buffer
*buffer
)
269 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
272 BOOL
string_buffer_resize(struct wined3d_string_buffer
*buffer
, int rc
)
275 unsigned int new_buffer_size
= buffer
->buffer_size
* 2;
277 while (rc
> 0 && (unsigned int)rc
>= new_buffer_size
- buffer
->content_size
)
278 new_buffer_size
*= 2;
279 if (!(new_buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
->buffer
, new_buffer_size
)))
281 ERR("Failed to grow buffer.\n");
282 buffer
->buffer
[buffer
->content_size
] = '\0';
285 buffer
->buffer
= new_buffer
;
286 buffer
->buffer_size
= new_buffer_size
;
290 int shader_vaddline(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
295 rem
= buffer
->buffer_size
- buffer
->content_size
;
296 rc
= vsnprintf(&buffer
->buffer
[buffer
->content_size
], rem
, format
, args
);
297 if (rc
< 0 /* C89 */ || (unsigned int)rc
>= rem
/* C99 */)
300 buffer
->content_size
+= rc
;
304 int shader_addline(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
311 va_start(args
, format
);
312 ret
= shader_vaddline(buffer
, format
, args
);
316 if (!string_buffer_resize(buffer
, ret
))
321 struct wined3d_string_buffer
*string_buffer_get(struct wined3d_string_buffer_list
*list
)
323 struct wined3d_string_buffer
*buffer
;
325 if (list_empty(&list
->list
))
327 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer
));
328 if (!buffer
|| !string_buffer_init(buffer
))
330 ERR("Couldn't allocate buffer for temporary string.\n");
332 HeapFree(GetProcessHeap(), 0, buffer
);
338 buffer
= LIST_ENTRY(list_head(&list
->list
), struct wined3d_string_buffer
, entry
);
339 list_remove(&buffer
->entry
);
341 string_buffer_clear(buffer
);
345 static int string_buffer_vsprintf(struct wined3d_string_buffer
*buffer
, const char *format
, va_list args
)
349 string_buffer_clear(buffer
);
350 return shader_vaddline(buffer
, format
, args
);
353 void string_buffer_sprintf(struct wined3d_string_buffer
*buffer
, const char *format
, ...)
360 va_start(args
, format
);
361 ret
= string_buffer_vsprintf(buffer
, format
, args
);
365 if (!string_buffer_resize(buffer
, ret
))
370 void string_buffer_release(struct wined3d_string_buffer_list
*list
, struct wined3d_string_buffer
*buffer
)
374 list_add_head(&list
->list
, &buffer
->entry
);
377 void string_buffer_list_init(struct wined3d_string_buffer_list
*list
)
379 list_init(&list
->list
);
382 void string_buffer_list_cleanup(struct wined3d_string_buffer_list
*list
)
384 struct wined3d_string_buffer
*buffer
, *buffer_next
;
386 LIST_FOR_EACH_ENTRY_SAFE(buffer
, buffer_next
, &list
->list
, struct wined3d_string_buffer
, entry
)
388 string_buffer_free(buffer
);
389 HeapFree(GetProcessHeap(), 0, buffer
);
391 list_init(&list
->list
);
394 /* Convert floating point offset relative to a register file to an absolute
395 * offset for float constants. */
396 static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type
, UINT register_idx
)
398 switch (register_type
)
400 case WINED3DSPR_CONST
: return register_idx
;
401 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
402 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
403 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
405 FIXME("Unsupported register type: %u.\n", register_type
);
410 static void shader_delete_constant_list(struct list
*clist
)
412 struct wined3d_shader_lconst
*constant
;
415 ptr
= list_head(clist
);
418 constant
= LIST_ENTRY(ptr
, struct wined3d_shader_lconst
, entry
);
419 ptr
= list_next(clist
, ptr
);
420 HeapFree(GetProcessHeap(), 0, constant
);
425 static void shader_set_limits(struct wined3d_shader
*shader
)
427 static const struct limits_entry
429 unsigned int min_version
;
430 unsigned int max_version
;
431 struct wined3d_shader_limits limits
;
435 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
436 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
437 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
438 /* DX10 cards on Windows advertise a D3D9 constant limit of 256
439 * even though they are capable of supporting much more (GL
440 * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
441 * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
443 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
444 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
449 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
450 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
455 /* min_version, max_version, sampler, constant_int, constant_float, constant_bool, packed_output, packed_input */
456 {WINED3D_SHADER_VERSION(1, 0), WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
457 {WINED3D_SHADER_VERSION(1, 4), WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
458 {WINED3D_SHADER_VERSION(2, 0), WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
459 {WINED3D_SHADER_VERSION(2, 1), WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
460 {WINED3D_SHADER_VERSION(3, 0), WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 12}},
461 {WINED3D_SHADER_VERSION(4, 0), WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 0, 32}},
464 const struct limits_entry
*limits_array
;
465 DWORD shader_version
= WINED3D_SHADER_VERSION(shader
->reg_maps
.shader_version
.major
,
466 shader
->reg_maps
.shader_version
.minor
);
469 switch (shader
->reg_maps
.shader_version
.type
)
472 FIXME("Unexpected shader type %u found.\n", shader
->reg_maps
.shader_version
.type
);
474 case WINED3D_SHADER_TYPE_VERTEX
:
475 limits_array
= vs_limits
;
477 case WINED3D_SHADER_TYPE_GEOMETRY
:
478 limits_array
= gs_limits
;
480 case WINED3D_SHADER_TYPE_PIXEL
:
481 limits_array
= ps_limits
;
485 while (limits_array
[i
].min_version
&& limits_array
[i
].min_version
<= shader_version
)
487 if (shader_version
<= limits_array
[i
].max_version
)
489 shader
->limits
= &limits_array
[i
].limits
;
496 FIXME("Unexpected shader version \"%u.%u\".\n",
497 shader
->reg_maps
.shader_version
.major
,
498 shader
->reg_maps
.shader_version
.minor
);
499 shader
->limits
= &limits_array
[max(0, i
- 1)].limits
;
503 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
508 bitmap
[idx
] |= (1 << shift
);
511 static BOOL
shader_record_register_usage(struct wined3d_shader
*shader
, struct wined3d_shader_reg_maps
*reg_maps
,
512 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
, unsigned int constf_size
)
516 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
517 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
518 reg_maps
->texcoord
|= 1 << reg
->idx
[0].offset
;
520 reg_maps
->address
|= 1 << reg
->idx
[0].offset
;
523 case WINED3DSPR_TEMP
:
524 reg_maps
->temporary
|= 1 << reg
->idx
[0].offset
;
527 case WINED3DSPR_INPUT
:
528 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
530 if (reg
->idx
[0].rel_addr
)
532 /* If relative addressing is used, we must assume that all registers
533 * are used. Even if it is a construct like v3[aL], we can't assume
534 * that v0, v1 and v2 aren't read because aL can be negative */
536 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
538 shader
->u
.ps
.input_reg_used
[i
] = TRUE
;
543 shader
->u
.ps
.input_reg_used
[reg
->idx
[0].offset
] = TRUE
;
547 reg_maps
->input_registers
|= 1 << reg
->idx
[0].offset
;
550 case WINED3DSPR_RASTOUT
:
551 if (reg
->idx
[0].offset
== 1)
555 case WINED3DSPR_MISCTYPE
:
556 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
558 if (!reg
->idx
[0].offset
)
560 else if (reg
->idx
[0].offset
== 1)
561 reg_maps
->usesfacing
= 1;
565 case WINED3DSPR_CONST
:
566 if (reg
->idx
[0].rel_addr
)
568 if (reg
->idx
[0].offset
< reg_maps
->min_rel_offset
)
569 reg_maps
->min_rel_offset
= reg
->idx
[0].offset
;
570 if (reg
->idx
[0].offset
> reg_maps
->max_rel_offset
)
571 reg_maps
->max_rel_offset
= reg
->idx
[0].offset
;
572 reg_maps
->usesrelconstF
= TRUE
;
576 if (reg
->idx
[0].offset
>= min(shader
->limits
->constant_float
, constf_size
))
578 WARN("Shader using float constant %u which is not supported.\n", reg
->idx
[0].offset
);
583 set_bitmap_bit(reg_maps
->constf
, reg
->idx
[0].offset
);
588 case WINED3DSPR_CONSTINT
:
589 if (reg
->idx
[0].offset
>= shader
->limits
->constant_int
)
591 WARN("Shader using integer constant %u which is not supported.\n", reg
->idx
[0].offset
);
596 reg_maps
->integer_constants
|= (1 << reg
->idx
[0].offset
);
600 case WINED3DSPR_CONSTBOOL
:
601 if (reg
->idx
[0].offset
>= shader
->limits
->constant_bool
)
603 WARN("Shader using bool constant %u which is not supported.\n", reg
->idx
[0].offset
);
608 reg_maps
->boolean_constants
|= (1 << reg
->idx
[0].offset
);
612 case WINED3DSPR_COLOROUT
:
613 reg_maps
->rt_mask
|= (1 << reg
->idx
[0].offset
);
617 TRACE("Not recording register of type %#x and [%#x][%#x].\n",
618 reg
->type
, reg
->idx
[0].offset
, reg
->idx
[1].offset
);
624 static void shader_record_sample(struct wined3d_shader_reg_maps
*reg_maps
,
625 unsigned int resource_idx
, unsigned int sampler_idx
, unsigned int bind_idx
)
627 struct wined3d_shader_sampler_map_entry
*entries
, *entry
;
628 struct wined3d_shader_sampler_map
*map
;
631 map
= ®_maps
->sampler_map
;
632 entries
= map
->entries
;
633 for (i
= 0; i
< map
->count
; ++i
)
635 if (entries
[i
].resource_idx
== resource_idx
&& entries
[i
].sampler_idx
== sampler_idx
)
641 if (!(entries
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entries
) * 4)))
643 ERR("Failed to allocate sampler map entries.\n");
647 map
->entries
= entries
;
649 else if (map
->count
== map
->size
)
651 size_t new_size
= map
->size
* 2;
653 if (sizeof(*entries
) * new_size
<= sizeof(*entries
) * map
->size
654 || !(entries
= HeapReAlloc(GetProcessHeap(), 0, entries
, sizeof(*entries
) * new_size
)))
656 ERR("Failed to resize sampler map entries.\n");
659 map
->size
= new_size
;
660 map
->entries
= entries
;
663 entry
= &entries
[map
->count
++];
664 entry
->resource_idx
= resource_idx
;
665 entry
->sampler_idx
= sampler_idx
;
666 entry
->bind_idx
= bind_idx
;
669 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
673 case WINED3DSIH_M4x4
:
674 case WINED3DSIH_M3x4
:
675 return param
== 1 ? 3 : 0;
677 case WINED3DSIH_M4x3
:
678 case WINED3DSIH_M3x3
:
679 return param
== 1 ? 2 : 0;
681 case WINED3DSIH_M3x2
:
682 return param
== 1 ? 1 : 0;
689 /* Note that this does not count the loop register as an address register. */
690 static HRESULT
shader_get_registers_used(struct wined3d_shader
*shader
, const struct wined3d_shader_frontend
*fe
,
691 struct wined3d_shader_reg_maps
*reg_maps
, struct wined3d_shader_signature
*input_signature
,
692 struct wined3d_shader_signature
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
694 struct wined3d_shader_signature_element input_signature_elements
[max(MAX_ATTRIBS
, MAX_REG_INPUT
)];
695 struct wined3d_shader_signature_element output_signature_elements
[MAX_REG_OUTPUT
];
696 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
697 void *fe_data
= shader
->frontend_data
;
698 struct wined3d_shader_version shader_version
;
699 const DWORD
*ptr
= byte_code
;
702 memset(reg_maps
, 0, sizeof(*reg_maps
));
703 memset(input_signature_elements
, 0, sizeof(input_signature_elements
));
704 memset(output_signature_elements
, 0, sizeof(output_signature_elements
));
705 reg_maps
->min_rel_offset
= ~0U;
707 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
708 reg_maps
->shader_version
= shader_version
;
710 shader_set_limits(shader
);
712 reg_maps
->constf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
713 sizeof(*reg_maps
->constf
) * ((min(shader
->limits
->constant_float
, constf_size
) + 31) / 32));
714 if (!reg_maps
->constf
)
716 ERR("Failed to allocate constant map memory.\n");
717 return E_OUTOFMEMORY
;
720 while (!fe
->shader_is_end(fe_data
, &ptr
))
722 struct wined3d_shader_instruction ins
;
725 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
727 /* Unhandled opcode, and its parameters. */
728 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
730 TRACE("Skipping unrecognized instruction.\n");
734 /* Handle declarations. */
735 if (ins
.handler_idx
== WINED3DSIH_DCL
)
737 struct wined3d_shader_semantic
*semantic
= &ins
.declaration
.semantic
;
738 unsigned int reg_idx
= semantic
->reg
.reg
.idx
[0].offset
;
740 switch (semantic
->reg
.reg
.type
)
742 /* Mark input registers used. */
743 case WINED3DSPR_INPUT
:
744 if (reg_idx
>= MAX_REG_INPUT
)
746 ERR("Invalid input register index %u.\n", reg_idx
);
749 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
&& shader_version
.major
== 3
750 && semantic
->usage
== WINED3D_DECL_USAGE_POSITION
&& !semantic
->usage_idx
)
751 return WINED3DERR_INVALIDCALL
;
752 reg_maps
->input_registers
|= 1 << reg_idx
;
753 shader_signature_from_semantic(&input_signature_elements
[reg_idx
], semantic
);
756 /* Vertex shader: mark 3.0 output registers used, save token. */
757 case WINED3DSPR_OUTPUT
:
758 if (reg_idx
>= MAX_REG_OUTPUT
)
760 ERR("Invalid output register index %u.\n", reg_idx
);
763 reg_maps
->output_registers
|= 1 << reg_idx
;
764 shader_signature_from_semantic(&output_signature_elements
[reg_idx
], semantic
);
765 if (semantic
->usage
== WINED3D_DECL_USAGE_FOG
)
769 case WINED3DSPR_SAMPLER
:
770 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
771 case WINED3DSPR_RESOURCE
:
772 if (reg_idx
>= ARRAY_SIZE(reg_maps
->resource_info
))
774 ERR("Invalid resource index %u.\n", reg_idx
);
777 reg_maps
->resource_info
[reg_idx
].type
= semantic
->resource_type
;
778 reg_maps
->resource_info
[reg_idx
].data_type
= semantic
->resource_data_type
;
782 TRACE("Not recording DCL register type %#x.\n", semantic
->reg
.reg
.type
);
786 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
788 struct wined3d_shader_register
*reg
= &ins
.declaration
.src
.reg
;
789 if (reg
->idx
[0].offset
>= WINED3D_MAX_CBS
)
790 ERR("Invalid CB index %u.\n", reg
->idx
[0].offset
);
792 reg_maps
->cb_sizes
[reg
->idx
[0].offset
] = reg
->idx
[1].offset
;
794 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
)
796 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
797 shader
->u
.gs
.input_type
= ins
.declaration
.primitive_type
;
799 FIXME("Invalid instruction %#x for shader type %#x.\n",
800 ins
.handler_idx
, shader_version
.type
);
802 else if (ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
804 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
805 shader
->u
.gs
.output_type
= ins
.declaration
.primitive_type
;
807 FIXME("Invalid instruction %#x for shader type %#x.\n",
808 ins
.handler_idx
, shader_version
.type
);
810 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
812 if (shader_version
.type
== WINED3D_SHADER_TYPE_GEOMETRY
)
813 shader
->u
.gs
.vertices_out
= ins
.declaration
.count
;
815 FIXME("Invalid instruction %#x for shader type %#x.\n",
816 ins
.handler_idx
, shader_version
.type
);
818 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
820 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
822 if (!lconst
) return E_OUTOFMEMORY
;
824 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
825 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
826 value
= (float *)lconst
->value
;
828 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
829 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
831 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
832 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
833 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
834 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
835 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
836 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
837 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
838 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
841 list_add_head(&shader
->constantsF
, &lconst
->entry
);
843 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
844 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
846 shader
->lconst_inf_or_nan
= TRUE
;
849 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
851 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
852 if (!lconst
) return E_OUTOFMEMORY
;
854 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
855 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, 4 * sizeof(DWORD
));
857 list_add_head(&shader
->constantsI
, &lconst
->entry
);
858 reg_maps
->local_int_consts
|= (1 << lconst
->idx
);
860 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
862 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
863 if (!lconst
) return E_OUTOFMEMORY
;
865 lconst
->idx
= ins
.dst
[0].reg
.idx
[0].offset
;
866 memcpy(lconst
->value
, ins
.src
[0].reg
.immconst_data
, sizeof(DWORD
));
868 list_add_head(&shader
->constantsB
, &lconst
->entry
);
869 reg_maps
->local_bool_consts
|= (1 << lconst
->idx
);
871 /* For subroutine prototypes. */
872 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
874 reg_maps
->labels
|= 1 << ins
.src
[0].reg
.idx
[0].offset
;
876 /* Set texture, address, temporary registers. */
879 BOOL color0_mov
= FALSE
;
882 /* This will loop over all the registers and try to
883 * make a bitmask of the ones we're interested in.
885 * Relative addressing tokens are ignored, but that's
886 * okay, since we'll catch any address registers when
887 * they are initialized (required by spec). */
888 for (i
= 0; i
< ins
.dst_count
; ++i
)
890 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.dst
[i
].reg
,
891 shader_version
.type
, constf_size
))
892 return WINED3DERR_INVALIDCALL
;
894 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
895 * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
896 * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
897 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
&& shader_version
.major
< 3)
899 UINT idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
901 switch (ins
.dst
[i
].reg
.type
)
903 case WINED3DSPR_RASTOUT
:
907 reg_maps
->output_registers
|= 1 << 10;
908 shader_signature_from_usage(&output_signature_elements
[10],
909 WINED3D_DECL_USAGE_POSITION
, 0, 10, WINED3DSP_WRITEMASK_ALL
);
913 reg_maps
->output_registers
|= 1 << 11;
914 shader_signature_from_usage(&output_signature_elements
[11],
915 WINED3D_DECL_USAGE_FOG
, 0, 11, WINED3DSP_WRITEMASK_0
);
919 reg_maps
->output_registers
|= 1 << 11;
920 shader_signature_from_usage(&output_signature_elements
[11],
921 WINED3D_DECL_USAGE_PSIZE
, 0, 11, WINED3DSP_WRITEMASK_1
);
926 case WINED3DSPR_ATTROUT
:
930 if (reg_maps
->output_registers
& (1 << idx
))
932 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
936 reg_maps
->output_registers
|= 1 << idx
;
937 shader_signature_from_usage(&output_signature_elements
[idx
],
938 WINED3D_DECL_USAGE_COLOR
, idx
- 8, idx
, ins
.dst
[i
].write_mask
);
943 case WINED3DSPR_TEXCRDOUT
:
945 reg_maps
->texcoord_mask
[idx
] |= ins
.dst
[i
].write_mask
;
946 if (reg_maps
->output_registers
& (1 << idx
))
948 output_signature_elements
[idx
].mask
|= ins
.dst
[i
].write_mask
;
952 reg_maps
->output_registers
|= 1 << idx
;
953 shader_signature_from_usage(&output_signature_elements
[idx
],
954 WINED3D_DECL_USAGE_TEXCOORD
, idx
, idx
, ins
.dst
[i
].write_mask
);
963 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
965 if (ins
.dst
[i
].reg
.type
== WINED3DSPR_COLOROUT
&& !ins
.dst
[i
].reg
.idx
[0].offset
)
967 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
968 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
969 * the mov and perform the sRGB write correction from the source register.
971 * However, if the mov is only partial, we can't do this, and if the write
972 * comes from an instruction other than MOV it is hard to do as well. If
973 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
974 shader
->u
.ps
.color0_mov
= FALSE
;
975 if (ins
.handler_idx
== WINED3DSIH_MOV
976 && ins
.dst
[i
].write_mask
== WINED3DSP_WRITEMASK_ALL
)
978 /* Used later when the source register is read. */
982 /* Also drop the MOV marker if the source register is overwritten prior to the shader
985 else if (ins
.dst
[i
].reg
.type
== WINED3DSPR_TEMP
986 && ins
.dst
[i
].reg
.idx
[0].offset
== shader
->u
.ps
.color0_reg
)
988 shader
->u
.ps
.color0_mov
= FALSE
;
992 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
993 if (shader_version
.major
== 1
994 && (ins
.handler_idx
== WINED3DSIH_TEX
995 || ins
.handler_idx
== WINED3DSIH_TEXBEM
996 || ins
.handler_idx
== WINED3DSIH_TEXBEML
997 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
998 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
999 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
1000 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
1001 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
1002 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
1003 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
1004 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
1006 unsigned int reg_idx
= ins
.dst
[i
].reg
.idx
[0].offset
;
1008 TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
1009 reg_maps
->resource_info
[reg_idx
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
1010 reg_maps
->resource_info
[reg_idx
].data_type
= WINED3D_DATA_FLOAT
;
1011 shader_record_sample(reg_maps
, reg_idx
, reg_idx
, reg_idx
);
1013 /* texbem is only valid with < 1.4 pixel shaders */
1014 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
1015 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1017 reg_maps
->bumpmat
|= 1 << reg_idx
;
1018 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
1020 reg_maps
->luminanceparams
|= 1 << reg_idx
;
1024 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
1026 reg_maps
->bumpmat
|= 1 << ins
.dst
[i
].reg
.idx
[0].offset
;
1030 if (ins
.handler_idx
== WINED3DSIH_NRM
) reg_maps
->usesnrm
= 1;
1031 else if (ins
.handler_idx
== WINED3DSIH_DSY
) reg_maps
->usesdsy
= 1;
1032 else if (ins
.handler_idx
== WINED3DSIH_DSX
) reg_maps
->usesdsx
= 1;
1033 else if (ins
.handler_idx
== WINED3DSIH_TEXLDD
) reg_maps
->usestexldd
= 1;
1034 else if (ins
.handler_idx
== WINED3DSIH_TEXLDL
) reg_maps
->usestexldl
= 1;
1035 else if (ins
.handler_idx
== WINED3DSIH_MOVA
) reg_maps
->usesmova
= 1;
1036 else if (ins
.handler_idx
== WINED3DSIH_IFC
) reg_maps
->usesifc
= 1;
1037 else if (ins
.handler_idx
== WINED3DSIH_CALL
) reg_maps
->usescall
= 1;
1038 else if (ins
.handler_idx
== WINED3DSIH_POW
) reg_maps
->usespow
= 1;
1039 else if (ins
.handler_idx
== WINED3DSIH_LOOP
1040 || ins
.handler_idx
== WINED3DSIH_REP
)
1043 if (cur_loop_depth
> max_loop_depth
)
1044 max_loop_depth
= cur_loop_depth
;
1046 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
1047 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
1051 else if (ins
.handler_idx
== WINED3DSIH_SAMPLE
1052 || ins
.handler_idx
== WINED3DSIH_SAMPLE_GRAD
1053 || ins
.handler_idx
== WINED3DSIH_SAMPLE_LOD
)
1055 shader_record_sample(reg_maps
, ins
.src
[1].reg
.idx
[0].offset
,
1056 ins
.src
[2].reg
.idx
[0].offset
, reg_maps
->sampler_map
.count
);
1060 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.predicate
->reg
,
1061 shader_version
.type
, constf_size
))
1062 return WINED3DERR_INVALIDCALL
;
1064 for (i
= 0; i
< ins
.src_count
; ++i
)
1066 unsigned int count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
1067 struct wined3d_shader_register reg
= ins
.src
[i
].reg
;
1069 if (!shader_record_register_usage(shader
, reg_maps
, &ins
.src
[i
].reg
,
1070 shader_version
.type
, constf_size
))
1071 return WINED3DERR_INVALIDCALL
;
1074 ++reg
.idx
[0].offset
;
1075 if (!shader_record_register_usage(shader
, reg_maps
, ®
,
1076 shader_version
.type
, constf_size
))
1077 return WINED3DERR_INVALIDCALL
;
1083 if (ins
.src
[i
].reg
.type
== WINED3DSPR_TEMP
1084 && ins
.src
[i
].swizzle
== WINED3DSP_NOSWIZZLE
)
1086 shader
->u
.ps
.color0_mov
= TRUE
;
1087 shader
->u
.ps
.color0_reg
= ins
.src
[i
].reg
.idx
[0].offset
;
1093 reg_maps
->loop_depth
= max_loop_depth
;
1095 /* PS before 2.0 don't have explicit color outputs. Instead the value of
1096 * R0 is written to the render target. */
1097 if (shader_version
.major
< 2 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
1098 reg_maps
->rt_mask
|= (1 << 0);
1100 shader
->functionLength
= ((const char *)ptr
- (const char *)byte_code
);
1102 if (input_signature
->elements
)
1104 for (i
= 0; i
< input_signature
->element_count
; ++i
)
1106 reg_maps
->input_registers
|= 1 << input_signature
->elements
[i
].register_idx
;
1107 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
1108 && input_signature
->elements
[i
].sysval_semantic
== WINED3D_SV_POSITION
)
1112 else if (!input_signature
->elements
&& reg_maps
->input_registers
)
1114 unsigned int count
= count_bits(reg_maps
->input_registers
);
1115 struct wined3d_shader_signature_element
*e
;
1118 if (!(input_signature
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*input_signature
->elements
) * count
)))
1119 return E_OUTOFMEMORY
;
1120 input_signature
->element_count
= count
;
1122 e
= input_signature
->elements
;
1123 for (i
= 0; i
< ARRAY_SIZE(input_signature_elements
); ++i
)
1125 if (!(reg_maps
->input_registers
& (1 << i
)))
1127 input_signature_elements
[i
].register_idx
= i
;
1128 *e
++ = input_signature_elements
[i
];
1132 if (output_signature
->elements
)
1134 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1136 reg_maps
->output_registers
|= 1 << output_signature
->elements
[i
].register_idx
;
1139 else if (reg_maps
->output_registers
)
1141 unsigned int count
= count_bits(reg_maps
->output_registers
);
1142 struct wined3d_shader_signature_element
*e
;
1144 if (!(output_signature
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*output_signature
->elements
) * count
)))
1145 return E_OUTOFMEMORY
;
1146 output_signature
->element_count
= count
;
1148 e
= output_signature
->elements
;
1149 for (i
= 0; i
< ARRAY_SIZE(output_signature_elements
); ++i
)
1151 if (!(reg_maps
->output_registers
& (1 << i
)))
1153 *e
++ = output_signature_elements
[i
];
1160 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps
*reg_maps
, unsigned int max
)
1162 DWORD map
= 1 << max
;
1164 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
1166 return wined3d_log2i(map
);
1169 static void shader_dump_decl_usage(const struct wined3d_shader_semantic
*semantic
,
1170 const struct wined3d_shader_version
*shader_version
)
1174 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
1176 switch (semantic
->resource_type
)
1178 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1182 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1186 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1191 TRACE("_unknown_ttype(0x%08x)", semantic
->resource_type
);
1195 else if (semantic
->reg
.reg
.type
== WINED3DSPR_RESOURCE
)
1197 TRACE("_resource_");
1198 switch (semantic
->resource_type
)
1200 case WINED3D_SHADER_RESOURCE_BUFFER
:
1204 case WINED3D_SHADER_RESOURCE_TEXTURE_1D
:
1208 case WINED3D_SHADER_RESOURCE_TEXTURE_2D
:
1212 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
:
1213 TRACE("texture2dms");
1216 case WINED3D_SHADER_RESOURCE_TEXTURE_3D
:
1220 case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
:
1221 TRACE("texturecube");
1224 case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
:
1225 TRACE("texture1darray");
1228 case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
:
1229 TRACE("texture2darray");
1232 case WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
:
1233 TRACE("texture2dmsarray");
1240 switch (semantic
->resource_data_type
)
1242 case WINED3D_DATA_FLOAT
:
1246 case WINED3D_DATA_INT
:
1250 case WINED3D_DATA_UINT
:
1254 case WINED3D_DATA_UNORM
:
1258 case WINED3D_DATA_SNORM
:
1263 TRACE(" (unknown)");
1269 /* Pixel shaders 3.0 don't have usage semantics. */
1270 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
) return;
1273 switch (semantic
->usage
)
1275 case WINED3D_DECL_USAGE_POSITION
:
1276 TRACE("position%u", semantic
->usage_idx
);
1279 case WINED3D_DECL_USAGE_BLEND_INDICES
:
1283 case WINED3D_DECL_USAGE_BLEND_WEIGHT
:
1287 case WINED3D_DECL_USAGE_NORMAL
:
1288 TRACE("normal%u", semantic
->usage_idx
);
1291 case WINED3D_DECL_USAGE_PSIZE
:
1295 case WINED3D_DECL_USAGE_COLOR
:
1296 if (!semantic
->usage_idx
) TRACE("color");
1297 else TRACE("specular%u", (semantic
->usage_idx
- 1));
1300 case WINED3D_DECL_USAGE_TEXCOORD
:
1301 TRACE("texture%u", semantic
->usage_idx
);
1304 case WINED3D_DECL_USAGE_TANGENT
:
1308 case WINED3D_DECL_USAGE_BINORMAL
:
1312 case WINED3D_DECL_USAGE_TESS_FACTOR
:
1313 TRACE("tessfactor");
1316 case WINED3D_DECL_USAGE_POSITIONT
:
1317 TRACE("positionT%u", semantic
->usage_idx
);
1320 case WINED3D_DECL_USAGE_FOG
:
1324 case WINED3D_DECL_USAGE_DEPTH
:
1328 case WINED3D_DECL_USAGE_SAMPLE
:
1333 FIXME("unknown_semantics(0x%08x)", semantic
->usage
);
1338 static void shader_dump_register(const struct wined3d_shader_register
*reg
,
1339 const struct wined3d_shader_version
*shader_version
)
1341 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
1342 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
1343 UINT offset
= reg
->idx
[0].offset
;
1347 case WINED3DSPR_TEMP
:
1351 case WINED3DSPR_INPUT
:
1355 case WINED3DSPR_CONST
:
1356 case WINED3DSPR_CONST2
:
1357 case WINED3DSPR_CONST3
:
1358 case WINED3DSPR_CONST4
:
1360 offset
= shader_get_float_offset(reg
->type
, offset
);
1363 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
1364 TRACE("%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
1367 case WINED3DSPR_RASTOUT
:
1368 TRACE("%s", rastout_reg_names
[offset
]);
1371 case WINED3DSPR_COLOROUT
:
1375 case WINED3DSPR_DEPTHOUT
:
1379 case WINED3DSPR_ATTROUT
:
1383 case WINED3DSPR_TEXCRDOUT
:
1384 /* Vertex shaders >= 3.0 use general purpose output registers
1385 * (WINED3DSPR_OUTPUT), which can include an address token. */
1386 if (shader_version
->major
>= 3) TRACE("o");
1390 case WINED3DSPR_CONSTINT
:
1394 case WINED3DSPR_CONSTBOOL
:
1398 case WINED3DSPR_LABEL
:
1402 case WINED3DSPR_LOOP
:
1406 case WINED3DSPR_SAMPLER
:
1410 case WINED3DSPR_MISCTYPE
:
1412 FIXME("Unhandled misctype register %u.\n", offset
);
1414 TRACE("%s", misctype_reg_names
[offset
]);
1417 case WINED3DSPR_PREDICATE
:
1421 case WINED3DSPR_IMMCONST
:
1425 case WINED3DSPR_CONSTBUFFER
:
1429 case WINED3DSPR_PRIMID
:
1433 case WINED3DSPR_NULL
:
1437 case WINED3DSPR_RESOURCE
:
1442 TRACE("unhandled_rtype(%#x)", reg
->type
);
1446 if (reg
->type
== WINED3DSPR_IMMCONST
)
1449 switch (reg
->immconst_type
)
1451 case WINED3D_IMMCONST_SCALAR
:
1452 switch (reg
->data_type
)
1454 case WINED3D_DATA_FLOAT
:
1455 TRACE("%.8e", *(const float *)reg
->immconst_data
);
1457 case WINED3D_DATA_INT
:
1458 TRACE("%d", reg
->immconst_data
[0]);
1460 case WINED3D_DATA_RESOURCE
:
1461 case WINED3D_DATA_SAMPLER
:
1462 case WINED3D_DATA_UINT
:
1463 TRACE("%u", reg
->immconst_data
[0]);
1466 TRACE("<unhandled data type %#x>", reg
->data_type
);
1471 case WINED3D_IMMCONST_VEC4
:
1472 switch (reg
->data_type
)
1474 case WINED3D_DATA_FLOAT
:
1475 TRACE("%.8e, %.8e, %.8e, %.8e",
1476 *(const float *)®
->immconst_data
[0], *(const float *)®
->immconst_data
[1],
1477 *(const float *)®
->immconst_data
[2], *(const float *)®
->immconst_data
[3]);
1479 case WINED3D_DATA_INT
:
1480 TRACE("%d, %d, %d, %d",
1481 reg
->immconst_data
[0], reg
->immconst_data
[1],
1482 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1484 case WINED3D_DATA_RESOURCE
:
1485 case WINED3D_DATA_SAMPLER
:
1486 case WINED3D_DATA_UINT
:
1487 TRACE("%u, %u, %u, %u",
1488 reg
->immconst_data
[0], reg
->immconst_data
[1],
1489 reg
->immconst_data
[2], reg
->immconst_data
[3]);
1492 TRACE("<unhandled data type %#x>", reg
->data_type
);
1498 TRACE("<unhandled immconst_type %#x>", reg
->immconst_type
);
1503 else if (reg
->type
!= WINED3DSPR_RASTOUT
1504 && reg
->type
!= WINED3DSPR_MISCTYPE
1505 && reg
->type
!= WINED3DSPR_NULL
)
1510 if (reg
->idx
[0].rel_addr
)
1512 shader_dump_src_param(reg
->idx
[0].rel_addr
, shader_version
);
1515 TRACE("%u]", offset
);
1517 if (reg
->idx
[1].offset
!= ~0U)
1520 if (reg
->idx
[1].rel_addr
)
1522 shader_dump_src_param(reg
->idx
[1].rel_addr
, shader_version
);
1525 TRACE("%u]", reg
->idx
[1].offset
);
1531 void shader_dump_dst_param(const struct wined3d_shader_dst_param
*param
,
1532 const struct wined3d_shader_version
*shader_version
)
1534 DWORD write_mask
= param
->write_mask
;
1536 shader_dump_register(¶m
->reg
, shader_version
);
1538 if (write_mask
&& write_mask
!= WINED3DSP_WRITEMASK_ALL
)
1540 static const char write_mask_chars
[] = "xyzw";
1543 if (write_mask
& WINED3DSP_WRITEMASK_0
) TRACE("%c", write_mask_chars
[0]);
1544 if (write_mask
& WINED3DSP_WRITEMASK_1
) TRACE("%c", write_mask_chars
[1]);
1545 if (write_mask
& WINED3DSP_WRITEMASK_2
) TRACE("%c", write_mask_chars
[2]);
1546 if (write_mask
& WINED3DSP_WRITEMASK_3
) TRACE("%c", write_mask_chars
[3]);
1550 void shader_dump_src_param(const struct wined3d_shader_src_param
*param
,
1551 const struct wined3d_shader_version
*shader_version
)
1553 enum wined3d_shader_src_modifier src_modifier
= param
->modifiers
;
1554 DWORD swizzle
= param
->swizzle
;
1556 if (src_modifier
== WINED3DSPSM_NEG
1557 || src_modifier
== WINED3DSPSM_BIASNEG
1558 || src_modifier
== WINED3DSPSM_SIGNNEG
1559 || src_modifier
== WINED3DSPSM_X2NEG
1560 || src_modifier
== WINED3DSPSM_ABSNEG
)
1562 else if (src_modifier
== WINED3DSPSM_COMP
)
1564 else if (src_modifier
== WINED3DSPSM_NOT
)
1567 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
1570 shader_dump_register(¶m
->reg
, shader_version
);
1574 switch (src_modifier
)
1576 case WINED3DSPSM_NONE
: break;
1577 case WINED3DSPSM_NEG
: break;
1578 case WINED3DSPSM_NOT
: break;
1579 case WINED3DSPSM_BIAS
: TRACE("_bias"); break;
1580 case WINED3DSPSM_BIASNEG
: TRACE("_bias"); break;
1581 case WINED3DSPSM_SIGN
: TRACE("_bx2"); break;
1582 case WINED3DSPSM_SIGNNEG
: TRACE("_bx2"); break;
1583 case WINED3DSPSM_COMP
: break;
1584 case WINED3DSPSM_X2
: TRACE("_x2"); break;
1585 case WINED3DSPSM_X2NEG
: TRACE("_x2"); break;
1586 case WINED3DSPSM_DZ
: TRACE("_dz"); break;
1587 case WINED3DSPSM_DW
: TRACE("_dw"); break;
1588 case WINED3DSPSM_ABSNEG
: TRACE(")"); break;
1589 case WINED3DSPSM_ABS
: TRACE(")"); break;
1590 default: TRACE("_unknown_modifier(%#x)", src_modifier
);
1594 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
1596 static const char swizzle_chars
[] = "xyzw";
1597 DWORD swizzle_x
= swizzle
& 0x03;
1598 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
1599 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
1600 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
1602 if (swizzle_x
== swizzle_y
1603 && swizzle_x
== swizzle_z
1604 && swizzle_x
== swizzle_w
)
1606 TRACE(".%c", swizzle_chars
[swizzle_x
]);
1610 TRACE(".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
1611 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
1616 /* Shared code in order to generate the bulk of the shader string.
1617 * NOTE: A description of how to parse tokens can be found on MSDN. */
1618 void shader_generate_main(const struct wined3d_shader
*shader
, struct wined3d_string_buffer
*buffer
,
1619 const struct wined3d_shader_reg_maps
*reg_maps
, const DWORD
*byte_code
, void *backend_ctx
)
1621 struct wined3d_device
*device
= shader
->device
;
1622 const struct wined3d_shader_frontend
*fe
= shader
->frontend
;
1623 void *fe_data
= shader
->frontend_data
;
1624 struct wined3d_shader_version shader_version
;
1625 struct wined3d_shader_loop_state loop_state
;
1626 struct wined3d_shader_instruction ins
;
1627 struct wined3d_shader_tex_mx tex_mx
;
1628 struct wined3d_shader_context ctx
;
1629 const DWORD
*ptr
= byte_code
;
1631 /* Initialize current parsing state. */
1632 tex_mx
.current_row
= 0;
1633 loop_state
.current_depth
= 0;
1634 loop_state
.current_reg
= 0;
1636 ctx
.shader
= shader
;
1637 ctx
.gl_info
= &device
->adapter
->gl_info
;
1638 ctx
.reg_maps
= reg_maps
;
1639 ctx
.buffer
= buffer
;
1640 ctx
.tex_mx
= &tex_mx
;
1641 ctx
.loop_state
= &loop_state
;
1642 ctx
.backend_data
= backend_ctx
;
1645 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1647 while (!fe
->shader_is_end(fe_data
, &ptr
))
1650 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1652 /* Unknown opcode and its parameters. */
1653 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1655 TRACE("Skipping unrecognized instruction.\n");
1660 FIXME("Predicates not implemented.\n");
1662 /* Call appropriate function for output target */
1663 device
->shader_backend
->shader_handle_instruction(&ins
);
1667 static void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param
*dst
)
1669 DWORD mmask
= dst
->modifiers
;
1674 case 13: TRACE("_d8"); break;
1675 case 14: TRACE("_d4"); break;
1676 case 15: TRACE("_d2"); break;
1677 case 1: TRACE("_x2"); break;
1678 case 2: TRACE("_x4"); break;
1679 case 3: TRACE("_x8"); break;
1680 default: TRACE("_unhandled_shift(%d)", dst
->shift
); break;
1683 if (mmask
& WINED3DSPDM_SATURATE
) TRACE("_sat");
1684 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) TRACE("_pp");
1685 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) TRACE("_centroid");
1687 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
1688 if (mmask
) FIXME("_unrecognized_modifier(%#x)", mmask
);
1691 static void shader_dump_primitive_type(enum wined3d_primitive_type primitive_type
)
1693 switch (primitive_type
)
1695 case WINED3D_PT_UNDEFINED
:
1698 case WINED3D_PT_POINTLIST
:
1701 case WINED3D_PT_LINELIST
:
1704 case WINED3D_PT_LINESTRIP
:
1707 case WINED3D_PT_TRIANGLELIST
:
1708 TRACE("trianglelist");
1710 case WINED3D_PT_TRIANGLESTRIP
:
1711 TRACE("trianglestrip");
1713 case WINED3D_PT_TRIANGLEFAN
:
1714 TRACE("trianglefan");
1716 case WINED3D_PT_LINELIST_ADJ
:
1717 TRACE("linelist_adj");
1719 case WINED3D_PT_LINESTRIP_ADJ
:
1720 TRACE("linestrip_adj");
1722 case WINED3D_PT_TRIANGLELIST_ADJ
:
1723 TRACE("trianglelist_adj");
1725 case WINED3D_PT_TRIANGLESTRIP_ADJ
:
1726 TRACE("trianglestrip_adj");
1729 TRACE("<unrecognized_primitive_type %#x>", primitive_type
);
1734 static void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*byte_code
)
1736 struct wined3d_shader_version shader_version
;
1737 const DWORD
*ptr
= byte_code
;
1738 const char *type_prefix
;
1741 TRACE("Parsing %p.\n", byte_code
);
1743 fe
->shader_read_header(fe_data
, &ptr
, &shader_version
);
1745 switch (shader_version
.type
)
1747 case WINED3D_SHADER_TYPE_VERTEX
:
1751 case WINED3D_SHADER_TYPE_GEOMETRY
:
1755 case WINED3D_SHADER_TYPE_PIXEL
:
1760 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
1761 type_prefix
= "unknown";
1765 TRACE("%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
1767 while (!fe
->shader_is_end(fe_data
, &ptr
))
1769 struct wined3d_shader_instruction ins
;
1771 fe
->shader_read_instruction(fe_data
, &ptr
, &ins
);
1772 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1774 TRACE("Skipping unrecognized instruction.\n");
1778 if (ins
.handler_idx
== WINED3DSIH_DCL
)
1780 shader_dump_decl_usage(&ins
.declaration
.semantic
, &shader_version
);
1781 shader_dump_ins_modifiers(&ins
.declaration
.semantic
.reg
);
1783 shader_dump_dst_param(&ins
.declaration
.semantic
.reg
, &shader_version
);
1785 else if (ins
.handler_idx
== WINED3DSIH_DCL_CONSTANT_BUFFER
)
1787 TRACE("%s ", shader_opcode_names
[ins
.handler_idx
]);
1788 shader_dump_src_param(&ins
.declaration
.src
, &shader_version
);
1789 TRACE(", %s", ins
.flags
& WINED3DSI_INDEXED_DYNAMIC
? "dynamicIndexed" : "immediateIndexed");
1791 else if (ins
.handler_idx
== WINED3DSIH_DCL_INPUT_PRIMITIVE
1792 || ins
.handler_idx
== WINED3DSIH_DCL_OUTPUT_TOPOLOGY
)
1794 TRACE("%s ", shader_opcode_names
[ins
.handler_idx
]);
1795 shader_dump_primitive_type(ins
.declaration
.primitive_type
);
1797 else if (ins
.handler_idx
== WINED3DSIH_DCL_VERTICES_OUT
)
1799 TRACE("%s %u", shader_opcode_names
[ins
.handler_idx
], ins
.declaration
.count
);
1801 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1803 TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(ins
.dst
[0].reg
.type
,
1804 ins
.dst
[0].reg
.idx
[0].offset
),
1805 *(const float *)&ins
.src
[0].reg
.immconst_data
[0],
1806 *(const float *)&ins
.src
[0].reg
.immconst_data
[1],
1807 *(const float *)&ins
.src
[0].reg
.immconst_data
[2],
1808 *(const float *)&ins
.src
[0].reg
.immconst_data
[3]);
1810 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1812 TRACE("defi i%u = %d, %d, %d, %d", ins
.dst
[0].reg
.idx
[0].offset
,
1813 ins
.src
[0].reg
.immconst_data
[0],
1814 ins
.src
[0].reg
.immconst_data
[1],
1815 ins
.src
[0].reg
.immconst_data
[2],
1816 ins
.src
[0].reg
.immconst_data
[3]);
1818 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1820 TRACE("defb b%u = %s", ins
.dst
[0].reg
.idx
[0].offset
, ins
.src
[0].reg
.immconst_data
[0] ? "true" : "false");
1827 shader_dump_src_param(ins
.predicate
, &shader_version
);
1831 /* PixWin marks instructions with the coissue flag with a '+' */
1832 if (ins
.coissue
) TRACE("+");
1834 TRACE("%s", shader_opcode_names
[ins
.handler_idx
]);
1836 if (ins
.handler_idx
== WINED3DSIH_IFC
1837 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
1841 case WINED3D_SHADER_REL_OP_GT
: TRACE("_gt"); break;
1842 case WINED3D_SHADER_REL_OP_EQ
: TRACE("_eq"); break;
1843 case WINED3D_SHADER_REL_OP_GE
: TRACE("_ge"); break;
1844 case WINED3D_SHADER_REL_OP_LT
: TRACE("_lt"); break;
1845 case WINED3D_SHADER_REL_OP_NE
: TRACE("_ne"); break;
1846 case WINED3D_SHADER_REL_OP_LE
: TRACE("_le"); break;
1847 default: TRACE("_(%u)", ins
.flags
);
1850 else if (ins
.handler_idx
== WINED3DSIH_TEX
1851 && shader_version
.major
>= 2
1852 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
1857 for (i
= 0; i
< ins
.dst_count
; ++i
)
1859 shader_dump_ins_modifiers(&ins
.dst
[i
]);
1860 TRACE(!i
? " " : ", ");
1861 shader_dump_dst_param(&ins
.dst
[i
], &shader_version
);
1864 /* Other source tokens */
1865 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
1867 TRACE(!i
? " " : ", ");
1868 shader_dump_src_param(&ins
.src
[i
- ins
.dst_count
], &shader_version
);
1875 static void shader_cleanup(struct wined3d_shader
*shader
)
1877 HeapFree(GetProcessHeap(), 0, shader
->output_signature
.elements
);
1878 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
1879 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
1880 shader
->device
->shader_backend
->shader_destroy(shader
);
1881 HeapFree(GetProcessHeap(), 0, shader
->reg_maps
.constf
);
1882 HeapFree(GetProcessHeap(), 0, shader
->reg_maps
.sampler_map
.entries
);
1883 HeapFree(GetProcessHeap(), 0, shader
->function
);
1884 shader_delete_constant_list(&shader
->constantsF
);
1885 shader_delete_constant_list(&shader
->constantsB
);
1886 shader_delete_constant_list(&shader
->constantsI
);
1887 list_remove(&shader
->shader_list_entry
);
1889 if (shader
->frontend
&& shader
->frontend_data
)
1890 shader
->frontend
->shader_free(shader
->frontend_data
);
1893 struct shader_none_priv
1895 const struct wined3d_vertex_pipe_ops
*vertex_pipe
;
1896 const struct fragment_pipeline
*fragment_pipe
;
1897 BOOL ffp_proj_control
;
1900 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
1901 static void shader_none_select_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
,
1902 enum wined3d_gl_resource_type tex_type
, const SIZE
*ds_mask_size
) {}
1903 static void shader_none_deselect_depth_blt(void *shader_priv
, const struct wined3d_gl_info
*gl_info
) {}
1904 static void shader_none_update_float_vertex_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
1905 static void shader_none_update_float_pixel_constants(struct wined3d_device
*device
, UINT start
, UINT count
) {}
1906 static void shader_none_load_constants(void *shader_priv
, struct wined3d_context
*context
,
1907 const struct wined3d_state
*state
) {}
1908 static void shader_none_destroy(struct wined3d_shader
*shader
) {}
1909 static void shader_none_free_context_data(struct wined3d_context
*context
) {}
1911 /* Context activation is done by the caller. */
1912 static void shader_none_select(void *shader_priv
, struct wined3d_context
*context
,
1913 const struct wined3d_state
*state
)
1915 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
1916 struct shader_none_priv
*priv
= shader_priv
;
1918 priv
->vertex_pipe
->vp_enable(gl_info
, !use_vs(state
));
1919 priv
->fragment_pipe
->enable_extension(gl_info
, !use_ps(state
));
1922 /* Context activation is done by the caller. */
1923 static void shader_none_disable(void *shader_priv
, struct wined3d_context
*context
)
1925 struct shader_none_priv
*priv
= shader_priv
;
1926 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
1928 priv
->vertex_pipe
->vp_enable(gl_info
, FALSE
);
1929 priv
->fragment_pipe
->enable_extension(gl_info
, FALSE
);
1931 context
->shader_update_mask
= (1 << WINED3D_SHADER_TYPE_PIXEL
)
1932 | (1 << WINED3D_SHADER_TYPE_VERTEX
)
1933 | (1 << WINED3D_SHADER_TYPE_GEOMETRY
);
1936 static HRESULT
shader_none_alloc(struct wined3d_device
*device
, const struct wined3d_vertex_pipe_ops
*vertex_pipe
,
1937 const struct fragment_pipeline
*fragment_pipe
)
1939 struct fragment_caps fragment_caps
;
1940 void *vertex_priv
, *fragment_priv
;
1941 struct shader_none_priv
*priv
;
1943 if (!(priv
= HeapAlloc(GetProcessHeap(), 0, sizeof(*priv
))))
1944 return E_OUTOFMEMORY
;
1946 if (!(vertex_priv
= vertex_pipe
->vp_alloc(&none_shader_backend
, priv
)))
1948 ERR("Failed to initialize vertex pipe.\n");
1949 HeapFree(GetProcessHeap(), 0, priv
);
1953 if (!(fragment_priv
= fragment_pipe
->alloc_private(&none_shader_backend
, priv
)))
1955 ERR("Failed to initialize fragment pipe.\n");
1956 vertex_pipe
->vp_free(device
);
1957 HeapFree(GetProcessHeap(), 0, priv
);
1961 priv
->vertex_pipe
= vertex_pipe
;
1962 priv
->fragment_pipe
= fragment_pipe
;
1963 fragment_pipe
->get_caps(&device
->adapter
->gl_info
, &fragment_caps
);
1964 priv
->ffp_proj_control
= fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_PROJ_CONTROL
;
1966 device
->vertex_priv
= vertex_priv
;
1967 device
->fragment_priv
= fragment_priv
;
1968 device
->shader_priv
= priv
;
1973 static void shader_none_free(struct wined3d_device
*device
)
1975 struct shader_none_priv
*priv
= device
->shader_priv
;
1977 priv
->fragment_pipe
->free_private(device
);
1978 priv
->vertex_pipe
->vp_free(device
);
1979 HeapFree(GetProcessHeap(), 0, priv
);
1982 static BOOL
shader_none_allocate_context_data(struct wined3d_context
*context
)
1987 static void shader_none_get_caps(const struct wined3d_gl_info
*gl_info
, struct shader_caps
*caps
)
1989 /* Set the shader caps to 0 for the none shader backend */
1990 caps
->vs_version
= 0;
1991 caps
->gs_version
= 0;
1992 caps
->ps_version
= 0;
1993 caps
->vs_uniform_count
= 0;
1994 caps
->ps_uniform_count
= 0;
1995 caps
->ps_1x_max_value
= 0.0f
;
1996 caps
->wined3d_caps
= 0;
1999 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
2001 /* We "support" every possible fixup, since we don't support any shader
2002 * model, and will never have to actually sample a texture. */
2006 static BOOL
shader_none_has_ffp_proj_control(void *shader_priv
)
2008 struct shader_none_priv
*priv
= shader_priv
;
2010 return priv
->ffp_proj_control
;
2013 const struct wined3d_shader_backend_ops none_shader_backend
=
2015 shader_none_handle_instruction
,
2017 shader_none_disable
,
2018 shader_none_select_depth_blt
,
2019 shader_none_deselect_depth_blt
,
2020 shader_none_update_float_vertex_constants
,
2021 shader_none_update_float_pixel_constants
,
2022 shader_none_load_constants
,
2023 shader_none_destroy
,
2026 shader_none_allocate_context_data
,
2027 shader_none_free_context_data
,
2028 shader_none_get_caps
,
2029 shader_none_color_fixup_supported
,
2030 shader_none_has_ffp_proj_control
,
2033 static HRESULT
shader_set_function(struct wined3d_shader
*shader
, const DWORD
*byte_code
,
2034 const struct wined3d_shader_signature
*output_signature
, DWORD float_const_count
,
2035 enum wined3d_shader_type type
, unsigned int max_version
)
2037 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2038 const struct wined3d_shader_frontend
*fe
;
2040 unsigned int backend_version
;
2041 const struct wined3d_d3d_info
*d3d_info
= &shader
->device
->adapter
->d3d_info
;
2043 TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u.\n",
2044 shader
, byte_code
, output_signature
, float_const_count
);
2046 fe
= shader_select_frontend(*byte_code
);
2049 FIXME("Unable to find frontend for shader.\n");
2050 return WINED3DERR_INVALIDCALL
;
2052 shader
->frontend
= fe
;
2053 shader
->frontend_data
= fe
->shader_init(byte_code
, output_signature
);
2054 if (!shader
->frontend_data
)
2056 FIXME("Failed to initialize frontend.\n");
2057 return WINED3DERR_INVALIDCALL
;
2060 /* First pass: trace shader. */
2061 if (TRACE_ON(d3d_shader
))
2062 shader_trace_init(fe
, shader
->frontend_data
, byte_code
);
2064 /* Initialize immediate constant lists. */
2065 list_init(&shader
->constantsF
);
2066 list_init(&shader
->constantsB
);
2067 list_init(&shader
->constantsI
);
2068 shader
->lconst_inf_or_nan
= FALSE
;
2070 /* Second pass: figure out which registers are used, what the semantics are, etc. */
2071 if (FAILED(hr
= shader_get_registers_used(shader
, fe
, reg_maps
, &shader
->input_signature
,
2072 &shader
->output_signature
, byte_code
, float_const_count
)))
2075 if (reg_maps
->shader_version
.type
!= type
)
2077 WARN("Wrong shader type %d.\n", reg_maps
->shader_version
.type
);
2078 return WINED3DERR_INVALIDCALL
;
2080 if (reg_maps
->shader_version
.major
> max_version
)
2082 WARN("Shader version %d not supported by this D3D API version.\n", reg_maps
->shader_version
.major
);
2083 return WINED3DERR_INVALIDCALL
;
2087 case WINED3D_SHADER_TYPE_VERTEX
:
2088 backend_version
= d3d_info
->limits
.vs_version
;
2090 case WINED3D_SHADER_TYPE_GEOMETRY
:
2091 backend_version
= d3d_info
->limits
.gs_version
;
2093 case WINED3D_SHADER_TYPE_PIXEL
:
2094 backend_version
= d3d_info
->limits
.ps_version
;
2097 FIXME("No backend version-checking for this shader type\n");
2098 backend_version
= 0;
2100 if (reg_maps
->shader_version
.major
> backend_version
)
2102 WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
2103 reg_maps
->shader_version
.major
, reg_maps
->shader_version
.minor
);
2104 return WINED3DERR_INVALIDCALL
;
2107 shader
->function
= HeapAlloc(GetProcessHeap(), 0, shader
->functionLength
);
2108 if (!shader
->function
)
2109 return E_OUTOFMEMORY
;
2110 memcpy(shader
->function
, byte_code
, shader
->functionLength
);
2115 ULONG CDECL
wined3d_shader_incref(struct wined3d_shader
*shader
)
2117 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
2119 TRACE("%p increasing refcount to %u.\n", shader
, refcount
);
2124 ULONG CDECL
wined3d_shader_decref(struct wined3d_shader
*shader
)
2126 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
2128 TRACE("%p decreasing refcount to %u.\n", shader
, refcount
);
2132 shader_cleanup(shader
);
2133 shader
->parent_ops
->wined3d_object_destroyed(shader
->parent
);
2134 HeapFree(GetProcessHeap(), 0, shader
);
2140 void * CDECL
wined3d_shader_get_parent(const struct wined3d_shader
*shader
)
2142 TRACE("shader %p.\n", shader
);
2144 return shader
->parent
;
2147 HRESULT CDECL
wined3d_shader_get_byte_code(const struct wined3d_shader
*shader
,
2148 void *byte_code
, UINT
*byte_code_size
)
2150 TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader
, byte_code
, byte_code_size
);
2154 *byte_code_size
= shader
->functionLength
;
2158 if (*byte_code_size
< shader
->functionLength
)
2160 /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
2161 * than the required size we should write the required size and
2162 * return D3DERR_MOREDATA. That's not actually true. */
2163 return WINED3DERR_INVALIDCALL
;
2166 memcpy(byte_code
, shader
->function
, shader
->functionLength
);
2171 /* Set local constants for d3d8 shaders. */
2172 HRESULT CDECL
wined3d_shader_set_local_constants_float(struct wined3d_shader
*shader
,
2173 UINT start_idx
, const float *src_data
, UINT count
)
2175 UINT end_idx
= start_idx
+ count
;
2178 TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader
, start_idx
, src_data
, count
);
2180 if (end_idx
> shader
->limits
->constant_float
)
2182 WARN("end_idx %u > float constants limit %u.\n",
2183 end_idx
, shader
->limits
->constant_float
);
2184 end_idx
= shader
->limits
->constant_float
;
2187 for (i
= start_idx
; i
< end_idx
; ++i
)
2189 struct wined3d_shader_lconst
*lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst
));
2192 return E_OUTOFMEMORY
;
2195 value
= (float *)lconst
->value
;
2196 memcpy(value
, src_data
+ (i
- start_idx
) * 4 /* 4 components */, 4 * sizeof(float));
2197 list_add_head(&shader
->constantsF
, &lconst
->entry
);
2199 if (isinf(value
[0]) || isnan(value
[0]) || isinf(value
[1]) || isnan(value
[1])
2200 || isinf(value
[2]) || isnan(value
[2]) || isinf(value
[3]) || isnan(value
[3]))
2202 shader
->lconst_inf_or_nan
= TRUE
;
2209 void find_vs_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2210 WORD swizzle_map
, struct vs_compile_args
*args
)
2212 args
->fog_src
= state
->render_states
[WINED3D_RS_FOGTABLEMODE
]
2213 == WINED3D_FOG_NONE
? VS_FOG_COORD
: VS_FOG_Z
;
2214 args
->clip_enabled
= state
->render_states
[WINED3D_RS_CLIPPING
]
2215 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
2216 args
->swizzle_map
= swizzle_map
;
2219 static BOOL
match_usage(BYTE usage1
, BYTE usage_idx1
, BYTE usage2
, BYTE usage_idx2
)
2221 if (usage_idx1
!= usage_idx2
)
2223 if (usage1
== usage2
)
2225 if (usage1
== WINED3D_DECL_USAGE_POSITION
&& usage2
== WINED3D_DECL_USAGE_POSITIONT
)
2227 if (usage2
== WINED3D_DECL_USAGE_POSITION
&& usage1
== WINED3D_DECL_USAGE_POSITIONT
)
2233 BOOL
vshader_get_input(const struct wined3d_shader
*shader
,
2234 BYTE usage_req
, BYTE usage_idx_req
, unsigned int *regnum
)
2236 WORD map
= shader
->reg_maps
.input_registers
;
2239 for (i
= 0; map
; map
>>= 1, ++i
)
2241 if (!(map
& 1)) continue;
2243 if (match_usage(shader
->u
.vs
.attributes
[i
].usage
,
2244 shader
->u
.vs
.attributes
[i
].usage_idx
, usage_req
, usage_idx_req
))
2253 static HRESULT
shader_signature_copy(struct wined3d_shader_signature
*dst
,
2254 const struct wined3d_shader_signature
*src
, char **signature_strings
)
2256 struct wined3d_shader_signature_element
*e
;
2261 ptr
= *signature_strings
;
2263 dst
->element_count
= src
->element_count
;
2264 if (!(dst
->elements
= HeapAlloc(GetProcessHeap(), 0, sizeof(*dst
->elements
) * dst
->element_count
)))
2265 return E_OUTOFMEMORY
;
2267 for (i
= 0; i
< src
->element_count
; ++i
)
2269 e
= &src
->elements
[i
];
2270 dst
->elements
[i
] = *e
;
2272 len
= strlen(e
->semantic_name
);
2273 memcpy(ptr
, e
->semantic_name
, len
+ 1);
2274 dst
->elements
[i
].semantic_name
= ptr
;
2278 *signature_strings
= ptr
;
2283 static HRESULT
shader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2284 const struct wined3d_shader_desc
*desc
, DWORD float_const_count
, enum wined3d_shader_type type
,
2285 void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2287 struct wined3d_shader_signature_element
*e
;
2293 if (!desc
->byte_code
)
2294 return WINED3DERR_INVALIDCALL
;
2297 shader
->device
= device
;
2298 shader
->parent
= parent
;
2299 shader
->parent_ops
= parent_ops
;
2302 if (desc
->input_signature
)
2304 for (i
= 0; i
< desc
->input_signature
->element_count
; ++i
)
2306 e
= &desc
->input_signature
->elements
[i
];
2307 len
= strlen(e
->semantic_name
);
2308 if (len
>= ~(SIZE_T
)0 - total
)
2309 return E_OUTOFMEMORY
;
2314 if (desc
->output_signature
)
2316 for (i
= 0; i
< desc
->output_signature
->element_count
; ++i
)
2318 e
= &desc
->output_signature
->elements
[i
];
2319 len
= strlen(e
->semantic_name
);
2320 if (len
>= ~(SIZE_T
)0 - total
)
2321 return E_OUTOFMEMORY
;
2326 if (!(shader
->signature_strings
= HeapAlloc(GetProcessHeap(), 0, total
)))
2327 return E_OUTOFMEMORY
;
2328 ptr
= shader
->signature_strings
;
2330 if (desc
->input_signature
&& FAILED(hr
= shader_signature_copy(&shader
->input_signature
,
2331 desc
->input_signature
, &ptr
)))
2333 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2336 if (desc
->output_signature
&& FAILED(hr
= shader_signature_copy(&shader
->output_signature
,
2337 desc
->output_signature
, &ptr
)))
2339 HeapFree(GetProcessHeap(), 0, shader
->input_signature
.elements
);
2340 HeapFree(GetProcessHeap(), 0, shader
->signature_strings
);
2344 list_init(&shader
->linked_programs
);
2345 list_add_head(&device
->shaders
, &shader
->shader_list_entry
);
2347 if (FAILED(hr
= shader_set_function(shader
, desc
->byte_code
, desc
->output_signature
,
2348 float_const_count
, type
, desc
->max_version
)))
2350 WARN("Failed to set function, hr %#x.\n", hr
);
2351 shader_cleanup(shader
);
2357 static HRESULT
vertexshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2358 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2360 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2364 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.vs_uniform_count
,
2365 WINED3D_SHADER_TYPE_VERTEX
, parent
, parent_ops
)))
2368 for (i
= 0; i
< shader
->input_signature
.element_count
; ++i
)
2370 const struct wined3d_shader_signature_element
*input
= &shader
->input_signature
.elements
[i
];
2372 if (!(reg_maps
->input_registers
& (1 << input
->register_idx
)) || !input
->semantic_name
)
2375 shader
->u
.vs
.attributes
[input
->register_idx
].usage
=
2376 shader_usage_from_semantic_name(input
->semantic_name
);
2377 shader
->u
.vs
.attributes
[input
->register_idx
].usage_idx
= input
->semantic_idx
;
2380 shader
->load_local_constsF
= (reg_maps
->usesrelconstF
&& !list_empty(&shader
->constantsF
)) ||
2381 shader
->lconst_inf_or_nan
;
2386 static HRESULT
geometryshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2387 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2391 if (FAILED(hr
= shader_init(shader
, device
, desc
, 0,
2392 WINED3D_SHADER_TYPE_GEOMETRY
, parent
, parent_ops
)))
2395 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2400 void find_ps_compile_args(const struct wined3d_state
*state
, const struct wined3d_shader
*shader
,
2401 BOOL position_transformed
, struct ps_compile_args
*args
, const struct wined3d_gl_info
*gl_info
)
2403 const struct wined3d_texture
*texture
;
2406 memset(args
, 0, sizeof(*args
)); /* FIXME: Make sure all bits are set. */
2407 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && state
->render_states
[WINED3D_RS_SRGBWRITEENABLE
])
2409 unsigned int rt_fmt_flags
= state
->fb
->render_targets
[0]->format_flags
;
2410 if (rt_fmt_flags
& WINED3DFMT_FLAG_SRGB_WRITE
)
2412 static unsigned int warned
= 0;
2414 args
->srgb_correction
= 1;
2415 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
] && !warned
++)
2416 WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
2417 "support, expect rendering artifacts.\n");
2421 if (shader
->reg_maps
.shader_version
.major
== 1
2422 && shader
->reg_maps
.shader_version
.minor
<= 3)
2424 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2426 DWORD flags
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
2428 if (flags
& WINED3D_TTFF_PROJECTED
)
2430 DWORD tex_transform
= flags
& ~WINED3D_TTFF_PROJECTED
;
2432 if (!state
->shader
[WINED3D_SHADER_TYPE_VERTEX
])
2434 enum wined3d_shader_resource_type resource_type
= shader
->reg_maps
.resource_info
[i
].type
;
2436 unsigned int index
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
2437 DWORD max_valid
= WINED3D_TTFF_COUNT4
;
2439 for (j
= 0; j
< state
->vertex_declaration
->element_count
; ++j
)
2441 struct wined3d_vertex_declaration_element
*element
=
2442 &state
->vertex_declaration
->elements
[j
];
2444 if (element
->usage
== WINED3D_DECL_USAGE_TEXCOORD
2445 && element
->usage_idx
== index
)
2447 max_valid
= element
->format
->component_count
;
2451 if (!tex_transform
|| tex_transform
> max_valid
)
2453 WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
2454 tex_transform
, max_valid
);
2455 tex_transform
= max_valid
;
2457 if ((resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_1D
&& tex_transform
> WINED3D_TTFF_COUNT1
)
2458 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_2D
2459 && tex_transform
> WINED3D_TTFF_COUNT2
)
2460 || (resource_type
== WINED3D_SHADER_RESOURCE_TEXTURE_3D
2461 && tex_transform
> WINED3D_TTFF_COUNT3
))
2462 tex_transform
|= WINED3D_PSARGS_PROJECTED
;
2465 WARN("Application requested projected texture with unsuitable texture coordinates.\n");
2466 WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
2467 i
, tex_transform
, resource_type
);
2471 tex_transform
= WINED3D_TTFF_COUNT4
| WINED3D_PSARGS_PROJECTED
;
2473 args
->tex_transform
|= tex_transform
<< i
* WINED3D_PSARGS_TEXTRANSFORM_SHIFT
;
2477 if (shader
->reg_maps
.shader_version
.major
== 1
2478 && shader
->reg_maps
.shader_version
.minor
<= 4)
2480 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2482 const struct wined3d_texture
*texture
= state
->textures
[i
];
2484 if (!shader
->reg_maps
.resource_info
[i
].type
)
2487 /* Treat unbound textures as 2D. The dummy texture will provide
2488 * the proper sample value. The tex_types bitmap defaults to
2489 * 2D because of the memset. */
2493 switch (texture
->target
)
2495 /* RECT textures are distinguished from 2D textures via np2_fixup */
2496 case GL_TEXTURE_RECTANGLE_ARB
:
2501 args
->tex_types
|= WINED3D_SHADER_TEX_3D
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2504 case GL_TEXTURE_CUBE_MAP_ARB
:
2505 args
->tex_types
|= WINED3D_SHADER_TEX_CUBE
<< i
* WINED3D_PSARGS_TEXTYPE_SHIFT
;
2511 for (i
= 0; i
< MAX_FRAGMENT_SAMPLERS
; ++i
)
2513 if (!shader
->reg_maps
.resource_info
[i
].type
)
2516 texture
= state
->textures
[i
];
2519 args
->color_fixup
[i
] = COLOR_FIXUP_IDENTITY
;
2522 args
->color_fixup
[i
] = texture
->resource
.format
->color_fixup
;
2524 if (texture
->resource
.format_flags
& WINED3DFMT_FLAG_SHADOW
)
2525 args
->shadow
|= 1 << i
;
2527 /* Flag samplers that need NP2 texcoord fixup. */
2528 if (!(texture
->flags
& WINED3D_TEXTURE_POW2_MAT_IDENT
))
2529 args
->np2_fixup
|= (1 << i
);
2531 if (shader
->reg_maps
.shader_version
.major
>= 3)
2533 if (position_transformed
)
2534 args
->vp_mode
= pretransformed
;
2535 else if (use_vs(state
))
2536 args
->vp_mode
= vertexshader
;
2538 args
->vp_mode
= fixedfunction
;
2539 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2543 args
->vp_mode
= vertexshader
;
2544 if (state
->render_states
[WINED3D_RS_FOGENABLE
])
2546 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
2548 case WINED3D_FOG_NONE
:
2549 if (position_transformed
|| use_vs(state
))
2551 args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
2555 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
2557 case WINED3D_FOG_NONE
: /* Fall through. */
2558 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2559 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2560 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2564 case WINED3D_FOG_LINEAR
: args
->fog
= WINED3D_FFP_PS_FOG_LINEAR
; break;
2565 case WINED3D_FOG_EXP
: args
->fog
= WINED3D_FFP_PS_FOG_EXP
; break;
2566 case WINED3D_FOG_EXP2
: args
->fog
= WINED3D_FFP_PS_FOG_EXP2
; break;
2571 args
->fog
= WINED3D_FFP_PS_FOG_OFF
;
2576 static HRESULT
pixelshader_init(struct wined3d_shader
*shader
, struct wined3d_device
*device
,
2577 const struct wined3d_shader_desc
*desc
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
2579 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
2580 unsigned int i
, highest_reg_used
= 0, num_regs_used
= 0;
2583 if (FAILED(hr
= shader_init(shader
, device
, desc
, device
->adapter
->d3d_info
.limits
.ps_uniform_count
,
2584 WINED3D_SHADER_TYPE_PIXEL
, parent
, parent_ops
)))
2587 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2589 if (shader
->u
.ps
.input_reg_used
[i
])
2592 highest_reg_used
= i
;
2596 /* Don't do any register mapping magic if it is not needed, or if we can't
2597 * achieve anything anyway */
2598 if (highest_reg_used
< (gl_info
->limits
.glsl_varyings
/ 4)
2599 || num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2601 if (num_regs_used
> (gl_info
->limits
.glsl_varyings
/ 4))
2603 /* This happens with relative addressing. The input mapper function
2604 * warns about this if the higher registers are declared too, so
2605 * don't write a FIXME here */
2606 WARN("More varying registers used than supported\n");
2609 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2611 shader
->u
.ps
.input_reg_map
[i
] = i
;
2614 shader
->u
.ps
.declared_in_count
= highest_reg_used
+ 1;
2618 shader
->u
.ps
.declared_in_count
= 0;
2619 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
2621 if (shader
->u
.ps
.input_reg_used
[i
])
2622 shader
->u
.ps
.input_reg_map
[i
] = shader
->u
.ps
.declared_in_count
++;
2623 else shader
->u
.ps
.input_reg_map
[i
] = ~0U;
2627 shader
->load_local_constsF
= shader
->lconst_inf_or_nan
;
2632 void pixelshader_update_resource_types(struct wined3d_shader
*shader
, WORD tex_types
)
2634 struct wined3d_shader_reg_maps
*reg_maps
= &shader
->reg_maps
;
2635 struct wined3d_shader_resource_info
*resource_info
= reg_maps
->resource_info
;
2638 if (reg_maps
->shader_version
.major
!= 1) return;
2640 for (i
= 0; i
< shader
->limits
->sampler
; ++i
)
2642 /* We don't sample from this sampler. */
2643 if (!resource_info
[i
].type
)
2646 switch ((tex_types
>> i
* WINED3D_PSARGS_TEXTYPE_SHIFT
) & WINED3D_PSARGS_TEXTYPE_MASK
)
2648 case WINED3D_SHADER_TEX_2D
:
2649 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_2D
;
2652 case WINED3D_SHADER_TEX_3D
:
2653 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_3D
;
2656 case WINED3D_SHADER_TEX_CUBE
:
2657 resource_info
[i
].type
= WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
;
2663 HRESULT CDECL
wined3d_shader_create_gs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2664 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2666 struct wined3d_shader
*object
;
2669 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2670 device
, desc
, parent
, parent_ops
, shader
);
2672 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2674 return E_OUTOFMEMORY
;
2676 if (FAILED(hr
= geometryshader_init(object
, device
, desc
, parent
, parent_ops
)))
2678 WARN("Failed to initialize geometry shader, hr %#x.\n", hr
);
2679 HeapFree(GetProcessHeap(), 0, object
);
2683 TRACE("Created geometry shader %p.\n", object
);
2689 HRESULT CDECL
wined3d_shader_create_ps(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2690 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2692 struct wined3d_shader
*object
;
2695 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2696 device
, desc
, parent
, parent_ops
, shader
);
2698 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2700 return E_OUTOFMEMORY
;
2702 if (FAILED(hr
= pixelshader_init(object
, device
, desc
, parent
, parent_ops
)))
2704 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2705 HeapFree(GetProcessHeap(), 0, object
);
2709 TRACE("Created pixel shader %p.\n", object
);
2715 HRESULT CDECL
wined3d_shader_create_vs(struct wined3d_device
*device
, const struct wined3d_shader_desc
*desc
,
2716 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_shader
**shader
)
2718 struct wined3d_shader
*object
;
2721 TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
2722 device
, desc
, parent
, parent_ops
, shader
);
2724 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2726 return E_OUTOFMEMORY
;
2728 if (FAILED(hr
= vertexshader_init(object
, device
, desc
, parent
, parent_ops
)))
2730 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2731 HeapFree(GetProcessHeap(), 0, object
);
2735 TRACE("Created vertex shader %p.\n", object
);