ReactOS  0.4.14-dev-98-gb0d4763
compiler.c
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Matteo Bruni
3  * Copyright 2010 Matteo Bruni for CodeWeavers
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 
20 #define COBJMACROS
21 #include "config.h"
22 #include "wine/port.h"
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
25 
26 #include "d3dcompiler_private.h"
27 #include "wine/wpp.h"
28 
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
30 
31 #define D3DXERR_INVALIDDATA 0x88760b59
32 
33 #define BUFFER_INITIAL_CAPACITY 256
34 
36 {
37  const char *buffer;
38  unsigned int size;
39  unsigned int pos;
40 };
41 
44 static const char *initial_filename;
45 
46 #define INCLUDES_INITIAL_CAPACITY 4
47 
49 {
50  const char *name;
51  const char *data;
52 };
53 
54 static struct loaded_include *includes;
56 static const char *parent_include;
57 
58 static char *wpp_output;
60 
61 static char *wpp_messages;
63 
64 /* Mutex used to guarantee a single invocation
65  of the D3DXAssembleShader function (or its variants) at a time.
66  This is needed as wpp isn't thread-safe */
69 {
70  0, 0, &wpp_mutex,
73  0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") }
74 };
75 static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
76 
77 /* Preprocessor error reporting functions */
78 static void wpp_write_message(const char *fmt, va_list args)
79 {
80  char* newbuffer;
81  int rc, newsize;
82 
83  if(wpp_messages_capacity == 0)
84  {
86  if(wpp_messages == NULL)
87  return;
88 
90  }
91 
92  while(1)
93  {
96 
97  if (rc < 0 || /* C89 */
98  rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
99  /* Resize the buffer */
100  newsize = wpp_messages_capacity * 2;
101  newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
102  if(newbuffer == NULL)
103  {
104  ERR("Error reallocating memory for parser messages\n");
105  return;
106  }
107  wpp_messages = newbuffer;
108  wpp_messages_capacity = newsize;
109  }
110  else
111  {
112  wpp_messages_size += rc;
113  return;
114  }
115  }
116 }
117 
118 static void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
119 {
120  va_list args;
121 
122  va_start(args, fmt);
124  va_end(args);
125 }
126 
127 static void wpp_error(const char *file, int line, int col, const char *_near,
128  const char *msg, va_list ap)
129 {
130  wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
131  line, col, "Error");
133  wpp_write_message_var("\n");
134 }
135 
136 static void wpp_warning(const char *file, int line, int col, const char *_near,
137  const char *msg, va_list ap)
138 {
139  wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
140  line, col, "Warning");
142  wpp_write_message_var("\n");
143 }
144 
145 static char *wpp_lookup_mem(const char *filename, int type, const char *parent_name,
146  char **include_path, int include_path_count)
147 {
148  /* We don't check for file existence here. We will potentially fail on
149  * the following wpp_open_mem(). */
150  char *path;
151  int i;
152 
153  TRACE("Looking for include %s, parent %s.\n", debugstr_a(filename), debugstr_a(parent_name));
154 
156  if (strcmp(parent_name, initial_filename))
157  {
158  for(i = 0; i < includes_size; i++)
159  {
160  if(!strcmp(parent_name, includes[i].name))
161  {
162  parent_include = includes[i].data;
163  break;
164  }
165  }
166  if(parent_include == NULL)
167  {
168  ERR("Parent include %s missing.\n", debugstr_a(parent_name));
169  return NULL;
170  }
171  }
172 
173  path = malloc(strlen(filename) + 1);
174  if(path)
176  return path;
177 }
178 
179 static void *wpp_open_mem(const char *filename, int type)
180 {
181  struct mem_file_desc *desc;
182  HRESULT hr;
183 
184  TRACE("Opening include %s.\n", debugstr_a(filename));
185 
187  {
188  current_shader.pos = 0;
189  return &current_shader;
190  }
191 
192  if(current_include == NULL) return NULL;
193  desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
194  if(!desc)
195  return NULL;
196 
198  filename, parent_include, (const void **)&desc->buffer, &desc->size)))
199  {
201  return NULL;
202  }
203 
205  {
206  if(includes_capacity == 0)
207  {
209  if(includes == NULL)
210  {
211  ERR("Error allocating memory for the loaded includes structure\n");
212  goto error;
213  }
214  includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes);
215  }
216  else
217  {
218  int newcapacity = includes_capacity * 2;
219  struct loaded_include *newincludes =
220  HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
221  if(newincludes == NULL)
222  {
223  ERR("Error reallocating memory for the loaded includes structure\n");
224  goto error;
225  }
226  includes = newincludes;
227  includes_capacity = newcapacity;
228  }
229  }
231  includes[includes_size++].data = desc->buffer;
232 
233  desc->pos = 0;
234  return desc;
235 
236 error:
237  ID3DInclude_Close(current_include, desc->buffer);
239  return NULL;
240 }
241 
242 static void wpp_close_mem(void *file)
243 {
244  struct mem_file_desc *desc = file;
245 
246  if(desc != &current_shader)
247  {
248  if(current_include)
249  ID3DInclude_Close(current_include, desc->buffer);
250  else
251  ERR("current_include == NULL, desc == %p, buffer = %s\n",
252  desc, desc->buffer);
253 
255  }
256 }
257 
258 static int wpp_read_mem(void *file, char *buffer, unsigned int len)
259 {
260  struct mem_file_desc *desc = file;
261 
262  len = min(len, desc->size - desc->pos);
263  memcpy(buffer, desc->buffer + desc->pos, len);
264  desc->pos += len;
265  return len;
266 }
267 
268 static void wpp_write_mem(const char *buffer, unsigned int len)
269 {
270  char *new_wpp_output;
271 
272  if(wpp_output_capacity == 0)
273  {
275  if(!wpp_output)
276  return;
277 
279  }
281  {
283  {
284  wpp_output_capacity *= 2;
285  }
286  new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
288  if(!new_wpp_output)
289  {
290  ERR("Error allocating memory\n");
291  return;
292  }
293  wpp_output = new_wpp_output;
294  }
296  wpp_output_size += len;
297 }
298 
299 static int wpp_close_output(void)
300 {
301  char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
302  wpp_output_size + 1);
303  if(!new_wpp_output) return 0;
304  wpp_output = new_wpp_output;
306  wpp_output_size++;
307  return 1;
308 }
309 
310 static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename,
311  const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
312 {
313  int ret;
314  HRESULT hr = S_OK;
315  const D3D_SHADER_MACRO *def = defines;
316 
317  static const struct wpp_callbacks wpp_callbacks =
318  {
320  wpp_open_mem,
322  wpp_read_mem,
324  wpp_error,
325  wpp_warning,
326  };
327 
328  if (def != NULL)
329  {
330  while (def->Name != NULL)
331  {
332  wpp_add_define(def->Name, def->Definition);
333  def++;
334  }
335  }
336  current_include = include;
337  includes_size = 0;
338 
340  wpp_output = NULL;
341 
344  wpp_messages = NULL;
345  current_shader.buffer = data;
346  current_shader.size = data_size;
348 
350  if (!wpp_close_output())
351  ret = 1;
352  if (ret)
353  {
354  TRACE("Error during shader preprocessing\n");
355  if (wpp_messages)
356  {
357  int size;
358  ID3DBlob *buffer;
359 
360  TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages));
361 
362  if (error_messages)
363  {
364  size = strlen(wpp_messages) + 1;
366  if (FAILED(hr))
367  goto cleanup;
368  CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size);
369  *error_messages = buffer;
370  }
371  }
372  if (data)
373  TRACE("Shader source:\n%s\n", debugstr_an(data, data_size));
374  hr = E_FAIL;
375  }
376 
377 cleanup:
378  /* Remove the previously added defines */
379  if (defines != NULL)
380  {
381  while (defines->Name != NULL)
382  {
383  wpp_del_define(defines->Name);
384  defines++;
385  }
386  }
388  return hr;
389 }
390 
391 static HRESULT assemble_shader(const char *preproc_shader,
392  ID3DBlob **shader_blob, ID3DBlob **error_messages)
393 {
394  struct bwriter_shader *shader;
395  char *messages = NULL;
396  HRESULT hr;
397  DWORD *res, size;
398  ID3DBlob *buffer;
399  char *pos;
400 
401  shader = SlAssembleShader(preproc_shader, &messages);
402 
403  if (messages)
404  {
405  TRACE("Assembler messages:\n");
406  TRACE("%s\n", debugstr_a(messages));
407 
408  TRACE("Shader source:\n");
409  TRACE("%s\n", debugstr_a(preproc_shader));
410 
411  if (error_messages)
412  {
413  const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
414 
415  size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
417  if (FAILED(hr))
418  {
421  return hr;
422  }
423  pos = ID3D10Blob_GetBufferPointer(buffer);
424  if (preproc_messages)
425  {
426  CopyMemory(pos, preproc_messages, strlen(preproc_messages) + 1);
427  pos += strlen(preproc_messages);
428  }
430 
431  if (*error_messages) ID3D10Blob_Release(*error_messages);
432  *error_messages = buffer;
433  }
435  }
436 
437  if (shader == NULL)
438  {
439  ERR("Asm reading failed\n");
440  return D3DXERR_INVALIDDATA;
441  }
442 
443  hr = SlWriteBytecode(shader, 9, &res, &size);
445  if (FAILED(hr))
446  {
447  ERR("SlWriteBytecode failed with 0x%08x\n", hr);
448  return D3DXERR_INVALIDDATA;
449  }
450 
451  if (shader_blob)
452  {
454  if (FAILED(hr))
455  {
456  HeapFree(GetProcessHeap(), 0, res);
457  return hr;
458  }
459  CopyMemory(ID3D10Blob_GetBufferPointer(buffer), res, size);
460  *shader_blob = buffer;
461  }
462 
463  HeapFree(GetProcessHeap(), 0, res);
464 
465  return S_OK;
466 }
467 
468 HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename,
469  const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags,
470  ID3DBlob **shader, ID3DBlob **error_messages)
471 {
472  HRESULT hr;
473 
474  TRACE("data %p, datasize %lu, filename %s, defines %p, include %p, sflags %#x, "
475  "shader %p, error_messages %p.\n",
476  data, datasize, debugstr_a(filename), defines, include, flags, shader, error_messages);
477 
479 
480  /* TODO: flags */
481  if (flags) FIXME("flags %x\n", flags);
482 
483  if (shader) *shader = NULL;
484  if (error_messages) *error_messages = NULL;
485 
486  hr = preprocess_shader(data, datasize, filename, defines, include, error_messages);
487  if (SUCCEEDED(hr))
488  hr = assemble_shader(wpp_output, shader, error_messages);
489 
492  return hr;
493 }
494 
495 struct target_info {
496  const char *name;
504 };
505 
506 /* Must be kept sorted for binary search */
507 static const struct target_info targets_info[] = {
508  { "cs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
509  { "cs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
510  { "cs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
511  { "ds_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
512  { "fx_2_0", ST_UNKNOWN, 2, 0, 0, 0, FALSE, FALSE },
513  { "fx_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
514  { "fx_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
515  { "fx_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
516  { "gs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
517  { "gs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
518  { "gs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
519  { "hs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
520  { "ps.1.0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE },
521  { "ps.1.1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE },
522  { "ps.1.2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE },
523  { "ps.1.3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE },
524  { "ps.1.4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE },
525  { "ps.2.0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE },
526  { "ps.2.a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE },
527  { "ps.2.b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE },
528  { "ps.2.sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE },
529  { "ps.3.0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE },
530  { "ps_1_0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE },
531  { "ps_1_1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE },
532  { "ps_1_2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE },
533  { "ps_1_3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE },
534  { "ps_1_4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE },
535  { "ps_2_0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE },
536  { "ps_2_a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE },
537  { "ps_2_b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE },
538  { "ps_2_sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE },
539  { "ps_3_0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE },
540  { "ps_3_sw", ST_PIXEL, 3, 0, 0, 0, TRUE, FALSE },
541  { "ps_4_0", ST_PIXEL, 4, 0, 0, 0, FALSE, TRUE },
542  { "ps_4_0_level_9_0", ST_PIXEL, 4, 0, 9, 0, FALSE, FALSE },
543  { "ps_4_0_level_9_1", ST_PIXEL, 4, 0, 9, 1, FALSE, FALSE },
544  { "ps_4_0_level_9_3", ST_PIXEL, 4, 0, 9, 3, FALSE, FALSE },
545  { "ps_4_1", ST_PIXEL, 4, 1, 0, 0, FALSE, TRUE },
546  { "ps_5_0", ST_PIXEL, 5, 0, 0, 0, FALSE, TRUE },
547  { "tx_1_0", ST_UNKNOWN, 1, 0, 0, 0, FALSE, FALSE },
548  { "vs.1.0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE },
549  { "vs.1.1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE },
550  { "vs.2.0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE },
551  { "vs.2.a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE },
552  { "vs.2.sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE },
553  { "vs.3.0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE },
554  { "vs.3.sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE },
555  { "vs_1_0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE },
556  { "vs_1_1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE },
557  { "vs_2_0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE },
558  { "vs_2_a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE },
559  { "vs_2_sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE },
560  { "vs_3_0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE },
561  { "vs_3_sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE },
562  { "vs_4_0", ST_VERTEX, 4, 0, 0, 0, FALSE, TRUE },
563  { "vs_4_0_level_9_0", ST_VERTEX, 4, 0, 9, 0, FALSE, FALSE },
564  { "vs_4_0_level_9_1", ST_VERTEX, 4, 0, 9, 1, FALSE, FALSE },
565  { "vs_4_0_level_9_3", ST_VERTEX, 4, 0, 9, 3, FALSE, FALSE },
566  { "vs_4_1", ST_VERTEX, 4, 1, 0, 0, FALSE, TRUE },
567  { "vs_5_0", ST_VERTEX, 5, 0, 0, 0, FALSE, TRUE },
568 };
569 
570 static const struct target_info * get_target_info(const char *target)
571 {
572  LONG min = 0;
574  LONG cur;
575  int res;
576 
577  while (min <= max)
578  {
579  cur = (min + max) / 2;
580  res = strcmp(target, targets_info[cur].name);
581  if (res < 0)
582  max = cur - 1;
583  else if (res > 0)
584  min = cur + 1;
585  else
586  return &targets_info[cur];
587  }
588 
589  return NULL;
590 }
591 
592 static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint,
593  ID3DBlob **shader_blob, ID3DBlob **error_messages)
594 {
595  struct bwriter_shader *shader;
596  char *messages = NULL;
597  HRESULT hr;
598  DWORD *res, size, major, minor;
599  ID3DBlob *buffer;
600  char *pos;
602  const struct target_info *info;
603 
604  TRACE("Preprocessed shader source: %s\n", debugstr_a(preproc_shader));
605 
606  TRACE("Checking compilation target %s\n", debugstr_a(target));
608  if (!info)
609  {
610  FIXME("Unknown compilation target %s\n", debugstr_a(target));
611  return D3DERR_INVALIDCALL;
612  }
613  else
614  {
615  if (!info->support)
616  {
617  FIXME("Compilation target %s not yet supported\n", debugstr_a(target));
618  return D3DERR_INVALIDCALL;
619  }
620  else
621  {
622  shader_type = info->type;
623  major = info->sm_major;
624  minor = info->sm_minor;
625  }
626  }
627 
628  shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
629 
630  if (messages)
631  {
632  TRACE("Compiler messages:\n");
633  TRACE("%s\n", debugstr_a(messages));
634 
635  TRACE("Shader source:\n");
636  TRACE("%s\n", debugstr_a(preproc_shader));
637 
638  if (error_messages)
639  {
640  const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
641 
642  size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
644  if (FAILED(hr))
645  {
648  return hr;
649  }
650  pos = ID3D10Blob_GetBufferPointer(buffer);
651  if (preproc_messages)
652  {
653  memcpy(pos, preproc_messages, strlen(preproc_messages) + 1);
654  pos += strlen(preproc_messages);
655  }
657 
658  if (*error_messages) ID3D10Blob_Release(*error_messages);
659  *error_messages = buffer;
660  }
662  }
663 
664  if (!shader)
665  {
666  ERR("HLSL shader parsing failed.\n");
667  return D3DXERR_INVALIDDATA;
668  }
669 
670  hr = SlWriteBytecode(shader, 9, &res, &size);
672  if (FAILED(hr))
673  {
674  ERR("SlWriteBytecode failed with error 0x%08x.\n", hr);
675  return D3DXERR_INVALIDDATA;
676  }
677 
678  if (shader_blob)
679  {
681  if (FAILED(hr))
682  {
683  HeapFree(GetProcessHeap(), 0, res);
684  return hr;
685  }
686  memcpy(ID3D10Blob_GetBufferPointer(buffer), res, size);
687  *shader_blob = buffer;
688  }
689 
690  HeapFree(GetProcessHeap(), 0, res);
691 
692  return S_OK;
693 }
694 
695 HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
696  const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
697  const char *target, UINT sflags, UINT eflags, UINT secondary_flags,
698  const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader,
699  ID3DBlob **error_messages)
700 {
701  HRESULT hr;
702 
703  TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
704  "target %s, sflags %#x, eflags %#x, secondary_flags %#x, secondary_data %p, "
705  "secondary_data_size %lu, shader %p, error_messages %p.\n",
706  data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
707  debugstr_a(target), sflags, eflags, secondary_flags, secondary_data,
708  secondary_data_size, shader, error_messages);
709 
710  if (secondary_data)
711  FIXME("secondary data not implemented yet\n");
712 
713  if (shader) *shader = NULL;
714  if (error_messages) *error_messages = NULL;
715 
717 
718  hr = preprocess_shader(data, data_size, filename, defines, include, error_messages);
719  if (SUCCEEDED(hr))
720  hr = compile_shader(wpp_output, target, entrypoint, shader, error_messages);
721 
724  return hr;
725 }
726 
727 HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
728  const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
729  const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
730 {
731  TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
732  "target %s, sflags %#x, eflags %#x, shader %p, error_messages %p.\n",
733  data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
734  debugstr_a(target), sflags, eflags, shader, error_messages);
735 
736  return D3DCompile2(data, data_size, filename, defines, include, entrypoint, target, sflags,
737  eflags, 0, NULL, 0, shader, error_messages);
738 }
739 
740 HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename,
741  const D3D_SHADER_MACRO *defines, ID3DInclude *include,
742  ID3DBlob **shader, ID3DBlob **error_messages)
743 {
744  HRESULT hr;
745  ID3DBlob *buffer;
746 
747  TRACE("data %p, size %lu, filename %s, defines %p, include %p, shader %p, error_messages %p\n",
748  data, size, debugstr_a(filename), defines, include, shader, error_messages);
749 
750  if (!data)
751  return E_INVALIDARG;
752 
754 
755  if (shader) *shader = NULL;
756  if (error_messages) *error_messages = NULL;
757 
758  hr = preprocess_shader(data, size, filename, defines, include, error_messages);
759 
760  if (SUCCEEDED(hr))
761  {
762  if (shader)
763  {
765  if (FAILED(hr))
766  goto cleanup;
767  CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size);
768  *shader = buffer;
769  }
770  else
771  hr = E_INVALIDARG;
772  }
773 
774 cleanup:
777  return hr;
778 }
779 
780 HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
781 {
782  FIXME("data %p, size %lu, flags %#x, comments %p, disassembly %p stub!\n",
783  data, size, flags, comments, disassembly);
784  return E_NOTIMPL;
785 }
786 
788  const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
789 {
790  FIXME("filename %s, defines %p, includes %p, entrypoint %s, target %s, flags1 %x, flags2 %x, code %p, errors %p\n",
791  debugstr_w(filename), defines, includes, debugstr_a(entrypoint), debugstr_a(target), flags1, flags2, code, errors);
792 
793  return E_NOTIMPL;
794 }
795 
796 #ifndef __REACTOS__
797 HRESULT WINAPI D3DLoadModule(const void *data, SIZE_T size, ID3D11Module **module)
798 {
799  FIXME("data %p, size %lu, module %p stub!\n", data, size, module);
800  return E_NOTIMPL;
801 }
802 #endif
static void PRINTF_ATTR(1, 2)
Definition: compiler.c:118
#define vsnprintf
Definition: tif_win32.c:406
static char * wpp_output
Definition: compiler.c:58
void wpp_set_callbacks(const struct wpp_callbacks *callbacks)
Definition: wpp.c:232
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
static void wpp_warning(const char *file, int line, int col, const char *_near, const char *msg, va_list ap)
Definition: compiler.c:136
static void wpp_write_message(const char *fmt, va_list args)
Definition: compiler.c:78
#define DWORD_PTR
Definition: treelist.c:76
HRESULT hr
Definition: shlfolder.c:183
#define error(str)
Definition: mkdosfs.c:1605
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static ID3DInclude * current_include
Definition: compiler.c:43
static int wpp_output_size
Definition: compiler.c:59
HRESULT WINAPI D3DCompileFromFile(const WCHAR *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *includes, const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
Definition: compiler.c:787
const char * name
Definition: compiler.c:496
#define D3DXERR_INVALIDDATA
Definition: compiler.c:31
GLsizei const GLchar ** path
Definition: glext.h:7234
static char * wpp_messages
Definition: compiler.c:61
DWORD level_minor
Definition: compiler.c:501
int wpp_add_define(const char *name, const char *value)
Definition: wpp.c:93
#define D3DERR_INVALIDCALL
static CRITICAL_SECTION wpp_mutex
Definition: compiler.c:67
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:740
static void wpp_error(const char *file, int line, int col, const char *_near, const char *msg, va_list ap)
Definition: compiler.c:127
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint, ID3DBlob **shader_blob, ID3DBlob **error_messages)
Definition: compiler.c:592
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
const char * filename
Definition: ioapi.h:135
#define E_FAIL
Definition: ddrawi.h:102
Definition: match.c:390
static struct mem_file_desc current_shader
Definition: compiler.c:42
struct _test_info info[]
Definition: SetCursorPos.c:19
static int wpp_close_output(void)
Definition: compiler.c:299
HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:468
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
#define va_end(ap)
Definition: acmsvcex.h:90
static void wpp_write_mem(const char *buffer, unsigned int len)
Definition: compiler.c:268
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MESSAGEBUFFER_INITIAL_SIZE
long LONG
Definition: pedump.c:60
static HRESULT assemble_shader(const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
Definition: compiler.c:391
unsigned int pos
Definition: compiler.c:39
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
void wpp_del_define(const char *name)
Definition: wpp.c:136
#define E_INVALIDARG
Definition: ddrawi.h:101
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
DWORD sm_minor
Definition: compiler.c:499
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
char * va_list
Definition: acmsvcex.h:78
static struct loaded_include * includes
Definition: compiler.c:54
const char * Definition
Definition: d3dcommon.idl:25
GLuint shader
Definition: glext.h:6030
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
const char file[]
Definition: icontest.c:11
#define CopyMemory
Definition: winbase.h:1640
static int wpp_messages_capacity
Definition: compiler.c:62
HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:727
unsigned int size
Definition: compiler.c:38
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const char * initial_filename
Definition: compiler.c:44
GLbitfield flags
Definition: glext.h:7161
#define BUFFER_INITIAL_CAPACITY
Definition: compiler.c:33
int ret
HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
Definition: compiler.c:780
const char * name
Definition: compiler.c:50
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
Definition: compiler.c:310
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:47
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler)
HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob)
Definition: blob.c:136
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
static int wpp_read_mem(void *file, char *buffer, unsigned int len)
Definition: compiler.c:258
void SlDeleteShader(struct bwriter_shader *shader)
enum shader_type type
Definition: compiler.c:497
static void wpp_close_mem(void *file)
Definition: compiler.c:242
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855
char comments[4096]
static const char * parent_include
Definition: compiler.c:56
static void * wpp_open_mem(const char *filename, int type)
Definition: compiler.c:179
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
DWORD level_major
Definition: compiler.c:500
const char * buffer
Definition: compiler.c:37
static int includes_size
Definition: compiler.c:55
#define S_OK
Definition: intsafe.h:59
#define ARRAY_SIZE(a)
Definition: main.h:24
#define major(rdev)
Definition: propsheet.cpp:879
static char * wpp_lookup_mem(const char *filename, int type, const char *parent_name, char **include_path, int include_path_count)
Definition: compiler.c:145
#define HeapReAlloc
Definition: compat.h:393
#define E_NOTIMPL
Definition: ddrawi.h:99
Definition: services.c:325
static const struct target_info * get_target_info(const char *target)
Definition: compiler.c:570
#define min(a, b)
Definition: monoChain.cc:55
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int UINT
Definition: ndis.h:50
DWORD sm_major
Definition: compiler.c:498
static const struct target_info targets_info[]
Definition: compiler.c:507
#define msg(x)
Definition: auth_time.c:54
struct bwriter_shader * SlAssembleShader(const char *text, char **messages)
Definition: name.c:36
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
static int wpp_output_capacity
Definition: compiler.c:59
GLuint res
Definition: glext.h:9613
const char * data
Definition: compiler.c:51
const char * Name
Definition: d3dcommon.idl:24
GLenum target
Definition: glext.h:7315
#define const
Definition: zconf.h:230
BOOL support
Definition: compiler.c:503
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define minor(rdev)
Definition: propsheet.cpp:880
static int wpp_messages_size
Definition: compiler.c:62
char * cleanup(char *str)
Definition: wpickclick.c:99
#define malloc
Definition: debug_ros.c:4
#define INCLUDES_INITIAL_CAPACITY
Definition: compiler.c:46
static int includes_capacity
Definition: compiler.c:55
struct bwriter_shader * parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, const char *entrypoint, char **messages) DECLSPEC_HIDDEN
Definition: hlsl.yy.c:2927
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, UINT secondary_flags, const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:695
HRESULT WINAPI D3DLoadModule(const void *data, SIZE_T size, ID3D11Module **module)
Definition: compiler.c:797
#define args
Definition: format.c:66
Definition: dsound.c:943
#define HeapFree(x, y, z)
Definition: compat.h:394
static CRITICAL_SECTION_DEBUG wpp_mutex_debug
Definition: compiler.c:68
#define SUCCEEDED(hr)
Definition: intsafe.h:57
int wpp_parse(const char *input, FILE *output)
Definition: wpp.c:184
Definition: fci.c:126