From: Giovanni Mascellani gmascellani@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl_codegen.c | 20 +++++++++++--------- libs/vkd3d-shader/hlsl_sm4.c | 6 ++++-- 3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c69dc4a08..27afeedd4 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 8bd9d1385..1ac15e328 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1187,12 +1187,9 @@ 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;
/* We should always have generated a cast to UINT. */ if (offset_node) @@ -1205,12 +1202,17 @@ struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct offset_node = NULL; }
- ret = var->reg; - - ret.allocated = var->reg.allocated; - ret.id = var->reg.id; if (offset_node) - offset = hlsl_ir_constant(offset_node)->value[0].u; + return hlsl_ir_constant(offset_node)->value[0].u; + return 0; +} + +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.id += offset / 4;
if (type_is_single_reg(var->data_type)) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 5558a1ff2..500c9f434 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) {