From 25232f2b2b35bcf1c265bc380c31cd1d32e4f4a6 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sun, 29 Sep 2024 23:51:43 +0200 Subject: [PATCH] vkd3d-shader/glsl: Implement VKD3DSIH_IMUL. --- libs/vkd3d-shader/glsl.c | 34 +++++++++++++++++++++++++++ tests/hlsl/default-values.shader_test | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index 6a8a5628..c2fb58c5 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -864,6 +864,37 @@ static void shader_glsl_movc(struct vkd3d_glsl_generator *gen, const struct vkd3 glsl_dst_cleanup(&dst, &gen->string_buffers); } +static void shader_glsl_mul_extended(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins) +{ + struct glsl_src src[2]; + struct glsl_dst dst; + uint32_t mask; + + if (ins->dst[0].reg.type != VKD3DSPR_NULL) + { + /* FIXME: imulExtended()/umulExtended() from ARB_gpu_shader5/GLSL 4.00+. */ + mask = glsl_dst_init(&dst, gen, ins, &ins->dst[0]); + shader_glsl_print_assignment(gen, &dst, ""); + glsl_dst_cleanup(&dst, &gen->string_buffers); + + vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, + "Internal compiler error: Unhandled 64-bit integer multiplication."); + } + + if (ins->dst[1].reg.type != VKD3DSPR_NULL) + { + mask = glsl_dst_init(&dst, gen, ins, &ins->dst[1]); + glsl_src_init(&src[0], gen, &ins->src[0], mask); + glsl_src_init(&src[1], gen, &ins->src[1], mask); + + shader_glsl_print_assignment(gen, &dst, "%s * %s", src[0].str->buffer, src[1].str->buffer); + + glsl_src_cleanup(&src[1], &gen->string_buffers); + glsl_src_cleanup(&src[0], &gen->string_buffers); + glsl_dst_cleanup(&dst, &gen->string_buffers); + } +} + static void shader_glsl_print_sysval_name(struct vkd3d_string_buffer *buffer, struct vkd3d_glsl_generator *gen, enum vkd3d_shader_sysval_semantic sysval, unsigned int idx) { @@ -1077,6 +1108,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen, case VKD3DSIH_LTO: shader_glsl_relop(gen, ins, "<", "lessThan"); break; + case VKD3DSIH_IMUL: + shader_glsl_mul_extended(gen, ins); + break; case VKD3DSIH_ISHL: shader_glsl_binop(gen, ins, "<<"); break; diff --git a/tests/hlsl/default-values.shader_test b/tests/hlsl/default-values.shader_test index 62722b68..7a759b36 100644 --- a/tests/hlsl/default-values.shader_test +++ b/tests/hlsl/default-values.shader_test @@ -88,7 +88,7 @@ if(sm<4) uniform 0 float4 10 20 30 40 if(sm<4) uniform 4 float4 50 60 70 80 if(sm>=4) uniform 0 int4 10 20 30 40 if(sm>=4) uniform 4 int4 50 60 70 80 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (100, 120, 140, 160)