ReactOS 0.4.15-dev-7931-gfd331f1
compiler.c File Reference
#include <stdarg.h>
#include <time.h>
#include "wine/debug.h"
#include "d3dcompiler_private.h"
#include "wpp_private.h"
Include dependency graph for compiler.c:

Go to the source code of this file.

Classes

struct  mem_file_desc
 
struct  loaded_include
 
struct  define
 
struct  target_info
 

Macros

#define COBJMACROS
 
#define D3DXERR_INVALIDDATA   0x88760b59
 
#define BUFFER_INITIAL_CAPACITY   256
 
#define INCLUDES_INITIAL_CAPACITY   4
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3dcompiler)
 
static void wpp_write_message (const char *fmt, __ms_va_list args)
 
static void WINAPIV PRINTF_ATTR (1, 2)
 
int WINAPIV ppy_error (const char *msg,...)
 
int WINAPIV ppy_warning (const char *msg,...)
 
charwpp_lookup (const char *filename, int type, const char *parent_name)
 
voidwpp_open (const char *filename, int type)
 
void wpp_close (void *file)
 
int wpp_read (void *file, char *buffer, unsigned int len)
 
void wpp_write (const char *buffer, unsigned int len)
 
static int wpp_close_output (void)
 
static void add_cmdline_defines (void)
 
static void del_cmdline_defines (void)
 
static void add_special_defines (void)
 
static void del_special_defines (void)
 
int wpp_add_define (const char *name, const char *value)
 
void wpp_del_define (const char *name)
 
int wpp_parse (const char *input, FILE *output)
 
static HRESULT preprocess_shader (const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
 
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 const struct target_infoget_target_info (const char *target)
 
static HRESULT compile_shader (const char *preproc_shader, const char *target, const char *entrypoint, ID3DBlob **shader_blob, ID3DBlob **error_messages)
 
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)
 
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 *includes, const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
 
HRESULT WINAPI D3DLoadModule (const void *data, SIZE_T size, ID3D11Module **module)
 

Variables

static struct mem_file_desc current_shader
 
static ID3DIncludecurrent_include
 
static const charinitial_filename
 
static struct loaded_includeincludes
 
static int includes_capacity
 
static int includes_size
 
static const charparent_include
 
static charwpp_output
 
static int wpp_output_capacity
 
static int wpp_output_size
 
static charwpp_messages
 
static int wpp_messages_capacity
 
static int wpp_messages_size
 
static struct definecmdline_defines
 
static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG wpp_mutex_debug
 
static const struct target_info targets_info []
 

Macro Definition Documentation

◆ BUFFER_INITIAL_CAPACITY

#define BUFFER_INITIAL_CAPACITY   256

Definition at line 32 of file compiler.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 20 of file compiler.c.

◆ D3DXERR_INVALIDDATA

#define D3DXERR_INVALIDDATA   0x88760b59

Definition at line 30 of file compiler.c.

◆ INCLUDES_INITIAL_CAPACITY

#define INCLUDES_INITIAL_CAPACITY   4

Definition at line 45 of file compiler.c.

Function Documentation

◆ add_cmdline_defines()

static void add_cmdline_defines ( void  )
static

Definition at line 326 of file compiler.c.

327{
328 struct define *def;
329
330 for (def = cmdline_defines; def; def = def->next)
331 {
332 if (def->value) pp_add_define( def->name, def->value );
333 }
334}
static struct define * cmdline_defines
Definition: compiler.c:70
pp_entry_t * pp_add_define(const char *def, const char *text)
Definition: preproc.c:194
struct define * next
Definition: compiler.c:65
char * value
Definition: compiler.c:67
char * name
Definition: compiler.c:66

Referenced by wpp_parse().

◆ add_special_defines()

static void add_special_defines ( void  )
static

Definition at line 346 of file compiler.c.

347{
348 time_t now = time(NULL);
349 pp_entry_t *ppp;
350 char buf[32];
351
352 strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
353 pp_add_define( "__DATE__", buf );
354
355 strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
356 pp_add_define( "__TIME__", buf );
357
358 ppp = pp_add_define( "__FILE__", "" );
359 if(ppp)
360 ppp->type = def_special;
361
362 ppp = pp_add_define( "__LINE__", "" );
363 if(ppp)
364 ppp->type = def_special;
365}
#define NULL
Definition: types.h:112
@ def_special
Definition: wpp_private.h:92
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
__u16 time
Definition: mkdosfs.c:8
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
size_t CDECL strftime(char *str, size_t max, const char *format, const struct tm *mstm)
Definition: strftime.c:293
Definition: wpp_private.h:95
def_type_t type
Definition: wpp_private.h:98

