Zebediah Figura : vkd3d-shader: Parse buffer declarations.
Alexandre Julliard
julliard at winehq.org
Wed Jun 23 16:09:59 CDT 2021
Module: vkd3d
Branch: master
Commit: 4695690ac876cc0c70c663a7b7154391d196162d
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=4695690ac876cc0c70c663a7b7154391d196162d
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Mon Jun 21 23:37:09 2021 -0500
vkd3d-shader: Parse buffer declarations.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
libs/vkd3d-shader/hlsl.c | 24 ++++++++++++++++++++++++
libs/vkd3d-shader/hlsl.h | 18 ++++++++++++++++++
libs/vkd3d-shader/hlsl.y | 30 ++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index c8ca4bb..aa95a43 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -592,6 +592,22 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl
return decl;
}
+struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name,
+ const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc)
+{
+ struct hlsl_buffer *buffer;
+
+ if (!(buffer = hlsl_alloc(ctx, sizeof(*buffer))))
+ return NULL;
+ buffer->type = type;
+ buffer->name = name;
+ if (reservation)
+ buffer->reservation = *reservation;
+ buffer->loc = loc;
+ list_add_tail(&ctx->buffers, &buffer->entry);
+ return buffer;
+}
+
static int compare_hlsl_types_rb(const void *key, const struct rb_entry *entry)
{
const struct hlsl_type *type = RB_ENTRY_VALUE(entry, const struct hlsl_type, scope_entry);
@@ -1583,12 +1599,14 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct hlsl_profile_info *
list_init(&ctx->static_initializers);
list_init(&ctx->extern_vars);
+ list_init(&ctx->buffers);
return true;
}
static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx)
{
+ struct hlsl_buffer *buffer, *next_buffer;
struct hlsl_scope *scope, *next_scope;
struct hlsl_ir_var *var, *next_var;
struct hlsl_type *type, *next_type;
@@ -1611,6 +1629,12 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx)
LIST_FOR_EACH_ENTRY_SAFE(type, next_type, &ctx->types, struct hlsl_type, entry)
hlsl_free_type(type);
+
+ LIST_FOR_EACH_ENTRY_SAFE(buffer, next_buffer, &ctx->buffers, struct hlsl_buffer, entry)
+ {
+ vkd3d_free((void *)buffer->name);
+ vkd3d_free(buffer);
+ }
}
int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d_shader_compile_info *compile_info,
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index b159cbb..16ec976 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -417,6 +417,21 @@ struct hlsl_vec4
float f[4];
};
+enum hlsl_buffer_type
+{
+ HLSL_BUFFER_CONSTANT,
+ HLSL_BUFFER_TEXTURE,
+};
+
+struct hlsl_buffer
+{
+ struct vkd3d_shader_location loc;
+ enum hlsl_buffer_type type;
+ const char *name;
+ struct hlsl_reg_reservation reservation;
+ struct list entry;
+};
+
struct hlsl_ctx
{
const struct hlsl_profile_info *profile;
@@ -435,6 +450,7 @@ struct hlsl_ctx
struct list scopes;
struct list extern_vars;
+ struct list buffers;
struct list types;
struct rb_tree functions;
const struct hlsl_ir_function_decl *cur_function;
@@ -609,6 +625,8 @@ struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *ba
unsigned int array_size) DECLSPEC_HIDDEN;
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN;
+struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name,
+ const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
struct vkd3d_shader_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 1a102a5..6f83648 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1561,6 +1561,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
struct hlsl_reg_reservation reg_reservation;
struct parse_colon_attribute colon_attribute;
struct hlsl_semantic semantic;
+ enum hlsl_buffer_type buffer_type;
}
%token KW_BLENDSTATE
@@ -1711,6 +1712,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
%type <boolval> boolean
+%type <buffer_type> buffer_type
+
%type <colon_attribute> colon_attribute
%type <function> func_declaration
@@ -1776,6 +1779,7 @@ hlsl_prog:
hlsl_add_function(ctx, $2.name, $2.decl, false);
}
+ | hlsl_prog buffer_declaration
| hlsl_prog declaration_statement
{
if (!list_empty($2))
@@ -1785,6 +1789,32 @@ hlsl_prog:
| hlsl_prog preproc_directive
| hlsl_prog ';'
+buffer_declaration:
+ buffer_type any_identifier colon_attribute '{' declaration_statement_list '}'
+ {
+ struct hlsl_buffer *buffer;
+
+ if ($3.semantic.name)
+ hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC, "Semantics are not allowed on buffers.");
+
+ if (!(buffer = hlsl_new_buffer(ctx, $1, $2, &$3.reg_reservation, @2)))
+ YYABORT;
+ }
+
+buffer_type:
+ KW_CBUFFER
+ {
+ $$ = HLSL_BUFFER_CONSTANT;
+ }
+ | KW_TBUFFER
+ {
+ $$ = HLSL_BUFFER_TEXTURE;
+ }
+
+declaration_statement_list:
+ declaration_statement
+ | declaration_statement_list declaration_statement
+
preproc_directive:
PRE_LINE STRING
{
More information about the wine-cvs
mailing list