-- v6: vkd3d-shader/dxil: Implement DX intrinsic CalculateLOD. tests/hlsl: Add tests for CalculateLevelOfDetail().
From: Conor McCarthy cmccarthy@codeweavers.com
Includes improvements made by Giovanni Mascellani. --- Makefile.am | 1 + tests/hlsl/calculate-lod.shader_test | 84 ++++++++++++++++++++++++++++ tests/shader_runner_d3d11.c | 2 +- tests/shader_runner_d3d12.c | 2 +- 4 files changed, 87 insertions(+), 2 deletions(-) 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..807776eec --- /dev/null +++ b/tests/hlsl/calculate-lod.shader_test @@ -0,0 +1,84 @@ +[require] +shader model >= 4.1 + + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[srv 0] +size (2d, 4, 4) +levels 3 + +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(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetail(s, pos.xy), + t.CalculateLevelOfDetail(s, float2(0.5 * pos.x, 0.5 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.25 * pos.x, 0.25 * pos.y)), + floor(10.0 * t.CalculateLevelOfDetail(s, float2(0.1 * pos.x, 0.7 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (2.0, 1.0, 0.0, 14.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetail(s, float2(3.0 * pos.x, 5.0 * pos.y)), + t.CalculateLevelOfDetail(s, float2(10.0 * pos.x, 10.0 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.1 * pos.x, 0.02 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.01 * pos.x, 0.01 * pos.y))); +} + +[test] +todo draw quad +probe all rgba (2.0, 2.0, 0.0, 0.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetailUnclamped(s, pos.xy), + t.CalculateLevelOfDetailUnclamped(s, float2(0.5 * pos.x, 0.5 * pos.y)), + t.CalculateLevelOfDetailUnclamped(s, float2(0.25 * pos.x, 0.25 * pos.y)), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.1 * pos.x, 0.7 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (2.0, 1.0, 0.0, 14.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(3.0 * pos.x, 6.0 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(8.0 * pos.x, 8.0 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.1 * pos.x, 0.02 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.01 * pos.x, 0.01 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (45.0, 50.0, -14.0, -47.0) diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 1285ca41f..b26d6a36b 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -358,7 +358,7 @@ static ID3D11Buffer *create_buffer(ID3D11Device *device, unsigned int bind_flags static void init_resource_2d(struct d3d11_shader_runner *runner, struct d3d11_resource *resource, const struct resource_params *params) { - D3D11_SUBRESOURCE_DATA resource_data[2]; + D3D11_SUBRESOURCE_DATA resource_data[3]; ID3D11Device *device = runner->device; D3D11_TEXTURE2D_DESC desc = {0}; HRESULT hr; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 9bf7bb248..56844ae36 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -104,7 +104,7 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co struct d3d12_shader_runner *runner = d3d12_shader_runner(r); struct test_context *test_context = &runner->test_context; ID3D12Device *device = test_context->device; - D3D12_SUBRESOURCE_DATA resource_data[2] = {0}; + D3D12_SUBRESOURCE_DATA resource_data[3] = {0}; struct d3d12_resource *resource; unsigned int buffer_offset = 0; D3D12_RESOURCE_STATES state;
From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/dxil.c | 36 ++++++++++++++++++++++++++++ tests/hlsl/calculate-lod.shader_test | 8 +++---- 2 files changed, 40 insertions(+), 4 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 807776eec..88325af61 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)
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Henri Verbeet.