ReactOS 0.4.17-dev-934-g091855f
compiler.c File Reference
#include <stdarg.h>
#include <time.h>
#include "wine/debug.h"
#include "d3dcompiler_private.h"
Include dependency graph for compiler.c:

Go to the source code of this file.

Classes

struct  d3dcompiler_include_from_file
 

Macros

#define COBJMACROS
 
#define D3DXERR_INVALIDDATA   0x88760b59
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3dcompiler)
 
static HRESULT hresult_from_vkd3d_result (int vkd3d_result)
 
static struct d3dcompiler_include_from_file * impl_from_ID3DInclude (ID3DInclude *iface)
 
static HRESULT WINAPI d3dcompiler_include_from_file_open (ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data, UINT *bytes)
 
static HRESULT WINAPI d3dcompiler_include_from_file_close (ID3DInclude *iface, const void *data)
 
static int open_include (const char *filename, bool local, const char *parent_data, void *context, struct vkd3d_shader_code *code)
 
static void close_include (const struct vkd3d_shader_code *code, void *context)
 
static const char * get_line (const char **ptr)
 
static HRESULT preprocess_shader (const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader_blob, ID3DBlob **messages_blob)
 
static HRESULT assemble_shader (const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
 
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)
 
static enum vkd3d_shader_target_type get_target_for_profile (const char *profile)
 
HRESULT WINAPI D3DCompile2 (const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point, const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags, const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob, ID3DBlob **messages_blob)
 
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)
 
HRESULT WINAPI D3DPreprocess (const void *data, SIZE_T size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader, ID3DBlob **error_messages)
 