Referenced by wpp_parse().

◆ assemble_shader()

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

Definition at line 553 of file compiler.c.

555{
556 struct bwriter_shader *shader;
557 char *messages = NULL;
558 HRESULT hr;
559 DWORD *res, size;
561 char *pos;
562
563 shader = SlAssembleShader(preproc_shader, &messages);
564
565 if (messages)
566 {
567 TRACE("Assembler messages:\n");
568 TRACE("%s\n", debugstr_a(messages));
569
570 TRACE("Shader source:\n");
571 TRACE("%s\n", debugstr_a(preproc_shader));
572
573 if (error_messages)
574 {
575 const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
576
577 size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
579 if (FAILED(hr))
580 {
583 return hr;
584 }
585 pos = ID3D10Blob_GetBufferPointer(buffer);
586 if (preproc_messages)
587 {
588 CopyMemory(pos, preproc_messages, strlen(preproc_messages) + 1);
589 pos += strlen(preproc_messages);
590 }
592
593 if (*error_messages) ID3D10Blob_Release(*error_messages);
595 }
597 }
598
599 if (shader == NULL)
600 {
601 ERR("Asm reading failed\n");
602 return D3DXERR_INVALIDDATA;
603 }
604
605 hr = SlWriteBytecode(shader, 9, &res, &size);
607 if (FAILED(hr))
608 {
609 ERR("SlWriteBytecode failed with 0x%08x\n", hr);
610 return D3DXERR_INVALIDDATA;
611 }
612
613 if (shader_blob)
614 {
616 if (FAILED(hr))
617 {
619 return hr;
620 }
621 CopyMemory(ID3D10Blob_GetBufferPointer(buffer), res, size);
622 *shader_blob = buffer;
623 }
624
626
627 return S_OK;
628}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERR(fmt,...)
Definition: debug.h:110
HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size)
void SlDeleteShader(struct bwriter_shader *shader)
#define D3DXERR_INVALIDDATA
Definition: compiler.c:30
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT ID3DBlob ID3DBlob ** error_messages
Definition: asm.c:32
struct bwriter_shader * SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN
HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob)
Definition: blob.c:133
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
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
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
#define CopyMemory
Definition: winbase.h:1710

Referenced by D3DAssemble().

◆ compile_shader()

static HRESULT compile_shader ( const char preproc_shader,
const char target,
const char entrypoint,
ID3DBlob **  shader_blob,
ID3DBlob **  error_messages 
)
static

Definition at line 754 of file compiler.c.

756{
757 struct bwriter_shader *shader;
758 char *messages = NULL;
759 HRESULT hr;
762 char *pos;
764 const struct target_info *info;
765
766 TRACE("Preprocessed shader source: %s\n", debugstr_a(preproc_shader));
767
768 TRACE("Checking compilation target %s\n", debugstr_a(target));
770 if (!info)
771 {
772 FIXME("Unknown compilation target %s\n", debugstr_a(target));
773 return D3DERR_INVALIDCALL;
774 }
775 else
776 {
777 if (!info->support)
778 {
779 FIXME("Compilation target %s not yet supported\n", debugstr_a(target));
780 return D3DERR_INVALIDCALL;
781 }
782 else
783 {
784 shader_type = info->type;
785 major = info->sm_major;
786 minor = info->sm_minor;
787 }
788 }
789
790 shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
791
792 if (messages)
793 {
794 TRACE("Compiler messages:\n");
795 TRACE("%s\n", debugstr_a(messages));
796
797 TRACE("Shader source:\n");
798 TRACE("%s\n", debugstr_a(preproc_shader));
799
800 if (error_messages)
801 {
802 const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
803
804 size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
806 if (FAILED(hr))
807 {
810 return hr;
811 }
812 pos = ID3D10Blob_GetBufferPointer(buffer);
813 if (preproc_messages)
814 {
815 memcpy(pos, preproc_messages, strlen(preproc_messages) + 1);
816 pos += strlen(preproc_messages);
817 }
819
820 if (*error_messages) ID3D10Blob_Release(*error_messages);
822 }
824 }
825
826 if (!shader)
827 {
828 ERR("HLSL shader parsing failed.\n");
829 return D3DXERR_INVALIDDATA;
830 }
831
832 hr = SlWriteBytecode(shader, 9, &res, &size);
834 if (FAILED(hr))
835 {
836 ERR("SlWriteBytecode failed with error 0x%08x.\n", hr);
837 return D3DXERR_INVALIDDATA;
838 }
839
840 if (shader_blob)
841 {
843 if (FAILED(hr))
844 {
846 return hr;
847 }
848 memcpy(ID3D10Blob_GetBufferPointer(buffer), res, size);
849 *shader_blob = buffer;
850 }
851
853
854 return S_OK;
855}
#define FIXME(fmt,...)
Definition: debug.h:111
static const struct target_info * get_target_info(const char *target)
Definition: compiler.c:732
struct bwriter_shader * parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, const char *entrypoint, char **messages) DECLSPEC_HIDDEN
#define D3DERR_INVALIDCALL
GLenum target
Definition: glext.h:7315
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define minor(rdev)
Definition: propsheet.cpp:929
#define major(rdev)
Definition: propsheet.cpp:928

