-- v5: vkd3d-shader/dxil: Implement DX intrinsic CalculateLOD. tests/hlsl: Add tests for CalculateLevelOfDetail().
From: Conor McCarthy cmccarthy@codeweavers.com
--- Makefile.am | 1 + tests/hlsl/calculate-lod.shader_test | 44 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/hlsl/calculate-lod.shader_test
diff --git a/Makefile.am b/Makefile.am index 68e8642e0..d6295d1f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,7 @@ vkd3d_shader_tests = \ tests/hlsl/bitwise.shader_test \ tests/hlsl/bool-cast.shader_test \ tests/hlsl/bool-semantics.shader_test \ + tests/hlsl/calculate-lod.shader_test \ tests/hlsl/cast-64-bit.shader_test \ tests/hlsl/cast-broadcast.shader_test \ tests/hlsl/cast-componentwise-compatible.shader_test \ diff --git a/tests/hlsl/calculate-lod.shader_test b/tests/hlsl/calculate-lod.shader_test new file mode 100644 index 000000000..aca46d4d8 --- /dev/null +++ b/tests/hlsl/calculate-lod.shader_test @@ -0,0 +1,44 @@ +[require] +shader model >= 4.1 + + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[srv 0] +size (2d, 4, 4) +levels 2 + +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.CalculateLevelOfDetail(s, float2(0.5, 0.5)); +} + +[test] +todo draw quad +probe all rgba (0.0, 0.0, 0.0, 0.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.CalculateLevelOfDetailUnclamped(s, float2(0.5, 0.5)); +} + +[test] +todo draw quad +probe all rgba (-3.40282347e+38, -3.40282347e+38, -3.40282347e+38, -3.40282347e+38) 1
From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/dxil.c | 36 ++++++++++++++++++++++++++++ tests/hlsl/calculate-lod.shader_test | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index b5a61d99d..76709ce81 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, @@ -4364,6 +4365,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) { @@ -5392,6 +5427,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 aca46d4d8..ca74d47fe 100644 --- a/tests/hlsl/calculate-lod.shader_test +++ b/tests/hlsl/calculate-lod.shader_test @@ -26,7 +26,7 @@ float4 main() : sv_target }
[test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (0.0, 0.0, 0.0, 0.0)
@@ -40,5 +40,5 @@ float4 main() : sv_target }
[test] -todo draw quad +todo(sm<6 | glsl) draw quad probe all rgba (-3.40282347e+38, -3.40282347e+38, -3.40282347e+38, -3.40282347e+38) 1
Hmm, sampling on a constant coordinate doesn't make a lot of sense and it leads to ill-defined results. What do you think of [the attached patch](/uploads/45b934dc0bc325ab2a51f90bcbf89a6b/patch.diff)?