HRESULT WINAPI D3DDisassemble (const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
 
HRESULT WINAPI D3DCompileFromFile (const WCHAR *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
 
HRESULT WINAPI D3DCreateLinker (ID3D11Linker **linker)
 
HRESULT WINAPI D3DLoadModule (const void *data, SIZE_T size, ID3D11Module **module)
 

Variables

static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG wpp_mutex_debug
 
const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file compiler.c.

◆ D3DXERR_INVALIDDATA

#define D3DXERR_INVALIDDATA   0x88760b59

Definition at line 53 of file compiler.c.

Function Documentation

◆ assemble_shader()

static HRESULT assemble_shader ( const char *  preproc_shader,
ID3DBlob **  shader_blob,
ID3DBlob **  error_messages 
)
static

Definition at line 285 of file compiler.c.

286{
287 struct bwriter_shader *shader;
288 char *messages = NULL;
289 uint32_t *res, size;
291 HRESULT hr;
292 char *pos;
293
294 shader = SlAssembleShader(preproc_shader, &messages);
295
296 if (messages)
297 {
298 TRACE("Assembler messages:\n");
299 TRACE("%s\n", debugstr_a(messages));
300
301 TRACE("Shader source:\n");
302 TRACE("%s\n", debugstr_a(preproc_shader));
303
304 if (error_messages)
305 {
306 const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
307
308 size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
310 if (FAILED(hr))
311 {
312 free(messages);
314 return hr;
315 }
316 pos = ID3D10Blob_GetBufferPointer(buffer);
317 if (preproc_messages)
318 {
319 CopyMemory(pos, preproc_messages, strlen(preproc_messages) + 1);
320 pos += strlen(preproc_messages);
321 }
323
324 if (*error_messages) ID3D10Blob_Release(*error_messages);
326 }
327 free(messages);
328 }
329
330 if (shader == NULL)
331 {
332 ERR("Asm reading failed\n");
333 return D3DXERR_INVALIDDATA;
334 }
335
338 if (FAILED(hr))
339 {
340 ERR("Failed to write bytecode, hr %#lx.\n", hr);
341 return D3DXERR_INVALIDDATA;
342 }
343
344 if (shader_blob)
345 {
347 if (FAILED(hr))
348 {
349 free(res);
350 return hr;
351 }
352 CopyMemory(ID3D10Blob_GetBufferPointer(buffer), res, size);
353 *shader_blob = buffer;
354 }
355
356 free(res);
357
358 return S_OK;
359}
#define ERR(fmt,...)
Definition: precomp.h:57
HRESULT shader_write_bytecode(const struct bwriter_shader *shader, uint32_t **result, uint32_t *size)
void SlDeleteShader(struct bwriter_shader *shader)
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT ID3DBlob ID3DBlob ** error_messages
Definition: asm.c:32
#define D3DXERR_INVALIDDATA
Definition: compiler.c:53
struct bwriter_shader * SlAssembleShader(const char *text, char **messages)
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
UINT32 uint32_t
Definition: types.h:75
HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob)
Definition: blob.c:133
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint shader
Definition: glext.h:6030
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_a
Definition: kernel32.h:31
#define CopyMemory
Definition: minwinbase.h:29
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by D3DAssemble().

◆ close_include()

static void close_include ( const struct vkd3d_shader_code *  code,
void *  context 
)
static

Definition at line 167 of file compiler.c.

168{
169 ID3DInclude *iface = context;
170
171 ID3DInclude_Close(iface, code->code);
172}
Definition: inflate.c:139
Definition: http.c:7252

Referenced by D3DCompile2(), and preprocess_shader().

◆ D3DAssemble()

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 at line 361 of file compiler.c.

364{
365 unsigned int preproc_size;
366 ID3DBlob *preproc_shader;
367 char *preproc_terminated;
368 HRESULT hr;
369
370 TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, sflags %#x, "
371 "shader %p, error_messages %p.\n",
373
375
376 /* TODO: flags */
377 if (flags) FIXME("flags %x\n", flags);
378
379 if (shader) *shader = NULL;
381
383 if (SUCCEEDED(hr))
384 {
385 preproc_size = ID3D10Blob_GetBufferSize(preproc_shader);
386 if ((preproc_terminated = malloc(preproc_size + 1)))
387 {
388 memcpy(preproc_terminated, ID3D10Blob_GetBufferPointer(preproc_shader), preproc_size);
389 ID3D10Blob_Release(preproc_shader);
390 preproc_terminated[preproc_size] = 0;
391
392 hr = assemble_shader(preproc_terminated, shader, error_messages);
393 free(preproc_terminated);
394 }
395 }
397 return hr;
398}
#define FIXME(fmt,...)
Definition: precomp.h:53
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:31
static SIZE_T const char const D3D_SHADER_MACRO * defines
Definition: asm.c:31
static SIZE_T datasize
Definition: asm.c:30
static CRITICAL_SECTION wpp_mutex
Definition: compiler.c:57
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader_blob, ID3DBlob **messages_blob)
Definition: compiler.c:191
static HRESULT assemble_shader(const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
Definition: compiler.c:285
#define malloc
Definition: debug_ros.c:4
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
#define SUCCEEDED(hr)
Definition: intsafe.h:50
const char * filename
Definition: ioapi.h:137
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

◆ D3DCompile()

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 at line 639 of file compiler.c.

642{
643 TRACE("data %p, data_size %Iu, filename %s, defines %p, include %p, entrypoint %s, "
644 "target %s, sflags %#x, eflags %#x, shader %p, error_messages %p.\n",
645 data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
647
648 return D3DCompile2(data, data_size, filename, defines, include, entrypoint, target, sflags,
650}
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point, const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags, const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob, ID3DBlob **messages_blob)
Definition: compiler.c:451
Definition: tools.h:99

Referenced by call_D3DCompile(), compile_shader_(), create_effect(), d2d_device_context_init(), D3DCompileFromFile(), D3DX10CompileFromMemory(), D3DX11CompileFromMemory(), d3dx9_effect_init(), D3DXCompileShader(), D3DXCompileShaderFromFileW(), test_fail(), test_hlsl_double(), test_include(), and test_no_output_blob().

◆ D3DCompile2()

HRESULT WINAPI D3DCompile2 ( const void *  data,
SIZE_T  data_size,
const char *  filename,
const D3D_SHADER_MACRO *  macros,
ID3DInclude *  include,
const char *  entry_point,
const char *  profile,
UINT  flags,
UINT  effect_flags,
UINT  secondary_flags,
const void *  secondary_data,
SIZE_T  secondary_data_size,
ID3DBlob **  shader_blob,
ID3DBlob **  messages_blob 
)

Definition at line 451 of file compiler.c.

456{
457 struct d3dcompiler_include_from_file include_from_file;
458 struct vkd3d_shader_preprocess_info preprocess_info;
459 struct vkd3d_shader_hlsl_source_info hlsl_info;
461 struct vkd3d_shader_compile_info compile_info;
463 struct vkd3d_shader_code byte_code;
464 const D3D_SHADER_MACRO *macro;
465 char *messages;
466 HRESULT hr;
467 int ret;
468
469 TRACE("data %p, data_size %Iu, filename %s, macros %p, include %p, entry_point %s, "
470 "profile %s, flags %#x, effect_flags %#x, secondary_flags %#x, secondary_data %p, "
471 "secondary_data_size %Iu, shader_blob %p, messages_blob %p.\n",
472 data, data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point),
473 debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data,
474 secondary_data_size, shader_blob, messages_blob);
475
477 {
478 include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
479 include_from_file.initial_filename = filename ? filename : "";
480 include = &include_from_file.ID3DInclude_iface;
481 }
482
485 {
486 FIXME("Ignoring flags %#x.\n", flags);
487 }
488 if (effect_flags & ~D3DCOMPILE_EFFECT_CHILD_EFFECT)
489 FIXME("Ignoring effect flags %#x.\n", effect_flags & ~D3DCOMPILE_EFFECT_CHILD_EFFECT);
490 if (secondary_flags)
491 FIXME("Ignoring secondary flags %#x.\n", secondary_flags);
492
493 if (shader_blob)
494 *shader_blob = NULL;
495 if (messages_blob)
496 *messages_blob = NULL;
497
498 option = &options[0];
501
503 compile_info.next = &preprocess_info;
504 compile_info.source.code = data;
505 compile_info.source.size = data_size;
506 compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
507 compile_info.target_type = get_target_for_profile(profile);
508 compile_info.options = options;
509 compile_info.option_count = 1;
510 compile_info.log_level = VKD3D_SHADER_LOG_INFO;
511 compile_info.source_name = filename;
512
513 preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
514 preprocess_info.next = &hlsl_info;
515 preprocess_info.macros = (const struct vkd3d_shader_macro *)macros;
516 preprocess_info.macro_count = 0;
517 if (macros)
518 {
519 for (macro = macros; macro->Name; ++macro)
520 ++preprocess_info.macro_count;
521 }
522 preprocess_info.pfn_open_include = open_include;
523 preprocess_info.pfn_close_include = close_include;
524 preprocess_info.include_context = include;
525
527 hlsl_info.next = NULL;
528 hlsl_info.profile = profile;
529 hlsl_info.entry_point = entry_point;
530 hlsl_info.secondary_code.code = secondary_data;
531 hlsl_info.secondary_code.size = secondary_data_size;
532
533 if (!(flags & D3DCOMPILE_DEBUG))
534 {
535 option = &options[compile_info.option_count++];
537 option->value = true;
538 }
539
541 {
542 option = &options[compile_info.option_count++];
545 }
547 {
548 option = &options[compile_info.option_count++];
551 }
552
554 {
555 option = &options[compile_info.option_count++];
558 }
559
560 if (effect_flags & D3DCOMPILE_EFFECT_CHILD_EFFECT)
561 {
562 option = &options[compile_info.option_count++];
564 option->value = true;
565 }
566
567#if D3D_COMPILER_VERSION <= 39
568 option = &options[compile_info.option_count++];
570 option->value = true;
571#endif
572
573 ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);
574
575 if (ret)
576 ERR("Failed to compile shader, vkd3d result %d.\n", ret);
577
578 if (messages)
579 {
580 if (*messages && ERR_ON(d3dcompiler))
581 {
582 const char *ptr = messages;
583 const char *line;
584
585 ERR("Shader log:\n");
586 while ((line = get_line(&ptr)))
587 {
588 ERR(" %.*s", (int)(ptr - line), line);
589 }
590 ERR("\n");
591 }
592
593 if (messages_blob)
594 {
595 size_t size = strlen(messages);
596 if (FAILED(hr = D3DCreateBlob(size, messages_blob)))
597 {
600 return hr;
601 }
602 memcpy(ID3D10Blob_GetBufferPointer(*messages_blob), messages, size);
603 }
604
606 }
607
608 if (ret)
610
611 if (!shader_blob)
612 {
614 return S_OK;
615 }
616
617 /* Unlike other effect profiles fx_4_x is using DXBC container. */
618 if (!strcmp(profile, "fx_4_0") || !strcmp(profile, "fx_4_1"))
619 {
620 struct vkd3d_shader_dxbc_section_desc section = { .tag = TAG_FX10, .data = byte_code };
621 struct vkd3d_shader_code dxbc;
622
625 if (ret)
627
628 byte_code = dxbc;
629 }
630
631 if (SUCCEEDED(hr = D3DCreateBlob(byte_code.size, shader_blob)))
632 memcpy(ID3D10Blob_GetBufferPointer(*shader_blob), byte_code.code, byte_code.size);
633
635
636 return hr;
637}
static WCHAR *(* get_line)(FILE *)
Definition: import.c:55
#define D3DCOMPILE_DEBUG
Definition: d3dcompiler.h:42
#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY
Definition: d3dcompiler.h:54
#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
Definition: d3dcompiler.h:45
#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR
Definition: d3dcompiler.h:46
#define D3DCOMPILE_EFFECT_CHILD_EFFECT
Definition: d3dcompiler.h:69
#define D3D_COMPILE_STANDARD_FILE_INCLUDE
Definition: d3dcompiler.h:85
static int open_include(const char *filename, bool local, const char *parent_data, void *context, struct vkd3d_shader_code *code)
Definition: compiler.c:149
static void close_include(const struct vkd3d_shader_code *code, void *context)
Definition: compiler.c:167
static HRESULT hresult_from_vkd3d_result(int vkd3d_result)
Definition: compiler.c:30
static enum vkd3d_shader_target_type get_target_for_profile(const char *profile)
Definition: compiler.c:400
const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl
Definition: compiler.c:143
#define TAG_FX10
Definition: effect.c:32
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
return ret
Definition: mutex.c:147
struct macel macros[16]
Definition: main.c:109
#define profile
Definition: kernel32.h:12
static PVOID ptr
Definition: dispmode.c:27
#define ERR_ON(ch)
Definition: debug.h:423
Definition: parser.c:49
Definition: getopt.h:109
WCHAR * name
Definition: getopt.h:110
Definition: parser.c:56
@ VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY
Definition: vkd3d_shader.h:310
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER
Definition: vkd3d_shader.h:302
@ VKD3D_SHADER_COMPILE_OPTION_CHILD_EFFECT
Definition: vkd3d_shader.h:341
@ VKD3D_SHADER_COMPILE_OPTION_API_VERSION
Definition: vkd3d_shader.h:279
@ VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG
Definition: vkd3d_shader.h:273
@ VKD3D_SHADER_COMPILE_OPTION_INCLUDE_EMPTY_BUFFERS_IN_EFFECTS
Definition: vkd3d_shader.h:360
VKD3D_SHADER_API void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code)
@ VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES
Definition: vkd3d_shader.h:193
@ VKD3D_SHADER_SOURCE_HLSL
VKD3D_SHADER_API int vkd3d_shader_serialize_dxbc(size_t section_count, const struct vkd3d_shader_dxbc_section_desc *sections, struct vkd3d_shader_code *dxbc, char **messages)
Definition: dxbc.c:53
@ VKD3D_SHADER_LOG_INFO
@ VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO
Definition: vkd3d_shader.h:68
@ VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO
Definition: vkd3d_shader.h:89
@ VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO
Definition: vkd3d_shader.h:84
@ VKD3D_SHADER_API_VERSION_1_3
Definition: vkd3d_shader.h:48
VKD3D_SHADER_API int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages)
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR
Definition: vkd3d_shader.h:174
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR
Definition: vkd3d_shader.h:173
VKD3D_SHADER_API void vkd3d_shader_free_messages(char *messages)

