From 825784322dd157b6e47c003a5ba5adc56b105a1b Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Tue, 10 Dec 2024 15:01:43 -0300 Subject: [PATCH] vkd3d-shader/ir: Properly lower texldp. --- libs/vkd3d-shader/ir.c | 60 ++++++++++++++++++++++++++++++++-- tests/hlsl/sampler.shader_test | 8 ++--- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 02d04211..1f12feb1 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -703,6 +703,54 @@ static enum vkd3d_result vsir_program_lower_sm1_sincos(struct vsir_program *prog return VKD3D_OK; } +static enum vkd3d_result vsir_program_lower_texldp(struct vsir_program *program, + struct vkd3d_shader_instruction *tex, unsigned int *tmp_idx) +{ + struct vkd3d_shader_instruction_array *instructions = &program->instructions; + struct vkd3d_shader_location *location = &tex->location; + struct vkd3d_shader_instruction *div_ins, *tex_ins; + size_t pos = tex - instructions->elements; + unsigned int w_comp; + + w_comp = vsir_swizzle_get_component(tex->src[0].swizzle, 3); + + if (!shader_instruction_array_insert_at(instructions, pos + 1, 2)) + return VKD3D_ERROR_OUT_OF_MEMORY; + + if (*tmp_idx == ~0u) + *tmp_idx = program->temp_count++; + + div_ins = &instructions->elements[pos + 1]; + tex_ins = &instructions->elements[pos + 2]; + + if (!vsir_instruction_init_with_params(program, div_ins, location, VKD3DSIH_DIV, 1, 2)) + return VKD3D_ERROR_OUT_OF_MEMORY; + + vsir_dst_param_init(&div_ins->dst[0], VKD3DSPR_TEMP, VKD3D_DATA_FLOAT, 1); + div_ins->dst[0].reg.dimension = VSIR_DIMENSION_VEC4; + div_ins->dst[0].reg.idx[0].offset = *tmp_idx; + div_ins->dst[0].write_mask = VKD3DSP_WRITEMASK_ALL; + + div_ins->src[0] = tex->src[0]; + + div_ins->src[1] = tex->src[0]; + div_ins->src[1].swizzle = vkd3d_shader_create_swizzle(w_comp, w_comp, w_comp, w_comp); + + if (!vsir_instruction_init_with_params(program, tex_ins, location, VKD3DSIH_TEX, 1, 2)) + return VKD3D_ERROR_OUT_OF_MEMORY; + + tex_ins->dst[0] = tex->dst[0]; + + tex_ins->src[0].reg = div_ins->dst[0].reg; + tex_ins->src[0].swizzle = VKD3D_SHADER_NO_SWIZZLE; + + tex_ins->src[1] = tex->src[1]; + + vkd3d_shader_instruction_make_nop(tex); + + return VKD3D_OK; +} + static enum vkd3d_result vsir_program_lower_tex(struct vsir_program *program, struct vkd3d_shader_instruction *tex, struct vkd3d_shader_message_context *message_context) { @@ -904,8 +952,16 @@ static enum vkd3d_result vsir_program_lower_instructions(struct vsir_program *pr break; case VKD3DSIH_TEX: - if ((ret = vsir_program_lower_tex(program, ins, message_context)) < 0) - return ret; + if (ins->flags == VKD3DSI_TEXLD_PROJECT) + { + if ((ret = vsir_program_lower_texldp(program, ins, &tmp_idx)) < 0) + return ret; + } + else + { + if ((ret = vsir_program_lower_tex(program, ins, message_context)) < 0) + return ret; + } break; case VKD3DSIH_TEXLDD: diff --git a/tests/hlsl/sampler.shader_test b/tests/hlsl/sampler.shader_test index 59bd0c4e..710b2c3e 100644 --- a/tests/hlsl/sampler.shader_test +++ b/tests/hlsl/sampler.shader_test @@ -86,16 +86,16 @@ float4 main() : sv_target [test] uniform 0 float4 50.0 50.0 42.0 100 -todo(sm<4 | msl) draw quad +todo(msl) draw quad probe (0, 0) rgba(1.0, 1.0, 0, 1.0) uniform 0 float4 0.075 0.025 -42.0 0.1 -todo(sm<4 | msl) draw quad +todo(msl) draw quad probe (0, 0) rgba(1.75, 0.25, 0, 1.0) uniform 0 float4 0.5 1.5 0.0 2.0 -todo(sm<4 | msl) draw quad +todo(msl) draw quad probe (0, 0) rgba(0.25, 1.75, 0, 1.0) uniform 0 float4 1.0 1.0 0.0 0.0 -todo(sm<4 | msl) draw quad +todo(msl) draw quad probe (0, 0) rgba(2.0, 2.0, 0, 1.0) [sampler 0]