Release 0.9.14.
[wine/multimedia.git] / dlls / wined3d / baseshader.c
blob4e304210f806a61fb50926dec0ee6043dcef91ad
1 /*
2 * shaders implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 * Copyright 2006 Ivan Gyurdiev
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include <string.h>
26 #include <stdio.h>
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
31 #define GLNAME_REQUIRE_GLSL ((const char *)1)
32 #define GLINFO_LOCATION (*gl_info)
34 typedef struct shader_reg_maps {
35 DWORD texcoord;
36 DWORD temporary;
37 DWORD address;
38 } shader_reg_maps;
40 inline static BOOL shader_is_version_token(DWORD token) {
41 return shader_is_pshader_version(token) ||
42 shader_is_vshader_version(token);
45 int shader_addline(
46 SHADER_BUFFER* buffer,
47 const char *format, ...) {
49 char* base = buffer->buffer + buffer->bsize;
50 int rc;
52 va_list args;
53 va_start(args, format);
54 rc = vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
55 va_end(args);
57 if (rc < 0 || /* C89 */
58 rc > SHADER_PGMSIZE - 1 - buffer->bsize) { /* C99 */
60 ERR("The buffer allocated for the shader program string "
61 "is too small at %d bytes.\n", SHADER_PGMSIZE);
62 buffer->bsize = SHADER_PGMSIZE - 1;
63 return -1;
66 buffer->bsize += rc;
67 buffer->lineNo++;
68 TRACE("GL HW (%u, %u) : %s", buffer->lineNo, buffer->bsize, base);
69 return 0;
72 const SHADER_OPCODE* shader_get_opcode(
73 IWineD3DBaseShader *iface, const DWORD code) {
75 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl*) iface;
77 DWORD i = 0;
78 DWORD version = This->baseShader.version;
79 DWORD hex_version = This->baseShader.hex_version;
80 const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
82 /** TODO: use dichotomic search */
83 while (NULL != shader_ins[i].name) {
84 if (((code & D3DSI_OPCODE_MASK) == shader_ins[i].opcode) &&
85 (((hex_version >= shader_ins[i].min_version) && (hex_version <= shader_ins[i].max_version)) ||
86 ((shader_ins[i].min_version == 0) && (shader_ins[i].max_version == 0)))) {
87 return &shader_ins[i];
89 ++i;
91 FIXME("Unsupported opcode %lx(%ld) masked %lx version %ld\n",
92 code, code, code & D3DSI_OPCODE_MASK, version);
93 return NULL;
96 /* Read a parameter opcode from the input stream,
97 * and possibly a relative addressing token.
98 * Return the number of tokens read */
99 int shader_get_param(
100 IWineD3DBaseShader* iface,
101 const DWORD* pToken,
102 DWORD* param,
103 DWORD* addr_token) {
105 /* PS >= 3.0 have relative addressing (with token)
106 * VS >= 2.0 have relative addressing (with token)
107 * VS >= 1.0 < 2.0 have relative addressing (without token)
108 * The version check below should work in general */
110 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
111 char rel_token = D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2 &&
112 ((*pToken & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
114 *param = *pToken;
115 *addr_token = rel_token? *(pToken + 1): 0;
116 return rel_token? 2:1;
119 /* Return the number of parameters to skip for an opcode */
120 static inline int shader_skip_opcode(
121 IWineD3DBaseShaderImpl* This,
122 const SHADER_OPCODE* curOpcode,
123 DWORD opcode_token) {
125 /* Shaders >= 2.0 may contain address tokens, but fortunately they
126 * have a useful legnth mask - use it here. Shaders 1.0 contain no such tokens */
128 return (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2)?
129 ((opcode_token & D3DSI_INSTLENGTH_MASK) >> D3DSI_INSTLENGTH_SHIFT):
130 curOpcode->num_params;
133 /* Read the parameters of an unrecognized opcode from the input stream
134 * Return the number of tokens read.
136 * Note: This function assumes source or destination token format.
137 * It will not work with specially-formatted tokens like DEF or DCL,
138 * but hopefully those would be recognized */
140 int shader_skip_unrecognized(
141 IWineD3DBaseShader* iface,
142 const DWORD* pToken) {
144 int tokens_read = 0;
145 int i = 0;
147 /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
148 while (*pToken & 0x80000000) {
150 DWORD param, addr_token;
151 tokens_read += shader_get_param(iface, pToken, &param, &addr_token);
152 pToken += tokens_read;
154 FIXME("Unrecognized opcode param: token=%08lX "
155 "addr_token=%08lX name=", param, addr_token);
156 shader_dump_param(iface, param, addr_token, i);
157 FIXME("\n");
158 ++i;
160 return tokens_read;
163 /* Note that this does not count the loop register
164 * as an address register. */
166 static void shader_get_registers_used(
167 IWineD3DBaseShader *iface,
168 shader_reg_maps* reg_maps,
169 CONST DWORD* pToken) {
171 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
173 if (pToken == NULL)
174 return;
176 reg_maps->temporary = 0;
177 reg_maps->texcoord = 0;
178 reg_maps->address = 0;
180 while (D3DVS_END() != *pToken) {
181 CONST SHADER_OPCODE* curOpcode;
182 DWORD opcode_token;
184 /* Skip version */
185 if (shader_is_version_token(*pToken)) {
186 ++pToken;
187 continue;
189 /* Skip comments */
190 } else if (shader_is_comment(*pToken)) {
191 DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
192 ++pToken;
193 pToken += comment_len;
194 continue;
197 /* Fetch opcode */
198 opcode_token = *pToken++;
199 curOpcode = shader_get_opcode(iface, opcode_token);
201 /* Unhandled opcode, and its parameters */
202 if (NULL == curOpcode) {
203 while (*pToken & 0x80000000)
204 ++pToken;
205 continue;
207 /* Skip declarations (for now) */
208 } else if (D3DSIO_DCL == curOpcode->opcode) {
209 pToken += curOpcode->num_params;
210 continue;
212 /* Skip definitions (for now) */
213 } else if (D3DSIO_DEF == curOpcode->opcode) {
214 pToken += curOpcode->num_params;
215 continue;
217 /* Set texture registers, and temporary registers */
218 } else {
219 int i, limit;
221 /* This will loop over all the registers and try to
222 * make a bitmask of the ones we're interested in.
224 * Relative addressing tokens are ignored, but that's
225 * okay, since we'll catch any address registers when
226 * they are initialized (required by spec) */
228 limit = (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED)?
229 curOpcode->num_params + 1: curOpcode->num_params;
231 for (i = 0; i < limit; ++i) {
233 DWORD param, addr_token, reg, regtype;
234 pToken += shader_get_param(iface, pToken, &param, &addr_token);
236 regtype = (param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT;
237 reg = param & D3DSP_REGNUM_MASK;
239 if (D3DSPR_TEXTURE == regtype) { /* vs: D3DSPR_ADDR */
241 if (shader_is_pshader_version(This->baseShader.hex_version))
242 reg_maps->texcoord |= (1 << reg);
243 else
244 reg_maps->address |= (1 << reg);
247 if (D3DSPR_TEMP == regtype)
248 reg_maps->temporary |= (1 << reg);
254 void shader_program_dump_decl_usage(
255 DWORD decl,
256 DWORD param) {
258 DWORD regtype = shader_get_regtype(param);
259 TRACE("dcl_");
261 if (regtype == D3DSPR_SAMPLER) {
262 DWORD ttype = decl & D3DSP_TEXTURETYPE_MASK;
264 switch (ttype) {
265 case D3DSTT_2D: TRACE("2d"); break;
266 case D3DSTT_CUBE: TRACE("cube"); break;
267 case D3DSTT_VOLUME: TRACE("volume"); break;
268 default: TRACE("unknown_ttype(%08lx)", ttype);
271 } else {
273 DWORD usage = decl & D3DSP_DCL_USAGE_MASK;
274 DWORD idx = (decl & D3DSP_DCL_USAGEINDEX_MASK) >> D3DSP_DCL_USAGEINDEX_SHIFT;
276 switch(usage) {
277 case D3DDECLUSAGE_POSITION:
278 TRACE("%s%ld", "position", idx);
279 break;
280 case D3DDECLUSAGE_BLENDINDICES:
281 TRACE("%s", "blend");
282 break;
283 case D3DDECLUSAGE_BLENDWEIGHT:
284 TRACE("%s", "weight");
285 break;
286 case D3DDECLUSAGE_NORMAL:
287 TRACE("%s%ld", "normal", idx);
288 break;
289 case D3DDECLUSAGE_PSIZE:
290 TRACE("%s", "psize");
291 break;
292 case D3DDECLUSAGE_COLOR:
293 if(idx == 0) {
294 TRACE("%s", "color");
295 } else {
296 TRACE("%s%ld", "specular", (idx - 1));
298 break;
299 case D3DDECLUSAGE_TEXCOORD:
300 TRACE("%s%ld", "texture", idx);
301 break;
302 case D3DDECLUSAGE_TANGENT:
303 TRACE("%s", "tangent");
304 break;
305 case D3DDECLUSAGE_BINORMAL:
306 TRACE("%s", "binormal");
307 break;
308 case D3DDECLUSAGE_TESSFACTOR:
309 TRACE("%s", "tessfactor");
310 break;
311 case D3DDECLUSAGE_POSITIONT:
312 TRACE("%s%ld", "positionT", idx);
313 break;
314 case D3DDECLUSAGE_FOG:
315 TRACE("%s", "fog");
316 break;
317 case D3DDECLUSAGE_DEPTH:
318 TRACE("%s", "depth");
319 break;
320 case D3DDECLUSAGE_SAMPLE:
321 TRACE("%s", "sample");
322 break;
323 default:
324 FIXME("unknown_semantics(%08lx)", usage);
329 static void shader_dump_arr_entry(
330 IWineD3DBaseShader *iface,
331 const DWORD param,
332 const DWORD addr_token,
333 int input) {
335 DWORD reg = param & D3DSP_REGNUM_MASK;
336 char relative =
337 ((param & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
339 TRACE("[");
340 if (relative) {
341 if (addr_token)
342 shader_dump_param(iface, addr_token, 0, input);
343 else
344 TRACE("a0.x");
345 TRACE(" + ");
347 TRACE("%lu]", reg);
350 void shader_dump_param(
351 IWineD3DBaseShader *iface,
352 const DWORD param,
353 const DWORD addr_token,
354 int input) {
356 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
357 static const char* rastout_reg_names[] = { "oPos", "oFog", "oPts" };
358 char swizzle_reg_chars[4];
360 DWORD reg = param & D3DSP_REGNUM_MASK;
361 DWORD regtype = shader_get_regtype(param);
363 /* There are some minor differences between pixel and vertex shaders */
364 BOOL pshader = shader_is_pshader_version(This->baseShader.hex_version);
366 /* For one, we'd prefer color components to be shown for pshaders.
367 * FIXME: use the swizzle function for this */
369 swizzle_reg_chars[0] = pshader? 'r': 'x';
370 swizzle_reg_chars[1] = pshader? 'g': 'y';
371 swizzle_reg_chars[2] = pshader? 'b': 'z';
372 swizzle_reg_chars[3] = pshader? 'a': 'w';
374 if (input) {
375 if ( ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) ||
376 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_BIASNEG) ||
377 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_SIGNNEG) ||
378 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_X2NEG) )
379 TRACE("-");
380 else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_COMP)
381 TRACE("1-");
382 else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NOT)
383 TRACE("!");
386 switch (regtype) {
387 case D3DSPR_TEMP:
388 TRACE("r%lu", reg);
389 break;
390 case D3DSPR_INPUT:
391 TRACE("v%lu", reg);
392 break;
393 case D3DSPR_CONST:
394 TRACE("c");
395 shader_dump_arr_entry(iface, param, addr_token, input);
396 break;
397 case D3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
398 TRACE("%c%lu", (pshader? 't':'a'), reg);
399 break;
400 case D3DSPR_RASTOUT:
401 TRACE("%s", rastout_reg_names[reg]);
402 break;
403 case D3DSPR_COLOROUT:
404 TRACE("oC%lu", reg);
405 break;
406 case D3DSPR_DEPTHOUT:
407 TRACE("oDepth");
408 break;
409 case D3DSPR_ATTROUT:
410 TRACE("oD%lu", reg);
411 break;
412 case D3DSPR_TEXCRDOUT:
414 /* Vertex shaders >= 3.0 use general purpose output registers
415 * (D3DSPR_OUTPUT), which can include an address token */
417 if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3) {
418 TRACE("o");
419 shader_dump_arr_entry(iface, param, addr_token, input);
421 else
422 TRACE("oT%lu", reg);
423 break;
424 case D3DSPR_CONSTINT:
425 TRACE("i");
426 shader_dump_arr_entry(iface, param, addr_token, input);
427 break;
428 case D3DSPR_CONSTBOOL:
429 TRACE("b");
430 shader_dump_arr_entry(iface, param, addr_token, input);
431 break;
432 case D3DSPR_LABEL:
433 TRACE("l%lu", reg);
434 break;
435 case D3DSPR_LOOP:
436 TRACE("aL");
437 break;
438 case D3DSPR_SAMPLER:
439 TRACE("s%lu", reg);
440 break;
441 case D3DSPR_PREDICATE:
442 TRACE("p%lu", reg);
443 break;
444 default:
445 TRACE("unhandled_rtype(%#lx)", regtype);
446 break;
449 if (!input) {
450 /* operand output (for modifiers and shift, see dump_ins_modifiers) */
452 if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
453 TRACE(".");
454 if (param & D3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
455 if (param & D3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
456 if (param & D3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
457 if (param & D3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
460 } else {
461 /** operand input */
462 DWORD swizzle = (param & D3DSP_SWIZZLE_MASK) >> D3DSP_SWIZZLE_SHIFT;
463 DWORD swizzle_r = swizzle & 0x03;
464 DWORD swizzle_g = (swizzle >> 2) & 0x03;
465 DWORD swizzle_b = (swizzle >> 4) & 0x03;
466 DWORD swizzle_a = (swizzle >> 6) & 0x03;
468 if (0 != (param & D3DSP_SRCMOD_MASK)) {
469 DWORD mask = param & D3DSP_SRCMOD_MASK;
470 switch (mask) {
471 case D3DSPSM_NONE: break;
472 case D3DSPSM_NEG: break;
473 case D3DSPSM_NOT: break;
474 case D3DSPSM_BIAS: TRACE("_bias"); break;
475 case D3DSPSM_BIASNEG: TRACE("_bias"); break;
476 case D3DSPSM_SIGN: TRACE("_bx2"); break;
477 case D3DSPSM_SIGNNEG: TRACE("_bx2"); break;
478 case D3DSPSM_COMP: break;
479 case D3DSPSM_X2: TRACE("_x2"); break;
480 case D3DSPSM_X2NEG: TRACE("_x2"); break;
481 case D3DSPSM_DZ: TRACE("_dz"); break;
482 case D3DSPSM_DW: TRACE("_dw"); break;
483 default:
484 TRACE("_unknown_modifier(%#lx)", mask >> D3DSP_SRCMOD_SHIFT);
489 * swizzle bits fields:
490 * RRGGBBAA
492 if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
493 if (swizzle_r == swizzle_g &&
494 swizzle_r == swizzle_b &&
495 swizzle_r == swizzle_a) {
496 TRACE(".%c", swizzle_reg_chars[swizzle_r]);
497 } else {
498 TRACE(".%c%c%c%c",
499 swizzle_reg_chars[swizzle_r],
500 swizzle_reg_chars[swizzle_g],
501 swizzle_reg_chars[swizzle_b],
502 swizzle_reg_chars[swizzle_a]);
508 /** Generate the variable & register declarations for the ARB_vertex_program
509 output target */
510 void generate_arb_declarations(
511 IWineD3DBaseShader *iface,
512 shader_reg_maps* reg_maps,
513 SHADER_BUFFER* buffer) {
515 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
516 DWORD i;
518 for(i = 0; i < This->baseShader.limits.temporary; i++) {
519 if (reg_maps->temporary & (1 << i))
520 shader_addline(buffer, "TEMP R%lu;\n", i);
523 for (i = 0; i < This->baseShader.limits.address; i++) {
524 if (reg_maps->address & (1 << i))
525 shader_addline(buffer, "ADDRESS A%ld;\n", i);
528 for(i = 0; i < This->baseShader.limits.texture; i++) {
529 if (reg_maps->texcoord & (1 << i))
530 shader_addline(buffer,"TEMP T%lu;\n", i);
533 /* Texture coordinate registers must be pre-loaded */
534 for (i = 0; i < This->baseShader.limits.texture; i++) {
535 if (reg_maps->texcoord & (1 << i))
536 shader_addline(buffer, "MOV T%lu, fragment.texcoord[%lu];\n", i, i);
539 /* Need to PARAM the environment parameters (constants) so we can use relative addressing */
540 shader_addline(buffer, "PARAM C[%d] = { program.env[0..%d] };\n",
541 This->baseShader.limits.constant_float,
542 This->baseShader.limits.constant_float - 1);
545 /** Generate the variable & register declarations for the GLSL
546 output target */
547 void generate_glsl_declarations(
548 IWineD3DBaseShader *iface,
549 shader_reg_maps* reg_maps,
550 SHADER_BUFFER* buffer) {
552 FIXME("GLSL not fully implemented yet.\n");
556 /** Shared code in order to generate the bulk of the shader string.
557 Use the shader_header_fct & shader_footer_fct to add strings
558 that are specific to pixel or vertex functions
559 NOTE: A description of how to parse tokens can be found at:
560 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/graphics/hh/graphics/usermodedisplaydriver_shader_cc8e4e05-f5c3-4ec0-8853-8ce07c1551b2.xml.asp */
561 void generate_base_shader(
562 IWineD3DBaseShader *iface,
563 SHADER_BUFFER* buffer,
564 CONST DWORD* pFunction) {
566 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
567 const DWORD *pToken = pFunction;
568 const SHADER_OPCODE *curOpcode = NULL;
569 SHADER_HANDLER hw_fct = NULL;
570 DWORD opcode_token;
571 DWORD i;
572 shader_reg_maps reg_maps;
574 /* Initialize current parsing state */
575 This->baseShader.parse_state.current_row = 0;
577 /* First pass: figure out which temporary and texture registers are used */
578 shader_get_registers_used(iface, &reg_maps, pToken);
580 /* TODO: check register usage against GL/Directx limits, and fail if they're exceeded
581 nUseAddressRegister < = GL_MAX_PROGRAM_ADDRESS_REGISTERS_AR
582 nUseTempRegister <= GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
585 /* Pre-declare registers */
586 if (wined3d_settings.shader_mode == SHADER_GLSL) {
587 generate_glsl_declarations(iface, &reg_maps, buffer);
588 shader_addline(buffer, "void main() {\n");
589 } else {
590 generate_arb_declarations(iface, &reg_maps, buffer);
593 /* Second pass, process opcodes */
594 if (NULL != pToken) {
595 while (D3DPS_END() != *pToken) {
597 /* Skip version token */
598 if (shader_is_version_token(*pToken)) {
599 ++pToken;
600 continue;
603 /* Skip comment tokens */
604 if (shader_is_comment(*pToken)) {
605 DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
606 ++pToken;
607 TRACE("#%s\n", (char*)pToken);
608 pToken += comment_len;
609 continue;
612 /* Read opcode */
613 opcode_token = *pToken++;
614 curOpcode = shader_get_opcode(iface, opcode_token);
615 hw_fct = (wined3d_settings.shader_mode ==
616 SHADER_GLSL ? curOpcode->hw_glsl_fct : curOpcode->hw_fct);
618 /* Unknown opcode and its parameters */
619 if (NULL == curOpcode) {
620 FIXME("Unrecognized opcode: token=%08lX\n", opcode_token);
621 pToken += shader_skip_unrecognized(iface, pToken);
623 /* If a generator function is set for current shader target, use it */
624 } else if (hw_fct != NULL) {
626 SHADER_OPCODE_ARG hw_arg;
628 hw_arg.shader = iface;
629 hw_arg.opcode = curOpcode;
630 hw_arg.buffer = buffer;
632 if (curOpcode->num_params > 0) {
634 DWORD param, addr_token = 0;
636 /* DCL instruction has usage dst parameter, not register */
637 if (curOpcode->opcode == D3DSIO_DCL)
638 param = *pToken++;
639 else
640 pToken += shader_get_param(iface, pToken, &param, &addr_token);
642 hw_arg.dst = param;
643 hw_arg.dst_addr = addr_token;
645 if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED)
646 hw_arg.predicate = *pToken++;
648 for (i = 1; i < curOpcode->num_params; i++) {
649 /* DEF* instructions have constant src parameters, not registers */
650 if (curOpcode->opcode == D3DSIO_DEF ||
651 curOpcode->opcode == D3DSIO_DEFI ||
652 curOpcode->opcode == D3DSIO_DEFB) {
653 param = *pToken++;
655 } else
656 pToken += shader_get_param(iface, pToken, &param, &addr_token);
658 hw_arg.src[i-1] = param;
659 hw_arg.src_addr[i-1] = addr_token;
663 /* Call appropriate function for output target */
664 hw_fct(&hw_arg);
666 } else {
668 /* Unless we encounter a no-op command, this opcode is unrecognized */
669 if (curOpcode->opcode != D3DSIO_NOP) {
670 FIXME("Can't handle opcode %s in hwShader\n", curOpcode->name);
671 pToken += shader_skip_opcode(This, curOpcode, opcode_token);
675 /* TODO: What about result.depth? */
680 /** Prints the GLSL info log which will contain error messages if they exist */
681 void print_glsl_info_log(
682 WineD3D_GL_Info *gl_info,
683 GLhandleARB obj)
685 int infologLength = 0;
686 char *infoLog;
688 GL_EXTCALL(glGetObjectParameterivARB(obj,
689 GL_OBJECT_INFO_LOG_LENGTH_ARB,
690 &infologLength));
692 if (infologLength > 0)
694 infoLog = (char *)HeapAlloc(GetProcessHeap(), 0, infologLength);
695 GL_EXTCALL(glGetInfoLogARB(obj, infologLength, NULL, infoLog));
696 FIXME("Error received from GLSL shader #%u: %s", obj, debugstr_a(infoLog));
697 HeapFree(GetProcessHeap(), 0, infoLog);
701 void shader_dump_ins_modifiers(const DWORD output) {
703 DWORD shift = (output & D3DSP_DSTSHIFT_MASK) >> D3DSP_DSTSHIFT_SHIFT;
704 DWORD mmask = output & D3DSP_DSTMOD_MASK;
706 switch (shift) {
707 case 0: break;
708 case 13: TRACE("_d8"); break;
709 case 14: TRACE("_d4"); break;
710 case 15: TRACE("_d2"); break;
711 case 1: TRACE("_x2"); break;
712 case 2: TRACE("_x4"); break;
713 case 3: TRACE("_x8"); break;
714 default: TRACE("_unhandled_shift(%ld)", shift); break;
717 if (mmask & D3DSPDM_SATURATE) TRACE("_sat");
718 if (mmask & D3DSPDM_PARTIALPRECISION) TRACE("_pp");
719 if (mmask & D3DSPDM_MSAMPCENTROID) TRACE("_centroid");
721 mmask &= ~(D3DSPDM_SATURATE | D3DSPDM_PARTIALPRECISION | D3DSPDM_MSAMPCENTROID);
722 if (mmask)
723 FIXME("_unrecognized_modifier(%#lx)", mmask >> D3DSP_DSTMOD_SHIFT);
726 /* TODO: Move other shared code here */