Commit 491d0e9d authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

d3dcompiler: Rename asm_alloc/realloc/free functions to more generic names.

parent e2866d6f
...@@ -1350,7 +1350,7 @@ static void gen_oldps_input(struct bwriter_shader *shader, DWORD texcoords) { ...@@ -1350,7 +1350,7 @@ static void gen_oldps_input(struct bwriter_shader *shader, DWORD texcoords) {
void create_vs10_parser(struct asm_parser *ret) { void create_vs10_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("vs_1_0\n"); TRACE_(parsed_shader)("vs_1_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1366,7 +1366,7 @@ void create_vs10_parser(struct asm_parser *ret) { ...@@ -1366,7 +1366,7 @@ void create_vs10_parser(struct asm_parser *ret) {
void create_vs11_parser(struct asm_parser *ret) { void create_vs11_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("vs_1_1\n"); TRACE_(parsed_shader)("vs_1_1\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1382,7 +1382,7 @@ void create_vs11_parser(struct asm_parser *ret) { ...@@ -1382,7 +1382,7 @@ void create_vs11_parser(struct asm_parser *ret) {
void create_vs20_parser(struct asm_parser *ret) { void create_vs20_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("vs_2_0\n"); TRACE_(parsed_shader)("vs_2_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1398,7 +1398,7 @@ void create_vs20_parser(struct asm_parser *ret) { ...@@ -1398,7 +1398,7 @@ void create_vs20_parser(struct asm_parser *ret) {
void create_vs2x_parser(struct asm_parser *ret) { void create_vs2x_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("vs_2_x\n"); TRACE_(parsed_shader)("vs_2_x\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1414,7 +1414,7 @@ void create_vs2x_parser(struct asm_parser *ret) { ...@@ -1414,7 +1414,7 @@ void create_vs2x_parser(struct asm_parser *ret) {
void create_vs30_parser(struct asm_parser *ret) { void create_vs30_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("vs_3_0\n"); TRACE_(parsed_shader)("vs_3_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1429,7 +1429,7 @@ void create_vs30_parser(struct asm_parser *ret) { ...@@ -1429,7 +1429,7 @@ void create_vs30_parser(struct asm_parser *ret) {
void create_ps10_parser(struct asm_parser *ret) { void create_ps10_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_1_0\n"); TRACE_(parsed_shader)("ps_1_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1445,7 +1445,7 @@ void create_ps10_parser(struct asm_parser *ret) { ...@@ -1445,7 +1445,7 @@ void create_ps10_parser(struct asm_parser *ret) {
void create_ps11_parser(struct asm_parser *ret) { void create_ps11_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_1_1\n"); TRACE_(parsed_shader)("ps_1_1\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1461,7 +1461,7 @@ void create_ps11_parser(struct asm_parser *ret) { ...@@ -1461,7 +1461,7 @@ void create_ps11_parser(struct asm_parser *ret) {
void create_ps12_parser(struct asm_parser *ret) { void create_ps12_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_1_2\n"); TRACE_(parsed_shader)("ps_1_2\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1477,7 +1477,7 @@ void create_ps12_parser(struct asm_parser *ret) { ...@@ -1477,7 +1477,7 @@ void create_ps12_parser(struct asm_parser *ret) {
void create_ps13_parser(struct asm_parser *ret) { void create_ps13_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_1_3\n"); TRACE_(parsed_shader)("ps_1_3\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1493,7 +1493,7 @@ void create_ps13_parser(struct asm_parser *ret) { ...@@ -1493,7 +1493,7 @@ void create_ps13_parser(struct asm_parser *ret) {
void create_ps14_parser(struct asm_parser *ret) { void create_ps14_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_1_4\n"); TRACE_(parsed_shader)("ps_1_4\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1509,7 +1509,7 @@ void create_ps14_parser(struct asm_parser *ret) { ...@@ -1509,7 +1509,7 @@ void create_ps14_parser(struct asm_parser *ret) {
void create_ps20_parser(struct asm_parser *ret) { void create_ps20_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_2_0\n"); TRACE_(parsed_shader)("ps_2_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1525,7 +1525,7 @@ void create_ps20_parser(struct asm_parser *ret) { ...@@ -1525,7 +1525,7 @@ void create_ps20_parser(struct asm_parser *ret) {
void create_ps2x_parser(struct asm_parser *ret) { void create_ps2x_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_2_x\n"); TRACE_(parsed_shader)("ps_2_x\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
...@@ -1541,7 +1541,7 @@ void create_ps2x_parser(struct asm_parser *ret) { ...@@ -1541,7 +1541,7 @@ void create_ps2x_parser(struct asm_parser *ret) {
void create_ps30_parser(struct asm_parser *ret) { void create_ps30_parser(struct asm_parser *ret) {
TRACE_(parsed_shader)("ps_3_0\n"); TRACE_(parsed_shader)("ps_3_0\n");
ret->shader = asm_alloc(sizeof(*ret->shader)); ret->shader = d3dcompiler_alloc(sizeof(*ret->shader));
if(!ret->shader) { if(!ret->shader) {
ERR("Failed to allocate memory for the shader\n"); ERR("Failed to allocate memory for the shader\n");
set_parse_status(&ret->status, PARSE_ERR); set_parse_status(&ret->status, PARSE_ERR);
......
...@@ -51,7 +51,7 @@ static void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) { ...@@ -51,7 +51,7 @@ static void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
if(!rel->has_rel_reg) { if(!rel->has_rel_reg) {
reg->rel_reg = NULL; reg->rel_reg = NULL;
} else { } else {
reg->rel_reg = asm_alloc(sizeof(*reg->rel_reg)); reg->rel_reg = d3dcompiler_alloc(sizeof(*reg->rel_reg));
if(!reg->rel_reg) { if(!reg->rel_reg) {
return; return;
} }
...@@ -1693,16 +1693,22 @@ struct bwriter_shader *parse_asm_shader(char **messages) ...@@ -1693,16 +1693,22 @@ struct bwriter_shader *parse_asm_shader(char **messages)
if (asm_ctx.messages.size) if (asm_ctx.messages.size)
{ {
/* Shrink the buffer to the used size */ /* Shrink the buffer to the used size */
*messages = asm_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1); *messages = d3dcompiler_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1);
if(!*messages) { if (!*messages)
{
ERR("Out of memory, no messages reported\n"); ERR("Out of memory, no messages reported\n");
asm_free(asm_ctx.messages.string); d3dcompiler_free(asm_ctx.messages.string);
} }
} else { }
else
{
*messages = NULL; *messages = NULL;
} }
} else { }
if(asm_ctx.messages.capacity) asm_free(asm_ctx.messages.string); else
{
if (asm_ctx.messages.capacity)
d3dcompiler_free(asm_ctx.messages.string);
} }
return ret; return ret;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright 2008 Stefan Dösinger * Copyright 2008 Stefan Dösinger
* Copyright 2009 Matteo Bruni * Copyright 2009 Matteo Bruni
* Copyright 2010 Rico Schüller * Copyright 2010 Rico Schüller
* Copyright 2012 Matteo Bruni for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -138,15 +139,18 @@ struct bwriter_shader { ...@@ -138,15 +139,18 @@ struct bwriter_shader {
unsigned int num_instrs, instr_alloc_size; unsigned int num_instrs, instr_alloc_size;
}; };
static inline LPVOID asm_alloc(SIZE_T size) { static inline void *d3dcompiler_alloc(SIZE_T size)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
} }
static inline LPVOID asm_realloc(LPVOID ptr, SIZE_T size) { static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
{
return HeapReAlloc(GetProcessHeap(), 0, ptr, size); return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
} }
static inline BOOL asm_free(LPVOID ptr) { static inline BOOL d3dcompiler_free(void *ptr)
{
return HeapFree(GetProcessHeap(), 0, ptr); return HeapFree(GetProcessHeap(), 0, ptr);
} }
......
...@@ -725,7 +725,7 @@ void compilation_message(struct compilation_messages *msg, const char *fmt, va_l ...@@ -725,7 +725,7 @@ void compilation_message(struct compilation_messages *msg, const char *fmt, va_l
if (msg->capacity == 0) if (msg->capacity == 0)
{ {
msg->string = asm_alloc(MESSAGEBUFFER_INITIAL_SIZE); msg->string = d3dcompiler_alloc(MESSAGEBUFFER_INITIAL_SIZE);
if (msg->string == NULL) if (msg->string == NULL)
{ {
ERR("Error allocating memory for parser messages\n"); ERR("Error allocating memory for parser messages\n");
...@@ -742,7 +742,7 @@ void compilation_message(struct compilation_messages *msg, const char *fmt, va_l ...@@ -742,7 +742,7 @@ void compilation_message(struct compilation_messages *msg, const char *fmt, va_l
if (rc < 0 || rc >= msg->capacity - msg->size) if (rc < 0 || rc >= msg->capacity - msg->size)
{ {
size = msg->capacity * 2; size = msg->capacity * 2;
buffer = asm_realloc(msg->string, size); buffer = d3dcompiler_realloc(msg->string, size);
if (buffer == NULL) if (buffer == NULL)
{ {
ERR("Error reallocating memory for parser messages\n"); ERR("Error reallocating memory for parser messages\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment