vkd3d-shader/hlsl: Validate that non-uniform objects are not referenced.

Note that in the future we should call
validate_static_object_references() after DCE and pruning branches,
because shaders such as these compile (at least in more modern versions
of the native compiler):

Branch pruning:
```
static RWTexture2D<float> tex;

float4 main() : sv_target
{
    if (0)
    {
        tex[int2(0, 0)] = 2;
    }
    return 0;
}
```

DCE:
```
static Texture2D tex;
uniform uint i;

float4 main() : sv_target
{
    float4 unused = tex.Load(int3(0, 1, 2));

    return 0;
}
```

These are "todo" tests in hlsl-static-initializer.shader_test
that depend on this.
This commit is contained in:
Francisco Casas 2022-12-05 21:48:28 -03:00 committed by Alexandre Julliard
parent 97c9669544
commit 17d6a4411e
Notes: Alexandre Julliard 2023-01-19 22:45:10 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/54
2 changed files with 27 additions and 8 deletions

View File

@ -1009,14 +1009,27 @@ static bool validate_static_object_references(struct hlsl_ctx *ctx, struct hlsl_
{
struct hlsl_ir_resource_load *load = hlsl_ir_resource_load(instr);
if (!hlsl_component_index_range_from_deref(ctx, &load->resource, &start, &count))
if (!(load->resource.var->storage_modifiers & HLSL_STORAGE_UNIFORM))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Loaded resource must have a single uniform source.");
}
else if (!hlsl_component_index_range_from_deref(ctx, &load->resource, &start, &count))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Loaded resource from \"%s\" must be determinable at compile time.",
load->resource.var->name);
note_non_static_deref_expressions(ctx, &load->resource, "loaded resource");
}
if (load->sampler.var && !hlsl_component_index_range_from_deref(ctx, &load->sampler, &start, &count))
if (load->sampler.var)
{
if (!(load->sampler.var->storage_modifiers & HLSL_STORAGE_UNIFORM))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Resource load sampler must have a single uniform source.");
}
else if (!hlsl_component_index_range_from_deref(ctx, &load->sampler, &start, &count))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Resource load sampler from \"%s\" must be determinable at compile time.",
@ -1024,11 +1037,17 @@ static bool validate_static_object_references(struct hlsl_ctx *ctx, struct hlsl_
note_non_static_deref_expressions(ctx, &load->sampler, "resource load sampler");
}
}
}
else if (instr->type == HLSL_IR_RESOURCE_STORE)
{
struct hlsl_ir_resource_store *store = hlsl_ir_resource_store(instr);
if (!hlsl_component_index_range_from_deref(ctx, &store->resource, &start, &count))
if (!(store->resource.var->storage_modifiers & HLSL_STORAGE_UNIFORM))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Accessed resource must have a single uniform source.");
}
else if (!hlsl_component_index_range_from_deref(ctx, &store->resource, &start, &count))
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Accessed resource from \"%s\" must be determinable at compile time.",

View File

@ -157,7 +157,7 @@ todo draw quad
todo probe (0, 0) rgba (11.0, 12.0, 13.0, 11.0)
[pixel shader fail todo]
[pixel shader fail]
float4 main(Texture2D tex2) : sv_target
{
Texture2D tex1;