mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader: Move the remainder of hlsl_parser_compile() to hlsl_compile_shader().
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
df5e4a865c
commit
8ce33da2ab
@@ -188,6 +188,22 @@ bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name)
|
|||||||
return rb_get(&ctx->functions, name) != NULL;
|
return rb_get(&ctx->functions, name) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name)
|
||||||
|
{
|
||||||
|
struct hlsl_ir_function_decl *decl;
|
||||||
|
struct hlsl_ir_function *func;
|
||||||
|
struct rb_entry *entry;
|
||||||
|
|
||||||
|
if ((entry = rb_get(&ctx->functions, name)))
|
||||||
|
{
|
||||||
|
func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
|
||||||
|
RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int hlsl_type_component_count(struct hlsl_type *type)
|
unsigned int hlsl_type_component_count(struct hlsl_type *type)
|
||||||
{
|
{
|
||||||
struct hlsl_struct_field *field;
|
struct hlsl_struct_field *field;
|
||||||
@@ -1606,7 +1622,9 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
|
|||||||
struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context)
|
struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context)
|
||||||
{
|
{
|
||||||
const struct vkd3d_shader_hlsl_source_info *hlsl_source_info;
|
const struct vkd3d_shader_hlsl_source_info *hlsl_source_info;
|
||||||
|
struct hlsl_ir_function_decl *entry_func;
|
||||||
const struct hlsl_profile_info *profile;
|
const struct hlsl_profile_info *profile;
|
||||||
|
const char *entry_point;
|
||||||
struct hlsl_ctx ctx;
|
struct hlsl_ctx ctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -1615,6 +1633,7 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
|
|||||||
ERR("No HLSL source info given.\n");
|
ERR("No HLSL source info given.\n");
|
||||||
return VKD3D_ERROR_INVALID_ARGUMENT;
|
return VKD3D_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
entry_point = hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main";
|
||||||
|
|
||||||
if (!(profile = get_target_info(hlsl_source_info->profile)))
|
if (!(profile = get_target_info(hlsl_source_info->profile)))
|
||||||
{
|
{
|
||||||
@@ -1627,9 +1646,30 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
|
|||||||
if (!hlsl_ctx_init(&ctx, message_context))
|
if (!hlsl_ctx_init(&ctx, message_context))
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
ret = hlsl_lexer_compile(&ctx, text, hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main");
|
hlsl_lexer_compile(&ctx, text);
|
||||||
|
|
||||||
|
if (ctx.failed)
|
||||||
|
{
|
||||||
|
hlsl_ctx_cleanup(&ctx);
|
||||||
|
return VKD3D_ERROR_INVALID_SHADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(entry_func = hlsl_get_func_decl(&ctx, entry_point)))
|
||||||
|
{
|
||||||
|
const struct vkd3d_shader_location loc = {.source_name = compile_info->source_name};
|
||||||
|
|
||||||
|
hlsl_error(&ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED,
|
||||||
|
"Entry point \"%s\" is not defined.", entry_point);
|
||||||
|
return VKD3D_ERROR_INVALID_SHADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hlsl_type_is_void(entry_func->return_type)
|
||||||
|
&& entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
|
||||||
|
hlsl_error(&ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
|
||||||
|
"Entry point \"%s\" is missing a return value semantic.", entry_point);
|
||||||
|
|
||||||
|
ret = hlsl_emit_dxbc(&ctx, entry_func);
|
||||||
|
|
||||||
hlsl_ctx_cleanup(&ctx);
|
hlsl_ctx_cleanup(&ctx);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -518,6 +518,7 @@ void hlsl_free_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
|
|||||||
void hlsl_free_var(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
|
void hlsl_free_var(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
|
bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
|
||||||
|
struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) DECLSPEC_HIDDEN;
|
struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
|
struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
@@ -571,7 +572,6 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type) DECLSPEC_HIDDEN;
|
|||||||
bool hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
bool hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
||||||
bool hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
bool hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint) DECLSPEC_HIDDEN;
|
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) DECLSPEC_HIDDEN;
|
||||||
int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint) DECLSPEC_HIDDEN;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -282,7 +282,7 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc)
|
|||||||
ctx->location.column += yyget_leng(ctx->scanner);
|
ctx->location.column += yyget_leng(ctx->scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint)
|
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text)
|
||||||
{
|
{
|
||||||
YY_BUFFER_STATE buffer;
|
YY_BUFFER_STATE buffer;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -291,7 +291,7 @@ int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entry
|
|||||||
buffer = yy_scan_string(text, ctx->scanner);
|
buffer = yy_scan_string(text, ctx->scanner);
|
||||||
yy_switch_to_buffer(buffer, ctx->scanner);
|
yy_switch_to_buffer(buffer, ctx->scanner);
|
||||||
|
|
||||||
ret = hlsl_parser_compile(ctx, entrypoint);
|
ret = hlsl_yyparse(ctx->scanner, ctx);
|
||||||
|
|
||||||
yy_delete_buffer(buffer, ctx->scanner);
|
yy_delete_buffer(buffer, ctx->scanner);
|
||||||
yylex_destroy(ctx->scanner);
|
yylex_destroy(ctx->scanner);
|
||||||
|
@@ -286,22 +286,6 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
|
|||||||
return &cast->node;
|
return &cast->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_ir_function_decl *get_func_entry(struct hlsl_ctx *ctx, const char *name)
|
|
||||||
{
|
|
||||||
struct hlsl_ir_function_decl *decl;
|
|
||||||
struct hlsl_ir_function *func;
|
|
||||||
struct rb_entry *entry;
|
|
||||||
|
|
||||||
if ((entry = rb_get(&ctx->functions, name)))
|
|
||||||
{
|
|
||||||
func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
|
|
||||||
RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
|
||||||
return decl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local)
|
static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_function_decl *func;
|
struct hlsl_ir_function_decl *func;
|
||||||
@@ -334,7 +318,7 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((func = get_func_entry(ctx, decl->name)))
|
if ((func = hlsl_get_func_decl(ctx, decl->name)))
|
||||||
{
|
{
|
||||||
hlsl_error(ctx, decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
hlsl_error(ctx, decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
|
||||||
"Variable '%s' is already defined as a function.", decl->name);
|
"Variable '%s' is already defined as a function.", decl->name);
|
||||||
@@ -3012,32 +2996,3 @@ expr:
|
|||||||
list_move_tail($$, $3);
|
list_move_tail($$, $3);
|
||||||
vkd3d_free($3);
|
vkd3d_free($3);
|
||||||
}
|
}
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint)
|
|
||||||
{
|
|
||||||
struct hlsl_ir_function_decl *entry_func;
|
|
||||||
|
|
||||||
yyparse(ctx->scanner, ctx);
|
|
||||||
|
|
||||||
if (ctx->failed)
|
|
||||||
return VKD3D_ERROR_INVALID_SHADER;
|
|
||||||
|
|
||||||
if (!(entry_func = get_func_entry(ctx, entrypoint)))
|
|
||||||
{
|
|
||||||
const struct vkd3d_shader_location loc = {.source_name = ctx->location.source_name};
|
|
||||||
|
|
||||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Entry point \"%s\" is not defined.", entrypoint);
|
|
||||||
return VKD3D_ERROR_INVALID_SHADER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hlsl_type_is_void(entry_func->return_type)
|
|
||||||
&& entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
|
|
||||||
{
|
|
||||||
hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
|
|
||||||
"Entry point \"%s\" is missing a return value semantic.", entry_func->func->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hlsl_emit_dxbc(ctx, entry_func);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user