vkd3d-shader/hlsl: Respect the deref offset for uniforms in sm4_register_from_deref().

Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Giovanni Mascellani 2021-09-23 15:42:50 +02:00 committed by Alexandre Julliard
parent 6f85aad54b
commit 62b25bc52b
3 changed files with 21 additions and 16 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -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)
{