mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-09-13 09:17:20 -07:00
Updated vkd3d-latest patchset
This commit is contained in:
parent
453c5cda07
commit
d44a516142
@ -0,0 +1,336 @@
|
||||
From 65a602939e9306618d1ec33d19b217b869638beb Mon Sep 17 00:00:00 2001
|
||||
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
|
||||
Date: Thu, 8 Jun 2023 14:11:22 +1000
|
||||
Subject: [PATCH] Updated vkd3d to ebf7573571d4bfcd3f38846886106f204fd7f0e8
|
||||
|
||||
---
|
||||
libs/vkd3d/libs/vkd3d-shader/hlsl.c | 13 ++
|
||||
libs/vkd3d/libs/vkd3d-shader/hlsl.h | 2 +
|
||||
libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c | 209 ++++++++++++++++----
|
||||
3 files changed, 191 insertions(+), 33 deletions(-)
|
||||
|
||||
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.c b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
|
||||
index 152ec6275eb..f1edfa5e625 100644
|
||||
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.c
|
||||
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
|
||||
@@ -1287,6 +1287,19 @@ struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl
|
||||
return load;
|
||||
}
|
||||
|
||||
+struct hlsl_ir_load *hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
|
||||
+ const struct vkd3d_shader_location *loc)
|
||||
+{
|
||||
+ /* This deref can only exists temporarily because it is not the real owner of its members. */
|
||||
+ struct hlsl_deref tmp_deref;
|
||||
+
|
||||
+ assert(deref->path_len >= 1);
|
||||
+
|
||||
+ tmp_deref = *deref;
|
||||
+ tmp_deref.path_len = deref->path_len - 1;
|
||||
+ return hlsl_new_load_index(ctx, &tmp_deref, NULL, loc);
|
||||
+}
|
||||
+
|
||||
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
|
||||
const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.h b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
|
||||
index 6b79c582f55..14037a4a96f 100644
|
||||
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.h
|
||||
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
|
||||
@@ -1129,6 +1129,8 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var
|
||||
const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
|
||||
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc);
|
||||
+struct hlsl_ir_load *hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
|
||||
+ const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc);
|
||||
|
||||
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
|
||||
index 2b6c595a15d..72ab27d3b80 100644
|
||||
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
|
||||
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
|
||||
@@ -123,15 +123,14 @@ static struct hlsl_ir_node *new_offset_instr_from_deref(struct hlsl_ctx *ctx, st
|
||||
}
|
||||
|
||||
/* TODO: remove when no longer needed, only used for transform_deref_paths_into_offsets() */
|
||||
-static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_deref *deref,
|
||||
+static bool replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_deref *deref,
|
||||
struct hlsl_ir_node *instr)
|
||||
{
|
||||
const struct hlsl_type *type;
|
||||
struct hlsl_ir_node *offset;
|
||||
struct hlsl_block block;
|
||||
|
||||
- if (!deref->var)
|
||||
- return;
|
||||
+ assert(deref->var);
|
||||
|
||||
/* register offsets shouldn't be used before this point is reached. */
|
||||
assert(!deref->offset.node);
|
||||
@@ -143,45 +142,19 @@ static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_der
|
||||
if (type->class == HLSL_CLASS_STRUCT || type->class == HLSL_CLASS_ARRAY)
|
||||
{
|
||||
hlsl_cleanup_deref(deref);
|
||||
- return;
|
||||
+ return true;
|
||||
}
|
||||
|
||||
deref->offset_regset = hlsl_type_get_regset(type);
|
||||
|
||||
if (!(offset = new_offset_instr_from_deref(ctx, &block, deref, &instr->loc)))
|
||||
- return;
|
||||
+ return false;
|
||||
list_move_before(&instr->entry, &block.instrs);
|
||||
|
||||
hlsl_cleanup_deref(deref);
|
||||
hlsl_src_from_node(&deref->offset, offset);
|
||||
-}
|
||||
|
||||
-/* TODO: remove when no longer needed. */
|
||||
-static bool transform_deref_paths_into_offsets(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
-{
|
||||
- switch(instr->type)
|
||||
- {
|
||||
- case HLSL_IR_LOAD:
|
||||
- replace_deref_path_with_offset(ctx, &hlsl_ir_load(instr)->src, instr);
|
||||
- return true;
|
||||
-
|
||||
- case HLSL_IR_STORE:
|
||||
- replace_deref_path_with_offset(ctx, &hlsl_ir_store(instr)->lhs, instr);
|
||||
- return true;
|
||||
-
|
||||
- case HLSL_IR_RESOURCE_LOAD:
|
||||
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_load(instr)->resource, instr);
|
||||
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_load(instr)->sampler, instr);
|
||||
- return true;
|
||||
-
|
||||
- case HLSL_IR_RESOURCE_STORE:
|
||||
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_store(instr)->resource, instr);
|
||||
- return true;
|
||||
-
|
||||
- default:
|
||||
- return false;
|
||||
- }
|
||||
- return false;
|
||||
+ return true;
|
||||
}
|
||||
|
||||
/* Split uniforms into two variables representing the constant and temp
|
||||
@@ -600,6 +573,44 @@ bool hlsl_transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx,
|
||||
return progress;
|
||||
}
|
||||
|
||||
+static bool transform_instr_derefs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
+{
|
||||
+ bool res;
|
||||
+ bool (*func)(struct hlsl_ctx *ctx, struct hlsl_deref *, struct hlsl_ir_node *) = context;
|
||||
+
|
||||
+ switch(instr->type)
|
||||
+ {
|
||||
+ case HLSL_IR_LOAD:
|
||||
+ res = func(ctx, &hlsl_ir_load(instr)->src, instr);
|
||||
+ return res;
|
||||
+
|
||||
+ case HLSL_IR_STORE:
|
||||
+ res = func(ctx, &hlsl_ir_store(instr)->lhs, instr);
|
||||
+ return res;
|
||||
+
|
||||
+ case HLSL_IR_RESOURCE_LOAD:
|
||||
+ res = func(ctx, &hlsl_ir_resource_load(instr)->resource, instr);
|
||||
+ if (hlsl_ir_resource_load(instr)->sampler.var)
|
||||
+ res |= func(ctx, &hlsl_ir_resource_load(instr)->sampler, instr);
|
||||
+ return res;
|
||||
+
|
||||
+ case HLSL_IR_RESOURCE_STORE:
|
||||
+ res = func(ctx, &hlsl_ir_resource_store(instr)->resource, instr);
|
||||
+ return res;
|
||||
+
|
||||
+ default:
|
||||
+ return false;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
+static bool transform_derefs(struct hlsl_ctx *ctx,
|
||||
+ bool (*func)(struct hlsl_ctx *ctx, struct hlsl_deref *, struct hlsl_ir_node *),
|
||||
+ struct hlsl_block *block)
|
||||
+{
|
||||
+ return hlsl_transform_ir(ctx, transform_instr_derefs, block, func);
|
||||
+}
|
||||
+
|
||||
struct recursive_call_ctx
|
||||
{
|
||||
const struct hlsl_ir_function_decl **backtrace;
|
||||
@@ -1981,6 +1992,81 @@ static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *i
|
||||
return true;
|
||||
}
|
||||
|
||||
+static bool lower_nonconstant_vector_derefs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
+{
|
||||
+ struct hlsl_ir_node *idx;
|
||||
+ struct hlsl_deref *deref;
|
||||
+ struct hlsl_type *type;
|
||||
+ unsigned int i;
|
||||
+
|
||||
+ if (instr->type != HLSL_IR_LOAD)
|
||||
+ return false;
|
||||
+
|
||||
+ deref = &hlsl_ir_load(instr)->src;
|
||||
+ assert(deref->var);
|
||||
+
|
||||
+ if (deref->path_len == 0)
|
||||
+ return false;
|
||||
+
|
||||
+ type = deref->var->data_type;
|
||||
+ for (i = 0; i < deref->path_len - 1; ++i)
|
||||
+ type = hlsl_get_element_type_from_path_index(ctx, type, deref->path[i].node);
|
||||
+
|
||||
+ idx = deref->path[deref->path_len - 1].node;
|
||||
+
|
||||
+ if (type->class == HLSL_CLASS_VECTOR && idx->type != HLSL_IR_CONSTANT)
|
||||
+ {
|
||||
+ struct hlsl_ir_node *eq, *swizzle, *dot, *operands[HLSL_MAX_OPERANDS] = {0};
|
||||
+ struct hlsl_ir_load *vector_load;
|
||||
+ struct hlsl_ir_constant *c;
|
||||
+ enum hlsl_ir_expr_op op;
|
||||
+
|
||||
+ if (!(vector_load = hlsl_new_load_parent(ctx, deref, &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &vector_load->node.entry);
|
||||
+
|
||||
+ if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), type->dimx, idx, &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &swizzle->entry);
|
||||
+
|
||||
+ if (!(c = hlsl_new_constant(ctx, hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, type->dimx), &instr->loc)))
|
||||
+ return false;
|
||||
+ c->value.u[0].u = 0;
|
||||
+ c->value.u[1].u = 1;
|
||||
+ c->value.u[2].u = 2;
|
||||
+ c->value.u[3].u = 3;
|
||||
+ list_add_before(&instr->entry, &c->node.entry);
|
||||
+
|
||||
+ operands[0] = swizzle;
|
||||
+ operands[1] = &c->node;
|
||||
+ if (!(eq = hlsl_new_expr(ctx, HLSL_OP2_EQUAL, operands,
|
||||
+ hlsl_get_vector_type(ctx, HLSL_TYPE_BOOL, type->dimx), &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &eq->entry);
|
||||
+
|
||||
+ if (!(eq = hlsl_new_cast(ctx, eq, type, &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &eq->entry);
|
||||
+
|
||||
+ op = HLSL_OP2_DOT;
|
||||
+ if (type->dimx == 1)
|
||||
+ op = type->base_type == HLSL_TYPE_BOOL ? HLSL_OP2_LOGIC_AND : HLSL_OP2_MUL;
|
||||
+
|
||||
+ /* Note: We may be creating a DOT for bool vectors here, which we need to lower to
|
||||
+ * LOGIC_OR + LOGIC_AND. */
|
||||
+ operands[0] = &vector_load->node;
|
||||
+ operands[1] = eq;
|
||||
+ if (!(dot = hlsl_new_expr(ctx, op, operands, instr->data_type, &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &dot->entry);
|
||||
+ hlsl_replace_node(instr, dot);
|
||||
+
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
/* Lower DIV to RCP + MUL. */
|
||||
static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
{
|
||||
@@ -2378,6 +2464,58 @@ static bool lower_int_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
|
||||
return true;
|
||||
}
|
||||
|
||||
+static bool lower_int_dot(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
+{
|
||||
+ struct hlsl_ir_node *arg1, *arg2, *mult, *comps[4] = {0}, *res;
|
||||
+ struct hlsl_type *type = instr->data_type;
|
||||
+ struct hlsl_ir_expr *expr;
|
||||
+ unsigned int i, dimx;
|
||||
+ bool is_bool;
|
||||
+
|
||||
+ if (instr->type != HLSL_IR_EXPR)
|
||||
+ return false;
|
||||
+ expr = hlsl_ir_expr(instr);
|
||||
+
|
||||
+ if (expr->op != HLSL_OP2_DOT)
|
||||
+ return false;
|
||||
+
|
||||
+ if (type->base_type == HLSL_TYPE_INT || type->base_type == HLSL_TYPE_UINT
|
||||
+ || type->base_type == HLSL_TYPE_BOOL)
|
||||
+ {
|
||||
+ arg1 = expr->operands[0].node;
|
||||
+ arg2 = expr->operands[1].node;
|
||||
+ assert(arg1->data_type->dimx == arg2->data_type->dimx);
|
||||
+ dimx = arg1->data_type->dimx;
|
||||
+ is_bool = type->base_type == HLSL_TYPE_BOOL;
|
||||
+
|
||||
+ if (!(mult = hlsl_new_binary_expr(ctx, is_bool ? HLSL_OP2_LOGIC_AND : HLSL_OP2_MUL, arg1, arg2)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &mult->entry);
|
||||
+
|
||||
+ for (i = 0; i < dimx; ++i)
|
||||
+ {
|
||||
+ unsigned int s = hlsl_swizzle_from_writemask(1 << i);
|
||||
+
|
||||
+ if (!(comps[i] = hlsl_new_swizzle(ctx, s, 1, mult, &instr->loc)))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &comps[i]->entry);
|
||||
+ }
|
||||
+
|
||||
+ res = comps[0];
|
||||
+ for (i = 1; i < dimx; ++i)
|
||||
+ {
|
||||
+ if (!(res = hlsl_new_binary_expr(ctx, is_bool ? HLSL_OP2_LOGIC_OR : HLSL_OP2_ADD, res, comps[i])))
|
||||
+ return false;
|
||||
+ list_add_before(&instr->entry, &res->entry);
|
||||
+ }
|
||||
+
|
||||
+ hlsl_replace_node(instr, res);
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
{
|
||||
struct hlsl_ir_node *arg1, *arg2, *mul1, *neg1, *ge, *neg2, *div, *mul2, *frc, *cond;
|
||||
@@ -3925,6 +4063,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
|
||||
hlsl_transform_ir(ctx, lower_narrowing_casts, body, NULL);
|
||||
hlsl_transform_ir(ctx, lower_casts_to_bool, body, NULL);
|
||||
+ hlsl_transform_ir(ctx, lower_int_dot, body, NULL);
|
||||
hlsl_transform_ir(ctx, lower_int_division, body, NULL);
|
||||
hlsl_transform_ir(ctx, lower_int_modulus, body, NULL);
|
||||
hlsl_transform_ir(ctx, lower_int_abs, body, NULL);
|
||||
@@ -3939,6 +4078,10 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
}
|
||||
while (progress);
|
||||
|
||||
+ hlsl_transform_ir(ctx, lower_nonconstant_vector_derefs, body, NULL);
|
||||
+ hlsl_transform_ir(ctx, lower_casts_to_bool, body, NULL);
|
||||
+ hlsl_transform_ir(ctx, lower_int_dot, body, NULL);
|
||||
+
|
||||
if (profile->major_version < 4)
|
||||
{
|
||||
hlsl_transform_ir(ctx, lower_division, body, NULL);
|
||||
@@ -3956,7 +4099,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
hlsl_transform_ir(ctx, track_object_components_usage, body, NULL);
|
||||
|
||||
/* TODO: move forward, remove when no longer needed */
|
||||
- hlsl_transform_ir(ctx, transform_deref_paths_into_offsets, body, NULL);
|
||||
+ transform_derefs(ctx, replace_deref_path_with_offset, body);
|
||||
while (hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL));
|
||||
|
||||
do
|
||||
--
|
||||
2.40.1
|
||||
|
Loading…
Reference in New Issue
Block a user