From 731b94f6f9dcba1996f812e99bdab308493c7693 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Mon, 4 Aug 2025 21:50:28 -0500 Subject: [PATCH] vkd3d-shader/d3dbc: Lower 1.4 TEXLD. --- Makefile.am | 1 + libs/vkd3d-shader/ir.c | 34 +++++++++++++++++++++++++++++- tests/hlsl/ps1-sampler.shader_test | 30 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/hlsl/ps1-sampler.shader_test diff --git a/Makefile.am b/Makefile.am index 3102a7829..4e6438d18 100644 --- a/Makefile.am +++ b/Makefile.am @@ -216,6 +216,7 @@ vkd3d_shader_tests = \ tests/hlsl/pow.shader_test \ tests/hlsl/precise-modifier.shader_test \ tests/hlsl/primitive-id.shader_test \ + tests/hlsl/ps1-sampler.shader_test \ tests/hlsl/rasteriser-ordered-views.shader_test \ tests/hlsl/rcp.shader_test \ tests/hlsl/reflect.shader_test \ diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 45c966d5b..0c5344a45 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -1387,6 +1387,36 @@ static enum vkd3d_result vsir_program_lower_sm4_sincos(struct vsir_program *prog return VKD3D_OK; } +static enum vkd3d_result vsir_program_lower_texld_sm1(struct vsir_program *program, + struct vkd3d_shader_instruction *ins, struct vkd3d_shader_message_context *message_context) +{ + unsigned int idx = ins->src[0].reg.idx[0].offset; + struct vkd3d_shader_src_param *srcs; + + /* texld DST, t# -> sample DST, t#, resource#, sampler# */ + + if (ins->src[0].modifiers) + { + vkd3d_shader_error(message_context, &ins->location, VKD3D_SHADER_ERROR_VSIR_NOT_IMPLEMENTED, + "Aborting due to not yet implemented feature: texld source modifier."); + return VKD3D_ERROR_NOT_IMPLEMENTED; + } + + if (!(srcs = shader_src_param_allocator_get(&program->instructions.src_params, 3))) + return VKD3D_ERROR_OUT_OF_MEMORY; + + /* Note we run before I/O normalization. */ + srcs[0] = ins->src[0]; + vsir_src_param_init_resource(&srcs[1], idx, idx); + vsir_src_param_init_sampler(&srcs[2], idx, idx); + + ins->opcode = VSIR_OP_SAMPLE; + ins->src = srcs; + ins->src_count = 3; + + return VKD3D_OK; +} + static enum vkd3d_result vsir_program_lower_texldp(struct vsir_program *program, struct vsir_program_iterator *it, unsigned int *tmp_idx) { @@ -1620,7 +1650,9 @@ static enum vkd3d_result vsir_program_lower_d3dbc_instructions(struct vsir_progr switch (ins->opcode) { case VSIR_OP_TEXLD: - if (ins->flags == VKD3DSI_TEXLD_PROJECT) + if (program->shader_version.major == 1) + ret = vsir_program_lower_texld_sm1(program, ins, message_context); + else if (ins->flags == VKD3DSI_TEXLD_PROJECT) ret = vsir_program_lower_texldp(program, &it, &tmp_idx); else ret = vsir_program_lower_texld(program, ins, message_context); diff --git a/tests/hlsl/ps1-sampler.shader_test b/tests/hlsl/ps1-sampler.shader_test new file mode 100644 index 000000000..0078d79b7 --- /dev/null +++ b/tests/hlsl/ps1-sampler.shader_test @@ -0,0 +1,30 @@ +[require] +shader model < 3.0 + +[sampler 0] +filter point point point +address wrap wrap wrap + +[srv 0] +size (2d, 2, 2) +1.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 +1.0 0.0 1.0 0.0 1.0 1.0 1.0 0.0 + +[vertex shader] +void main(inout float4 pos : position, out float4 tex : texcoord) +{ + tex = pos + 0.75; +} + +[pixel shader d3dbc-hex] +% TODO: Convert to assembly or HLSL. +ffff0104 % ps_1_4 +00000042 800f0000 b0e40000 % texld r0, t0 +0000ffff % end + +[test] +draw quad +probe (320, 240) f32(1, 1, 1, 0) +probe (480, 240) f32(1, 0, 1, 0) +probe (320, 360) f32(1, 1, 0, 0) +probe (480, 360) f32(1, 0, 0, 0)