diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index 51dd8f88..42c04f10 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -62,6 +62,9 @@ struct vkd3d_glsl_generator const struct vkd3d_shader_scan_combined_resource_sampler_info *combined_sampler_info; }; +static void shader_glsl_print_subscript(struct vkd3d_string_buffer *buffer, struct vkd3d_glsl_generator *gen, + const struct vkd3d_shader_src_param *rel_addr, unsigned int offset); + static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_glsl_compiler_error( struct vkd3d_glsl_generator *generator, enum vkd3d_shader_error error, const char *fmt, ...) @@ -263,6 +266,11 @@ static void shader_glsl_print_register_name(struct vkd3d_string_buffer *buffer, gen->prefix, reg->idx[0].offset, reg->idx[2].offset); break; + case VKD3DSPR_IDXTEMP: + vkd3d_string_buffer_printf(buffer, "x%u", reg->idx[0].offset); + shader_glsl_print_subscript(buffer, gen, reg->idx[1].rel_addr, reg->idx[1].offset); + break; + default: vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, "Internal compiler error: Unhandled register type %#x.", reg->type); @@ -438,6 +446,26 @@ static uint32_t glsl_dst_init(struct glsl_dst *glsl_dst, struct vkd3d_glsl_gener return write_mask; } +static void shader_glsl_print_subscript(struct vkd3d_string_buffer *buffer, struct vkd3d_glsl_generator *gen, + const struct vkd3d_shader_src_param *rel_addr, unsigned int offset) +{ + struct glsl_src r; + + if (!rel_addr) + { + vkd3d_string_buffer_printf(buffer, "[%u]", offset); + return; + } + + glsl_src_init(&r, gen, rel_addr, VKD3DSP_WRITEMASK_0); + vkd3d_string_buffer_printf(buffer, "[%s", r.str->buffer); + if (offset) + vkd3d_string_buffer_printf(buffer, " + %u", offset); + else + vkd3d_string_buffer_printf(buffer, "]"); + glsl_src_cleanup(&r, &gen->string_buffers); +} + static void VKD3D_PRINTF_FUNC(4, 0) shader_glsl_vprint_assignment(struct vkd3d_glsl_generator *gen, struct glsl_dst *dst, enum vkd3d_data_type data_type, const char *format, va_list args) { @@ -1048,6 +1076,15 @@ static void shader_glsl_ret(struct vkd3d_glsl_generator *gen, const struct vkd3d } } +static void shader_glsl_dcl_indexable_temp(struct vkd3d_glsl_generator *gen, + const struct vkd3d_shader_instruction *ins) +{ + shader_glsl_print_indent(gen->buffer, gen->indent); + vkd3d_string_buffer_printf(gen->buffer, "vec4 x%u[%u];\n", + ins->declaration.indexable_temp.register_idx, + ins->declaration.indexable_temp.register_size); +} + static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins) { @@ -1062,6 +1099,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen, case VKD3DSIH_AND: shader_glsl_binop(gen, ins, "&"); break; + case VKD3DSIH_DCL_INDEXABLE_TEMP: + shader_glsl_dcl_indexable_temp(gen, ins); + break; case VKD3DSIH_DCL_INPUT: case VKD3DSIH_DCL_INPUT_PS: case VKD3DSIH_DCL_INPUT_PS_SIV: diff --git a/tests/hlsl/matrix-indexing.shader_test b/tests/hlsl/matrix-indexing.shader_test index 91907d90..d2603514 100644 --- a/tests/hlsl/matrix-indexing.shader_test +++ b/tests/hlsl/matrix-indexing.shader_test @@ -136,5 +136,5 @@ float4 main() : sv_target [test] uniform 0 float 3 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (12, 13, 14, 15) diff --git a/tests/hlsl/non-const-indexing.shader_test b/tests/hlsl/non-const-indexing.shader_test index 0b9cebf1..399dd022 100644 --- a/tests/hlsl/non-const-indexing.shader_test +++ b/tests/hlsl/non-const-indexing.shader_test @@ -12,16 +12,16 @@ uniform 0 float4 1.0 2.0 3.0 4.0 uniform 4 float4 5.0 6.0 7.0 8.0 uniform 8 float4 9.0 10.0 11.0 12.0 uniform 12 float4 0 0 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0) uniform 12 float4 1 0 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0) uniform 12 float4 0 1 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0) uniform 12 float4 1 1 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (9.0, 10.0, 11.0, 12.0) @@ -61,7 +61,7 @@ float4 main() : sv_target [test] uniform 0 float 2.3 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (3, 3, 3, 3) @@ -102,16 +102,16 @@ float4 main() : sv_target [test] uniform 0 float4 0 0 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0) uniform 0 float4 1 0 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0) uniform 0 float4 0 1 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0) uniform 0 float4 1 1 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (9.0, 10.0, 11.0, 12.0) @@ -130,7 +130,7 @@ float4 main() : sv_target [test] uniform 0 float4 0 0 2.4 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (1.0, 120.0, 90.0, 4.0) @@ -148,12 +148,12 @@ float4 main() : sv_target if(sm<4) uniform 0 float 3 if(sm<4) uniform 4 float 1 if(sm>=4) uniform 0 float4 3 1 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (7, 7, 7, 7) if(sm<4) uniform 0 float 5 if(sm<4) uniform 4 float 0 if(sm>=4) uniform 0 float4 5 0 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (10, 10, 10, 10) @@ -186,13 +186,13 @@ if(sm<4) uniform 0 float 2 if(sm<4) uniform 4 float 1 if(sm<4) uniform 8 float -1 if(sm>=4) uniform 0 float4 2 1 -1 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (30, 31, 32, 33) if(sm<4) uniform 0 float 1 if(sm<4) uniform 4 float 0 if(sm<4) uniform 8 float 1 if(sm>=4) uniform 0 float4 1 0 1 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (70, 71, 72, 73) @@ -214,12 +214,12 @@ float4 main() : sv_target if(sm<4) uniform 0 float 11 if(sm<4) uniform 4 float 12 if(sm>=4) uniform 0 float4 11 12 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5, 5, 5, 5) if(sm<4) uniform 0 float 13 if(sm<4) uniform 4 float 10 if(sm>=4) uniform 0 float4 13 10 0 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (9, 9, 9, 9) @@ -244,15 +244,15 @@ float4 main() : sv_target [test] uniform 0 int 0 uniform 1 int 0 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (100, 6, 7, 8) uniform 0 int 2 uniform 1 int 2 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5, 6, 100, 8) uniform 0 int 1 uniform 1 int 3 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (5, 6, 7, 4) @@ -281,7 +281,7 @@ uniform 0 float4 1 2 3 4 uniform 4 float4 5 6 7 8 uniform 8 int 3 uniform 9 int 4 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (1126, 3344, 5566, 3788) @@ -301,7 +301,7 @@ float4 main() : sv_target [test] uniform 0 uint 1 uniform 1 uint 0x40a00000 -todo(glsl) draw quad +draw quad probe (0, 0) rgba (1, 5, 3, 4) @@ -332,7 +332,7 @@ uniform 8 float 3.0 uniform 12 float 4.0 uniform 16 uint4 3 1 0 2 uniform 20 uint4 0 3 1 2 -todo(glsl) draw quad +draw quad if(sm<4) probe (0,0) rgba (1.0, 1.0, 1.0, 1.0) if(sm>=4 & sm<6) todo probe (0,0) rgba (4.0, 4.0, 4.0, 4.0) if(sm>=6) probe (0,0) rgba (4.0, 3.0, 2.0, 1.0)