Commit 24c84947 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3dcompiler: Return an HRESULT from parse_hlsl().

parent fdb3db52
......@@ -752,12 +752,11 @@ static const struct target_info * get_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)
ID3DBlob **shader, ID3DBlob **error_messages)
{
struct bwriter_shader *shader;
DWORD size, major, minor;
char *messages = NULL;
HRESULT hr;
DWORD *res, size, major, minor;
ID3DBlob *buffer;
char *pos;
enum shader_type shader_type;
......@@ -787,7 +786,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co
}
}
shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
hr = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, shader, &messages);
if (messages)
{
......@@ -800,14 +799,18 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co
if (error_messages)
{
const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL;
HRESULT blob_hr;
size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1;
hr = D3DCreateBlob(size, &buffer);
if (FAILED(hr))
if (FAILED(blob_hr = D3DCreateBlob(size, &buffer)))
{
HeapFree(GetProcessHeap(), 0, messages);
if (shader) SlDeleteShader(shader);
return hr;
if (*shader)
{
ID3D10Blob_Release(*shader);
*shader = NULL;
}
return blob_hr;
}
pos = ID3D10Blob_GetBufferPointer(buffer);
if (preproc_messages)
......@@ -823,35 +826,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co
HeapFree(GetProcessHeap(), 0, messages);
}
if (!shader)
{
ERR("HLSL shader parsing failed.\n");
return D3DXERR_INVALIDDATA;
}
hr = shader_write_bytecode(shader, &res, &size);
SlDeleteShader(shader);
if (FAILED(hr))
{
ERR("Failed to write bytecode, hr %#x.\n", hr);
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;
return hr;
}
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
......
......@@ -1081,8 +1081,8 @@ BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
void init_functions_tree(struct wine_rb_tree *funcs) DECLSPEC_HIDDEN;
void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl,
BOOL intrinsic) DECLSPEC_HIDDEN;
struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, char **messages) DECLSPEC_HIDDEN;
HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, ID3D10Blob **shader, char **messages) DECLSPEC_HIDDEN;
const char *debug_base_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
......
......@@ -273,20 +273,20 @@ row_major {return KW_ROW_MAJOR; }
%%
struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, char **messages);
HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, ID3D10Blob **shader, char **messages);
struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, char **messages)
HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, ID3D10Blob **shader, char **messages)
{
struct bwriter_shader *ret = NULL;
YY_BUFFER_STATE buffer;
HRESULT hr;
buffer = hlsl__scan_string(text);
hlsl__switch_to_buffer(buffer);
ret = parse_hlsl(type, major, minor, entrypoint, messages);
hr = parse_hlsl(type, major, minor, entrypoint, shader, messages);
hlsl__delete_buffer(buffer);
return ret;
return hr;
}
......@@ -2942,13 +2942,14 @@ static void compute_liveness(struct hlsl_ir_function_decl *entry_func)
compute_liveness_recurse(entry_func->body, 0, 0);
}
struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, char **messages)
HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
const char *entrypoint, ID3D10Blob **shader_blob, char **messages)
{
struct hlsl_ir_function_decl *entry_func;
struct hlsl_scope *scope, *next_scope;
struct hlsl_type *hlsl_type, *next_type;
struct hlsl_ir_var *var, *next_var;
HRESULT hr = E_FAIL;
unsigned int i;
hlsl_ctx.status = PARSE_SUCCESS;
......@@ -2998,6 +2999,9 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
compute_liveness(entry_func);
if (hlsl_ctx.status != PARSE_ERR)
hr = E_NOTIMPL;
out:
if (messages)
{
......@@ -3036,5 +3040,5 @@ out:
free_hlsl_type(hlsl_type);
}
return NULL;
return hr;
}
......@@ -1159,7 +1159,7 @@ static void test_fail(void)
{
compiled = errors = NULL;
hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors);
todo_wine ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr);
ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr);
ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]);
ok(!compiled, "Test %u, target %s, expected no compiled shader blob.\n", i, targets[j]);
ID3D10Blob_Release(errors);
......
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