Now that !319 is merged, we can continue replacing the sm4 register structs with vsir register structs.
This second part takes care of replacing sm4_register with vkd3d_shader_register.
Following patches in my [use_vkd3d_reg_5](https://gitlab.winehq.org/fcasas/vkd3d/-/commits/use_vkd3d_reg_5) branch.
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 64 +++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 6a9438b98..22006fac7 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -535,6 +535,20 @@ static enum vsir_dimension vsir_dimension_from_sm4_dimension(enum vkd3d_sm4_dime } }
+static enum vkd3d_sm4_dimension sm4_dimension_from_vsir_dimension(enum vsir_dimension dim) +{ + switch (dim) + { + case VSIR_DIMENSION_NONE: + return VKD3D_SM4_DIMENSION_NONE; + case VSIR_DIMENSION_SCALAR: + return VKD3D_SM4_DIMENSION_SCALAR; + case VSIR_DIMENSION_VEC4: + return VKD3D_SM4_DIMENSION_VEC4; + } + vkd3d_unreachable(); +} + enum vkd3d_sm4_resource_type { VKD3D_SM4_RESOURCE_BUFFER = 0x1, @@ -3594,7 +3608,7 @@ struct sm4_register enum vkd3d_shader_register_type type; struct vkd3d_shader_register_index idx[2]; unsigned int idx_count; - enum vkd3d_sm4_dimension dim; + enum vsir_dimension dimension; uint32_t immconst_uint[4]; unsigned int mod; }; @@ -3641,7 +3655,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r if (regset == HLSL_REGSET_TEXTURES) { reg->type = VKD3DSPR_RESOURCE; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = var->regs[HLSL_REGSET_TEXTURES].id; @@ -3653,7 +3667,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r else if (regset == HLSL_REGSET_UAVS) { reg->type = VKD3DSPR_UAV; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = var->regs[HLSL_REGSET_UAVS].id; @@ -3665,7 +3679,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r else if (regset == HLSL_REGSET_SAMPLERS) { reg->type = VKD3DSPR_SAMPLER; - reg->dim = VKD3D_SM4_DIMENSION_NONE; + reg->dimension = VSIR_DIMENSION_NONE; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_NONE; reg->idx[0].offset = var->regs[HLSL_REGSET_SAMPLERS].id; @@ -3680,7 +3694,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
assert(data_type->class <= HLSL_CLASS_VECTOR); reg->type = VKD3DSPR_CONSTBUFFER; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = var->buffer->reg.id; @@ -3703,7 +3717,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r reg->idx_count = 1; }
- reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; *writemask = ((1u << data_type->dimx) - 1) << (offset % 4); } else @@ -3712,7 +3726,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
assert(hlsl_reg.allocated); reg->type = VKD3DSPR_INPUT; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = hlsl_reg.id; @@ -3735,9 +3749,9 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r }
if (reg->type == VKD3DSPR_DEPTHOUT) - reg->dim = VKD3D_SM4_DIMENSION_SCALAR; + reg->dimension = VSIR_DIMENSION_SCALAR; else - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; *writemask = ((1u << data_type->dimx) - 1) << (offset % 4); } else @@ -3746,7 +3760,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
assert(hlsl_reg.allocated); reg->type = VKD3DSPR_OUTPUT; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; reg->idx[0].offset = hlsl_reg.id; reg->idx_count = 1; *writemask = hlsl_reg.writemask; @@ -3758,7 +3772,7 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
assert(hlsl_reg.allocated); reg->type = VKD3DSPR_TEMP; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; if (swizzle_type) *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = hlsl_reg.id; @@ -3782,7 +3796,7 @@ static void sm4_register_from_node(struct sm4_register *reg, unsigned int *write { assert(instr->reg.allocated); reg->type = VKD3DSPR_TEMP; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->dimension = VSIR_DIMENSION_VEC4; *swizzle_type = VKD3D_SM4_SWIZZLE_VEC4; reg->idx[0].offset = instr->reg.id; reg->idx_count = 1; @@ -3803,14 +3817,14 @@ static void sm4_src_from_constant_value(struct sm4_src_register *src, src->reg.type = VKD3DSPR_IMMCONST; if (width == 1) { - src->reg.dim = VKD3D_SM4_DIMENSION_SCALAR; + src->reg.dimension = VSIR_DIMENSION_SCALAR; src->reg.immconst_uint[0] = value->u[0].u; } else { unsigned int i, j = 0;
- src->reg.dim = VKD3D_SM4_DIMENSION_VEC4; + src->reg.dimension = VSIR_DIMENSION_VEC4; for (i = 0; i < 4; ++i) { if ((map_writemask & (1u << i)) && (j < width)) @@ -3858,7 +3872,7 @@ static void sm4_write_dst_register(const struct tpf_writer *tpf, const struct sm sm4_reg_type = register_type_info->sm4_type; }
- reg_dim = dst->reg.dim; + reg_dim = sm4_dimension_from_vsir_dimension(dst->reg.dimension);
token |= sm4_reg_type << VKD3D_SM4_REGISTER_TYPE_SHIFT; token |= dst->reg.idx_count << VKD3D_SM4_REGISTER_ORDER_SHIFT; @@ -3893,7 +3907,7 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm sm4_reg_type = register_type_info->sm4_type; }
- reg_dim = src->reg.dim; + reg_dim = sm4_dimension_from_vsir_dimension(src->reg.dimension);
token |= sm4_reg_type << VKD3D_SM4_REGISTER_TYPE_SHIFT; token |= src->reg.idx_count << VKD3D_SM4_REGISTER_ORDER_SHIFT; @@ -3933,7 +3947,7 @@ static uint32_t sm4_register_order(const struct sm4_register *reg) { uint32_t order = 1; if (reg->type == VKD3DSPR_IMMCONST) - order += reg->dim == VKD3D_SM4_DIMENSION_VEC4 ? 4 : 1; + order += reg->dimension == VSIR_DIMENSION_VEC4 ? 4 : 1; order += reg->idx_count; if (reg->mod) ++order; @@ -4015,7 +4029,7 @@ static void write_sm4_dcl_constant_buffer(const struct tpf_writer *tpf, const st { .opcode = VKD3D_SM4_OP_DCL_CONSTANT_BUFFER,
- .srcs[0].reg.dim = VKD3D_SM4_DIMENSION_VEC4, + .srcs[0].reg.dimension = VSIR_DIMENSION_VEC4, .srcs[0].reg.type = VKD3DSPR_CONSTBUFFER, .srcs[0].reg.idx[0].offset = cbuffer->reg.id, .srcs[0].reg.idx[1].offset = (cbuffer->used_size + 3) / 4, @@ -4123,7 +4137,7 @@ static void write_sm4_dcl_semantic(const struct tpf_writer *tpf, const struct hl
struct sm4_instruction instr = { - .dsts[0].reg.dim = VKD3D_SM4_DIMENSION_VEC4, + .dsts[0].reg.dimension = VSIR_DIMENSION_VEC4, .dst_count = 1, };
@@ -4149,7 +4163,7 @@ static void write_sm4_dcl_semantic(const struct tpf_writer *tpf, const struct hl }
if (instr.dsts[0].reg.type == VKD3DSPR_DEPTHOUT) - instr.dsts[0].reg.dim = VKD3D_SM4_DIMENSION_SCALAR; + instr.dsts[0].reg.dimension = VSIR_DIMENSION_SCALAR;
hlsl_sm4_usage_from_semantic(tpf->ctx, &var->semantic, output, &usage); if (usage == ~0u) @@ -4282,7 +4296,7 @@ static void write_sm4_unary_op_with_two_destinations(const struct tpf_writer *tp sm4_dst_from_node(&instr.dsts[dst_idx], dst); assert(1 - dst_idx >= 0); instr.dsts[1 - dst_idx].reg.type = VKD3DSPR_NULL; - instr.dsts[1 - dst_idx].reg.dim = VKD3D_SM4_DIMENSION_NONE; + instr.dsts[1 - dst_idx].reg.dimension = VSIR_DIMENSION_NONE; instr.dsts[1 - dst_idx].reg.idx_count = 0; instr.dst_count = 2;
@@ -4342,7 +4356,7 @@ static void write_sm4_binary_op_with_two_destinations(const struct tpf_writer *t sm4_dst_from_node(&instr.dsts[dst_idx], dst); assert(1 - dst_idx >= 0); instr.dsts[1 - dst_idx].reg.type = VKD3DSPR_NULL; - instr.dsts[1 - dst_idx].reg.dim = VKD3D_SM4_DIMENSION_NONE; + instr.dsts[1 - dst_idx].reg.dimension = VSIR_DIMENSION_NONE; instr.dsts[1 - dst_idx].reg.idx_count = 0; instr.dst_count = 2;
@@ -4434,7 +4448,7 @@ static void write_sm4_ld(const struct tpf_writer *tpf, const struct hlsl_ir_node memset(&instr.srcs[2], 0, sizeof(instr.srcs[2])); instr.srcs[2].swizzle_type = VKD3D_SM4_SWIZZLE_NONE; reg->type = VKD3DSPR_IMMCONST; - reg->dim = VKD3D_SM4_DIMENSION_SCALAR; + reg->dimension = VSIR_DIMENSION_SCALAR; reg->immconst_uint[0] = index->value.u[0].u; } else if (tpf->ctx->profile->major_version == 4 && tpf->ctx->profile->minor_version == 0) @@ -4596,7 +4610,7 @@ static void write_sm4_cast_from_bool(const struct tpf_writer *tpf, const struct sm4_src_from_node(&instr.srcs[0], arg, instr.dsts[0].writemask); instr.srcs[1].swizzle_type = VKD3D_SM4_SWIZZLE_NONE; instr.srcs[1].reg.type = VKD3DSPR_IMMCONST; - instr.srcs[1].reg.dim = VKD3D_SM4_DIMENSION_SCALAR; + instr.srcs[1].reg.dimension = VSIR_DIMENSION_SCALAR; instr.srcs[1].reg.immconst_uint[0] = mask; instr.src_count = 2;
@@ -5331,7 +5345,7 @@ static void write_sm4_gather(const struct tpf_writer *tpf, const struct hlsl_ir_
src = &instr.srcs[instr.src_count++]; sm4_src_from_deref(tpf->ctx, src, sampler, VKD3DSP_WRITEMASK_ALL); - src->reg.dim = VKD3D_SM4_DIMENSION_VEC4; + src->reg.dimension = VSIR_DIMENSION_VEC4; src->swizzle_type = VKD3D_SM4_SWIZZLE_SCALAR; src->swizzle = swizzle;
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 22006fac7..c571c2ddf 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3609,7 +3609,10 @@ struct sm4_register struct vkd3d_shader_register_index idx[2]; unsigned int idx_count; enum vsir_dimension dimension; - uint32_t immconst_uint[4]; + union + { + uint32_t immconst_uint[4]; + } u; unsigned int mod; };
@@ -3818,7 +3821,7 @@ static void sm4_src_from_constant_value(struct sm4_src_register *src, if (width == 1) { src->reg.dimension = VSIR_DIMENSION_SCALAR; - src->reg.immconst_uint[0] = value->u[0].u; + src->reg.u.immconst_uint[0] = value->u[0].u; } else { @@ -3828,9 +3831,9 @@ static void sm4_src_from_constant_value(struct sm4_src_register *src, for (i = 0; i < 4; ++i) { if ((map_writemask & (1u << i)) && (j < width)) - src->reg.immconst_uint[i] = value->u[j++].u; + src->reg.u.immconst_uint[i] = value->u[j++].u; else - src->reg.immconst_uint[i] = 0; + src->reg.u.immconst_uint[i] = 0; } } } @@ -3933,12 +3936,12 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm
if (src->reg.type == VKD3DSPR_IMMCONST) { - put_u32(buffer, src->reg.immconst_uint[0]); + put_u32(buffer, src->reg.u.immconst_uint[0]); if (reg_dim == VKD3D_SM4_DIMENSION_VEC4) { - put_u32(buffer, src->reg.immconst_uint[1]); - put_u32(buffer, src->reg.immconst_uint[2]); - put_u32(buffer, src->reg.immconst_uint[3]); + put_u32(buffer, src->reg.u.immconst_uint[1]); + put_u32(buffer, src->reg.u.immconst_uint[2]); + put_u32(buffer, src->reg.u.immconst_uint[3]); } } } @@ -4449,7 +4452,7 @@ static void write_sm4_ld(const struct tpf_writer *tpf, const struct hlsl_ir_node instr.srcs[2].swizzle_type = VKD3D_SM4_SWIZZLE_NONE; reg->type = VKD3DSPR_IMMCONST; reg->dimension = VSIR_DIMENSION_SCALAR; - reg->immconst_uint[0] = index->value.u[0].u; + reg->u.immconst_uint[0] = index->value.u[0].u; } else if (tpf->ctx->profile->major_version == 4 && tpf->ctx->profile->minor_version == 0) { @@ -4611,7 +4614,7 @@ static void write_sm4_cast_from_bool(const struct tpf_writer *tpf, const struct instr.srcs[1].swizzle_type = VKD3D_SM4_SWIZZLE_NONE; instr.srcs[1].reg.type = VKD3DSPR_IMMCONST; instr.srcs[1].reg.dimension = VSIR_DIMENSION_SCALAR; - instr.srcs[1].reg.immconst_uint[0] = mask; + instr.srcs[1].reg.u.immconst_uint[0] = mask; instr.src_count = 2;
write_sm4_instruction(tpf, &instr);
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c571c2ddf..12fa070ce 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3613,7 +3613,6 @@ struct sm4_register { uint32_t immconst_uint[4]; } u; - unsigned int mod; };
struct sm4_instruction @@ -3635,6 +3634,7 @@ struct sm4_instruction struct sm4_register reg; enum vkd3d_sm4_swizzle_type swizzle_type; unsigned int swizzle; + unsigned int mod; } srcs[5]; unsigned int src_count;
@@ -3920,12 +3920,12 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm token |= (uint32_t)src->swizzle_type << VKD3D_SM4_SWIZZLE_TYPE_SHIFT; token |= src->swizzle << VKD3D_SM4_SWIZZLE_SHIFT; } - if (src->reg.mod) + if (src->mod) token |= VKD3D_SM4_EXTENDED_OPERAND; put_u32(buffer, token);
- if (src->reg.mod) - put_u32(buffer, (src->reg.mod << VKD3D_SM4_REGISTER_MODIFIER_SHIFT) + if (src->mod) + put_u32(buffer, (src->mod << VKD3D_SM4_REGISTER_MODIFIER_SHIFT) | VKD3D_SM4_EXTENDED_OPERAND_MODIFIER);
for (j = 0; j < src->reg.idx_count; ++j) @@ -3946,13 +3946,22 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm } }
-static uint32_t sm4_register_order(const struct sm4_register *reg) +static uint32_t sm4_dst_register_order(const struct sm4_dst_register *dst) { uint32_t order = 1; - if (reg->type == VKD3DSPR_IMMCONST) - order += reg->dimension == VSIR_DIMENSION_VEC4 ? 4 : 1; - order += reg->idx_count; - if (reg->mod) + if (dst->reg.type == VKD3DSPR_IMMCONST) + order += dst->reg.dimension == VSIR_DIMENSION_VEC4 ? 4 : 1; + order += dst->reg.idx_count; + return order; +} + +static uint32_t sm4_src_register_order(const struct sm4_src_register *src) +{ + uint32_t order = 1; + if (src->reg.type == VKD3DSPR_IMMCONST) + order += src->reg.dimension == VSIR_DIMENSION_VEC4 ? 4 : 1; + order += src->reg.idx_count; + if (src->mod) ++order; return order; } @@ -3965,9 +3974,9 @@ static void write_sm4_instruction(const struct tpf_writer *tpf, const struct sm4
size += instr->modifier_count; for (i = 0; i < instr->dst_count; ++i) - size += sm4_register_order(&instr->dsts[i].reg); + size += sm4_dst_register_order(&instr->dsts[i]); for (i = 0; i < instr->src_count; ++i) - size += sm4_register_order(&instr->srcs[i].reg); + size += sm4_src_register_order(&instr->srcs[i]); size += instr->idx_count; if (instr->byte_stride) ++size; @@ -4281,7 +4290,7 @@ static void write_sm4_unary_op(const struct tpf_writer *tpf, enum vkd3d_sm4_opco instr.dst_count = 1;
sm4_src_from_node(&instr.srcs[0], src, instr.dsts[0].writemask); - instr.srcs[0].reg.mod = src_mod; + instr.srcs[0].mod = src_mod; instr.src_count = 1;
write_sm4_instruction(tpf, &instr);
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 12fa070ce..c79b80577 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3603,18 +3603,6 @@ static uint32_t sm4_encode_instruction_modifier(const struct sm4_instruction_mod return word; }
-struct sm4_register -{ - enum vkd3d_shader_register_type type; - struct vkd3d_shader_register_index idx[2]; - unsigned int idx_count; - enum vsir_dimension dimension; - union - { - uint32_t immconst_uint[4]; - } u; -}; - struct sm4_instruction { enum vkd3d_sm4_opcode opcode; @@ -3624,14 +3612,14 @@ struct sm4_instruction
struct sm4_dst_register { - struct sm4_register reg; + struct vkd3d_shader_register reg; unsigned int writemask; } dsts[2]; unsigned int dst_count;
struct sm4_src_register { - struct sm4_register reg; + struct vkd3d_shader_register reg; enum vkd3d_sm4_swizzle_type swizzle_type; unsigned int swizzle; unsigned int mod; @@ -3644,7 +3632,7 @@ struct sm4_instruction unsigned int idx_count; };
-static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *reg, +static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct vkd3d_shader_register *reg, unsigned int *writemask, enum vkd3d_sm4_swizzle_type *swizzle_type, const struct hlsl_deref *deref) { @@ -3794,7 +3782,7 @@ static void sm4_src_from_deref(struct hlsl_ctx *ctx, struct sm4_src_register *sr src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); }
-static void sm4_register_from_node(struct sm4_register *reg, unsigned int *writemask, +static void sm4_register_from_node(struct vkd3d_shader_register *reg, unsigned int *writemask, enum vkd3d_sm4_swizzle_type *swizzle_type, const struct hlsl_ir_node *instr) { assert(instr->reg.allocated); @@ -4452,7 +4440,7 @@ static void write_sm4_ld(const struct tpf_writer *tpf, const struct hlsl_ir_node { if (sample_index->type == HLSL_IR_CONSTANT) { - struct sm4_register *reg = &instr.srcs[2].reg; + struct vkd3d_shader_register *reg = &instr.srcs[2].reg; struct hlsl_ir_constant *index;
index = hlsl_ir_constant(sample_index);
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Henri Verbeet.