From: Giovanni Mascellani gmascellani@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2 (Matteo): Simplify hlsl_offset_from_deref() a bit, use (offset % 4) instead of (offset & 3) for consistency.
libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl_codegen.c | 30 ++++++++++++++++-------------- libs/vkd3d-shader/hlsl_sm4.c | 6 ++++-- 3 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c69dc4a0..27afeedd 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -687,6 +687,7 @@ unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second); unsigned int hlsl_map_swizzle(unsigned int swizzle, unsigned int writemask); unsigned int hlsl_swizzle_from_writemask(unsigned int writemask);
+unsigned int hlsl_offset_from_deref(const struct hlsl_deref *deref); struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct hlsl_type *type);
bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic, diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 8bd9d138..9efc3dad 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1187,30 +1187,32 @@ static bool type_is_single_reg(const struct hlsl_type *type) return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR; }
-struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct hlsl_type *type) +unsigned int hlsl_offset_from_deref(const struct hlsl_deref *deref) { struct hlsl_ir_node *offset_node = deref->offset.node; - const struct hlsl_ir_var *var = deref->var; - struct hlsl_reg ret = {0}; - unsigned int offset = 0; + + if (!offset_node) + return 0;
/* We should always have generated a cast to UINT. */ - if (offset_node) - assert(offset_node->data_type->type == HLSL_CLASS_SCALAR - && offset_node->data_type->base_type == HLSL_TYPE_UINT); + assert(offset_node->data_type->type == HLSL_CLASS_SCALAR + && offset_node->data_type->base_type == HLSL_TYPE_UINT);
- if (offset_node && offset_node->type != HLSL_IR_CONSTANT) + if (offset_node->type != HLSL_IR_CONSTANT) { FIXME("Dereference with non-constant offset of type %s.\n", hlsl_node_type_to_string(offset_node->type)); offset_node = NULL; }
- ret = var->reg; + return hlsl_ir_constant(offset_node)->value[0].u; +} + +struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct hlsl_type *type) +{ + const struct hlsl_ir_var *var = deref->var; + struct hlsl_reg ret = var->reg; + unsigned int offset = hlsl_offset_from_deref(deref);
- ret.allocated = var->reg.allocated; - ret.id = var->reg.id; - if (offset_node) - offset = hlsl_ir_constant(offset_node)->value[0].u; ret.id += offset / 4;
if (type_is_single_reg(var->data_type)) @@ -1221,7 +1223,7 @@ struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct else { assert(type_is_single_reg(type)); - ret.writemask = ((1 << type->dimx) - 1) << (offset & 3); + ret.writemask = ((1 << type->dimx) - 1) << (offset % 4); } return ret; } diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 5558a1ff..500c9f43 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -612,12 +612,14 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
if (var->is_uniform) { + unsigned int offset = hlsl_offset_from_deref(deref) + var->buffer_offset; + reg->type = VKD3D_SM4_RT_CONSTBUFFER; reg->dim = VKD3D_SM4_DIMENSION_VEC4; reg->idx[0] = var->buffer->reg.id; - reg->idx[1] = var->buffer_offset / 4; + reg->idx[1] = offset / 4; reg->idx_count = 2; - *writemask = ((1u << data_type->dimx) - 1) << (var->buffer_offset & 3); + *writemask = ((1u << data_type->dimx) - 1) << (offset & 3); } else if (var->is_input_semantic) {