summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2013-02-10 00:15:11 -0500
committerAndreas Boll <andreas.boll.dev@gmail.com>2013-04-17 12:36:44 +0200
commit330716ff6b9fb8c168981a474e23eed4a4827f1d (patch)
tree3db77ecb5f7960fbe98aa4a6ac1d5c93fd3820d9
parent80a4d818d9ab766acee6057e64a92ffaf04e866f (diff)
r300g/tests: Add helper functions for creating a full program
Now you can convert assembly strings into a full struct radeon_compiler object and use it to test individual compiler pases. NOTE: This is a candidate for the stable branches. Reviewed-by: Marek Olšák <maraeo@gmail.com> (cherry picked from commit 5e1321ddf4dacb212ed3215f2b9beead630353a1)
-rw-r--r--src/gallium/drivers/r300/compiler/tests/rc_test_helpers.c67
-rw-r--r--src/gallium/drivers/r300/compiler/tests/rc_test_helpers.h16
2 files changed, 75 insertions, 8 deletions
diff --git a/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.c b/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.c
index 3d17a48be4..551fe05ece 100644
--- a/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.c
+++ b/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.c
@@ -1,5 +1,6 @@
/*
* Copyright 2011 Tom Stellard <tstellar@gmail.com>
+ * Copyright 2013 Advanced Micro Devices, Inc.
*
* All Rights Reserved.
*
@@ -23,6 +24,7 @@
* 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 <errno.h>
@@ -32,9 +34,14 @@
#include <string.h>
#include <sys/types.h>
-#include "../radeon_compiler_util.h"
-#include "../radeon_opcodes.h"
-#include "../radeon_program.h"
+#include "r500_fragprog.h"
+#include "r300_fragprog_swizzle.h"
+#include "radeon_compiler.h"
+#include "radeon_compiler_util.h"
+#include "radeon_opcodes.h"
+#include "radeon_program.h"
+#include "radeon_regalloc.h"
+#include "radeon_swizzle.h"
#include "rc_test_helpers.h"
@@ -286,6 +293,7 @@ int init_rc_normal_dst(
if (tokens.WriteMask.Length == 0) {
inst->U.I.DstReg.WriteMask = RC_MASK_XYZW;
} else {
+ inst->U.I.DstReg.WriteMask = 0;
/* The first character should be '.' */
if (tokens.WriteMask.String[0] != '.') {
fprintf(stderr, "1st char of writemask is not valid.\n");
@@ -338,7 +346,8 @@ struct inst_tokens {
* this string is the same that is output by rc_program_print.
* @return 1 On success, 0 on failure
*/
-int init_rc_normal_instruction(
+
+int parse_rc_normal_instruction(
struct rc_instruction * inst,
const char * inst_str)
{
@@ -347,10 +356,6 @@ int init_rc_normal_instruction(
regmatch_t matches[REGEX_INST_MATCHES];
struct inst_tokens tokens;
- /* Initialize inst */
- memset(inst, 0, sizeof(struct rc_instruction));
- inst->Type = RC_INSTRUCTION_NORMAL;
-
/* Execute the regex */
if (!regex_helper(regex_str, inst_str, matches, REGEX_INST_MATCHES)) {
return 0;
@@ -367,6 +372,8 @@ int init_rc_normal_instruction(
/* Fill out the rest of the instruction. */
+ inst->Type = RC_INSTRUCTION_NORMAL;
+
for (i = 0; i < MAX_RC_OPCODE; i++) {
const struct rc_opcode_info * info = rc_get_opcode_info(i);
unsigned int first_src = 3;
@@ -405,3 +412,47 @@ int init_rc_normal_instruction(
}
return 1;
}
+
+int init_rc_normal_instruction(
+ struct rc_instruction * inst,
+ const char * inst_str)
+{
+ /* Initialize inst */
+ memset(inst, 0, sizeof(struct rc_instruction));
+
+ return parse_rc_normal_instruction(inst, inst_str);
+}
+
+void add_instruction(struct radeon_compiler *c, const char * inst_string)
+{
+ struct rc_instruction * new_inst =
+ rc_insert_new_instruction(c, c->Program.Instructions.Prev);
+
+ parse_rc_normal_instruction(new_inst, inst_string);
+
+}
+
+void init_compiler(
+ struct radeon_compiler *c,
+ enum rc_program_type program_type,
+ unsigned is_r500,
+ unsigned is_r400)
+{
+ struct rc_regalloc_state *rs = malloc(sizeof(struct rc_regalloc_state));
+ rc_init(c, rs);
+
+ c->is_r500 = is_r500;
+ c->max_temp_regs = is_r500 ? 128 : (is_r400 ? 64 : 32);
+ c->max_constants = is_r500 ? 256 : 32;
+ c->max_alu_insts = (is_r500 || is_r400) ? 512 : 64;
+ c->max_tex_insts = (is_r500 || is_r400) ? 512 : 32;
+ if (program_type == RC_FRAGMENT_PROGRAM) {
+ c->has_half_swizzles = 1;
+ c->has_presub = 1;
+ c->has_omod = 1;
+ c->SwizzleCaps =
+ is_r500 ? &r500_swizzle_caps : &r300_swizzle_caps;
+ } else {
+ c->SwizzleCaps = &r300_vertprog_swizzle_caps;
+ }
+}
diff --git a/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.h b/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.h
index 63d246eeda..49a46a94ab 100644
--- a/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.h
+++ b/src/gallium/drivers/r300/compiler/tests/rc_test_helpers.h
@@ -1,5 +1,6 @@
/*
* Copyright 2011 Tom Stellard <tstellar@gmail.com>
+ * Copyright 2013 Advanced Micro Devices, Inc.
*
* All Rights Reserved.
*
@@ -23,8 +24,11 @@
* 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_compiler.h"
+
int init_rc_normal_src(
struct rc_instruction * inst,
unsigned int src_index,
@@ -34,6 +38,18 @@ int init_rc_normal_dst(
struct rc_instruction * inst,
const char * dst_str);
+int parse_rc_normal_instruction(
+ struct rc_instruction * inst,
+ const char * inst_str);
+
int init_rc_normal_instruction(
struct rc_instruction * inst,
const char * inst_str);
+
+void add_instruction(struct radeon_compiler *c, const char * inst_string);
+
+void init_compiler(
+ struct radeon_compiler *c,
+ enum rc_program_type program_type,
+ unsigned is_r500,
+ unsigned is_r400);