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

This commit is contained in:
Petrichor Park
2024-08-19 12:19:36 -05:00
committed by Henri Verbeet
parent 16cb69a324
commit e49beca0d5
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
7 changed files with 107 additions and 8 deletions

View File

@@ -280,6 +280,31 @@ static bool fold_cos(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
return true;
}
static bool fold_countbits(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:
dst->u[k].u = vkd3d_popcount(src->value.u[k].u);
break;
default:
FIXME("Fold 'countbits' 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)
{
@@ -1407,6 +1432,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
success = fold_cos(ctx, &res, instr->data_type, arg1);
break;
case HLSL_OP1_COUNTBITS:
success = fold_countbits(ctx, &res, instr->data_type, arg1);
break;
case HLSL_OP1_EXP2:
success = fold_exp2(ctx, &res, instr->data_type, arg1);
break;