Referenced by D3DCompile().

◆ D3DCompileFromFile()

HRESULT WINAPI D3DCompileFromFile ( const WCHAR *  filename,
const D3D_SHADER_MACRO *  defines,
ID3DInclude *  include,
const char *  entrypoint,
const char *  target,
UINT  flags1,
UINT  flags2,
ID3DBlob **  code,
ID3DBlob **  errors 
)

Definition at line 743 of file compiler.c.

745{
746 char filename_a[MAX_PATH], *source = NULL;
747 DWORD source_size, read_size;
748 HANDLE file;
749 HRESULT hr;
750
751 TRACE("filename %s, defines %p, include %p, entrypoint %s, target %s, flags1 %#x, flags2 %#x, "
752 "code %p, errors %p.\n", debugstr_w(filename), defines, include, debugstr_a(entrypoint),
753 debugstr_a(target), flags1, flags2, code, errors);
754
758
759 source_size = GetFileSize(file, NULL);
760 if (source_size == INVALID_FILE_SIZE)
761 {
763 goto end;
764 }
765
766 if (!(source = malloc(source_size)))
767 {
769 goto end;
770 }
771
772 if (!ReadFile(file, source, source_size, &read_size, NULL) || read_size != source_size)
773 {
774 WARN("Failed to read file contents.\n");
775 hr = E_FAIL;
776 goto end;
777 }
778
779 WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, sizeof(filename_a), NULL, NULL);
780
781 hr = D3DCompile(source, source_size, filename_a, defines, include, entrypoint, target,
782 flags1, flags2, code, errors);
783
784end:
785 free(source);
787 return hr;
788}
#define WARN(fmt,...)
Definition: precomp.h:61
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:639
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define WideCharToMultiByte
Definition: compat.h:111
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint end
Definition: gl.h:1545
#define debugstr_w
Definition: kernel32.h:32
Definition: fci.c:123
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define INVALID_FILE_SIZE
Definition: winbase.h:528
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by D3DX11CompileFromFileW(), and test_include().

