vkd3d-shader/hlsl: Don't invalidate OOB constant derefs.

This commit is contained in:
Elizabeth Figura 2025-03-10 16:51:20 -05:00 committed by Henri Verbeet
parent 193e40c271
commit a87b1efbd2
Notes: Henri Verbeet 2025-03-12 22:21:25 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1415
2 changed files with 30 additions and 2 deletions

View File

@ -1627,9 +1627,18 @@ static void copy_propagation_invalidate_variable_from_deref_recurse(struct hlsl_
if (path_node->type == HLSL_IR_CONSTANT)
{
uint32_t index = hlsl_ir_constant(path_node)->value.u[0].u;
/* Don't bother invalidating anything if the index is constant but
* out-of-range.
* Such indices are illegal in HLSL, but only if the code is not
* dead, and we can't always know if code is dead without copy-prop
* itself. */
if (index >= hlsl_type_element_count(type))
return;
copy_propagation_invalidate_variable_from_deref_recurse(ctx, var_def, deref, subtype,
depth + 1, hlsl_ir_constant(path_node)->value.u[0].u * subtype_comp_count,
writemask, time);
depth + 1, index * subtype_comp_count, writemask, time);
}
else
{

View File

@ -186,3 +186,22 @@ if(sm<4) uniform 8 float4 1 0 0 0
if(sm>=4) uniform 8 uint4 1 0 0 0
todo(msl) draw quad
probe (0, 0) rgba(3.0, 3.0, 3.0, 3.0)
% OOB indexes are illegal, but sm < 6 allows them in dead code.
% We need copy-prop to know if the code is dead.
% This means copy-prop needs to be able to handle OOB indexes.
[pixel shader fail(sm>=6)]
float4 main() : sv_target
{
static float4 arr[4];
bool x = false;
if (x)
{
arr[100] = 0;
return arr[100];
}
return 0;
}