summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2006-11-18 17:23:30 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2006-11-18 17:23:30 +0000
commita89e063149e183760e8dc2783922cbd389fc106e (patch)
treec5240ed9d28b92d6888693424639135f6eb4b0c7 /src/mesa/shader/slang
parent61068ba46bbf2c2bb2b1e434602a9361125e76e5 (diff)
comments
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r--src/mesa/shader/slang/slang_assemble.h42
-rw-r--r--src/mesa/shader/slang/slang_execute.c26
2 files changed, 50 insertions, 18 deletions
diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h
index 3f75e971be..d004e66500 100644
--- a/src/mesa/shader/slang/slang_assemble.h
+++ b/src/mesa/shader/slang/slang_assemble.h
@@ -42,56 +42,65 @@ typedef enum slang_assembly_type_
slang_asm_float_move,
slang_asm_float_push,
slang_asm_float_deref,
- slang_asm_float_add,
+ slang_asm_float_add, /* a = pop(); b = pop(); push(a + b); */
slang_asm_float_multiply,
slang_asm_float_divide,
- slang_asm_float_negate,
- slang_asm_float_less,
+ slang_asm_float_negate, /* push(-pop()) */
+ slang_asm_float_less, /* a = pop(); b = pop(); push(a < b); */
slang_asm_float_equal_exp,
slang_asm_float_equal_int,
- slang_asm_float_to_int,
- slang_asm_float_sine,
+ slang_asm_float_to_int, /* push(floatToInt(pop())) */
+ slang_asm_float_sine, /* push(sin(pop()) */
slang_asm_float_arcsine,
slang_asm_float_arctan,
- slang_asm_float_power,
+ slang_asm_float_power, /* push(pow(pop(), pop())) */
slang_asm_float_log2,
slang_asm_float_floor,
slang_asm_float_ceil,
- slang_asm_float_noise1,
- slang_asm_float_noise2,
+ slang_asm_float_noise1, /* push(noise1(pop()) */
+ slang_asm_float_noise2, /* push(noise2(pop(), pop())) */
slang_asm_float_noise3,
slang_asm_float_noise4,
+
slang_asm_int_copy,
slang_asm_int_move,
slang_asm_int_push,
slang_asm_int_deref,
slang_asm_int_to_float,
slang_asm_int_to_addr,
+
slang_asm_bool_copy,
slang_asm_bool_move,
slang_asm_bool_push,
slang_asm_bool_deref,
+
slang_asm_addr_copy,
slang_asm_addr_push,
slang_asm_addr_deref,
slang_asm_addr_add,
slang_asm_addr_multiply,
+
slang_asm_vec4_tex1d,
slang_asm_vec4_tex2d,
slang_asm_vec4_tex3d,
slang_asm_vec4_texcube,
slang_asm_vec4_shad1d,
slang_asm_vec4_shad2d,
+
slang_asm_jump,
slang_asm_jump_if_zero,
+
slang_asm_enter,
slang_asm_leave,
+
slang_asm_local_alloc,
slang_asm_local_free,
slang_asm_local_addr,
slang_asm_global_addr,
- slang_asm_call,
+
+ slang_asm_call, /* push(ip); jump(inst->param[0]); */
slang_asm_return,
+
slang_asm_discard,
slang_asm_exit,
/* GL_MESA_shader_debug */
@@ -113,13 +122,21 @@ typedef enum slang_assembly_type_
slang_asm__last
} slang_assembly_type;
+
+/**
+ * An assembly-level shader instruction.
+ */
typedef struct slang_assembly_
{
- slang_assembly_type type;
- GLfloat literal;
- GLuint param[2];
+ slang_assembly_type type; /**< The instruction opcode */
+ GLfloat literal; /**< float literal */
+ GLuint param[2]; /**< Two integer/address parameters */
} slang_assembly;
+
+/**
+ * A list of slang_assembly instructions
+ */
typedef struct slang_assembly_file_
{
slang_assembly *code;
@@ -127,6 +144,7 @@ typedef struct slang_assembly_file_
GLuint capacity;
} slang_assembly_file;
+
extern GLvoid
_slang_assembly_file_ctr(slang_assembly_file *);
diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c
index d6689bc8a4..e469de0207 100644
--- a/src/mesa/shader/slang/slang_execute.c
+++ b/src/mesa/shader/slang/slang_execute.c
@@ -59,6 +59,11 @@ slang_machine_dtr(slang_machine * self)
#endif
}
+
+/**
+ * Initialize the shader virtual machine.
+ * NOTE: stack grows downward in memory.
+ */
void
slang_machine_init(slang_machine * mach)
{
@@ -71,7 +76,7 @@ slang_machine_init(slang_machine * mach)
#if DEBUG_SLANG
-foo static void
+static void
dump_instruction(FILE * f, slang_assembly * a, unsigned int i)
{
fprintf(f, "%.5u:\t", i);
@@ -362,7 +367,7 @@ _slang_execute2(const slang_assembly_file * file, slang_machine * mach)
stack = mach->mem + SLANG_MACHINE_GLOBAL_SIZE;
while (!mach->exit) {
- slang_assembly *a = &file->code[mach->ip];
+ const slang_assembly *a = &file->code[mach->ip];
#if DEBUG_SLANG
if (f != NULL && a->type != slang_asm_none) {
@@ -386,8 +391,13 @@ _slang_execute2(const slang_assembly_file * file, slang_machine * mach)
case slang_asm_float_copy:
case slang_asm_int_copy:
case slang_asm_bool_copy:
- mach->mem[(stack[mach->sp + a->param[0] / 4]._addr + a->param[1]) /
- 4]._float = stack[mach->sp]._float;
+ /* store top value on stack to memory */
+ {
+ GLuint address
+ = (stack[mach->sp + a->param[0] / 4]._addr + a->param[1]) / 4;
+ GLfloat value = stack[mach->sp]._float;
+ mach->mem[address]._float = value;
+ }
mach->sp++;
break;
case slang_asm_float_move:
@@ -400,15 +410,18 @@ _slang_execute2(const slang_assembly_file * file, slang_machine * mach)
case slang_asm_float_push:
case slang_asm_int_push:
case slang_asm_bool_push:
+ /* push float/int/bool literal onto stop of stack */
mach->sp--;
stack[mach->sp]._float = a->literal;
break;
case slang_asm_float_deref:
case slang_asm_int_deref:
case slang_asm_bool_deref:
+ /* load value from memory, replace stop of stack with it */
stack[mach->sp]._float = mach->mem[stack[mach->sp]._addr / 4]._float;
break;
case slang_asm_float_add:
+ /* pop two top floats, push sum */
stack[mach->sp + 1]._float += stack[mach->sp]._float;
mach->sp++;
break;
@@ -425,8 +438,8 @@ _slang_execute2(const slang_assembly_file * file, slang_machine * mach)
break;
case slang_asm_float_less:
stack[mach->sp + 1]._float =
- stack[mach->sp + 1]._float <
- stack[mach->sp]._float ? (GLfloat) 1 : (GLfloat) 0;
+ (stack[mach->sp + 1]._float < stack[mach->sp]._float)
+ ? (GLfloat) 1 : (GLfloat) 0;
mach->sp++;
break;
case slang_asm_float_equal_exp:
@@ -436,6 +449,7 @@ _slang_execute2(const slang_assembly_file * file, slang_machine * mach)
mach->sp++;
break;
case slang_asm_float_equal_int:
+ /* pop top two values, compare, push 0 or 1 */
mach->sp--;
stack[mach->sp]._float =
(stack[mach->sp + 1 + a->param[0] / 4]._float ==