mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Split deref-offset into a node and a constant uint.
This uint will be used for the following:
- Since SM4's relative addressing (the capability of passing a register
as an index to another register) only has whole-register granularity,
we will need to make the offset node express the offset in
whole-registers and specify the register component in this uint,
otherwise we would have to add additional / and % operations in the
output binary.
- If, after we apply constant folding and copy propagation, we determine
that the offset is a single constant node, we can store all the offset
in this uint constant, and remove the offset src.
This allows DCE to remove a good bunch of the nodes previously required
only for the offset constants, which makes the output more liteweight
and readable, and simplifies the implementation of relative addressing
when writing tpf in the following patches.
In dump_deref(), we use "c" to indicate components instead of whole
registers. Since now both the offset node and the offset uint are in
components a lowered deref would look like:
var[@42c + 2c]
But, once we express the offset node in whole registers we will remove
the "c" from the node part:
var[@22 + 3c]
This commit is contained in:
committed by
Alexandre Julliard
parent
81be47c00b
commit
61a17643a2
Notes:
Alexandre Julliard
2023-10-31 22:38:12 +01:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/396
@@ -513,6 +513,7 @@ static bool init_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hl
|
||||
deref->var = var;
|
||||
deref->path_len = path_len;
|
||||
deref->offset.node = NULL;
|
||||
deref->const_offset = 0;
|
||||
deref->data_type = NULL;
|
||||
|
||||
if (path_len == 0)
|
||||
@@ -541,6 +542,7 @@ bool hlsl_init_deref_from_index_chain(struct hlsl_ctx *ctx, struct hlsl_deref *d
|
||||
deref->path = NULL;
|
||||
deref->path_len = 0;
|
||||
deref->offset.node = NULL;
|
||||
deref->const_offset = 0;
|
||||
|
||||
assert(chain);
|
||||
if (chain->type == HLSL_IR_INDEX)
|
||||
@@ -1137,6 +1139,7 @@ void hlsl_cleanup_deref(struct hlsl_deref *deref)
|
||||
deref->path_len = 0;
|
||||
|
||||
hlsl_src_remove(&deref->offset);
|
||||
deref->const_offset = 0;
|
||||
}
|
||||
|
||||
/* Initializes a simple variable dereference, so that it can be passed to load/store functions. */
|
||||
@@ -2411,21 +2414,37 @@ static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_der
|
||||
if (deref->var)
|
||||
{
|
||||
vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
|
||||
if (deref->path_len)
|
||||
if (!hlsl_deref_is_lowered(deref))
|
||||
{
|
||||
vkd3d_string_buffer_printf(buffer, "[");
|
||||
for (i = 0; i < deref->path_len; ++i)
|
||||
if (deref->path_len)
|
||||
{
|
||||
vkd3d_string_buffer_printf(buffer, "[");
|
||||
dump_src(buffer, &deref->path[i]);
|
||||
for (i = 0; i < deref->path_len; ++i)
|
||||
{
|
||||
vkd3d_string_buffer_printf(buffer, "[");
|
||||
dump_src(buffer, &deref->path[i]);
|
||||
vkd3d_string_buffer_printf(buffer, "]");
|
||||
}
|
||||
vkd3d_string_buffer_printf(buffer, "]");
|
||||
}
|
||||
vkd3d_string_buffer_printf(buffer, "]");
|
||||
}
|
||||
else if (deref->offset.node)
|
||||
else
|
||||
{
|
||||
bool show_rel, show_const;
|
||||
|
||||
show_rel = deref->offset.node;
|
||||
show_const = deref->const_offset != 0 || !show_rel;
|
||||
|
||||
vkd3d_string_buffer_printf(buffer, "[");
|
||||
dump_src(buffer, &deref->offset);
|
||||
if (show_rel)
|
||||
{
|
||||
dump_src(buffer, &deref->offset);
|
||||
vkd3d_string_buffer_printf(buffer, "c");
|
||||
}
|
||||
if (show_rel && show_const)
|
||||
vkd3d_string_buffer_printf(buffer, " + ");
|
||||
if (show_const)
|
||||
vkd3d_string_buffer_printf(buffer, "%uc", deref->const_offset);
|
||||
vkd3d_string_buffer_printf(buffer, "]");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user