summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mesa/shader/slang/slang_assemble.c18
-rw-r--r--src/mesa/shader/slang/slang_compile_function.c19
-rw-r--r--src/mesa/shader/slang/slang_compile_function.h8
3 files changed, 32 insertions, 13 deletions
diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c
index 09b1df7cb0e..0cba5d5d007 100644
--- a/src/mesa/shader/slang/slang_assemble.c
+++ b/src/mesa/shader/slang/slang_assemble.c
@@ -289,24 +289,18 @@ _slang_assemble_function(slang_assemble_ctx * A, slang_function * fun)
fun->address = A->file->count;
if (fun->body == NULL) {
- /* jump to the actual function body - we do not know it, so add the instruction
- * to fixup table */
- fun->fixups.table = (GLuint *)
- slang_alloc_realloc(fun->fixups.table,
- fun->fixups.count * sizeof(GLuint),
- (fun->fixups.count + 1) * sizeof(GLuint));
- if (fun->fixups.table == NULL)
- return GL_FALSE;
- fun->fixups.table[fun->fixups.count] = fun->address;
- fun->fixups.count++;
+ /* jump to the actual function body - we do not know it, so add
+ * the instruction to fixup table
+ */
+ if (!slang_fixup_save(&fun->fixups, fun->address))
+ return GL_FALSE;
if (!PUSH(A->file, slang_asm_jump))
return GL_FALSE;
return GL_TRUE;
}
else {
- GLuint i;
-
/* resolve all fixup table entries and delete it */
+ GLuint i;
for (i = 0; i < fun->fixups.count; i++)
A->file->code[fun->fixups.table[i]].param[0] = fun->address;
slang_fixup_table_free(&fun->fixups);
diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c
index b0e2b62d423..e6e0d89ddb6 100644
--- a/src/mesa/shader/slang/slang_compile_function.c
+++ b/src/mesa/shader/slang/slang_compile_function.c
@@ -47,6 +47,25 @@ slang_fixup_table_free(slang_fixup_table * fix)
slang_fixup_table_init(fix);
}
+/**
+ * Add a new fixup address to the table.
+ */
+GLboolean
+slang_fixup_save(slang_fixup_table *fixups, GLuint address)
+{
+ fixups->table = (GLuint *)
+ slang_alloc_realloc(fixups->table,
+ fixups->count * sizeof(GLuint),
+ (fixups->count + 1) * sizeof(GLuint));
+ if (fixups->table == NULL)
+ return GL_FALSE;
+ fixups->table[fixups->count] = address;
+ fixups->count++;
+ return GL_TRUE;
+}
+
+
+
/* slang_function */
int
diff --git a/src/mesa/shader/slang/slang_compile_function.h b/src/mesa/shader/slang/slang_compile_function.h
index 6d3b85399cd..8835544bf38 100644
--- a/src/mesa/shader/slang/slang_compile_function.h
+++ b/src/mesa/shader/slang/slang_compile_function.h
@@ -41,14 +41,20 @@ typedef enum slang_function_kind_
slang_func_operator
} slang_function_kind;
+
+/**
+ * When we need to fill in addresses which we won't know until the future,
+ * we keep track of them with a fix-up table.
+ */
typedef struct slang_fixup_table_
{
- GLuint *table;
+ GLuint *table; /**< array[count] of addresses */
GLuint count;
} slang_fixup_table;
extern void slang_fixup_table_init(slang_fixup_table *);
extern void slang_fixup_table_free(slang_fixup_table *);
+extern GLboolean slang_fixup_save(slang_fixup_table *fixups, GLuint address);
/**