From: Francisco Casas fcasas@codeweavers.com
Note that in the future we should call validate_static_object_references() after dce, and dce has to be able to delete resource stores and resource loads, because shaders such as this compile (at least in 10.0.10011.16384):
``` static Texture2D tex[2]; uniform int i;
float4 main() : sv_target { if (0) return tex[i].Load(int3(0, 0, 0)); else return float4(0, 1, 2, 3); } ```
The same for some of the "todo" tests in hlsl-static-initializer.shader_test.
Doing this requires to move `transform_deref_paths_into_offsets` after `dce`, which implies translating `compute_liveness` and `dce` to index paths.
An alternative course of action is to write the checks in hlsl_sm1.c and hlsl_sm4_write.c instead. --- libs/vkd3d-shader/hlsl.y | 1 - libs/vkd3d-shader/hlsl_codegen.c | 30 ++++++++++++++++++++--- tests/hlsl-static-initializer.shader_test | 4 +-- 3 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 91bc3192..0b6eb105 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2176,7 +2176,6 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (type_has_object_components(var->data_type, false)) { - hlsl_fixme(ctx, &var->loc, "Uninitialized static objects."); vkd3d_free(v); continue; } diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 6e4168fc..33fc8754 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1016,12 +1016,28 @@ static bool validate_static_object_references(struct hlsl_ctx *ctx, struct hlsl_ 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)) + else if (load->resource.var->modifiers & HLSL_STORAGE_STATIC) { 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"); + "Loaded resource from static variable "%s" must be initialized.", + load->resource.var->name); + } + + if (load->sampler.var) + { + 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 (load->sampler.var->modifiers & HLSL_STORAGE_STATIC) + { + hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF, + "Loaded sampler from static variable "%s" must be initialized.", + load->sampler.var->name); + } } } else if (instr->type == HLSL_IR_RESOURCE_STORE) @@ -1035,6 +1051,12 @@ static bool validate_static_object_references(struct hlsl_ctx *ctx, struct hlsl_ store->resource.var->name); note_non_static_deref_expressions(ctx, &store->resource, "accessed resource"); } + else if (store->resource.var->modifiers & HLSL_STORAGE_STATIC) + { + hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NON_STATIC_OBJECT_REF, + "Accesed resource from static variable "%s" must be initialized.", + store->resource.var->name); + } }
return false; diff --git a/tests/hlsl-static-initializer.shader_test b/tests/hlsl-static-initializer.shader_test index 65ae23eb..2ad11eab 100644 --- a/tests/hlsl-static-initializer.shader_test +++ b/tests/hlsl-static-initializer.shader_test @@ -25,7 +25,7 @@ float4 main() : sv_target }
-[pixel shader fail todo] +[pixel shader fail] static Texture2D tex;
float4 main() : sv_target @@ -34,7 +34,7 @@ float4 main() : sv_target }
-[pixel shader todo] +[pixel shader] // This is allowed in 10.0.10011.16384 but not in 9.29.952.3111 static Texture2D tex;