Referenced by D3DCompile2().

◆ 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 630 of file compiler.c.

633{
634 HRESULT hr;
635
636 TRACE("data %p, datasize %lu, filename %s, defines %p, include %p, sflags %#x, "
637 "shader %p, error_messages %p.\n",
639
641
642 /* TODO: flags */
643 if (flags) FIXME("flags %x\n", flags);
644
645 if (shader) *shader = NULL;
647
649 if (SUCCEEDED(hr))
651
654 return hr;
655}
static CRITICAL_SECTION wpp_mutex
Definition: compiler.c:75
static char * wpp_output
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 **error_messages)
Definition: compiler.c:484
static HRESULT assemble_shader(const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
Definition: compiler.c:553
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
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
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by D3DXAssembleShader().

◆ 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 889 of file compiler.c.

892{
893 TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
894 "target %s, sflags %#x, eflags %#x, shader %p, error_messages %p.\n",
895 data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
897
898 return D3DCompile2(data, data_size, filename, defines, include, entrypoint, target, sflags,
900}
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:857

Referenced by d3dx9_effect_init(), D3DXCompileShader(), and D3DXCompileShaderFromFileW().

◆ D3DCompile2()

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

862{
863 HRESULT hr;
864
865 TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
866 "target %s, sflags %#x, eflags %#x, secondary_flags %#x, secondary_data %p, "
867 "secondary_data_size %lu, shader %p, error_messages %p.\n",
868 data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
869 debugstr_a(target), sflags, eflags, secondary_flags, secondary_data,
870 secondary_data_size, shader, error_messages);
871
872 if (secondary_data)
873 FIXME("secondary data not implemented yet\n");
874
875 if (shader) *shader = NULL;
877
879
881 if (SUCCEEDED(hr))
883
886 return hr;
887}
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint, ID3DBlob **shader_blob, ID3DBlob **error_messages)
Definition: compiler.c:754

Referenced by D3DCompile().

◆ D3DCompileFromFile()

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

951{
952 FIXME("filename %s, defines %p, includes %p, entrypoint %s, target %s, flags1 %x, flags2 %x, code %p, errors %p\n",
953 debugstr_w(filename), defines, includes, debugstr_a(entrypoint), debugstr_a(target), flags1, flags2, code, errors);
954
955 return E_NOTIMPL;
956}
static struct loaded_include * includes
Definition: compiler.c:53
#define E_NOTIMPL
Definition: ddrawi.h:99
#define debugstr_w
Definition: kernel32.h:32
Definition: inflate.c:139

◆ D3DDisassemble()

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

Definition at line 942 of file compiler.c.

943{
944 FIXME("data %p, size %lu, flags %#x, comments %p, disassembly %p stub!\n",
945 data, size, flags, comments, disassembly);
946 return E_NOTIMPL;
947}
char comments[4096]

◆ D3DLoadModule()

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

Definition at line 959 of file compiler.c.

960{
961 FIXME("data %p, size %lu, module %p stub!\n", data, size, module);
962 return E_NOTIMPL;
963}

◆ 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 902 of file compiler.c.

