diff options
author | Michal Krol <[email protected]> | 2006-05-16 10:04:24 +0000 |
---|---|---|
committer | Michal Krol <[email protected]> | 2006-05-16 10:04:24 +0000 |
commit | 21ef956e9a48ab21e724a480a592e17d651477e6 (patch) | |
tree | 341779220a3e68298889f9e9c134ac2050e5551a /src/mesa/shader | |
parent | a67330d157ffe05602a3163c946aa97e29cb6bb5 (diff) |
Extend printMESA function to output also to shader's info log.
Fix float-to-int conversion for x86 back-end.
Diffstat (limited to 'src/mesa/shader')
-rw-r--r-- | src/mesa/shader/slang/slang_execute.c | 32 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_execute.h | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_execute_x86.c | 63 |
3 files changed, 75 insertions, 22 deletions
diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index 5577909da06..e5beb509f0b 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -29,6 +29,7 @@ */ #include "imports.h" +#include "slang_compile.h" #include "slang_execute.h" #include "slang_library_noise.h" #include "slang_library_texsample.h" @@ -38,6 +39,7 @@ GLvoid slang_machine_ctr (slang_machine *self) { slang_machine_init (self); + self->infolog = NULL; #if defined(USE_X86_ASM) || defined(SLANG_X86) self->x86.compiled_func = NULL; #endif @@ -45,6 +47,10 @@ GLvoid slang_machine_ctr (slang_machine *self) GLvoid slang_machine_dtr (slang_machine *self) { + if (self->infolog != NULL) { + slang_info_log_destruct (self->infolog); + slang_alloc_free (self->infolog); + } #if defined(USE_X86_ASM) || defined(SLANG_X86) if (self->x86.compiled_func != NULL) _mesa_exec_free (self->x86.compiled_func); @@ -60,14 +66,6 @@ void slang_machine_init (slang_machine *mach) mach->exit = 0; } -int _slang_execute (const slang_assembly_file *file) -{ - slang_machine mach; - - slang_machine_ctr (&mach); - return _slang_execute2 (file, &mach); -} - #if DEBUG_SLANG static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) @@ -286,6 +284,17 @@ static void dump (const slang_assembly_file *file) #endif +static GLvoid +ensure_infolog_created (slang_info_log **infolog) +{ + if (*infolog == NULL) { + *infolog = slang_alloc_malloc (sizeof (slang_info_log)); + if (*infolog == NULL) + return; + slang_info_log_construct (*infolog); + } +} + int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) { slang_machine_slot *stack; @@ -545,12 +554,19 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) /* mesa-specific extensions */ case slang_asm_float_print: _mesa_printf ("slang print: %f\n", stack[mach->sp]._float); + ensure_infolog_created (&mach->infolog); + slang_info_log_print (mach->infolog, "%f", stack[mach->sp]._float); break; case slang_asm_int_print: _mesa_printf ("slang print: %d\n", (GLint) stack[mach->sp]._float); + ensure_infolog_created (&mach->infolog); + slang_info_log_print (mach->infolog, "%d", (GLint) (stack[mach->sp]._float)); break; case slang_asm_bool_print: _mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false"); + ensure_infolog_created (&mach->infolog); + slang_info_log_print (mach->infolog, "%s", + (GLint) (stack[mach->sp]._float) ? "true" : "false"); break; default: assert (0); diff --git a/src/mesa/shader/slang/slang_execute.h b/src/mesa/shader/slang/slang_execute.h index 4fca84c5506..4afad20a4de 100644 --- a/src/mesa/shader/slang/slang_execute.h +++ b/src/mesa/shader/slang/slang_execute.h @@ -59,6 +59,7 @@ typedef struct slang_machine_ GLuint kill; /* discard the fragment */ GLuint exit; /* terminate the shader */ slang_machine_slot mem[SLANG_MACHINE_MEMORY_SIZE]; + struct slang_info_log_ *infolog; /* printMESA() support */ #if defined(USE_X86_ASM) || defined(SLANG_X86) slang_machine_x86 x86; #endif @@ -69,7 +70,6 @@ GLvoid slang_machine_dtr (slang_machine *); void slang_machine_init (slang_machine *); -int _slang_execute (const slang_assembly_file *); int _slang_execute2 (const slang_assembly_file *, slang_machine *); #if defined(USE_X86_ASM) || defined(SLANG_X86) diff --git a/src/mesa/shader/slang/slang_execute_x86.c b/src/mesa/shader/slang/slang_execute_x86.c index ea140bd0b0d..9d2967f2b73 100644 --- a/src/mesa/shader/slang/slang_execute_x86.c +++ b/src/mesa/shader/slang/slang_execute_x86.c @@ -29,6 +29,7 @@ */ #include "imports.h" +#include "slang_compile.h" #include "slang_execute.h" #include "slang_library_noise.h" #include "slang_library_texsample.h" @@ -133,30 +134,53 @@ static GLfloat do_floorf (GLfloat x) return FLOORF (x); } +static GLfloat +do_ftoi (GLfloat x) +{ + return (GLfloat) ((GLint) (x)); +} + static GLfloat do_powf (GLfloat y, GLfloat x) { return (GLfloat) _mesa_pow ((GLdouble) x, (GLdouble) y); } -static GLvoid do_print_float (GLfloat x) +static GLvoid +ensure_infolog_created (slang_info_log **infolog) { - _mesa_printf ("slang print: %f\n", x); + if (*infolog == NULL) { + *infolog = slang_alloc_malloc (sizeof (slang_info_log)); + if (*infolog == NULL) + return; + slang_info_log_construct (*infolog); + } } -static GLvoid do_print_int (GLfloat x) +static GLvoid do_print_float (slang_info_log **infolog, GLfloat x) { - _mesa_printf ("slang print: %d\n", (GLint) x); + _mesa_printf ("slang print: %f\n", x); + ensure_infolog_created (infolog); + slang_info_log_print (*infolog, "%f", x); } -static GLvoid do_print_bool (GLfloat x) +static GLvoid do_print_int (slang_info_log **infolog, GLfloat x) { - _mesa_printf ("slang print: %s\n", (GLint) x ? "true" : "false"); + _mesa_printf ("slang print: %d\n", (GLint) (x)); + ensure_infolog_created (infolog); + slang_info_log_print (*infolog, "%d", (GLint) (x)); +} + +static GLvoid do_print_bool (slang_info_log **infolog, GLfloat x) +{ + _mesa_printf ("slang print: %s\n", (GLint) (x) ? "true" : "false"); + ensure_infolog_created (infolog); + slang_info_log_print (*infolog, "%s", (GLint) (x) ? "true" : "false"); } #define FLOAT_ONE 0x3f800000 #define FLOAT_ZERO 0 -static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a) +static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a, slang_info_log **infolog) { GLint disp; @@ -287,8 +311,9 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a) } break; case slang_asm_float_to_int: - x87_fld (&G->f, x86_deref (G->r_esp)); - x87_fistp (&G->f, x86_deref (G->r_esp)); + /* TODO: use fistp without rounding */ + x86_call (&G->f, (GLubyte *) (do_ftoi)); + x87_fstp (&G->f, x86_deref (G->r_esp)); break; case slang_asm_float_sine: /* TODO: use fsin */ @@ -457,14 +482,26 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a) x86_jmp (&G->f, G->l_exit); break; /* mesa-specific extensions */ - case slang_asm_float_print: - x86_call (&G->f, (GLubyte *) do_print_float); - break; + case slang_asm_float_print: + /* TODO: use push imm32 */ + x86_mov_reg_imm (&G->f, G->r_eax, (GLint) (infolog)); + x86_push (&G->f, G->r_eax); + x86_call (&G->f, (GLubyte *) (do_print_float)); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4)); + break; case slang_asm_int_print: + /* TODO: use push imm32 */ + x86_mov_reg_imm (&G->f, G->r_eax, (GLint) (infolog)); + x86_push (&G->f, G->r_eax); x86_call (&G->f, (GLubyte *) do_print_int); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4)); break; case slang_asm_bool_print: + /* TODO: use push imm32 */ + x86_mov_reg_imm (&G->f, G->r_eax, (GLint) (infolog)); + x86_push (&G->f, G->r_eax); x86_call (&G->f, (GLubyte *) do_print_bool); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4)); break; default: assert (0); @@ -523,7 +560,7 @@ GLboolean _slang_x86_codegen (slang_machine *mach, slang_assembly_file *file, GL G.labels[i] = x86_get_label (&G.f); if (i == start) x86_fixup_fwd_jump (&G.f, j_body); - codegen_assem (&G, &file->code[i]); + codegen_assem (&G, &file->code[i], &mach->infolog); } /* |