mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Merge HLSL_OP3_MOVC into HLSL_OP3_TERNARY.
This commit is contained in:
parent
8f6f875a59
commit
3a0a4b625f
Notes:
Alexandre Julliard
2024-04-09 15:44:37 -05:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/744
@ -2631,7 +2631,6 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
|
||||
|
||||
[HLSL_OP3_CMP] = "cmp",
|
||||
[HLSL_OP3_DP2ADD] = "dp2add",
|
||||
[HLSL_OP3_MOVC] = "movc",
|
||||
[HLSL_OP3_TERNARY] = "ternary",
|
||||
};
|
||||
|
||||
|
@ -602,11 +602,8 @@ enum hlsl_ir_expr_op
|
||||
* then adds c. */
|
||||
HLSL_OP3_DP2ADD,
|
||||
/* TERNARY(a, b, c) returns 'b' if 'a' is true and 'c' otherwise. 'a' must always be boolean.
|
||||
* MOVC(a, b, c) returns 'c' if 'a' is bitwise zero and 'b' otherwise.
|
||||
* CMP(a, b, c) returns 'b' if 'a' >= 0, and 'c' otherwise. It's used only for SM1-SM3 targets,
|
||||
while SM4+ is using MOVC in such cases. */
|
||||
* CMP(a, b, c) returns 'b' if 'a' >= 0, and 'c' otherwise. It's used only for SM1-SM3 targets. */
|
||||
HLSL_OP3_CMP,
|
||||
HLSL_OP3_MOVC,
|
||||
HLSL_OP3_TERNARY,
|
||||
};
|
||||
|
||||
|
@ -2954,7 +2954,7 @@ static bool lower_logic_not(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, st
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Use movc/cmp for the ternary operator. */
|
||||
/* Lower TERNARY to CMP for SM1. */
|
||||
static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block)
|
||||
{
|
||||
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = { 0 }, *replacement;
|
||||
@ -2981,35 +2981,23 @@ static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, stru
|
||||
|
||||
assert(cond->data_type->base_type == HLSL_TYPE_BOOL);
|
||||
|
||||
if (ctx->profile->major_version < 4)
|
||||
{
|
||||
type = hlsl_get_numeric_type(ctx, instr->data_type->class, HLSL_TYPE_FLOAT,
|
||||
instr->data_type->dimx, instr->data_type->dimy);
|
||||
type = hlsl_get_numeric_type(ctx, instr->data_type->class, HLSL_TYPE_FLOAT,
|
||||
instr->data_type->dimx, instr->data_type->dimy);
|
||||
|
||||
if (!(float_cond = hlsl_new_cast(ctx, cond, type, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, float_cond);
|
||||
if (!(float_cond = hlsl_new_cast(ctx, cond, type, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, float_cond);
|
||||
|
||||
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, float_cond, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, neg);
|
||||
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, float_cond, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, neg);
|
||||
|
||||
memset(operands, 0, sizeof(operands));
|
||||
operands[0] = neg;
|
||||
operands[1] = second;
|
||||
operands[2] = first;
|
||||
if (!(replacement = hlsl_new_expr(ctx, HLSL_OP3_CMP, operands, first->data_type, &instr->loc)))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(operands, 0, sizeof(operands));
|
||||
operands[0] = cond;
|
||||
operands[1] = first;
|
||||
operands[2] = second;
|
||||
if (!(replacement = hlsl_new_expr(ctx, HLSL_OP3_MOVC, operands, first->data_type, &instr->loc)))
|
||||
return false;
|
||||
}
|
||||
memset(operands, 0, sizeof(operands));
|
||||
operands[0] = neg;
|
||||
operands[1] = second;
|
||||
operands[2] = first;
|
||||
if (!(replacement = hlsl_new_expr(ctx, HLSL_OP3_CMP, operands, first->data_type, &instr->loc)))
|
||||
return false;
|
||||
|
||||
hlsl_block_add_instr(block, replacement);
|
||||
return true;
|
||||
@ -5429,9 +5417,10 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
hlsl_transform_ir(ctx, track_object_components_usage, body, NULL);
|
||||
sort_synthetic_separated_samplers_first(ctx);
|
||||
|
||||
lower_ir(ctx, lower_ternary, body);
|
||||
if (profile->major_version < 4)
|
||||
{
|
||||
lower_ir(ctx, lower_ternary, body);
|
||||
|
||||
lower_ir(ctx, lower_nonfloat_exprs, body);
|
||||
/* Constants casted to float must be folded, and new casts to bool also need to be lowered. */
|
||||
hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL);
|
||||
|
@ -5343,7 +5343,7 @@ static void write_sm4_expr(const struct tpf_writer *tpf, const struct hlsl_ir_ex
|
||||
&expr->node, arg1, arg2);
|
||||
break;
|
||||
|
||||
case HLSL_OP3_MOVC:
|
||||
case HLSL_OP3_TERNARY:
|
||||
write_sm4_ternary_op(tpf, VKD3D_SM4_OP_MOVC, &expr->node, arg1, arg2, arg3);
|
||||
break;
|
||||
|
||||
|
@ -318,7 +318,7 @@ probe all rgba (2.0, 3.0, 3.0, 2.0)
|
||||
|
||||
% Objects can be used, but their types have to be identical.
|
||||
|
||||
[pixel shader todo]
|
||||
[pixel shader todo(sm<4)]
|
||||
Texture2D t;
|
||||
|
||||
float4 main() : sv_target
|
||||
|
Loading…
Reference in New Issue
Block a user