diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-01-08 05:41:34 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-01-08 05:41:34 +0000 |
commit | c00801de923e125863aaf8180439d59d610b2517 (patch) | |
tree | e2896aa2785f3cf2151aeeb3c95fb5cc09a2fe02 /lib/mesa/src/compiler/glsl/tests | |
parent | be30e6efb92db21299b936c0e068e7088941e9c9 (diff) |
Revert to Mesa 13.0.6 again.
Corruption has again been reported on Intel hardware running Xorg with
the modesetting driver (which uses OpenGL based acceleration instead of
SNA acceleration the intel driver defaults to).
Reported in various forms on Sandy Bridge (X220), Ivy Bridge (X230) and
Haswell (X240). Confirmed to not occur with the intel driver but the
xserver was changed to default to the modesetting driver on >= gen4
hardware (except Ironlake).
One means of triggering this is to open a large pdf with xpdf on an
idle machine and highlight a section of the document.
There have been reports of gpu hangs on gen4 intel hardware
(T500 with GM45, X61 with 965GM) when starting Xorg as well.
Diffstat (limited to 'lib/mesa/src/compiler/glsl/tests')
20 files changed, 222 insertions, 1088 deletions
diff --git a/lib/mesa/src/compiler/glsl/tests/.deps/lower_int64_test.Po b/lib/mesa/src/compiler/glsl/tests/.deps/lower_int64_test.Po deleted file mode 100644 index 9ce06a81e..000000000 --- a/lib/mesa/src/compiler/glsl/tests/.deps/lower_int64_test.Po +++ /dev/null @@ -1 +0,0 @@ -# dummy diff --git a/lib/mesa/src/compiler/glsl/tests/.deps/opt_add_neg_to_sub_test.Po b/lib/mesa/src/compiler/glsl/tests/.deps/opt_add_neg_to_sub_test.Po deleted file mode 100644 index 9ce06a81e..000000000 --- a/lib/mesa/src/compiler/glsl/tests/.deps/opt_add_neg_to_sub_test.Po +++ /dev/null @@ -1 +0,0 @@ -# dummy diff --git a/lib/mesa/src/compiler/glsl/tests/blob_test.c b/lib/mesa/src/compiler/glsl/tests/blob_test.c index df0e91af3..4806029bc 100644 --- a/lib/mesa/src/compiler/glsl/tests/blob_test.c +++ b/lib/mesa/src/compiler/glsl/tests/blob_test.c @@ -23,7 +23,6 @@ /* A collection of unit tests for blob.c */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> @@ -50,10 +49,7 @@ static void expect_equal(uint64_t expected, uint64_t actual, const char *test) { if (actual != expected) { - fprintf(stderr, - "Error: Test '%s' failed: " - "Expected=%" PRIu64 ", " - "Actual=%" PRIu64 "\n", + fprintf (stderr, "Error: Test '%s' failed: Expected=%ld, Actual=%ld\n", test, expected, actual); error = true; } @@ -63,9 +59,7 @@ static void expect_unequal(uint64_t expected, uint64_t actual, const char *test) { if (actual == expected) { - fprintf(stderr, - "Error: Test '%s' failed: Result=%" PRIu64 ", " - "but expected something different.\n", + fprintf (stderr, "Error: Test '%s' failed: Result=%ld, but expected something different.\n", test, actual); error = true; } @@ -118,13 +112,14 @@ expect_equal_bytes(uint8_t *expected, uint8_t *actual, static void test_write_and_read_functions (void) { + void *ctx = ralloc_context(NULL); struct blob *blob; struct blob_reader reader; uint8_t *reserved; size_t str_offset, uint_offset; uint8_t reserve_buf[sizeof(reserve_test_str)]; - blob = blob_create(); + blob = blob_create(ctx); /*** Test blob by writing one of every possible kind of value. */ @@ -184,19 +179,20 @@ test_write_and_read_functions (void) "read_consumes_all_bytes"); expect_equal(false, reader.overrun, "read_does_not_overrun"); - blob_destroy(blob); + ralloc_free(ctx); } /* Test that data values are written and read with proper alignment. */ static void test_alignment(void) { + void *ctx = ralloc_context(NULL); struct blob *blob; struct blob_reader reader; uint8_t bytes[] = "ABCDEFGHIJKLMNOP"; size_t delta, last, num_bytes; - blob = blob_create(); + blob = blob_create(ctx); /* First, write an intptr value to the blob and capture that size. This is * the expected offset between any pair of intptr values (if written with @@ -242,18 +238,19 @@ test_alignment(void) "aligned read of intptr_t"); } - blob_destroy(blob); + ralloc_free(ctx); } /* Test that we detect overrun. */ static void test_overrun(void) { + void *ctx =ralloc_context(NULL); struct blob *blob; struct blob_reader reader; uint32_t value = 0xdeadbeef; - blob = blob_create(); + blob = blob_create(ctx); blob_write_uint32(blob, value); @@ -264,7 +261,7 @@ test_overrun(void) expect_equal(0, blob_read_uint32(&reader), "read at overrun"); expect_equal(true, reader.overrun, "overrun flag set"); - blob_destroy(blob); + ralloc_free(ctx); } /* Test that we can read and write some large objects, (exercising the code in @@ -281,7 +278,7 @@ test_big_objects(void) size_t i; char *buf; - blob = blob_create(); + blob = blob_create(ctx); /* Initialize our buffer. */ buf = ralloc_size(ctx, size); @@ -308,7 +305,6 @@ test_big_objects(void) expect_equal(false, reader.overrun, "overrun flag not set reading large objects"); - blob_destroy(blob); ralloc_free(ctx); } diff --git a/lib/mesa/src/compiler/glsl/tests/cache_test.c b/lib/mesa/src/compiler/glsl/tests/cache_test.c index af1b66fb3..724dfcd77 100644 --- a/lib/mesa/src/compiler/glsl/tests/cache_test.c +++ b/lib/mesa/src/compiler/glsl/tests/cache_test.c @@ -30,34 +30,39 @@ #include <ftw.h> #include <errno.h> #include <stdarg.h> -#include <inttypes.h> -#include <limits.h> -#include <time.h> -#include <unistd.h> #include "util/mesa-sha1.h" -#include "util/disk_cache.h" +#include "cache.h" bool error = false; #ifdef ENABLE_SHADER_CACHE +void +_mesa_warning(void *ctx, const char *fmt, ...); -static void -expect_true(bool result, const char *test) +void +_mesa_warning(void *ctx, const char *fmt, ...) { - if (!result) { - fprintf(stderr, "Error: Test '%s' failed: Expected=true" - ", Actual=false\n", test); - error = true; - } + va_list vargs; + (void) ctx; + + va_start(vargs, fmt); + + /* This output is not thread-safe, but that's good enough for the + * standalone compiler. + */ + fprintf(stderr, "Mesa warning: "); + vfprintf(stderr, fmt, vargs); + fprintf(stderr, "\n"); + + va_end(vargs); } static void expect_equal(uint64_t actual, uint64_t expected, const char *test) { if (actual != expected) { - fprintf(stderr, "Error: Test '%s' failed: Expected=%" PRIu64 - ", Actual=%" PRIu64 "\n", + fprintf(stderr, "Error: Test '%s' failed: Expected=%ld, Actual=%ld\n", test, expected, actual); error = true; } @@ -124,95 +129,71 @@ rmrf_local(const char *path) if (path == NULL || *path == '\0' || *path != '.') return -1; - return nftw(path, remove_entry, 64, FTW_DEPTH | FTW_PHYS); -} - -static void -check_directories_created(const char *cache_dir) -{ - bool sub_dirs_created = false; - - char buf[PATH_MAX]; - if (getcwd(buf, PATH_MAX)) { - char *full_path = NULL; - if (asprintf(&full_path, "%s%s", buf, ++cache_dir) != -1 ) { - struct stat sb; - if (stat(full_path, &sb) != -1 && S_ISDIR(sb.st_mode)) - sub_dirs_created = true; - - free(full_path); - } - } - - expect_true(sub_dirs_created, "create sub dirs"); + return nftw(path, remove_entry, 64, FTW_DEPTH | FTW_PHYS | FTW_MOUNT); } #define CACHE_TEST_TMP "./cache-test-tmp" static void -test_disk_cache_create(void) +test_cache_create(void) { - struct disk_cache *cache; + struct program_cache *cache; int err; /* Before doing anything else, ensure that with - * MESA_GLSL_CACHE_DISABLE set, that disk_cache_create returns NULL. + * MESA_GLSL_CACHE_DISABLE set, that cache_create returns NULL. */ setenv("MESA_GLSL_CACHE_DISABLE", "1", 1); - cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set"); + cache = cache_create(); + expect_null(cache, "cache_create with MESA_GLSL_CACHE_DISABLE set"); unsetenv("MESA_GLSL_CACHE_DISABLE"); - /* For the first real disk_cache_create() clear these environment + /* For the first real cache_create() clear these environment * variables to test creation of cache in home directory. */ unsetenv("MESA_GLSL_CACHE_DIR"); unsetenv("XDG_CACHE_HOME"); - cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with no environment variables"); + cache = cache_create(); + expect_non_null(cache, "cache_create with no environment variables"); - disk_cache_destroy(cache); + cache_destroy(cache); /* Test with XDG_CACHE_HOME set */ setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1); - cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with" + cache = cache_create(); + expect_null(cache, "cache_create with XDG_CACHE_HOME set with" "a non-existing parent directory"); mkdir(CACHE_TEST_TMP, 0755); - cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set"); - - check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/mesa"); + cache = cache_create(); + expect_non_null(cache, "cache_create with XDG_CACHE_HOME set"); - disk_cache_destroy(cache); + cache_destroy(cache); /* Test with MESA_GLSL_CACHE_DIR set */ err = rmrf_local(CACHE_TEST_TMP); expect_equal(err, 0, "Removing " CACHE_TEST_TMP); setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1); - cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with" + cache = cache_create(); + expect_null(cache, "cache_create with MESA_GLSL_CACHE_DIR set with" "a non-existing parent directory"); mkdir(CACHE_TEST_TMP, 0755); - cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set"); + cache = cache_create(); + expect_non_null(cache, "cache_create with MESA_GLSL_CACHE_DIR set"); - check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/mesa"); - - disk_cache_destroy(cache); + cache_destroy(cache); } static bool -does_cache_contain(struct disk_cache *cache, const cache_key key) +does_cache_contain(struct program_cache *cache, cache_key key) { void *result; - result = disk_cache_get(cache, key, NULL); + result = cache_get(cache, key, NULL); if (result) { free(result); @@ -223,31 +204,15 @@ does_cache_contain(struct disk_cache *cache, const cache_key key) } static void -wait_until_file_written(struct disk_cache *cache, const cache_key key) -{ - struct timespec req; - struct timespec rem; - - /* Set 100ms delay */ - req.tv_sec = 0; - req.tv_nsec = 100000000; - - unsigned retries = 0; - while (retries++ < 20) { - if (does_cache_contain(cache, key)) { - break; - } - - nanosleep(&req, &rem); - } -} - -static void test_put_and_get(void) { - struct disk_cache *cache; + struct program_cache *cache; + /* If the text of this blob is changed, then blob_key_byte_zero + * also needs to be updated. + */ char blob[] = "This is a blob of thirty-seven bytes"; uint8_t blob_key[20]; + uint8_t blob_key_byte_zero = 0xca; char string[] = "While this string has thirty-four"; uint8_t string_key[20]; char *result; @@ -256,49 +221,39 @@ test_put_and_get(void) uint8_t one_KB_key[20], one_MB_key[20]; int count; - cache = disk_cache_create("test", "make_check", 0); + cache = cache_create(); - disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); + _mesa_sha1_compute(blob, sizeof(blob), blob_key); - /* Ensure that disk_cache_get returns nothing before anything is added. */ - result = disk_cache_get(cache, blob_key, &size); - expect_null(result, "disk_cache_get with non-existent item (pointer)"); - expect_equal(size, 0, "disk_cache_get with non-existent item (size)"); + /* Ensure that cache_get returns nothing before anything is added. */ + result = cache_get(cache, blob_key, &size); + expect_null(result, "cache_get with non-existent item (pointer)"); + expect_equal(size, 0, "cache_get with non-existent item (size)"); /* Simple test of put and get. */ - disk_cache_put(cache, blob_key, blob, sizeof(blob)); + cache_put(cache, blob_key, blob, sizeof(blob)); - /* disk_cache_put() hands things off to a thread give it some time to - * finish. - */ - wait_until_file_written(cache, blob_key); - - result = disk_cache_get(cache, blob_key, &size); - expect_equal_str(blob, result, "disk_cache_get of existing item (pointer)"); - expect_equal(size, sizeof(blob), "disk_cache_get of existing item (size)"); + result = cache_get(cache, blob_key, &size); + expect_equal_str(blob, result, "cache_get of existing item (pointer)"); + expect_equal(size, sizeof(blob), "cache_get of existing item (size)"); free(result); /* Test put and get of a second item. */ - disk_cache_compute_key(cache, string, sizeof(string), string_key); - disk_cache_put(cache, string_key, string, sizeof(string)); - - /* disk_cache_put() hands things off to a thread give it some time to - * finish. - */ - wait_until_file_written(cache, string_key); + _mesa_sha1_compute(string, sizeof(string), string_key); + cache_put(cache, string_key, string, sizeof(string)); - result = disk_cache_get(cache, string_key, &size); - expect_equal_str(result, string, "2nd disk_cache_get of existing item (pointer)"); - expect_equal(size, sizeof(string), "2nd disk_cache_get of existing item (size)"); + result = cache_get(cache, string_key, &size); + expect_equal_str(result, string, "2nd cache_get of existing item (pointer)"); + expect_equal(size, sizeof(string), "2nd cache_get of existing item (size)"); free(result); /* Set the cache size to 1KB and add a 1KB item to force an eviction. */ - disk_cache_destroy(cache); + cache_destroy(cache); setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1); - cache = disk_cache_create("test", "make_check", 0); + cache = cache_create(); one_KB = calloc(1, 1024); @@ -308,7 +263,7 @@ test_put_and_get(void) * (with only three files in the cache), the probability is good * that each of the three files will end up in their own * directory. Then, if the directory containing the .tmp file for - * the new item being added for disk_cache_put() is the chosen victim + * the new item being added for cache_put() is the chosen victim * directory for eviction, then no suitable file will be found and * nothing will be evicted. * @@ -319,28 +274,22 @@ test_put_and_get(void) * For this test, we force this signature to land in the same * directory as the original blob first written to the cache. */ - disk_cache_compute_key(cache, one_KB, 1024, one_KB_key); - one_KB_key[0] = blob_key[0]; + _mesa_sha1_compute(one_KB, 1024, one_KB_key); + one_KB_key[0] = blob_key_byte_zero; - disk_cache_put(cache, one_KB_key, one_KB, 1024); + cache_put(cache, one_KB_key, one_KB, 1024); free(one_KB); - /* disk_cache_put() hands things off to a thread give it some time to - * finish. - */ - wait_until_file_written(cache, one_KB_key); - - result = disk_cache_get(cache, one_KB_key, &size); - expect_non_null(result, "3rd disk_cache_get of existing item (pointer)"); - expect_equal(size, 1024, "3rd disk_cache_get of existing item (size)"); + result = cache_get(cache, one_KB_key, &size); + expect_non_null(result, "3rd cache_get of existing item (pointer)"); + expect_equal(size, 1024, "3rd cache_get of existing item (size)"); free(result); - /* Ensure eviction happened by checking that both of the previous - * cache itesm were evicted. + /* Ensure eviction happened by checking that only one of the two + * previously-added items can still be fetched. */ - bool contains_1KB_file = false; count = 0; if (does_cache_contain(cache, blob_key)) count++; @@ -348,31 +297,18 @@ test_put_and_get(void) if (does_cache_contain(cache, string_key)) count++; - if (does_cache_contain(cache, one_KB_key)) { - count++; - contains_1KB_file = true; - } - - expect_true(contains_1KB_file, - "disk_cache_put eviction last file == MAX_SIZE (1KB)"); - expect_equal(count, 1, "disk_cache_put eviction with MAX_SIZE=1K"); + expect_equal(count, 1, "cache_put eviction with MAX_SIZE=1K"); /* Now increase the size to 1M, add back both items, and ensure all - * three that have been added are available via disk_cache_get. + * three that have been added are available via cache_get. */ - disk_cache_destroy(cache); + cache_destroy(cache); setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1); - cache = disk_cache_create("test", "make_check", 0); + cache = cache_create(); - disk_cache_put(cache, blob_key, blob, sizeof(blob)); - disk_cache_put(cache, string_key, string, sizeof(string)); - - /* disk_cache_put() hands things off to a thread give it some time to - * finish. - */ - wait_until_file_written(cache, blob_key); - wait_until_file_written(cache, string_key); + cache_put(cache, blob_key, blob, sizeof(blob)); + cache_put(cache, string_key, string, sizeof(string)); count = 0; if (does_cache_contain(cache, blob_key)) @@ -389,19 +325,13 @@ test_put_and_get(void) /* Finally, check eviction again after adding an object of size 1M. */ one_MB = calloc(1024, 1024); - disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key); - one_MB_key[0] = blob_key[0]; + _mesa_sha1_compute(one_MB, 1024 * 1024, one_MB_key); + one_MB_key[0] = blob_key_byte_zero;; - disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024); + cache_put(cache, one_MB_key, one_MB, 1024 * 1024); free(one_MB); - /* disk_cache_put() hands things off to a thread give it some time to - * finish. - */ - wait_until_file_written(cache, one_MB_key); - - bool contains_1MB_file = false; count = 0; if (does_cache_contain(cache, blob_key)) count++; @@ -412,22 +342,15 @@ test_put_and_get(void) if (does_cache_contain(cache, one_KB_key)) count++; - if (does_cache_contain(cache, one_MB_key)) { - count++; - contains_1MB_file = true; - } - - expect_true(contains_1MB_file, - "disk_cache_put eviction last file == MAX_SIZE (1MB)"); - expect_equal(count, 1, "eviction after overflow with MAX_SIZE=1M"); + expect_equal(count, 2, "eviction after overflow with MAX_SIZE=1M"); - disk_cache_destroy(cache); + cache_destroy(cache); } static void test_put_key_and_get_key(void) { - struct disk_cache *cache; + struct program_cache *cache; bool result; uint8_t key_a[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, @@ -438,42 +361,42 @@ test_put_key_and_get_key(void) { 0, 1, 42, 43, 44, 45, 46, 47, 48, 49, 50, 55, 52, 53, 54, 55, 56, 57, 58, 59}; - cache = disk_cache_create("test", "make_check", 0); + cache = cache_create(); - /* First test that disk_cache_has_key returns false before disk_cache_put_key */ - result = disk_cache_has_key(cache, key_a); - expect_equal(result, 0, "disk_cache_has_key before key added"); + /* First test that cache_has_key returns false before cache_put_key */ + result = cache_has_key(cache, key_a); + expect_equal(result, 0, "cache_has_key before key added"); - /* Then a couple of tests of disk_cache_put_key followed by disk_cache_has_key */ - disk_cache_put_key(cache, key_a); - result = disk_cache_has_key(cache, key_a); - expect_equal(result, 1, "disk_cache_has_key after key added"); + /* Then a couple of tests of cache_put_key followed by cache_has_key */ + cache_put_key(cache, key_a); + result = cache_has_key(cache, key_a); + expect_equal(result, 1, "cache_has_key after key added"); - disk_cache_put_key(cache, key_b); - result = disk_cache_has_key(cache, key_b); - expect_equal(result, 1, "2nd disk_cache_has_key after key added"); + cache_put_key(cache, key_b); + result = cache_has_key(cache, key_b); + expect_equal(result, 1, "2nd cache_has_key after key added"); /* Test that a key with the same two bytes as an existing key * forces an eviction. */ - disk_cache_put_key(cache, key_a_collide); - result = disk_cache_has_key(cache, key_a_collide); + cache_put_key(cache, key_a_collide); + result = cache_has_key(cache, key_a_collide); expect_equal(result, 1, "put_key of a colliding key lands in the cache"); - result = disk_cache_has_key(cache, key_a); + result = cache_has_key(cache, key_a); expect_equal(result, 0, "put_key of a colliding key evicts from the cache"); /* And finally test that we can re-add the original key to re-evict * the colliding key. */ - disk_cache_put_key(cache, key_a); - result = disk_cache_has_key(cache, key_a); + cache_put_key(cache, key_a); + result = cache_has_key(cache, key_a); expect_equal(result, 1, "put_key of original key lands again"); - result = disk_cache_has_key(cache, key_a_collide); + result = cache_has_key(cache, key_a_collide); expect_equal(result, 0, "put_key of orginal key evicts the colliding key"); - disk_cache_destroy(cache); + cache_destroy(cache); } #endif /* ENABLE_SHADER_CACHE */ @@ -483,7 +406,7 @@ main(void) #ifdef ENABLE_SHADER_CACHE int err; - test_disk_cache_create(); + test_cache_create(); test_put_and_get(); diff --git a/lib/mesa/src/compiler/glsl/tests/compare_ir.py b/lib/mesa/src/compiler/glsl/tests/compare_ir index ed993396e..a40fc810c 100644..100755 --- a/lib/mesa/src/compiler/glsl/tests/compare_ir.py +++ b/lib/mesa/src/compiler/glsl/tests/compare_ir @@ -1,3 +1,4 @@ +#!/usr/bin/env python # coding=utf-8 # # Copyright © 2011 Intel Corporation @@ -33,7 +34,7 @@ import tempfile from sexps import * if len(sys.argv) != 3: - print 'Usage: python2 ./compare_ir.py <file1> <file2>' + print 'Usage: compare_ir <file1> <file2>' exit(1) with open(sys.argv[1]) as f: diff --git a/lib/mesa/src/compiler/glsl/tests/general_ir_test.cpp b/lib/mesa/src/compiler/glsl/tests/general_ir_test.cpp index 57917f337..217305bf8 100644 --- a/lib/mesa/src/compiler/glsl/tests/general_ir_test.cpp +++ b/lib/mesa/src/compiler/glsl/tests/general_ir_test.cpp @@ -38,7 +38,6 @@ TEST(ir_variable_constructor, interface) glsl_type::get_interface_instance(f, ARRAY_SIZE(f), GLSL_INTERFACE_PACKING_STD140, - false, "simple_interface"); static const char name[] = "named_instance"; @@ -64,7 +63,6 @@ TEST(ir_variable_constructor, interface_array) glsl_type::get_interface_instance(f, ARRAY_SIZE(f), GLSL_INTERFACE_PACKING_STD140, - false, "simple_interface"); const glsl_type *const interface_array = diff --git a/lib/mesa/src/compiler/glsl/tests/lower_int64_test.cpp b/lib/mesa/src/compiler/glsl/tests/lower_int64_test.cpp deleted file mode 100644 index 4ddc43358..000000000 --- a/lib/mesa/src/compiler/glsl/tests/lower_int64_test.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * - * 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 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS 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. - */ -#include <gtest/gtest.h> -#include "main/compiler.h" -#include "main/mtypes.h" -#include "main/macros.h" -#include "ir.h" -#include "ir_builder.h" - -using namespace ir_builder; - -namespace lower_64bit { -void expand_source(ir_factory &body, - ir_rvalue *val, - ir_variable **expanded_src); - -ir_dereference_variable *compact_destination(ir_factory &body, - const glsl_type *type, - ir_variable *result[4]); - -ir_rvalue *lower_op_to_function_call(ir_instruction *base_ir, - ir_expression *ir, - ir_function_signature *callee); -}; - -class expand_source : public ::testing::Test { -public: - virtual void SetUp(); - virtual void TearDown(); - - exec_list instructions; - ir_factory *body; - ir_variable *expanded_src[4]; - void *mem_ctx; -}; - -void -expand_source::SetUp() -{ - mem_ctx = ralloc_context(NULL); - - memset(expanded_src, 0, sizeof(expanded_src)); - instructions.make_empty(); - body = new ir_factory(&instructions, mem_ctx); -} - -void -expand_source::TearDown() -{ - delete body; - body = NULL; - - ralloc_free(mem_ctx); - mem_ctx = NULL; -} - -static ir_dereference_variable * -create_variable(void *mem_ctx, const glsl_type *type) -{ - ir_variable *var = new(mem_ctx) ir_variable(type, - "variable", - ir_var_temporary); - - return new(mem_ctx) ir_dereference_variable(var); -} - -static ir_expression * -create_expression(void *mem_ctx, const glsl_type *type) -{ - return new(mem_ctx) ir_expression(ir_unop_neg, - create_variable(mem_ctx, type)); -} - -static void -check_expanded_source(const glsl_type *type, - ir_variable *expanded_src[4]) -{ - const glsl_type *const expanded_type = - type->base_type == GLSL_TYPE_UINT64 - ? glsl_type::uvec2_type :glsl_type::ivec2_type; - - for (int i = 0; i < type->vector_elements; i++) { - EXPECT_EQ(expanded_type, expanded_src[i]->type); - - /* All elements that are part of the vector must be unique. */ - for (int j = i - 1; j >= 0; j--) { - EXPECT_NE(expanded_src[i], expanded_src[j]) - << " Element " << i << " is the same as element " << j; - } - } - - /* All elements that are not part of the vector must be the same as element - * 0. This is primarily for scalars (where every element is the same). - */ - for (int i = type->vector_elements; i < 4; i++) { - EXPECT_EQ(expanded_src[0], expanded_src[i]) - << " Element " << i << " should be the same as element 0"; - } -} - -static void -check_instructions(exec_list *instructions, - const glsl_type *type, - const ir_instruction *source) -{ - const glsl_type *const expanded_type = - type->base_type == GLSL_TYPE_UINT64 - ? glsl_type::uvec2_type : glsl_type::ivec2_type; - - const ir_expression_operation unpack_opcode = - type->base_type == GLSL_TYPE_UINT64 - ? ir_unop_unpack_uint_2x32 : ir_unop_unpack_int_2x32; - - ir_instruction *ir; - - /* The instruction list should contain IR to represent: - * - * type tmp1; - * tmp1 = source; - * uvec2 tmp2; - * tmp2 = unpackUint2x32(tmp1.x); - * uvec2 tmp3; - * tmp3 = unpackUint2x32(tmp1.y); - * uvec2 tmp4; - * tmp4 = unpackUint2x32(tmp1.z); - * uvec2 tmp5; - * tmp5 = unpackUint2x32(tmp1.w); - */ - ASSERT_FALSE(instructions->is_empty()); - ir = (ir_instruction *) instructions->pop_head(); - ir_variable *const tmp1 = ir->as_variable(); - EXPECT_EQ(ir_type_variable, ir->ir_type); - EXPECT_EQ(type, tmp1->type) << - " Got " << - tmp1->type->name << - ", expected " << - type->name; - - ASSERT_FALSE(instructions->is_empty()); - ir = (ir_instruction *) instructions->pop_head(); - ir_assignment *const assign1 = ir->as_assignment(); - EXPECT_EQ(ir_type_assignment, ir->ir_type); - ASSERT_NE((void *)0, assign1); - EXPECT_EQ(tmp1, assign1->lhs->variable_referenced()); - EXPECT_EQ(source, assign1->rhs); - - for (unsigned i = 0; i < type->vector_elements; i++) { - ASSERT_FALSE(instructions->is_empty()); - ir = (ir_instruction *) instructions->pop_head(); - ir_variable *const tmp2 = ir->as_variable(); - EXPECT_EQ(ir_type_variable, ir->ir_type); - EXPECT_EQ(expanded_type, tmp2->type); - - ASSERT_FALSE(instructions->is_empty()); - ir = (ir_instruction *) instructions->pop_head(); - ir_assignment *const assign2 = ir->as_assignment(); - EXPECT_EQ(ir_type_assignment, ir->ir_type); - ASSERT_NE((void *)0, assign2); - EXPECT_EQ(tmp2, assign2->lhs->variable_referenced()); - ir_expression *unpack = assign2->rhs->as_expression(); - ASSERT_NE((void *)0, unpack); - EXPECT_EQ(unpack_opcode, unpack->operation); - EXPECT_EQ(tmp1, unpack->operands[0]->variable_referenced()); - } - - EXPECT_TRUE(instructions->is_empty()); -} - -TEST_F(expand_source, uint64_variable) -{ - const glsl_type *const type = glsl_type::uint64_t_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, u64vec2_variable) -{ - const glsl_type *const type = glsl_type::u64vec2_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, u64vec3_variable) -{ - const glsl_type *const type = glsl_type::u64vec3_type; - - /* Generate an operand that is a scalar variable dereference. */ - ir_variable *const var = new(mem_ctx) ir_variable(type, - "variable", - ir_var_temporary); - - ir_dereference_variable *const deref = - new(mem_ctx) ir_dereference_variable(var); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, u64vec4_variable) -{ - const glsl_type *const type = glsl_type::u64vec4_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, int64_variable) -{ - const glsl_type *const type = glsl_type::int64_t_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, i64vec2_variable) -{ - const glsl_type *const type = glsl_type::i64vec2_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, i64vec3_variable) -{ - const glsl_type *const type = glsl_type::i64vec3_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, i64vec4_variable) -{ - const glsl_type *const type = glsl_type::i64vec4_type; - ir_dereference_variable *const deref = create_variable(mem_ctx, type); - - lower_64bit::expand_source(*body, deref, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, deref); -} - -TEST_F(expand_source, uint64_expression) -{ - const glsl_type *const type = glsl_type::uint64_t_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, u64vec2_expression) -{ - const glsl_type *const type = glsl_type::u64vec2_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, u64vec3_expression) -{ - const glsl_type *const type = glsl_type::u64vec3_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, u64vec4_expression) -{ - const glsl_type *const type = glsl_type::u64vec4_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, int64_expression) -{ - const glsl_type *const type = glsl_type::int64_t_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, i64vec2_expression) -{ - const glsl_type *const type = glsl_type::i64vec2_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, i64vec3_expression) -{ - const glsl_type *const type = glsl_type::i64vec3_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -TEST_F(expand_source, i64vec4_expression) -{ - const glsl_type *const type = glsl_type::i64vec4_type; - ir_expression *const expr = create_expression(mem_ctx, type); - - lower_64bit::expand_source(*body, expr, expanded_src); - - check_expanded_source(type, expanded_src); - check_instructions(&instructions, type, expr); -} - -class compact_destination : public ::testing::Test { -public: - virtual void SetUp(); - virtual void TearDown(); - - exec_list instructions; - ir_factory *body; - ir_variable *expanded_src[4]; - void *mem_ctx; -}; - -void -compact_destination::SetUp() -{ - mem_ctx = ralloc_context(NULL); - - memset(expanded_src, 0, sizeof(expanded_src)); - instructions.make_empty(); - body = new ir_factory(&instructions, mem_ctx); -} - -void -compact_destination::TearDown() -{ - delete body; - body = NULL; - - ralloc_free(mem_ctx); - mem_ctx = NULL; -} - -TEST_F(compact_destination, uint64) -{ - const glsl_type *const type = glsl_type::uint64_t_type; - - for (unsigned i = 0; i < type->vector_elements; i++) { - expanded_src[i] = new(mem_ctx) ir_variable(glsl_type::uvec2_type, - "result", - ir_var_temporary); - } - - ir_dereference_variable *deref = - lower_64bit::compact_destination(*body, - type, - expanded_src); - - ASSERT_EQ(ir_type_dereference_variable, deref->ir_type); - EXPECT_EQ(type, deref->var->type) << - " Got " << - deref->var->type->name << - ", expected " << - type->name; - - ir_instruction *ir; - - ASSERT_FALSE(instructions.is_empty()); - ir = (ir_instruction *) instructions.pop_head(); - ir_variable *const var = ir->as_variable(); - ASSERT_NE((void *)0, var); - EXPECT_EQ(deref->var, var); - - for (unsigned i = 0; i < type->vector_elements; i++) { - ASSERT_FALSE(instructions.is_empty()); - ir = (ir_instruction *) instructions.pop_head(); - ir_assignment *const assign = ir->as_assignment(); - ASSERT_NE((void *)0, assign); - EXPECT_EQ(deref->var, assign->lhs->variable_referenced()); - } -} diff --git a/lib/mesa/src/compiler/glsl/tests/lower_jumps/create_test_cases.py b/lib/mesa/src/compiler/glsl/tests/lower_jumps/create_test_cases.py index 623487eb4..3be1079bc 100644 --- a/lib/mesa/src/compiler/glsl/tests/lower_jumps/create_test_cases.py +++ b/lib/mesa/src/compiler/glsl/tests/lower_jumps/create_test_cases.py @@ -21,7 +21,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -import argparse import os import os.path import re @@ -31,8 +30,6 @@ import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) # For access to sexps.py, which is in parent dir from sexps import * -runner = ":" -outdir = "." def make_test_case(f_name, ret_type, body): """Create a simple optimization test case consisting of a single function with the given name, return type, and body. @@ -239,13 +236,6 @@ def if_execute_flag(statements): check_sexp(statements) return [['if', ['var_ref', 'execute_flag'], statements, []]] -def if_return_flag(then_statements, else_statements): - """Wrap statements in an if test with return_flag as the condition. - """ - check_sexp(then_statements) - check_sexp(else_statements) - return [['if', ['var_ref', 'return_flag'], then_statements, else_statements]] - def if_not_return_flag(statements): """Wrap statements in an if test so that they will only execute if return_flag is False. @@ -298,15 +288,15 @@ def create_test_case(doc_string, input_sexp, expected_sexp, test_name, 'do_lower_jumps({0:d}, {1:d}, {2:d}, {3:d}, {4:d})'.format( pull_out_jumps, lower_sub_return, lower_main_return, lower_continue, lower_break)) - args = [runner, 'optpass', '--quiet', '--input-ir', optimization] - test_file = os.path.join(outdir, '{0}.opt_test'.format(test_name)) + args = ['../../glsl_test', 'optpass', '--quiet', '--input-ir', optimization] + test_file = '{0}.opt_test'.format(test_name) with open(test_file, 'w') as f: f.write('#!/usr/bin/env bash\n#\n# This file was generated by create_test_cases.py.\n#\n') f.write(doc_string) f.write('{0} <<EOF\n'.format(bash_quote(*args))) f.write('{0}\nEOF\n'.format(input_str)) os.chmod(test_file, 0774) - expected_file = os.path.join(outdir, '{0}.opt_test.expected'.format(test_name)) + expected_file = '{0}.opt_test.expected'.format(test_name) with open(expected_file, 'w') as f: f.write('{0}\n'.format(expected_output)) @@ -462,10 +452,7 @@ def test_lower_pulled_out_jump(): loop(simple_if('b', simple_if('c', [], continue_()), lowered_return_simple()) + break_()) + - - if_return_flag(assign_x('return_flag', const_bool(1)) + - assign_x('execute_flag', const_bool(0)), - assign_x('d', const_float(1)))) + if_not_return_flag(assign_x('d', const_float(1)))) )) create_test_case(doc_string, input_sexp, expected_sexp, 'lower_pulled_out_jump', lower_main_return=True, pull_out_jumps=True) @@ -596,14 +583,11 @@ def test_lower_return_void_at_end_of_loop(): assign_x('b', const_float(2)) )) expected_sexp = make_test_case('main', 'void', ( - declare_execute_flag() + declare_return_flag() + loop(assign_x('a', const_float(1)) + lowered_return_simple() + break_()) + - if_return_flag(assign_x('return_flag', const_bool(1)) + - assign_x('execute_flag', const_bool(0)), - assign_x('b', const_float(2))) + if_not_return_flag(assign_x('b', const_float(2))) )) create_test_case(doc_string, input_sexp, input_sexp, 'return_void_at_end_of_loop_lower_nothing') create_test_case(doc_string, input_sexp, expected_sexp, 'return_void_at_end_of_loop_lower_return', @@ -628,10 +612,7 @@ def test_lower_return_non_void_at_end_of_loop(): loop(assign_x('a', const_float(1)) + lowered_return_simple(const_float(2)) + break_()) + - if_return_flag(assign_x('return_value', '(var_ref return_value)') + - assign_x('return_flag', const_bool(1)) + - assign_x('execute_flag', const_bool(0)), - assign_x('b', const_float(3)) + + if_not_return_flag(assign_x('b', const_float(3)) + lowered_return(const_float(4))) + final_return() )) @@ -642,17 +623,6 @@ def test_lower_return_non_void_at_end_of_loop(): lower_sub_return=True, lower_break=True) if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--runner', - help='The glsl_test runner', - required=True) - parser.add_argument('--outdir', - help='Directory to put the generated files in', - required=True) - args = parser.parse_args() - runner = args.runner - outdir = args.outdir - test_lower_returns_main() test_lower_returns_sub() test_lower_returns_1() diff --git a/lib/mesa/src/compiler/glsl/tests/opt_add_neg_to_sub_test.cpp b/lib/mesa/src/compiler/glsl/tests/opt_add_neg_to_sub_test.cpp deleted file mode 100644 index b82e47ffb..000000000 --- a/lib/mesa/src/compiler/glsl/tests/opt_add_neg_to_sub_test.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright © 2016 Intel Corporation - * - * 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 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS 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. - */ -#include <gtest/gtest.h> -#include "ir.h" -#include "ir_builder.h" -#include "opt_add_neg_to_sub.h" - -using namespace ir_builder; - -class add_neg_to_sub : public ::testing::Test { -public: - virtual void SetUp(); - virtual void TearDown(); - - exec_list instructions; - ir_factory *body; - void *mem_ctx; - ir_variable *var_a; - ir_variable *var_b; - ir_variable *var_c; - add_neg_to_sub_visitor v; -}; - -void -add_neg_to_sub::SetUp() -{ - mem_ctx = ralloc_context(NULL); - - instructions.make_empty(); - body = new ir_factory(&instructions, mem_ctx); - - var_a = new(mem_ctx) ir_variable(glsl_type::float_type, - "a", - ir_var_temporary); - - var_b = new(mem_ctx) ir_variable(glsl_type::float_type, - "b", - ir_var_temporary); - - var_c = new(mem_ctx) ir_variable(glsl_type::float_type, - "c", - ir_var_temporary); -} - -void -add_neg_to_sub::TearDown() -{ - delete body; - body = NULL; - - ralloc_free(mem_ctx); - mem_ctx = NULL; -} - -TEST_F(add_neg_to_sub, a_plus_b) -{ - body->emit(assign(var_c, add(var_a, var_b))); - - visit_list_elements(&v, &instructions); - - ASSERT_FALSE(instructions.is_empty()); - - ir_instruction *const ir = (ir_instruction *) instructions.pop_head(); - - EXPECT_TRUE(instructions.is_empty()); - - /* The resulting instruction should be 'c = a + b'. */ - ir_assignment *const assign = ir->as_assignment(); - ASSERT_NE((void *)0, assign); - - EXPECT_EQ(var_c, assign->lhs->variable_referenced()); - - ir_expression *const expr = assign->rhs->as_expression(); - ASSERT_NE((void *)0, expr); - EXPECT_EQ(ir_binop_add, expr->operation); - - ir_dereference_variable *const deref_a = - expr->operands[0]->as_dereference_variable(); - ir_dereference_variable *const deref_b = - expr->operands[1]->as_dereference_variable(); - - ASSERT_NE((void *)0, deref_a); - EXPECT_EQ(var_a, deref_a->var); - ASSERT_NE((void *)0, deref_b); - EXPECT_EQ(var_b, deref_b->var); -} - -TEST_F(add_neg_to_sub, a_plus_neg_b) -{ - body->emit(assign(var_c, add(var_a, neg(var_b)))); - - visit_list_elements(&v, &instructions); - - ASSERT_FALSE(instructions.is_empty()); - - ir_instruction *const ir = (ir_instruction *) instructions.pop_head(); - - EXPECT_TRUE(instructions.is_empty()); - - /* The resulting instruction should be 'c = a - b'. */ - ir_assignment *const assign = ir->as_assignment(); - ASSERT_NE((void *)0, assign); - - EXPECT_EQ(var_c, assign->lhs->variable_referenced()); - - ir_expression *const expr = assign->rhs->as_expression(); - ASSERT_NE((void *)0, expr); - EXPECT_EQ(ir_binop_sub, expr->operation); - - ir_dereference_variable *const deref_a = - expr->operands[0]->as_dereference_variable(); - ir_dereference_variable *const deref_b = - expr->operands[1]->as_dereference_variable(); - - ASSERT_NE((void *)0, deref_a); - EXPECT_EQ(var_a, deref_a->var); - ASSERT_NE((void *)0, deref_b); - EXPECT_EQ(var_b, deref_b->var); -} - -TEST_F(add_neg_to_sub, neg_a_plus_b) -{ - body->emit(assign(var_c, add(neg(var_a), var_b))); - - visit_list_elements(&v, &instructions); - - ASSERT_FALSE(instructions.is_empty()); - - ir_instruction *const ir = (ir_instruction *) instructions.pop_head(); - - EXPECT_TRUE(instructions.is_empty()); - - /* The resulting instruction should be 'c = b - a'. */ - ir_assignment *const assign = ir->as_assignment(); - ASSERT_NE((void *)0, assign); - - EXPECT_EQ(var_c, assign->lhs->variable_referenced()); - - ir_expression *const expr = assign->rhs->as_expression(); - ASSERT_NE((void *)0, expr); - EXPECT_EQ(ir_binop_sub, expr->operation); - - ir_dereference_variable *const deref_b = - expr->operands[0]->as_dereference_variable(); - ir_dereference_variable *const deref_a = - expr->operands[1]->as_dereference_variable(); - - ASSERT_NE((void *)0, deref_a); - EXPECT_EQ(var_a, deref_a->var); - ASSERT_NE((void *)0, deref_b); - EXPECT_EQ(var_b, deref_b->var); -} - -TEST_F(add_neg_to_sub, neg_a_plus_neg_b) -{ - body->emit(assign(var_c, add(neg(var_a), neg(var_b)))); - - visit_list_elements(&v, &instructions); - - ASSERT_FALSE(instructions.is_empty()); - - ir_instruction *const ir = (ir_instruction *) instructions.pop_head(); - - EXPECT_TRUE(instructions.is_empty()); - - /* The resulting instruction should be 'c = -b - a'. */ - ir_assignment *const assign = ir->as_assignment(); - ASSERT_NE((void *)0, assign); - - EXPECT_EQ(var_c, assign->lhs->variable_referenced()); - - ir_expression *const expr = assign->rhs->as_expression(); - ASSERT_NE((void *)0, expr); - EXPECT_EQ(ir_binop_sub, expr->operation); - - ir_expression *const neg_b = expr->operands[0]->as_expression(); - ir_dereference_variable *const deref_a = - expr->operands[1]->as_dereference_variable(); - - ASSERT_NE((void *)0, deref_a); - EXPECT_EQ(var_a, deref_a->var); - - ASSERT_NE((void *)0, neg_b); - - ir_dereference_variable *const deref_b = - neg_b->operands[0]->as_dereference_variable(); - - ASSERT_NE((void *)0, deref_b); - EXPECT_EQ(var_b, deref_b->var); -} diff --git a/lib/mesa/src/compiler/glsl/tests/optimization-test b/lib/mesa/src/compiler/glsl/tests/optimization-test new file mode 100755 index 000000000..26a51be69 --- /dev/null +++ b/lib/mesa/src/compiler/glsl/tests/optimization-test @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +if [ ! -z "$srcdir" ]; then + compare_ir=`pwd`/tests/compare_ir +else + compare_ir=./compare_ir +fi + +total=0 +pass=0 + +echo "====== Generating tests ======" +for dir in tests/*/; do + if [ -e "${dir}create_test_cases.py" ]; then + cd $dir; $PYTHON2 create_test_cases.py; cd .. + fi + echo "$dir" +done + +echo "====== Testing optimization passes ======" +for test in `find . -iname '*.opt_test'`; do + echo -n "Testing $test..." + (cd `dirname "$test"`; ./`basename "$test"`) > "$test.out" 2>&1 + total=$((total+1)) + if $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" >/dev/null 2>&1; then + echo "PASS" + pass=$((pass+1)) + else + echo "FAIL" + $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" + fi +done + +echo "" +echo "$pass/$total tests returned correct results" +echo "" + +if [[ $pass == $total ]]; then + exit 0 +else + exit 1 +fi diff --git a/lib/mesa/src/compiler/glsl/tests/optimization-test.sh b/lib/mesa/src/compiler/glsl/tests/optimization-test.sh deleted file mode 100755 index e54edc7fb..000000000 --- a/lib/mesa/src/compiler/glsl/tests/optimization-test.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -if [ -z "$PYTHON2" ]; then - PYTHON2=python2 -fi - -which $PYTHON2 >/dev/null -if [ $? -ne 0 ]; then - echo "Could not find python2. Make sure that PYTHON2 variable is correctly set." - exit 1 -fi - -if [ -z "$srcdir" -o -z "$abs_builddir" ]; then - echo "" - echo "Warning: you're invoking the script manually and things may fail." - echo "Attempting to determine/set srcdir and abs_builddir variables." - echo "" - - # Variable should point to the Makefile.glsl.am - srcdir=./../../ - cd `dirname "$0"` - # Variable should point to the folder two levels above glsl_test - abs_builddir=`pwd`/../../ -fi - -compare_ir=$srcdir/glsl/tests/compare_ir.py - -total=0 -pass=0 -has_tests=0 - -# Store our location before we start diving into subdirectories. -ORIGDIR=`pwd` -echo "====== Generating tests ======" -for dir in $srcdir/glsl/tests/*/; do - if [ -e "${dir}create_test_cases.py" ]; then - echo "$dir" - # construct the correct builddir - completedir="$abs_builddir/glsl/tests/`echo ${dir} | sed 's|.*/glsl/tests/||g'`" - mkdir -p $completedir - cd $dir; - $PYTHON2 create_test_cases.py --runner $abs_builddir/glsl/glsl_test --outdir $completedir; - if [ $? -eq 0 ]; then - has_tests=1 - fi - cd .. - fi -done -cd "$ORIGDIR" - -if [ $has_tests -eq 0 ]; then - echo "Could not generate any tests." - exit 1 -fi - -if [ ! -f "$compare_ir" ]; then - echo "Could not find compare_ir. Make sure that srcdir variable is correctly set." - exit 1 -fi - -echo "====== Testing optimization passes ======" -for test in `find . -iname '*.opt_test'`; do - echo -n "Testing `echo $test| sed 's|.*/glsl/tests/||g'`..." - ./$test > "$test.out" 2>&1 - total=$((total+1)) - if $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" >/dev/null 2>&1; then - echo "PASS" - pass=$((pass+1)) - else - echo "FAIL" - $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" - fi -done - -if [ $total -eq 0 ]; then - echo "Could not find any tests." - exit 1 -fi - -echo "" -echo "$pass/$total tests returned correct results" -echo "" - -if [ $pass = $total ]; then - exit 0 -else - exit 1 -fi diff --git a/lib/mesa/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp b/lib/mesa/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp index 94a6d270e..245494c73 100644 --- a/lib/mesa/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp +++ b/lib/mesa/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp @@ -25,7 +25,7 @@ #include "main/mtypes.h" #include "main/macros.h" #include "util/ralloc.h" -#include "string_to_uint_map.h" +#include "util/string_to_uint_map.h" #include "uniform_initializer_utils.h" namespace linker { @@ -70,7 +70,6 @@ set_uniform_initializer::SetUp() { this->mem_ctx = ralloc_context(NULL); this->prog = rzalloc(NULL, struct gl_shader_program); - this->prog->data = rzalloc(this->prog, struct gl_shader_program_data); /* Set default values used by the test cases. */ @@ -111,43 +110,43 @@ establish_uniform_storage(struct gl_shader_program *prog, unsigned num_storage, const unsigned red_zone_components = total_components - data_components; prog->UniformHash = new string_to_uint_map; - prog->data->UniformStorage = rzalloc_array(prog, struct gl_uniform_storage, - num_storage); - prog->data->NumUniformStorage = num_storage; + prog->UniformStorage = rzalloc_array(prog, struct gl_uniform_storage, + num_storage); + prog->NumUniformStorage = num_storage; - prog->data->UniformStorage[index_to_set].name = (char *) name; - prog->data->UniformStorage[index_to_set].type = type; - prog->data->UniformStorage[index_to_set].array_elements = array_size; + prog->UniformStorage[index_to_set].name = (char *) name; + prog->UniformStorage[index_to_set].type = type; + prog->UniformStorage[index_to_set].array_elements = array_size; for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { - prog->data->UniformStorage[index_to_set].opaque[sh].index = ~0; - prog->data->UniformStorage[index_to_set].opaque[sh].active = false; + prog->UniformStorage[index_to_set].opaque[sh].index = ~0; + prog->UniformStorage[index_to_set].opaque[sh].active = false; } - prog->data->UniformStorage[index_to_set].num_driver_storage = 0; - prog->data->UniformStorage[index_to_set].driver_storage = NULL; - prog->data->UniformStorage[index_to_set].storage = + prog->UniformStorage[index_to_set].num_driver_storage = 0; + prog->UniformStorage[index_to_set].driver_storage = NULL; + prog->UniformStorage[index_to_set].storage = rzalloc_array(prog, union gl_constant_value, total_components); - fill_storage_array_with_sentinels(prog->data->UniformStorage[index_to_set].storage, + fill_storage_array_with_sentinels(prog->UniformStorage[index_to_set].storage, data_components, red_zone_components); prog->UniformHash->put(index_to_set, - prog->data->UniformStorage[index_to_set].name); + prog->UniformStorage[index_to_set].name); for (unsigned i = 0; i < num_storage; i++) { if (i == index_to_set) continue; - prog->data->UniformStorage[i].name = (char *) "invalid slot"; - prog->data->UniformStorage[i].type = glsl_type::void_type; - prog->data->UniformStorage[i].array_elements = 0; + prog->UniformStorage[i].name = (char *) "invalid slot"; + prog->UniformStorage[i].type = glsl_type::void_type; + prog->UniformStorage[i].array_elements = 0; for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { - prog->data->UniformStorage[i].opaque[sh].index = ~0; - prog->data->UniformStorage[i].opaque[sh].active = false; + prog->UniformStorage[i].opaque[sh].index = ~0; + prog->UniformStorage[i].opaque[sh].active = false; } - prog->data->UniformStorage[i].num_driver_storage = 0; - prog->data->UniformStorage[i].driver_storage = NULL; - prog->data->UniformStorage[i].storage = NULL; + prog->UniformStorage[i].num_driver_storage = 0; + prog->UniformStorage[i].driver_storage = NULL; + prog->UniformStorage[i].storage = NULL; } return red_zone_components; @@ -170,7 +169,7 @@ non_array_test(void *mem_ctx, struct gl_shader_program *prog, linker::set_uniform_initializer(mem_ctx, prog, name, type, val, 0xF00F); - verify_data(prog->data->UniformStorage[actual_index].storage, 0, val, + verify_data(prog->UniformStorage[actual_index].storage, 0, val, red_zone_components, 0xF00F); } @@ -326,7 +325,7 @@ array_test(void *mem_ctx, struct gl_shader_program *prog, linker::set_uniform_initializer(mem_ctx, prog, name, element_type, val, 0xF00F); - verify_data(prog->data->UniformStorage[actual_index].storage, array_size, + verify_data(prog->UniformStorage[actual_index].storage, array_size, val, red_zone_components, 0xF00F); } diff --git a/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.cpp b/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.cpp index 9a66ebafb..ec64be18c 100644 --- a/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.cpp +++ b/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.cpp @@ -96,12 +96,6 @@ generate_data_element(void *mem_ctx, const glsl_type *type, case GLSL_TYPE_DOUBLE: data.d[i] = double(values[idx]); break; - case GLSL_TYPE_UINT64: - data.u64[i] = (uint64_t) values[idx]; - break; - case GLSL_TYPE_INT64: - data.i64[i] = (int64_t) values[idx]; - break; case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_STRUCT: case GLSL_TYPE_ARRAY: @@ -136,12 +130,6 @@ generate_data_element(void *mem_ctx, const glsl_type *type, case GLSL_TYPE_DOUBLE: ASSERT_EQ(data.d[i], val->value.d[i]); break; - case GLSL_TYPE_UINT64: - ASSERT_EQ(data.u64[i], val->value.u64[i]); - break; - case GLSL_TYPE_INT64: - ASSERT_EQ(data.i64[i], val->value.i64[i]); - break; case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_STRUCT: case GLSL_TYPE_ARRAY: @@ -214,7 +202,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size, ir_constant *val, unsigned red_zone_size, unsigned int boolean_true) { - if (val->type->is_array()) { + if (val->type->base_type == GLSL_TYPE_ARRAY) { const glsl_type *const element_type = val->array_elements[0]->type; for (unsigned i = 0; i < storage_array_size; i++) { @@ -248,12 +236,6 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size, case GLSL_TYPE_DOUBLE: EXPECT_EQ(val->value.d[i], *(double *)&storage[i*2].i); break; - case GLSL_TYPE_UINT64: - EXPECT_EQ(val->value.u64[i], *(uint64_t *)&storage[i*2].i); - break; - case GLSL_TYPE_INT64: - EXPECT_EQ(val->value.i64[i], *(int64_t *)&storage[i*2].i); - break; case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_STRUCT: case GLSL_TYPE_ARRAY: diff --git a/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.h b/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.h index f65254cdc..b4d0c1022 100644 --- a/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.h +++ b/lib/mesa/src/compiler/glsl/tests/uniform_initializer_utils.h @@ -21,8 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#ifndef GLSL_UNIFORM_INITIALIZER_UTILS_H -#define GLSL_UNIFORM_INITIALIZER_UTILS_H +#pragma once #include "program/prog_parameter.h" #include "ir.h" @@ -47,5 +46,3 @@ extern void verify_data(gl_constant_value *storage, unsigned storage_array_size, ir_constant *val, unsigned red_zone_size, unsigned int boolean_true); - -#endif /* GLSL_UNIFORM_INITIALIZER_UTILS_H */ diff --git a/lib/mesa/src/compiler/glsl/tests/varyings_test.cpp b/lib/mesa/src/compiler/glsl/tests/varyings_test.cpp index eb134c9e8..7643e1bbb 100644 --- a/lib/mesa/src/compiler/glsl/tests/varyings_test.cpp +++ b/lib/mesa/src/compiler/glsl/tests/varyings_test.cpp @@ -83,7 +83,6 @@ link_varyings::link_varyings() glsl_type::get_interface_instance(f, ARRAY_SIZE(f), GLSL_INTERFACE_PACKING_STD140, - false, "simple_interface"); } diff --git a/lib/mesa/src/compiler/glsl/tests/warnings-test b/lib/mesa/src/compiler/glsl/tests/warnings-test new file mode 100755 index 000000000..1bea46653 --- /dev/null +++ b/lib/mesa/src/compiler/glsl/tests/warnings-test @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Execute several shaders, and check that the InfoLog outcome is the expected. + +compiler=./glsl_compiler +total=0 +pass=0 + +echo "====== Testing compilation output ======" +for test in `find . -iname '*.vert'`; do + echo -n "Testing $test..." + $compiler --just-log --version 150 "$test" > "$test.out" 2>&1 + total=$((total+1)) + if diff "$test.expected" "$test.out" >/dev/null 2>&1; then + echo "PASS" + pass=$((pass+1)) + else + echo "FAIL" + diff "$test.expected" "$test.out" + fi +done + +echo "" +echo "$pass/$total tests returned correct results" +echo "" + +if [[ $pass == $total ]]; then + exit 0 +else + exit 1 +fi diff --git a/lib/mesa/src/compiler/glsl/tests/warnings-test.sh b/lib/mesa/src/compiler/glsl/tests/warnings-test.sh deleted file mode 100755 index d5dc3b597..000000000 --- a/lib/mesa/src/compiler/glsl/tests/warnings-test.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh - -if [ -z "$srcdir" -o -z "$abs_builddir" ]; then - echo "" - echo "Warning: you're invoking the script manually and things may fail." - echo "Attempting to determine/set srcdir and abs_builddir variables." - echo "" - - # Variable should point to the Makefile.glsl.am - srcdir=./../../ - cd `dirname "$0"` - # Variable should point to glsl_compiler - abs_builddir=`pwd`/../../ -fi - -# Execute several shaders, and check that the InfoLog outcome is the expected. - -compiler=$abs_builddir/glsl_compiler -total=0 -pass=0 - -if [ ! -x "$compiler" ]; then - echo "Could not find glsl_compiler. Ensure that it is build via make check" - exit 1 -fi - -tests_relative_dir="glsl/tests/warnings" - -echo "====== Testing compilation output ======" -for test in $srcdir/$tests_relative_dir/*.vert; do - test_output="$abs_builddir/$tests_relative_dir/`basename $test`" - mkdir -p $abs_builddir/$tests_relative_dir/ - echo -n "Testing `basename $test`..." - $compiler --just-log --version 150 "$test" > "$test_output.out" 2>&1 - total=$((total+1)) - if diff "$test.expected" "$test_output.out" >/dev/null 2>&1; then - echo "PASS" - pass=$((pass+1)) - else - echo "FAIL" - diff "$test.expected" "$test_output.out" - fi -done - -if [ $total -eq 0 ]; then - echo "Could not find any tests." - exit 1 -fi - -echo "" -echo "$pass/$total tests returned correct results" -echo "" - -if [ $pass = $total ]; then - exit 0 -else - exit 1 -fi diff --git a/lib/mesa/src/compiler/glsl/tests/warnings/026-out-function-parameter-shaderout.vert.expected b/lib/mesa/src/compiler/glsl/tests/warnings/026-out-function-parameter-shaderout.vert.expected index 60d3a8af8..e69de29bb 100644 --- a/lib/mesa/src/compiler/glsl/tests/warnings/026-out-function-parameter-shaderout.vert.expected +++ b/lib/mesa/src/compiler/glsl/tests/warnings/026-out-function-parameter-shaderout.vert.expected @@ -1,2 +0,0 @@ - -error: unresolved reference to function `fooFunction' diff --git a/lib/mesa/src/compiler/glsl/tests/warnings/027-inout-function-parameter-shaderout.vert.expected b/lib/mesa/src/compiler/glsl/tests/warnings/027-inout-function-parameter-shaderout.vert.expected index 651818d91..17249752d 100644 --- a/lib/mesa/src/compiler/glsl/tests/warnings/027-inout-function-parameter-shaderout.vert.expected +++ b/lib/mesa/src/compiler/glsl/tests/warnings/027-inout-function-parameter-shaderout.vert.expected @@ -1,3 +1 @@ 0:11(14): warning: `willBeDefined' used uninitialized - -error: unresolved reference to function `fooFunction' diff --git a/lib/mesa/src/compiler/glsl/tests/warnings/030-array-as-function-parameter.vert.expected b/lib/mesa/src/compiler/glsl/tests/warnings/030-array-as-function-parameter.vert.expected index b1355d3a9..21cb2c5a2 100644 --- a/lib/mesa/src/compiler/glsl/tests/warnings/030-array-as-function-parameter.vert.expected +++ b/lib/mesa/src/compiler/glsl/tests/warnings/030-array-as-function-parameter.vert.expected @@ -5,5 +5,3 @@ 0:14(20): warning: `undefinedIndex' used uninitialized 0:14(51): warning: `undefinedIndex' used uninitialized 0:14(82): warning: `undefinedIndex' used uninitialized - -error: unresolved reference to function `foo' |