diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d41da128..c39f2020 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5346,11 +5346,6 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block, } else { - cond_type = hlsl_get_numeric_type(ctx, cond_type->class, HLSL_TYPE_BOOL, - cond_type->dimx, cond_type->dimy); - if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc))) - return false; - if (common_type->dimx == 1 && common_type->dimy == 1) { common_type = hlsl_get_numeric_type(ctx, cond_type->class, @@ -5372,6 +5367,11 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block, hlsl_release_string_buffer(ctx, cond_string); hlsl_release_string_buffer(ctx, value_string); } + + cond_type = hlsl_get_numeric_type(ctx, common_type->class, HLSL_TYPE_BOOL, + common_type->dimx, common_type->dimy); + if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc))) + return false; } if (!(first = add_implicit_conversion(ctx, block, first, common_type, &first->loc))) diff --git a/tests/hlsl/ternary.shader_test b/tests/hlsl/ternary.shader_test index 1f39a917..fd1b3efd 100644 --- a/tests/hlsl/ternary.shader_test +++ b/tests/hlsl/ternary.shader_test @@ -203,7 +203,7 @@ draw quad probe (0, 0) rgba (1.0, 6.0, 7.0, 4.0) -[pixel shader todo] +[pixel shader] static float1x4 cond = {1, 0, 0, 1}; static float4 a = {1, 2, 3, 4}; @@ -215,7 +215,7 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe (0, 0) rgba (1.0, 1.0, 1.0, 1.0) @@ -246,6 +246,34 @@ draw quad probe (0, 0) rgba (3.0, 3.0, 3.0, 3.0) +[pixel shader] + +static float1x1 cond = {1}; +static float1 a = {2}; +static float1 b = {3}; + +float4 main() : sv_target +{ + return (cond ? a : b)[0]; +} + +[test] +draw quad +probe (0, 0) rgba (2.0, 2.0, 2.0, 2.0) + + +[pixel shader fail] + +static float1x1 cond = {1}; +static float1 a = {2}; +static float1 b = {3}; + +float4 main() : sv_target +{ + return (cond ? a : b)[0][0]; +} + + [pixel shader] uniform float cond;