◆ d3dcompiler_include_from_file_close()

static HRESULT WINAPI d3dcompiler_include_from_file_close ( ID3DInclude *  iface,
const void *  data 
)
static

Definition at line 137 of file compiler.c.

138{
139 free((void *)data);
140 return S_OK;
141}

◆ d3dcompiler_include_from_file_open()

static HRESULT WINAPI d3dcompiler_include_from_file_open ( ID3DInclude *  iface,
D3D_INCLUDE_TYPE  include_type,
const char *  filename,
const void *  parent_data,
const void **  data,
UINT *  bytes 
)
static

Definition at line 78 of file compiler.c.

80{
82 char *fullpath, *buffer = NULL, current_dir[MAX_PATH + 1];
83 const char *initial_dir;
86 ULONG read;
87 DWORD len;
88
89 if ((initial_dir = strrchr(include->initial_filename, '\\')))
90 {
91 len = initial_dir - include->initial_filename + 1;
92 initial_dir = include->initial_filename;
93 }
94 else
95 {
96 len = GetCurrentDirectoryA(MAX_PATH, current_dir);
97 current_dir[len] = '\\';
98 len++;
99 initial_dir = current_dir;
100 }
101 fullpath = malloc(len + strlen(filename) + 1);
102 if (!fullpath)
103 return E_OUTOFMEMORY;
104 memcpy(fullpath, initial_dir, len);
105 strcpy(fullpath + len, filename);
106
109 goto error;
110
111 TRACE("Include file found at %s.\n", debugstr_a(fullpath));
112
114 if (size == INVALID_FILE_SIZE)
115 goto error;
116 buffer = malloc(size);
117 if (!buffer)
118 goto error;
119 if (!ReadFile(file, buffer, size, &read, NULL) || read != size)
120 goto error;
121
122 *bytes = size;
123 *data = buffer;
124
125 free(fullpath);
127 return S_OK;
128
129error:
130 free(fullpath);
131 free(buffer);
133 WARN("Returning E_FAIL.\n");
134 return E_FAIL;
135}
#define read
Definition: acwin.h:97
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static struct d3dcompiler_include_from_file * impl_from_ID3DInclude(ID3DInclude *iface)
Definition: compiler.c:73
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2164
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3303
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
strcpy
Definition: string.h:131
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59

