2 * shaders implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006 Ivan Gyurdiev
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wined3d_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
33 WINE_DECLARE_DEBUG_CHANNEL(d3d
);
35 static const char *shader_opcode_names
[] =
37 /* WINED3DSIH_ABS */ "abs",
38 /* WINED3DSIH_ADD */ "add",
39 /* WINED3DSIH_BEM */ "bem",
40 /* WINED3DSIH_BREAK */ "break",
41 /* WINED3DSIH_BREAKC */ "breakc",
42 /* WINED3DSIH_BREAKP */ "breakp",
43 /* WINED3DSIH_CALL */ "call",
44 /* WINED3DSIH_CALLNZ */ "callnz",
45 /* WINED3DSIH_CMP */ "cmp",
46 /* WINED3DSIH_CND */ "cnd",
47 /* WINED3DSIH_CRS */ "crs",
48 /* WINED3DSIH_DCL */ "dcl",
49 /* WINED3DSIH_DEF */ "def",
50 /* WINED3DSIH_DEFB */ "defb",
51 /* WINED3DSIH_DEFI */ "defi",
52 /* WINED3DSIH_DP2ADD */ "dp2add",
53 /* WINED3DSIH_DP3 */ "dp3",
54 /* WINED3DSIH_DP4 */ "dp4",
55 /* WINED3DSIH_DST */ "dst",
56 /* WINED3DSIH_DSX */ "dsx",
57 /* WINED3DSIH_DSY */ "dsy",
58 /* WINED3DSIH_ELSE */ "else",
59 /* WINED3DSIH_ENDIF */ "endif",
60 /* WINED3DSIH_ENDLOOP */ "endloop",
61 /* WINED3DSIH_ENDREP */ "endrep",
62 /* WINED3DSIH_EXP */ "exp",
63 /* WINED3DSIH_EXPP */ "expp",
64 /* WINED3DSIH_FRC */ "frc",
65 /* WINED3DSIH_IF */ "if",
66 /* WINED3DSIH_IFC */ "ifc",
67 /* WINED3DSIH_LABEL */ "label",
68 /* WINED3DSIH_LIT */ "lit",
69 /* WINED3DSIH_LOG */ "log",
70 /* WINED3DSIH_LOGP */ "logp",
71 /* WINED3DSIH_LOOP */ "loop",
72 /* WINED3DSIH_LRP */ "lrp",
73 /* WINED3DSIH_M3x2 */ "m3x2",
74 /* WINED3DSIH_M3x3 */ "m3x3",
75 /* WINED3DSIH_M3x4 */ "m3x4",
76 /* WINED3DSIH_M4x3 */ "m4x3",
77 /* WINED3DSIH_M4x4 */ "m4x4",
78 /* WINED3DSIH_MAD */ "mad",
79 /* WINED3DSIH_MAX */ "max",
80 /* WINED3DSIH_MIN */ "min",
81 /* WINED3DSIH_MOV */ "mov",
82 /* WINED3DSIH_MOVA */ "mova",
83 /* WINED3DSIH_MUL */ "mul",
84 /* WINED3DSIH_NOP */ "nop",
85 /* WINED3DSIH_NRM */ "nrm",
86 /* WINED3DSIH_PHASE */ "phase",
87 /* WINED3DSIH_POW */ "pow",
88 /* WINED3DSIH_RCP */ "rcp",
89 /* WINED3DSIH_REP */ "rep",
90 /* WINED3DSIH_RET */ "ret",
91 /* WINED3DSIH_RSQ */ "rsq",
92 /* WINED3DSIH_SETP */ "setp",
93 /* WINED3DSIH_SGE */ "sge",
94 /* WINED3DSIH_SGN */ "sgn",
95 /* WINED3DSIH_SINCOS */ "sincos",
96 /* WINED3DSIH_SLT */ "slt",
97 /* WINED3DSIH_SUB */ "sub",
98 /* WINED3DSIH_TEX */ "texld",
99 /* WINED3DSIH_TEXBEM */ "texbem",
100 /* WINED3DSIH_TEXBEML */ "texbeml",
101 /* WINED3DSIH_TEXCOORD */ "texcrd",
102 /* WINED3DSIH_TEXDEPTH */ "texdepth",
103 /* WINED3DSIH_TEXDP3 */ "texdp3",
104 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
105 /* WINED3DSIH_TEXKILL */ "texkill",
106 /* WINED3DSIH_TEXLDD */ "texldd",
107 /* WINED3DSIH_TEXLDL */ "texldl",
108 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
109 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
110 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
111 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
112 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
113 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
114 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
115 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
116 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
117 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
118 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
119 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
122 const struct wined3d_shader_frontend
*shader_select_frontend(DWORD version_token
)
124 switch (version_token
>> 16)
128 return &sm1_shader_frontend
;
133 return &sm4_shader_frontend
;
136 FIXME("Unrecognised version token %#x\n", version_token
);
141 void shader_buffer_clear(struct wined3d_shader_buffer
*buffer
)
143 buffer
->buffer
[0] = '\0';
146 buffer
->newline
= TRUE
;
149 BOOL
shader_buffer_init(struct wined3d_shader_buffer
*buffer
)
151 buffer
->buffer
= HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE
);
154 ERR("Failed to allocate shader buffer memory.\n");
158 shader_buffer_clear(buffer
);
162 void shader_buffer_free(struct wined3d_shader_buffer
*buffer
)
164 HeapFree(GetProcessHeap(), 0, buffer
->buffer
);
167 int shader_vaddline(struct wined3d_shader_buffer
*buffer
, const char *format
, va_list args
)
169 char* base
= buffer
->buffer
+ buffer
->bsize
;
172 rc
= vsnprintf(base
, SHADER_PGMSIZE
- 1 - buffer
->bsize
, format
, args
);
174 if (rc
< 0 /* C89 */ || (unsigned int)rc
> SHADER_PGMSIZE
- 1 - buffer
->bsize
/* C99 */)
176 ERR("The buffer allocated for the shader program string "
177 "is too small at %d bytes.\n", SHADER_PGMSIZE
);
178 buffer
->bsize
= SHADER_PGMSIZE
- 1;
182 if (buffer
->newline
) {
183 TRACE("GL HW (%u, %u) : %s", buffer
->lineNo
+ 1, buffer
->bsize
, base
);
184 buffer
->newline
= FALSE
;
190 if (buffer
->buffer
[buffer
->bsize
-1] == '\n') {
192 buffer
->newline
= TRUE
;
197 int shader_addline(struct wined3d_shader_buffer
*buffer
, const char *format
, ...)
202 va_start(args
, format
);
203 ret
= shader_vaddline(buffer
, format
, args
);
209 void shader_init(struct IWineD3DBaseShaderClass
*shader
, IWineD3DDevice
*device
)
212 shader
->device
= device
;
213 list_init(&shader
->linked_programs
);
216 /* Convert floating point offset relative
217 * to a register file to an absolute offset for float constants */
218 static unsigned int shader_get_float_offset(WINED3DSHADER_PARAM_REGISTER_TYPE register_type
, UINT register_idx
)
220 switch (register_type
)
222 case WINED3DSPR_CONST
: return register_idx
;
223 case WINED3DSPR_CONST2
: return 2048 + register_idx
;
224 case WINED3DSPR_CONST3
: return 4096 + register_idx
;
225 case WINED3DSPR_CONST4
: return 6144 + register_idx
;
227 FIXME("Unsupported register type: %d\n", register_type
);
232 static void shader_delete_constant_list(struct list
* clist
) {
235 struct local_constant
* constant
;
237 ptr
= list_head(clist
);
239 constant
= LIST_ENTRY(ptr
, struct local_constant
, entry
);
240 ptr
= list_next(clist
, ptr
);
241 HeapFree(GetProcessHeap(), 0, constant
);
246 static inline void set_bitmap_bit(DWORD
*bitmap
, DWORD bit
)
251 bitmap
[idx
] |= (1 << shift
);
254 static void shader_record_register_usage(IWineD3DBaseShaderImpl
*This
, struct shader_reg_maps
*reg_maps
,
255 const struct wined3d_shader_register
*reg
, enum wined3d_shader_type shader_type
)
259 case WINED3DSPR_TEXTURE
: /* WINED3DSPR_ADDR */
260 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
) reg_maps
->texcoord
|= 1 << reg
->idx
;
261 else reg_maps
->address
|= 1 << reg
->idx
;
264 case WINED3DSPR_TEMP
:
265 reg_maps
->temporary
|= 1 << reg
->idx
;
268 case WINED3DSPR_INPUT
:
269 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
273 /* If relative addressing is used, we must assume that all registers
274 * are used. Even if it is a construct like v3[aL], we can't assume
275 * that v0, v1 and v2 aren't read because aL can be negative */
277 for (i
= 0; i
< MAX_REG_INPUT
; ++i
)
279 ((IWineD3DPixelShaderImpl
*)This
)->input_reg_used
[i
] = TRUE
;
284 ((IWineD3DPixelShaderImpl
*)This
)->input_reg_used
[reg
->idx
] = TRUE
;
287 else reg_maps
->input_registers
|= 1 << reg
->idx
;
290 case WINED3DSPR_RASTOUT
:
291 if (reg
->idx
== 1) reg_maps
->fog
= 1;
294 case WINED3DSPR_MISCTYPE
:
295 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
297 if (reg
->idx
== 0) reg_maps
->vpos
= 1;
298 else if (reg
->idx
== 1) reg_maps
->usesfacing
= 1;
302 case WINED3DSPR_CONST
:
305 if (shader_type
!= WINED3D_SHADER_TYPE_PIXEL
)
307 if (reg
->idx
< ((IWineD3DVertexShaderImpl
*)This
)->min_rel_offset
)
309 ((IWineD3DVertexShaderImpl
*)This
)->min_rel_offset
= reg
->idx
;
311 if (reg
->idx
> ((IWineD3DVertexShaderImpl
*)This
)->max_rel_offset
)
313 ((IWineD3DVertexShaderImpl
*)This
)->max_rel_offset
= reg
->idx
;
316 reg_maps
->usesrelconstF
= TRUE
;
320 set_bitmap_bit(reg_maps
->constf
, reg
->idx
);
324 case WINED3DSPR_CONSTINT
:
325 reg_maps
->integer_constants
|= (1 << reg
->idx
);
328 case WINED3DSPR_CONSTBOOL
:
329 reg_maps
->boolean_constants
|= (1 << reg
->idx
);
332 case WINED3DSPR_COLOROUT
:
333 reg_maps
->highest_render_target
= max(reg_maps
->highest_render_target
, reg
->idx
);
337 TRACE("Not recording register of type %#x and idx %u\n", reg
->type
, reg
->idx
);
342 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr
, unsigned int param
)
346 case WINED3DSIH_M4x4
:
347 case WINED3DSIH_M3x4
:
348 return param
== 1 ? 3 : 0;
350 case WINED3DSIH_M4x3
:
351 case WINED3DSIH_M3x3
:
352 return param
== 1 ? 2 : 0;
354 case WINED3DSIH_M3x2
:
355 return param
== 1 ? 1 : 0;
362 static const char *shader_semantic_name_from_usage(WINED3DDECLUSAGE usage
)
364 static const char *semantic_names
[] =
366 /* WINED3DDECLUSAGE_POSITION */ "SV_POSITION",
367 /* WINED3DDECLUSAGE_BLENDWEIGHT */ "BLENDWEIGHT",
368 /* WINED3DDECLUSAGE_BLENDINDICES */ "BLENDINDICES",
369 /* WINED3DDECLUSAGE_NORMAL */ "NORMAL",
370 /* WINED3DDECLUSAGE_PSIZE */ "PSIZE",
371 /* WINED3DDECLUSAGE_TEXCOORD */ "TEXCOORD",
372 /* WINED3DDECLUSAGE_TANGENT */ "TANGENT",
373 /* WINED3DDECLUSAGE_BINORMAL */ "BINORMAL",
374 /* WINED3DDECLUSAGE_TESSFACTOR */ "TESSFACTOR",
375 /* WINED3DDECLUSAGE_POSITIONT */ "POSITIONT",
376 /* WINED3DDECLUSAGE_COLOR */ "COLOR",
377 /* WINED3DDECLUSAGE_FOG */ "FOG",
378 /* WINED3DDECLUSAGE_DEPTH */ "DEPTH",
379 /* WINED3DDECLUSAGE_SAMPLE */ "SAMPLE",
382 if (usage
>= sizeof(semantic_names
) / sizeof(*semantic_names
))
384 FIXME("Unrecognized usage %#x\n", usage
);
385 return "UNRECOGNIZED";
388 return semantic_names
[usage
];
391 BOOL
shader_match_semantic(const char *semantic_name
, WINED3DDECLUSAGE usage
)
393 return !strcmp(semantic_name
, shader_semantic_name_from_usage(usage
));
396 static void shader_signature_from_semantic(struct wined3d_shader_signature_element
*e
,
397 const struct wined3d_shader_semantic
*s
)
399 e
->semantic_name
= shader_semantic_name_from_usage(s
->usage
);
400 e
->semantic_idx
= s
->usage_idx
;
401 e
->sysval_semantic
= 0;
402 e
->component_type
= 0;
403 e
->register_idx
= s
->reg
.reg
.idx
;
404 e
->mask
= s
->reg
.write_mask
;
407 /* Note that this does not count the loop register
408 * as an address register. */
410 HRESULT
shader_get_registers_used(IWineD3DBaseShader
*iface
, const struct wined3d_shader_frontend
*fe
,
411 struct shader_reg_maps
*reg_maps
, struct wined3d_shader_attribute
*attributes
,
412 struct wined3d_shader_signature_element
*input_signature
,
413 struct wined3d_shader_signature_element
*output_signature
, const DWORD
*byte_code
, DWORD constf_size
)
415 IWineD3DBaseShaderImpl
* This
= (IWineD3DBaseShaderImpl
*) iface
;
416 void *fe_data
= This
->baseShader
.frontend_data
;
417 struct wined3d_shader_version shader_version
;
418 unsigned int cur_loop_depth
= 0, max_loop_depth
= 0;
419 const DWORD
* pToken
= byte_code
;
421 /* There are some minor differences between pixel and vertex shaders */
423 memset(reg_maps
, 0, sizeof(*reg_maps
));
425 /* get_registers_used is called on every compile on some 1.x shaders, which can result
426 * in stacking up a collection of local constants. Delete the old constants if existing
428 shader_delete_constant_list(&This
->baseShader
.constantsF
);
429 shader_delete_constant_list(&This
->baseShader
.constantsB
);
430 shader_delete_constant_list(&This
->baseShader
.constantsI
);
432 fe
->shader_read_header(fe_data
, &pToken
, &shader_version
);
433 reg_maps
->shader_version
= shader_version
;
435 reg_maps
->constf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
436 sizeof(*reg_maps
->constf
) * ((constf_size
+ 31) / 32));
437 if(!reg_maps
->constf
) {
438 ERR("Out of memory\n");
439 return E_OUTOFMEMORY
;
442 while (!fe
->shader_is_end(fe_data
, &pToken
))
444 struct wined3d_shader_instruction ins
;
449 fe
->shader_read_comment(&pToken
, &comment
);
450 if (comment
) continue;
453 fe
->shader_read_opcode(fe_data
, &pToken
, &ins
, ¶m_size
);
455 /* Unhandled opcode, and its parameters */
456 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
458 TRACE("Skipping unrecognized instruction.\n");
459 pToken
+= param_size
;
463 /* Handle declarations */
464 if (ins
.handler_idx
== WINED3DSIH_DCL
)
466 struct wined3d_shader_semantic semantic
;
468 fe
->shader_read_semantic(&pToken
, &semantic
);
470 switch (semantic
.reg
.reg
.type
)
472 /* Vshader: mark attributes used
473 * Pshader: mark 3.0 input registers used, save token */
474 case WINED3DSPR_INPUT
:
475 reg_maps
->input_registers
|= 1 << semantic
.reg
.reg
.idx
;
476 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
)
478 attributes
[semantic
.reg
.reg
.idx
].usage
= semantic
.usage
;
479 attributes
[semantic
.reg
.reg
.idx
].usage_idx
= semantic
.usage_idx
;
483 shader_signature_from_semantic(&input_signature
[semantic
.reg
.reg
.idx
], &semantic
);
487 /* Vshader: mark 3.0 output registers used, save token */
488 case WINED3DSPR_OUTPUT
:
489 reg_maps
->output_registers
|= 1 << semantic
.reg
.reg
.idx
;
490 shader_signature_from_semantic(&output_signature
[semantic
.reg
.reg
.idx
], &semantic
);
491 if (semantic
.usage
== WINED3DDECLUSAGE_FOG
) reg_maps
->fog
= 1;
494 /* Save sampler usage token */
495 case WINED3DSPR_SAMPLER
:
496 reg_maps
->sampler_type
[semantic
.reg
.reg
.idx
] = semantic
.sampler_type
;
500 TRACE("Not recording DCL register type %#x.\n", semantic
.reg
.reg
.type
);
504 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
506 struct wined3d_shader_dst_param dst
;
507 struct wined3d_shader_src_param rel_addr
;
509 local_constant
* lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant
));
510 if (!lconst
) return E_OUTOFMEMORY
;
512 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
513 lconst
->idx
= dst
.reg
.idx
;
515 memcpy(lconst
->value
, pToken
, 4 * sizeof(DWORD
));
518 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
519 if (shader_version
.major
== 1 && shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
521 float *value
= (float *) lconst
->value
;
522 if (value
[0] < -1.0f
) value
[0] = -1.0f
;
523 else if (value
[0] > 1.0f
) value
[0] = 1.0f
;
524 if (value
[1] < -1.0f
) value
[1] = -1.0f
;
525 else if (value
[1] > 1.0f
) value
[1] = 1.0f
;
526 if (value
[2] < -1.0f
) value
[2] = -1.0f
;
527 else if (value
[2] > 1.0f
) value
[2] = 1.0f
;
528 if (value
[3] < -1.0f
) value
[3] = -1.0f
;
529 else if (value
[3] > 1.0f
) value
[3] = 1.0f
;
532 list_add_head(&This
->baseShader
.constantsF
, &lconst
->entry
);
534 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
536 struct wined3d_shader_dst_param dst
;
537 struct wined3d_shader_src_param rel_addr
;
539 local_constant
* lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant
));
540 if (!lconst
) return E_OUTOFMEMORY
;
542 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
543 lconst
->idx
= dst
.reg
.idx
;
545 memcpy(lconst
->value
, pToken
, 4 * sizeof(DWORD
));
548 list_add_head(&This
->baseShader
.constantsI
, &lconst
->entry
);
549 reg_maps
->local_int_consts
|= (1 << dst
.reg
.idx
);
551 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
553 struct wined3d_shader_dst_param dst
;
554 struct wined3d_shader_src_param rel_addr
;
556 local_constant
* lconst
= HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant
));
557 if (!lconst
) return E_OUTOFMEMORY
;
559 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
560 lconst
->idx
= dst
.reg
.idx
;
562 memcpy(lconst
->value
, pToken
, sizeof(DWORD
));
565 list_add_head(&This
->baseShader
.constantsB
, &lconst
->entry
);
566 reg_maps
->local_bool_consts
|= (1 << dst
.reg
.idx
);
568 /* If there's a loop in the shader */
569 else if (ins
.handler_idx
== WINED3DSIH_LOOP
570 || ins
.handler_idx
== WINED3DSIH_REP
)
572 struct wined3d_shader_src_param src
, rel_addr
;
574 fe
->shader_read_src_param(fe_data
, &pToken
, &src
, &rel_addr
);
576 /* Rep and Loop always use an integer constant for the control parameters */
577 if (ins
.handler_idx
== WINED3DSIH_REP
)
579 reg_maps
->integer_constants
|= 1 << src
.reg
.idx
;
583 fe
->shader_read_src_param(fe_data
, &pToken
, &src
, &rel_addr
);
584 reg_maps
->integer_constants
|= 1 << src
.reg
.idx
;
588 if(cur_loop_depth
> max_loop_depth
)
589 max_loop_depth
= cur_loop_depth
;
591 else if (ins
.handler_idx
== WINED3DSIH_ENDLOOP
592 || ins
.handler_idx
== WINED3DSIH_ENDREP
)
596 /* For subroutine prototypes */
597 else if (ins
.handler_idx
== WINED3DSIH_LABEL
)
599 struct wined3d_shader_src_param src
, rel_addr
;
601 fe
->shader_read_src_param(fe_data
, &pToken
, &src
, &rel_addr
);
602 reg_maps
->labels
|= 1 << src
.reg
.idx
;
604 /* Set texture, address, temporary registers */
608 BOOL color0_mov
= FALSE
;
610 /* This will loop over all the registers and try to
611 * make a bitmask of the ones we're interested in.
613 * Relative addressing tokens are ignored, but that's
614 * okay, since we'll catch any address registers when
615 * they are initialized (required by spec) */
619 struct wined3d_shader_dst_param dst_param
;
620 struct wined3d_shader_src_param dst_rel_addr
;
622 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst_param
, &dst_rel_addr
);
624 shader_record_register_usage(This
, reg_maps
, &dst_param
.reg
, shader_version
.type
);
626 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
627 * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
628 * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
629 if (shader_version
.type
== WINED3D_SHADER_TYPE_VERTEX
&& shader_version
.major
< 3
630 && dst_param
.reg
.type
== WINED3DSPR_TEXCRDOUT
)
632 reg_maps
->texcoord_mask
[dst_param
.reg
.idx
] |= dst_param
.write_mask
;
635 if (shader_version
.type
== WINED3D_SHADER_TYPE_PIXEL
)
637 IWineD3DPixelShaderImpl
*ps
= (IWineD3DPixelShaderImpl
*)This
;
639 if(dst_param
.reg
.type
== WINED3DSPR_COLOROUT
&& dst_param
.reg
.idx
== 0)
641 /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
642 * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
643 * the mov and perform the sRGB write correction from the source register.
645 * However, if the mov is only partial, we can't do this, and if the write
646 * comes from an instruction other than MOV it is hard to do as well. If
647 * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
649 ps
->color0_mov
= FALSE
;
650 if (ins
.handler_idx
== WINED3DSIH_MOV
)
652 /* Used later when the source register is read. */
656 /* Also drop the MOV marker if the source register is overwritten prior to the shader
659 else if(dst_param
.reg
.type
== WINED3DSPR_TEMP
&& dst_param
.reg
.idx
== ps
->color0_reg
)
661 ps
->color0_mov
= FALSE
;
665 /* Declare 1.X samplers implicitly, based on the destination reg. number */
666 if (shader_version
.major
== 1
667 && (ins
.handler_idx
== WINED3DSIH_TEX
668 || ins
.handler_idx
== WINED3DSIH_TEXBEM
669 || ins
.handler_idx
== WINED3DSIH_TEXBEML
670 || ins
.handler_idx
== WINED3DSIH_TEXDP3TEX
671 || ins
.handler_idx
== WINED3DSIH_TEXM3x2TEX
672 || ins
.handler_idx
== WINED3DSIH_TEXM3x3SPEC
673 || ins
.handler_idx
== WINED3DSIH_TEXM3x3TEX
674 || ins
.handler_idx
== WINED3DSIH_TEXM3x3VSPEC
675 || ins
.handler_idx
== WINED3DSIH_TEXREG2AR
676 || ins
.handler_idx
== WINED3DSIH_TEXREG2GB
677 || ins
.handler_idx
== WINED3DSIH_TEXREG2RGB
))
679 /* Fake sampler usage, only set reserved bit and ttype */
680 DWORD sampler_code
= dst_param
.reg
.idx
;
682 TRACE("Setting fake 2D sampler for 1.x pixelshader\n");
683 reg_maps
->sampler_type
[sampler_code
] = WINED3DSTT_2D
;
685 /* texbem is only valid with < 1.4 pixel shaders */
686 if (ins
.handler_idx
== WINED3DSIH_TEXBEM
687 || ins
.handler_idx
== WINED3DSIH_TEXBEML
)
689 reg_maps
->bumpmat
|= 1 << dst_param
.reg
.idx
;
690 if (ins
.handler_idx
== WINED3DSIH_TEXBEML
)
692 reg_maps
->luminanceparams
|= 1 << dst_param
.reg
.idx
;
696 else if (ins
.handler_idx
== WINED3DSIH_BEM
)
698 reg_maps
->bumpmat
|= 1 << dst_param
.reg
.idx
;
702 if (ins
.handler_idx
== WINED3DSIH_NRM
)
704 reg_maps
->usesnrm
= 1;
706 else if (ins
.handler_idx
== WINED3DSIH_DSY
)
708 reg_maps
->usesdsy
= 1;
710 else if (ins
.handler_idx
== WINED3DSIH_DSX
)
712 reg_maps
->usesdsx
= 1;
714 else if(ins
.handler_idx
== WINED3DSIH_TEXLDD
)
716 reg_maps
->usestexldd
= 1;
718 else if(ins
.handler_idx
== WINED3DSIH_TEXLDL
)
720 reg_maps
->usestexldl
= 1;
722 else if(ins
.handler_idx
== WINED3DSIH_MOVA
)
724 reg_maps
->usesmova
= 1;
726 else if(ins
.handler_idx
== WINED3DSIH_IFC
)
728 reg_maps
->usesifc
= 1;
730 else if(ins
.handler_idx
== WINED3DSIH_CALL
)
732 reg_maps
->usescall
= 1;
735 limit
= ins
.src_count
+ (ins
.predicate
? 1 : 0);
736 for (i
= 0; i
< limit
; ++i
)
738 struct wined3d_shader_src_param src_param
, src_rel_addr
;
741 fe
->shader_read_src_param(fe_data
, &pToken
, &src_param
, &src_rel_addr
);
742 count
= get_instr_extra_regcount(ins
.handler_idx
, i
);
744 shader_record_register_usage(This
, reg_maps
, &src_param
.reg
, shader_version
.type
);
748 shader_record_register_usage(This
, reg_maps
, &src_param
.reg
, shader_version
.type
);
754 IWineD3DPixelShaderImpl
*ps
= (IWineD3DPixelShaderImpl
*) This
;
755 if(src_param
.reg
.type
== WINED3DSPR_TEMP
&&
756 src_param
.swizzle
== WINED3DSP_NOSWIZZLE
)
758 ps
->color0_mov
= TRUE
;
759 ps
->color0_reg
= src_param
.reg
.idx
;
765 reg_maps
->loop_depth
= max_loop_depth
;
767 This
->baseShader
.functionLength
= ((const char *)pToken
- (const char *)byte_code
);
772 unsigned int shader_find_free_input_register(const struct shader_reg_maps
*reg_maps
, unsigned int max
)
774 DWORD map
= 1 << max
;
776 map
&= reg_maps
->shader_version
.major
< 3 ? ~reg_maps
->texcoord
: ~reg_maps
->input_registers
;
778 return wined3d_log2i(map
);
781 static void shader_dump_decl_usage(const struct wined3d_shader_semantic
*semantic
,
782 const struct wined3d_shader_version
*shader_version
)
786 if (semantic
->reg
.reg
.type
== WINED3DSPR_SAMPLER
)
788 switch (semantic
->sampler_type
)
790 case WINED3DSTT_2D
: TRACE("_2d"); break;
791 case WINED3DSTT_CUBE
: TRACE("_cube"); break;
792 case WINED3DSTT_VOLUME
: TRACE("_volume"); break;
793 default: TRACE("_unknown_ttype(0x%08x)", semantic
->sampler_type
);
798 /* Pixel shaders 3.0 don't have usage semantics */
799 if (shader_version
->major
< 3 && shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
)
804 switch (semantic
->usage
)
806 case WINED3DDECLUSAGE_POSITION
:
807 TRACE("position%d", semantic
->usage_idx
);
809 case WINED3DDECLUSAGE_BLENDINDICES
:
812 case WINED3DDECLUSAGE_BLENDWEIGHT
:
815 case WINED3DDECLUSAGE_NORMAL
:
816 TRACE("normal%d", semantic
->usage_idx
);
818 case WINED3DDECLUSAGE_PSIZE
:
821 case WINED3DDECLUSAGE_COLOR
:
822 if (semantic
->usage_idx
== 0) TRACE("color");
823 else TRACE("specular%d", (semantic
->usage_idx
- 1));
825 case WINED3DDECLUSAGE_TEXCOORD
:
826 TRACE("texture%d", semantic
->usage_idx
);
828 case WINED3DDECLUSAGE_TANGENT
:
831 case WINED3DDECLUSAGE_BINORMAL
:
834 case WINED3DDECLUSAGE_TESSFACTOR
:
837 case WINED3DDECLUSAGE_POSITIONT
:
838 TRACE("positionT%d", semantic
->usage_idx
);
840 case WINED3DDECLUSAGE_FOG
:
843 case WINED3DDECLUSAGE_DEPTH
:
846 case WINED3DDECLUSAGE_SAMPLE
:
850 FIXME("unknown_semantics(0x%08x)", semantic
->usage
);
855 static void shader_dump_register(const struct wined3d_shader_register
*reg
,
856 const struct wined3d_shader_version
*shader_version
)
858 static const char * const rastout_reg_names
[] = {"oPos", "oFog", "oPts"};
859 static const char * const misctype_reg_names
[] = {"vPos", "vFace"};
860 UINT offset
= reg
->idx
;
864 case WINED3DSPR_TEMP
:
868 case WINED3DSPR_INPUT
:
872 case WINED3DSPR_CONST
:
873 case WINED3DSPR_CONST2
:
874 case WINED3DSPR_CONST3
:
875 case WINED3DSPR_CONST4
:
877 offset
= shader_get_float_offset(reg
->type
, reg
->idx
);
880 case WINED3DSPR_TEXTURE
: /* vs: case WINED3DSPR_ADDR */
881 TRACE("%c", shader_version
->type
== WINED3D_SHADER_TYPE_PIXEL
? 't' : 'a');
884 case WINED3DSPR_RASTOUT
:
885 TRACE("%s", rastout_reg_names
[reg
->idx
]);
888 case WINED3DSPR_COLOROUT
:
892 case WINED3DSPR_DEPTHOUT
:
896 case WINED3DSPR_ATTROUT
:
900 case WINED3DSPR_TEXCRDOUT
:
901 /* Vertex shaders >= 3.0 use general purpose output registers
902 * (WINED3DSPR_OUTPUT), which can include an address token */
903 if (shader_version
->major
>= 3) TRACE("o");
907 case WINED3DSPR_CONSTINT
:
911 case WINED3DSPR_CONSTBOOL
:
915 case WINED3DSPR_LABEL
:
919 case WINED3DSPR_LOOP
:
923 case WINED3DSPR_SAMPLER
:
927 case WINED3DSPR_MISCTYPE
:
928 if (reg
->idx
> 1) FIXME("Unhandled misctype register %d\n", reg
->idx
);
929 else TRACE("%s", misctype_reg_names
[reg
->idx
]);
932 case WINED3DSPR_PREDICATE
:
936 case WINED3DSPR_IMMCONST
:
940 case WINED3DSPR_CONSTBUFFER
:
945 TRACE("unhandled_rtype(%#x)", reg
->type
);
949 if (reg
->type
== WINED3DSPR_IMMCONST
)
952 switch (reg
->immconst_type
)
954 case WINED3D_IMMCONST_FLOAT
:
955 TRACE("%.8e", *(const float *)reg
->immconst_data
);
958 case WINED3D_IMMCONST_FLOAT4
:
959 TRACE("%.8e, %.8e, %.8e, %.8e",
960 *(const float *)®
->immconst_data
[0], *(const float *)®
->immconst_data
[1],
961 *(const float *)®
->immconst_data
[2], *(const float *)®
->immconst_data
[3]);
965 TRACE("<unhandled immconst_type %#x>", reg
->immconst_type
);
970 else if (reg
->type
!= WINED3DSPR_RASTOUT
&& reg
->type
!= WINED3DSPR_MISCTYPE
)
972 if (reg
->array_idx
!= ~0U)
974 TRACE("%u[%u", offset
, reg
->array_idx
);
978 shader_dump_src_param(reg
->rel_addr
, shader_version
);
987 shader_dump_src_param(reg
->rel_addr
, shader_version
);
991 if (reg
->rel_addr
) TRACE("]");
996 void shader_dump_dst_param(const struct wined3d_shader_dst_param
*param
,
997 const struct wined3d_shader_version
*shader_version
)
999 DWORD write_mask
= param
->write_mask
;
1001 shader_dump_register(¶m
->reg
, shader_version
);
1003 if (write_mask
!= WINED3DSP_WRITEMASK_ALL
)
1005 static const char *write_mask_chars
= "xyzw";
1008 if (write_mask
& WINED3DSP_WRITEMASK_0
) TRACE("%c", write_mask_chars
[0]);
1009 if (write_mask
& WINED3DSP_WRITEMASK_1
) TRACE("%c", write_mask_chars
[1]);
1010 if (write_mask
& WINED3DSP_WRITEMASK_2
) TRACE("%c", write_mask_chars
[2]);
1011 if (write_mask
& WINED3DSP_WRITEMASK_3
) TRACE("%c", write_mask_chars
[3]);
1015 void shader_dump_src_param(const struct wined3d_shader_src_param
*param
,
1016 const struct wined3d_shader_version
*shader_version
)
1018 DWORD src_modifier
= param
->modifiers
;
1019 DWORD swizzle
= param
->swizzle
;
1021 if (src_modifier
== WINED3DSPSM_NEG
1022 || src_modifier
== WINED3DSPSM_BIASNEG
1023 || src_modifier
== WINED3DSPSM_SIGNNEG
1024 || src_modifier
== WINED3DSPSM_X2NEG
1025 || src_modifier
== WINED3DSPSM_ABSNEG
)
1027 else if (src_modifier
== WINED3DSPSM_COMP
)
1029 else if (src_modifier
== WINED3DSPSM_NOT
)
1032 if (src_modifier
== WINED3DSPSM_ABS
|| src_modifier
== WINED3DSPSM_ABSNEG
)
1035 shader_dump_register(¶m
->reg
, shader_version
);
1039 switch (src_modifier
)
1041 case WINED3DSPSM_NONE
: break;
1042 case WINED3DSPSM_NEG
: break;
1043 case WINED3DSPSM_NOT
: break;
1044 case WINED3DSPSM_BIAS
: TRACE("_bias"); break;
1045 case WINED3DSPSM_BIASNEG
: TRACE("_bias"); break;
1046 case WINED3DSPSM_SIGN
: TRACE("_bx2"); break;
1047 case WINED3DSPSM_SIGNNEG
: TRACE("_bx2"); break;
1048 case WINED3DSPSM_COMP
: break;
1049 case WINED3DSPSM_X2
: TRACE("_x2"); break;
1050 case WINED3DSPSM_X2NEG
: TRACE("_x2"); break;
1051 case WINED3DSPSM_DZ
: TRACE("_dz"); break;
1052 case WINED3DSPSM_DW
: TRACE("_dw"); break;
1053 case WINED3DSPSM_ABSNEG
: TRACE(")"); break;
1054 case WINED3DSPSM_ABS
: TRACE(")"); break;
1056 TRACE("_unknown_modifier(%#x)", src_modifier
);
1060 if (swizzle
!= WINED3DSP_NOSWIZZLE
)
1062 static const char *swizzle_chars
= "xyzw";
1063 DWORD swizzle_x
= swizzle
& 0x03;
1064 DWORD swizzle_y
= (swizzle
>> 2) & 0x03;
1065 DWORD swizzle_z
= (swizzle
>> 4) & 0x03;
1066 DWORD swizzle_w
= (swizzle
>> 6) & 0x03;
1068 if (swizzle_x
== swizzle_y
1069 && swizzle_x
== swizzle_z
1070 && swizzle_x
== swizzle_w
)
1072 TRACE(".%c", swizzle_chars
[swizzle_x
]);
1076 TRACE(".%c%c%c%c", swizzle_chars
[swizzle_x
], swizzle_chars
[swizzle_y
],
1077 swizzle_chars
[swizzle_z
], swizzle_chars
[swizzle_w
]);
1082 /* Shared code in order to generate the bulk of the shader string.
1083 * NOTE: A description of how to parse tokens can be found on msdn */
1084 void shader_generate_main(IWineD3DBaseShader
*iface
, struct wined3d_shader_buffer
*buffer
,
1085 const shader_reg_maps
*reg_maps
, const DWORD
*pFunction
, void *backend_ctx
)
1087 IWineD3DBaseShaderImpl
* This
= (IWineD3DBaseShaderImpl
*) iface
;
1088 IWineD3DDeviceImpl
*device
= (IWineD3DDeviceImpl
*) This
->baseShader
.device
; /* To access shader backend callbacks */
1089 const struct wined3d_shader_frontend
*fe
= This
->baseShader
.frontend
;
1090 void *fe_data
= This
->baseShader
.frontend_data
;
1091 struct wined3d_shader_src_param src_rel_addr
[4];
1092 struct wined3d_shader_src_param src_param
[4];
1093 struct wined3d_shader_version shader_version
;
1094 struct wined3d_shader_src_param dst_rel_addr
;
1095 struct wined3d_shader_dst_param dst_param
;
1096 struct wined3d_shader_instruction ins
;
1097 struct wined3d_shader_context ctx
;
1098 const DWORD
*pToken
= pFunction
;
1101 /* Initialize current parsing state */
1103 ctx
.reg_maps
= reg_maps
;
1104 ctx
.buffer
= buffer
;
1105 ctx
.backend_data
= backend_ctx
;
1108 ins
.dst
= &dst_param
;
1109 ins
.src
= src_param
;
1110 This
->baseShader
.parse_state
.current_row
= 0;
1112 fe
->shader_read_header(fe_data
, &pToken
, &shader_version
);
1114 while (!fe
->shader_is_end(fe_data
, &pToken
))
1116 const char *comment
;
1119 /* Skip comment tokens */
1120 fe
->shader_read_comment(&pToken
, &comment
);
1121 if (comment
) continue;
1124 fe
->shader_read_opcode(fe_data
, &pToken
, &ins
, ¶m_size
);
1126 /* Unknown opcode and its parameters */
1127 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1129 TRACE("Skipping unrecognized instruction.\n");
1130 pToken
+= param_size
;
1135 if (ins
.handler_idx
== WINED3DSIH_DCL
1136 || ins
.handler_idx
== WINED3DSIH_NOP
1137 || ins
.handler_idx
== WINED3DSIH_DEF
1138 || ins
.handler_idx
== WINED3DSIH_DEFI
1139 || ins
.handler_idx
== WINED3DSIH_DEFB
1140 || ins
.handler_idx
== WINED3DSIH_PHASE
)
1142 pToken
+= param_size
;
1146 /* Destination token */
1147 if (ins
.dst_count
) fe
->shader_read_dst_param(fe_data
, &pToken
, &dst_param
, &dst_rel_addr
);
1149 /* Predication token */
1150 if (ins
.predicate
) ins
.predicate
= *pToken
++;
1152 /* Other source tokens */
1153 for (i
= 0; i
< ins
.src_count
; ++i
)
1155 fe
->shader_read_src_param(fe_data
, &pToken
, &src_param
[i
], &src_rel_addr
[i
]);
1158 /* Call appropriate function for output target */
1159 device
->shader_backend
->shader_handle_instruction(&ins
);
1163 static void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param
*dst
)
1165 DWORD mmask
= dst
->modifiers
;
1170 case 13: TRACE("_d8"); break;
1171 case 14: TRACE("_d4"); break;
1172 case 15: TRACE("_d2"); break;
1173 case 1: TRACE("_x2"); break;
1174 case 2: TRACE("_x4"); break;
1175 case 3: TRACE("_x8"); break;
1176 default: TRACE("_unhandled_shift(%d)", dst
->shift
); break;
1179 if (mmask
& WINED3DSPDM_SATURATE
) TRACE("_sat");
1180 if (mmask
& WINED3DSPDM_PARTIALPRECISION
) TRACE("_pp");
1181 if (mmask
& WINED3DSPDM_MSAMPCENTROID
) TRACE("_centroid");
1183 mmask
&= ~(WINED3DSPDM_SATURATE
| WINED3DSPDM_PARTIALPRECISION
| WINED3DSPDM_MSAMPCENTROID
);
1185 FIXME("_unrecognized_modifier(%#x)", mmask
);
1188 void shader_trace_init(const struct wined3d_shader_frontend
*fe
, void *fe_data
, const DWORD
*pFunction
)
1190 struct wined3d_shader_version shader_version
;
1191 const DWORD
* pToken
= pFunction
;
1192 const char *type_prefix
;
1195 TRACE("Parsing %p\n", pFunction
);
1197 fe
->shader_read_header(fe_data
, &pToken
, &shader_version
);
1199 switch (shader_version
.type
)
1201 case WINED3D_SHADER_TYPE_VERTEX
:
1205 case WINED3D_SHADER_TYPE_GEOMETRY
:
1209 case WINED3D_SHADER_TYPE_PIXEL
:
1214 FIXME("Unhandled shader type %#x.\n", shader_version
.type
);
1215 type_prefix
= "unknown";
1219 TRACE("%s_%u_%u\n", type_prefix
, shader_version
.major
, shader_version
.minor
);
1221 while (!fe
->shader_is_end(fe_data
, &pToken
))
1223 struct wined3d_shader_instruction ins
;
1224 const char *comment
;
1228 fe
->shader_read_comment(&pToken
, &comment
);
1231 TRACE("//%s\n", comment
);
1235 fe
->shader_read_opcode(fe_data
, &pToken
, &ins
, ¶m_size
);
1236 if (ins
.handler_idx
== WINED3DSIH_TABLE_SIZE
)
1238 TRACE("Skipping unrecognized instruction.\n");
1239 pToken
+= param_size
;
1243 if (ins
.handler_idx
== WINED3DSIH_DCL
)
1245 struct wined3d_shader_semantic semantic
;
1247 fe
->shader_read_semantic(&pToken
, &semantic
);
1249 shader_dump_decl_usage(&semantic
, &shader_version
);
1250 shader_dump_ins_modifiers(&semantic
.reg
);
1252 shader_dump_dst_param(&semantic
.reg
, &shader_version
);
1254 else if (ins
.handler_idx
== WINED3DSIH_DEF
)
1256 struct wined3d_shader_dst_param dst
;
1257 struct wined3d_shader_src_param rel_addr
;
1259 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
1261 TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(dst
.reg
.type
, dst
.reg
.idx
),
1262 *(const float *)(pToken
),
1263 *(const float *)(pToken
+ 1),
1264 *(const float *)(pToken
+ 2),
1265 *(const float *)(pToken
+ 3));
1268 else if (ins
.handler_idx
== WINED3DSIH_DEFI
)
1270 struct wined3d_shader_dst_param dst
;
1271 struct wined3d_shader_src_param rel_addr
;
1273 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
1275 TRACE("defi i%u = %d, %d, %d, %d", dst
.reg
.idx
,
1282 else if (ins
.handler_idx
== WINED3DSIH_DEFB
)
1284 struct wined3d_shader_dst_param dst
;
1285 struct wined3d_shader_src_param rel_addr
;
1287 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst
, &rel_addr
);
1289 TRACE("defb b%u = %s", dst
.reg
.idx
, *pToken
? "true" : "false");
1294 struct wined3d_shader_src_param dst_rel_addr
, src_rel_addr
;
1295 struct wined3d_shader_dst_param dst_param
;
1296 struct wined3d_shader_src_param src_param
;
1300 fe
->shader_read_dst_param(fe_data
, &pToken
, &dst_param
, &dst_rel_addr
);
1303 /* Print out predication source token first - it follows
1304 * the destination token. */
1307 fe
->shader_read_src_param(fe_data
, &pToken
, &src_param
, &src_rel_addr
);
1309 shader_dump_src_param(&src_param
, &shader_version
);
1313 /* PixWin marks instructions with the coissue flag with a '+' */
1314 if (ins
.coissue
) TRACE("+");
1316 TRACE("%s", shader_opcode_names
[ins
.handler_idx
]);
1318 if (ins
.handler_idx
== WINED3DSIH_IFC
1319 || ins
.handler_idx
== WINED3DSIH_BREAKC
)
1323 case COMPARISON_GT
: TRACE("_gt"); break;
1324 case COMPARISON_EQ
: TRACE("_eq"); break;
1325 case COMPARISON_GE
: TRACE("_ge"); break;
1326 case COMPARISON_LT
: TRACE("_lt"); break;
1327 case COMPARISON_NE
: TRACE("_ne"); break;
1328 case COMPARISON_LE
: TRACE("_le"); break;
1329 default: TRACE("_(%u)", ins
.flags
);
1332 else if (ins
.handler_idx
== WINED3DSIH_TEX
1333 && shader_version
.major
>= 2
1334 && (ins
.flags
& WINED3DSI_TEXLD_PROJECT
))
1339 /* We already read the destination token, print it. */
1342 shader_dump_ins_modifiers(&dst_param
);
1344 shader_dump_dst_param(&dst_param
, &shader_version
);
1347 /* Other source tokens */
1348 for (i
= ins
.dst_count
; i
< (ins
.dst_count
+ ins
.src_count
); ++i
)
1350 fe
->shader_read_src_param(fe_data
, &pToken
, &src_param
, &src_rel_addr
);
1351 TRACE(!i
? " " : ", ");
1352 shader_dump_src_param(&src_param
, &shader_version
);
1359 void shader_cleanup(IWineD3DBaseShader
*iface
)
1361 IWineD3DBaseShaderImpl
*This
= (IWineD3DBaseShaderImpl
*)iface
;
1363 ((IWineD3DDeviceImpl
*)This
->baseShader
.device
)->shader_backend
->shader_destroy(iface
);
1364 HeapFree(GetProcessHeap(), 0, This
->baseShader
.reg_maps
.constf
);
1365 HeapFree(GetProcessHeap(), 0, This
->baseShader
.function
);
1366 shader_delete_constant_list(&This
->baseShader
.constantsF
);
1367 shader_delete_constant_list(&This
->baseShader
.constantsB
);
1368 shader_delete_constant_list(&This
->baseShader
.constantsI
);
1369 list_remove(&This
->baseShader
.shader_list_entry
);
1371 if (This
->baseShader
.frontend
&& This
->baseShader
.frontend_data
)
1373 This
->baseShader
.frontend
->shader_free(This
->baseShader
.frontend_data
);
1377 static void shader_none_handle_instruction(const struct wined3d_shader_instruction
*ins
) {}
1378 static void shader_none_select(const struct wined3d_context
*context
, BOOL usePS
, BOOL useVS
) {}
1379 static void shader_none_select_depth_blt(IWineD3DDevice
*iface
, enum tex_types tex_type
) {}
1380 static void shader_none_deselect_depth_blt(IWineD3DDevice
*iface
) {}
1381 static void shader_none_update_float_vertex_constants(IWineD3DDevice
*iface
, UINT start
, UINT count
) {}
1382 static void shader_none_update_float_pixel_constants(IWineD3DDevice
*iface
, UINT start
, UINT count
) {}
1383 static void shader_none_load_constants(const struct wined3d_context
*context
, char usePS
, char useVS
) {}
1384 static void shader_none_load_np2fixup_constants(IWineD3DDevice
*iface
, char usePS
, char useVS
) {}
1385 static void shader_none_destroy(IWineD3DBaseShader
*iface
) {}
1386 static HRESULT
shader_none_alloc(IWineD3DDevice
*iface
) {return WINED3D_OK
;}
1387 static void shader_none_free(IWineD3DDevice
*iface
) {}
1388 static BOOL
shader_none_dirty_const(IWineD3DDevice
*iface
) {return FALSE
;}
1390 #define GLINFO_LOCATION (*gl_info)
1391 static void shader_none_get_caps(WINED3DDEVTYPE devtype
,
1392 const struct wined3d_gl_info
*gl_info
, struct shader_caps
*pCaps
)
1394 /* Set the shader caps to 0 for the none shader backend */
1395 pCaps
->VertexShaderVersion
= 0;
1396 pCaps
->PixelShaderVersion
= 0;
1397 pCaps
->PixelShader1xMaxValue
= 0.0f
;
1399 #undef GLINFO_LOCATION
1400 static BOOL
shader_none_color_fixup_supported(struct color_fixup_desc fixup
)
1402 if (TRACE_ON(d3d_shader
) && TRACE_ON(d3d
))
1404 TRACE("Checking support for fixup:\n");
1405 dump_color_fixup_desc(fixup
);
1408 /* Faked to make some apps happy. */
1409 if (!is_yuv_fixup(fixup
))
1415 TRACE("[FAILED]\n");
1419 const shader_backend_t none_shader_backend
= {
1420 shader_none_handle_instruction
,
1422 shader_none_select_depth_blt
,
1423 shader_none_deselect_depth_blt
,
1424 shader_none_update_float_vertex_constants
,
1425 shader_none_update_float_pixel_constants
,
1426 shader_none_load_constants
,
1427 shader_none_load_np2fixup_constants
,
1428 shader_none_destroy
,
1431 shader_none_dirty_const
,
1432 shader_none_get_caps
,
1433 shader_none_color_fixup_supported
,