mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-09-13 09:16:14 -07:00
vkd3d-shader/hlsl: Use values at the time of the swizzle's load in copy-propagation.
This preempts us from replacing a swizzle incorrectly, as in the following example: 1: A.x = 1.0 2: A 3: A.x = 2.0 4: @2.x were @4 ends up being 2.0 instead of 1.0, because that's the value stored in A.x at time 4, and we should be querying it at time 2. This also helps us to avoid replacing a swizzle with itself in copy-prop which can result in infinite loops, as with the included tests this commit. Consider the following sequence of instructions: 1 : A 2 : B = @1 3 : B 4 : A = @3 5 : @1.x Current copy-prop would replace 5 so it points to @3 now: 1 : A 2 : B = @1 3 : B 4 : A = @3 5 : @3.x But in the next iteration it would make it point back to @1, keeping it spinning infinitively. The solution is to index the instructions and don't replace the swizzle if the new load happens after the current load.
This commit is contained in:
parent
d877b877b3
commit
736f3ae2df
Notes:
Alexandre Julliard
2023-11-29 23:19:07 +01:00
Approved-by: Zebediah Figura (@zfigura) Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/487
@ -1518,12 +1518,14 @@ static void copy_propagation_set_value(struct hlsl_ctx *ctx, struct copy_propaga
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx,
|
static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx,
|
||||||
const struct copy_propagation_state *state, const struct hlsl_deref *deref,
|
const struct copy_propagation_state *state, const struct hlsl_ir_load *load,
|
||||||
unsigned int swizzle, struct hlsl_ir_node *instr)
|
unsigned int swizzle, struct hlsl_ir_node *instr)
|
||||||
{
|
{
|
||||||
const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type);
|
const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type);
|
||||||
|
const struct hlsl_deref *deref = &load->src;
|
||||||
const struct hlsl_ir_var *var = deref->var;
|
const struct hlsl_ir_var *var = deref->var;
|
||||||
struct hlsl_ir_node *new_instr = NULL;
|
struct hlsl_ir_node *new_instr = NULL;
|
||||||
|
unsigned int time = load->node.index;
|
||||||
unsigned int start, count, i;
|
unsigned int start, count, i;
|
||||||
unsigned int ret_swizzle = 0;
|
unsigned int ret_swizzle = 0;
|
||||||
|
|
||||||
@ -1535,7 +1537,7 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx,
|
|||||||
struct copy_propagation_value *value;
|
struct copy_propagation_value *value;
|
||||||
|
|
||||||
if (!(value = copy_propagation_get_value(state, var, start + hlsl_swizzle_get_component(swizzle, i),
|
if (!(value = copy_propagation_get_value(state, var, start + hlsl_swizzle_get_component(swizzle, i),
|
||||||
instr->index)))
|
time)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!new_instr)
|
if (!new_instr)
|
||||||
@ -1570,12 +1572,14 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx,
|
static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx,
|
||||||
const struct copy_propagation_state *state, const struct hlsl_deref *deref,
|
const struct copy_propagation_state *state, const struct hlsl_ir_load *load,
|
||||||
unsigned int swizzle, struct hlsl_ir_node *instr)
|
unsigned int swizzle, struct hlsl_ir_node *instr)
|
||||||
{
|
{
|
||||||
const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type);
|
const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type);
|
||||||
|
const struct hlsl_deref *deref = &load->src;
|
||||||
const struct hlsl_ir_var *var = deref->var;
|
const struct hlsl_ir_var *var = deref->var;
|
||||||
struct hlsl_constant_value values = {0};
|
struct hlsl_constant_value values = {0};
|
||||||
|
unsigned int time = load->node.index;
|
||||||
unsigned int start, count, i;
|
unsigned int start, count, i;
|
||||||
struct hlsl_ir_node *cons;
|
struct hlsl_ir_node *cons;
|
||||||
|
|
||||||
@ -1587,7 +1591,7 @@ static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx,
|
|||||||
struct copy_propagation_value *value;
|
struct copy_propagation_value *value;
|
||||||
|
|
||||||
if (!(value = copy_propagation_get_value(state, var, start + hlsl_swizzle_get_component(swizzle, i),
|
if (!(value = copy_propagation_get_value(state, var, start + hlsl_swizzle_get_component(swizzle, i),
|
||||||
instr->index)) || value->node->type != HLSL_IR_CONSTANT)
|
time)) || value->node->type != HLSL_IR_CONSTANT)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
values.u[i] = hlsl_ir_constant(value->node)->value.u[value->component];
|
values.u[i] = hlsl_ir_constant(value->node)->value.u[value->component];
|
||||||
@ -1624,10 +1628,10 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_propagation_replace_with_constant_vector(ctx, state, &load->src, HLSL_SWIZZLE(X, Y, Z, W), &load->node))
|
if (copy_propagation_replace_with_constant_vector(ctx, state, load, HLSL_SWIZZLE(X, Y, Z, W), &load->node))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (copy_propagation_replace_with_single_instr(ctx, state, &load->src, HLSL_SWIZZLE(X, Y, Z, W), &load->node))
|
if (copy_propagation_replace_with_single_instr(ctx, state, load, HLSL_SWIZZLE(X, Y, Z, W), &load->node))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1642,10 +1646,10 @@ static bool copy_propagation_transform_swizzle(struct hlsl_ctx *ctx,
|
|||||||
return false;
|
return false;
|
||||||
load = hlsl_ir_load(swizzle->val.node);
|
load = hlsl_ir_load(swizzle->val.node);
|
||||||
|
|
||||||
if (copy_propagation_replace_with_constant_vector(ctx, state, &load->src, swizzle->swizzle, &swizzle->node))
|
if (copy_propagation_replace_with_constant_vector(ctx, state, load, swizzle->swizzle, &swizzle->node))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (copy_propagation_replace_with_single_instr(ctx, state, &load->src, swizzle->swizzle, &swizzle->node))
|
if (copy_propagation_replace_with_single_instr(ctx, state, load, swizzle->swizzle, &swizzle->node))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,7 +18,58 @@ float4 main() : sv_target
|
|||||||
[test]
|
[test]
|
||||||
uniform 0 float 0.0
|
uniform 0 float 0.0
|
||||||
draw quad
|
draw quad
|
||||||
todo(sm<6) probe all rgba (2.0, 2.0, 2.0, 2.0)
|
probe all rgba (2.0, 2.0, 2.0, 2.0)
|
||||||
uniform 0 float 1.0
|
uniform 0 float 1.0
|
||||||
draw quad
|
draw quad
|
||||||
todo(sm<6) probe all rgba (-2.0, -2.0, -2.0, -2.0)
|
probe all rgba (-2.0, -2.0, -2.0, -2.0)
|
||||||
|
|
||||||
|
|
||||||
|
[pixel shader]
|
||||||
|
float cond;
|
||||||
|
|
||||||
|
float4 main() : sv_target
|
||||||
|
{
|
||||||
|
float2 r = {1, 2};
|
||||||
|
float2 tmp;
|
||||||
|
|
||||||
|
// invalidate r
|
||||||
|
if (cond)
|
||||||
|
r = float2(10, 20);
|
||||||
|
|
||||||
|
tmp = r;
|
||||||
|
r = tmp;
|
||||||
|
return r.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
[test]
|
||||||
|
uniform 0 float 0.0
|
||||||
|
draw quad
|
||||||
|
probe all rgba (2.0, 2.0, 2.0, 2.0)
|
||||||
|
uniform 0 float 1.0
|
||||||
|
draw quad
|
||||||
|
probe all rgba (20.0, 20.0, 20.0, 20.0)
|
||||||
|
|
||||||
|
|
||||||
|
[pixel shader]
|
||||||
|
float cond;
|
||||||
|
|
||||||
|
float4 main() : sv_target
|
||||||
|
{
|
||||||
|
float2 r = {3, 4};
|
||||||
|
|
||||||
|
// invalidate r
|
||||||
|
if (cond)
|
||||||
|
r = float2(30, 40);
|
||||||
|
|
||||||
|
r = r;
|
||||||
|
r = float2(1, r.y);
|
||||||
|
|
||||||
|
return float4(r, 0, 0);
|
||||||
|
}
|
||||||
|
[test]
|
||||||
|
uniform 0 float 0.0
|
||||||
|
draw quad
|
||||||
|
probe all rgba (1.0, 4.0, 0.0, 0.0)
|
||||||
|
uniform 0 float 1.0
|
||||||
|
draw quad
|
||||||
|
probe all rgba (1.0, 40.0, 0.0, 0.0)
|
||||||
|
Loading…
Reference in New Issue
Block a user