◆ D3DCreateLinker()

HRESULT WINAPI D3DCreateLinker ( ID3D11Linker **  linker)

Definition at line 790 of file compiler.c.

791{
792 FIXME("linker %p stub!\n", linker);
793 return E_NOTIMPL;
794}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ D3DDisassemble()

HRESULT WINAPI D3DDisassemble ( const void *  data,
SIZE_T  size,
UINT  flags,
const char *  comments,
ID3DBlob **  disassembly 
)

Definition at line 668 of file compiler.c.

670{
671 struct vkd3d_shader_compile_info compile_info;
673 struct vkd3d_shader_code asm_code;
674 const char *ptr = data;
675 char *messages;
676 HRESULT hr;
677 int ret;
678
679 TRACE("data %p, size %Iu, flags %#x, comments %p, disassembly %p.\n",
680 data, size, flags, comments, disassembly);
681
682 if (flags)
683 FIXME("Ignoring flags %#x.\n", flags);
684
685 if (comments)
686 FIXME("Ignoring comments %s.\n", debugstr_a(comments));
687
688#if D3D_COMPILER_VERSION >= 46
689 if (!size)
690 return E_INVALIDARG;
691#endif
692
693 if (size >= 4 && read_u32(&ptr) == TAG_DXBC)
694 source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
695 else
697
699 compile_info.next = NULL;
700 compile_info.source.code = data;
701 compile_info.source.size = size;
702 compile_info.source_type = source_type;
703 compile_info.target_type = VKD3D_SHADER_TARGET_D3D_ASM;
704 compile_info.options = NULL;
705 compile_info.option_count = 0;
706 compile_info.log_level = VKD3D_SHADER_LOG_INFO;
707 compile_info.source_name = NULL;
708
709 ret = vkd3d_shader_compile(&compile_info, &asm_code, &messages);
710
711 if (ret)
712 ERR("Failed to disassemble shader, vkd3d result %d.\n", ret);
713
714 if (messages)
715 {
716 if (*messages && ERR_ON(d3dcompiler))
717 {
718 const char *ptr = messages;
719 const char *line;
720
721 ERR("Shader log:\n");
722 while ((line = get_line(&ptr)))
723 {
724 ERR(" %.*s", (int)(ptr - line), line);
725 }
726 ERR("\n");
727 }
728
730 }
731
732 if (ret)
734
735 if (SUCCEEDED(hr = D3DCreateBlob(asm_code.size, disassembly)))
736 memcpy(ID3D10Blob_GetBufferPointer(*disassembly), asm_code.code, asm_code.size);
737
739
740 return hr;
741}
#define TAG_DXBC
#define E_INVALIDARG
Definition: ddrawi.h:101
char comments[4096]
static uint32_t read_u32(const char **ptr)
Definition: utils.h:24
enum vkd3d_shader_source_type source_type
vkd3d_shader_source_type
@ VKD3D_SHADER_SOURCE_D3D_BYTECODE
@ VKD3D_SHADER_SOURCE_DXBC_TPF
@ VKD3D_SHADER_TARGET_D3D_ASM

