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
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
31 #define GLNAME_REQUIRE_GLSL ((const char *)1)
33 inline static BOOL shader_is_version_token(DWORD token) {
34 return shader_is_pshader_version(token) ||
35 shader_is_vshader_version(token);
39 SHADER_BUFFER* buffer,
40 const char *format, ...) {
42 char* base = buffer->buffer + buffer->bsize;
46 va_start(args, format);
47 rc = vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
50 if (rc < 0 || /* C89 */
51 rc > SHADER_PGMSIZE - 1 - buffer->bsize) { /* C99 */
53 ERR("The buffer allocated for the shader program string "
54 "is too small at %d bytes.\n", SHADER_PGMSIZE);
55 buffer->bsize = SHADER_PGMSIZE - 1;
61 TRACE("GL HW (%u, %u) : %s", buffer->lineNo, buffer->bsize, base);
65 const SHADER_OPCODE* shader_get_opcode(
66 IWineD3DBaseShader *iface, const DWORD code) {
68 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl*) iface;
71 DWORD hex_version = This->baseShader.hex_version;
72 const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
74 /** TODO: use dichotomic search */
75 while (NULL != shader_ins[i].name) {
76 if (((code & D3DSI_OPCODE_MASK) == shader_ins[i].opcode) &&
77 (((hex_version >= shader_ins[i].min_version) && (hex_version <= shader_ins[i].max_version)) ||
78 ((shader_ins[i].min_version == 0) && (shader_ins[i].max_version == 0)))) {
79 return &shader_ins[i];
83 FIXME("Unsupported opcode %#lx(%ld) masked %#lx, shader version %#lx\n",
84 code, code, code & D3DSI_OPCODE_MASK, hex_version);
88 /* Read a parameter opcode from the input stream,
89 * and possibly a relative addressing token.
90 * Return the number of tokens read */
92 IWineD3DBaseShader* iface,
97 /* PS >= 3.0 have relative addressing (with token)
98 * VS >= 2.0 have relative addressing (with token)
99 * VS >= 1.0 < 2.0 have relative addressing (without token)
100 * The version check below should work in general */
102 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
103 char rel_token = D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2 &&
104 ((*pToken & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
107 *addr_token = rel_token? *(pToken + 1): 0;
108 return rel_token? 2:1;
111 /* Return the number of parameters to skip for an opcode */
112 static inline int shader_skip_opcode(
113 IWineD3DBaseShaderImpl* This,
114 const SHADER_OPCODE* curOpcode,
115 DWORD opcode_token) {
117 /* Shaders >= 2.0 may contain address tokens, but fortunately they
118 * have a useful legnth mask - use it here. Shaders 1.0 contain no such tokens */
120 return (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2)?
121 ((opcode_token & D3DSI_INSTLENGTH_MASK) >> D3DSI_INSTLENGTH_SHIFT):
122 curOpcode->num_params;
125 /* Read the parameters of an unrecognized opcode from the input stream
126 * Return the number of tokens read.
128 * Note: This function assumes source or destination token format.
129 * It will not work with specially-formatted tokens like DEF or DCL,
130 * but hopefully those would be recognized */
132 int shader_skip_unrecognized(
133 IWineD3DBaseShader* iface,
134 const DWORD* pToken) {
139 /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
140 while (*pToken & 0x80000000) {
142 DWORD param, addr_token;
143 tokens_read += shader_get_param(iface, pToken, ¶m, &addr_token);
144 pToken += tokens_read;
146 FIXME("Unrecognized opcode param: token=%08lX "
147 "addr_token=%08lX name=", param, addr_token);
148 shader_dump_param(iface, param, addr_token, i);
155 /* Convert floating point offset relative
156 * to a register file to an absolute offset for float constants */
158 unsigned int shader_get_float_offset(const DWORD reg) {
160 unsigned int regnum = reg & D3DSP_REGNUM_MASK;
161 int regtype = shader_get_regtype(reg);
164 case D3DSPR_CONST: return regnum;
165 case D3DSPR_CONST2: return 2048 + regnum;
166 case D3DSPR_CONST3: return 4096 + regnum;
167 case D3DSPR_CONST4: return 6144 + regnum;
169 FIXME("Unsupported register type: %d\n", regtype);
174 /* Note that this does not count the loop register
175 * as an address register. */
177 void shader_get_registers_used(
178 IWineD3DBaseShader *iface,
179 shader_reg_maps* reg_maps,
180 semantic* semantics_in,
181 semantic* semantics_out,
182 CONST DWORD* pToken) {
184 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
186 /* There are some minor differences between pixel and vertex shaders */
187 char pshader = shader_is_pshader_version(This->baseShader.hex_version);
192 while (D3DVS_END() != *pToken) {
193 CONST SHADER_OPCODE* curOpcode;
197 if (shader_is_version_token(*pToken)) {
202 } else if (shader_is_comment(*pToken)) {
203 DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
205 pToken += comment_len;
210 opcode_token = *pToken++;
211 curOpcode = shader_get_opcode(iface, opcode_token);
213 /* Unhandled opcode, and its parameters */
214 if (NULL == curOpcode) {
215 while (*pToken & 0x80000000)
218 /* Handle declarations */
219 } else if (D3DSIO_DCL == curOpcode->opcode) {
221 DWORD usage = *pToken++;
222 DWORD param = *pToken++;
223 DWORD regtype = shader_get_regtype(param);
224 unsigned int regnum = param & D3DSP_REGNUM_MASK;
226 /* Vshader: mark attributes used
227 Pshader: mark 3.0 input registers used, save token */
228 if (D3DSPR_INPUT == regtype) {
231 reg_maps->attributes[regnum] = 1;
233 reg_maps->packed_input[regnum] = 1;
235 semantics_in[regnum].usage = usage;
236 semantics_in[regnum].reg = param;
238 /* Vshader: mark 3.0 output registers used, save token */
239 } else if (D3DSPR_OUTPUT == regtype) {
240 reg_maps->packed_output[regnum] = 1;
241 semantics_out[regnum].usage = usage;
242 semantics_out[regnum].reg = param;
244 /* Save sampler usage token */
245 } else if (D3DSPR_SAMPLER == regtype)
246 reg_maps->samplers[regnum] = usage;
248 /* Skip definitions (for now) */
249 } else if (D3DSIO_DEF == curOpcode->opcode) {
250 pToken += curOpcode->num_params;
252 /* If there's a loop in the shader */
253 } else if (D3DSIO_LOOP == curOpcode->opcode) {
255 pToken += curOpcode->num_params;
257 /* Set texture, address, temporary registers */
261 /* Declare 1.X samplers implicitly, based on the destination reg. number */
262 if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 &&
263 (D3DSIO_TEX == curOpcode->opcode ||
264 D3DSIO_TEXBEM == curOpcode->opcode ||
265 D3DSIO_TEXM3x2TEX == curOpcode->opcode ||
266 D3DSIO_TEXM3x3TEX == curOpcode->opcode)) {
268 /* Fake sampler usage, only set reserved bit and ttype */
269 DWORD sampler_code = *pToken & D3DSP_REGNUM_MASK;
270 reg_maps->samplers[sampler_code] = (0x1 << 31) | D3DSTT_2D;
272 } else if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 &&
273 (D3DSIO_TEXM3x3SPEC == curOpcode->opcode ||
274 D3DSIO_TEXM3x3VSPEC == curOpcode->opcode)) {
276 /* 3D sampler usage, only set reserved bit and ttype
277 * FIXME: This could be either Cube or Volume, but we wouldn't know unless
278 * we waited to generate the shader until the textures were all bound.
279 * For now, use Cube textures because they are more common. */
280 DWORD sampler_code = *pToken & D3DSP_REGNUM_MASK;
281 reg_maps->samplers[sampler_code] = (0x1 << 31) | D3DSTT_CUBE;
284 /* This will loop over all the registers and try to
285 * make a bitmask of the ones we're interested in.
287 * Relative addressing tokens are ignored, but that's
288 * okay, since we'll catch any address registers when
289 * they are initialized (required by spec) */
291 limit = (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED)?
292 curOpcode->num_params + 1: curOpcode->num_params;
294 for (i = 0; i < limit; ++i) {
296 DWORD param, addr_token, reg, regtype;
297 pToken += shader_get_param(iface, pToken, ¶m, &addr_token);
299 regtype = shader_get_regtype(param);
300 reg = param & D3DSP_REGNUM_MASK;
302 if (D3DSPR_TEXTURE == regtype) { /* vs: D3DSPR_ADDR */
305 reg_maps->texcoord[reg] = 1;
307 reg_maps->address[reg] = 1;
310 else if (D3DSPR_TEMP == regtype)
311 reg_maps->temporary[reg] = 1;
313 else if (D3DSPR_INPUT == regtype && !pshader)
314 reg_maps->attributes[reg] = 1;
320 static void shader_dump_decl_usage(
321 IWineD3DBaseShaderImpl* This,
325 DWORD regtype = shader_get_regtype(param);
329 if (regtype == D3DSPR_SAMPLER) {
330 DWORD ttype = decl & D3DSP_TEXTURETYPE_MASK;
333 case D3DSTT_2D: TRACE("_2d"); break;
334 case D3DSTT_CUBE: TRACE("_cube"); break;
335 case D3DSTT_VOLUME: TRACE("_volume"); break;
336 default: TRACE("_unknown_ttype(%08lx)", ttype);
341 DWORD usage = decl & D3DSP_DCL_USAGE_MASK;
342 DWORD idx = (decl & D3DSP_DCL_USAGEINDEX_MASK) >> D3DSP_DCL_USAGEINDEX_SHIFT;
344 /* Pixel shaders 3.0 don't have usage semantics */
345 char pshader = shader_is_pshader_version(This->baseShader.hex_version);
346 if (pshader && This->baseShader.hex_version < D3DPS_VERSION(3,0))
352 case D3DDECLUSAGE_POSITION:
353 TRACE("%s%ld", "position", idx);
355 case D3DDECLUSAGE_BLENDINDICES:
356 TRACE("%s", "blend");
358 case D3DDECLUSAGE_BLENDWEIGHT:
359 TRACE("%s", "weight");
361 case D3DDECLUSAGE_NORMAL:
362 TRACE("%s%ld", "normal", idx);
364 case D3DDECLUSAGE_PSIZE:
365 TRACE("%s", "psize");
367 case D3DDECLUSAGE_COLOR:
369 TRACE("%s", "color");
371 TRACE("%s%ld", "specular", (idx - 1));
374 case D3DDECLUSAGE_TEXCOORD:
375 TRACE("%s%ld", "texture", idx);
377 case D3DDECLUSAGE_TANGENT:
378 TRACE("%s", "tangent");
380 case D3DDECLUSAGE_BINORMAL:
381 TRACE("%s", "binormal");
383 case D3DDECLUSAGE_TESSFACTOR:
384 TRACE("%s", "tessfactor");
386 case D3DDECLUSAGE_POSITIONT:
387 TRACE("%s%ld", "positionT", idx);
389 case D3DDECLUSAGE_FOG:
392 case D3DDECLUSAGE_DEPTH:
393 TRACE("%s", "depth");
395 case D3DDECLUSAGE_SAMPLE:
396 TRACE("%s", "sample");
399 FIXME("unknown_semantics(%08lx)", usage);
404 static void shader_dump_arr_entry(
405 IWineD3DBaseShader *iface,
407 const DWORD addr_token,
412 ((param & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
417 shader_dump_param(iface, addr_token, 0, input);
427 void shader_dump_param(
428 IWineD3DBaseShader *iface,
430 const DWORD addr_token,
433 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
434 static const char* rastout_reg_names[] = { "oPos", "oFog", "oPts" };
435 char swizzle_reg_chars[4];
437 DWORD reg = param & D3DSP_REGNUM_MASK;
438 DWORD regtype = shader_get_regtype(param);
440 /* There are some minor differences between pixel and vertex shaders */
441 char pshader = shader_is_pshader_version(This->baseShader.hex_version);
443 /* For one, we'd prefer color components to be shown for pshaders.
444 * FIXME: use the swizzle function for this */
446 swizzle_reg_chars[0] = pshader? 'r': 'x';
447 swizzle_reg_chars[1] = pshader? 'g': 'y';
448 swizzle_reg_chars[2] = pshader? 'b': 'z';
449 swizzle_reg_chars[3] = pshader? 'a': 'w';
452 if ( ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) ||
453 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_BIASNEG) ||
454 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_SIGNNEG) ||
455 ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_X2NEG) )
457 else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_COMP)
459 else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NOT)
469 shader_dump_arr_entry(iface, param, addr_token, reg, input);
476 shader_dump_arr_entry(iface, param, addr_token, shader_get_float_offset(param), input);
478 case D3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
479 TRACE("%c%lu", (pshader? 't':'a'), reg);
482 TRACE("%s", rastout_reg_names[reg]);
484 case D3DSPR_COLOROUT:
487 case D3DSPR_DEPTHOUT:
493 case D3DSPR_TEXCRDOUT:
495 /* Vertex shaders >= 3.0 use general purpose output registers
496 * (D3DSPR_OUTPUT), which can include an address token */
498 if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3) {
500 shader_dump_arr_entry(iface, param, addr_token, reg, input);
505 case D3DSPR_CONSTINT:
507 shader_dump_arr_entry(iface, param, addr_token, reg, input);
509 case D3DSPR_CONSTBOOL:
511 shader_dump_arr_entry(iface, param, addr_token, reg, input);
522 case D3DSPR_PREDICATE:
526 TRACE("unhandled_rtype(%#lx)", regtype);
531 /* operand output (for modifiers and shift, see dump_ins_modifiers) */
533 if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
535 if (param & D3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
536 if (param & D3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
537 if (param & D3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
538 if (param & D3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
543 DWORD swizzle = (param & D3DSP_SWIZZLE_MASK) >> D3DSP_SWIZZLE_SHIFT;
544 DWORD swizzle_r = swizzle & 0x03;
545 DWORD swizzle_g = (swizzle >> 2) & 0x03;
546 DWORD swizzle_b = (swizzle >> 4) & 0x03;
547 DWORD swizzle_a = (swizzle >> 6) & 0x03;
549 if (0 != (param & D3DSP_SRCMOD_MASK)) {
550 DWORD mask = param & D3DSP_SRCMOD_MASK;
552 case D3DSPSM_NONE: break;
553 case D3DSPSM_NEG: break;
554 case D3DSPSM_NOT: break;
555 case D3DSPSM_BIAS: TRACE("_bias"); break;
556 case D3DSPSM_BIASNEG: TRACE("_bias"); break;
557 case D3DSPSM_SIGN: TRACE("_bx2"); break;
558 case D3DSPSM_SIGNNEG: TRACE("_bx2"); break;
559 case D3DSPSM_COMP: break;
560 case D3DSPSM_X2: TRACE("_x2"); break;
561 case D3DSPSM_X2NEG: TRACE("_x2"); break;
562 case D3DSPSM_DZ: TRACE("_dz"); break;
563 case D3DSPSM_DW: TRACE("_dw"); break;
565 TRACE("_unknown_modifier(%#lx)", mask >> D3DSP_SRCMOD_SHIFT);
570 * swizzle bits fields:
573 if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
574 if (swizzle_r == swizzle_g &&
575 swizzle_r == swizzle_b &&
576 swizzle_r == swizzle_a) {
577 TRACE(".%c", swizzle_reg_chars[swizzle_r]);
580 swizzle_reg_chars[swizzle_r],
581 swizzle_reg_chars[swizzle_g],
582 swizzle_reg_chars[swizzle_b],
583 swizzle_reg_chars[swizzle_a]);
589 /** Shared code in order to generate the bulk of the shader string.
590 Use the shader_header_fct & shader_footer_fct to add strings
591 that are specific to pixel or vertex functions
592 NOTE: A description of how to parse tokens can be found at:
593 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/graphics/hh/graphics/usermodedisplaydriver_shader_cc8e4e05-f5c3-4ec0-8853-8ce07c1551b2.xml.asp */
594 void shader_generate_main(
595 IWineD3DBaseShader *iface,
596 SHADER_BUFFER* buffer,
597 shader_reg_maps* reg_maps,
598 CONST DWORD* pFunction) {
600 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
601 const DWORD *pToken = pFunction;
602 const SHADER_OPCODE *curOpcode = NULL;
603 SHADER_HANDLER hw_fct = NULL;
606 SHADER_OPCODE_ARG hw_arg;
608 /* Initialize current parsing state */
609 hw_arg.shader = iface;
610 hw_arg.buffer = buffer;
611 hw_arg.reg_maps = reg_maps;
612 This->baseShader.parse_state.current_row = 0;
614 /* Second pass, process opcodes */
615 if (NULL != pToken) {
616 while (D3DPS_END() != *pToken) {
618 /* Skip version token */
619 if (shader_is_version_token(*pToken)) {
624 /* Skip comment tokens */
625 if (shader_is_comment(*pToken)) {
626 DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
628 TRACE("#%s\n", (char*)pToken);
629 pToken += comment_len;
634 opcode_token = *pToken++;
635 curOpcode = shader_get_opcode(iface, opcode_token);
638 if (curOpcode == NULL)
640 else if (This->baseShader.shader_mode == SHADER_GLSL)
641 hw_fct = curOpcode->hw_glsl_fct;
642 else if (This->baseShader.shader_mode == SHADER_ARB)
643 hw_fct = curOpcode->hw_fct;
645 /* Unknown opcode and its parameters */
646 if (NULL == curOpcode) {
647 FIXME("Unrecognized opcode: token=%08lX\n", opcode_token);
648 pToken += shader_skip_unrecognized(iface, pToken);
651 } else if (D3DSIO_DCL == curOpcode->opcode ||
652 D3DSIO_NOP == curOpcode->opcode) {
654 pToken += shader_skip_opcode(This, curOpcode, opcode_token);
656 /* If a generator function is set for current shader target, use it */
657 } else if (hw_fct != NULL) {
659 hw_arg.opcode = curOpcode;
661 /* Destination token */
662 if (curOpcode->dst_token) {
664 DWORD param, addr_token = 0;
665 pToken += shader_get_param(iface, pToken, ¶m, &addr_token);
667 hw_arg.dst_addr = addr_token;
670 /* Predication token */
671 if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED)
672 hw_arg.predicate = *pToken++;
674 /* Other source tokens */
675 for (i = curOpcode->dst_token; i < curOpcode->num_params; i++) {
677 DWORD param, addr_token = 0;
679 /* DEF* instructions have constant src parameters, not registers */
680 if (curOpcode->opcode == D3DSIO_DEF ||
681 curOpcode->opcode == D3DSIO_DEFI ||
682 curOpcode->opcode == D3DSIO_DEFB) {
686 pToken += shader_get_param(iface, pToken, ¶m, &addr_token);
688 hw_arg.src[i-1] = param;
689 hw_arg.src_addr[i-1] = addr_token;
692 /* Call appropriate function for output target */
695 /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
696 if (This->baseShader.shader_mode == SHADER_GLSL)
697 shader_glsl_add_instruction_modifiers(&hw_arg);
699 /* Unhandled opcode */
702 FIXME("Can't handle opcode %s in hwShader\n", curOpcode->name);
703 pToken += shader_skip_opcode(This, curOpcode, opcode_token);
706 /* TODO: What about result.depth? */
711 void shader_dump_ins_modifiers(const DWORD output) {
713 DWORD shift = (output & D3DSP_DSTSHIFT_MASK) >> D3DSP_DSTSHIFT_SHIFT;
714 DWORD mmask = output & D3DSP_DSTMOD_MASK;
718 case 13: TRACE("_d8"); break;
719 case 14: TRACE("_d4"); break;
720 case 15: TRACE("_d2"); break;
721 case 1: TRACE("_x2"); break;
722 case 2: TRACE("_x4"); break;
723 case 3: TRACE("_x8"); break;
724 default: TRACE("_unhandled_shift(%ld)", shift); break;
727 if (mmask & D3DSPDM_SATURATE) TRACE("_sat");
728 if (mmask & D3DSPDM_PARTIALPRECISION) TRACE("_pp");
729 if (mmask & D3DSPDM_MSAMPCENTROID) TRACE("_centroid");
731 mmask &= ~(D3DSPDM_SATURATE | D3DSPDM_PARTIALPRECISION | D3DSPDM_MSAMPCENTROID);
733 FIXME("_unrecognized_modifier(%#lx)", mmask >> D3DSP_DSTMOD_SHIFT);
736 /* First pass: trace shader, initialize length and version */
737 void shader_trace_init(
738 IWineD3DBaseShader *iface,
739 const DWORD* pFunction) {
741 IWineD3DBaseShaderImpl *This =(IWineD3DBaseShaderImpl *)iface;
743 const DWORD* pToken = pFunction;
744 const SHADER_OPCODE* curOpcode = NULL;
746 unsigned int len = 0;
749 TRACE("(%p) : Parsing programme\n", This);
751 if (NULL != pToken) {
752 while (D3DVS_END() != *pToken) {
753 if (shader_is_version_token(*pToken)) { /** version */
754 This->baseShader.hex_version = *pToken;
755 TRACE("%s_%lu_%lu\n", shader_is_pshader_version(This->baseShader.hex_version)? "ps": "vs",
756 D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version),
757 D3DSHADER_VERSION_MINOR(This->baseShader.hex_version));
762 if (shader_is_comment(*pToken)) { /** comment */
763 DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
765 TRACE("//%s\n", (char*)pToken);
766 pToken += comment_len;
767 len += comment_len + 1;
770 opcode_token = *pToken++;
771 curOpcode = shader_get_opcode(iface, opcode_token);
774 if (NULL == curOpcode) {
776 FIXME("Unrecognized opcode: token=%08lX\n", opcode_token);
777 tokens_read = shader_skip_unrecognized(iface, pToken);
778 pToken += tokens_read;
782 if (curOpcode->opcode == D3DSIO_DCL) {
784 DWORD usage = *pToken;
785 DWORD param = *(pToken + 1);
787 shader_dump_decl_usage(This, usage, param);
788 shader_dump_ins_modifiers(param);
790 shader_dump_param(iface, param, 0, 0);
794 } else if (curOpcode->opcode == D3DSIO_DEF) {
796 unsigned int offset = shader_get_float_offset(*pToken);
798 TRACE("def c%u = %f, %f, %f, %f", offset,
799 *(float *)(pToken + 1),
800 *(float *)(pToken + 2),
801 *(float *)(pToken + 3),
802 *(float *)(pToken + 4));
806 } else if (curOpcode->opcode == D3DSIO_DEFI) {
808 TRACE("defi i%lu = %ld, %ld, %ld, %ld", *pToken & D3DSP_REGNUM_MASK,
809 (long) *(pToken + 1),
810 (long) *(pToken + 2),
811 (long) *(pToken + 3),
812 (long) *(pToken + 4));
817 } else if (curOpcode->opcode == D3DSIO_DEFB) {
819 TRACE("defb b%lu = %s", *pToken & D3DSP_REGNUM_MASK,
820 *(pToken + 1)? "true": "false");
827 DWORD param, addr_token;
830 /* Print out predication source token first - it follows
831 * the destination token. */
832 if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED) {
834 shader_dump_param(iface, *(pToken + 2), 0, 1);
838 TRACE("%s", curOpcode->name);
840 /* Destination token */
841 if (curOpcode->dst_token) {
843 /* Destination token */
844 tokens_read = shader_get_param(iface, pToken, ¶m, &addr_token);
845 pToken += tokens_read;
848 shader_dump_ins_modifiers(param);
850 shader_dump_param(iface, param, addr_token, 0);
853 /* Predication token - already printed out, just skip it */
854 if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED) {
859 /* Other source tokens */
860 for (i = curOpcode->dst_token; i < curOpcode->num_params; ++i) {
862 tokens_read = shader_get_param(iface, pToken, ¶m, &addr_token);
863 pToken += tokens_read;
866 TRACE((i == 0)? " " : ", ");
867 shader_dump_param(iface, param, addr_token, 1);
873 This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
875 This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
879 /* TODO: Move other shared code here */