Goes atop !533. The last two commits belongs to this MR.
-- v4: vkd3d-shader/dxil: Implement DX intrinsic Binary. vkd3d-shader/dxil: Add an operand type code for the return type.
From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/dxil.c | 49 ++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index 15cc380f5..b128b41fd 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -3776,38 +3776,39 @@ struct sm6_dx_opcode_info H -> handle v -> void o -> overloaded + R -> matches the return type */ static const struct sm6_dx_opcode_info sm6_dx_op_table[] = { - [DX_BFREV ] = {"m0", "m", sm6_parser_emit_dx_unary}, + [DX_BFREV ] = {"m", "R", sm6_parser_emit_dx_unary}, [DX_BUFFER_LOAD ] = {"o", "Hii", sm6_parser_emit_dx_buffer_load}, [DX_CBUFFER_LOAD_LEGACY ] = {"o", "Hi", sm6_parser_emit_dx_cbuffer_load}, [DX_COUNT_BITS ] = {"i", "m", sm6_parser_emit_dx_unary}, [DX_CREATE_HANDLE ] = {"H", "ccib", sm6_parser_emit_dx_create_handle}, - [DX_DERIV_COARSEX ] = {"e0", "e", sm6_parser_emit_dx_unary}, - [DX_DERIV_COARSEY ] = {"e0", "e", sm6_parser_emit_dx_unary}, - [DX_DERIV_FINEX ] = {"e0", "e", sm6_parser_emit_dx_unary}, - [DX_DERIV_FINEY ] = {"e0", "e", sm6_parser_emit_dx_unary}, - [DX_EXP ] = {"g0", "g", sm6_parser_emit_dx_unary}, + [DX_DERIV_COARSEX ] = {"e", "R", sm6_parser_emit_dx_unary}, + [DX_DERIV_COARSEY ] = {"e", "R", sm6_parser_emit_dx_unary}, + [DX_DERIV_FINEX ] = {"e", "R", sm6_parser_emit_dx_unary}, + [DX_DERIV_FINEY ] = {"e", "R", sm6_parser_emit_dx_unary}, + [DX_EXP ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_FIRST_BIT_HI ] = {"i", "m", sm6_parser_emit_dx_unary}, [DX_FIRST_BIT_LO ] = {"i", "m", sm6_parser_emit_dx_unary}, [DX_FIRST_BIT_SHI ] = {"i", "m", sm6_parser_emit_dx_unary}, - [DX_FRC ] = {"g0", "g", sm6_parser_emit_dx_unary}, + [DX_FRC ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_LEGACY_F16TOF32 ] = {"f", "i", sm6_parser_emit_dx_unary}, [DX_LEGACY_F32TOF16 ] = {"i", "f", sm6_parser_emit_dx_unary}, [DX_LOAD_INPUT ] = {"o", "ii8i", sm6_parser_emit_dx_load_input}, - [DX_LOG ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_ROUND_NE ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_ROUND_NI ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_ROUND_PI ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_ROUND_Z ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_RSQRT ] = {"g0", "g", sm6_parser_emit_dx_unary}, - [DX_SQRT ] = {"g0", "g", sm6_parser_emit_dx_unary}, + [DX_LOG ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_ROUND_NE ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_ROUND_NI ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_ROUND_PI ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_ROUND_Z ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_RSQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_SQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_STORE_OUTPUT ] = {"v", "ii8o", sm6_parser_emit_dx_store_output}, };
static bool sm6_parser_validate_operand_type(struct sm6_parser *sm6, const struct sm6_value *value, char info_type, - bool is_return) + const struct sm6_type *ret_type, bool is_return) { const struct sm6_type *type = value->type;
@@ -3843,23 +3844,14 @@ static bool sm6_parser_validate_operand_type(struct sm6_parser *sm6, const struc case 'o': /* TODO: some type checking may be possible */ return true; + case 'R': + return type == ret_type; default: FIXME("Unhandled operand code '%c'.\n", info_type); return false; } }
-static bool operand_types_match(struct sm6_value *dst, const struct sm6_value **operands, unsigned int operand_count, - char index_char) -{ - unsigned int i = index_char - '0'; - - assert(i < 10); - if (i >= operand_count) - return false; - return dst->type == operands[i]->type; -} - static bool sm6_parser_validate_dx_op(struct sm6_parser *sm6, enum dx_intrinsic_opcode op, const char *name, const struct sm6_value **operands, unsigned int operand_count, struct sm6_value *dst) { @@ -3869,8 +3861,7 @@ static bool sm6_parser_validate_dx_op(struct sm6_parser *sm6, enum dx_intrinsic_ info = &sm6_dx_op_table[op];
assert(info->ret_type[0]); - if (!sm6_parser_validate_operand_type(sm6, dst, info->ret_type[0], true) - || (info->ret_type[1] && !operand_types_match(dst, operands, operand_count, info->ret_type[1]))) + if (!sm6_parser_validate_operand_type(sm6, dst, info->ret_type[0], NULL, true)) { WARN("Failed to validate return type for dx intrinsic id %u, '%s'.\n", op, name); /* Return type validation failure is not so critical. We only need to set @@ -3880,7 +3871,7 @@ static bool sm6_parser_validate_dx_op(struct sm6_parser *sm6, enum dx_intrinsic_ for (i = 0; i < operand_count; ++i) { const struct sm6_value *value = operands[i]; - if (!sm6_parser_validate_operand_type(sm6, value, info->operand_info[i], false)) + if (!sm6_parser_validate_operand_type(sm6, value, info->operand_info[i], dst->type, false)) { WARN("Failed to validate operand %u for dx intrinsic id %u, '%s'.\n", i + 1, op, name); vkd3d_shader_parser_error(&sm6->p, VKD3D_SHADER_ERROR_DXIL_INVALID_OPERAND,
From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/dxil.c | 47 +++++++++++++++++++ tests/hlsl/arithmetic-int-uniform.shader_test | 6 +-- tests/hlsl/clamp.shader_test | 2 +- tests/hlsl/max.shader_test | 4 +- 4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index b128b41fd..61ddb412d 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -342,6 +342,12 @@ enum dx_intrinsic_opcode DX_FIRST_BIT_LO = 32, DX_FIRST_BIT_HI = 33, DX_FIRST_BIT_SHI = 34, + DX_FMAX = 35, + DX_FMIN = 36, + DX_IMAX = 37, + DX_IMIN = 38, + DX_UMAX = 39, + DX_UMIN = 40, DX_CREATE_HANDLE = 57, DX_CBUFFER_LOAD_LEGACY = 59, DX_BUFFER_LOAD = 68, @@ -3546,6 +3552,41 @@ static void sm6_parser_emit_dx_unary(struct sm6_parser *sm6, enum dx_intrinsic_o instruction_dst_param_init_ssa_scalar(ins, sm6); }
+static enum vkd3d_shader_opcode map_dx_binary_op(enum dx_intrinsic_opcode op, const struct sm6_type *type) +{ + switch (op) + { + case DX_FMAX: + return type->u.width == 64 ? VKD3DSIH_DMAX : VKD3DSIH_MAX; + case DX_FMIN: + return type->u.width == 64 ? VKD3DSIH_DMIN : VKD3DSIH_MIN; + case DX_IMAX: + return VKD3DSIH_IMAX; + case DX_IMIN: + return VKD3DSIH_IMIN; + case DX_UMAX: + return VKD3DSIH_UMAX; + case DX_UMIN: + return VKD3DSIH_UMIN; + default: + vkd3d_unreachable(); + } +} + +static void sm6_parser_emit_dx_binary(struct sm6_parser *sm6, enum dx_intrinsic_opcode op, + const struct sm6_value **operands, struct function_emission_state *state) +{ + struct vkd3d_shader_instruction *ins = state->ins; + struct vkd3d_shader_src_param *src_params; + + vsir_instruction_init(ins, &sm6->p.location, map_dx_binary_op(op, operands[0]->type)); + src_params = instruction_src_params_alloc(ins, 2, sm6); + src_param_init_from_value(&src_params[0], operands[0]); + src_param_init_from_value(&src_params[1], operands[1]); + + 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) { @@ -3793,7 +3834,11 @@ static const struct sm6_dx_opcode_info sm6_dx_op_table[] = [DX_FIRST_BIT_HI ] = {"i", "m", sm6_parser_emit_dx_unary}, [DX_FIRST_BIT_LO ] = {"i", "m", sm6_parser_emit_dx_unary}, [DX_FIRST_BIT_SHI ] = {"i", "m", sm6_parser_emit_dx_unary}, + [DX_FMAX ] = {"g", "RR", sm6_parser_emit_dx_binary}, + [DX_FMIN ] = {"g", "RR", sm6_parser_emit_dx_binary}, [DX_FRC ] = {"g", "R", sm6_parser_emit_dx_unary}, + [DX_IMAX ] = {"m", "RR", sm6_parser_emit_dx_binary}, + [DX_IMIN ] = {"m", "RR", sm6_parser_emit_dx_binary}, [DX_LEGACY_F16TOF32 ] = {"f", "i", sm6_parser_emit_dx_unary}, [DX_LEGACY_F32TOF16 ] = {"i", "f", sm6_parser_emit_dx_unary}, [DX_LOAD_INPUT ] = {"o", "ii8i", sm6_parser_emit_dx_load_input}, @@ -3805,6 +3850,8 @@ static const struct sm6_dx_opcode_info sm6_dx_op_table[] = [DX_RSQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_SQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_STORE_OUTPUT ] = {"v", "ii8o", sm6_parser_emit_dx_store_output}, + [DX_UMAX ] = {"m", "RR", sm6_parser_emit_dx_binary}, + [DX_UMIN ] = {"m", "RR", sm6_parser_emit_dx_binary}, };
static bool sm6_parser_validate_operand_type(struct sm6_parser *sm6, const struct sm6_value *value, char info_type, diff --git a/tests/hlsl/arithmetic-int-uniform.shader_test b/tests/hlsl/arithmetic-int-uniform.shader_test index bb83eb76e..fe6ad7e9f 100644 --- a/tests/hlsl/arithmetic-int-uniform.shader_test +++ b/tests/hlsl/arithmetic-int-uniform.shader_test @@ -98,7 +98,7 @@ float4 main() : SV_TARGET
[test] uniform 0 float4 5.0 -7.0 0.0 -10.0 -todo(sm>=6) draw quad +draw quad probe all rgba (5.0, 7.0, 0.0, 10.0)
[pixel shader] @@ -194,5 +194,5 @@ float4 main() : SV_TARGET
[test] uniform 0 int64_t2 5000000000 -7000000000 -todo draw quad -probe all rgba (5.0, 7.0, 0.0, 0.0) +draw quad +probe all rgba (5.0e9, 7.0e9, 0.0, 0.0) diff --git a/tests/hlsl/clamp.shader_test b/tests/hlsl/clamp.shader_test index 3d797ec3f..40d0294bd 100644 --- a/tests/hlsl/clamp.shader_test +++ b/tests/hlsl/clamp.shader_test @@ -8,7 +8,7 @@ float4 main() : sv_target
[test] uniform 0 float4 -0.3 -0.1 0.7 0.0 -todo(sm>=6) draw quad +draw quad probe all rgba (-0.1, 0.7, -0.3, 0.3)
diff --git a/tests/hlsl/max.shader_test b/tests/hlsl/max.shader_test index e2763df46..09f4a882c 100644 --- a/tests/hlsl/max.shader_test +++ b/tests/hlsl/max.shader_test @@ -8,7 +8,7 @@ float4 main() : sv_target
[test] uniform 0 float4 0.7 -0.1 0.0 0.0 -todo(sm>=6) draw quad +draw quad probe all rgba (0.7, 2.1, 2.0, -1.0)
@@ -24,7 +24,7 @@ float4 main() : sv_target
[test] uniform 0 float4 0.7 -0.1 0.4 0.8 -todo(sm>=6) draw quad +draw quad probe all rgba (0.7, 0.8, 0.7, 0.2)