From 7cc802afd720cf01741448ca864f062c7a8eaed7 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Wed, 4 Dec 2024 15:16:45 -0300 Subject: [PATCH] vkd3d-shader/ir: Properly lower texldb. --- libs/vkd3d-shader/ir.c | 31 ++++++++++++++++++++++++------ tests/hlsl/sample-bias.shader_test | 8 ++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index cdc0c184..02d04211 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -703,7 +703,8 @@ static enum vkd3d_result vsir_program_lower_sm1_sincos(struct vsir_program *prog return VKD3D_OK; } -static enum vkd3d_result vsir_program_lower_tex(struct vsir_program *program, struct vkd3d_shader_instruction *tex) +static enum vkd3d_result vsir_program_lower_tex(struct vsir_program *program, + struct vkd3d_shader_instruction *tex, struct vkd3d_shader_message_context *message_context) { unsigned int idx = tex->src[1].reg.idx[0].offset; struct vkd3d_shader_src_param *srcs; @@ -711,16 +712,34 @@ static enum vkd3d_result vsir_program_lower_tex(struct vsir_program *program, st VKD3D_ASSERT(tex->src[1].reg.idx_count == 1); VKD3D_ASSERT(!tex->src[1].reg.idx[0].rel_addr); - if (!(srcs = shader_src_param_allocator_get(&program->instructions.src_params, 3))) + if (!(srcs = shader_src_param_allocator_get(&program->instructions.src_params, 4))) return VKD3D_ERROR_OUT_OF_MEMORY; srcs[0] = tex->src[0]; vsir_src_param_init_resource(&srcs[1], idx, idx); vsir_src_param_init_sampler(&srcs[2], idx, idx); - tex->opcode = VKD3DSIH_SAMPLE; - tex->src = srcs; - tex->src_count = 3; + if (!tex->flags) + { + tex->opcode = VKD3DSIH_SAMPLE; + tex->src = srcs; + tex->src_count = 3; + } + else if (tex->flags == VKD3DSI_TEXLD_BIAS) + { + tex->opcode = VKD3DSIH_SAMPLE_B; + tex->src = srcs; + tex->src_count = 4; + + srcs[3] = tex->src[0]; + srcs[3].swizzle = VKD3D_SHADER_SWIZZLE(W, W, W, W); + } + else + { + vkd3d_shader_error(message_context, &tex->location, + VKD3D_SHADER_ERROR_VSIR_NOT_IMPLEMENTED, "Unhandled tex flags %#x.", tex->flags); + return VKD3D_ERROR_NOT_IMPLEMENTED; + } return VKD3D_OK; } @@ -885,7 +904,7 @@ static enum vkd3d_result vsir_program_lower_instructions(struct vsir_program *pr break; case VKD3DSIH_TEX: - if ((ret = vsir_program_lower_tex(program, ins)) < 0) + if ((ret = vsir_program_lower_tex(program, ins, message_context)) < 0) return ret; break; diff --git a/tests/hlsl/sample-bias.shader_test b/tests/hlsl/sample-bias.shader_test index 6de183b6..d3843134 100644 --- a/tests/hlsl/sample-bias.shader_test +++ b/tests/hlsl/sample-bias.shader_test @@ -37,11 +37,11 @@ probe (0, 0) rgba (10.0, 0.0, 10.0, 0.0) uniform 0 float4 7.5 0.0 0.0 0.0 todo(msl) draw quad -todo(sm<4) probe (0, 0) rgba(4.0, 0.0, 10.0, 0.0) +probe (0, 0) rgba(4.0, 0.0, 10.0, 0.0) uniform 0 float4 8.5 0.0 0.0 0.0 todo(msl) draw quad -todo(sm<4) probe (0, 0) rgba(0.0, 0.0, 10.0, 0.0) +probe (0, 0) rgba(0.0, 0.0, 10.0, 0.0) [require] shader model >= 3.0 @@ -65,8 +65,8 @@ probe (0, 0) rgba (10.0, 0.0, 10.0, 0.0) uniform 0 float4 7.5 0.0 0.0 0.0 todo(msl) draw quad -todo(sm<4) probe (0,0) rgba (4.0, 0.0, 10.0, 0.0) +probe (0,0) rgba(4.0, 0.0, 10.0, 0.0) uniform 0 float4 8.5 0.0 0.0 0.0 todo(msl) draw quad -todo(sm<4) probe (0,0) rgba (0.0, 0.0, 10.0, 0.0) +probe (0,0) rgba(0.0, 0.0, 10.0, 0.0)