From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com --- v2: - Use switch statement in hlsl_type_component_count(). --- libs/vkd3d-shader/hlsl.c | 41 +++++++++++++--------- tests/hlsl-initializer-objects.shader_test | 4 +-- 2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 01709c8c..e5b2e8e4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -548,25 +548,32 @@ struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const cha
unsigned int hlsl_type_component_count(const struct hlsl_type *type) { - unsigned int count = 0, i; - - if (type->type <= HLSL_CLASS_LAST_NUMERIC) - { - return type->dimx * type->dimy; - } - if (type->type == HLSL_CLASS_ARRAY) - { - return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count; - } - if (type->type != HLSL_CLASS_STRUCT) + switch (type->type) { - ERR("Unexpected data type %#x.\n", type->type); - return 0; - } + case HLSL_CLASS_SCALAR: + case HLSL_CLASS_VECTOR: + case HLSL_CLASS_MATRIX: + return type->dimx * type->dimy; + + case HLSL_CLASS_STRUCT: + { + unsigned int count = 0, i; + + for (i = 0; i < type->e.record.field_count; ++i) + count += hlsl_type_component_count(type->e.record.fields[i].type); + return count; + } + + case HLSL_CLASS_ARRAY: + return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
- for (i = 0; i < type->e.record.field_count; ++i) - count += hlsl_type_component_count(type->e.record.fields[i].type); - return count; + case HLSL_CLASS_OBJECT: + return 1; + + default: + assert(0); + return 0; + } }
bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2) diff --git a/tests/hlsl-initializer-objects.shader_test b/tests/hlsl-initializer-objects.shader_test index 2306d07f..70f060c2 100644 --- a/tests/hlsl-initializer-objects.shader_test +++ b/tests/hlsl-initializer-objects.shader_test @@ -71,7 +71,7 @@ float4 main() : sv_target }
-[pixel shader fail todo] +[pixel shader fail] Texture2D tex;
struct foo @@ -90,7 +90,7 @@ float4 main() : sv_target }
-[pixel shader fail todo] +[pixel shader fail] Texture2D tex;
struct foo