diff options
-rw-r--r-- | src/mesa/shader/slang/slang_assemble.c | 20 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_assemble.h | 3 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 219 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_execute.c | 95 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_execute.h | 18 |
5 files changed, 158 insertions, 197 deletions
diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c index a9e2b07a512..6f928d73781 100644 --- a/src/mesa/shader/slang/slang_assemble.c +++ b/src/mesa/shader/slang/slang_assemble.c @@ -1186,23 +1186,3 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i return 1;
}
-
-
-
-
-
-
-
-
-void xxx_first (slang_assembly_file *file)
-{
- slang_assembly_file_push (file, slang_asm_jump);
-}
-
-void xxx_prolog (slang_assembly_file *file, unsigned int addr)
-{
- file->code[0].param[0] = file->count;
- slang_assembly_file_push_label (file, slang_asm_call, addr);
- slang_assembly_file_push (file, slang_asm_exit);
-}
-
diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h index 69e81d6af6e..d93755c7e7b 100644 --- a/src/mesa/shader/slang/slang_assemble.h +++ b/src/mesa/shader/slang/slang_assemble.h @@ -134,9 +134,6 @@ int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
slang_assembly_stack_info *);
-void xxx_first (slang_assembly_file *);
-void xxx_prolog (slang_assembly_file *, unsigned int);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 688eac33c7a..3418f6fae27 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -27,15 +27,15 @@ * slang front-end compiler * \author Michal Krol */ - -#include "imports.h" -#include "grammar_mesa.h" +
+#include "imports.h"
+#include "grammar_mesa.h"
#include "slang_utility.h" #include "slang_compile.h" #include "slang_preprocess.h" -#include "slang_storage.h" -#include "slang_assemble.h" -#include "slang_execute.h" +#include "slang_storage.h"
+#include "slang_assemble.h"
+#include "slang_execute.h"
/* This is a straightforward implementation of the slang front-end compiler. @@ -1832,7 +1832,7 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_function *func, break; default: return 0; - } + }
func->parameters->outer_scope = scope; while (*C->I++ == PARAMETER_NEXT) { @@ -2093,31 +2093,20 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop /* assemble the parsed function */ if (definition) { -static int x = 0; -static slang_assembly_file file; slang_assembly_name_space space; -x++; -if (x == 1) +
slang_assembly_file_construct (&file); space.funcs = funcs; space.structs = structs; space.vars = scope; -if (x == 1) -xxx_first (&file); + (**parsed_func_ret).address = file.count; if (!_slang_assemble_function (&file, *parsed_func_ret, &space)) { slang_assembly_file_destruct (&file); return 0; } -if (slang_string_compare ("main", (**parsed_func_ret).header.name) == 0) -{ -xxx_prolog (&file, (**parsed_func_ret).address); -_slang_execute (&file); -slang_assembly_file_destruct (&file); -_mesa_exit (0); -} } return 1; } @@ -2251,120 +2240,110 @@ static int compile_with_grammar (grammar id, const char *source, slang_translati static const char *slang_shader_syn = #include "library/slang_shader_syn.h" ; -/* -static const byte slang_core_gc_bin[] = { -#include "library/slang_core_gc_bin.h" -};*/ + static const byte slang_core_gc[] = { #include "library/slang_core_gc.h" }; -static const byte slang_common_builtin_gc_bin[] = { -#include "library/slang_common_builtin_gc_bin.h" +static const byte slang_common_builtin_gc[] = { +#include "library/slang_common_builtin_gc.h" }; -static const byte slang_fragment_builtin_gc_bin[] = { -#include "library/slang_fragment_builtin_gc_bin.h" +static const byte slang_fragment_builtin_gc[] = { +#include "library/slang_fragment_builtin_gc.h" }; -static const byte slang_vertex_builtin_gc_bin[] = { -#include "library/slang_vertex_builtin_gc_bin.h" -}; +static const byte slang_vertex_builtin_gc[] = { +#include "library/slang_vertex_builtin_gc.h" +};
+
+int compile (grammar *id, slang_translation_unit builtin_units[3], int compiled[3],
+ const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)
+{
+ slang_translation_unit *builtins = NULL;
+
+ /* load slang grammar */
+ *id = grammar_load_from_text ((const byte *) (slang_shader_syn));
+ if (*id == 0)
+ {
+ byte buf[1024];
+ int pos;
+
+ grammar_get_last_error (buf, 1024, &pos);
+ slang_info_log_error (log, (const char *) (buf));
+ return 0;
+ }
+
+ /* set shader type - the syntax is slightly different for different shaders */
+ if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin)
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 1);
+ else
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 2);
+
+ /* enable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 1);
+
+ /* if parsing user-specified shader, load built-in library */
+ if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
+ {
+ if (!compile_binary (slang_core_gc, &builtin_units[0], slang_unit_fragment_builtin, log,
+ NULL))
+ return 0;
+ compiled[0] = 1;
+
+ if (!compile_binary (slang_common_builtin_gc, &builtin_units[1],
+ slang_unit_fragment_builtin, log, NULL))
+ return 0;
+ compiled[1] = 1;
+
+ if (type == slang_unit_fragment_shader)
+ {
+ if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[2],
+ slang_unit_fragment_builtin, log, NULL))
+ return 0;
+ }
+ else if (type == slang_unit_vertex_shader)
+ {
+ if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[2],
+ slang_unit_vertex_builtin, log, NULL))
+ return 0;
+ }
+ compiled[2] = 1;
+
+ /* disable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);
+ builtins = builtin_units;
+ }
+
+ /* compile the actual shader - pass-in built-in library for external shader */
+ if (!compile_with_grammar (*id, source, unit, type, log, builtins))
+ return 0;
+
+ return 1;
+} int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log) -{ - grammar id; - slang_translation_unit builtin_units[3]; - slang_translation_unit *builtins = NULL; - - /* load slang grammar */ - id = grammar_load_from_text ((const byte *) slang_shader_syn); - if (id == 0) - { - char buf[1024]; - unsigned int pos; - grammar_get_last_error ( (unsigned char*) buf, 1024, (int*) &pos); - slang_info_log_error (log, buf); - return 0; - } - - /* set shader type - the syntax is slightly different for different shaders */ - if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin) - grammar_set_reg8 (id, (const byte *) "shader_type", 1); - else - grammar_set_reg8 (id, (const byte *) "shader_type", 2); - - /* enable language extensions */ - grammar_set_reg8 (id, (const byte *) "parsing_builtin", 1); - - /* if parsing user-specified shader, load built-in library */ - if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader) - { - /*if (!compile_binary (slang_core_gc_bin, builtin_units, - slang_unit_fragment_builtin, log, NULL))*/ - if (!compile_with_grammar (id, (const char*) slang_core_gc, builtin_units, slang_unit_fragment_builtin, - log, NULL)) - { - grammar_destroy (id); - return 0; - } - if (!compile_binary (slang_common_builtin_gc_bin, builtin_units + 1, - slang_unit_fragment_builtin, log, NULL)) - { - slang_translation_unit_destruct (builtin_units); - grammar_destroy (id); - return 0; - } - if (type == slang_unit_fragment_shader) - { - if (!compile_binary (slang_fragment_builtin_gc_bin, builtin_units + 2, - slang_unit_fragment_builtin, log, NULL)) - { - slang_translation_unit_destruct (builtin_units); - slang_translation_unit_destruct (builtin_units + 1); - grammar_destroy (id); - return 0; - } - } - else if (type == slang_unit_vertex_shader) - { - if (!compile_binary (slang_vertex_builtin_gc_bin, builtin_units + 2, - slang_unit_vertex_builtin, log, NULL)) - { - slang_translation_unit_destruct (builtin_units); - slang_translation_unit_destruct (builtin_units + 1); - grammar_destroy (id); - return 0; - } - } - - /* disable language extensions */ - grammar_set_reg8 (id, (const byte *) "parsing_builtin", 0); - builtins = builtin_units; - } +{
+ int success; + grammar id = 0; + slang_translation_unit builtin_units[3];
+ int compiled[3] = { 0 }; - /* compile the actual shader - pass-in built-in library for external shader */ - if (!compile_with_grammar (id, source, unit, type, log, builtins)) - { - if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader) - { - slang_translation_unit_destruct (builtin_units); - slang_translation_unit_destruct (builtin_units + 1); - slang_translation_unit_destruct (builtin_units + 2); - } - grammar_destroy (id); - return 0; - } + success = compile (&id, builtin_units, compiled, source, unit, type, log); /* destroy built-in library */ if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader) - { - slang_translation_unit_destruct (builtin_units); - slang_translation_unit_destruct (builtin_units + 1); - slang_translation_unit_destruct (builtin_units + 2); - } - grammar_destroy (id); - return 1; + {
+ int i;
+
+ for (i = 0; i < 3; i++)
+ if (compiled[i] != 0) + slang_translation_unit_destruct (&builtin_units[i]); + }
+ if (id != 0) + grammar_destroy (id);
+ + return success; } diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index 5b1d6d39409..e4df8325776 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -34,9 +34,10 @@ #include "slang_storage.h"
#include "slang_execute.h"
-#define DEBUG_SLANG
+#define DEBUG_SLANG 1
+
+#if DEBUG_SLANG
-#ifdef DEBUG_SLANG
static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
{
fprintf (f, "%.5u:\t", i);
@@ -182,52 +183,52 @@ static void dump (const slang_assembly_file *file) fclose (f);
}
+
#endif
int _slang_execute (const slang_assembly_file *file)
{
slang_machine mach;
+
#ifdef DEBUG_SLANG
FILE *f;
#endif
+ /* assume 32-bit floats and uints; should work fine also on 64-bit platforms */
+ static_assert(sizeof (GLfloat) == 4);
+ static_assert(sizeof (GLuint) == 4);
+
mach.ip = 0;
mach.sp = SLANG_MACHINE_STACK_SIZE;
mach.bp = 0;
mach.kill = 0;
mach.exit = 0;
+ mach.global = mach.mem;
+ mach.stack = mach.global + SLANG_MACHINE_GLOBAL_SIZE;
- /* assume 32-bit machine */
- /* XXX why???, disabling the pointer size assertions here.
- * See bug 4021.
- */
- static_assert(sizeof (GLfloat) == 4);
- /*static_assert(sizeof (GLfloat *) == 4);*/
- static_assert(sizeof (GLuint) == 4);
- /*static_assert(sizeof (GLuint *) == 4);*/
-
-#ifdef DEBUG_SLANG
+#if DEBUG_SLANG
dump (file);
-#endif
-
-#ifdef DEBUG_SLANG
f = fopen ("~mesa-slang-assembly-execution.txt", "w");
#endif
while (!mach.exit)
{
- slang_assembly *a = file->code + mach.ip;
-#ifdef DEBUG_SLANG
+ slang_assembly *a;
+
+#if DEBUG_SLANG
if (f != NULL)
{
unsigned int i;
- dump_instruction (f, a, mach.ip);
+
+ dump_instruction (f, file->code + mach.ip, mach.ip);
fprintf (f, "\t\tsp=%u bp=%u\n", mach.sp, mach.bp);
for (i = mach.sp; i < SLANG_MACHINE_STACK_SIZE; i++)
- fprintf (f, "\t%.5u\t%6f\t%u\n", i, mach.stack._float[i], mach.stack._addr[i]);
+ fprintf (f, "\t%.5u\t%6f\t%u\n", i, mach.stack[i]._float, mach.stack[i]._addr);
fflush (f);
}
#endif
+
+ a = file->code + mach.ip;
mach.ip++;
switch (a->type)
@@ -237,94 +238,94 @@ int _slang_execute (const slang_assembly_file *file) case slang_asm_float_copy:
case slang_asm_int_copy:
case slang_asm_bool_copy:
- *(mach.stack._floatp[mach.sp + a->param[0] / 4] + a->param[1] / 4) =
- mach.stack._float[mach.sp];
+ mach.mem[mach.stack[mach.sp + a->param[0] / 4]._addr + a->param[1] / 4]._float =
+ mach.stack[mach.sp]._float;
mach.sp++;
break;
case slang_asm_float_move:
case slang_asm_int_move:
case slang_asm_bool_move:
- mach.stack._float[mach.sp + a->param[0] / 4] =
- mach.stack._float[mach.sp + (mach.stack._addr[mach.sp] + a->param[1]) / 4];
+ mach.stack[mach.sp + a->param[0] / 4]._float =
+ mach.stack[mach.sp + (mach.stack[mach.sp]._addr + a->param[1]) / 4]._float;
break;
case slang_asm_float_push:
case slang_asm_int_push:
case slang_asm_bool_push:
mach.sp--;
- mach.stack._float[mach.sp] = a->literal;
+ mach.stack[mach.sp]._float = a->literal;
break;
case slang_asm_float_deref:
case slang_asm_int_deref:
case slang_asm_bool_deref:
- mach.stack._float[mach.sp] = *mach.stack._floatp[mach.sp];
+ mach.stack[mach.sp]._float = mach.mem[mach.stack[mach.sp]._addr]._float;
break;
case slang_asm_float_add:
- mach.stack._float[mach.sp + 1] += mach.stack._float[mach.sp];
+ mach.stack[mach.sp + 1]._float += mach.stack[mach.sp]._float;
mach.sp++;
break;
case slang_asm_float_multiply:
- mach.stack._float[mach.sp + 1] *= mach.stack._float[mach.sp];
+ mach.stack[mach.sp + 1]._float *= mach.stack[mach.sp]._float;
mach.sp++;
break;
case slang_asm_float_divide:
- mach.stack._float[mach.sp + 1] /= mach.stack._float[mach.sp];
+ mach.stack[mach.sp + 1]._float /= mach.stack[mach.sp]._float;
mach.sp++;
break;
case slang_asm_float_negate:
- mach.stack._float[mach.sp] = -mach.stack._float[mach.sp];
+ mach.stack[mach.sp]._float = -mach.stack[mach.sp]._float;
break;
case slang_asm_float_less:
- mach.stack._float[mach.sp + 1] =
- mach.stack._float[mach.sp + 1] < mach.stack._float[mach.sp] ? 1.0f : 0.0f;
+ mach.stack[mach.sp + 1]._float =
+ mach.stack[mach.sp + 1]._float < mach.stack[mach.sp]._float ? 1.0f : 0.0f;
mach.sp++;
break;
case slang_asm_float_equal:
mach.sp--;
- mach.stack._float[mach.sp] = mach.stack._float[mach.sp + 1 + a->param[0] / 4] ==
- mach.stack._float[mach.sp + 1 + a->param[1] / 4] ? 1.0f : 0.0f;
+ mach.stack[mach.sp]._float = mach.stack[mach.sp + 1 + a->param[0] / 4]._float ==
+ mach.stack[mach.sp + 1 + a->param[1] / 4]._float ? 1.0f : 0.0f;
break;
case slang_asm_float_to_int:
- mach.stack._float[mach.sp] = (GLfloat) (GLint) mach.stack._float[mach.sp];
+ mach.stack[mach.sp]._float = (GLfloat) (GLint) mach.stack[mach.sp]._float;
break;
case slang_asm_int_to_float:
break;
case slang_asm_int_to_addr:
- mach.stack._addr[mach.sp] = (GLuint) (GLint) mach.stack._float[mach.sp];
+ mach.stack[mach.sp]._addr = (GLuint) (GLint) mach.stack[mach.sp]._float;
break;
case slang_asm_addr_copy:
- *mach.stack._addrp[mach.sp + 1] = mach.stack._addr[mach.sp];
+ mach.mem[mach.stack[mach.sp + 1]._addr]._addr = mach.stack[mach.sp]._addr;
mach.sp++;
break;
case slang_asm_addr_push:
mach.sp--;
- mach.stack._addr[mach.sp] = a->param[0];
+ mach.stack[mach.sp]._addr = a->param[0];
break;
case slang_asm_addr_deref:
- mach.stack._addr[mach.sp] = *mach.stack._addrp[mach.sp];
+ mach.stack[mach.sp]._addr = mach.mem[mach.stack[mach.sp]._addr]._addr;
break;
case slang_asm_addr_add:
- mach.stack._addr[mach.sp + 1] += mach.stack._addr[mach.sp];
+ mach.stack[mach.sp + 1]._addr += mach.stack[mach.sp]._addr;
mach.sp++;
break;
case slang_asm_addr_multiply:
- mach.stack._addr[mach.sp + 1] *= mach.stack._addr[mach.sp];
+ mach.stack[mach.sp + 1]._addr *= mach.stack[mach.sp]._addr;
mach.sp++;
break;
case slang_asm_jump:
mach.ip = a->param[0];
break;
case slang_asm_jump_if_zero:
- if (mach.stack._float[mach.sp] == 0.0f)
+ if (mach.stack[mach.sp]._float == 0.0f)
mach.ip = a->param[0];
mach.sp++;
break;
case slang_asm_enter:
mach.sp--;
- mach.stack._addr[mach.sp] = mach.bp;
+ mach.stack[mach.sp]._addr = mach.bp;
mach.bp = mach.sp + a->param[0] / 4;
break;
case slang_asm_leave:
- mach.bp = mach.stack._addr[mach.sp];
+ mach.bp = mach.stack[mach.sp]._addr;
mach.sp++;
break;
case slang_asm_local_alloc:
@@ -335,16 +336,16 @@ int _slang_execute (const slang_assembly_file *file) break;
case slang_asm_local_addr:
mach.sp--;
- mach.stack._addr[mach.sp] = (GLuint) mach.stack._addr + mach.bp * 4 -
+ mach.stack[mach.sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach.bp * 4 -
(a->param[0] + a->param[1]) + 4;
break;
case slang_asm_call:
mach.sp--;
- mach.stack._addr[mach.sp] = mach.ip;
+ mach.stack[mach.sp]._addr = mach.ip;
mach.ip = a->param[0];
break;
case slang_asm_return:
- mach.ip = mach.stack._addr[mach.sp];
+ mach.ip = mach.stack[mach.sp]._addr;
mach.sp++;
break;
case slang_asm_discard:
@@ -356,7 +357,7 @@ int _slang_execute (const slang_assembly_file *file) }
}
-#ifdef DEBUG_SLANG
+#if DEBUG_SLANG
if (f != NULL)
fclose (f);
#endif
diff --git a/src/mesa/shader/slang/slang_execute.h b/src/mesa/shader/slang/slang_execute.h index 8ff1eb17c56..f911574b159 100644 --- a/src/mesa/shader/slang/slang_execute.h +++ b/src/mesa/shader/slang/slang_execute.h @@ -29,7 +29,15 @@ extern "C" {
#endif
+typedef union slang_machine_slot_
+{
+ GLfloat _float;
+ GLuint _addr;
+} slang_machine_slot;
+
+#define SLANG_MACHINE_GLOBAL_SIZE 3072
#define SLANG_MACHINE_STACK_SIZE 1024
+#define SLANG_MACHINE_MEMORY_SIZE (SLANG_MACHINE_GLOBAL_SIZE + SLANG_MACHINE_STACK_SIZE)
typedef struct slang_machine_
{
@@ -38,13 +46,9 @@ typedef struct slang_machine_ GLuint bp; /* base pointer, for local variable access */
GLuint kill; /* discard the fragment */
GLuint exit; /* terminate the shader */
- union stack_
- {
- GLfloat _float[SLANG_MACHINE_STACK_SIZE];
- GLfloat *_floatp[SLANG_MACHINE_STACK_SIZE];
- GLuint _addr[SLANG_MACHINE_STACK_SIZE];
- GLuint *_addrp[SLANG_MACHINE_STACK_SIZE];
- } stack;
+ slang_machine_slot mem[SLANG_MACHINE_MEMORY_SIZE];
+ slang_machine_slot *global;
+ slang_machine_slot *stack;
} slang_machine;
int _slang_execute (const slang_assembly_file *);
|