2010-08-17 19:22:59 +02:00
|
|
|
/*
|
2010-08-24 23:05:12 +02:00
|
|
|
* Copyright 2009 Matteo Bruni
|
2010-08-17 19:22:59 +02:00
|
|
|
* Copyright 2010 Matteo Bruni for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
#define COBJMACROS
|
2019-07-02 13:26:27 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <time.h>
|
2010-08-17 19:22:59 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "d3dcompiler_private.h"
|
2019-07-02 13:26:27 +02:00
|
|
|
#include "wpp_private.h"
|
2010-08-17 19:22:59 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
#define D3DXERR_INVALIDDATA 0x88760b59
|
|
|
|
|
|
|
|
#define BUFFER_INITIAL_CAPACITY 256
|
|
|
|
|
|
|
|
struct mem_file_desc
|
|
|
|
{
|
|
|
|
const char *buffer;
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int pos;
|
|
|
|
};
|
|
|
|
|
2010-10-18 13:05:48 +02:00
|
|
|
static struct mem_file_desc current_shader;
|
|
|
|
static ID3DInclude *current_include;
|
2012-07-11 17:27:51 +02:00
|
|
|
static const char *initial_filename;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
|
|
|
#define INCLUDES_INITIAL_CAPACITY 4
|
|
|
|
|
|
|
|
struct loaded_include
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *data;
|
|
|
|
};
|
|
|
|
|
2010-10-18 13:05:48 +02:00
|
|
|
static struct loaded_include *includes;
|
|
|
|
static int includes_capacity, includes_size;
|
|
|
|
static const char *parent_include;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2010-10-18 13:05:48 +02:00
|
|
|
static char *wpp_output;
|
|
|
|
static int wpp_output_capacity, wpp_output_size;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2010-10-18 13:05:48 +02:00
|
|
|
static char *wpp_messages;
|
|
|
|
static int wpp_messages_capacity, wpp_messages_size;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
struct define
|
|
|
|
{
|
|
|
|
struct define *next;
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct define *cmdline_defines;
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
/* Mutex used to guarantee a single invocation
|
|
|
|
of the D3DXAssembleShader function (or its variants) at a time.
|
|
|
|
This is needed as wpp isn't thread-safe */
|
|
|
|
static CRITICAL_SECTION wpp_mutex;
|
|
|
|
static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
|
|
|
|
{
|
|
|
|
0, 0, &wpp_mutex,
|
|
|
|
{ &wpp_mutex_debug.ProcessLocksList,
|
|
|
|
&wpp_mutex_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
/* Preprocessor error reporting functions */
|
2019-07-02 13:37:18 +02:00
|
|
|
static void wpp_write_message(const char *fmt, __ms_va_list args)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
char* newbuffer;
|
|
|
|
int rc, newsize;
|
|
|
|
|
|
|
|
if(wpp_messages_capacity == 0)
|
|
|
|
{
|
|
|
|
wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE);
|
|
|
|
if(wpp_messages == NULL)
|
|
|
|
return;
|
2013-02-08 10:34:39 +01:00
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
rc = vsnprintf(wpp_messages + wpp_messages_size,
|
|
|
|
wpp_messages_capacity - wpp_messages_size, fmt, args);
|
|
|
|
|
|
|
|
if (rc < 0 || /* C89 */
|
|
|
|
rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
|
|
|
|
/* Resize the buffer */
|
|
|
|
newsize = wpp_messages_capacity * 2;
|
|
|
|
newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
|
|
|
|
if(newbuffer == NULL)
|
|
|
|
{
|
|
|
|
ERR("Error reallocating memory for parser messages\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wpp_messages = newbuffer;
|
|
|
|
wpp_messages_capacity = newsize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wpp_messages_size += rc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 08:02:55 +02:00
|
|
|
static void WINAPIV PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_list args;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_start(args, fmt);
|
2010-08-24 23:05:12 +02:00
|
|
|
wpp_write_message(fmt, args);
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_end(args);
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
|
2019-07-07 08:02:55 +02:00
|
|
|
int WINAPIV ppy_error(const char *msg, ...)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_list ap;
|
|
|
|
__ms_va_start(ap, msg);
|
2019-07-02 13:26:27 +02:00
|
|
|
wpp_write_message_var("%s:%d:%d: %s: ",
|
|
|
|
pp_status.input ? pp_status.input : "'main file'",
|
|
|
|
pp_status.line_number, pp_status.char_number, "Error");
|
2010-08-24 23:05:12 +02:00
|
|
|
wpp_write_message(msg, ap);
|
|
|
|
wpp_write_message_var("\n");
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_end(ap);
|
2019-07-02 13:26:27 +02:00
|
|
|
pp_status.state = 1;
|
|
|
|
return 1;
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
|
2019-07-07 08:02:55 +02:00
|
|
|
int WINAPIV ppy_warning(const char *msg, ...)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_list ap;
|
|
|
|
__ms_va_start(ap, msg);
|
2019-07-02 13:26:27 +02:00
|
|
|
wpp_write_message_var("%s:%d:%d: %s: ",
|
|
|
|
pp_status.input ? pp_status.input : "'main file'",
|
|
|
|
pp_status.line_number, pp_status.char_number, "Warning");
|
2010-08-24 23:05:12 +02:00
|
|
|
wpp_write_message(msg, ap);
|
|
|
|
wpp_write_message_var("\n");
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_end(ap);
|
2019-07-02 13:26:27 +02:00
|
|
|
return 0;
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
char *wpp_lookup(const char *filename, int type, const char *parent_name)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2014-06-24 22:25:30 +02:00
|
|
|
/* We don't check for file existence here. We will potentially fail on
|
|
|
|
* the following wpp_open_mem(). */
|
2010-08-24 23:05:12 +02:00
|
|
|
char *path;
|
|
|
|
int i;
|
|
|
|
|
2014-06-24 22:25:30 +02:00
|
|
|
TRACE("Looking for include %s, parent %s.\n", debugstr_a(filename), debugstr_a(parent_name));
|
2013-09-03 16:29:41 +02:00
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
parent_include = NULL;
|
2013-09-03 16:29:41 +02:00
|
|
|
if (strcmp(parent_name, initial_filename))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
for(i = 0; i < includes_size; i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(parent_name, includes[i].name))
|
|
|
|
{
|
|
|
|
parent_include = includes[i].data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(parent_include == NULL)
|
|
|
|
{
|
2013-09-03 16:29:41 +02:00
|
|
|
ERR("Parent include %s missing.\n", debugstr_a(parent_name));
|
2010-08-24 23:05:12 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path = malloc(strlen(filename) + 1);
|
|
|
|
if(path)
|
|
|
|
memcpy(path, filename, strlen(filename) + 1);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
void *wpp_open(const char *filename, int type)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
struct mem_file_desc *desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2013-09-03 16:29:41 +02:00
|
|
|
TRACE("Opening include %s.\n", debugstr_a(filename));
|
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
if(!strcmp(filename, initial_filename))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
current_shader.pos = 0;
|
|
|
|
return ¤t_shader;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(current_include == NULL) return NULL;
|
|
|
|
desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
|
|
|
|
if(!desc)
|
|
|
|
return NULL;
|
2013-02-08 10:34:39 +01:00
|
|
|
|
2013-09-05 09:54:43 +02:00
|
|
|
if (FAILED(hr = ID3DInclude_Open(current_include, type ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
|
|
|
|
filename, parent_include, (const void **)&desc->buffer, &desc->size)))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(includes_capacity == includes_size)
|
|
|
|
{
|
|
|
|
if(includes_capacity == 0)
|
|
|
|
{
|
2011-02-07 14:35:37 +01:00
|
|
|
includes = HeapAlloc(GetProcessHeap(), 0, INCLUDES_INITIAL_CAPACITY * sizeof(*includes));
|
2010-08-24 23:05:12 +02:00
|
|
|
if(includes == NULL)
|
|
|
|
{
|
|
|
|
ERR("Error allocating memory for the loaded includes structure\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2011-02-07 14:35:37 +01:00
|
|
|
includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes);
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int newcapacity = includes_capacity * 2;
|
|
|
|
struct loaded_include *newincludes =
|
|
|
|
HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
|
|
|
|
if(newincludes == NULL)
|
|
|
|
{
|
|
|
|
ERR("Error reallocating memory for the loaded includes structure\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
includes = newincludes;
|
|
|
|
includes_capacity = newcapacity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
includes[includes_size].name = filename;
|
|
|
|
includes[includes_size++].data = desc->buffer;
|
|
|
|
|
|
|
|
desc->pos = 0;
|
|
|
|
return desc;
|
|
|
|
|
|
|
|
error:
|
|
|
|
ID3DInclude_Close(current_include, desc->buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
void wpp_close(void *file)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
struct mem_file_desc *desc = file;
|
|
|
|
|
|
|
|
if(desc != ¤t_shader)
|
|
|
|
{
|
|
|
|
if(current_include)
|
|
|
|
ID3DInclude_Close(current_include, desc->buffer);
|
|
|
|
else
|
|
|
|
ERR("current_include == NULL, desc == %p, buffer = %s\n",
|
|
|
|
desc, desc->buffer);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
int wpp_read(void *file, char *buffer, unsigned int len)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
struct mem_file_desc *desc = file;
|
|
|
|
|
|
|
|
len = min(len, desc->size - desc->pos);
|
|
|
|
memcpy(buffer, desc->buffer + desc->pos, len);
|
|
|
|
desc->pos += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
void wpp_write(const char *buffer, unsigned int len)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
char *new_wpp_output;
|
|
|
|
|
|
|
|
if(wpp_output_capacity == 0)
|
|
|
|
{
|
|
|
|
wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY);
|
|
|
|
if(!wpp_output)
|
|
|
|
return;
|
2013-02-08 10:34:39 +01:00
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
wpp_output_capacity = BUFFER_INITIAL_CAPACITY;
|
|
|
|
}
|
|
|
|
if(len > wpp_output_capacity - wpp_output_size)
|
|
|
|
{
|
|
|
|
while(len > wpp_output_capacity - wpp_output_size)
|
|
|
|
{
|
|
|
|
wpp_output_capacity *= 2;
|
|
|
|
}
|
|
|
|
new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
|
|
|
|
wpp_output_capacity);
|
|
|
|
if(!new_wpp_output)
|
|
|
|
{
|
|
|
|
ERR("Error allocating memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wpp_output = new_wpp_output;
|
|
|
|
}
|
|
|
|
memcpy(wpp_output + wpp_output_size, buffer, len);
|
|
|
|
wpp_output_size += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wpp_close_output(void)
|
|
|
|
{
|
|
|
|
char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
|
|
|
|
wpp_output_size + 1);
|
|
|
|
if(!new_wpp_output) return 0;
|
|
|
|
wpp_output = new_wpp_output;
|
|
|
|
wpp_output[wpp_output_size]='\0';
|
2011-01-04 16:41:42 +01:00
|
|
|
wpp_output_size++;
|
2010-08-24 23:05:12 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:26:27 +02:00
|
|
|
static void add_cmdline_defines(void)
|
|
|
|
{
|
|
|
|
struct define *def;
|
|
|
|
|
|
|
|
for (def = cmdline_defines; def; def = def->next)
|
|
|
|
{
|
|
|
|
if (def->value) pp_add_define( def->name, def->value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void del_cmdline_defines(void)
|
|
|
|
{
|
|
|
|
struct define *def;
|
|
|
|
|
|
|
|
for (def = cmdline_defines; def; def = def->next)
|
|
|
|
{
|
|
|
|
if (def->value) pp_del_define( def->name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_special_defines(void)
|
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
|
|
|
pp_entry_t *ppp;
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
|
|
|
|
pp_add_define( "__DATE__", buf );
|
|
|
|
|
|
|
|
strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
|
|
|
|
pp_add_define( "__TIME__", buf );
|
|
|
|
|
|
|
|
ppp = pp_add_define( "__FILE__", "" );
|
|
|
|
if(ppp)
|
|
|
|
ppp->type = def_special;
|
|
|
|
|
|
|
|
ppp = pp_add_define( "__LINE__", "" );
|
|
|
|
if(ppp)
|
|
|
|
ppp->type = def_special;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void del_special_defines(void)
|
|
|
|
{
|
|
|
|
pp_del_define( "__DATE__" );
|
|
|
|
pp_del_define( "__TIME__" );
|
|
|
|
pp_del_define( "__FILE__" );
|
|
|
|
pp_del_define( "__LINE__" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* add a define to the preprocessor list */
|
|
|
|
int wpp_add_define( const char *name, const char *value )
|
|
|
|
{
|
|
|
|
struct define *def;
|
|
|
|
|
|
|
|
if (!value) value = "";
|
|
|
|
|
|
|
|
for (def = cmdline_defines; def; def = def->next)
|
|
|
|
{
|
|
|
|
if (!strcmp( def->name, name ))
|
|
|
|
{
|
|
|
|
char *new_value = pp_xstrdup(value);
|
|
|
|
if(!new_value)
|
|
|
|
return 1;
|
|
|
|
free( def->value );
|
|
|
|
def->value = new_value;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def = pp_xmalloc( sizeof(*def) );
|
|
|
|
if(!def)
|
|
|
|
return 1;
|
|
|
|
def->next = cmdline_defines;
|
|
|
|
def->name = pp_xstrdup(name);
|
|
|
|
if(!def->name)
|
|
|
|
{
|
|
|
|
free(def);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
def->value = pp_xstrdup(value);
|
|
|
|
if(!def->value)
|
|
|
|
{
|
|
|
|
free(def->name);
|
|
|
|
free(def);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cmdline_defines = def;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* undefine a previously added definition */
|
|
|
|
void wpp_del_define( const char *name )
|
|
|
|
{
|
|
|
|
struct define *def;
|
|
|
|
|
|
|
|
for (def = cmdline_defines; def; def = def->next)
|
|
|
|
{
|
|
|
|
if (!strcmp( def->name, name ))
|
|
|
|
{
|
|
|
|
free( def->value );
|
|
|
|
def->value = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the main preprocessor parsing loop */
|
|
|
|
int wpp_parse( const char *input, FILE *output )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pp_status.input = NULL;
|
|
|
|
pp_status.line_number = 1;
|
|
|
|
pp_status.char_number = 1;
|
|
|
|
pp_status.state = 0;
|
|
|
|
|
|
|
|
ret = pp_push_define_state();
|
|
|
|
if(ret)
|
|
|
|
return ret;
|
|
|
|
add_cmdline_defines();
|
|
|
|
add_special_defines();
|
|
|
|
|
|
|
|
if (!input) pp_status.file = stdin;
|
|
|
|
else if (!(pp_status.file = wpp_open(input, 1)))
|
|
|
|
{
|
|
|
|
ppy_error("Could not open %s\n", input);
|
|
|
|
del_special_defines();
|
|
|
|
del_cmdline_defines();
|
|
|
|
pp_pop_define_state();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
pp_status.input = input ? pp_xstrdup(input) : NULL;
|
|
|
|
|
|
|
|
ppy_out = output;
|
|
|
|
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
|
|
|
|
|
|
|
|
ret = ppy_parse();
|
|
|
|
/* If there were errors during processing, return an error code */
|
|
|
|
if (!ret && pp_status.state) ret = pp_status.state;
|
|
|
|
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
wpp_close(pp_status.file);
|
|
|
|
free(pp_status.input);
|
|
|
|
}
|
|
|
|
/* Clean if_stack, it could remain dirty on errors */
|
|
|
|
while (pp_get_if_depth()) pp_pop_if();
|
|
|
|
del_special_defines();
|
|
|
|
del_cmdline_defines();
|
|
|
|
pp_pop_define_state();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename,
|
2010-09-09 18:41:39 +02:00
|
|
|
const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
const D3D_SHADER_MACRO *def = defines;
|
|
|
|
|
|
|
|
if (def != NULL)
|
|
|
|
{
|
|
|
|
while (def->Name != NULL)
|
|
|
|
{
|
|
|
|
wpp_add_define(def->Name, def->Definition);
|
|
|
|
def++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_include = include;
|
|
|
|
includes_size = 0;
|
|
|
|
|
|
|
|
wpp_output_size = wpp_output_capacity = 0;
|
|
|
|
wpp_output = NULL;
|
|
|
|
|
|
|
|
wpp_messages_size = wpp_messages_capacity = 0;
|
|
|
|
wpp_messages = NULL;
|
|
|
|
current_shader.buffer = data;
|
|
|
|
current_shader.size = data_size;
|
2012-07-11 17:27:51 +02:00
|
|
|
initial_filename = filename ? filename : "";
|
2010-09-09 18:41:39 +02:00
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
ret = wpp_parse(initial_filename, NULL);
|
2010-09-09 18:41:39 +02:00
|
|
|
if (!wpp_close_output())
|
|
|
|
ret = 1;
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
TRACE("Error during shader preprocessing\n");
|
|
|
|
if (wpp_messages)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
ID3DBlob *buffer;
|
|
|
|
|
2012-07-11 17:27:49 +02:00
|
|
|
TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages));
|
2010-09-09 18:41:39 +02:00
|
|
|
|
|
|
|
if (error_messages)
|
|
|
|
{
|
|
|
|
size = strlen(wpp_messages) + 1;
|
|
|
|
hr = D3DCreateBlob(size, &buffer);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto cleanup;
|
|
|
|
CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size);
|
|
|
|
*error_messages = buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
TRACE("Shader source:\n%s\n", debugstr_an(data, data_size));
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/* Remove the previously added defines */
|
|
|
|
if (defines != NULL)
|
|
|
|
{
|
|
|
|
while (defines->Name != NULL)
|
|
|
|
{
|
|
|
|
wpp_del_define(defines->Name);
|
|
|
|
defines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, wpp_messages);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-04-20 18:21:27 +02:00
|
|
|
static HRESULT assemble_shader(const char *preproc_shader,
|
2011-01-12 23:06:44 +01:00
|
|
|
ID3DBlob **shader_blob, ID3DBlob **error_messages)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
struct bwriter_shader *shader;
|
|
|
|
char *messages = NULL;
|
|
|
|
HRESULT hr;
|
2012-05-15 16:12:53 +02:00
|
|
|
DWORD *res, size;
|
|
|
|
ID3DBlob *buffer;
|
2010-08-24 23:05:12 +02:00
|
|
|
char *pos;
|
|
|
|
|
2011-01-12 23:06:44 +01:00
|
|
|
shader = SlAssembleShader(preproc_shader, &messages);
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2011-04-20 18:21:27 +02:00
|
|
|
if (messages)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2011-04-20 18:21:27 +02:00
|
|
|
TRACE("Assembler messages:\n");
|
2012-07-11 17:27:49 +02:00
|
|
|
TRACE("%s\n", debugstr_a(messages));
|
2010-08-24 23:05:12 +02:00
|
|
|
|
|
|
|
TRACE("Shader source:\n");
|
2011-01-12 23:06:44 +01:00
|
|
|
TRACE("%s\n", debugstr_a(preproc_shader));
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2011-01-12 23:06:44 +01:00
|
|
|
if (error_messages)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2011-04-20 18:21:27 +02:00
|
|
|
const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
|
|
|
|
|
|
|
|
size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
|
2010-08-24 23:05:12 +02:00
|
|
|
hr = D3DCreateBlob(size, &buffer);
|
2011-01-12 23:06:44 +01:00
|
|
|
if (FAILED(hr))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, messages);
|
2011-01-12 23:06:44 +01:00
|
|
|
if (shader) SlDeleteShader(shader);
|
2010-08-24 23:05:12 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
pos = ID3D10Blob_GetBufferPointer(buffer);
|
2011-01-12 23:06:44 +01:00
|
|
|
if (preproc_messages)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2011-01-12 23:06:44 +01:00
|
|
|
CopyMemory(pos, preproc_messages, strlen(preproc_messages) + 1);
|
|
|
|
pos += strlen(preproc_messages);
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
2011-04-20 18:21:27 +02:00
|
|
|
CopyMemory(pos, messages, strlen(messages) + 1);
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2011-04-20 18:21:27 +02:00
|
|
|
if (*error_messages) ID3D10Blob_Release(*error_messages);
|
2011-01-12 23:06:44 +01:00
|
|
|
*error_messages = buffer;
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, messages);
|
|
|
|
}
|
|
|
|
|
2011-01-12 23:06:44 +01:00
|
|
|
if (shader == NULL)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
ERR("Asm reading failed\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:07:13 +01:00
|
|
|
hr = shader_write_bytecode(shader, &res, &size);
|
2010-08-24 23:05:12 +02:00
|
|
|
SlDeleteShader(shader);
|
2011-01-12 23:06:44 +01:00
|
|
|
if (FAILED(hr))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
2020-03-20 00:07:13 +01:00
|
|
|
ERR("Failed to write bytecode, hr %#x.\n", hr);
|
2010-08-24 23:05:12 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2011-01-12 23:06:44 +01:00
|
|
|
if (shader_blob)
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
hr = D3DCreateBlob(size, &buffer);
|
2011-01-12 23:06:44 +01:00
|
|
|
if (FAILED(hr))
|
2010-08-24 23:05:12 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, res);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
CopyMemory(ID3D10Blob_GetBufferPointer(buffer), res, size);
|
2011-01-12 23:06:44 +01:00
|
|
|
*shader_blob = buffer;
|
2010-08-24 23:05:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, res);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
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)
|
|
|
|
{
|
2010-08-24 23:05:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-25 14:26:27 +01:00
|
|
|
TRACE("data %p, datasize %lu, filename %s, defines %p, include %p, sflags %#x, "
|
|
|
|
"shader %p, error_messages %p.\n",
|
2012-10-11 19:48:46 +02:00
|
|
|
data, datasize, debugstr_a(filename), defines, include, flags, shader, error_messages);
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
EnterCriticalSection(&wpp_mutex);
|
|
|
|
|
|
|
|
/* TODO: flags */
|
2010-09-09 18:41:39 +02:00
|
|
|
if (flags) FIXME("flags %x\n", flags);
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
if (shader) *shader = NULL;
|
|
|
|
if (error_messages) *error_messages = NULL;
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
hr = preprocess_shader(data, datasize, filename, defines, include, error_messages);
|
2010-09-09 18:41:39 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2011-04-20 18:21:27 +02:00
|
|
|
hr = assemble_shader(wpp_output, shader, error_messages);
|
2010-08-24 23:05:12 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, wpp_output);
|
|
|
|
LeaveCriticalSection(&wpp_mutex);
|
|
|
|
return hr;
|
2010-08-17 19:22:59 +02:00
|
|
|
}
|
2010-08-21 03:00:47 +02:00
|
|
|
|
2013-05-12 23:55:51 +02:00
|
|
|
struct target_info {
|
|
|
|
const char *name;
|
|
|
|
enum shader_type type;
|
|
|
|
DWORD sm_major;
|
|
|
|
DWORD sm_minor;
|
|
|
|
DWORD level_major;
|
|
|
|
DWORD level_minor;
|
|
|
|
BOOL sw;
|
|
|
|
BOOL support;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Must be kept sorted for binary search */
|
|
|
|
static const struct target_info targets_info[] = {
|
|
|
|
{ "cs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "cs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "cs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ds_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "fx_2_0", ST_UNKNOWN, 2, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "fx_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "fx_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "fx_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "gs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "gs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "gs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "hs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.1.0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps.1.1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.1.2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.1.3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.1.4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.2.0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps.2.a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.2.b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps.2.sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "ps.3.0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_1_0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_1_1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_1_2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_1_3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_1_4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_2_0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_2_a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_2_b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE },
|
|
|
|
{ "ps_2_sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "ps_3_0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_3_sw", ST_PIXEL, 3, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "ps_4_0", ST_PIXEL, 4, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_4_0_level_9_0", ST_PIXEL, 4, 0, 9, 0, FALSE, FALSE },
|
|
|
|
{ "ps_4_0_level_9_1", ST_PIXEL, 4, 0, 9, 1, FALSE, FALSE },
|
|
|
|
{ "ps_4_0_level_9_3", ST_PIXEL, 4, 0, 9, 3, FALSE, FALSE },
|
|
|
|
{ "ps_4_1", ST_PIXEL, 4, 1, 0, 0, FALSE, TRUE },
|
|
|
|
{ "ps_5_0", ST_PIXEL, 5, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "tx_1_0", ST_UNKNOWN, 1, 0, 0, 0, FALSE, FALSE },
|
|
|
|
{ "vs.1.0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs.1.1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs.2.0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs.2.a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "vs.2.sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "vs.3.0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs.3.sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "vs_1_0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_1_1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_2_0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_2_a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE },
|
|
|
|
{ "vs_2_sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "vs_3_0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_3_sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE },
|
|
|
|
{ "vs_4_0", ST_VERTEX, 4, 0, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_4_0_level_9_0", ST_VERTEX, 4, 0, 9, 0, FALSE, FALSE },
|
|
|
|
{ "vs_4_0_level_9_1", ST_VERTEX, 4, 0, 9, 1, FALSE, FALSE },
|
|
|
|
{ "vs_4_0_level_9_3", ST_VERTEX, 4, 0, 9, 3, FALSE, FALSE },
|
|
|
|
{ "vs_4_1", ST_VERTEX, 4, 1, 0, 0, FALSE, TRUE },
|
|
|
|
{ "vs_5_0", ST_VERTEX, 5, 0, 0, 0, FALSE, TRUE },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct target_info * get_target_info(const char *target)
|
|
|
|
{
|
|
|
|
LONG min = 0;
|
2018-07-20 21:45:54 +02:00
|
|
|
LONG max = ARRAY_SIZE(targets_info) - 1;
|
2013-05-12 23:55:51 +02:00
|
|
|
LONG cur;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
cur = (min + max) / 2;
|
|
|
|
res = strcmp(target, targets_info[cur].name);
|
|
|
|
if (res < 0)
|
|
|
|
max = cur - 1;
|
|
|
|
else if (res > 0)
|
|
|
|
min = cur + 1;
|
|
|
|
else
|
|
|
|
return &targets_info[cur];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-15 16:12:54 +02:00
|
|
|
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint,
|
|
|
|
ID3DBlob **shader_blob, ID3DBlob **error_messages)
|
|
|
|
{
|
|
|
|
struct bwriter_shader *shader;
|
|
|
|
char *messages = NULL;
|
|
|
|
HRESULT hr;
|
2012-07-10 15:39:44 +02:00
|
|
|
DWORD *res, size, major, minor;
|
2012-05-15 16:12:54 +02:00
|
|
|
ID3DBlob *buffer;
|
|
|
|
char *pos;
|
2012-07-10 15:39:44 +02:00
|
|
|
enum shader_type shader_type;
|
2013-05-12 23:55:51 +02:00
|
|
|
const struct target_info *info;
|
2012-05-15 16:12:54 +02:00
|
|
|
|
2012-06-07 00:19:01 +02:00
|
|
|
TRACE("Preprocessed shader source: %s\n", debugstr_a(preproc_shader));
|
|
|
|
|
2013-05-12 23:55:51 +02:00
|
|
|
TRACE("Checking compilation target %s\n", debugstr_a(target));
|
|
|
|
info = get_target_info(target);
|
|
|
|
if (!info)
|
2012-07-10 15:39:44 +02:00
|
|
|
{
|
2013-05-12 23:55:51 +02:00
|
|
|
FIXME("Unknown compilation target %s\n", debugstr_a(target));
|
2012-07-10 15:39:44 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-12 23:55:51 +02:00
|
|
|
if (!info->support)
|
|
|
|
{
|
|
|
|
FIXME("Compilation target %s not yet supported\n", debugstr_a(target));
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shader_type = info->type;
|
|
|
|
major = info->sm_major;
|
|
|
|
minor = info->sm_minor;
|
|
|
|
}
|
2012-07-10 15:39:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
|
2012-05-15 16:12:54 +02:00
|
|
|
|
|
|
|
if (messages)
|
|
|
|
{
|
|
|
|
TRACE("Compiler messages:\n");
|
2012-07-11 17:27:49 +02:00
|
|
|
TRACE("%s\n", debugstr_a(messages));
|
2012-05-15 16:12:54 +02:00
|
|
|
|
|
|
|
TRACE("Shader source:\n");
|
|
|
|
TRACE("%s\n", debugstr_a(preproc_shader));
|
|
|
|
|
|
|
|
if (error_messages)
|
|
|
|
{
|
|
|
|
const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
|
|
|
|
|
|
|
|
size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
|
|
|
|
hr = D3DCreateBlob(size, &buffer);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, messages);
|
|
|
|
if (shader) SlDeleteShader(shader);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
pos = ID3D10Blob_GetBufferPointer(buffer);
|
|
|
|
if (preproc_messages)
|
|
|
|
{
|
|
|
|
memcpy(pos, preproc_messages, strlen(preproc_messages) + 1);
|
|
|
|
pos += strlen(preproc_messages);
|
|
|
|
}
|
|
|
|
memcpy(pos, messages, strlen(messages) + 1);
|
|
|
|
|
|
|
|
if (*error_messages) ID3D10Blob_Release(*error_messages);
|
|
|
|
*error_messages = buffer;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shader)
|
|
|
|
{
|
|
|
|
ERR("HLSL shader parsing failed.\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:07:13 +01:00
|
|
|
hr = shader_write_bytecode(shader, &res, &size);
|
2012-05-15 16:12:54 +02:00
|
|
|
SlDeleteShader(shader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2020-03-20 00:07:13 +01:00
|
|
|
ERR("Failed to write bytecode, hr %#x.\n", hr);
|
2012-05-15 16:12:54 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shader_blob)
|
|
|
|
{
|
|
|
|
hr = D3DCreateBlob(size, &buffer);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, res);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
memcpy(ID3D10Blob_GetBufferPointer(buffer), res, size);
|
|
|
|
*shader_blob = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, res);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-29 17:58:02 +02:00
|
|
|
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
|
2010-08-21 03:00:47 +02:00
|
|
|
const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
|
2015-07-29 17:58:02 +02:00
|
|
|
const char *target, UINT sflags, UINT eflags, UINT secondary_flags,
|
|
|
|
const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader,
|
|
|
|
ID3DBlob **error_messages)
|
2010-08-21 03:00:47 +02:00
|
|
|
{
|
2012-05-15 16:12:54 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-25 14:26:27 +01:00
|
|
|
TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
|
|
|
|
"target %s, sflags %#x, eflags %#x, secondary_flags %#x, secondary_data %p, "
|
|
|
|
"secondary_data_size %lu, shader %p, error_messages %p.\n",
|
2010-08-21 03:00:47 +02:00
|
|
|
data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
|
2015-07-29 17:58:02 +02:00
|
|
|
debugstr_a(target), sflags, eflags, secondary_flags, secondary_data,
|
|
|
|
secondary_data_size, shader, error_messages);
|
|
|
|
|
|
|
|
if (secondary_data)
|
|
|
|
FIXME("secondary data not implemented yet\n");
|
2010-08-21 03:00:47 +02:00
|
|
|
|
2012-05-15 16:12:54 +02:00
|
|
|
if (shader) *shader = NULL;
|
|
|
|
if (error_messages) *error_messages = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection(&wpp_mutex);
|
2010-08-21 03:00:47 +02:00
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
hr = preprocess_shader(data, data_size, filename, defines, include, error_messages);
|
2012-05-15 16:12:54 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = compile_shader(wpp_output, target, entrypoint, shader, error_messages);
|
2010-08-21 03:00:47 +02:00
|
|
|
|
2012-05-15 16:12:54 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wpp_output);
|
|
|
|
LeaveCriticalSection(&wpp_mutex);
|
|
|
|
return hr;
|
2010-08-21 03:00:47 +02:00
|
|
|
}
|
2010-09-09 18:41:39 +02:00
|
|
|
|
2015-07-29 17:58:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2016-03-25 14:26:27 +01:00
|
|
|
TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s, "
|
|
|
|
"target %s, sflags %#x, eflags %#x, shader %p, error_messages %p.\n",
|
2015-07-29 17:58:02 +02:00
|
|
|
data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
|
|
|
|
debugstr_a(target), sflags, eflags, shader, error_messages);
|
|
|
|
|
|
|
|
return D3DCompile2(data, data_size, filename, defines, include, entrypoint, target, sflags,
|
|
|
|
eflags, 0, NULL, 0, shader, error_messages);
|
|
|
|
}
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
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 hr;
|
|
|
|
ID3DBlob *buffer;
|
|
|
|
|
2013-05-12 23:56:01 +02:00
|
|
|
TRACE("data %p, size %lu, filename %s, defines %p, include %p, shader %p, error_messages %p\n",
|
|
|
|
data, size, debugstr_a(filename), defines, include, shader, error_messages);
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
if (!data)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&wpp_mutex);
|
|
|
|
|
|
|
|
if (shader) *shader = NULL;
|
|
|
|
if (error_messages) *error_messages = NULL;
|
|
|
|
|
2012-07-11 17:27:51 +02:00
|
|
|
hr = preprocess_shader(data, size, filename, defines, include, error_messages);
|
2010-09-09 18:41:39 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (shader)
|
|
|
|
{
|
|
|
|
hr = D3DCreateBlob(wpp_output_size, &buffer);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto cleanup;
|
|
|
|
CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size);
|
|
|
|
*shader = buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
HeapFree(GetProcessHeap(), 0, wpp_output);
|
|
|
|
LeaveCriticalSection(&wpp_mutex);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-09-17 15:32:06 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
|
|
|
|
{
|
|
|
|
FIXME("data %p, size %lu, flags %#x, comments %p, disassembly %p stub!\n",
|
|
|
|
data, size, flags, comments, disassembly);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2015-07-23 11:09:32 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
FIXME("filename %s, defines %p, includes %p, entrypoint %s, target %s, flags1 %x, flags2 %x, code %p, errors %p\n",
|
|
|
|
debugstr_w(filename), defines, includes, debugstr_a(entrypoint), debugstr_a(target), flags1, flags2, code, errors);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-05-02 11:32:17 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI D3DLoadModule(const void *data, SIZE_T size, ID3D11Module **module)
|
|
|
|
{
|
|
|
|
FIXME("data %p, size %lu, module %p stub!\n", data, size, module);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|