vkd3d-shader/glsl: Implement loops.

This commit is contained in:
Henri Verbeet 2024-10-03 15:07:16 +02:00
parent 790f35533b
commit 93f1af721f
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
4 changed files with 59 additions and 33 deletions

View File

@ -651,6 +651,20 @@ static void shader_glsl_cast(struct vkd3d_glsl_generator *gen, const struct vkd3
glsl_dst_cleanup(&dst, &gen->string_buffers);
}
static void shader_glsl_end_block(struct vkd3d_glsl_generator *gen)
{
--gen->indent;
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "}\n");
}
static void shader_glsl_begin_block(struct vkd3d_glsl_generator *gen)
{
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "{\n");
++gen->indent;
}
static void shader_glsl_if(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{
const char *condition;
@ -664,23 +678,28 @@ static void shader_glsl_if(struct vkd3d_glsl_generator *gen, const struct vkd3d_
glsl_src_cleanup(&src, &gen->string_buffers);
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "{\n");
++gen->indent;
shader_glsl_begin_block(gen);
}
static void shader_glsl_else(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{
unsigned int i = 4 * (gen->indent - 1);
vkd3d_string_buffer_printf(gen->buffer, "%*s}\n%*selse\n%*s{\n", i, "", i, "", i, "");
shader_glsl_end_block(gen);
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "else\n");
shader_glsl_begin_block(gen);
}
static void shader_glsl_endif(struct vkd3d_glsl_generator *gen)
static void shader_glsl_loop(struct vkd3d_glsl_generator *gen)
{
--gen->indent;
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "}\n");
vkd3d_string_buffer_printf(gen->buffer, "for (;;)\n");
shader_glsl_begin_block(gen);
}
static void shader_glsl_break(struct vkd3d_glsl_generator *gen)
{
shader_glsl_print_indent(gen->buffer, gen->indent);
vkd3d_string_buffer_printf(gen->buffer, "break;\n");
}
static void shader_glsl_ld(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
@ -1130,6 +1149,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_AND:
shader_glsl_binop(gen, ins, "&");
break;
case VKD3DSIH_BREAK:
shader_glsl_break(gen);
break;
case VKD3DSIH_DCL_INDEXABLE_TEMP:
shader_glsl_dcl_indexable_temp(gen, ins);
break;
@ -1157,7 +1179,8 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
shader_glsl_else(gen, ins);
break;
case VKD3DSIH_ENDIF:
shader_glsl_endif(gen);
case VKD3DSIH_ENDLOOP:
shader_glsl_end_block(gen);
break;
case VKD3DSIH_EQO:
case VKD3DSIH_IEQ:
@ -1223,6 +1246,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_LOG:
shader_glsl_intrinsic(gen, ins, "log2");
break;
case VKD3DSIH_LOOP:
shader_glsl_loop(gen);
break;
case VKD3DSIH_MOV:
shader_glsl_mov(gen, ins);
break;

View File

@ -235,23 +235,23 @@ float4 main() : sv_target
[test]
uniform 0 float 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.2, 0.3, 0.3) 1
uniform 0 float 0.1
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.3, 0.3, 0.3) 1
uniform 0 float 0.3
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.5, 0.3, 0.3) 1
uniform 0 float 0.7
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.9, 0.7, 0.6) 1
uniform 0 float 0.9
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.1, 0.7, 0.6) 1
[pixel shader todo(sm<4)]
@ -291,21 +291,21 @@ float4 main() : sv_target
uniform 0 float4 0.3 0.0 0.0 0.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.1 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.2, 0.6, 0.6) 1
uniform 4 float4 0.35 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.3, 0.6, 0.6) 1
uniform 8 float4 0.5 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.5, 0.6, 0.6) 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 (0.3, 0.5, 0.6, 0.6) 1
uniform 4 float4 2.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.1, 0.6, 0.6) 1

View File

@ -118,7 +118,7 @@ float4 main() : sv_target
}
[test]
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (10.0, 10.0, 10.0, 10.0)
[pixel shader todo(sm<4)]
@ -137,7 +137,7 @@ float4 main() : sv_target
}
[test]
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (10.0, 10.0, 10.0, 10.0)
[pixel shader todo(sm<4)]
@ -156,7 +156,7 @@ float4 main() : sv_target
}
[test]
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (10.0, 10.0, 10.0, 10.0)
% unroll can't be used with fastopt or loop

View File

@ -160,23 +160,23 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.1, 0.1, 0.1) 1
uniform 0 float 0.1
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) 1
uniform 0 float 0.3
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.4, 0.4, 0.4) 1
uniform 0 float 0.7
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.8, 0.8, 0.8, 0.8) 1
uniform 0 float 0.9
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.9, 0.9, 0.9, 0.9) 1
[pixel shader todo(sm<4)]
@ -236,21 +236,21 @@ void main(out float4 ret : sv_target)
uniform 0 float4 0.3 0.0 0.0 0.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.1 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.1, 0.1, 0.1) 1
uniform 4 float4 0.35 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) 1
uniform 8 float4 0.5 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.4, 0.4, 0.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 (0.4, 0.4, 0.4, 0.4) 1
uniform 4 float4 2.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(sm<4) draw quad
probe (0, 0) rgba (0.9, 0.9, 0.9, 0.9) 1