2 * Copyright 2008 Stefan Dösinger
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2008-2009 Henri Verbeet for CodeWeavers
5 * Copyright 2010 Rico Schüller
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "d3dcompiler_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler
);
30 #define WINE_D3DCOMPILER_TO_STR(x) case x: return #x
32 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c
)
36 WINE_D3DCOMPILER_TO_STR(D3D_SVC_SCALAR
);
37 WINE_D3DCOMPILER_TO_STR(D3D_SVC_VECTOR
);
38 WINE_D3DCOMPILER_TO_STR(D3D_SVC_MATRIX_ROWS
);
39 WINE_D3DCOMPILER_TO_STR(D3D_SVC_MATRIX_COLUMNS
);
40 WINE_D3DCOMPILER_TO_STR(D3D_SVC_OBJECT
);
41 WINE_D3DCOMPILER_TO_STR(D3D_SVC_STRUCT
);
42 WINE_D3DCOMPILER_TO_STR(D3D_SVC_INTERFACE_CLASS
);
43 WINE_D3DCOMPILER_TO_STR(D3D_SVC_INTERFACE_POINTER
);
45 FIXME("Unrecognized D3D_SHADER_VARIABLE_CLASS %#x.\n", c
);
46 return "unrecognized";
50 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t
)
54 WINE_D3DCOMPILER_TO_STR(D3D_SVT_VOID
);
55 WINE_D3DCOMPILER_TO_STR(D3D_SVT_BOOL
);
56 WINE_D3DCOMPILER_TO_STR(D3D_SVT_INT
);
57 WINE_D3DCOMPILER_TO_STR(D3D_SVT_FLOAT
);
58 WINE_D3DCOMPILER_TO_STR(D3D_SVT_STRING
);
59 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE
);
60 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE1D
);
61 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2D
);
62 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE3D
);
63 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURECUBE
);
64 WINE_D3DCOMPILER_TO_STR(D3D_SVT_SAMPLER
);
65 WINE_D3DCOMPILER_TO_STR(D3D_SVT_PIXELSHADER
);
66 WINE_D3DCOMPILER_TO_STR(D3D_SVT_VERTEXSHADER
);
67 WINE_D3DCOMPILER_TO_STR(D3D_SVT_UINT
);
68 WINE_D3DCOMPILER_TO_STR(D3D_SVT_UINT8
);
69 WINE_D3DCOMPILER_TO_STR(D3D_SVT_GEOMETRYSHADER
);
70 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RASTERIZER
);
71 WINE_D3DCOMPILER_TO_STR(D3D_SVT_DEPTHSTENCIL
);
72 WINE_D3DCOMPILER_TO_STR(D3D_SVT_BLEND
);
73 WINE_D3DCOMPILER_TO_STR(D3D_SVT_BUFFER
);
74 WINE_D3DCOMPILER_TO_STR(D3D_SVT_CBUFFER
);
75 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TBUFFER
);
76 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE1DARRAY
);
77 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DARRAY
);
78 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RENDERTARGETVIEW
);
79 WINE_D3DCOMPILER_TO_STR(D3D_SVT_DEPTHSTENCILVIEW
);
80 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DMS
);
81 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DMSARRAY
);
82 WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURECUBEARRAY
);
83 WINE_D3DCOMPILER_TO_STR(D3D_SVT_HULLSHADER
);
84 WINE_D3DCOMPILER_TO_STR(D3D_SVT_DOMAINSHADER
);
85 WINE_D3DCOMPILER_TO_STR(D3D_SVT_INTERFACE_POINTER
);
86 WINE_D3DCOMPILER_TO_STR(D3D_SVT_COMPUTESHADER
);
87 WINE_D3DCOMPILER_TO_STR(D3D_SVT_DOUBLE
);
88 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE1D
);
89 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE1DARRAY
);
90 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE2D
);
91 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE2DARRAY
);
92 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE3D
);
93 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWBUFFER
);
94 WINE_D3DCOMPILER_TO_STR(D3D_SVT_BYTEADDRESS_BUFFER
);
95 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWBYTEADDRESS_BUFFER
);
96 WINE_D3DCOMPILER_TO_STR(D3D_SVT_STRUCTURED_BUFFER
);
97 WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWSTRUCTURED_BUFFER
);
98 WINE_D3DCOMPILER_TO_STR(D3D_SVT_APPEND_STRUCTURED_BUFFER
);
99 WINE_D3DCOMPILER_TO_STR(D3D_SVT_CONSUME_STRUCTURED_BUFFER
);
101 FIXME("Unrecognized D3D_SHADER_VARIABLE_TYPE %#x.\n", t
);
102 return "unrecognized";
106 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part
)
110 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_INPUT_SIGNATURE_BLOB
);
111 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_OUTPUT_SIGNATURE_BLOB
);
112 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB
);
113 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB
);
114 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_ALL_SIGNATURE_BLOB
);
115 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_DEBUG_INFO
);
116 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_LEGACY_SHADER
);
117 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_XNA_PREPASS_SHADER
);
118 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_XNA_SHADER
);
119 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_ALTERNATE_SHADER
);
120 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_COMPILE_DETAILS
);
121 WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_COMPILE_PERF
);
123 FIXME("Unrecognized D3D_BLOB_PART %#x\n", part
);
124 return "unrecognized";
128 const char *debug_print_srcmod(DWORD mod
)
132 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_NEG
);
133 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_BIAS
);
134 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_BIASNEG
);
135 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_SIGN
);
136 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_SIGNNEG
);
137 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_COMP
);
138 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_X2
);
139 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_X2NEG
);
140 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_DZ
);
141 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_DW
);
142 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_ABS
);
143 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_ABSNEG
);
144 WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_NOT
);
146 FIXME("Unrecognized source modifier %#x.\n", mod
);
147 return "unrecognized_src_mod";
151 #undef WINE_D3DCOMPILER_TO_STR
153 const char *debug_print_dstmod(DWORD mod
)
159 case BWRITERSPDM_SATURATE
:
161 case BWRITERSPDM_PARTIALPRECISION
:
163 case BWRITERSPDM_MSAMPCENTROID
:
165 case BWRITERSPDM_SATURATE
| BWRITERSPDM_PARTIALPRECISION
:
167 case BWRITERSPDM_SATURATE
| BWRITERSPDM_MSAMPCENTROID
:
168 return "_sat_centroid";
169 case BWRITERSPDM_PARTIALPRECISION
| BWRITERSPDM_MSAMPCENTROID
:
170 return "_pp_centroid";
171 case BWRITERSPDM_SATURATE
| BWRITERSPDM_PARTIALPRECISION
| BWRITERSPDM_MSAMPCENTROID
:
172 return "_sat_pp_centroid";
174 return "Unexpected modifier\n";
178 const char *debug_print_shift(DWORD shift
)
180 static const char * const shiftstrings
[] =
199 return shiftstrings
[shift
];
202 static const char *get_regname(const struct shader_reg
*reg
)
206 case BWRITERSPR_TEMP
:
207 return wine_dbg_sprintf("r%u", reg
->regnum
);
208 case BWRITERSPR_INPUT
:
209 return wine_dbg_sprintf("v%u", reg
->regnum
);
210 case BWRITERSPR_CONST
:
211 return wine_dbg_sprintf("c%u", reg
->regnum
);
212 case BWRITERSPR_ADDR
:
213 return wine_dbg_sprintf("a%u", reg
->regnum
);
214 case BWRITERSPR_TEXTURE
:
215 return wine_dbg_sprintf("t%u", reg
->regnum
);
216 case BWRITERSPR_RASTOUT
:
219 case BWRITERSRO_POSITION
: return "oPos";
220 case BWRITERSRO_FOG
: return "oFog";
221 case BWRITERSRO_POINT_SIZE
: return "oPts";
222 default: return "Unexpected RASTOUT";
224 case BWRITERSPR_ATTROUT
:
225 return wine_dbg_sprintf("oD%u", reg
->regnum
);
226 case BWRITERSPR_TEXCRDOUT
:
227 return wine_dbg_sprintf("oT%u", reg
->regnum
);
228 case BWRITERSPR_OUTPUT
:
229 return wine_dbg_sprintf("o%u", reg
->regnum
);
230 case BWRITERSPR_CONSTINT
:
231 return wine_dbg_sprintf("i%u", reg
->regnum
);
232 case BWRITERSPR_COLOROUT
:
233 return wine_dbg_sprintf("oC%u", reg
->regnum
);
234 case BWRITERSPR_DEPTHOUT
:
236 case BWRITERSPR_SAMPLER
:
237 return wine_dbg_sprintf("s%u", reg
->regnum
);
238 case BWRITERSPR_CONSTBOOL
:
239 return wine_dbg_sprintf("b%u", reg
->regnum
);
240 case BWRITERSPR_LOOP
:
242 case BWRITERSPR_MISCTYPE
:
245 case 0: return "vPos";
246 case 1: return "vFace";
247 default: return "unexpected misctype";
249 case BWRITERSPR_LABEL
:
250 return wine_dbg_sprintf("l%u", reg
->regnum
);
251 case BWRITERSPR_PREDICATE
:
252 return wine_dbg_sprintf("p%u", reg
->regnum
);
254 return wine_dbg_sprintf("unknown regname %#x", reg
->type
);
258 static const char *debug_print_writemask(DWORD mask
)
261 unsigned char pos
= 1;
263 if(mask
== BWRITERSP_WRITEMASK_ALL
) return "";
265 if(mask
& BWRITERSP_WRITEMASK_0
) ret
[pos
++] = 'x';
266 if(mask
& BWRITERSP_WRITEMASK_1
) ret
[pos
++] = 'y';
267 if(mask
& BWRITERSP_WRITEMASK_2
) ret
[pos
++] = 'z';
268 if(mask
& BWRITERSP_WRITEMASK_3
) ret
[pos
++] = 'w';
271 return wine_dbg_sprintf("%s", ret
);
274 static const char *debug_print_swizzle(DWORD arg
)
282 case BWRITERVS_NOSWIZZLE
:
284 case BWRITERVS_SWIZZLE_X
:
286 case BWRITERVS_SWIZZLE_Y
:
288 case BWRITERVS_SWIZZLE_Z
:
290 case BWRITERVS_SWIZZLE_W
:
294 swizzle
[0] = (arg
>> (BWRITERVS_SWIZZLE_SHIFT
+ 0)) & 0x03;
295 swizzle
[1] = (arg
>> (BWRITERVS_SWIZZLE_SHIFT
+ 2)) & 0x03;
296 swizzle
[2] = (arg
>> (BWRITERVS_SWIZZLE_SHIFT
+ 4)) & 0x03;
297 swizzle
[3] = (arg
>> (BWRITERVS_SWIZZLE_SHIFT
+ 6)) & 0x03;
300 for (i
= 0; i
< 4; ++i
)
304 case 0: ret
[1 + i
] = 'x'; break;
305 case 1: ret
[1 + i
] = 'y'; break;
306 case 2: ret
[1 + i
] = 'z'; break;
307 case 3: ret
[1 + i
] = 'w'; break;
312 return wine_dbg_sprintf("%s", ret
);
315 static const char *debug_print_relarg(const struct shader_reg
*reg
)
317 const char *short_swizzle
;
318 if (!reg
->rel_reg
) return "";
320 short_swizzle
= debug_print_swizzle(reg
->rel_reg
->u
.swizzle
);
322 if (reg
->rel_reg
->type
== BWRITERSPR_ADDR
)
323 return wine_dbg_sprintf("[a%u%s]", reg
->rel_reg
->regnum
, short_swizzle
);
324 else if(reg
->rel_reg
->type
== BWRITERSPR_LOOP
&& reg
->rel_reg
->regnum
== 0)
325 return wine_dbg_sprintf("[aL%s]", short_swizzle
);
327 return "Unexpected relative addressing argument";
330 const char *debug_print_dstreg(const struct shader_reg
*reg
)
332 return wine_dbg_sprintf("%s%s%s", get_regname(reg
),
333 debug_print_relarg(reg
),
334 debug_print_writemask(reg
->u
.writemask
));
337 const char *debug_print_srcreg(const struct shader_reg
*reg
)
341 case BWRITERSPSM_NONE
:
342 return wine_dbg_sprintf("%s%s%s", get_regname(reg
),
343 debug_print_relarg(reg
),
344 debug_print_swizzle(reg
->u
.swizzle
));
345 case BWRITERSPSM_NEG
:
346 return wine_dbg_sprintf("-%s%s%s", get_regname(reg
),
347 debug_print_relarg(reg
),
348 debug_print_swizzle(reg
->u
.swizzle
));
349 case BWRITERSPSM_BIAS
:
350 return wine_dbg_sprintf("%s%s_bias%s", get_regname(reg
),
351 debug_print_relarg(reg
),
352 debug_print_swizzle(reg
->u
.swizzle
));
353 case BWRITERSPSM_BIASNEG
:
354 return wine_dbg_sprintf("-%s%s_bias%s", get_regname(reg
),
355 debug_print_relarg(reg
),
356 debug_print_swizzle(reg
->u
.swizzle
));
357 case BWRITERSPSM_SIGN
:
358 return wine_dbg_sprintf("%s%s_bx2%s", get_regname(reg
),
359 debug_print_relarg(reg
),
360 debug_print_swizzle(reg
->u
.swizzle
));
361 case BWRITERSPSM_SIGNNEG
:
362 return wine_dbg_sprintf("-%s%s_bx2%s", get_regname(reg
),
363 debug_print_relarg(reg
),
364 debug_print_swizzle(reg
->u
.swizzle
));
365 case BWRITERSPSM_COMP
:
366 return wine_dbg_sprintf("1 - %s%s%s", get_regname(reg
),
367 debug_print_relarg(reg
),
368 debug_print_swizzle(reg
->u
.swizzle
));
370 return wine_dbg_sprintf("%s%s_x2%s", get_regname(reg
),
371 debug_print_relarg(reg
),
372 debug_print_swizzle(reg
->u
.swizzle
));
373 case BWRITERSPSM_X2NEG
:
374 return wine_dbg_sprintf("-%s%s_x2%s", get_regname(reg
),
375 debug_print_relarg(reg
),
376 debug_print_swizzle(reg
->u
.swizzle
));
378 return wine_dbg_sprintf("%s%s_dz%s", get_regname(reg
),
379 debug_print_relarg(reg
),
380 debug_print_swizzle(reg
->u
.swizzle
));
382 return wine_dbg_sprintf("%s%s_dw%s", get_regname(reg
),
383 debug_print_relarg(reg
),
384 debug_print_swizzle(reg
->u
.swizzle
));
385 case BWRITERSPSM_ABS
:
386 return wine_dbg_sprintf("%s%s_abs%s", get_regname(reg
),
387 debug_print_relarg(reg
),
388 debug_print_swizzle(reg
->u
.swizzle
));
389 case BWRITERSPSM_ABSNEG
:
390 return wine_dbg_sprintf("-%s%s_abs%s", get_regname(reg
),
391 debug_print_relarg(reg
),
392 debug_print_swizzle(reg
->u
.swizzle
));
393 case BWRITERSPSM_NOT
:
394 return wine_dbg_sprintf("!%s%s%s", get_regname(reg
),
395 debug_print_relarg(reg
),
396 debug_print_swizzle(reg
->u
.swizzle
));
398 return "Unknown modifier";
401 const char *debug_print_comp(DWORD comp
)
405 case BWRITER_COMPARISON_NONE
: return "";
406 case BWRITER_COMPARISON_GT
: return "_gt";
407 case BWRITER_COMPARISON_EQ
: return "_eq";
408 case BWRITER_COMPARISON_GE
: return "_ge";
409 case BWRITER_COMPARISON_LT
: return "_lt";
410 case BWRITER_COMPARISON_NE
: return "_ne";
411 case BWRITER_COMPARISON_LE
: return "_le";
412 default: return "_unknown";
416 const char *debug_print_opcode(DWORD opcode
)
420 case BWRITERSIO_NOP
: return "nop";
421 case BWRITERSIO_MOV
: return "mov";
422 case BWRITERSIO_ADD
: return "add";
423 case BWRITERSIO_SUB
: return "sub";
424 case BWRITERSIO_MAD
: return "mad";
425 case BWRITERSIO_MUL
: return "mul";
426 case BWRITERSIO_RCP
: return "rcp";
427 case BWRITERSIO_RSQ
: return "rsq";
428 case BWRITERSIO_DP3
: return "dp3";
429 case BWRITERSIO_DP4
: return "dp4";
430 case BWRITERSIO_MIN
: return "min";
431 case BWRITERSIO_MAX
: return "max";
432 case BWRITERSIO_SLT
: return "slt";
433 case BWRITERSIO_SGE
: return "sge";
434 case BWRITERSIO_EXP
: return "exp";
435 case BWRITERSIO_LOG
: return "log";
436 case BWRITERSIO_LIT
: return "lit";
437 case BWRITERSIO_DST
: return "dst";
438 case BWRITERSIO_LRP
: return "lrp";
439 case BWRITERSIO_FRC
: return "frc";
440 case BWRITERSIO_M4x4
: return "m4x4";
441 case BWRITERSIO_M4x3
: return "m4x3";
442 case BWRITERSIO_M3x4
: return "m3x4";
443 case BWRITERSIO_M3x3
: return "m3x3";
444 case BWRITERSIO_M3x2
: return "m3x2";
445 case BWRITERSIO_CALL
: return "call";
446 case BWRITERSIO_CALLNZ
: return "callnz";
447 case BWRITERSIO_LOOP
: return "loop";
448 case BWRITERSIO_RET
: return "ret";
449 case BWRITERSIO_ENDLOOP
: return "endloop";
450 case BWRITERSIO_LABEL
: return "label";
451 case BWRITERSIO_DCL
: return "dcl";
452 case BWRITERSIO_POW
: return "pow";
453 case BWRITERSIO_CRS
: return "crs";
454 case BWRITERSIO_SGN
: return "sgn";
455 case BWRITERSIO_ABS
: return "abs";
456 case BWRITERSIO_NRM
: return "nrm";
457 case BWRITERSIO_SINCOS
: return "sincos";
458 case BWRITERSIO_REP
: return "rep";
459 case BWRITERSIO_ENDREP
: return "endrep";
460 case BWRITERSIO_IF
: return "if";
461 case BWRITERSIO_IFC
: return "ifc";
462 case BWRITERSIO_ELSE
: return "else";
463 case BWRITERSIO_ENDIF
: return "endif";
464 case BWRITERSIO_BREAK
: return "break";
465 case BWRITERSIO_BREAKC
: return "breakc";
466 case BWRITERSIO_MOVA
: return "mova";
467 case BWRITERSIO_DEFB
: return "defb";
468 case BWRITERSIO_DEFI
: return "defi";
469 case BWRITERSIO_TEXCOORD
: return "texcoord";
470 case BWRITERSIO_TEXKILL
: return "texkill";
471 case BWRITERSIO_TEX
: return "tex";
472 case BWRITERSIO_TEXBEM
: return "texbem";
473 case BWRITERSIO_TEXBEML
: return "texbeml";
474 case BWRITERSIO_TEXREG2AR
: return "texreg2ar";
475 case BWRITERSIO_TEXREG2GB
: return "texreg2gb";
476 case BWRITERSIO_TEXM3x2PAD
: return "texm3x2pad";
477 case BWRITERSIO_TEXM3x2TEX
: return "texm3x2tex";
478 case BWRITERSIO_TEXM3x3PAD
: return "texm3x3pad";
479 case BWRITERSIO_TEXM3x3TEX
: return "texm3x3tex";
480 case BWRITERSIO_TEXM3x3SPEC
: return "texm3x3vspec";
481 case BWRITERSIO_TEXM3x3VSPEC
: return "texm3x3vspec";
482 case BWRITERSIO_EXPP
: return "expp";
483 case BWRITERSIO_LOGP
: return "logp";
484 case BWRITERSIO_CND
: return "cnd";
485 case BWRITERSIO_DEF
: return "def";
486 case BWRITERSIO_TEXREG2RGB
: return "texreg2rgb";
487 case BWRITERSIO_TEXDP3TEX
: return "texdp3tex";
488 case BWRITERSIO_TEXM3x2DEPTH
: return "texm3x2depth";
489 case BWRITERSIO_TEXDP3
: return "texdp3";
490 case BWRITERSIO_TEXM3x3
: return "texm3x3";
491 case BWRITERSIO_TEXDEPTH
: return "texdepth";
492 case BWRITERSIO_CMP
: return "cmp";
493 case BWRITERSIO_BEM
: return "bem";
494 case BWRITERSIO_DP2ADD
: return "dp2add";
495 case BWRITERSIO_DSX
: return "dsx";
496 case BWRITERSIO_DSY
: return "dsy";
497 case BWRITERSIO_TEXLDD
: return "texldd";
498 case BWRITERSIO_SETP
: return "setp";
499 case BWRITERSIO_TEXLDL
: return "texldl";
500 case BWRITERSIO_BREAKP
: return "breakp";
501 case BWRITERSIO_PHASE
: return "phase";
503 case BWRITERSIO_TEXLDP
: return "texldp";
504 case BWRITERSIO_TEXLDB
: return "texldb";
506 default: return "unknown";
510 void skip_dword_unknown(const char **ptr
, unsigned int count
)
515 FIXME("Skipping %u unknown DWORDs:\n", count
);
516 for (i
= 0; i
< count
; ++i
)
519 FIXME("\t0x%08x\n", d
);
523 static void write_dword_unknown(char **ptr
, DWORD d
)
525 FIXME("Writing unknown DWORD 0x%08x\n", d
);
529 HRESULT
dxbc_add_section(struct dxbc
*dxbc
, DWORD tag
, const char *data
, DWORD data_size
)
531 TRACE("dxbc %p, tag %s, size %#x.\n", dxbc
, debugstr_an((const char *)&tag
, 4), data_size
);
533 if (dxbc
->count
>= dxbc
->size
)
535 struct dxbc_section
*new_sections
;
536 DWORD new_size
= dxbc
->size
<< 1;
538 new_sections
= HeapReAlloc(GetProcessHeap(), 0, dxbc
->sections
, new_size
* sizeof(*dxbc
->sections
));
541 ERR("Failed to allocate dxbc section memory\n");
542 return E_OUTOFMEMORY
;
545 dxbc
->sections
= new_sections
;
546 dxbc
->size
= new_size
;
549 dxbc
->sections
[dxbc
->count
].tag
= tag
;
550 dxbc
->sections
[dxbc
->count
].data_size
= data_size
;
551 dxbc
->sections
[dxbc
->count
].data
= data
;
557 HRESULT
dxbc_init(struct dxbc
*dxbc
, UINT size
)
559 TRACE("dxbc %p, size %u.\n", dxbc
, size
);
561 /* use a good starting value for the size if none specified */
564 dxbc
->sections
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*dxbc
->sections
));
567 ERR("Failed to allocate dxbc section memory\n");
568 return E_OUTOFMEMORY
;
577 HRESULT
dxbc_parse(const char *data
, SIZE_T data_size
, struct dxbc
*dxbc
)
579 const char *ptr
= data
;
582 DWORD tag
, total_size
, chunk_count
;
586 WARN("No data supplied.\n");
590 read_dword(&ptr
, &tag
);
591 TRACE("tag: %s.\n", debugstr_an((const char *)&tag
, 4));
595 WARN("Wrong tag.\n");
600 skip_dword_unknown(&ptr
, 4);
602 skip_dword_unknown(&ptr
, 1);
604 read_dword(&ptr
, &total_size
);
605 TRACE("total size: %#x\n", total_size
);
607 if (data_size
!= total_size
)
609 WARN("Wrong size supplied.\n");
610 return D3DERR_INVALIDCALL
;
613 read_dword(&ptr
, &chunk_count
);
614 TRACE("chunk count: %#x\n", chunk_count
);
616 hr
= dxbc_init(dxbc
, chunk_count
);
619 WARN("Failed to init dxbc\n");
623 for (i
= 0; i
< chunk_count
; ++i
)
625 DWORD chunk_tag
, chunk_size
;
626 const char *chunk_ptr
;
629 read_dword(&ptr
, &chunk_offset
);
630 TRACE("chunk %u at offset %#x\n", i
, chunk_offset
);
632 chunk_ptr
= data
+ chunk_offset
;
634 read_dword(&chunk_ptr
, &chunk_tag
);
635 read_dword(&chunk_ptr
, &chunk_size
);
637 hr
= dxbc_add_section(dxbc
, chunk_tag
, chunk_ptr
, chunk_size
);
640 WARN("Failed to add section to dxbc\n");
648 void dxbc_destroy(struct dxbc
*dxbc
)
650 TRACE("dxbc %p.\n", dxbc
);
652 HeapFree(GetProcessHeap(), 0, dxbc
->sections
);
655 HRESULT
dxbc_write_blob(struct dxbc
*dxbc
, ID3DBlob
**blob
)
657 DWORD size
= 32, offset
= size
+ 4 * dxbc
->count
;
663 TRACE("dxbc %p, blob %p.\n", dxbc
, blob
);
665 for (i
= 0; i
< dxbc
->count
; ++i
)
667 size
+= 12 + dxbc
->sections
[i
].data_size
;
670 hr
= D3DCreateBlob(size
, &object
);
673 WARN("Failed to create blob\n");
677 ptr
= ID3D10Blob_GetBufferPointer(object
);
679 write_dword(&ptr
, TAG_DXBC
);
682 write_dword_unknown(&ptr
, 0);
683 write_dword_unknown(&ptr
, 0);
684 write_dword_unknown(&ptr
, 0);
685 write_dword_unknown(&ptr
, 0);
687 /* seems to be always 1 */
688 write_dword_unknown(&ptr
, 1);
691 write_dword(&ptr
, size
);
694 write_dword(&ptr
, dxbc
->count
);
696 /* write the chunk offsets */
697 for (i
= 0; i
< dxbc
->count
; ++i
)
699 write_dword(&ptr
, offset
);
700 offset
+= 8 + dxbc
->sections
[i
].data_size
;
703 /* write the chunks */
704 for (i
= 0; i
< dxbc
->count
; ++i
)
706 write_dword(&ptr
, dxbc
->sections
[i
].tag
);
707 write_dword(&ptr
, dxbc
->sections
[i
].data_size
);
708 memcpy(ptr
, dxbc
->sections
[i
].data
, dxbc
->sections
[i
].data_size
);
709 ptr
+= dxbc
->sections
[i
].data_size
;
712 TRACE("Created ID3DBlob %p\n", object
);