From c7f571eb7e44da65950054fa75f599453bceca0c Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 30 Aug 2006 22:36:29 +0000 Subject: [PATCH] Add missing vec4 instructions to the interpreter. Other cosmetic changes. --- src/mesa/shader/slang/slang_execute.c | 173 ++++++++++++++++++++-- src/mesa/shader/slang/slang_execute.h | 3 +- src/mesa/shader/slang/slang_execute_x86.c | 30 ++-- 3 files changed, 176 insertions(+), 30 deletions(-) diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index bdf3cee257b..98bfd896c4e 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -246,7 +246,7 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) case slang_asm_exit: fprintf (f, "exit"); break; - /* mesa-specific extensions */ + /* GL_MESA_shader_debug */ case slang_asm_float_print: fprintf (f, "float_print"); break; @@ -256,7 +256,38 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) case slang_asm_bool_print: fprintf (f, "bool_print"); break; - default: + /* vec4 */ + case slang_asm_float_to_vec4: + fprintf (f, "float_to_vec4"); + break; + case slang_asm_vec4_add: + fprintf (f, "vec4_add"); + break; + case slang_asm_vec4_subtract: + fprintf (f, "vec4_subtract"); + break; + case slang_asm_vec4_multiply: + fprintf (f, "vec4_multiply"); + break; + case slang_asm_vec4_divide: + fprintf (f, "vec4_divide"); + break; + case slang_asm_vec4_negate: + fprintf (f, "vec4_negate"); + break; + case slang_asm_vec4_dot: + fprintf (f, "vec4_dot"); + break; + case slang_asm_vec4_copy: + fprintf (f, "vec4_copy"); + break; + case slang_asm_vec4_deref: + fprintf (f, "vec4_deref"); + break; + case slang_asm_vec4_equal_int: + fprintf (f, "vec4_equal"); + break; + default: break; } @@ -295,7 +326,8 @@ ensure_infolog_created (slang_info_log **infolog) } } -int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) +GLboolean +_slang_execute2 (const slang_assembly_file *file, slang_machine *mach) { slang_machine_slot *stack; @@ -320,7 +352,7 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) if (mach->x86.compiled_func != NULL) { mach->x86.compiled_func (mach); - return 1; + return GL_TRUE; } #endif @@ -533,7 +565,7 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) break; case slang_asm_local_addr: mach->sp--; - stack[mach->sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach->bp * 4 - + stack[mach->sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach->bp * 4 - (a->param[0] + a->param[1]) + 4; break; case slang_asm_call: @@ -551,7 +583,7 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) case slang_asm_exit: mach->exit = 1; break; - /* mesa-specific extensions */ + /* GL_MESA_shader_debug */ case slang_asm_float_print: _mesa_printf ("slang print: %f\n", stack[mach->sp]._float); ensure_infolog_created (&mach->infolog); @@ -568,17 +600,130 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) slang_info_log_print (mach->infolog, "%s", (GLint) (stack[mach->sp]._float) ? "true" : "false"); break; - default: - _mesa_problem(NULL, "bad slang opcode 0x%x", a->type); - return 0; - } - } + /* vec4 */ + case slang_asm_float_to_vec4: + /* [vec4] | float > [vec4] */ + { + GLuint da = stack[mach->sp + 1]._addr; + mach->mem[da / 4]._float = stack[mach->sp]._float; + mach->sp++; + } + break; + case slang_asm_vec4_add: + /* [vec4] | vec4 > [vec4] */ + { + GLuint da = stack[mach->sp + 4]._addr; + mach->mem[da / 4]._float += stack[mach->sp]._float; + mach->mem[(da + 4) / 4]._float += stack[mach->sp + 1]._float; + mach->mem[(da + 8) / 4]._float += stack[mach->sp + 2]._float; + mach->mem[(da + 12) / 4]._float += stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_subtract: + /* [vec4] | vec4 > [vec4] */ + { + GLuint da = stack[mach->sp + 4]._addr; + mach->mem[da / 4]._float -= stack[mach->sp]._float; + mach->mem[(da + 4) / 4]._float -= stack[mach->sp + 1]._float; + mach->mem[(da + 8) / 4]._float -= stack[mach->sp + 2]._float; + mach->mem[(da + 12) / 4]._float -= stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_multiply: + /* [vec4] | vec4 > [vec4] */ + { + GLuint da = stack[mach->sp + 4]._addr; + mach->mem[da / 4]._float *= stack[mach->sp]._float; + mach->mem[(da + 4) / 4]._float *= stack[mach->sp + 1]._float; + mach->mem[(da + 8) / 4]._float *= stack[mach->sp + 2]._float; + mach->mem[(da + 12) / 4]._float *= stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_divide: + /* [vec4] | vec4 > [vec4] */ + { + GLuint da = stack[mach->sp + 4]._addr; + mach->mem[da / 4]._float /= stack[mach->sp]._float; + mach->mem[(da + 4) / 4]._float /= stack[mach->sp + 1]._float; + mach->mem[(da + 8) / 4]._float /= stack[mach->sp + 2]._float; + mach->mem[(da + 12) / 4]._float /= stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_negate: + /* [vec4] > [vec4] */ + { + GLuint da = stack[mach->sp]._addr; + mach->mem[da / 4]._float = -mach->mem[da / 4]._float; + mach->mem[(da + 4) / 4]._float = -mach->mem[(da + 4) / 4]._float; + mach->mem[(da + 8) / 4]._float = -mach->mem[(da + 8) / 4]._float; + mach->mem[(da + 12) / 4]._float = -mach->mem[(da + 12) / 4]._float; + } + break; + case slang_asm_vec4_dot: + /* [vec4] | vec4 > [float] */ + { + GLuint da = stack[mach->sp + 4]._addr; + mach->mem[da / 4]._float = + mach->mem[da / 4]._float * stack[mach->sp]._float + + mach->mem[(da + 4) / 4]._float * stack[mach->sp + 1]._float + + mach->mem[(da + 8) / 4]._float * stack[mach->sp + 2]._float + + mach->mem[(da + 12) / 4]._float * stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_copy: + /* [vec4] | vec4 > [vec4] */ + { + GLuint da = stack[mach->sp + a->param[0] / 4]._addr + a->param[1]; + mach->mem[da / 4]._float = stack[mach->sp]._float; + mach->mem[(da + 4) / 4]._float = stack[mach->sp + 1]._float; + mach->mem[(da + 8) / 4]._float = stack[mach->sp + 2]._float; + mach->mem[(da + 12) / 4]._float = stack[mach->sp + 3]._float; + mach->sp += 4; + } + break; + case slang_asm_vec4_deref: + /* [vec4] > vec4 */ + { + GLuint sa = stack[mach->sp]._addr; + mach->sp -= 3; + stack[mach->sp]._float = mach->mem[sa / 4]._float; + stack[mach->sp + 1]._float = mach->mem[(sa + 4) / 4]._float; + stack[mach->sp + 2]._float = mach->mem[(sa + 8) / 4]._float; + stack[mach->sp + 3]._float = mach->mem[(sa + 12) / 4]._float; + } + break; + case slang_asm_vec4_equal_int: + { + GLuint sp0 = mach->sp + a->param[0] / 4; + GLuint sp1 = mach->sp + a->param[1] / 4; + mach->sp--; + if (stack[sp0]._float == stack[sp1]._float && + stack[sp0 + 1]._float == stack[sp1 + 1]._float && + stack[sp0 + 2]._float == stack[sp1 + 2]._float && + stack[sp0 + 3]._float == stack[sp1 + 3]._float) { + stack[mach->sp]._float = 1.0f; + } + else { + stack[mach->sp]._float = 0.0f; + } + } + break; + default: + _mesa_problem(NULL, "bad slang opcode 0x%x", a->type); + return GL_FALSE; + } + } #if DEBUG_SLANG - if (f != NULL) - fclose (f); + if (f != NULL) + fclose (f); #endif - return 1; + return GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_execute.h b/src/mesa/shader/slang/slang_execute.h index 4afad20a4de..cb152c71420 100644 --- a/src/mesa/shader/slang/slang_execute.h +++ b/src/mesa/shader/slang/slang_execute.h @@ -70,7 +70,8 @@ GLvoid slang_machine_dtr (slang_machine *); void slang_machine_init (slang_machine *); -int _slang_execute2 (const slang_assembly_file *, slang_machine *); +GLboolean +_slang_execute2 (const slang_assembly_file *, slang_machine *); #if defined(USE_X86_ASM) || defined(SLANG_X86) GLboolean _slang_x86_codegen (slang_machine *, slang_assembly_file *, GLuint); diff --git a/src/mesa/shader/slang/slang_execute_x86.c b/src/mesa/shader/slang/slang_execute_x86.c index 468984dce6b..3e21edff6a3 100644 --- a/src/mesa/shader/slang/slang_execute_x86.c +++ b/src/mesa/shader/slang/slang_execute_x86.c @@ -507,7 +507,7 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * break; /* vec4 */ case slang_asm_float_to_vec4: - /* [vec4] | float */ + /* [vec4] | float > [vec4] */ x87_fld (&G->f, x86_deref (G->r_esp)); x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4)); x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp)); @@ -517,20 +517,20 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * x87_fstp (&G->f, x86_deref (G->r_eax)); break; case slang_asm_vec4_add: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [vec4] */ + x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16)); + for (i = 0; i < 4; i++) + x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_esp, i * 4)); x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16)); - x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp)); - for (i = 0; i < 4; i++) - x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); for (i = 0; i < 4; i++) x87_faddp (&G->f, G->r_st4); for (i = 0; i < 4; i++) x87_fstp (&G->f, x86_make_disp (G->r_eax, 12 - i * 4)); break; case slang_asm_vec4_subtract: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [vec4] */ x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16)); for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); @@ -543,20 +543,20 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * x87_fstp (&G->f, x86_make_disp (G->r_eax, 12 - i * 4)); break; case slang_asm_vec4_multiply: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [vec4] */ + x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16)); + for (i = 0; i < 4; i++) + x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_esp, i * 4)); x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16)); - x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp)); - for (i = 0; i < 4; i++) - x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); for (i = 0; i < 4; i++) x87_fmulp (&G->f, G->r_st4); for (i = 0; i < 4; i++) x87_fstp (&G->f, x86_make_disp (G->r_eax, 12 - i * 4)); break; case slang_asm_vec4_divide: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [vec4] */ x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16)); for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); @@ -569,7 +569,7 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * x87_fstp (&G->f, x86_make_disp (G->r_eax, 12 - i * 4)); break; case slang_asm_vec4_negate: - /* [vec4] */ + /* [vec4] > [vec4] */ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp)); for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_eax, i * 4)); @@ -579,7 +579,7 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * } break; case slang_asm_vec4_dot: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [float] */ for (i = 0; i < 4; i++) x87_fld (&G->f, x86_make_disp (G->r_esp, i * 4)); x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16)); @@ -593,7 +593,7 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * x87_fstp (&G->f, x86_deref (G->r_eax)); break; case slang_asm_vec4_copy: - /* [vec4] | vec4 */ + /* [vec4] | vec4 > [vec4] */ x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, a->param[0])); x86_pop (&G->f, G->r_ecx); x86_pop (&G->f, G->r_edx); @@ -605,7 +605,7 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log * x86_mov (&G->f, x86_make_disp (G->r_eax, a->param[1] + 12), G->r_ecx); break; case slang_asm_vec4_deref: - /* [vec4] */ + /* [vec4] > vec4 */ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp)); x86_mov (&G->f, G->r_ecx, x86_make_disp (G->r_eax, 12)); x86_mov (&G->f, G->r_edx, x86_make_disp (G->r_eax, 8)); -- 2.30.2