ReactOS  0.4.14-dev-115-g4576127
shader_sm1.c
Go to the documentation of this file.
1 /*
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 Stefan Dösinger for CodeWeavers
8  * Copyright 2009 Henri Verbeet for CodeWeavers
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 #include "config.h"
26 #include "wine/port.h"
27 
28 #include "wined3d_private.h"
29 
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
31 
32 /* DCL usage masks */
33 #define WINED3D_SM1_DCL_USAGE_SHIFT 0
34 #define WINED3D_SM1_DCL_USAGE_MASK (0xfu << WINED3D_SM1_DCL_USAGE_SHIFT)
35 #define WINED3D_SM1_DCL_USAGE_INDEX_SHIFT 16
36 #define WINED3D_SM1_DCL_USAGE_INDEX_MASK (0xfu << WINED3D_SM1_DCL_USAGE_INDEX_SHIFT)
37 
38 /* DCL sampler type */
39 #define WINED3D_SM1_RESOURCE_TYPE_SHIFT 27
40 #define WINED3D_SM1_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM1_RESOURCE_TYPE_SHIFT)
41 
42 /* Opcode-related masks */
43 #define WINED3D_SM1_OPCODE_MASK 0x0000ffff
44 
45 #define WINED3D_SM1_INSTRUCTION_FLAGS_SHIFT 16
46 #define WINED3D_SM1_INSTRUCTION_FLAGS_MASK (0xffu << WINED3D_SM1_INSTRUCTION_FLAGS_SHIFT)
47 
48 #define WINED3D_SM1_INSTRUCTION_LENGTH_SHIFT 24
49 #define WINED3D_SM1_INSTRUCTION_LENGTH_MASK (0xfu << WINED3D_SM1_INSTRUCTION_LENGTH_SHIFT)
50 
51 #define WINED3D_SM1_COISSUE (0x1u << 30)
52 
53 #define WINED3D_SM1_COMMENT_SIZE_SHIFT 16
54 #define WINED3D_SM1_COMMENT_SIZE_MASK (0x7fffu << WINED3D_SM1_COMMENT_SIZE_SHIFT)
55 
56 #define WINED3D_SM1_INSTRUCTION_PREDICATED (0x1u << 28)
57 
58 /* Register number mask */
59 #define WINED3D_SM1_REGISTER_NUMBER_MASK 0x000007ff
60 
61 /* Register type masks */
62 #define WINED3D_SM1_REGISTER_TYPE_SHIFT 28
63 #define WINED3D_SM1_REGISTER_TYPE_MASK (0x7u << WINED3D_SM1_REGISTER_TYPE_SHIFT)
64 #define WINED3D_SM1_REGISTER_TYPE_SHIFT2 8
65 #define WINED3D_SM1_REGISTER_TYPE_MASK2 (0x18u << WINED3D_SM1_REGISTER_TYPE_SHIFT2)
66 
67 /* Relative addressing mask */
68 #define WINED3D_SM1_ADDRESS_MODE_SHIFT 13
69 #define WINED3D_SM1_ADDRESS_MODE_MASK (0x1u << WINED3D_SM1_ADDRESS_MODE_SHIFT)
70 
71 /* Destination modifier mask */
72 #define WINED3D_SM1_DST_MODIFIER_SHIFT 20
73 #define WINED3D_SM1_DST_MODIFIER_MASK (0xfu << WINED3D_SM1_DST_MODIFIER_SHIFT)
74 
75 /* Destination shift mask */
76 #define WINED3D_SM1_DSTSHIFT_SHIFT 24
77 #define WINED3D_SM1_DSTSHIFT_MASK (0xfu << WINED3D_SM1_DSTSHIFT_SHIFT)
78 
79 /* Write mask */
80 #define WINED3D_SM1_WRITEMASK_SHIFT 16
81 #define WINED3D_SM1_WRITEMASK_MASK (0xfu << WINED3D_SM1_WRITEMASK_SHIFT)
82 
83 /* Swizzle mask */
84 #define WINED3D_SM1_SWIZZLE_SHIFT 16
85 #define WINED3D_SM1_SWIZZLE_MASK (0xffu << WINED3D_SM1_SWIZZLE_SHIFT)
86 
87 /* Source modifier mask */
88 #define WINED3D_SM1_SRC_MODIFIER_SHIFT 24
89 #define WINED3D_SM1_SRC_MODIFIER_MASK (0xfu << WINED3D_SM1_SRC_MODIFIER_SHIFT)
90 
91 #define WINED3D_SM1_END 0x0000ffff
92 
93 #define WINED3D_SM1_VERSION_MAJOR(version) (((version) >> 8) & 0xff)
94 #define WINED3D_SM1_VERSION_MINOR(version) (((version) >> 0) & 0xff)
95 
97 {
100 };
101 
103 {
109 };
110 
112 {
162 
196 
200 };
201 
203 {
205  unsigned int dst_count;
206  unsigned int param_count;
210 };
211 
213 {
216  const DWORD *start;
217 
224 };
225 
226 /* This table is not order or position dependent. */
228 {
229  /* Arithmetic */
230  {WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
231  {WINED3D_SM1_OP_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
233  {WINED3D_SM1_OP_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
234  {WINED3D_SM1_OP_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
235  {WINED3D_SM1_OP_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
236  {WINED3D_SM1_OP_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
237  {WINED3D_SM1_OP_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
238  {WINED3D_SM1_OP_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
239  {WINED3D_SM1_OP_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
240  {WINED3D_SM1_OP_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
241  {WINED3D_SM1_OP_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
242  {WINED3D_SM1_OP_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
243  {WINED3D_SM1_OP_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
244  {WINED3D_SM1_OP_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
245  {WINED3D_SM1_OP_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
246  {WINED3D_SM1_OP_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
247  {WINED3D_SM1_OP_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
248  {WINED3D_SM1_OP_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
249  {WINED3D_SM1_OP_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
250  {WINED3D_SM1_OP_LIT, 1, 2, WINED3DSIH_LIT, 0, 0 },
251  {WINED3D_SM1_OP_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
252  {WINED3D_SM1_OP_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
253  {WINED3D_SM1_OP_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
254  {WINED3D_SM1_OP_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
255  {WINED3D_SM1_OP_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
258  {WINED3D_SM1_OP_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
261  /* Matrix */
262  {WINED3D_SM1_OP_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
263  {WINED3D_SM1_OP_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
264  {WINED3D_SM1_OP_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
265  {WINED3D_SM1_OP_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
266  {WINED3D_SM1_OP_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
267  /* Declare registers */
268  {WINED3D_SM1_OP_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
269  /* Constant definitions */
270  {WINED3D_SM1_OP_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
271  {WINED3D_SM1_OP_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
272  {WINED3D_SM1_OP_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
273  /* Flow control */
289 
290  {WINED3D_SM1_OP_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
292  {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
293 };
294 
296 {
297  /* Arithmetic */
298  {WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
299  {WINED3D_SM1_OP_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
300  {WINED3D_SM1_OP_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
301  {WINED3D_SM1_OP_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
302  {WINED3D_SM1_OP_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
303  {WINED3D_SM1_OP_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
304  {WINED3D_SM1_OP_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
305  {WINED3D_SM1_OP_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
306  {WINED3D_SM1_OP_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
307  {WINED3D_SM1_OP_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
308  {WINED3D_SM1_OP_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
309  {WINED3D_SM1_OP_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
310  {WINED3D_SM1_OP_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
311  {WINED3D_SM1_OP_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
312  {WINED3D_SM1_OP_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
313  {WINED3D_SM1_OP_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
314  {WINED3D_SM1_OP_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
315  {WINED3D_SM1_OP_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
316  {WINED3D_SM1_OP_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
317  {WINED3D_SM1_OP_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
318  {WINED3D_SM1_OP_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
319  {WINED3D_SM1_OP_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
322  {WINED3D_SM1_OP_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
323  {WINED3D_SM1_OP_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
324  {WINED3D_SM1_OP_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
328  /* Matrix */
329  {WINED3D_SM1_OP_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
330  {WINED3D_SM1_OP_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
331  {WINED3D_SM1_OP_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
332  {WINED3D_SM1_OP_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
333  {WINED3D_SM1_OP_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
334  /* Register declarations */
335  {WINED3D_SM1_OP_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
336  /* Flow control */
352  /* Constant definitions */
353  {WINED3D_SM1_OP_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
354  {WINED3D_SM1_OP_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
355  {WINED3D_SM1_OP_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
356  /* Texture */
384  {WINED3D_SM1_OP_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
386  {WINED3D_SM1_OP_PHASE, 0, 0, WINED3DSIH_PHASE, 0, 0 },
387  {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
388 };
389 
391 {
392  /* WINED3D_SM1_RESOURCE_UNKNOWN */ WINED3D_SHADER_RESOURCE_NONE,
393  /* WINED3D_SM1_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D,
394  /* WINED3D_SM1_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D,
395  /* WINED3D_SM1_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
396  /* WINED3D_SM1_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D,
397 };
398 
399 /* Read a parameter opcode from the input stream,
400  * and possibly a relative addressing token.
401  * Return the number of tokens read */
402 static unsigned int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr,
403  DWORD *token, DWORD *addr_token)
404 {
405  unsigned int count = 1;
406 
407  *token = *ptr;
408 
409  /* PS >= 3.0 have relative addressing (with token)
410  * VS >= 2.0 have relative addressing (with token)
411  * VS >= 1.0 < 2.0 have relative addressing (without token)
412  * The version check below should work in general */
414  {
415  if (priv->shader_version.major < 2)
416  {
417  *addr_token = (1u << 31)
421  }
422  else
423  {
424  *addr_token = *(ptr + 1);
425  ++count;
426  }
427  }
428 
429  return count;
430 }
431 
432 static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD token)
433 {
434  DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
435  const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table;
436  unsigned int i = 0;
437 
439  {
441  && shader_version >= opcode_table[i].min_version
442  && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
443  {
444  return &opcode_table[i];
445  }
446  ++i;
447  }
448 
449  FIXME("Unsupported opcode %#x, token 0x%08x, shader version %#x.\n",
450  token & WINED3D_SM1_OPCODE_MASK, token, shader_version);
451 
452  return NULL;
453 }
454 
455 /* Return the number of parameters to skip for an opcode */
456 static unsigned int shader_skip_opcode(const struct wined3d_sm1_data *priv,
457  const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
458 {
459  unsigned int length;
460  /* Shaders >= 2.0 may contain address tokens, but fortunately they
461  * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
463  return (priv->shader_version.major >= 2) ? length : opcode_info->param_count;
464 }
465 
466 static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
468 {
471  src->reg.data_type = WINED3D_DATA_FLOAT;
472  src->reg.idx[0].offset = param & WINED3D_SM1_REGISTER_NUMBER_MASK;
473  src->reg.idx[0].rel_addr = rel_addr;
474  src->reg.idx[1].offset = ~0U;
475  src->reg.idx[1].rel_addr = NULL;
478 }
479 
480 static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
482 {
485  dst->reg.data_type = WINED3D_DATA_FLOAT;
486  dst->reg.idx[0].offset = param & WINED3D_SM1_REGISTER_NUMBER_MASK;
487  dst->reg.idx[0].rel_addr = rel_addr;
488  dst->reg.idx[1].offset = ~0U;
489  dst->reg.idx[1].rel_addr = NULL;
493 }
494 
495 /* Read the parameters of an unrecognized opcode from the input stream
496  * Return the number of tokens read.
497  *
498  * Note: This function assumes source or destination token format.
499  * It will not work with specially-formatted tokens like DEF or DCL,
500  * but hopefully those would be recognized */
501 static unsigned int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
502 {
503  unsigned int tokens_read = 0, i = 0;
504 
505  /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
506  while (*ptr & 0x80000000)
507  {
508  DWORD token, addr_token = 0;
509  struct wined3d_shader_src_param rel_addr;
510 
511  tokens_read += shader_get_param(priv, ptr, &token, &addr_token);
512  ptr += tokens_read;
513 
514  FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x.\n", token, addr_token);
515 
517  shader_parse_src_param(addr_token, NULL, &rel_addr);
518 
519  if (!i)
520  {
522 
524  }
525  else
526  {
528 
530  }
531  ++i;
532  }
533  return tokens_read;
534 }
535 
536 static void *shader_sm1_init(const DWORD *byte_code, size_t byte_code_size,
537  const struct wined3d_shader_signature *output_signature)
538 {
539  struct wined3d_sm1_data *priv;
540  BYTE major, minor;
541 
542  TRACE("Version: 0x%08x.\n", *byte_code);
543 
544  major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
545  minor = WINED3D_SM1_VERSION_MINOR(*byte_code);
547  {
548  WARN("Invalid shader version %u.%u (%#x).\n", major, minor, *byte_code);
549  return NULL;
550  }
551 
552  if (!(priv = heap_alloc(sizeof(*priv))))
553  return NULL;
554 
555  if (output_signature->element_count)
556  FIXME("SM 1-3 shader shouldn't have output signatures.\n");
557 
558  switch (*byte_code >> 16)
559  {
560  case WINED3D_SM1_VS:
563  break;
564 
565  case WINED3D_SM1_PS:
568  break;
569 
570  default:
571  FIXME("Unrecognized shader type %#x.\n", *byte_code >> 16);
572  heap_free(priv);
573  return NULL;
574  }
575  priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
576  priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(*byte_code);
577 
578  priv->start = &byte_code[1];
579 
580  return priv;
581 }
582 
583 static void shader_sm1_free(void *data)
584 {
585  heap_free(data);
586 }
587 
589 {
590  struct wined3d_sm1_data *priv = data;
591 
592  *ptr = priv->start;
594 }
595 
596 static void shader_sm1_read_src_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
598 {
599  DWORD token, addr_token;
600 
601  *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
603  {
606  }
607  else
608  {
610  }
611 }
612 
613 static void shader_sm1_read_dst_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
615 {
616  DWORD token, addr_token;
617 
618  *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
620  {
623  }
624  else
625  {
627  }
628 }
629 
630 static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
631 {
632  enum wined3d_sm1_resource_type resource_type;
633  DWORD usage_token = *(*ptr)++;
634  DWORD dst_token = *(*ptr)++;
635 
636  semantic->usage = (usage_token & WINED3D_SM1_DCL_USAGE_MASK) >> WINED3D_SM1_DCL_USAGE_SHIFT;
638  resource_type = (usage_token & WINED3D_SM1_RESOURCE_TYPE_MASK) >> WINED3D_SM1_RESOURCE_TYPE_SHIFT;
639  if (resource_type >= ARRAY_SIZE(resource_type_table))
640  {
641  FIXME("Unhandled resource type %#x.\n", resource_type);
643  }
644  else
645  {
646  semantic->resource_type = resource_type_table[resource_type];
647  }
649  shader_parse_dst_param(dst_token, NULL, &semantic->reg);
650 }
651 
653  enum wined3d_immconst_type type, enum wined3d_data_type data_type)
654 {
655  unsigned int count = type == WINED3D_IMMCONST_VEC4 ? 4 : 1;
656  src_param->reg.type = WINED3DSPR_IMMCONST;
657  src_param->reg.data_type = data_type;
658  src_param->reg.idx[0].offset = ~0U;
659  src_param->reg.idx[0].rel_addr = NULL;
660  src_param->reg.idx[1].offset = ~0U;
661  src_param->reg.idx[1].rel_addr = NULL;
662  src_param->reg.immconst_type = type;
663  memcpy(src_param->reg.u.immconst_data, *ptr, count * sizeof(DWORD));
664  src_param->swizzle = WINED3DSP_NOSWIZZLE;
665  src_param->modifiers = 0;
666 
667  *ptr += count;
668 }
669 
670 static void shader_sm1_read_comment(const DWORD **ptr)
671 {
672  DWORD token = **ptr;
673  const char *comment;
674  UINT size;
675 
677  {
679  comment = (const char *)++(*ptr);
680  *ptr += size;
681 
682  if (size > 1 && *(const DWORD *)comment == WINEMAKEFOURCC('T', 'E', 'X', 'T'))
683  {
684  const char *end = comment + size * sizeof(token);
685  const char *p = comment + sizeof(token);
686  const char *line = p;
687 
688  TRACE("// TEXT\n");
689  while (p != end)
690  {
691  if (*p == '\n')
692  {
693  UINT len = p - line;
694  if (len && *(p - 1) == '\r') --len;
695  TRACE("// %s\n", debugstr_an(line, len));
696  line = ++p;
697  }
698  else ++p;
699  }
700  if (line != p)
701  TRACE("// %s\n", debugstr_an(line, p - line));
702  }
703  else if (size)
704  TRACE("// %s\n", debugstr_an(comment, size * sizeof(token)));
705  else
706  break;
707 
708  token = **ptr;
709  }
710 }
711 
713 {
715  {
716  if (ins->flags)
717  {
718  FIXME("Ignoring unexpected instruction flags %#x for %s.\n",
720  ins->flags = 0;
721  }
722  }
723 }
724 
725 static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
726 {
727  const struct wined3d_sm1_opcode_info *opcode_info;
728  struct wined3d_sm1_data *priv = data;
729  DWORD opcode_token;
730  unsigned int i;
731  const DWORD *p;
732 
734 
735  opcode_token = *(*ptr)++;
736  if (!(opcode_info = shader_get_opcode(priv, opcode_token)))
737  {
738  FIXME("Unrecognized opcode: token=0x%08x.\n", opcode_token);
740  *ptr += shader_skip_unrecognized(priv, *ptr);
741  return;
742  }
743 
744  ins->handler_idx = opcode_info->handler_idx;
746  ins->coissue = opcode_token & WINED3D_SM1_COISSUE;
747  ins->predicate = opcode_token & WINED3D_SM1_INSTRUCTION_PREDICATED ? &priv->pred_param : NULL;
748  ins->dst_count = opcode_info->dst_count ? 1 : 0;
749  ins->dst = &priv->dst_param;
750  ins->src_count = opcode_info->param_count - opcode_info->dst_count;
751  ins->src = priv->src_param;
752  memset(&ins->texel_offset, 0, sizeof(ins->texel_offset));
753 
754  p = *ptr;
755  *ptr += shader_skip_opcode(priv, opcode_info, opcode_token);
756 
757  if (ins->handler_idx == WINED3DSIH_DCL)
758  {
760  }
761  else if (ins->handler_idx == WINED3DSIH_DEF)
762  {
763  shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
765  }
766  else if (ins->handler_idx == WINED3DSIH_DEFB)
767  {
768  shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
770  }
771  else if (ins->handler_idx == WINED3DSIH_DEFI)
772  {
773  shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
775  }
776  else
777  {
778  /* Destination token */
779  if (ins->dst_count)
780  shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
781 
782  /* Predication token */
783  if (ins->predicate)
784  shader_sm1_read_src_param(priv, &p, &priv->pred_param, &priv->pred_rel_addr);
785 
786  /* Other source tokens */
787  for (i = 0; i < ins->src_count; ++i)
788  shader_sm1_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]);
789  }
790 
792 }
793 
794 static BOOL shader_sm1_is_end(void *data, const DWORD **ptr)
795 {
797 
798  if (**ptr == WINED3D_SM1_END)
799  {
800  ++(*ptr);
801  return TRUE;
802  }
803 
804  return FALSE;
805 }
806 
808 {
814 };
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
wined3d_sm1_address_mode_type
Definition: shader_sm1.c:96
#define WINED3D_SM1_INSTRUCTION_LENGTH_MASK
Definition: shader_sm1.c:49
#define WINED3D_SM1_RESOURCE_TYPE_MASK
Definition: shader_sm1.c:40
#define TRUE
Definition: types.h:120
#define WINED3D_SM1_DST_MODIFIER_SHIFT
Definition: shader_sm1.c:72
static const struct wined3d_sm1_opcode_info * shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD token)
Definition: shader_sm1.c:432
static void shader_sm1_read_comment(const DWORD **ptr)
Definition: shader_sm1.c:670
#define WINED3D_SM1_REGISTER_TYPE_MASK2
Definition: shader_sm1.c:65
#define WINED3D_SM1_SRC_MODIFIER_MASK
Definition: shader_sm1.c:89
const DWORD * start
Definition: shader_sm1.c:216
#define WINED3D_SM1_DCL_USAGE_SHIFT
Definition: shader_sm1.c:33
enum wined3d_sm1_opcode opcode
Definition: shader_sm1.c:204
struct wined3d_shader_src_param src_rel_addr[4]
Definition: shader_sm1.c:218
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WINED3D_SM1_COMMENT_SIZE_SHIFT
Definition: shader_sm1.c:53
const struct wined3d_shader_dst_param * dst
#define WINED3D_SM1_COISSUE
Definition: shader_sm1.c:51
#define WARN(fmt,...)
Definition: debug.h:111
#define U(x)
Definition: wordpad.c:44
static const struct wined3d_sm4_opcode_info opcode_table[]
Definition: shader_sm4.c:883
static void shader_sm1_read_immconst(const DWORD **ptr, struct wined3d_shader_src_param *src_param, enum wined3d_immconst_type type, enum wined3d_data_type data_type)
Definition: shader_sm1.c:652
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
struct wined3d_shader_dst_param dst_param
Definition: shader_sm1.c:223
const char * debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx)
Definition: shader.c:334
#define WINED3D_SM1_INSTRUCTION_FLAGS_MASK
Definition: shader_sm1.c:46
#define WINED3D_SM1_REGISTER_TYPE_MASK
Definition: shader_sm1.c:63
GLuint GLuint end
Definition: gl.h:1545
unsigned int dst_count
Definition: shader_sm1.c:205
#define WINED3D_SM1_VS
#define WINED3D_SM1_INSTRUCTION_LENGTH_SHIFT
Definition: shader_sm1.c:48
union wined3d_shader_instruction::@270 declaration
#define WINED3D_SM1_OPCODE_MASK
Definition: shader_sm1.c:43
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define WINED3D_SM1_INSTRUCTION_PREDICATED
Definition: shader_sm1.c:56
static void * shader_sm1_init(const DWORD *byte_code, size_t byte_code_size, const struct wined3d_shader_signature *output_signature)
Definition: shader_sm1.c:536
static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr, struct wined3d_shader_dst_param *dst)
Definition: shader_sm1.c:480
enum wined3d_decl_usage usage
#define WINED3D_SM1_COMMENT_SIZE_MASK
Definition: shader_sm1.c:54
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct wined3d_shader_semantic semantic
const struct wined3d_shader_src_param * src
unsigned int BOOL
Definition: ntddk_ex.h:94
static unsigned int shader_skip_opcode(const struct wined3d_sm1_data *priv, const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
Definition: shader_sm1.c:456
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
struct wined3d_shader_src_param pred_rel_addr
Definition: shader_sm1.c:219
#define FIXME(fmt,...)
Definition: debug.h:110
static PVOID ptr
Definition: dispmode.c:27
#define WINED3D_SM1_END
Definition: shader_sm1.c:91
smooth NULL
Definition: ftsmooth.c:416
wined3d_sm1_opcode
Definition: shader_sm1.c:111
Definition: parser.c:48
#define WINED3D_SM1_DCL_USAGE_MASK
Definition: shader_sm1.c:34
wined3d_immconst_type
#define WINED3D_SM1_REGISTER_NUMBER_MASK
Definition: shader_sm1.c:59
#define WINED3D_SM1_WRITEMASK_SHIFT
Definition: shader_sm1.c:80
static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
Definition: shader_sm1.c:588
#define WINED3D_SM1_SWIZZLE_MASK
Definition: shader_sm1.c:85
enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
#define WINED3D_SM1_RESOURCE_TYPE_SHIFT
Definition: shader_sm1.c:39
wined3d_shader_resource_type
#define WINED3DSP_NOSWIZZLE
const struct wined3d_shader_src_param * predicate
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define WINEMAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: wined3d.h:101
#define WINED3D_SM1_SWIZZLE_SHIFT
Definition: shader_sm1.c:84
static unsigned int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
Definition: shader_sm1.c:501
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
struct wined3d_shader_src_param dst_rel_addr
Definition: shader_sm1.c:220
struct wined3d_shader_src_param pred_param
Definition: shader_sm1.c:222
GLfloat param
Definition: glext.h:5796
enum wined3d_shader_resource_type resource_type
unsigned long DWORD
Definition: ntddk_ex.h:95
static void shader_sm1_free(void *data)
Definition: shader_sm1.c:583
WINED3D_SHADER_INSTRUCTION_HANDLER
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const struct wined3d_sm1_opcode_info vs_opcode_table[]
Definition: shader_sm1.c:227
#define WINED3D_SM1_DST_MODIFIER_MASK
Definition: shader_sm1.c:73
unsigned min_version
Definition: lex.c:81
static void shader_sm1_read_src_param(struct wined3d_sm1_data *priv, const DWORD **ptr, struct wined3d_shader_src_param *src_param, struct wined3d_shader_src_param *src_rel_addr)
Definition: shader_sm1.c:596
char line[200]
Definition: main.c:97
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:47
Definition: id3.c:18
static const struct wined3d_sm1_opcode_info ps_opcode_table[]
Definition: shader_sm1.c:295
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WINED3D_SM1_DCL_USAGE_INDEX_SHIFT
Definition: shader_sm1.c:35
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
const struct wined3d_shader_frontend sm1_shader_frontend
Definition: shader_sm1.c:807
#define WINED3D_SHADER_VERSION(major, minor)
static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
Definition: shader_sm1.c:630
GLenum src
Definition: glext.h:6340
#define WINED3D_SM1_SRC_MODIFIER_SHIFT
Definition: shader_sm1.c:88
#define WINED3D_SM1_ADDRESS_MODE_SHIFT
Definition: shader_sm1.c:68
struct wined3d_shader_src_param src_param[4]
Definition: shader_sm1.c:221
#define WINED3D_SM1_DCL_USAGE_INDEX_MASK
Definition: shader_sm1.c:36
static BOOL shader_sm1_is_end(void *data, const DWORD **ptr)
Definition: shader_sm1.c:794
#define WINED3D_SM1_WRITEMASK_MASK
Definition: shader_sm1.c:81
#define ARRAY_SIZE(a)
Definition: main.h:24
#define major(rdev)
Definition: propsheet.cpp:879
static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr, struct wined3d_shader_src_param *src)
Definition: shader_sm1.c:466
GLenum GLenum dst
Definition: glext.h:6340
#define WINED3D_SM1_INSTRUCTION_FLAGS_SHIFT
Definition: shader_sm1.c:45
wined3d_data_type
unsigned int UINT
Definition: ndis.h:50
enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
Definition: shader_sm1.c:207
struct wined3d_shader_version shader_version
Definition: shader_sm1.c:214
#define WINED3D_SM1_VERSION_MINOR(version)
Definition: shader_sm1.c:94
const struct wined3d_sm1_opcode_info * opcode_table
Definition: shader_sm1.c:215
struct wined3d_shader_texel_offset texel_offset
#define WINED3D_SM1_DSTSHIFT_MASK
Definition: shader_sm1.c:77
#define WINED3D_SM1_VERSION_MAJOR(version)
Definition: shader_sm1.c:93
#define WINED3D_SM1_REGISTER_TYPE_SHIFT2
Definition: shader_sm1.c:64
static enum wined3d_shader_resource_type resource_type_table[]
Definition: shader_sm1.c:390
static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
Definition: shader_sm1.c:725
#define minor(rdev)
Definition: propsheet.cpp:880
static void shader_sm1_validate_instruction(struct wined3d_shader_instruction *ins)
Definition: shader_sm1.c:712
enum wined3d_data_type resource_data_type
struct wined3d_shader_dst_param reg
#define WINED3D_SM1_DSTSHIFT_SHIFT
Definition: shader_sm1.c:76
wined3d_sm1_resource_type
Definition: shader_sm1.c:102
GLfloat GLfloat p
Definition: glext.h:8902
#define WINED3D_SM1_REGISTER_TYPE_SHIFT
Definition: shader_sm1.c:62
unsigned int param_count
Definition: shader_sm1.c:206
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader)
#define memset(x, y, z)
Definition: compat.h:39
#define WINED3D_SM1_PS
struct wined3d_shader_register reg
static void shader_sm1_read_dst_param(struct wined3d_sm1_data *priv, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param, struct wined3d_shader_src_param *dst_rel_addr)
Definition: shader_sm1.c:613
static unsigned int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token)
Definition: shader_sm1.c:402
static BOOL heap_free(void *mem)
Definition: appwiz.h:75