From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c79b8057..718667b3 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3613,7 +3613,7 @@ struct sm4_instruction struct sm4_dst_register { struct vkd3d_shader_register reg; - unsigned int writemask; + unsigned int write_mask; } dsts[2]; unsigned int dst_count;
@@ -3798,7 +3798,7 @@ static void sm4_dst_from_node(struct sm4_dst_register *dst, const struct hlsl_ir { unsigned int swizzle_type;
- sm4_register_from_node(&dst->reg, &dst->writemask, &swizzle_type, instr); + sm4_register_from_node(&dst->reg, &dst->write_mask, &swizzle_type, instr); }
static void sm4_src_from_constant_value(struct sm4_src_register *src, @@ -3869,7 +3869,7 @@ static void sm4_write_dst_register(const struct tpf_writer *tpf, const struct sm token |= dst->reg.idx_count << VKD3D_SM4_REGISTER_ORDER_SHIFT; token |= reg_dim << VKD3D_SM4_DIMENSION_SHIFT; if (reg_dim == VKD3D_SM4_DIMENSION_VEC4) - token |= dst->writemask << VKD3D_SM4_WRITEMASK_SHIFT; + token |= dst->write_mask << VKD3D_SM4_WRITEMASK_SHIFT; put_u32(buffer, token);
for (j = 0; j < dst->reg.idx_count; ++j) @@ -4152,14 +4152,14 @@ static void write_sm4_dcl_semantic(const struct tpf_writer *tpf, const struct hl { instr.dsts[0].reg.idx_count = 0; } - instr.dsts[0].writemask = (1 << var->data_type->dimx) - 1; + instr.dsts[0].write_mask = (1 << var->data_type->dimx) - 1; } else { instr.dsts[0].reg.type = output ? VKD3DSPR_OUTPUT : VKD3DSPR_INPUT; instr.dsts[0].reg.idx[0].offset = var->regs[HLSL_REGSET_NUMERIC].id; instr.dsts[0].reg.idx_count = 1; - instr.dsts[0].writemask = var->regs[HLSL_REGSET_NUMERIC].writemask; + instr.dsts[0].write_mask = var->regs[HLSL_REGSET_NUMERIC].writemask; }
if (instr.dsts[0].reg.type == VKD3DSPR_DEPTHOUT) @@ -4277,7 +4277,7 @@ static void write_sm4_unary_op(const struct tpf_writer *tpf, enum vkd3d_sm4_opco sm4_dst_from_node(&instr.dsts[0], dst); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], src, instr.dsts[0].writemask); + sm4_src_from_node(&instr.srcs[0], src, instr.dsts[0].write_mask); instr.srcs[0].mod = src_mod; instr.src_count = 1;
@@ -4300,7 +4300,7 @@ static void write_sm4_unary_op_with_two_destinations(const struct tpf_writer *tp instr.dsts[1 - dst_idx].reg.idx_count = 0; instr.dst_count = 2;
- sm4_src_from_node(&instr.srcs[0], src, instr.dsts[dst_idx].writemask); + sm4_src_from_node(&instr.srcs[0], src, instr.dsts[dst_idx].write_mask); instr.src_count = 1;
write_sm4_instruction(tpf, &instr); @@ -4317,8 +4317,8 @@ static void write_sm4_binary_op(const struct tpf_writer *tpf, enum vkd3d_sm4_opc sm4_dst_from_node(&instr.dsts[0], dst); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[0].writemask); - sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[0].writemask); + sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[0].write_mask); + sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[0].write_mask); instr.src_count = 2;
write_sm4_instruction(tpf, &instr); @@ -4360,8 +4360,8 @@ static void write_sm4_binary_op_with_two_destinations(const struct tpf_writer *t instr.dsts[1 - dst_idx].reg.idx_count = 0; instr.dst_count = 2;
- sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[dst_idx].writemask); - sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[dst_idx].writemask); + sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[dst_idx].write_mask); + sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[dst_idx].write_mask); instr.src_count = 2;
write_sm4_instruction(tpf, &instr); @@ -4379,9 +4379,9 @@ static void write_sm4_ternary_op(const struct tpf_writer *tpf, enum vkd3d_sm4_op sm4_dst_from_node(&instr.dsts[0], dst); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[0].writemask); - sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[0].writemask); - sm4_src_from_node(&instr.srcs[2], src3, instr.dsts[0].writemask); + sm4_src_from_node(&instr.srcs[0], src1, instr.dsts[0].write_mask); + sm4_src_from_node(&instr.srcs[1], src2, instr.dsts[0].write_mask); + sm4_src_from_node(&instr.srcs[2], src3, instr.dsts[0].write_mask); instr.src_count = 3;
write_sm4_instruction(tpf, &instr); @@ -4432,7 +4432,7 @@ static void write_sm4_ld(const struct tpf_writer *tpf, const struct hlsl_ir_node
sm4_src_from_node(&instr.srcs[0], coords, coords_writemask);
- sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].write_mask);
instr.src_count = 2;
@@ -4520,7 +4520,7 @@ static void write_sm4_sample(const struct tpf_writer *tpf, const struct hlsl_ir_ instr.dst_count = 1;
sm4_src_from_node(&instr.srcs[0], coords, VKD3DSP_WRITEMASK_ALL); - sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].write_mask); sm4_src_from_deref(tpf->ctx, &instr.srcs[2], sampler, VKD3DSP_WRITEMASK_ALL); instr.src_count = 3;
@@ -4562,7 +4562,7 @@ static void write_sm4_sampleinfo(const struct tpf_writer *tpf, const struct hlsl sm4_dst_from_node(&instr.dsts[0], dst); instr.dst_count = 1;
- sm4_src_from_deref(tpf->ctx, &instr.srcs[0], resource, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[0], resource, instr.dsts[0].write_mask); instr.src_count = 1;
write_sm4_instruction(tpf, &instr); @@ -4585,7 +4585,7 @@ static void write_sm4_resinfo(const struct tpf_writer *tpf, const struct hlsl_ir instr.dst_count = 1;
sm4_src_from_node(&instr.srcs[0], load->lod.node, VKD3DSP_WRITEMASK_ALL); - sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[1], resource, instr.dsts[0].write_mask); instr.src_count = 2;
write_sm4_instruction(tpf, &instr); @@ -4607,7 +4607,7 @@ static void write_sm4_cast_from_bool(const struct tpf_writer *tpf, const struct sm4_dst_from_node(&instr.dsts[0], &expr->node); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], arg, instr.dsts[0].writemask); + sm4_src_from_node(&instr.srcs[0], arg, instr.dsts[0].write_mask); instr.srcs[1].swizzle_type = VKD3D_SM4_SWIZZLE_NONE; instr.srcs[1].reg.type = VKD3DSPR_IMMCONST; instr.srcs[1].reg.dimension = VSIR_DIMENSION_SCALAR; @@ -4734,7 +4734,7 @@ static void write_sm4_store_uav_typed(const struct tpf_writer *tpf, const struct memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM5_OP_STORE_UAV_TYPED;
- sm4_register_from_deref(tpf->ctx, &instr.dsts[0].reg, &instr.dsts[0].writemask, NULL, dst); + sm4_register_from_deref(tpf->ctx, &instr.dsts[0].reg, &instr.dsts[0].write_mask, NULL, dst); instr.dst_count = 1;
sm4_src_from_node(&instr.srcs[0], coords, VKD3DSP_WRITEMASK_ALL); @@ -5276,19 +5276,19 @@ static void write_sm4_load(const struct tpf_writer *tpf, const struct hlsl_ir_lo
instr.opcode = VKD3D_SM4_OP_MOVC;
- sm4_src_from_deref(tpf->ctx, &instr.srcs[0], &load->src, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[0], &load->src, instr.dsts[0].write_mask);
memset(&value, 0xff, sizeof(value)); - sm4_src_from_constant_value(&instr.srcs[1], &value, type->dimx, instr.dsts[0].writemask); + sm4_src_from_constant_value(&instr.srcs[1], &value, type->dimx, instr.dsts[0].write_mask); memset(&value, 0, sizeof(value)); - sm4_src_from_constant_value(&instr.srcs[2], &value, type->dimx, instr.dsts[0].writemask); + sm4_src_from_constant_value(&instr.srcs[2], &value, type->dimx, instr.dsts[0].write_mask); instr.src_count = 3; } else { instr.opcode = VKD3D_SM4_OP_MOV;
- sm4_src_from_deref(tpf->ctx, &instr.srcs[0], &load->src, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[0], &load->src, instr.dsts[0].write_mask); instr.src_count = 1; }
@@ -5341,7 +5341,7 @@ static void write_sm4_gather(const struct tpf_writer *tpf, const struct hlsl_ir_ } }
- sm4_src_from_deref(tpf->ctx, &instr.srcs[instr.src_count++], resource, instr.dsts[0].writemask); + sm4_src_from_deref(tpf->ctx, &instr.srcs[instr.src_count++], resource, instr.dsts[0].write_mask);
src = &instr.srcs[instr.src_count++]; sm4_src_from_deref(tpf->ctx, src, sampler, VKD3DSP_WRITEMASK_ALL); @@ -5447,10 +5447,10 @@ static void write_sm4_store(const struct tpf_writer *tpf, const struct hlsl_ir_s instr.opcode = VKD3D_SM4_OP_MOV;
sm4_register_from_deref(tpf->ctx, &instr.dsts[0].reg, &writemask, NULL, &store->lhs); - instr.dsts[0].writemask = hlsl_combine_writemasks(writemask, store->writemask); + instr.dsts[0].write_mask = hlsl_combine_writemasks(writemask, store->writemask); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], rhs, instr.dsts[0].writemask); + sm4_src_from_node(&instr.srcs[0], rhs, instr.dsts[0].write_mask); instr.src_count = 1;
write_sm4_instruction(tpf, &instr); @@ -5469,7 +5469,7 @@ static void write_sm4_swizzle(const struct tpf_writer *tpf, const struct hlsl_ir
sm4_register_from_node(&instr.srcs[0].reg, &writemask, &instr.srcs[0].swizzle_type, swizzle->val.node); instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_combine_swizzles(hlsl_swizzle_from_writemask(writemask), - swizzle->swizzle, swizzle->node.data_type->dimx), instr.dsts[0].writemask); + swizzle->swizzle, swizzle->node.data_type->dimx), instr.dsts[0].write_mask); instr.src_count = 1;
write_sm4_instruction(tpf, &instr);
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 718667b3..a63f0d65 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3610,11 +3610,7 @@ struct sm4_instruction struct sm4_instruction_modifier modifiers[1]; unsigned int modifier_count;
- struct sm4_dst_register - { - struct vkd3d_shader_register reg; - unsigned int write_mask; - } dsts[2]; + struct vkd3d_shader_dst_param dsts[2]; unsigned int dst_count;
struct sm4_src_register @@ -3794,7 +3790,7 @@ static void sm4_register_from_node(struct vkd3d_shader_register *reg, unsigned i *writemask = instr->reg.writemask; }
-static void sm4_dst_from_node(struct sm4_dst_register *dst, const struct hlsl_ir_node *instr) +static void sm4_dst_from_node(struct vkd3d_shader_dst_param *dst, const struct hlsl_ir_node *instr) { unsigned int swizzle_type;
@@ -3844,7 +3840,7 @@ static void sm4_src_from_node(struct sm4_src_register *src, src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); }
-static void sm4_write_dst_register(const struct tpf_writer *tpf, const struct sm4_dst_register *dst) +static void sm4_write_dst_register(const struct tpf_writer *tpf, const struct vkd3d_shader_dst_param *dst) { const struct vkd3d_sm4_register_type_info *register_type_info; struct vkd3d_bytecode_buffer *buffer = tpf->buffer; @@ -3934,7 +3930,7 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm } }
-static uint32_t sm4_dst_register_order(const struct sm4_dst_register *dst) +static uint32_t vkd3d_shader_dst_param_order(const struct vkd3d_shader_dst_param *dst) { uint32_t order = 1; if (dst->reg.type == VKD3DSPR_IMMCONST) @@ -3962,7 +3958,7 @@ 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_dst_register_order(&instr->dsts[i]); + size += vkd3d_shader_dst_param_order(&instr->dsts[i]); for (i = 0; i < instr->src_count; ++i) size += sm4_src_register_order(&instr->srcs[i]); size += instr->idx_count;
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 48 ++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index a63f0d65..63771736 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -1954,6 +1954,16 @@ static uint32_t swizzle_from_sm4(uint32_t s) return vkd3d_shader_create_swizzle(s & 0x3, (s >> 2) & 0x3, (s >> 4) & 0x3, (s >> 6) & 0x3); }
+static uint32_t swizzle_to_sm4(uint32_t s) +{ + uint32_t ret = 0; + ret |= ((vkd3d_swizzle_get_component(s, 0)) & 0x3); + ret |= ((vkd3d_swizzle_get_component(s, 1)) & 0x3) << 2; + ret |= ((vkd3d_swizzle_get_component(s, 2)) & 0x3) << 4; + ret |= ((vkd3d_swizzle_get_component(s, 3)) & 0x3) << 6; + return ret; +} + static bool register_is_input_output(const struct vkd3d_shader_register *reg) { switch (reg->type) @@ -3617,7 +3627,7 @@ struct sm4_instruction { struct vkd3d_shader_register reg; enum vkd3d_sm4_swizzle_type swizzle_type; - unsigned int swizzle; + DWORD swizzle; unsigned int mod; } srcs[5]; unsigned int src_count; @@ -3771,11 +3781,14 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct vkd3d_shader_re static void sm4_src_from_deref(struct hlsl_ctx *ctx, struct sm4_src_register *src, const struct hlsl_deref *deref, unsigned int map_writemask) { - unsigned int writemask; + unsigned int writemask, hlsl_swizzle;
sm4_register_from_deref(ctx, &src->reg, &writemask, &src->swizzle_type, deref); if (src->swizzle_type == VKD3D_SM4_SWIZZLE_VEC4) - src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); + { + hlsl_swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); + src->swizzle = swizzle_from_sm4(hlsl_swizzle); + } }
static void sm4_register_from_node(struct vkd3d_shader_register *reg, unsigned int *writemask, @@ -3800,6 +3813,7 @@ static void sm4_dst_from_node(struct vkd3d_shader_dst_param *dst, const struct h static void sm4_src_from_constant_value(struct sm4_src_register *src, const struct hlsl_constant_value *value, unsigned int width, unsigned int map_writemask) { + src->swizzle = VKD3D_SHADER_NO_SWIZZLE; src->swizzle_type = VKD3D_SM4_SWIZZLE_NONE; src->reg.type = VKD3DSPR_IMMCONST; if (width == 1) @@ -3825,7 +3839,7 @@ static void sm4_src_from_constant_value(struct sm4_src_register *src, static void sm4_src_from_node(struct sm4_src_register *src, const struct hlsl_ir_node *instr, unsigned int map_writemask) { - unsigned int writemask; + unsigned int writemask, hlsl_swizzle;
if (instr->type == HLSL_IR_CONSTANT) { @@ -3837,7 +3851,10 @@ static void sm4_src_from_node(struct sm4_src_register *src,
sm4_register_from_node(&src->reg, &writemask, &src->swizzle_type, instr); if (src->swizzle_type == VKD3D_SM4_SWIZZLE_VEC4) - src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); + { + hlsl_swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask); + src->swizzle = swizzle_from_sm4(hlsl_swizzle); + } }
static void sm4_write_dst_register(const struct tpf_writer *tpf, const struct vkd3d_shader_dst_param *dst) @@ -3902,7 +3919,7 @@ static void sm4_write_src_register(const struct tpf_writer *tpf, const struct sm if (reg_dim == VKD3D_SM4_DIMENSION_VEC4) { token |= (uint32_t)src->swizzle_type << VKD3D_SM4_SWIZZLE_TYPE_SHIFT; - token |= src->swizzle << VKD3D_SM4_SWIZZLE_SHIFT; + token |= swizzle_to_sm4(src->swizzle) << VKD3D_SM4_SWIZZLE_SHIFT; } if (src->mod) token |= VKD3D_SM4_EXTENDED_OPERAND; @@ -4031,7 +4048,7 @@ static void write_sm4_dcl_constant_buffer(const struct tpf_writer *tpf, const st .srcs[0].reg.idx[1].offset = (cbuffer->used_size + 3) / 4, .srcs[0].reg.idx_count = 2, .srcs[0].swizzle_type = VKD3D_SM4_SWIZZLE_VEC4, - .srcs[0].swizzle = HLSL_SWIZZLE(X, Y, Z, W), + .srcs[0].swizzle = VKD3D_SHADER_NO_SWIZZLE, .src_count = 1, }; write_sm4_instruction(tpf, &instr); @@ -5307,8 +5324,8 @@ static void write_sm4_loop(const struct tpf_writer *tpf, const struct hlsl_ir_lo }
static void write_sm4_gather(const struct tpf_writer *tpf, const struct hlsl_ir_node *dst, - const struct hlsl_deref *resource, const struct hlsl_deref *sampler, const struct hlsl_ir_node *coords, - unsigned int swizzle, const struct hlsl_ir_node *texel_offset) + const struct hlsl_deref *resource, const struct hlsl_deref *sampler, + const struct hlsl_ir_node *coords, DWORD swizzle, const struct hlsl_ir_node *texel_offset) { struct sm4_src_register *src; struct sm4_instruction instr; @@ -5386,22 +5403,22 @@ static void write_sm4_resource_load(const struct tpf_writer *tpf, const struct h
case HLSL_RESOURCE_GATHER_RED: write_sm4_gather(tpf, &load->node, &load->resource, &load->sampler, coords, - HLSL_SWIZZLE(X, X, X, X), texel_offset); + VKD3D_SHADER_SWIZZLE(X, X, X, X), texel_offset); break;
case HLSL_RESOURCE_GATHER_GREEN: write_sm4_gather(tpf, &load->node, &load->resource, &load->sampler, coords, - HLSL_SWIZZLE(Y, Y, Y, Y), texel_offset); + VKD3D_SHADER_SWIZZLE(Y, Y, Y, Y), texel_offset); break;
case HLSL_RESOURCE_GATHER_BLUE: write_sm4_gather(tpf, &load->node, &load->resource, &load->sampler, coords, - HLSL_SWIZZLE(Z, Z, Z, Z), texel_offset); + VKD3D_SHADER_SWIZZLE(Z, Z, Z, Z), texel_offset); break;
case HLSL_RESOURCE_GATHER_ALPHA: write_sm4_gather(tpf, &load->node, &load->resource, &load->sampler, coords, - HLSL_SWIZZLE(W, W, W, W), texel_offset); + VKD3D_SHADER_SWIZZLE(W, W, W, W), texel_offset); break;
case HLSL_RESOURCE_SAMPLE_INFO: @@ -5454,8 +5471,8 @@ static void write_sm4_store(const struct tpf_writer *tpf, const struct hlsl_ir_s
static void write_sm4_swizzle(const struct tpf_writer *tpf, const struct hlsl_ir_swizzle *swizzle) { + unsigned int writemask, hlsl_swizzle; struct sm4_instruction instr; - unsigned int writemask;
memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV; @@ -5464,8 +5481,9 @@ static void write_sm4_swizzle(const struct tpf_writer *tpf, const struct hlsl_ir instr.dst_count = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, &instr.srcs[0].swizzle_type, swizzle->val.node); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_combine_swizzles(hlsl_swizzle_from_writemask(writemask), + hlsl_swizzle = hlsl_map_swizzle(hlsl_combine_swizzles(hlsl_swizzle_from_writemask(writemask), swizzle->swizzle, swizzle->node.data_type->dimx), instr.dsts[0].write_mask); + instr.srcs[0].swizzle = swizzle_from_sm4(hlsl_swizzle); instr.src_count = 1;
write_sm4_instruction(tpf, &instr);
This merge request was approved by Giovanni Mascellani.
Approved, though I guess that eventually we'd like to have just one convention on how to store swizzles (i.e., one component per byte or four components packed into a single byte). I suppose there is no fundamental reason why the HLSL compiler must be different from the rest of vkd3d-shader.
On Thu Sep 28 14:19:14 2023 +0000, Giovanni Mascellani wrote:
Approved, though I guess that eventually we'd like to have just one convention on how to store swizzles (i.e., one component per byte or four components packed into a single byte). I suppose there is no fundamental reason why the HLSL compiler must be different from the rest of vkd3d-shader.
Yep, eventually we would like the HLSL compiler to match VSIR in this regard, albeit we may need to use an uint64 to also have enough space matrix swizzles.
This merge request was approved by Henri Verbeet.