Skip to content
Snippets Groups Projects
Commit 17d6a441 authored by Francisco Casas's avatar Francisco Casas Committed by Alexandre Julliard
Browse files

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.
parent 97c96695
No related branches found
No related tags found
1 merge request!54vkd3d-shader/hlsl: Initialize static variables to 0 by default.
......@@ -1009,26 +1009,45 @@ 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)
{
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF,
"Resource load sampler from \"%s\" must be determinable at compile time.",
load->sampler.var->name);
note_non_static_deref_expressions(ctx, &load->sampler, "resource load sampler");
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.",
load->sampler.var->name);
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.",
......
......@@ -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;
......
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