Zebediah Figura : d3dcompiler: Return an HRESULT from parse_hlsl().
Alexandre Julliard
julliard at winehq.org
Thu Jun 11 15:26:47 CDT 2020
Module: wine
Branch: master
Commit: 24c84947c835d42190e61b70ee5be98bdedd1e9b
URL: https://source.winehq.org/git/wine.git/?a=commit;h=24c84947c835d42190e61b70ee5be98bdedd1e9b
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Mon Jun 8 16:49:39 2020 -0500
d3dcompiler: Return an HRESULT from parse_hlsl().
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/d3dcompiler_43/compiler.c | 49 ++++++++-----------------------
dlls/d3dcompiler_43/d3dcompiler_private.h | 4 +--
dlls/d3dcompiler_43/hlsl.l | 14 ++++-----
dlls/d3dcompiler_43/hlsl.y | 10 +++++--
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 2 +-
5 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c
index 9fc7c1d773..78fb0c46cc 100644
--- a/dlls/d3dcompiler_43/compiler.c
+++ b/dlls/d3dcompiler_43/compiler.c
@@ -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,
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index 9ac2f14041..9feaee0d8a 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -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;
diff --git a/dlls/d3dcompiler_43/hlsl.l b/dlls/d3dcompiler_43/hlsl.l
index 2994c7dea6..6ffd137597 100644
--- a/dlls/d3dcompiler_43/hlsl.l
+++ b/dlls/d3dcompiler_43/hlsl.l
@@ -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;
}
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index b5057db887..28d4dd7f2c 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -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;
}
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
index e82b466de2..24829235a5 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -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);
More information about the wine-cvs
mailing list