r300g/compiler: Prevent regalloc from swizzling texture operands v2
authorTom Stellard <thomas.stellard@amd.com>
Mon, 20 May 2013 15:05:03 +0000 (08:05 -0700)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 1 Jul 2013 04:38:57 +0000 (21:38 -0700)
https://bugs.freedesktop.org/show_bug.cgi?id=63520

NOTE: This is a candidate for the stable branches.

Reviewed-by: Marek Olšák <maraeo@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/r300/Makefile.am
src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c
src/gallium/drivers/r300/compiler/tests/r300_compiler_tests.c
src/gallium/drivers/r300/compiler/tests/radeon_compiler_regalloc_tests.c [new file with mode: 0644]
src/gallium/drivers/r300/compiler/tests/regalloc_tex_1d_swizzle.test [new file with mode: 0644]

index f82b8e9f9643f8b3b7d5e2f2a5ae144b8574d49d..ab8b4e8297d3c99411bb2dca6ef5adae280e3923 100644 (file)
@@ -24,6 +24,7 @@ r300_compiler_tests_CPPFLAGS = \
 r300_compiler_tests_SOURCES = \
        $(testdir)/r300_compiler_tests.c \
        $(testdir)/radeon_compiler_optimize_tests.c \
+       $(testdir)/radeon_compiler_regalloc_tests.c \
        $(testdir)/radeon_compiler_util_tests.c \
        $(testdir)/rc_test_helpers.c \
        $(testdir)/unit_test.c
index 6442e0dca8049b85036cee76336215d249675aa7..1970a346d1d296e3221791500da7403d0be35a95 100644 (file)
@@ -383,6 +383,14 @@ static enum rc_reg_class variable_get_class(
                                                        RC_INSTRUCTION_PAIR ) {
                                                old_swizzle = r.U.P.Arg->Swizzle;
                                        } else {
+                                               /* Source operands of TEX
+                                                * instructions can't be
+                                                * swizzle on r300/r400 GPUs.
+                                                */
+                                               if (!variable->C->is_r500) {
+                                                       can_change_writemask = 0;
+                                                       break;
+                                               }
                                                old_swizzle = r.U.I.Src->Swizzle;
                                        }
                                        new_swizzle = rc_adjust_channels(
index cc4725ab06d73b7e3d2f49173209d508e19358ff..0406ae6196459f0c3a8f5edd4591adcd97712359 100644 (file)
@@ -33,6 +33,7 @@ int main(int argc, char ** argv)
 {
        unsigned pass = 1;
        pass &= radeon_compiler_optimize_run_tests();
+       pass &= radeon_compiler_regalloc_run_tests();
        pass &= radeon_compiler_util_run_tests();
 
        if (pass) {
diff --git a/src/gallium/drivers/r300/compiler/tests/radeon_compiler_regalloc_tests.c b/src/gallium/drivers/r300/compiler/tests/radeon_compiler_regalloc_tests.c
new file mode 100644 (file)
index 0000000..eeb6b07
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2013 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Tom Stellard <thomas.stellard@amd.com>
+ */
+
+#include "radeon_program_pair.h"
+
+#include "r300_compiler_tests.h"
+#include "rc_test_helpers.h"
+#include "unit_test.h"
+
+static void dummy_allocate_hw_inputs(
+       struct r300_fragment_program_compiler * c,
+       void (*allocate)(void * data, unsigned input, unsigned hwreg),
+       void * mydata)
+{
+       unsigned i;
+       for (i = 0; i < 10; i++) {
+               allocate(mydata, i, i);
+       }
+}
+
+static void test_runner_rc_regalloc(
+       struct test_result *result,
+       struct radeon_compiler *c,
+       const char *filename)
+{
+       struct rc_test_file test_file;
+       unsigned optimizations = 1;
+       unsigned do_full_regalloc = 1;
+       struct rc_instruction *inst;
+       unsigned pass = 1;
+
+       test_begin(result);
+
+       if (!load_program(c, &test_file, filename)) {
+               fprintf(stderr, "Failed to load program\n");
+       }
+
+       rc_pair_translate(c, NULL);
+       rc_pair_schedule(c, &optimizations);
+       rc_pair_remove_dead_sources(c, NULL);
+       rc_pair_regalloc(c, &do_full_regalloc);
+
+       for(inst = c->Program.Instructions.Next;
+                               inst != &c->Program.Instructions;
+                               inst = inst->Next) {
+               if (inst->Type == RC_INSTRUCTION_NORMAL &&
+                               inst->U.I.Opcode != RC_OPCODE_BEGIN_TEX) {
+                       if (GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 0)
+                                                       != RC_SWIZZLE_X) {
+                               pass = 0;
+                       }
+               }
+       }
+
+       test_check(result, pass);
+}
+
+static void tex_1d_swizzle(struct test_result *result)
+{
+       struct radeon_compiler c;
+
+       init_compiler(&c, RC_FRAGMENT_PROGRAM, 0, 0);
+       struct r300_fragment_program_compiler *cc =
+               (struct r300_fragment_program_compiler*)&c;
+       cc->AllocateHwInputs = dummy_allocate_hw_inputs;
+
+       test_runner_rc_regalloc(result, &c, "regalloc_tex_1d_swizzle.test");
+}
+
+unsigned radeon_compiler_regalloc_run_tests()
+{
+       struct test tests[] = {
+               {"rc_pair_regalloc() => TEX 1D Swizzle - r300", tex_1d_swizzle},
+               {NULL, NULL}
+       };
+       return run_tests(tests);
+}
diff --git a/src/gallium/drivers/r300/compiler/tests/regalloc_tex_1d_swizzle.test b/src/gallium/drivers/r300/compiler/tests/regalloc_tex_1d_swizzle.test
new file mode 100644 (file)
index 0000000..8ecfcc1
--- /dev/null
@@ -0,0 +1,15 @@
+const[0] = {     0.0000     2.0000     1.0000     0.0000 }
+  0: TEX temp[8].xyz, input[1].xy__, 2D[0];
+  1: TEX temp[10].xyz, input[2].xyz_, CUBE[2];
+  2: TEX temp[12].xyz, input[1].xy__, 2D[1];
+  3: DP3 temp[14].w, input[2].xyz_, input[2].xyz_;
+  4: MAD temp[15].xyz, temp[12].xyz_, const[0].yyy_, -none.111_;
+  5: MAD temp[16].xyz, temp[10].xyz_, const[0].yyy_, -none.111_;
+  6: MUL temp[17].xyz, temp[8].xyz_, input[0].xyz_;
+  7: MOV output[0].w, none.___0;
+  8: MOV temp[0].x, temp[14].w___;
+  9: TEX temp[18].x, temp[0].x___, 1D[3];
+ 10: DP3 temp[20].w, temp[16].xyz_, temp[15].xyz_;
+ 11: MUL temp[21].xyz, temp[17].xyz_, temp[18].xxx_;
+ 12: MUL output[0].xyz, temp[21].xyz_, temp[20].www_;
+=