Referenced by D3DXDisassembleShader(), and test_disassemble_shader().

◆ D3DLoadModule()

HRESULT WINAPI D3DLoadModule ( const void *  data,
SIZE_T  size,
ID3D11Module **  module 
)

Definition at line 796 of file compiler.c.

797{
798 FIXME("data %p, size %Iu, module %p stub!\n", data, size, module);
799 return E_NOTIMPL;
800}

◆ D3DPreprocess()

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 at line 652 of file compiler.c.

655{
656 TRACE("data %p, size %Iu, filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
658
659 if (!data)
660 return E_INVALIDARG;
661
662 if (shader) *shader = NULL;
664
666}

Referenced by call_D3DPreprocess(), d3dpreprocess_test(), D3DX10PreprocessShaderFromMemory(), D3DXPreprocessShader(), and D3DXPreprocessShaderFromFileW().

◆ get_line()

static const char * get_line ( const char **  ptr)
static

Definition at line 174 of file compiler.c.

175{
176 const char *p, *q;
177
178 p = *ptr;
179 if (!(q = strstr(p, "\n")))
180 {
181 if (!*p)
182 return NULL;
183 *ptr += strlen(p);
184 return p;
185 }
186 *ptr = q + 1;
187
188 return p;
189}
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902

◆ get_target_for_profile()

static enum vkd3d_shader_target_type get_target_for_profile ( const char *  profile)
static

Definition at line 400 of file compiler.c.

401{
402 size_t profile_len, i;
403
404 static const char * const d3dbc_profiles[] =
405 {
406 "ps.1.",
407 "ps.2.",
408 "ps.3.",
409
410 "ps_1_",
411 "ps_2_",
412 "ps_3_",
413
414 "vs.1.",
415 "vs.2.",
416 "vs.3.",
417
418 "vs_1_",
419 "vs_2_",
420 "vs_3_",
421
422 "tx_1_",
423 };
424
425 static const char * const fx_profiles[] =
426 {
427 "fx_2_0",
428 "fx_4_0",
429 "fx_4_1",
430 "fx_5_0",
431 };
432
433 profile_len = strlen(profile);
434 for (i = 0; i < ARRAY_SIZE(d3dbc_profiles); ++i)
435 {
436 size_t len = strlen(d3dbc_profiles[i]);
437
438 if (len <= profile_len && !memcmp(profile, d3dbc_profiles[i], len))
440 }
441
442 for (i = 0; i < ARRAY_SIZE(fx_profiles); ++i)
443 {
444 if (!strcmp(profile, fx_profiles[i]))
446 }
447
449}
#define ARRAY_SIZE(A)
Definition: main.h:20
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
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
@ VKD3D_SHADER_TARGET_DXBC_TPF
@ VKD3D_SHADER_TARGET_D3D_BYTECODE
@ VKD3D_SHADER_TARGET_FX

Referenced by D3DCompile2().

◆ hresult_from_vkd3d_result()

static HRESULT hresult_from_vkd3d_result ( int  vkd3d_result)
static

Definition at line 30 of file compiler.c.

31{
32 switch (vkd3d_result)
33 {
34 case VKD3D_OK:
35 return S_OK;
37 WARN("Invalid shader bytecode.\n");
38 /* fall-through */
39 case VKD3D_ERROR:
40 return E_FAIL;
42 return E_OUTOFMEMORY;
44 return E_INVALIDARG;
46 return E_NOTIMPL;
47 default:
48 FIXME("Unhandled vkd3d result %d.\n", vkd3d_result);
49 return E_FAIL;
50 }
51}
vkd3d_result
Definition: vkd3d_types.h:41
@ VKD3D_ERROR_INVALID_ARGUMENT
Definition: vkd3d_types.h:51
@ VKD3D_ERROR_NOT_IMPLEMENTED
Definition: vkd3d_types.h:55
@ VKD3D_ERROR_INVALID_SHADER
Definition: vkd3d_types.h:53
@ VKD3D_ERROR
Definition: vkd3d_types.h:47
@ VKD3D_OK
Definition: vkd3d_types.h:43
@ VKD3D_ERROR_OUT_OF_MEMORY
Definition: vkd3d_types.h:49

Referenced by create_shader_stage(), d3d12_cache_session_FindValue(), d3d12_cache_session_init(), d3d12_cache_session_StoreValue(), d3d12_pipeline_state_find_and_init_uav_counters(), d3d12_pipeline_state_init_graphics(), d3d12_root_signature_create(), d3d12_root_signature_deserializer_init(), d3d12_versioned_root_signature_deserializer_GetRootSignatureDescAtVersion(), d3d12_versioned_root_signature_deserializer_init(), D3DCompile2(), D3DDisassemble(), preprocess_shader(), vkd3d_serialize_root_signature(), and vkd3d_serialize_versioned_root_signature().

◆ impl_from_ID3DInclude()

static struct d3dcompiler_include_from_file * impl_from_ID3DInclude ( ID3DInclude *  iface)
inlinestatic

Definition at line 73 of file compiler.c.

74{
75 return CONTAINING_RECORD(iface, struct d3dcompiler_include_from_file, ID3DInclude_iface);
76}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by d3dcompiler_include_from_file_open().

◆ open_include()

static int open_include ( const char *  filename,
bool  local,
const char *  parent_data,
void *  context,
struct vkd3d_shader_code *  code 
)
static

Definition at line 149 of file compiler.c.

151{
152 ID3DInclude *iface = context;
153 unsigned int size = 0;
154
155 if (!iface)
156 return VKD3D_ERROR;
157
158 memset(code, 0, sizeof(*code));
159 if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
160 filename, parent_data, &code->code, &size)))
161 return VKD3D_ERROR;
162
163 code->size = size;
164 return VKD3D_OK;
165}
#define local
Definition: zutil.h:30
#define memset(x, y, z)
Definition: compat.h:39