905{
906 HRESULT hr;
908
909 TRACE("data %p, size %lu, filename %s, defines %p, include %p, shader %p, error_messages %p\n",
911
912 if (!data)
913 return E_INVALIDARG;
914
916
917 if (shader) *shader = NULL;
919
921
922 if (SUCCEEDED(hr))
923 {
924 if (shader)
925 {
927 if (FAILED(hr))
928 goto cleanup;
929 CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size);
930 *shader = buffer;
931 }
932 else
934 }
935
936cleanup:
939 return hr;
940}
static int wpp_output_size
Definition: compiler.c:58
#define E_INVALIDARG
Definition: ddrawi.h:101
static void cleanup(void)
Definition: main.c:1335

Referenced by D3DXPreprocessShader(), and D3DXPreprocessShaderFromFileW().

◆ del_cmdline_defines()

static void del_cmdline_defines ( void  )
static

Definition at line 336 of file compiler.c.

337{
338 struct define *def;
339
340 for (def = cmdline_defines; def; def = def->next)
341 {
342 if (def->value) pp_del_define( def->name );
343 }
344}
void pp_del_define(const char *name)
Definition: preproc.c:176

Referenced by wpp_parse().

◆ del_special_defines()

static void del_special_defines ( void  )
static

Definition at line 367 of file compiler.c.

368{
369 pp_del_define( "__DATE__" );
370 pp_del_define( "__TIME__" );
371 pp_del_define( "__FILE__" );
372 pp_del_define( "__LINE__" );
373}

Referenced by wpp_parse().

◆ get_target_info()

static const struct target_info * get_target_info ( const char target)
static

Definition at line 732 of file compiler.c.

733{
734 LONG min = 0;
736 LONG cur;
737 int res;
738
739 while (min <= max)
740 {
741 cur = (min + max) / 2;
743 if (res < 0)
744 max = cur - 1;
745 else if (res > 0)
746 min = cur + 1;
747 else
748 return &targets_info[cur];
749 }
750
751 return NULL;
752}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ARRAY_SIZE(A)
Definition: main.h:33
static const struct target_info targets_info[]
Definition: compiler.c:669
FxCollectionEntry * cur
#define min(a, b)
Definition: monoChain.cc:55
long LONG
Definition: pedump.c:60
Definition: name.c:39
#define max(a, b)
Definition: svc.c:63

Referenced by compile_shader().

◆ ppy_error()

int WINAPIV ppy_error ( const char msg,
  ... 
)

Definition at line 135 of file compiler.c.

136{
139 wpp_write_message_var("%s:%d:%d: %s: ",
140 pp_status.input ? pp_status.input : "'main file'",
143 wpp_write_message_var("\n");
145 pp_status.state = 1;
146 return 1;
147}
#define msg(x)
Definition: auth_time.c:54
static void wpp_write_message(const char *fmt, __ms_va_list args)
Definition: compiler.c:86
int char_number
Definition: wpp_private.h:223
char * input
Definition: wpp_private.h:220
int line_number
Definition: wpp_private.h:222
#define __ms_va_list
Definition: windef.h:456
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by pp_pop_if(), and wpp_parse().

◆ ppy_warning()

int WINAPIV ppy_warning ( const char msg,
  ... 
)

Definition at line 149 of file compiler.c.

150{
153 wpp_write_message_var("%s:%d:%d: %s: ",
154 pp_status.input ? pp_status.input : "'main file'",
157 wpp_write_message_var("\n");
159 return 0;
160}

Referenced by pp_add_define(), pp_add_macro(), and pp_del_define().

◆ preprocess_shader()

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

Definition at line 484 of file compiler.c.

486{
487 int ret;
488 HRESULT hr = S_OK;
489 const D3D_SHADER_MACRO *def = defines;
490
491 if (def != NULL)
492 {
493 while (def->Name != NULL)
494 {
495 wpp_add_define(def->Name, def->Definition);
496 def++;
497 }
498 }
500 includes_size = 0;
501
504
507 current_shader.buffer = data;
508 current_shader.size = data_size;
510
512 if (!wpp_close_output())
513 ret = 1;
514 if (ret)
515 {
516 TRACE("Error during shader preprocessing\n");
517 if (wpp_messages)
518 {
519 int size;
521
522 TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages));
523
524 if (error_messages)
525 {
526 size = strlen(wpp_messages) + 1;
528 if (FAILED(hr))
529 goto cleanup;
530 CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size);
532 }
533 }
534 if (data)
535 TRACE("Shader source:\n%s\n", debugstr_an(data, data_size));
536 hr = E_FAIL;
537 }
538
539cleanup:
540 /* Remove the previously added defines */
541 if (defines != NULL)
542 {
543 while (defines->Name != NULL)
544 {
546 defines++;
547 }
548 }
550 return hr;
551}
static int wpp_output_capacity
Definition: compiler.c:58
static int wpp_close_output(void)
Definition: compiler.c:315
static char * wpp_messages
Definition: compiler.c:60
static int wpp_messages_capacity
Definition: compiler.c:61
static int wpp_messages_size
Definition: compiler.c:61
int wpp_add_define(const char *name, const char *value)
Definition: compiler.c:377
void wpp_del_define(const char *name)
Definition: compiler.c:420
int wpp_parse(const char *input, FILE *output)
Definition: compiler.c:437
static ID3DInclude * current_include
Definition: compiler.c:42
static const char * initial_filename
Definition: compiler.c:43
static struct mem_file_desc current_shader
Definition: compiler.c:41
static int includes_size
Definition: compiler.c:54
#define E_FAIL
Definition: ddrawi.h:102
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
const char * Name
Definition: d3dcommon.idl:24
const char * Definition
Definition: d3dcommon.idl:25
int ret

