diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index 03c5458b..da8ba662 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -404,6 +404,7 @@ enum dx_intrinsic_opcode DX_ATOMIC_BINOP = 78, DX_ATOMIC_CMP_XCHG = 79, DX_BARRIER = 80, + DX_CALCULATE_LOD = 81, DX_DISCARD = 82, DX_DERIV_COARSEX = 83, DX_DERIV_COARSEY = 84, @@ -4486,6 +4487,40 @@ static void sm6_parser_emit_dx_buffer_update_counter(struct sm6_parser *sm6, enu instruction_dst_param_init_ssa_scalar(ins, sm6); } +static void sm6_parser_emit_dx_calculate_lod(struct sm6_parser *sm6, enum dx_intrinsic_opcode op, + const struct sm6_value **operands, struct function_emission_state *state) +{ + const struct sm6_value *resource, *sampler; + struct vkd3d_shader_src_param *src_params; + struct vkd3d_shader_instruction *ins; + struct vkd3d_shader_register coord; + unsigned int clamp; + + resource = operands[0]; + sampler = operands[1]; + if (!sm6_value_validate_is_texture_handle(resource, op, sm6) + || !sm6_value_validate_is_sampler_handle(sampler, op, sm6)) + { + return; + } + + if (!sm6_parser_emit_coordinate_construct(sm6, &operands[2], 3, NULL, state, &coord)) + return; + + clamp = sm6_value_get_constant_uint(operands[5]); + + ins = state->ins; + vsir_instruction_init(ins, &sm6->p.location, VKD3DSIH_LOD); + if (!(src_params = instruction_src_params_alloc(ins, 3, sm6))) + return; + src_param_init_vector_from_reg(&src_params[0], &coord); + src_params[1].reg = resource->u.handle.reg; + src_param_init_scalar(&src_params[1], !clamp); + src_param_init_vector_from_reg(&src_params[2], &sampler->u.handle.reg); + + instruction_dst_param_init_ssa_scalar(ins, sm6); +} + static void sm6_parser_emit_dx_cbuffer_load(struct sm6_parser *sm6, enum dx_intrinsic_opcode op, const struct sm6_value **operands, struct function_emission_state *state) { @@ -5514,6 +5549,7 @@ static const struct sm6_dx_opcode_info sm6_dx_op_table[] = [DX_BUFFER_LOAD ] = {"o", "Hii", sm6_parser_emit_dx_buffer_load}, [DX_BUFFER_STORE ] = {"v", "Hiiooooc", sm6_parser_emit_dx_buffer_store}, [DX_BUFFER_UPDATE_COUNTER ] = {"i", "H8", sm6_parser_emit_dx_buffer_update_counter}, + [DX_CALCULATE_LOD ] = {"f", "HHfffb", sm6_parser_emit_dx_calculate_lod}, [DX_CBUFFER_LOAD_LEGACY ] = {"o", "Hi", sm6_parser_emit_dx_cbuffer_load}, [DX_COS ] = {"g", "R", sm6_parser_emit_dx_sincos}, [DX_COUNT_BITS ] = {"i", "m", sm6_parser_emit_dx_unary}, diff --git a/tests/hlsl/calculate-lod.shader_test b/tests/hlsl/calculate-lod.shader_test index 807776ee..88325af6 100644 --- a/tests/hlsl/calculate-lod.shader_test +++ b/tests/hlsl/calculate-lod.shader_test @@ -29,7 +29,7 @@ float4 main(float4 pos : sv_position) : sv_target } [test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (2.0, 1.0, 0.0, 14.0) @@ -46,7 +46,7 @@ float4 main(float4 pos : sv_position) : sv_target } [test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (2.0, 2.0, 0.0, 0.0) @@ -63,7 +63,7 @@ float4 main(float4 pos : sv_position) : sv_target } [test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (2.0, 1.0, 0.0, 14.0) @@ -80,5 +80,5 @@ float4 main(float4 pos : sv_position) : sv_target } [test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (45.0, 50.0, -14.0, -47.0)