[PATCH vkd3d 5/5] vkd3d-shader/hlsl: Propagate copies for resource load instructions.

Matteo Bruni mbruni at codeweavers.com
Fri Jan 21 15:22:29 CST 2022


From: Zebediah Figura <zfigura at codeweavers.com>

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
 Makefile.am                      |  3 ---
 libs/vkd3d-shader/hlsl_codegen.c | 39 +++++++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a3ec6850..1c14f958 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -306,9 +306,6 @@ XFAIL_TESTS = \
 	tests/hlsl-vector-indexing.shader_test \
 	tests/hlsl-vector-indexing-uniform.shader_test \
 	tests/max.shader_test \
-	tests/sampler.shader_test \
-	tests/texture-load.shader_test \
-	tests/texture-load-typed.shader_test \
 	tests/trigonometry.shader_test
 endif
 
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index e19b204c..98afd0e0 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -399,8 +399,8 @@ static struct hlsl_ir_node *copy_propagation_compute_replacement(const struct co
     return node;
 }
 
-static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_load *load,
-        struct copy_propagation_state *state)
+static bool copy_propagation_transform_load(struct hlsl_ctx *ctx,
+        struct hlsl_ir_load *load, struct copy_propagation_state *state)
 {
     struct hlsl_ir_node *node = &load->node, *new_node;
     struct hlsl_type *type = node->data_type;
@@ -441,6 +441,35 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l
     return true;
 }
 
+static bool copy_propagation_transform_object_load(struct hlsl_ctx *ctx,
+        struct hlsl_deref *deref, struct copy_propagation_state *state)
+{
+    struct hlsl_ir_load *load;
+    struct hlsl_ir_node *node;
+    unsigned int swizzle;
+
+    if (!(node = copy_propagation_compute_replacement(state, deref, 1, &swizzle)))
+        return false;
+
+    /* Only HLSL_IR_LOAD can produce an object. */
+    load = hlsl_ir_load(node);
+    deref->var = load->src.var;
+    hlsl_src_remove(&deref->offset);
+    hlsl_src_from_node(&deref->offset, load->src.offset.node);
+    return true;
+}
+
+static bool copy_propagation_transform_resource_load(struct hlsl_ctx *ctx,
+        struct hlsl_ir_resource_load *load, struct copy_propagation_state *state)
+{
+    bool progress = false;
+
+    progress |= copy_propagation_transform_object_load(ctx, &load->resource, state);
+    if (load->sampler.var)
+        progress |= copy_propagation_transform_object_load(ctx, &load->sampler, state);
+    return progress;
+}
+
 static void copy_propagation_record_store(struct hlsl_ctx *ctx, struct hlsl_ir_store *store,
         struct copy_propagation_state *state)
 {
@@ -477,7 +506,11 @@ static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_b
         switch (instr->type)
         {
             case HLSL_IR_LOAD:
-                progress |= copy_propagation_analyze_load(ctx, hlsl_ir_load(instr), state);
+                progress |= copy_propagation_transform_load(ctx, hlsl_ir_load(instr), state);
+                break;
+
+            case HLSL_IR_RESOURCE_LOAD:
+                progress |= copy_propagation_transform_resource_load(ctx, hlsl_ir_resource_load(instr), state);
                 break;
 
             case HLSL_IR_STORE:
-- 
2.34.1




More information about the wine-devel mailing list