Referenced by D3DCompile2(), and preprocess_shader().

◆ preprocess_shader()

static HRESULT preprocess_shader ( const void *  data,
SIZE_T  data_size,
const char *  filename,
const D3D_SHADER_MACRO *  defines,
ID3DInclude *  include,
ID3DBlob **  shader_blob,
ID3DBlob **  messages_blob 
)
static

Definition at line 191 of file compiler.c.

194{
195 struct d3dcompiler_include_from_file include_from_file;
196 struct vkd3d_shader_preprocess_info preprocess_info;
197 struct vkd3d_shader_compile_info compile_info;
198 const D3D_SHADER_MACRO *def = defines;
199 struct vkd3d_shader_code byte_code;
200 char *messages;
201 HRESULT hr;
202 int ret;
203
205 {
206 include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
207 include_from_file.initial_filename = filename ? filename : "";
208 include = &include_from_file.ID3DInclude_iface;
209 }
210
212 compile_info.next = &preprocess_info;
213 compile_info.source.code = data;
214 compile_info.source.size = data_size;
215 compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
216 compile_info.target_type = VKD3D_SHADER_TARGET_NONE;
217 compile_info.options = NULL;
218 compile_info.option_count = 0;
219 compile_info.log_level = VKD3D_SHADER_LOG_INFO;
220 compile_info.source_name = filename;
221
222 preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
223 preprocess_info.next = NULL;
224 preprocess_info.macros = (const struct vkd3d_shader_macro *)defines;
225 preprocess_info.macro_count = 0;
226 if (defines)
227 {
228 for (def = defines; def->Name; ++def)
229 ++preprocess_info.macro_count;
230 }
231 preprocess_info.pfn_open_include = open_include;
232 preprocess_info.pfn_close_include = close_include;
233 preprocess_info.include_context = include;
234
235 ret = vkd3d_shader_preprocess(&compile_info, &byte_code, &messages);
236
237 if (ret)
238 ERR("Failed to preprocess shader, vkd3d result %d.\n", ret);
239
240 if (messages)
241 {
242 if (*messages && ERR_ON(d3dcompiler))
243 {
244 const char *ptr = messages;
245 const char *line;
246
247 ERR("Shader log:\n");
248 while ((line = get_line(&ptr)))
249 {
250 ERR(" %.*s", (int)(ptr - line), line);
251 }
252 ERR("\n");
253 }
254
255 if (messages_blob)
256 {
257 size_t size = strlen(messages);
258 if (FAILED(hr = D3DCreateBlob(size, messages_blob)))
259 {
262 return hr;
263 }
264 memcpy(ID3D10Blob_GetBufferPointer(*messages_blob), messages, size);
265 }
266 else
267 {
269 }
270 }
271
272 if (!ret)
273 {
274 if (FAILED(hr = D3DCreateBlob(byte_code.size, shader_blob)))
275 {
277 return hr;
278 }
279 memcpy(ID3D10Blob_GetBufferPointer(*shader_blob), byte_code.code, byte_code.size);
280 }
281
283}
const char * Name
Definition: d3dcommon.idl:24
VKD3D_SHADER_API int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages)
@ VKD3D_SHADER_TARGET_NONE

Referenced by D3DAssemble(), and D3DPreprocess().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3dcompiler  )

Variable Documentation

◆ d3dcompiler_include_from_file_vtbl

const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl
Initial value:
=
{
}
static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data, UINT *bytes)
Definition: compiler.c:78
static HRESULT WINAPI d3dcompiler_include_from_file_close(ID3DInclude *iface, const void *data)
Definition: compiler.c:137

Definition at line 143 of file compiler.c.

Referenced by D3DCompile2(), and preprocess_shader().

◆ wpp_mutex

static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 }
static

Definition at line 57 of file compiler.c.

Referenced by D3DAssemble().

◆ wpp_mutex_debug

CRITICAL_SECTION_DEBUG wpp_mutex_debug
static
Initial value:
=
{
0, 0, &wpp_mutex,
0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") }
}
static CRITICAL_SECTION_DEBUG wpp_mutex_debug
Definition: compiler.c:58
#define DWORD_PTR
Definition: treelist.c:76

Definition at line 58 of file compiler.c.