comctl32/tests: Flush events before testing edit control IME messages.
[wine.git] / dlls / d3dcompiler_43 / utils.c
bloba8c13a63b67994f26549abfb6eb0343d093419ff
1 /*
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
6 * Copyright 2012 Matteo Bruni for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <stdio.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)
34 switch (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);
44 default:
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)
52 switch (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);
100 default:
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)
108 switch(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);
122 default:
123 FIXME("Unrecognized D3D_BLOB_PART %#x\n", part);
124 return "unrecognized";
128 const char *debug_print_srcmod(uint32_t mod)
130 switch (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);
145 default:
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(uint32_t mod)
155 switch (mod)
157 case 0:
158 return "";
159 case BWRITERSPDM_SATURATE:
160 return "_sat";
161 case BWRITERSPDM_PARTIALPRECISION:
162 return "_pp";
163 case BWRITERSPDM_MSAMPCENTROID:
164 return "_centroid";
165 case BWRITERSPDM_SATURATE | BWRITERSPDM_PARTIALPRECISION:
166 return "_sat_pp";
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";
173 default:
174 return "Unexpected modifier\n";
178 const char *debug_print_shift(uint32_t shift)
180 static const char * const shiftstrings[] =
183 "_x2",
184 "_x4",
185 "_x8",
186 "_x16",
187 "_x32",
194 "_d16",
195 "_d8",
196 "_d4",
197 "_d2",
199 return shiftstrings[shift];
202 static const char *get_regname(const struct shader_reg *reg)
204 switch (reg->type)
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:
217 switch (reg->regnum)
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:
235 return "oDepth";
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:
241 return "aL";
242 case BWRITERSPR_MISCTYPE:
243 switch (reg->regnum)
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);
253 default:
254 return wine_dbg_sprintf("unknown regname %#x", reg->type);
258 static const char *debug_print_writemask(uint32_t mask)
260 char ret[6];
261 unsigned char pos = 1;
263 if(mask == BWRITERSP_WRITEMASK_ALL) return "";
264 ret[0] = '.';
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';
269 ret[pos] = 0;
271 return wine_dbg_sprintf("%s", ret);
274 static const char *debug_print_swizzle(uint32_t arg)
276 char ret[6];
277 unsigned int i;
278 uint32_t swizzle[4];
280 switch (arg)
282 case BWRITERVS_NOSWIZZLE:
283 return "";
284 case BWRITERVS_SWIZZLE_X:
285 return ".x";
286 case BWRITERVS_SWIZZLE_Y:
287 return ".y";
288 case BWRITERVS_SWIZZLE_Z:
289 return ".z";
290 case BWRITERVS_SWIZZLE_W:
291 return ".w";
294 swizzle[0] = arg & 3;
295 swizzle[1] = (arg >> 2) & 3;
296 swizzle[2] = (arg >> 4) & 3;
297 swizzle[3] = (arg >> 6) & 3;
299 ret[0] = '.';
300 for (i = 0; i < 4; ++i)
302 switch (swizzle[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;
310 ret[5] = '\0';
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->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);
326 else
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->writemask));
337 const char *debug_print_srcreg(const struct shader_reg *reg)
339 switch (reg->srcmod)
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->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->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->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->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->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->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->swizzle));
369 case BWRITERSPSM_X2:
370 return wine_dbg_sprintf("%s%s_x2%s", get_regname(reg),
371 debug_print_relarg(reg),
372 debug_print_swizzle(reg->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->swizzle));
377 case BWRITERSPSM_DZ:
378 return wine_dbg_sprintf("%s%s_dz%s", get_regname(reg),
379 debug_print_relarg(reg),
380 debug_print_swizzle(reg->swizzle));
381 case BWRITERSPSM_DW:
382 return wine_dbg_sprintf("%s%s_dw%s", get_regname(reg),
383 debug_print_relarg(reg),
384 debug_print_swizzle(reg->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->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->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->swizzle));
398 return "Unknown modifier";
401 const char *debug_print_comp(uint32_t comp)
403 switch (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(uint32_t opcode)
418 switch (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_u32_unknown(const char **ptr, unsigned int count)
512 unsigned int i;
513 uint32_t u32;
515 FIXME("Skipping %u unknown u32s:\n", count);
516 for (i = 0; i < count; ++i)
518 u32 = read_u32(ptr);
519 FIXME("\t0x%08x\n", u32);
523 static void write_u32_unknown(char **ptr, uint32_t u32)
525 FIXME("Writing unknown u32 0x%08x.\n", u32);
526 write_u32(ptr, u32);
529 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t data_size)
531 TRACE("dxbc %p, tag %s, size %#Ix.\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));
539 if (!new_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;
552 ++dxbc->count;
554 return S_OK;
557 HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size)
559 TRACE("dxbc %p, size %u.\n", dxbc, size);
561 /* use a good starting value for the size if none specified */
562 if (!size) size = 2;
564 dxbc->sections = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*dxbc->sections));
565 if (!dxbc->sections)
567 ERR("Failed to allocate dxbc section memory\n");
568 return E_OUTOFMEMORY;
571 dxbc->size = size;
572 dxbc->count = 0;
574 return S_OK;
577 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc)
579 uint32_t tag, total_size, chunk_count;
580 const char *ptr = data;
581 unsigned int i;
582 HRESULT hr;
584 if (!data)
586 WARN("No data supplied.\n");
587 return E_FAIL;
590 tag = read_u32(&ptr);
591 TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
593 if (tag != TAG_DXBC)
595 WARN("Wrong tag.\n");
596 return E_FAIL;
599 /* checksum? */
600 skip_u32_unknown(&ptr, 4);
602 skip_u32_unknown(&ptr, 1);
604 total_size = read_u32(&ptr);
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 chunk_count = read_u32(&ptr);
614 TRACE("chunk count: %#x\n", chunk_count);
616 hr = dxbc_init(dxbc, chunk_count);
617 if (FAILED(hr))
619 WARN("Failed to init dxbc\n");
620 return hr;
623 for (i = 0; i < chunk_count; ++i)
625 uint32_t chunk_tag, chunk_size;
626 const char *chunk_ptr;
627 uint32_t chunk_offset;
629 chunk_offset = read_u32(&ptr);
630 TRACE("chunk %u at offset %#x\n", i, chunk_offset);
632 chunk_ptr = data + chunk_offset;
634 chunk_tag = read_u32(&chunk_ptr);
635 chunk_size = read_u32(&chunk_ptr);
637 hr = dxbc_add_section(dxbc, chunk_tag, chunk_ptr, chunk_size);
638 if (FAILED(hr))
640 WARN("Failed to add section to dxbc\n");
641 return hr;
645 return hr;
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;
658 ID3DBlob *object;
659 HRESULT hr;
660 char *ptr;
661 unsigned int i;
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);
671 if (FAILED(hr))
673 WARN("Failed to create blob\n");
674 return hr;
677 ptr = ID3D10Blob_GetBufferPointer(object);
679 write_u32(&ptr, TAG_DXBC);
681 /* signature(?) */
682 write_u32_unknown(&ptr, 0);
683 write_u32_unknown(&ptr, 0);
684 write_u32_unknown(&ptr, 0);
685 write_u32_unknown(&ptr, 0);
687 /* seems to be always 1 */
688 write_u32_unknown(&ptr, 1);
690 /* DXBC size */
691 write_u32(&ptr, size);
693 /* chunk count */
694 write_u32(&ptr, dxbc->count);
696 /* write the chunk offsets */
697 for (i = 0; i < dxbc->count; ++i)
699 write_u32(&ptr, offset);
700 offset += 8 + dxbc->sections[i].data_size;
703 /* write the chunks */
704 for (i = 0; i < dxbc->count; ++i)
706 write_u32(&ptr, dxbc->sections[i].tag);
707 write_u32(&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);
714 *blob = object;
716 return S_OK;
719 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args)
721 char* buffer;
722 int rc, size;
724 if (msg->capacity == 0)
726 msg->string = d3dcompiler_alloc(MESSAGEBUFFER_INITIAL_SIZE);
727 if (msg->string == NULL)
729 ERR("Error allocating memory for parser messages\n");
730 return;
732 msg->capacity = MESSAGEBUFFER_INITIAL_SIZE;
735 while (1)
737 rc = vsnprintf(msg->string + msg->size,
738 msg->capacity - msg->size, fmt, args);
740 if (rc < 0 || rc >= msg->capacity - msg->size)
742 size = msg->capacity * 2;
743 buffer = d3dcompiler_realloc(msg->string, size);
744 if (buffer == NULL)
746 ERR("Error reallocating memory for parser messages\n");
747 return;
749 msg->string = buffer;
750 msg->capacity = size;
752 else
754 TRACE("%s", msg->string + msg->size);
755 msg->size += rc;
756 return;