vkd3d-shader/glsl: Implement switches.

This commit is contained in:
Henri Verbeet 2024-10-03 15:46:07 +02:00
parent 93f1af721f
commit 27eb3c07ad
Notes: Henri Verbeet 2024-10-09 13:19:34 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1162
2 changed files with 66 additions and 25 deletions

View File

@ -702,6 +702,37 @@ static void shader_glsl_break(struct vkd3d_glsl_generator *gen)
vkd3d_string_buffer_printf(gen->buffer, "break;\n");
}
static void shader_glsl_switch(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{
struct glsl_src src;
glsl_src_init(&src, gen, &ins->src[0], VKD3DSP_WRITEMASK_0);
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "switch (%s)\n", src.str->buffer);
shader_glsl_begin_block(gen);
glsl_src_cleanup(&src, &gen->string_buffers);
}
static void shader_glsl_case(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{
struct glsl_src src;
glsl_src_init(&src, gen, &ins->src[0], VKD3DSP_WRITEMASK_0);
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "case %s:\n", src.str->buffer);
glsl_src_cleanup(&src, &gen->string_buffers);
}
static void shader_glsl_default(struct vkd3d_glsl_generator *gen)
{
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "default:\n");
}
static void shader_glsl_ld(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{
const struct glsl_resource_type_info *resource_type_info;
@ -1152,6 +1183,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_BREAK:
shader_glsl_break(gen);
break;
case VKD3DSIH_CASE:
shader_glsl_case(gen, ins);
break;
case VKD3DSIH_DCL_INDEXABLE_TEMP:
shader_glsl_dcl_indexable_temp(gen, ins);
break;
@ -1163,6 +1197,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_DCL_OUTPUT_SIV:
case VKD3DSIH_NOP:
break;
case VKD3DSIH_DEFAULT:
shader_glsl_default(gen);
break;
case VKD3DSIH_DIV:
shader_glsl_binop(gen, ins, "/");
break;
@ -1180,6 +1217,7 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
break;
case VKD3DSIH_ENDIF:
case VKD3DSIH_ENDLOOP:
case VKD3DSIH_ENDSWITCH:
shader_glsl_end_block(gen);
break;
case VKD3DSIH_EQO:
@ -1288,6 +1326,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_SQRT:
shader_glsl_intrinsic(gen, ins, "sqrt");
break;
case VKD3DSIH_SWITCH:
shader_glsl_switch(gen, ins);
break;
default:
shader_glsl_unhandled(gen, ins);
break;

View File

@ -17,15 +17,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 3 0 0 0
if(sm>=4) uniform 0 uint4 3 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (5.0, 5.0, 5.0, 5.0)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (4.0, 4.0, 4.0, 4.0)
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (3.0, 3.0, 3.0, 3.0)
@ -45,15 +45,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 3 0 0 0
if(sm>=4) uniform 0 uint4 3 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (5.0, 5.0, 5.0, 5.0)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (5.0, 5.0, 5.0, 5.0)
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (5.0, 5.0, 5.0, 5.0)
@ -91,15 +91,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.0, 3.0, 4.0)
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.0, 3.0, 4.0)
@ -127,11 +127,11 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.1, 3.1, 4.1)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
@ -159,11 +159,11 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.1, 3.1, 4.1)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
[pixel shader fail(sm<4 | sm>=6) todo(sm<4)]
@ -188,10 +188,10 @@ float4 main() : sv_target
[test]
uniform 0 float4 2.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.1, 3.1, 4.1)
uniform 0 float4 1.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
[pixel shader fail]
@ -390,15 +390,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.1, 2.1, 3.1, 4.1)
if(sm<4) uniform 0 float4 1 0 0 0
if(sm>=4) uniform 0 uint4 1 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.2, 2.2, 3.2, 4.2)
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
% switch breaks within a loop
@ -431,7 +431,7 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0)
@ -464,15 +464,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (4.0, 5.0, 6.0, 7.0)
if(sm<4) uniform 0 float4 2 0 0 0
if(sm>=4) uniform 0 uint4 2 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (2.0, 3.0, 4.0, 5.0)
if(sm<4) uniform 0 float4 3 0 0 0
if(sm>=4) uniform 0 uint4 3 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (4.0, 5.0, 6.0, 7.0)
@ -505,15 +505,15 @@ float4 main() : sv_target
[test]
if(sm<4) uniform 0 float4 3 0 0 0
if(sm>=4) uniform 0 uint4 3 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
if(sm<4) uniform 0 float4 0 0 0 0
if(sm>=4) uniform 0 uint4 0 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (4.0, 5.0, 6.0, 7.0)
if(sm<4) uniform 0 float4 5 0 0 0
if(sm>=4) uniform 0 uint4 5 0 0 0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
% 'continue' is not supported in switches