From 02eb9acc5e4307db09662592951ef44319a0cda5 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 13 Feb 2006 11:38:37 +0000 Subject: Get it running for ARB_vertex_shader. Add experimental print functions to builtin library. Some functionality missing: - automatic arrays; - general constructors; - local variable initialization; - texture sampling and noise; - semantic error checking; - function prototypes. --- src/mesa/shader/slang/slang_execute.c | 246 +++++++++++++++++++++++----------- 1 file changed, 167 insertions(+), 79 deletions(-) (limited to 'src/mesa/shader/slang/slang_execute.c') diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index e4df832577..a40a35cd57 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.3 + * Version: 6.5 * - * Copyright (C) 2005 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -34,7 +34,24 @@ #include "slang_storage.h" #include "slang_execute.h" -#define DEBUG_SLANG 1 +#define DEBUG_SLANG 0 + +void slang_machine_init (slang_machine *mach) +{ + mach->ip = 0; + mach->sp = SLANG_MACHINE_STACK_SIZE; + mach->bp = 0; + mach->kill = 0; + mach->exit = 0; +} + +int _slang_execute (const slang_assembly_file *file) +{ + slang_machine mach; + + slang_machine_init (&mach); + return _slang_execute2 (file, &mach); +} #if DEBUG_SLANG @@ -44,6 +61,7 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) switch (a->type) { + /* core */ case slang_asm_none: fprintf (f, "none"); break; @@ -74,12 +92,36 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) case slang_asm_float_less: fprintf (f, "float_less"); break; - case slang_asm_float_equal: + case slang_asm_float_equal_exp: + fprintf (f, "float_equal"); + break; + case slang_asm_float_equal_int: fprintf (f, "float_equal\t%d, %d", a->param[0], a->param[1]); break; case slang_asm_float_to_int: fprintf (f, "float_to_int"); break; + case slang_asm_float_sine: + fprintf (f, "float_sine"); + break; + case slang_asm_float_arcsine: + fprintf (f, "float_arcsine"); + break; + case slang_asm_float_arctan: + fprintf (f, "float_arctan"); + break; + case slang_asm_float_power: + fprintf (f, "float_power"); + break; + case slang_asm_float_log2: + fprintf (f, "float_log2"); + break; + case slang_asm_float_floor: + fprintf (f, "float_floor"); + break; + case slang_asm_float_ceil: + fprintf (f, "float_ceil"); + break; case slang_asm_int_copy: fprintf (f, "int_copy\t%d, %d", a->param[0], a->param[1]); break; @@ -158,6 +200,16 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) case slang_asm_exit: fprintf (f, "exit"); break; + /* mesa-specific extensions */ + case slang_asm_float_print: + fprintf (f, "float_print"); + break; + case slang_asm_int_print: + fprintf (f, "int_print"); + break; + case slang_asm_bool_print: + fprintf (f, "bool_print"); + break; default: break; } @@ -186,11 +238,13 @@ static void dump (const slang_assembly_file *file) #endif -int _slang_execute (const slang_assembly_file *file) +int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) { - slang_machine mach; + slang_machine_slot *stack; -#ifdef DEBUG_SLANG +#if DEBUG_SLANG + static unsigned int counter = 0; + char filename[256]; FILE *f; #endif @@ -198,161 +252,195 @@ int _slang_execute (const slang_assembly_file *file) 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; - #if DEBUG_SLANG dump (file); - f = fopen ("~mesa-slang-assembly-execution.txt", "w"); + counter++; + _mesa_sprintf (filename, "~mesa-slang-assembly-exec-(%u).txt", counter); + f = fopen (filename, "w"); #endif - while (!mach.exit) + stack = mach->mem + SLANG_MACHINE_GLOBAL_SIZE; + + while (!mach->exit) { - slang_assembly *a; + slang_assembly *a = &file->code[mach->ip]; #if DEBUG_SLANG - if (f != NULL) + if (f != NULL && a->type != slang_asm_none) { unsigned int i; - 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[i]._float, mach.stack[i]._addr); + 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, stack[i]._float, stack[i]._addr); fflush (f); } #endif - a = file->code + mach.ip; - mach.ip++; + mach->ip++; switch (a->type) { + /* core */ case slang_asm_none: break; case slang_asm_float_copy: case slang_asm_int_copy: case slang_asm_bool_copy: - mach.mem[mach.stack[mach.sp + a->param[0] / 4]._addr + a->param[1] / 4]._float = - mach.stack[mach.sp]._float; - mach.sp++; + mach->mem[(stack[mach->sp + a->param[0] / 4]._addr + a->param[1]) / 4]._float = + stack[mach->sp]._float; + mach->sp++; break; case slang_asm_float_move: case slang_asm_int_move: case slang_asm_bool_move: - mach.stack[mach.sp + a->param[0] / 4]._float = - mach.stack[mach.sp + (mach.stack[mach.sp]._addr + a->param[1]) / 4]._float; + stack[mach->sp + a->param[0] / 4]._float = + stack[mach->sp + (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[mach.sp]._float = a->literal; + mach->sp--; + stack[mach->sp]._float = a->literal; break; case slang_asm_float_deref: case slang_asm_int_deref: case slang_asm_bool_deref: - mach.stack[mach.sp]._float = mach.mem[mach.stack[mach.sp]._addr]._float; + stack[mach->sp]._float = mach->mem[stack[mach->sp]._addr / 4]._float; break; case slang_asm_float_add: - mach.stack[mach.sp + 1]._float += mach.stack[mach.sp]._float; - mach.sp++; + stack[mach->sp + 1]._float += stack[mach->sp]._float; + mach->sp++; break; case slang_asm_float_multiply: - mach.stack[mach.sp + 1]._float *= mach.stack[mach.sp]._float; - mach.sp++; + stack[mach->sp + 1]._float *= stack[mach->sp]._float; + mach->sp++; break; case slang_asm_float_divide: - mach.stack[mach.sp + 1]._float /= mach.stack[mach.sp]._float; - mach.sp++; + stack[mach->sp + 1]._float /= stack[mach->sp]._float; + mach->sp++; break; case slang_asm_float_negate: - mach.stack[mach.sp]._float = -mach.stack[mach.sp]._float; + stack[mach->sp]._float = -stack[mach->sp]._float; break; case slang_asm_float_less: - mach.stack[mach.sp + 1]._float = - mach.stack[mach.sp + 1]._float < mach.stack[mach.sp]._float ? 1.0f : 0.0f; - mach.sp++; + stack[mach->sp + 1]._float = + stack[mach->sp + 1]._float < stack[mach->sp]._float ? (GLfloat) 1 : (GLfloat) 0; + mach->sp++; + break; + case slang_asm_float_equal_exp: + stack[mach->sp + 1]._float = + stack[mach->sp + 1]._float == stack[mach->sp]._float ? (GLfloat) 1 : (GLfloat) 0; + mach->sp++; break; - case slang_asm_float_equal: - mach.sp--; - 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; + case slang_asm_float_equal_int: + mach->sp--; + stack[mach->sp]._float = stack[mach->sp + 1 + a->param[0] / 4]._float == + stack[mach->sp + 1 + a->param[1] / 4]._float ? (GLfloat) 1 : (GLfloat) 0; break; case slang_asm_float_to_int: - mach.stack[mach.sp]._float = (GLfloat) (GLint) mach.stack[mach.sp]._float; + stack[mach->sp]._float = (GLfloat) (GLint) stack[mach->sp]._float; + break; + case slang_asm_float_sine: + stack[mach->sp]._float = (GLfloat) _mesa_sin (stack[mach->sp]._float); + break; + case slang_asm_float_arcsine: + stack[mach->sp]._float = _mesa_asinf (stack[mach->sp]._float); + break; + case slang_asm_float_arctan: + stack[mach->sp]._float = _mesa_atanf (stack[mach->sp]._float); + break; + case slang_asm_float_power: + stack[mach->sp + 1]._float = + (GLfloat) _mesa_pow (stack[mach->sp + 1]._float, stack[mach->sp]._float); + mach->sp++; + break; + case slang_asm_float_log2: + stack[mach->sp]._float = LOG2 (stack[mach->sp]._float); + break; + case slang_asm_float_floor: + stack[mach->sp]._float = FLOORF (stack[mach->sp]._float); + break; + case slang_asm_float_ceil: + stack[mach->sp]._float = CEILF (stack[mach->sp]._float); break; case slang_asm_int_to_float: break; case slang_asm_int_to_addr: - mach.stack[mach.sp]._addr = (GLuint) (GLint) mach.stack[mach.sp]._float; + stack[mach->sp]._addr = (GLuint) (GLint) stack[mach->sp]._float; break; case slang_asm_addr_copy: - mach.mem[mach.stack[mach.sp + 1]._addr]._addr = mach.stack[mach.sp]._addr; - mach.sp++; + mach->mem[stack[mach->sp + 1]._addr / 4]._addr = stack[mach->sp]._addr; + mach->sp++; break; case slang_asm_addr_push: - mach.sp--; - mach.stack[mach.sp]._addr = a->param[0]; + mach->sp--; + stack[mach->sp]._addr = a->param[0]; break; case slang_asm_addr_deref: - mach.stack[mach.sp]._addr = mach.mem[mach.stack[mach.sp]._addr]._addr; + stack[mach->sp]._addr = mach->mem[stack[mach->sp]._addr / 4]._addr; break; case slang_asm_addr_add: - mach.stack[mach.sp + 1]._addr += mach.stack[mach.sp]._addr; - mach.sp++; + stack[mach->sp + 1]._addr += stack[mach->sp]._addr; + mach->sp++; break; case slang_asm_addr_multiply: - mach.stack[mach.sp + 1]._addr *= mach.stack[mach.sp]._addr; - mach.sp++; + stack[mach->sp + 1]._addr *= stack[mach->sp]._addr; + mach->sp++; break; case slang_asm_jump: - mach.ip = a->param[0]; + mach->ip = a->param[0]; break; case slang_asm_jump_if_zero: - if (mach.stack[mach.sp]._float == 0.0f) - mach.ip = a->param[0]; - mach.sp++; + if (stack[mach->sp]._float == 0.0f) + mach->ip = a->param[0]; + mach->sp++; break; case slang_asm_enter: - mach.sp--; - mach.stack[mach.sp]._addr = mach.bp; - mach.bp = mach.sp + a->param[0] / 4; + mach->sp--; + stack[mach->sp]._addr = mach->bp; + mach->bp = mach->sp + a->param[0] / 4; break; case slang_asm_leave: - mach.bp = mach.stack[mach.sp]._addr; - mach.sp++; + mach->bp = stack[mach->sp]._addr; + mach->sp++; break; case slang_asm_local_alloc: - mach.sp -= a->param[0] / 4; + mach->sp -= a->param[0] / 4; break; case slang_asm_local_free: - mach.sp += a->param[0] / 4; + mach->sp += a->param[0] / 4; break; case slang_asm_local_addr: - mach.sp--; - mach.stack[mach.sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach.bp * 4 - + mach->sp--; + 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[mach.sp]._addr = mach.ip; - mach.ip = a->param[0]; + mach->sp--; + stack[mach->sp]._addr = mach->ip; + mach->ip = a->param[0]; break; case slang_asm_return: - mach.ip = mach.stack[mach.sp]._addr; - mach.sp++; + mach->ip = stack[mach->sp]._addr; + mach->sp++; break; case slang_asm_discard: - mach.kill = 1; + mach->kill = 1; break; case slang_asm_exit: - mach.exit = 1; + mach->exit = 1; + break; + /* mesa-specific extensions */ + case slang_asm_float_print: + _mesa_printf ("slang print: %f\n", stack[mach->sp]._float); + break; + case slang_asm_int_print: + _mesa_printf ("slang print: %d\n", (GLint) stack[mach->sp]._float); + break; + case slang_asm_bool_print: + _mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false"); break; } } @@ -362,6 +450,6 @@ int _slang_execute (const slang_assembly_file *file) fclose (f); #endif - return 0; + return 1; } -- cgit v1.2.3