Skip to content
Snippets Groups Projects
Commit ea848f5a authored by Francisco Casas's avatar Francisco Casas
Browse files

vkd3d-shader/hlsl: Support indexing non-load expressions.

by replacing the value pointer of the last index in the chain with a
load to a synthetic variable that holds the value.
parent 82ab1c2f
No related branches found
Tags wine-0.9.54
No related merge requests found
......@@ -731,6 +731,51 @@ static bool lower_calls(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *
return true;
}
/* In some cases, hlsl_ir_index chains may not end up in an hlsl_ir_load, for instance, consider the
* expression:
*
* (a + b)[1]
*
* To ensure that the index chains always end up in a hlsl_ir_load, so that each index can be turned
* into a single hlsl_ir_load later, the value of the instruction at the end of the index chain is
* stored into a synthetic variable and the last index in the chain is modified to point to it. */
static bool copy_index_values(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_index *index;
struct hlsl_ir_node *val;
if (instr->type != HLSL_IR_INDEX)
return false;
index = hlsl_ir_index(instr);
val = index->val.node;
if (val->type != HLSL_IR_INDEX && val->type != HLSL_IR_LOAD)
{
struct hlsl_ir_store *store;
struct hlsl_ir_load *load;
struct hlsl_ir_var *var;
if (!(var = hlsl_new_synthetic_var(ctx, "index-val", val->data_type, &val->loc)))
return false;
if (!(store = hlsl_new_simple_store(ctx, var, val)))
return false;
list_add_before(&instr->entry, &store->node.entry);
if (!(load = hlsl_new_var_load(ctx, var, instr->loc)))
return false;
list_add_before(&instr->entry, &load->node.entry);
hlsl_src_remove(&index->val);
hlsl_src_from_node(&index->val, &load->node);
return true;
}
return false;
}
/* hlsl_ir_index nodes are a parse-time construct used to represent array indexing and struct
* record access before knowing if they will be used in the lhs of an assignment --in which case
* they are lowered into a deref-- or as the load of an element within a larger value.
......@@ -3333,6 +3378,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
while (transform_ir(ctx, lower_calls, body, NULL));
transform_ir(ctx, copy_index_values, body, NULL);
while (transform_ir(ctx, lower_index_loads, body, NULL));
LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry)
......
[pixel shader todo]
[pixel shader]
float4 a, b;
float4 main() : sv_target
......@@ -9,8 +9,8 @@ float4 main() : sv_target
[test]
uniform 0 float4 1.0 2.0 3.0 4.0
uniform 4 float4 5.0 6.0 7.0 8.0
todo draw quad
todo probe all rgba (8.0, 8.0, 8.0, 8.0)
draw quad
probe all rgba (8.0, 8.0, 8.0, 8.0)
[pixel shader todo]
......@@ -30,7 +30,7 @@ todo draw quad
todo probe all rgba (10.0, 10.0, 10.0, 10.0)
[pixel shader todo]
[pixel shader]
float4 a;
int i;
......@@ -41,8 +41,8 @@ float4 main() : sv_target
[test]
uniform 0 float4 1.0 2.0 3.0 4.0
todo draw quad
todo probe all rgba (3.0, 3.0, 3.0, 3.0)
draw quad
probe all rgba (3.0, 3.0, 3.0, 3.0)
[pixel shader todo]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment