vkd3d-shader/hlsl: Implement the firstbitlow() intrinsic.

This commit is contained in:
Petrichor Park
2024-08-13 11:34:23 -05:00
committed by Henri Verbeet
parent e6d840170d
commit e35604dbf0
Notes: Henri Verbeet 2025-09-22 11:46:20 +02:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/965
9 changed files with 135 additions and 4 deletions

View File

@@ -334,6 +334,34 @@ static bool fold_countbits(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst
return true;
}
static bool fold_ctz(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
{
enum hlsl_base_type type = dst_type->e.numeric.type;
unsigned int k;
VKD3D_ASSERT(type == src->node.data_type->e.numeric.type);
for (k = 0; k < dst_type->e.numeric.dimx; ++k)
{
switch (type)
{
case HLSL_TYPE_UINT:
if (!src->value.u[k].u)
dst->u[k].u = ~0u;
else
dst->u[k].u = vkd3d_ctz(src->value.u[k].u);
break;
default:
FIXME("Fold 'ctz' for type %s.\n", debug_hlsl_type(ctx, dst_type));
return false;
}
}
return true;
}
static bool fold_exp2(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
{
@@ -1469,6 +1497,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
success = fold_countbits(ctx, &res, instr->data_type, arg1);
break;
case HLSL_OP1_CTZ:
success = fold_ctz(ctx, &res, instr->data_type, arg1);
break;
case HLSL_OP1_EXP2:
success = fold_exp2(ctx, &res, instr->data_type, arg1);
break;