Referenced by D3DAssemble(), D3DCompile2(), and D3DPreprocess().

◆ PRINTF_ATTR()

static void WINAPIV PRINTF_ATTR ( ,
 
)
static

Definition at line 126 of file compiler.c.

127{
129
133}
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3dcompiler  )

◆ wpp_add_define()

int wpp_add_define ( const char name,
const char value 
)

Definition at line 377 of file compiler.c.

378{
379 struct define *def;
380
381 if (!value) value = "";
382
383 for (def = cmdline_defines; def; def = def->next)
384 {
385 if (!strcmp( def->name, name ))
386 {
387 char *new_value = pp_xstrdup(value);
388 if(!new_value)
389 return 1;
390 free( def->value );
391 def->value = new_value;
392
393 return 0;
394 }
395 }
396
397 def = pp_xmalloc( sizeof(*def) );
398 if(!def)
399 return 1;
400 def->next = cmdline_defines;
401 def->name = pp_xstrdup(name);
402 if(!def->name)
403 {
404 free(def);
405 return 1;
406 }
407 def->value = pp_xstrdup(value);
408 if(!def->value)
409 {
410 free(def->name);
411 free(def);
412 return 1;
413 }
414 cmdline_defines = def;
415 return 0;
416}
#define free
Definition: debug_ros.c:5
char * pp_xstrdup(const char *str)
Definition: preproc.c:73
void * pp_xmalloc(size_t size)
Definition: preproc.c:45
Definition: pdh_main.c:94

Referenced by add_widl_version_define(), main(), and preprocess_shader().

◆ wpp_close()

void wpp_close ( void file)

Definition at line 258 of file compiler.c.

259{
260 struct mem_file_desc *desc = file;
261
262 if(desc != &current_shader)
263 {
265 ID3DInclude_Close(current_include, desc->buffer);
266 else
267 ERR("current_include == NULL, desc == %p, buffer = %s\n",
268 desc, desc->buffer);
269
271 }
272}
static const WCHAR desc[]
Definition: protectdata.c:36
Definition: fci.c:127

Referenced by wpp_parse().

◆ wpp_close_output()

static int wpp_close_output ( void  )
static

Definition at line 315 of file compiler.c.

316{
317 char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
318 wpp_output_size + 1);
319 if(!new_wpp_output) return 0;
320 wpp_output = new_wpp_output;
323 return 1;
324}
#define HeapReAlloc
Definition: compat.h:734

Referenced by preprocess_shader().

◆ wpp_del_define()

void wpp_del_define ( const char name)

Definition at line 420 of file compiler.c.

421{
422 struct define *def;
423
424 for (def = cmdline_defines; def; def = def->next)
425 {
426 if (!strcmp( def->name, name ))
427 {
428 free( def->value );
429 def->value = NULL;
430 return;
431 }
432 }
433}

Referenced by preprocess_shader().

◆ wpp_lookup()

char * wpp_lookup ( const char filename,
int  type,
const char parent_name 
)

Definition at line 162 of file compiler.c.

