vkd3d-shader/hlsl: Add support for ternary operator.

This commit is contained in:
Nikolay Sivov 2023-04-03 23:15:00 +02:00 committed by Alexandre Julliard
parent 725d408974
commit c190c184ce
Notes: Alexandre Julliard 2023-04-06 22:23:07 +02:00
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/139
3 changed files with 26 additions and 1 deletions

View File

@ -116,6 +116,7 @@ vkd3d_shader_tests = \
tests/hlsl-struct-array.shader_test \ tests/hlsl-struct-array.shader_test \
tests/hlsl-struct-assignment.shader_test \ tests/hlsl-struct-assignment.shader_test \
tests/hlsl-struct-semantics.shader_test \ tests/hlsl-struct-semantics.shader_test \
tests/hlsl-ternary.shader_test \
tests/hlsl-transpose.shader_test \ tests/hlsl-transpose.shader_test \
tests/hlsl-type-names.shader_test \ tests/hlsl-type-names.shader_test \
tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing.shader_test \

View File

@ -5743,7 +5743,16 @@ conditional_expr:
logicor_expr logicor_expr
| logicor_expr '?' expr ':' assignment_expr | logicor_expr '?' expr ':' assignment_expr
{ {
hlsl_fixme(ctx, &@$, "Ternary operator."); struct hlsl_ir_node *cond = node_from_list($1), *first = node_from_list($3), *second = node_from_list($5);
list_move_tail($1, $3);
list_move_tail($1, $5);
vkd3d_free($3);
vkd3d_free($5);
if (!hlsl_add_conditional(ctx, $1, cond, first, second))
YYABORT;
$$ = $1;
} }
assignment_expr: assignment_expr:

View File

@ -0,0 +1,15 @@
[pixel shader]
uniform float4 x;
float4 main() : SV_TARGET
{
return x.x ? x : x - 1;
}
[test]
uniform 0 float4 2.0 3.0 4.0 5.0
draw quad
probe all rgba (2.0, 3.0, 4.0, 5.0)
uniform 0 float4 0.0 10.0 11.0 12.0
draw quad
probe all rgba (-1.0, 9.0, 10.0, 11.0)