163{
164 /* We don't check for file existence here. We will potentially fail on
165 * the following wpp_open_mem(). */
166 char *path;
167 int i;
168
169 TRACE("Looking for include %s, parent %s.\n", debugstr_a(filename), debugstr_a(parent_name));
170
172 if (strcmp(parent_name, initial_filename))
173 {
174 for(i = 0; i < includes_size; i++)
175 {
176 if(!strcmp(parent_name, includes[i].name))
177 {
178 parent_include = includes[i].data;
179 break;
180 }
181 }
182 if(parent_include == NULL)
183 {
184 ERR("Parent include %s missing.\n", debugstr_a(parent_name));
185 return NULL;
186 }
187 }
188
189 path = malloc(strlen(filename) + 1);
190 if(path)
192 return path;
193}
static const char * parent_include
Definition: compiler.c:55
#define malloc
Definition: debug_ros.c:4
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

Referenced by pp_open_include().

◆ wpp_open()

void * wpp_open ( const char filename,
int  type 
)

Definition at line 195 of file compiler.c.

196{
197 struct mem_file_desc *desc;
198 HRESULT hr;
199
200 TRACE("Opening include %s.\n", debugstr_a(filename));
201
203 {
204 current_shader.pos = 0;
205 return &current_shader;
206 }
207
208 if(current_include == NULL) return NULL;
209 desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
210 if(!desc)
211 return NULL;
212
214 filename, parent_include, (const void **)&desc->buffer, &desc->size)))
215 {
217 return NULL;
218 }
219
221 {
222 if(includes_capacity == 0)
223 {
225 if(includes == NULL)
226 {
227 ERR("Error allocating memory for the loaded includes structure\n");
228 goto error;
229 }
230 includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes);
231 }
232 else
233 {
234 int newcapacity = includes_capacity * 2;
235 struct loaded_include *newincludes =
236 HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
237 if(newincludes == NULL)
238 {
239 ERR("Error reallocating memory for the loaded includes structure\n");
240 goto error;
241 }
242 includes = newincludes;
243 includes_capacity = newcapacity;
244 }
245 }
247 includes[includes_size++].data = desc->buffer;
248
249 desc->pos = 0;
250 return desc;
251
252error:
253 ID3DInclude_Close(current_include, desc->buffer);
255 return NULL;
256}
#define INCLUDES_INITIAL_CAPACITY
Definition: compiler.c:45
static int includes_capacity
Definition: compiler.c:54
@ D3D_INCLUDE_SYSTEM
Definition: d3dcommon.idl:49
@ D3D_INCLUDE_LOCAL
Definition: d3dcommon.idl:48
#define HeapAlloc
Definition: compat.h:733
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define error(str)
Definition: mkdosfs.c:1605

Referenced by pp_open_include(), and wpp_parse().

◆ wpp_parse()

int wpp_parse ( const char input,
FILE output 
)

Definition at line 437 of file compiler.c.

438{
439 int ret;
440
444 pp_status.state = 0;
445
447 if(ret)
448 return ret;
451
452 if (!input) pp_status.file = stdin;
453 else if (!(pp_status.file = wpp_open(input, 1)))
454 {
455 ppy_error("Could not open %s\n", input);
459 return 2;
460 }
461
463
464 ppy_out = output;
465 pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
466
467 ret = ppy_parse();
468 /* If there were errors during processing, return an error code */
470
471 if (input)
472 {
475 }
476 /* Clean if_stack, it could remain dirty on errors */
477 while (pp_get_if_depth()) pp_pop_if();
481 return ret;
482}
static void del_special_defines(void)
Definition: compiler.c:367
void * wpp_open(const char *filename, int type)
Definition: compiler.c:195
int WINAPIV ppy_error(const char *msg,...)
Definition: compiler.c:135
static void add_special_defines(void)
Definition: compiler.c:346
void wpp_close(void *file)
Definition: compiler.c:258
static void add_cmdline_defines(void)
Definition: compiler.c:326
static void del_cmdline_defines(void)
Definition: compiler.c:336
int pp_get_if_depth(void)
Definition: preproc.c:433
int pp_push_define_state(void)
Definition: preproc.c:148
void pp_pop_define_state(void)
Definition: preproc.c:161
pp_if_state_t pp_pop_if(void)
Definition: preproc.c:380
void WINAPIV int ppy_parse(void)
FILE * ppy_out
void WINAPIV pp_writestring(const char *format,...) __attribute__((format(printf
GLenum GLenum GLenum input
Definition: glext.h:9031
#define stdin
Definition: stdio.h:98
void * file
Definition: wpp_private.h:221

Referenced by main(), and preprocess_shader().

◆ wpp_read()

int wpp_read ( void file,
char buffer,
unsigned int  len 
)

Definition at line 274 of file compiler.c.

275{
276 struct mem_file_desc *desc = file;
277
278 len = min(len, desc->size - desc->pos);
279 memcpy(buffer, desc->buffer + desc->pos, len);
280 desc->pos += len;
281 return len;
282}
GLenum GLsizei len
Definition: glext.h:6722

◆ wpp_write()

void wpp_write ( const char buffer,
unsigned int  len 
)

Definition at line 284 of file compiler.c.

285{
286 char *new_wpp_output;
287
288 if(wpp_output_capacity == 0)
289 {
291 if(!wpp_output)
292 return;
293
295 }
297 {
299 {
301 }
302 new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
304 if(!new_wpp_output)
305 {
306 ERR("Error allocating memory\n");
307 return;
308 }
309 wpp_output = new_wpp_output;
310 }
313}
#define BUFFER_INITIAL_CAPACITY
Definition: compiler.c:32

◆ wpp_write_message()

static void wpp_write_message ( const char fmt,
__ms_va_list  args 
)
static

Definition at line 86 of file compiler.c.

87{
88 char* newbuffer;
89 int rc, newsize;
90
92 {
94 if(wpp_messages == NULL)
95 return;
96
98 }
99
100 while(1)
101 {
104
105 if (rc < 0 || /* C89 */
106 rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
107 /* Resize the buffer */
108 newsize = wpp_messages_capacity * 2;
109 newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
110 if(newbuffer == NULL)
111 {
112 ERR("Error reallocating memory for parser messages\n");
113 return;
114 }
115 wpp_messages = newbuffer;
116 wpp_messages_capacity = newsize;
117 }
118 else
119 {
120 wpp_messages_size += rc;
121 return;
122 }
123 }
124}
#define MESSAGEBUFFER_INITIAL_SIZE
#define vsnprintf
Definition: tif_win32.c:406

Referenced by ppy_error(), ppy_warning(), and PRINTF_ATTR().

Variable Documentation

◆ cmdline_defines

struct define* cmdline_defines
static

◆ current_include

ID3DInclude* current_include
static

Definition at line 42 of file compiler.c.

Referenced by preprocess_shader(), wpp_close(), and wpp_open().

◆ current_shader

struct mem_file_desc current_shader
static

Definition at line 41 of file compiler.c.

Referenced by preprocess_shader(), wpp_close(), and wpp_open().

◆ includes

◆ includes_capacity

int includes_capacity
static

Definition at line 54 of file compiler.c.

Referenced by wpp_open().

◆ includes_size

int includes_size
static

Definition at line 54 of file compiler.c.

Referenced by preprocess_shader(), wpp_lookup(), and wpp_open().

◆ initial_filename

const char* initial_filename
static

Definition at line 43 of file compiler.c.

Referenced by preprocess_shader(), wpp_lookup(), and wpp_open().

◆ parent_include

const char* parent_include
static

Definition at line 55 of file compiler.c.

Referenced by wpp_lookup(), and wpp_open().

◆ targets_info

const struct target_info targets_info[]
static

Definition at line 669 of file compiler.c.

Referenced by get_target_info().

◆ wpp_messages

char* wpp_messages
static

Definition at line 60 of file compiler.c.

Referenced by preprocess_shader(), and wpp_write_message().

◆ wpp_messages_capacity

int wpp_messages_capacity
static

Definition at line 61 of file compiler.c.

Referenced by preprocess_shader(), and wpp_write_message().

◆ wpp_messages_size

int wpp_messages_size
static

Definition at line 61 of file compiler.c.

Referenced by preprocess_shader(), and wpp_write_message().

◆ wpp_mutex

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

Definition at line 75 of file compiler.c.

Referenced by D3DAssemble(), D3DCompile2(), and D3DPreprocess().

◆ 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:76
LIST_ENTRY ProcessLocksList
Definition: winbase.h:883
#define DWORD_PTR
Definition: treelist.c:76

Definition at line 76 of file compiler.c.

◆ wpp_output

char* wpp_output
static

◆ wpp_output_capacity

int wpp_output_capacity
static

Definition at line 58 of file compiler.c.

Referenced by preprocess_shader(), and wpp_write().

◆ wpp_output_size

int wpp_output_size
static

Definition at line 58 of file compiler.c.

Referenced by D3DPreprocess(), preprocess_shader(), wpp_close_output(), and wpp_write().