From 05dab5eaa2703cd3f16f52e9ecc4eee04b969b62 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 13 Dec 2006 15:34:10 -0700 Subject: Checkpoint GLSL compiler work. Add new sources, remove obsolete. --- src/mesa/sources | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 09692c6f15..6e6f1c0bfd 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -87,7 +87,6 @@ SWRAST_SOURCES = \ swrast/s_aatriangle.c \ swrast/s_accum.c \ swrast/s_alpha.c \ - swrast/s_arbshader.c \ swrast/s_atifragshader.c \ swrast/s_bitmap.c \ swrast/s_blend.c \ @@ -128,7 +127,6 @@ TNL_SOURCES = \ tnl/t_save_playback.c \ tnl/t_vb_arbprogram.c \ tnl/t_vb_arbprogram_sse.c \ - tnl/t_vb_arbshader.c\ tnl/t_vb_program.c \ tnl/t_vb_render.c \ tnl/t_vb_texgen.c \ @@ -149,8 +147,6 @@ TNL_SOURCES = \ tnl/t_vtx_eval.c \ tnl/t_vtx_exec.c - - SHADER_SOURCES = \ shader/arbprogparse.c \ shader/arbprogram.c \ @@ -165,34 +161,6 @@ SHADER_SOURCES = \ shader/shaderobjects.c \ shader/shaderobjects_3dlabs.c -SLANG_C_SOURCES = \ - shader/slang/MachineIndependent/preprocessor/atom.c \ - shader/slang/MachineIndependent/preprocessor/cpp.c \ - shader/slang/MachineIndependent/preprocessor/cppstruct.c \ - shader/slang/MachineIndependent/preprocessor/memory.c \ - shader/slang/MachineIndependent/preprocessor/scanner.c \ - shader/slang/MachineIndependent/preprocessor/symbols.c \ - shader/slang/MachineIndependent/preprocessor/tokens.c - -SLANG_CPP_SOURCES = \ - shader/slang/slang_mesa.cpp \ - shader/slang/MachineIndependent/Gen_glslang.cpp \ - shader/slang/MachineIndependent/Gen_glslang_tab.cpp \ - shader/slang/MachineIndependent/InfoSink.cpp \ - shader/slang/MachineIndependent/Initialize.cpp \ - shader/slang/MachineIndependent/Intermediate.cpp \ - shader/slang/MachineIndependent/intermOut.cpp \ - shader/slang/MachineIndependent/IntermTraverse.cpp \ - shader/slang/MachineIndependent/parseConst.cpp \ - shader/slang/MachineIndependent/ParseHelper.cpp \ - shader/slang/MachineIndependent/PoolAlloc.cpp \ - shader/slang/MachineIndependent/QualifierAlive.cpp \ - shader/slang/MachineIndependent/RemoveTree.cpp \ - shader/slang/MachineIndependent/ShaderLang.cpp \ - shader/slang/MachineIndependent/SymbolTable.cpp \ - shader/slang/OGLCompilersDLL/Initialisation.cpp \ - shader/slang/OSDependent/Linux/ossource.cpp - SLANG_SOURCES = \ shader/slang/slang_analyse.c \ shader/slang/slang_assemble.c \ @@ -200,18 +168,24 @@ SLANG_SOURCES = \ shader/slang/slang_assemble_conditional.c \ shader/slang/slang_assemble_constructor.c \ shader/slang/slang_assemble_typeinfo.c \ + shader/slang/slang_codegen.c \ shader/slang/slang_compile.c \ shader/slang/slang_compile_function.c \ shader/slang/slang_compile_operation.c \ shader/slang/slang_compile_struct.c \ shader/slang/slang_compile_variable.c \ + shader/slang/slang_emit.c \ + shader/slang/slang_error.c \ shader/slang/slang_execute.c \ shader/slang/slang_export.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ shader/slang/slang_link.c \ + shader/slang/slang_link2.c \ shader/slang/slang_preprocess.c \ + shader/slang/slang_simplify.c \ shader/slang/slang_storage.c \ + shader/slang/slang_print.c \ shader/slang/slang_utility.c ASM_C_SOURCES = \ @@ -324,7 +298,6 @@ SOLO_SOURCES = \ $(SWRAST_SETUP_SOURCES) \ $(ASM_C_SOURCES) \ $(SLANG_SOURCES) -# $(SLANG_C_SOURCES) CORE_SOURCES = \ $(GLAPI_SOURCES) \ -- cgit v1.2.3 From 2a9950dcb37849a64a59c3a88a858a6f8c33d8b5 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 13 Dec 2006 19:20:45 -0700 Subject: Remove unneeded -I directories (3Dlabs headers). --- src/mesa/sources | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 6e6f1c0bfd..cdae7b4d31 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -336,7 +336,5 @@ INCLUDE_DIRS = \ -I$(TOP)/src/mesa/shader \ -I$(TOP)/src/mesa/shader/grammar \ -I$(TOP)/src/mesa/shader/slang \ - -I$(TOP)/src/mesa/shader/slang/OSDependent/Linux \ - -I$(TOP)/src/mesa/shader/slang/OGLCompilersDLL \ -I$(TOP)/src/mesa/swrast \ -I$(TOP)/src/mesa/swrast_setup -- cgit v1.2.3 From 39adc3025071927b6fd4ec1b9dbe9c03b20c82de Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 15 Dec 2006 08:55:49 -0700 Subject: change/add/rm several filenames --- src/mesa/sources | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index cdae7b4d31..eed6fb0a0e 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -98,11 +98,11 @@ SWRAST_SOURCES = \ swrast/s_drawpix.c \ swrast/s_feedback.c \ swrast/s_fog.c \ + swrast/s_fragprog.c \ swrast/s_imaging.c \ swrast/s_lines.c \ swrast/s_logic.c \ swrast/s_masking.c \ - swrast/s_nvfragprog.c \ swrast/s_points.c \ swrast/s_readpix.c \ swrast/s_span.c \ @@ -157,9 +157,16 @@ SHADER_SOURCES = \ shader/nvvertexec.c \ shader/nvvertparse.c \ shader/program.c \ + shader/prog_instruction.c \ + shader/prog_parameter.c \ + shader/prog_print.c \ + shader/prog_statevars.c \ shader/programopt.c \ - shader/shaderobjects.c \ - shader/shaderobjects_3dlabs.c + shader/shader_api.c \ + + +## shader/shaderobjects.c \ +## shader/shaderobjects_3dlabs.c SLANG_SOURCES = \ shader/slang/slang_analyse.c \ -- cgit v1.2.3 From 0bf5dbe002a64e198f55724cc1542602c012490f Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 19 Dec 2006 18:02:41 -0700 Subject: Overhaul of GLSL API functions, dispatching, etc. --- src/mesa/drivers/common/driverfuncs.c | 46 +++++++++++++++++++++++++++++-- src/mesa/drivers/common/driverfuncs.h | 8 ++++-- src/mesa/main/context.c | 17 ++++++------ src/mesa/main/dd.h | 52 +++++++++++++++++++++++++++++++++++ src/mesa/main/mtypes.h | 22 +++++++++------ src/mesa/main/state.c | 4 +-- src/mesa/main/texstate.c | 2 +- src/mesa/sources | 5 +--- src/mesa/swrast/s_context.c | 2 +- src/mesa/swrast/s_span.c | 2 +- 10 files changed, 130 insertions(+), 30 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c index 1e44904b93..bc637a879e 100644 --- a/src/mesa/drivers/common/driverfuncs.c +++ b/src/mesa/drivers/common/driverfuncs.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 6.5.3 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -43,6 +43,7 @@ #include "fbobject.h" #include "texrender.h" #endif +#include "shader_api.h" #include "arrayobj.h" #include "driverfuncs.h" @@ -248,4 +249,45 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->EndList = NULL; driver->BeginCallList = NULL; driver->EndCallList = NULL; + + + /* XXX temporary here */ + _mesa_init_glsl_driver_functions(driver); +} + + +/** + * Plug in Mesa's GLSL functions. + */ +void +_mesa_init_glsl_driver_functions(struct dd_function_table *driver) +{ + driver->AttachShader = _mesa_attach_shader; + driver->BindAttribLocation = _mesa_bind_attrib_location; + driver->CompileShader = _mesa_compile_shader; + driver->CreateProgram = _mesa_create_program; + driver->CreateShader = _mesa_create_shader; + driver->DeleteProgram2 = _mesa_delete_program2; + driver->DeleteShader = _mesa_delete_shader; + driver->DetachShader = _mesa_detach_shader; + driver->GetActiveAttrib = _mesa_get_active_attrib; + driver->GetActiveUniform = _mesa_get_active_uniform; + driver->GetAttachedShaders = _mesa_get_attached_shaders; + driver->GetAttribLocation = _mesa_get_attrib_location; + driver->GetHandle = _mesa_get_handle; + driver->GetProgramiv = _mesa_get_programiv; + driver->GetProgramInfoLog = _mesa_get_program_info_log; + driver->GetShaderiv = _mesa_get_shaderiv; + driver->GetShaderInfoLog = _mesa_get_shader_info_log; + driver->GetShaderSource = _mesa_get_shader_source; + driver->GetUniformfv = _mesa_get_uniformfv; + driver->GetUniformLocation = _mesa_get_uniform_location; + driver->IsProgram = _mesa_is_program; + driver->IsShader = _mesa_is_shader; + driver->LinkProgram = _mesa_link_program; + driver->ShaderSource = _mesa_shader_source; + driver->Uniform = _mesa_uniform; + driver->UniformMatrix = _mesa_uniform_matrix; + driver->UseProgram = _mesa_use_program; + driver->ValidateProgram = _mesa_validate_program; } diff --git a/src/mesa/drivers/common/driverfuncs.h b/src/mesa/drivers/common/driverfuncs.h index 64f56d91f9..50f2b4271d 100644 --- a/src/mesa/drivers/common/driverfuncs.h +++ b/src/mesa/drivers/common/driverfuncs.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 6.5.3 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -29,4 +29,8 @@ extern void _mesa_init_driver_functions(struct dd_function_table *driver); + +extern void +_mesa_init_glsl_driver_functions(struct dd_function_table *driver); + #endif diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 4986b29ef0..c5220b5b2e 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -131,7 +131,7 @@ #include "math/m_xform.h" #include "math/mathmod.h" #endif -#include "shaderobjects.h" +#include "shaders.h" #ifdef USE_SPARC_ASM #include "sparc/sparc.h" @@ -705,7 +705,6 @@ alloc_shared_state( GLcontext *ctx ) ss->ArrayObjects = _mesa_NewHashTable(); #if FEATURE_ARB_shader_objects - ss->GL2Objects = _mesa_NewHashTable (); ss->ShaderObjects = _mesa_NewHashTable(); ss->ProgramObjects = _mesa_NewHashTable(); #endif @@ -784,11 +783,10 @@ alloc_shared_state( GLcontext *ctx ) _mesa_DeleteHashTable (ss->ArrayObjects); #if FEATURE_ARB_shader_objects - if (ss->GL2Objects) { - _mesa_DeleteHashTable (ss->GL2Objects); + if (ss->ShaderObjects) _mesa_DeleteHashTable (ss->ShaderObjects); + if (ss->ProgramObjects) _mesa_DeleteHashTable (ss->ProgramObjects); - } #endif #if FEATURE_EXT_framebuffer_object @@ -953,8 +951,11 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) _mesa_DeleteHashTable(ss->ArrayObjects); #if FEATURE_ARB_shader_objects - _mesa_HashDeleteAll(ss->GL2Objects, delete_shaderobj_cb, ctx); - _mesa_DeleteHashTable(ss->GL2Objects); + /* XXX SLANG TO-DO */ + /* + struct _mesa_HashTable *ShaderObjects; + struct _mesa_HashTable *ProgramObjects; + */ #endif #if FEATURE_EXT_framebuffer_object @@ -1202,7 +1203,7 @@ init_attrib_groups( GLcontext *ctx ) _mesa_init_query( ctx ); _mesa_init_rastpos( ctx ); _mesa_init_scissor( ctx ); - _mesa_init_shaderobjects (ctx); + _mesa_init_shader_state( ctx ); _mesa_init_stencil( ctx ); _mesa_init_transform( ctx ); _mesa_init_varray( ctx ); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index 1de2542bee..90c1f69c3d 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -821,6 +821,58 @@ struct dd_function_table { void (*BindArrayObject)(GLcontext *ctx, struct gl_array_object *obj); /*@}*/ + /** + * \name GLSL-related functions (ARB extensions and OpenGL 2.x) + */ + /*@{*/ + void (*AttachShader)(GLcontext *ctx, GLuint program, GLuint shader); + void (*BindAttribLocation)(GLcontext *ctx, GLuint program, GLuint index, + const GLcharARB *name); + void (*CompileShader)(GLcontext *ctx, GLuint shader); + GLuint (*CreateShader)(GLcontext *ctx, GLenum type); + GLuint (*CreateProgram)(GLcontext *ctx); + void (*DeleteProgram2)(GLcontext *ctx, GLuint program); + void (*DeleteShader)(GLcontext *ctx, GLuint shader); + void (*DetachShader)(GLcontext *ctx, GLuint program, GLuint shader); + void (*GetActiveAttrib)(GLcontext *ctx, GLuint program, GLuint index, + GLsizei maxLength, GLsizei * length, GLint * size, + GLenum * type, GLcharARB * name); + void (*GetActiveUniform)(GLcontext *ctx, GLuint program, GLuint index, + GLsizei maxLength, GLsizei *length, GLint *size, + GLenum *type, GLcharARB *name); + void (*GetAttachedShaders)(GLcontext *ctx, GLuint program, GLsizei maxCount, + GLsizei *count, GLuint *obj); + GLint (*GetAttribLocation)(GLcontext *ctx, GLuint program, + const GLcharARB *name); + GLuint (*GetHandle)(GLcontext *ctx, GLenum pname); + void (*GetProgramiv)(GLcontext *ctx, GLuint program, + GLenum pname, GLint *params); + void (*GetProgramInfoLog)(GLcontext *ctx, GLuint program, GLsizei bufSize, + GLsizei *length, GLchar *infoLog); + void (*GetShaderiv)(GLcontext *ctx, GLuint shader, + GLenum pname, GLint *params); + void (*GetShaderInfoLog)(GLcontext *ctx, GLuint shader, GLsizei bufSize, + GLsizei *length, GLchar *infoLog); + void (*GetShaderSource)(GLcontext *ctx, GLuint shader, GLsizei maxLength, + GLsizei *length, GLcharARB *sourceOut); + void (*GetUniformfv)(GLcontext *ctx, GLuint program, GLint location, + GLfloat *params); + GLint (*GetUniformLocation)(GLcontext *ctx, GLuint program, + const GLcharARB *name); + GLboolean (*IsProgram)(GLcontext *ctx, GLuint name); + GLboolean (*IsShader)(GLcontext *ctx, GLuint name); + void (*LinkProgram)(GLcontext *ctx, GLuint program); + void (*ShaderSource)(GLcontext *ctx, GLuint shader, const GLchar *source); + void (*Uniform)(GLcontext *ctx, GLint location, GLsizei count, + const GLvoid *values, GLenum type); + void (*UniformMatrix)(GLcontext *ctx, GLint cols, GLint rows, + GLenum matrixType, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *values); + void (*UseProgram)(GLcontext *ctx, GLuint program); + void (*ValidateProgram)(GLcontext *ctx, GLuint program); + /* XXX many more to come */ + /*@}*/ + /** * \name Support for multiple T&L engines diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 5ed95ccf65..4a8f7d22e3 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -7,9 +7,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 6.5.3 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -2052,8 +2052,10 @@ struct gl_shader GLuint Name; /**< AKA the handle */ GLchar *Source; /**< Source code string */ GLboolean CompileStatus; + GLboolean DeletePending; GLuint NumPrograms; /**< size of Programs[] array */ struct gl_program **Programs; /**< Post-compile assembly code */ + GLchar *InfoLog; }; @@ -2070,21 +2072,24 @@ struct gl_linked_program struct gl_program **Shaders; /**< List of the shaders */ struct gl_vertex_program *VertexProgram; /**< Linked vertex program */ struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */ - GLboolean LinkStatus; /**< GL_LINK_STATUS */ struct gl_program_parameter_list *Uniforms; /**< Plus constants, etc */ struct gl_program_parameter_list *Varying; + struct gl_program_parameter_list *Attributes; /**< Vertex attributes */ + GLboolean LinkStatus; /**< GL_LINK_STATUS */ + GLboolean Validated; + GLboolean DeletePending; + GLchar *InfoLog; }; /** - * Context state for vertex/fragment shaders. + * Context state for GLSL vertex/fragment shaders. */ -struct gl_shader_objects_state +struct gl_shader_state { - struct gl2_program_intf **CurrentProgram; GLboolean _VertexShaderPresent; GLboolean _FragmentShaderPresent; - struct gl_linked_program *Linked; /* XXX temporary here */ + struct gl_linked_program *CurrentProgram; }; @@ -2145,7 +2150,6 @@ struct gl_shared_state #endif #if FEATURE_ARB_shader_objects - struct _mesa_HashTable *GL2Objects; struct _mesa_HashTable *ShaderObjects; struct _mesa_HashTable *ProgramObjects; #endif @@ -2966,7 +2970,7 @@ struct __GLcontextRec struct gl_query_state Query; /**< GL_ARB_occlusion_query */ - struct gl_shader_objects_state ShaderObjects; /* GL_ARB_shader_objects */ + struct gl_shader_state Shader; /**< GLSL shader object state */ /*@}*/ #if FEATURE_EXT_framebuffer_object diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index e121f59258..1d8666888e 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -93,7 +93,7 @@ #include "texenvprogram.h" #endif #if FEATURE_ARB_shader_objects -#include "shaderobjects.h" +#include "shaders.h" #endif #include "debug.h" #include "dispatch.h" @@ -949,7 +949,7 @@ update_arrays( GLcontext *ctx ) static void update_program(GLcontext *ctx) { - const struct gl_linked_program *linked = ctx->ShaderObjects.Linked; + const struct gl_linked_program *linked = ctx->Shader.CurrentProgram; /* These _Enabled flags indicate if the program is enabled AND valid. */ diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index e379933a66..e089de9310 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -41,7 +41,7 @@ #include "texenvprogram.h" #include "mtypes.h" #include "math/m_xform.h" -#include "shaderobjects.h" +/*#include "shaderobjects.h"*/ diff --git a/src/mesa/sources b/src/mesa/sources index eed6fb0a0e..19f43384ea 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -48,6 +48,7 @@ MAIN_SOURCES = \ main/rastpos.c \ main/rbadaptors.c \ main/renderbuffer.c \ + main/shaders.c \ main/state.c \ main/stencil.c \ main/texcompress.c \ @@ -164,10 +165,6 @@ SHADER_SOURCES = \ shader/programopt.c \ shader/shader_api.c \ - -## shader/shaderobjects.c \ -## shader/shaderobjects_3dlabs.c - SLANG_SOURCES = \ shader/slang/slang_analyse.c \ shader/slang/slang_assemble.c \ diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 46f99ef6e0..749e278ffa 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -102,7 +102,7 @@ _swrast_update_rasterflags( GLcontext *ctx ) rasterMask |= FRAGPROG_BIT; } - if (ctx->ShaderObjects._FragmentShaderPresent) { + if (ctx->Shader._FragmentShaderPresent) { rasterMask |= FRAGPROG_BIT; } diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 7bfb23f0f7..536ac30033 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1365,7 +1365,7 @@ shade_texture_span(GLcontext *ctx, SWspan *span) if (span->interpMask & SPAN_Z) _swrast_span_interpolate_z (ctx, span); - if (ctx->ShaderObjects.Linked && span->interpMask & SPAN_VARYING) + if (ctx->Shader.CurrentProgram && span->interpMask & SPAN_VARYING) interpolate_varying(ctx, span); /* Run fragment program/shader now */ -- cgit v1.2.3 From 691ed5e54b0dc305c9a117a6a9804435041a86f0 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 13 Jan 2007 14:49:52 -0700 Subject: Rework code related to temp register allocation, both for user variables and expression temporarires. Much better register utilization now. Lots of other fixes. The OpenGL GLSL "orange book" brick shader demo works now. --- src/mesa/shader/slang/slang_codegen.c | 239 ++++++++++++++------------------- src/mesa/shader/slang/slang_compile.c | 56 +++++--- src/mesa/shader/slang/slang_emit.c | 206 ++++++++++++++-------------- src/mesa/shader/slang/slang_emit.h | 13 +- src/mesa/shader/slang/slang_ir.h | 1 + src/mesa/shader/slang/slang_link2.c | 2 + src/mesa/shader/slang/slang_print.c | 207 ++-------------------------- src/mesa/shader/slang/slang_print.h | 4 - src/mesa/shader/slang/slang_storage.c | 4 +- src/mesa/shader/slang/slang_vartable.c | 202 ++++++++++++++++++++++++++++ src/mesa/shader/slang/slang_vartable.h | 38 ++++++ src/mesa/sources | 1 + 12 files changed, 496 insertions(+), 477 deletions(-) create mode 100644 src/mesa/shader/slang/slang_vartable.c create mode 100644 src/mesa/shader/slang/slang_vartable.h (limited to 'src/mesa/sources') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 46a5ecd5d5..aff108dace 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -38,6 +38,7 @@ #include "slang_error.h" #include "slang_simplify.h" #include "slang_emit.h" +#include "slang_vartable.h" #include "slang_ir.h" #include "mtypes.h" #include "program.h" @@ -259,10 +260,10 @@ _slang_sizeof_type_specifier(const slang_type_specifier *spec) * 4. other? */ static void -slang_allocate_storage(slang_gen_context *gc, slang_ir_node *n, - struct gl_program *prog) +slang_allocate_storage(slang_assemble_ctx *A, slang_ir_node *n) { - assert(gc); + struct gl_program *prog = A->program; + assert(A->vartable); assert(n); assert(n->Opcode == IR_VAR_DECL || n->Opcode == IR_VAR); assert(prog); @@ -285,33 +286,22 @@ slang_allocate_storage(slang_gen_context *gc, slang_ir_node *n, /* variable declaration */ assert(n->Var); assert(!is_sampler_type(&n->Var->type)); - printf("Alloc storage for %p %s:\n", (void*) n->Var, (char*) n->Var->a_name); - /* - assert(n->Store->Index < 0); - */ n->Store->File = PROGRAM_TEMPORARY; n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier); assert(n->Store->Size > 0); - if (n->Store->Index < 0) - n->Store->Index = _slang_alloc_temporary(gc, n->Store->Size); - printf(" Location = %d\n", n->Store->Index); - /* - printf("alloc var %s storage at %d (size %d)\n", - (char *) n->Var->a_name, - n->Store->Index, - n->Store->Size); - */ - assert(n->Store->Size > 0); - n->Var->declared = GL_TRUE; return; } +#if 00 if (n->Store->File == PROGRAM_UNDEFINED) { printf("*** Var %s size %d\n", (char*) n->Var->a_name, n->Store->Size); - assert(n->Store->File != PROGRAM_UNDEFINED); } +#endif + /** + ** XXX this all has to be redone + **/ if (n->Store->Index < 0) { /* determine storage location for this var */ @@ -342,7 +332,6 @@ slang_allocate_storage(slang_gen_context *gc, slang_ir_node *n, } else { /* what's this??? */ - abort(); } } } @@ -533,54 +522,6 @@ static slang_asm_info AsmInfo[] = { }; -#if 000 /* prototype for future symbol table scheme */ - -#define MAX_DEPTH 100 -static slang_variable_scope *Stack[MAX_DEPTH]; -static int CurDepth; - -static void -_slang_push_scope(slang_variable_scope *scope) -{ - Stack[CurDepth++] = scope; - assert(CurDepth < MAX_DEPTH); -} - -static void -_slang_pop_scope(void) -{ - CurDepth--; - assert(CurDepth >= 0); -} - -static slang_variable_scope * -_slang_current_scope(void) -{ - if (CurDepth > 0) - return Stack[CurDepth - 1]; - else - return NULL; -} - -static slang_variable * -_slang_find_variable(slang_atom name) -{ - int i; - for (i = CurDepth - 1; i >= 0; i--) { - int j; - for (j = 0; j < Stack[i]->num_variables; j++) { - if (Stack[i]->variables[j].a_name == name) { - return Stack[i]->variables + j; - } - } - } - return NULL; -} - -#endif - - - /** * Recursively free an IR tree. */ @@ -675,15 +616,14 @@ new_var(slang_assemble_ctx *A, slang_operation *oper, printf("VAR NOT FOUND %s\n", (char *) name); assert(v); } - /** - assert(v->declared); - **/ assert(!oper->var || oper->var == v); v->used = GL_TRUE; - oper->var = v; + n->Swizzle = swizzle; n->Var = v; - slang_allocate_storage(A->codegen, n, A->program); + + slang_allocate_storage(A, n); + return n; } @@ -725,7 +665,7 @@ slang_is_writemask(const char *field, GLuint *mask) /** - * Check if the given function is really just a wrapper for an + * Check if the given function is really just a wrapper for a * basic assembly instruction. */ static GLboolean @@ -753,7 +693,7 @@ slang_inline_asm_function(slang_assemble_ctx *A, slang_operation *inlined = slang_operation_new(1); /*assert(oper->type == slang_oper_call); or vec4_add, etc */ - + printf("Inline asm %s\n", (char*) fun->header.a_name); inlined->type = fun->body->children[0].type; inlined->a_id = fun->body->children[0].a_id; inlined->num_children = numArgs; @@ -833,9 +773,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, for (i = 0; i < substCount; i++) { if (v == substOld[i]) { /* OK, replace this slang_oper_identifier with a new expr */ - assert(substNew[i]->type == slang_oper_identifier || - substNew[i]->type == slang_oper_literal_float); -#if 1 /* DEBUG only */ +#if 0 /* DEBUG only */ if (substNew[i]->type == slang_oper_identifier) { assert(substNew[i]->var); assert(substNew[i]->var->a_name); @@ -843,7 +781,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, (char*)v->a_name, (char*) substNew[i]->var->a_name, (void*) oper); } - else + else { printf("Substitute %s with %f in id node %p\n", (char*)v->a_name, substNew[i]->literal[0], (void*) oper); @@ -958,15 +896,15 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, substNew = (slang_operation **) _mesa_calloc(totalArgs * sizeof(slang_operation *)); - printf("\nInline call to %s (total vars=%d nparams=%d)\n", + printf("Inline call to %s (total vars=%d nparams=%d)\n", (char *) fun->header.a_name, fun->parameters->num_variables, numArgs); - if (haveRetValue && !returnOper) { - /* Create comma sequence for inlined code, the left child will be the - * function body and the right child will be a variable (__retVal) - * that will get the return value. + /* Create 3-child comma sequence for inlined code: + * child[0]: declare __resultTmp + * child[1]: inlined function body + * child[2]: __resultTmp */ slang_operation *commaSeq; slang_operation *declOper = NULL; @@ -981,13 +919,13 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* allocate the return var */ resultVar = slang_variable_scope_grow(commaSeq->locals); /* - printf("Alloc __resultTemp in scope %p for retval of calling %s\n", + printf("Alloc __resultTmp in scope %p for retval of calling %s\n", (void*)commaSeq->locals, (char *) fun->header.a_name); */ resultVar->a_name = slang_atom_pool_atom(A->atoms, "__resultTmp"); resultVar->type = fun->header.type; /* XXX copy? */ - /*resultVar->type.qualifier = slang_qual_out;*/ + resultVar->isTemp = GL_TRUE; /* child[0] = __resultTmp declaration */ declOper = &commaSeq->children[0]; @@ -1027,12 +965,12 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, */ substCount = 0; for (i = 0; i < totalArgs; i++) { - slang_variable *p = &fun->parameters->variables[i]; - + slang_variable *p = fun->parameters->variables[i]; + /* printf("Param %d: %s %s \n", i, slang_type_qual_string(p->type.qualifier), (char *) p->a_name); - + */ if (p->type.qualifier == slang_qual_inout || p->type.qualifier == slang_qual_out) { /* an output param */ @@ -1042,9 +980,10 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, else arg = returnOper; paramMode[i] = SUBST; - assert(arg->type == slang_oper_identifier - /*||arg->type == slang_oper_variable_decl*/); - slang_resolve_variable(arg); + + if (arg->type == slang_oper_identifier) + slang_resolve_variable(arg); + /* replace parameter 'p' with argument 'arg' */ substOld[substCount] = p; substNew[substCount] = arg; /* will get copied */ @@ -1073,15 +1012,14 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, assert(paramMode[i]); } -#if 00 - printf("ABOUT to inline body %p with checksum %d\n", - (char *) fun->body, slang_checksum_tree(fun->body)); -#endif - /* actual code inlining: */ slang_operation_copy(inlined, fun->body); -#if 000 + /*** XXX review this */ + assert(inlined->type = slang_oper_block_no_new_scope); + inlined->type = slang_oper_block_new_scope; + +#if 0 printf("======================= orig body code ======================\n"); printf("=== params scope = %p\n", (void*) fun->parameters); slang_print_tree(fun->body, 8); @@ -1092,7 +1030,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* do parameter substitution in inlined code: */ slang_substitute(A, inlined, substCount, substOld, substNew, GL_FALSE); -#if 000 +#if 0 printf("======================= subst code ==========================\n"); slang_print_tree(inlined, 8); printf("=============================================================\n"); @@ -1104,7 +1042,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, numCopyIn = 0; for (i = 0; i < numArgs; i++) { if (paramMode[i] == COPY_IN) { - slang_variable *p = &fun->parameters->variables[i]; + slang_variable *p = fun->parameters->variables[i]; /* declare parameter 'p' */ slang_operation *decl = slang_operation_insert(&inlined->num_children, &inlined->children, @@ -1138,7 +1076,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, for (i = 0; i < totalArgs; i++) { if (paramMode[i] == COPY_OUT) { - const slang_variable *p = &fun->parameters->variables[i]; + const slang_variable *p = fun->parameters->variables[i]; /* actualCallVar = outParam */ /*if (i > 0 || !haveRetValue)*/ slang_operation *ass = slang_operation_insert(&inlined->num_children, @@ -1215,7 +1153,6 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, printf("\n"); #endif - /* assemble what we just made XXX here??? */ n = _slang_gen_operation(A, oper); CurFunction->end_label = NULL; @@ -1323,7 +1260,6 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, dest_oper = &dest_oper->children[0]; } - assert(dest_oper->type == slang_oper_identifier); n0 = _slang_gen_operation(A, dest_oper); assert(n0->Var); assert(n0->Store); @@ -1676,9 +1612,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) return NULL; varDecl->Var = v; - v->declared = GL_TRUE; - slang_allocate_storage(A->codegen, varDecl, A->program); + slang_allocate_storage(A, varDecl); if (oper->num_children > 0) { /* child is initializer */ @@ -1728,7 +1663,9 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) */ slang_atom aVar = oper->var ? oper->var->a_name : oper->a_id; slang_ir_node *n = new_var(A, oper, aVar, SWIZZLE_NOOP); + /* assert(oper->var); + */ return n; } @@ -1856,7 +1793,7 @@ _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) /* new storage info since we don't want to change the original */ base->Store = _slang_clone_ir_storage(base->Store); if (_slang_type_is_vector(array_ti.spec.type)) { - /* scalar element (float) of a basic vector (vec3) */ + /* scalar element (float) of a basic vector (ex: vec3) */ const GLuint max = _slang_type_dim(array_ti.spec.type); if (index >= max) { RETURN_ERROR("array index out of bounds", 0); @@ -1888,39 +1825,60 @@ static slang_ir_node * _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) { switch (oper->type) { - case slang_oper_block_no_new_scope: case slang_oper_block_new_scope: + { + slang_ir_node *n; + + A->vartable = _slang_push_var_table(A->vartable); + + oper->type = slang_oper_block_no_new_scope; /* temp change */ + n = _slang_gen_operation(A, oper); + oper->type = slang_oper_block_new_scope; /* restore */ + + A->vartable = _slang_pop_var_table(A->vartable); + + if (n) + n = new_node(IR_SCOPE, n, NULL); + return n; + } + break; + + case slang_oper_block_no_new_scope: /* list of operations */ assert(oper->num_children > 0); { slang_ir_node *n, *tree = NULL; GLuint i; + for (i = 0; i < oper->num_children; i++) { n = _slang_gen_operation(A, &oper->children[i]); - if (!n) + if (!n) { + _slang_free_ir_tree(tree); return NULL; /* error must have occured */ + } tree = tree ? new_seq(tree, n) : n; } - if (oper->locals->num_variables > 0) { - int i; - /* - printf("\n****** Deallocate vars in scope!\n"); - */ - for (i = 0; i < oper->locals->num_variables; i++) { - slang_variable *v = oper->locals->variables + i; - if (v->aux) { - slang_ir_storage *store = (slang_ir_storage *) v->aux; - /* - printf(" Deallocate var %s\n", (char*) v->a_name); - */ - assert(store->File == PROGRAM_TEMPORARY); - assert(store->Index >= 0); - _slang_free_temporary(A->codegen, store->Index, store->Size); +#if 00 + if (oper->locals->num_variables > 0) { + int i; + /* + printf("\n****** Deallocate vars in scope!\n"); + */ + for (i = 0; i < oper->locals->num_variables; i++) { + slang_variable *v = oper->locals->variables + i; + if (v->aux) { + slang_ir_storage *store = (slang_ir_storage *) v->aux; + /* + printf(" Deallocate var %s\n", (char*) v->a_name); + */ + assert(store->File == PROGRAM_TEMPORARY); + assert(store->Index >= 0); + _slang_free_temp(A->vartable, store->Index, store->Size); + } } } - } - +#endif return tree; } break; @@ -2022,12 +1980,10 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return _slang_gen_assignment(A, oper); case slang_oper_addassign: { + /* XXX this is broken */ slang_ir_node *n; assert(oper->num_children == 2); - n = _slang_gen_function_call_name(A, "+=", oper, NULL); - /* The result of this operation should be stored back into child[0] */ - assert(n->Children[0]->Store); - n->Store = n->Children[0]->Store; + n = _slang_gen_function_call_name(A, "+=", oper, &oper->children[0]); return n; } case slang_oper_subassign: @@ -2171,9 +2127,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, /* We know it's a uniform, but don't allocate storage unless * it's really used. */ - store = _slang_new_ir_storage(PROGRAM_STATE_VAR, -1, size); - } if (dbg) printf("UNIFORM "); } @@ -2260,10 +2214,12 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, if (!n) return GL_FALSE; n->Var = var; - var->declared = GL_TRUE; store = _slang_new_ir_storage(PROGRAM_TEMPORARY, index, size); var->aux = store; /* save var's storage info */ - slang_allocate_storage(A->codegen, n, A->program); + + slang_allocate_storage(A, n); + + _slang_add_variable(A->vartable, var); /* IR code for the var's initializer, if present */ if (var->initializer) { @@ -2284,7 +2240,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, n = new_seq(n, init); } - success = _slang_emit_code(n, A->codegen, A->program, GL_FALSE); + success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE); _slang_free_ir_tree(n); } @@ -2328,8 +2284,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) assert(A->program->Parameters ); assert(A->program->Varying); - assert(A->codegen); - /* A->codegen = _slang_new_codegen_context();*/ + assert(A->vartable); /* fold constant expressions, etc. */ slang_simplify(fun->body, &A->space, A->atoms); @@ -2340,8 +2295,16 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) if (!CurFunction->end_label) CurFunction->end_label = slang_atom_pool_gen(A->atoms, "__endOfFunc_main_"); + /* push new vartable scope */ + A->vartable = _slang_push_var_table(A->vartable); + /* Generate IR tree for the function body code */ n = _slang_gen_operation(A, fun->body); + if (n) + n = new_node(IR_SCOPE, n, NULL); + + /* pop vartable, restore previous */ + A->vartable = _slang_pop_var_table(A->vartable); if (!n) { /* XXX record error */ @@ -2361,11 +2324,13 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #if 0 printf("************* IR for %s *******\n", (char*)fun->header.a_name); slang_print_ir(n, 0); +#endif +#if 1 printf("************* End codegen function ************\n\n"); #endif /* Emit program instructions */ - success = _slang_emit_code(n, A->codegen, A->program, GL_TRUE); + success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE); _slang_free_ir_tree(n); /* free codegen context */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 9a77c5a3d6..c459eb29e7 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -39,6 +39,7 @@ #include "slang_storage.h" #include "slang_error.h" #include "slang_emit.h" +#include "slang_vartable.h" #include "slang_print.h" @@ -98,7 +99,9 @@ _slang_code_object_ctr(slang_code_object * self) for (i = 0; i < SLANG_BUILTIN_TOTAL; i++) _slang_code_unit_ctr(&self->builtin[i], self); _slang_code_unit_ctr(&self->unit, self); +#if 01 _slang_assembly_file_ctr(&self->assembly); +#endif slang_machine_ctr(&self->machine); self->varpool.next_addr = 0; slang_atom_pool_construct(&self->atompool); @@ -116,7 +119,9 @@ _slang_code_object_dtr(slang_code_object * self) for (i = 0; i < SLANG_BUILTIN_TOTAL; i++) _slang_code_unit_dtr(&self->builtin[i]); _slang_code_unit_dtr(&self->unit); +#if 01 slang_assembly_file_destruct(&self->assembly); +#endif slang_machine_dtr(&self->machine); slang_atom_pool_destruct(&self->atompool); slang_export_data_table_dtr(&self->expdata); @@ -248,7 +253,7 @@ typedef struct slang_output_ctx_ slang_var_pool *global_pool; slang_machine *machine; struct gl_program *program; - slang_gen_context *codegen; + slang_var_table *vartable; } slang_output_ctx; /* _slang_compile() */ @@ -868,7 +873,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, slang_operation *o = &oper->children[i - first_var]; o->type = slang_oper_variable_decl; o->locals->outer_scope = O->vars; - o->a_id = O->vars->variables[i].a_name; + o->a_id = O->vars->variables[i]->a_name; } } } @@ -879,9 +884,6 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, */ oper->type = slang_oper_asm; oper->a_id = parse_identifier(C); - if (strcmp((char*)oper->a_id, "dot") == 0) { - printf("Assemble dot! **************************\n"); - } if (oper->a_id == SLANG_ATOM_NULL) return 0; while (*C->I != OP_END) { @@ -1547,15 +1549,19 @@ parse_function_definition(slang_parse_ctx * C, slang_output_ctx * O, static GLboolean initialize_global(slang_assemble_ctx * A, slang_variable * var) { +#if 01 slang_assembly_file_restore_point point; +#endif slang_machine mach; slang_assembly_local_info save_local = A->local; slang_operation op_id, op_assign; GLboolean result; +#if 01 /* save the current assembly */ if (!slang_assembly_file_restore_point_save(A->file, &point)) return GL_FALSE; +#endif /* setup the machine */ mach = *A->mach; @@ -1578,13 +1584,13 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) /* put the variable into operation's scope */ op_id.locals->variables = - (slang_variable *) slang_alloc_malloc(sizeof(slang_variable)); + (slang_variable **) slang_alloc_malloc(sizeof(slang_variable *)); if (op_id.locals->variables == NULL) { slang_operation_destruct(&op_id); return GL_FALSE; } op_id.locals->num_variables = 1; - op_id.locals->variables[0] = *var; + op_id.locals->variables[0] = var; /* construct the assignment expression */ if (!slang_operation_construct(&op_assign)) { @@ -1605,8 +1611,12 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) op_assign.children[0] = op_id; op_assign.children[1] = *var->initializer; +#if 0 /* this should go away */ /* insert the actual expression */ result = _slang_assemble_operation(A, &op_assign, slang_ref_forbid); +#else + result = 1; +#endif /* carefully destroy the operations */ op_assign.num_children = 0; @@ -1627,9 +1637,11 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) return GL_FALSE; #endif +#if 01 /* restore the old assembly */ if (!slang_assembly_file_restore_point_load(A->file, &point)) return GL_FALSE; +#endif A->local = save_local; /* now we copy the contents of the initialized variable back to the original machine */ @@ -1732,8 +1744,11 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, A.space.funcs = O->funs; A.space.structs = O->structs; A.space.vars = O->vars; - A.codegen = O->codegen; A.program = O->program; +#if 0 + A.codegen = O->codegen; +#endif + A.vartable = O->vartable; _slang_codegen_global_variable(&A, var, C->type); } @@ -1896,7 +1911,10 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, A.space.structs = O->structs; A.space.vars = O->vars; A.program = O->program; +#if 0 A.codegen = O->codegen; +#endif + A.vartable = O->vartable; _slang_reset_error(); @@ -1906,14 +1924,14 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, (*parsed_func_ret)->param_count); #endif - +#if 0 if (!_slang_assemble_function(&A, *parsed_func_ret)) { /* propogate the error message back through the info log */ C->L->text = _mesa_strdup(_slang_error_text()); C->L->dont_free_text = GL_FALSE; return GL_FALSE; } - +#endif #if 0 printf("**************************************\n"); @@ -1961,6 +1979,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, struct gl_program *program) { slang_output_ctx o; + GLboolean success; /* setup output context */ o.funs = &unit->funs; @@ -1970,7 +1989,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, o.global_pool = &unit->object->varpool; o.machine = &unit->object->machine; o.program = program; - o.codegen = _slang_new_codegen_context(); + o.vartable = _slang_push_var_table(NULL); /* parse individual functions and declarations */ while (*C->I != EXTERNAL_NULL) { @@ -1978,20 +1997,25 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, case EXTERNAL_FUNCTION_DEFINITION: { slang_function *func; - - if (!parse_function(C, &o, 1, &func)) - return GL_FALSE; + success = parse_function(C, &o, 1, &func); } break; case EXTERNAL_DECLARATION: - if (!parse_declaration(C, &o)) - return GL_FALSE; + success = parse_declaration(C, &o); break; default: + success = GL_FALSE; + } + + if (!success) { + /* xxx free codegen */ + _slang_pop_var_table(o.vartable); return GL_FALSE; } } C->I++; + + _slang_pop_var_table(o.vartable); return GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 2670134025..81f8565502 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -34,6 +34,7 @@ #include "program.h" #include "prog_instruction.h" #include "prog_parameter.h" +#include "prog_print.h" #include "slang_emit.h" @@ -83,6 +84,7 @@ static slang_ir_info IrInfo[] = { { IR_COS, "IR_COS", OPCODE_COS, 1, 1 }, /* other */ { IR_SEQ, "IR_SEQ", 0, 0, 0 }, + { IR_SCOPE, "IR_SCOPE", 0, 0, 0 }, { IR_LABEL, "IR_LABEL", 0, 0, 0 }, { IR_JUMP, "IR_JUMP", 0, 0, 0 }, { IR_CJUMP, "IR_CJUMP", 0, 0, 0 }, @@ -227,6 +229,11 @@ slang_print_ir(const slang_ir_node *n, int indent) slang_print_ir(n->Children[0], indent + IND); slang_print_ir(n->Children[1], indent + IND); break; + case IR_SCOPE: + printf("NEW SCOPE\n"); + assert(!n->Children[1]); + slang_print_ir(n->Children[0], indent + 3); + break; case IR_MOVE: printf("MOVE (writemask = %s)\n", writemask_string(n->Writemask)); slang_print_ir(n->Children[0], indent+3); @@ -279,71 +286,36 @@ slang_print_ir(const slang_ir_node *n, int indent) } -GLint -_slang_alloc_temporary(slang_gen_context *gc, GLint size) -{ - const GLuint sz4 = (size + 3) / 4; - GLuint i, j; - ASSERT(size > 0); /* number of floats */ - - for (i = 0; i < MAX_PROGRAM_TEMPS; i++) { - GLuint found = 0; - for (j = 0; j < sz4; j++) { - if (!gc->TempUsed[i + j]) { - found++; - } - } - if (found == sz4) { - /* found block of size/4 free regs */ - for (j = 0; j < sz4; j++) - gc->TempUsed[i + j] = GL_TRUE; - return i; - } - } - return -1; -} - - - -static GLboolean -is_temporary(const slang_gen_context *gc, const slang_ir_storage *st) -{ - if (st->File == PROGRAM_TEMPORARY && gc->TempUsed[st->Index]) - return gc->TempUsed[st->Index]; - else - return GL_FALSE; -} - - -void -_slang_free_temporary(slang_gen_context *gc, GLuint r, GLint size) -{ - const GLuint sz4 = (size + 3) / 4; - GLuint i; - for (i = 0; i < sz4; i++) { - if (gc->TempUsed[r + i]) - gc->TempUsed[r + i] = GL_FALSE; - } -} - - /** * Allocate temporary storage for an intermediate result (such as for * a multiply or add, etc. */ static void -slang_alloc_temp_storage(slang_gen_context *gc, slang_ir_node *n, GLint size) +alloc_temp_storage(slang_var_table *vt, slang_ir_node *n, GLint size) { GLint indx; assert(!n->Var); assert(!n->Store); assert(size > 0); - printf("Allocate binop temp:\n"); - indx = _slang_alloc_temporary(gc, size); + indx = _slang_alloc_temp(vt, size); n->Store = _slang_new_ir_storage(PROGRAM_TEMPORARY, indx, size); } +static void +free_temp_storage(slang_var_table *vt, slang_ir_node *n) +{ + if (n->Store->File == PROGRAM_TEMPORARY && n->Store->Index >= 0) { + if (_slang_is_temp(vt, n->Store->Index)) { + _slang_free_temp(vt, n->Store->Index, n->Store->Size); + /* XXX free(store)? */ + n->Store->Index = -1; + n->Store->Size = -1; + } + } +} + + static slang_ir_storage * alloc_constant(const GLfloat v[], GLuint size, struct gl_program *prog) { @@ -445,14 +417,14 @@ new_instruction(struct gl_program *prog, gl_inst_opcode opcode) static struct prog_instruction * -emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog); +emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog); /** * Generate code for a simple binary-op instruction. */ static struct prog_instruction * -emit_binop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) +emit_binop(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) { struct prog_instruction *inst; const slang_ir_info *info = slang_find_ir_info(n->Opcode); @@ -460,25 +432,32 @@ emit_binop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) assert(info->InstOpcode != OPCODE_NOP); - emit(gc, n->Children[0], prog); - emit(gc, n->Children[1], prog); + /* gen code for children */ + emit(vt, n->Children[0], prog); + emit(vt, n->Children[1], prog); + + /* gen this instruction */ inst = new_instruction(prog, info->InstOpcode); - /* alloc temp storage for the result: */ - if (!n->Store || n->Store->File == PROGRAM_UNDEFINED) { - slang_alloc_temp_storage(gc, n, info->ResultSize); - } - storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store, n->Children[0]->Swizzle); storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Store, n->Children[1]->Swizzle); + free_temp_storage(vt, n->Children[0]); + free_temp_storage(vt, n->Children[1]); + + if (!n->Store) { + alloc_temp_storage(vt, n, info->ResultSize); + } + storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); + inst->Comment = n->Comment; + /*_mesa_print_instruction(inst);*/ return inst; } static struct prog_instruction * -emit_unop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) +emit_unop(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) { struct prog_instruction *inst; const slang_ir_info *info = slang_find_ir_info(n->Opcode); @@ -486,26 +465,28 @@ emit_unop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) assert(info->NumParams == 1); - emit(gc, n->Children[0], prog); + /* gen code for child */ + emit(vt, n->Children[0], prog); + /* gen this instruction */ inst = new_instruction(prog, info->InstOpcode); - - if (!n->Store) - slang_alloc_temp_storage(gc, n, info->ResultSize); - - storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); - storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store, n->Children[0]->Swizzle); + free_temp_storage(vt, n->Children[0]); - inst->Comment = n->Comment; + if (!n->Store) { + alloc_temp_storage(vt, n, info->ResultSize); + } + storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); + inst->Comment = n->Comment; + /*_mesa_print_instruction(inst);*/ return inst; } static struct prog_instruction * -emit_negation(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) +emit_negation(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) { /* Implement as MOV dst, -src; */ /* XXX we could look at the previous instruction and in some circumstances @@ -513,10 +494,10 @@ emit_negation(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) */ struct prog_instruction *inst; - emit(gc, n->Children[0], prog); + emit(vt, n->Children[0], prog); if (!n->Store) - slang_alloc_temp_storage(gc, n, n->Children[0]->Store->Size); + alloc_temp_storage(vt, n, n->Children[0]->Store->Size); inst = new_instruction(prog, OPCODE_MOV); storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); @@ -563,7 +544,7 @@ emit_jump(const char *target, struct gl_program *prog) static struct prog_instruction * -emit_tex(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) +emit_tex(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) { struct prog_instruction *inst; if (n->Opcode == IR_TEX) { @@ -578,7 +559,7 @@ emit_tex(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) } if (!n->Store) - slang_alloc_temp_storage(gc, n, 4); + alloc_temp_storage(vt, n, 4); storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); @@ -600,7 +581,7 @@ emit_tex(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) static struct prog_instruction * -emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) +emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) { struct prog_instruction *inst; if (!n) @@ -610,34 +591,54 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) case IR_SEQ: assert(n->Children[0]); assert(n->Children[1]); - emit(gc, n->Children[0], prog); - inst = emit(gc, n->Children[1], prog); + emit(vt, n->Children[0], prog); + inst = emit(vt, n->Children[1], prog); n->Store = n->Children[1]->Store; return inst; - break; + + case IR_SCOPE: + /* new variable scope */ + vt = _slang_push_var_table(vt); + inst = emit(vt, n->Children[0], prog); + vt = _slang_pop_var_table(vt); + return inst; + case IR_VAR_DECL: + /* Variable declaration - allocate a register for it */ + assert(n->Store); + assert(n->Store->File != PROGRAM_UNDEFINED); + assert(n->Store->Size > 0); + if (n->Var->isTemp) + n->Store->Index = _slang_alloc_temp(vt, n->Store->Size); + else + n->Store->Index = _slang_alloc_var(vt, n->Store->Size); + break; + case IR_VAR: - /* Storage should have already been resolved/allocated */ + /* Reference to a variable + * Storage should have already been resolved/allocated. + */ assert(n->Store); assert(n->Store->File != PROGRAM_UNDEFINED); assert(n->Store->Index >= 0); assert(n->Store->Size > 0); break; + case IR_MOVE: /* rhs */ assert(n->Children[1]); - inst = emit(gc, n->Children[1], prog); + inst = emit(vt, n->Children[1], prog); /* lhs */ - emit(gc, n->Children[0], prog); + emit(vt, n->Children[0], prog); #if 1 - if (inst && is_temporary(gc, n->Children[1]->Store)) { + if (inst && _slang_is_temp(vt, n->Children[1]->Store->Index)) { /* Peephole optimization: * Just modify the RHS to put its result into the dest of this * MOVE operation. Then, this MOVE is a no-op. */ - _slang_free_temporary(gc, n->Children[1]->Store->Index, - n->Children[1]->Store->Size); + _slang_free_temp(vt, n->Children[1]->Store->Index, + n->Children[1]->Store->Size); *n->Children[1]->Store = *n->Children[0]->Store; /* fixup the prev (RHS) instruction */ storage_to_dst_reg(&inst->DstReg, n->Children[0]->Store, n->Writemask); @@ -673,9 +674,9 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) n->Children[1]->Swizzle); } /* XXX is this test correct? */ - if (n->Children[1]->Store->File == PROGRAM_TEMPORARY) { - _slang_free_temporary(gc, n->Children[1]->Store->Index, - n->Children[1]->Store->Size); + if (_slang_is_temp(vt, n->Children[1]->Store->Index)) { + _slang_free_temp(vt, n->Children[1]->Store->Index, + n->Children[1]->Store->Size); } /*inst->Comment = _mesa_strdup("IR_MOVE");*/ n->Store = n->Children[0]->Store; /*XXX new */ @@ -697,7 +698,7 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) case IR_POW: case IR_EXP: case IR_EXP2: - return emit_binop(gc, n, prog); + return emit_binop(vt, n, prog); case IR_RSQ: case IR_RCP: case IR_FLOOR: @@ -707,13 +708,13 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) case IR_COS: case IR_DDX: case IR_DDY: - return emit_unop(gc, n, prog); + return emit_unop(vt, n, prog); case IR_TEX: case IR_TEXB: case IR_TEXP: - return emit_tex(gc, n, prog); + return emit_tex(vt, n, prog); case IR_NEG: - return emit_negation(gc, n, prog); + return emit_negation(vt, n, prog); case IR_LABEL: return emit_label(n->Target, prog); case IR_FLOAT: @@ -726,7 +727,7 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) * Next instruction is typically an IR_CJUMP. */ /* last child expr instruction: */ - struct prog_instruction *inst = emit(gc, n->Children[0], prog); + struct prog_instruction *inst = emit(vt, n->Children[0], prog); if (inst) { /* set inst's CondUpdate flag */ inst->CondUpdate = GL_TRUE; @@ -737,13 +738,13 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) * is normally generated for the expression "i". * Generate a move instruction just to set condition codes. */ - slang_alloc_temp_storage(gc, n, 1); + alloc_temp_storage(vt, n, 1); inst = new_instruction(prog, OPCODE_MOV); inst->CondUpdate = GL_TRUE; storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store, n->Children[0]->Swizzle); - _slang_free_temporary(gc, n->Store->Index, n->Store->Size); + _slang_free_temp(vt, n->Store->Index, n->Store->Size); return inst; /* XXX or null? */ } } @@ -760,23 +761,14 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) } -slang_gen_context * -_slang_new_codegen_context(void) -{ - slang_gen_context *gc = (slang_gen_context *) _mesa_calloc(sizeof(*gc)); - return gc; -} - - - GLboolean -_slang_emit_code(slang_ir_node *n, slang_gen_context *gc, +_slang_emit_code(slang_ir_node *n, slang_var_table *vt, struct gl_program *prog, GLboolean withEnd) { GLboolean success; - if (emit(gc, n, prog)) { - /* finish up by addeing the END opcode to program */ + if (emit(vt, n, prog)) { + /* finish up by adding the END opcode to program */ if (withEnd) { struct prog_instruction *inst; inst = new_instruction(prog, OPCODE_END); @@ -788,8 +780,8 @@ _slang_emit_code(slang_ir_node *n, slang_gen_context *gc, success = GL_FALSE; } -#if 0 printf("*********** End generate code (%u inst):\n", prog->NumInstructions); +#if 0 _mesa_print_program(prog); _mesa_print_program_parameters(ctx,prog); #endif diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h index 73ae0827c0..7a845feac2 100644 --- a/src/mesa/shader/slang/slang_emit.h +++ b/src/mesa/shader/slang/slang_emit.h @@ -32,10 +32,6 @@ #include "mtypes.h" -extern slang_gen_context * -_slang_new_codegen_context(void); - - extern void slang_print_ir(const slang_ir_node *n, int indent); @@ -48,15 +44,8 @@ extern slang_ir_storage * _slang_clone_ir_storage(slang_ir_storage *store); -extern GLint -_slang_alloc_temporary(slang_gen_context *gc, GLint size); - -extern void -_slang_free_temporary(slang_gen_context *gc, GLuint r, GLint size); - - extern GLboolean -_slang_emit_code(slang_ir_node *n, slang_gen_context *gc, +_slang_emit_code(slang_ir_node *n, slang_var_table *vartable, struct gl_program *prog, GLboolean withEnd); diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h index b106e85dbb..baf1137e73 100644 --- a/src/mesa/shader/slang/slang_ir.h +++ b/src/mesa/shader/slang/slang_ir.h @@ -45,6 +45,7 @@ typedef enum { IR_NOP = 0, IR_SEQ, /* sequence (eval left, then right) */ + IR_SCOPE, /* new variable scope (one child) */ IR_LABEL, /* target of a jump or cjump */ IR_JUMP, /* unconditional jump */ IR_CJUMP, /* conditional jump */ diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c index 7dfdd288e1..3ea7954451 100644 --- a/src/mesa/shader/slang/slang_link2.c +++ b/src/mesa/shader/slang/slang_link2.c @@ -259,8 +259,10 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) if (inst->Opcode == OPCODE_TEX || inst->Opcode == OPCODE_TXB || inst->Opcode == OPCODE_TXP) { + /* printf("====== remap sampler from %d to %d\n", inst->Sampler, map[ inst->Sampler ]); + */ inst->Sampler = map[ inst->Sampler ]; } } diff --git a/src/mesa/shader/slang/slang_print.c b/src/mesa/shader/slang/slang_print.c index 020f30a940..07509cddbc 100644 --- a/src/mesa/shader/slang/slang_print.c +++ b/src/mesa/shader/slang/slang_print.c @@ -188,7 +188,7 @@ find_scope(const slang_variable_scope *s, slang_atom name) { GLuint i; for (i = 0; i < s->num_variables; i++) { - if (s->variables[i].a_name == name) + if (s->variables[i]->a_name == name) return s; } if (s->outer_scope) @@ -202,8 +202,8 @@ find_var(const slang_variable_scope *s, slang_atom name) { GLuint i; for (i = 0; i < s->num_variables; i++) { - if (s->variables[i].a_name == name) - return &s->variables[i]; + if (s->variables[i]->a_name == name) + return s->variables[i]; } if (s->outer_scope) return find_var(s->outer_scope, name); @@ -621,7 +621,7 @@ slang_print_function(const slang_function *f, GLboolean body) (char *) f->header.a_name); for (i = 0; i < f->param_count; i++) { - print_variable(&f->parameters->variables[i], 3); + print_variable(f->parameters->variables[i], 3); } printf(")\n"); @@ -632,199 +632,6 @@ slang_print_function(const slang_function *f, GLboolean body) -/* operation */ -#define OP_END 0 -#define OP_BLOCK_BEGIN_NO_NEW_SCOPE 1 -#define OP_BLOCK_BEGIN_NEW_SCOPE 2 -#define OP_DECLARE 3 -#define OP_ASM 4 -#define OP_BREAK 5 -#define OP_CONTINUE 6 -#define OP_DISCARD 7 -#define OP_RETURN 8 -#define OP_EXPRESSION 9 -#define OP_IF 10 -#define OP_WHILE 11 -#define OP_DO 12 -#define OP_FOR 13 -#define OP_PUSH_VOID 14 -#define OP_PUSH_BOOL 15 -#define OP_PUSH_INT 16 -#define OP_PUSH_FLOAT 17 -#define OP_PUSH_IDENTIFIER 18 -#define OP_SEQUENCE 19 -#define OP_ASSIGN 20 -#define OP_ADDASSIGN 21 -#define OP_SUBASSIGN 22 -#define OP_MULASSIGN 23 -#define OP_DIVASSIGN 24 -/*#define OP_MODASSIGN 25*/ -/*#define OP_LSHASSIGN 26*/ -/*#define OP_RSHASSIGN 27*/ -/*#define OP_ORASSIGN 28*/ -/*#define OP_XORASSIGN 29*/ -/*#define OP_ANDASSIGN 30*/ -#define OP_SELECT 31 -#define OP_LOGICALOR 32 -#define OP_LOGICALXOR 33 -#define OP_LOGICALAND 34 -/*#define OP_BITOR 35*/ -/*#define OP_BITXOR 36*/ -/*#define OP_BITAND 37*/ -#define OP_EQUAL 38 -#define OP_NOTEQUAL 39 -#define OP_LESS 40 -#define OP_GREATER 41 -#define OP_LESSEQUAL 42 -#define OP_GREATEREQUAL 43 -/*#define OP_LSHIFT 44*/ -/*#define OP_RSHIFT 45*/ -#define OP_ADD 46 -#define OP_SUBTRACT 47 -#define OP_MULTIPLY 48 -#define OP_DIVIDE 49 -/*#define OP_MODULUS 50*/ -#define OP_PREINCREMENT 51 -#define OP_PREDECREMENT 52 -#define OP_PLUS 53 -#define OP_MINUS 54 -/*#define OP_COMPLEMENT 55*/ -#define OP_NOT 56 -#define OP_SUBSCRIPT 57 -#define OP_CALL 58 -#define OP_FIELD 59 -#define OP_POSTINCREMENT 60 -#define OP_POSTDECREMENT 61 - - -void -slang_print_opcode(unsigned int opcode) -{ - switch (opcode) { - case OP_PUSH_VOID: - printf("OP_PUSH_VOID\n"); - break; - case OP_PUSH_BOOL: - printf("OP_PUSH_BOOL\n"); - break; - case OP_PUSH_INT: - printf("OP_PUSH_INT\n"); - break; - case OP_PUSH_FLOAT: - printf("OP_PUSH_FLOAT\n"); - break; - case OP_PUSH_IDENTIFIER: - printf("OP_PUSH_IDENTIFIER\n"); - break; - case OP_SEQUENCE: - printf("OP_SEQUENCE\n"); - break; - case OP_ASSIGN: - printf("OP_ASSIGN\n"); - break; - case OP_ADDASSIGN: - printf("OP_ADDASSIGN\n"); - break; - case OP_SUBASSIGN: - printf("OP_SUBASSIGN\n"); - break; - case OP_MULASSIGN: - printf("OP_MULASSIGN\n"); - break; - case OP_DIVASSIGN: - printf("OP_DIVASSIGN\n"); - break; - /*case OP_MODASSIGN:*/ - /*case OP_LSHASSIGN:*/ - /*case OP_RSHASSIGN:*/ - /*case OP_ORASSIGN:*/ - /*case OP_XORASSIGN:*/ - /*case OP_ANDASSIGN:*/ - case OP_SELECT: - printf("OP_SELECT\n"); - break; - case OP_LOGICALOR: - printf("OP_LOGICALOR\n"); - break; - case OP_LOGICALXOR: - printf("OP_LOGICALXOR\n"); - break; - case OP_LOGICALAND: - printf("OP_LOGICALAND\n"); - break; - /*case OP_BITOR:*/ - /*case OP_BITXOR:*/ - /*case OP_BITAND:*/ - case OP_EQUAL: - printf("OP_EQUAL\n"); - break; - case OP_NOTEQUAL: - printf("OP_NOTEQUAL\n"); - break; - case OP_LESS: - printf("OP_LESS\n"); - break; - case OP_GREATER: - printf("OP_GREATER\n"); - break; - case OP_LESSEQUAL: - printf("OP_LESSEQUAL\n"); - break; - case OP_GREATEREQUAL: - printf("OP_GREATEREQUAL\n"); - break; - /*case OP_LSHIFT:*/ - /*case OP_RSHIFT:*/ - case OP_ADD: - printf("OP_ADD\n"); - break; - case OP_SUBTRACT: - printf("OP_SUBTRACT\n"); - break; - case OP_MULTIPLY: - printf("OP_MULTIPLY\n"); - break; - case OP_DIVIDE: - printf("OP_DIVIDE\n"); - break; - /*case OP_MODULUS:*/ - case OP_PREINCREMENT: - printf("OP_PREINCREMENT\n"); - break; - case OP_PREDECREMENT: - printf("OP_PREDECREMENT\n"); - break; - case OP_PLUS: - printf("OP_PLUS\n"); - break; - case OP_MINUS: - printf("OP_MINUS\n"); - break; - case OP_NOT: - printf("OP_NOT\n"); - break; - /*case OP_COMPLEMENT:*/ - case OP_SUBSCRIPT: - printf("OP_SUBSCRIPT\n"); - break; - case OP_CALL: - printf("OP_CALL\n"); - break; - case OP_FIELD: - printf("OP_FIELD\n"); - break; - case OP_POSTINCREMENT: - printf("OP_POSTINCREMENT\n"); - break; - case OP_POSTDECREMENT: - printf("OP_POSTDECREMENT\n"); - break; - default: - printf("UNKNOWN OP %d\n", opcode); - } -} - - const char * slang_asm_string(slang_assembly_type t) @@ -1083,6 +890,7 @@ slang_print_type(const slang_fully_specified_type *t) } +#if 0 static char * slang_var_string(const slang_variable *v) { @@ -1092,6 +900,7 @@ slang_var_string(const slang_variable *v) slang_fq_type_string(&v->type)); return str; } +#endif void @@ -1111,13 +920,13 @@ _slang_print_var_scope(const slang_variable_scope *vars, int indent) printf("Var scope %p %d vars:\n", (void *) vars, vars->num_variables); for (i = 0; i < vars->num_variables; i++) { spaces(indent + 3); - printf("%s\n", (char *) vars->variables[i].a_name); + printf("%s (at %p)\n", (char *) vars->variables[i]->a_name, (void*) (vars->variables + i)); } spaces(indent + 3); printf("outer_scope = %p\n", (void*) vars->outer_scope); if (vars->outer_scope) { - spaces(indent + 3); + /*spaces(indent + 3);*/ _slang_print_var_scope(vars->outer_scope, indent + 3); } } diff --git a/src/mesa/shader/slang/slang_print.h b/src/mesa/shader/slang/slang_print.h index a98607a540..ae39be6806 100644 --- a/src/mesa/shader/slang/slang_print.h +++ b/src/mesa/shader/slang/slang_print.h @@ -10,10 +10,6 @@ extern void slang_print_tree(const slang_operation *op, int indent); -extern void -slang_print_opcode(unsigned int opcode); - - extern const char * slang_asm_string(slang_assembly_type t); diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c index 6220b7c5bf..71ac0692e1 100644 --- a/src/mesa/shader/slang/slang_storage.c +++ b/src/mesa/shader/slang/slang_storage.c @@ -126,8 +126,8 @@ static GLboolean aggregate_variables (slang_storage_aggregate *agg, slang_variab GLuint i; for (i = 0; i < vars->num_variables; i++) - if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier, - vars->variables[i].array_len, funcs, structs, globals, mach, file, atoms)) + if (!_slang_aggregate_variable (agg, &vars->variables[i]->type.specifier, + vars->variables[i]->array_len, funcs, structs, globals, mach, file, atoms)) return GL_FALSE; return GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_vartable.c b/src/mesa/shader/slang/slang_vartable.c new file mode 100644 index 0000000000..cd6a081e04 --- /dev/null +++ b/src/mesa/shader/slang/slang_vartable.c @@ -0,0 +1,202 @@ + +#include "imports.h" +#include "slang_compile.h" +#include "slang_compile_variable.h" +#include "slang_vartable.h" + + +static int dbg = 0; + + +typedef enum { + FREE, + VAR, + TEMP +} TempState; + +static int Level = 0; + +struct slang_var_table_ +{ + int level; + int num_entries; + slang_variable **vars; /* array [num_entries] */ + + TempState temps[MAX_PROGRAM_TEMPS]; + + struct slang_var_table_ *parent; +}; + + + +/** + * Create new table, put at head, return ptr to it. + */ +slang_var_table * +_slang_push_var_table(slang_var_table *parent) +{ + slang_var_table *t + = (slang_var_table *) _mesa_calloc(sizeof(slang_var_table)); + if (t) { + t->level = Level++; + t->parent = parent; + if (parent) { + /* copy the info indicating which temp regs are in use */ + memcpy(t->temps, parent->temps, sizeof(t->temps)); + } + if (dbg) printf("Pushing level %d\n", t->level); + } + return t; +} + + +/** + * Destroy given table, return ptr to parent + */ +slang_var_table * +_slang_pop_var_table(slang_var_table *t) +{ + slang_var_table *parent = t->parent; + int i; + if (dbg) printf("Popping level %d\n", t->level); + if (t->parent) { + for (i = 0; i < MAX_PROGRAM_TEMPS; i++) { + if (t->temps[i] && !t->parent->temps[i]) + if (dbg) printf(" Free reg %d\n", i); + } + } + for (i = 0; i < t->num_entries; i++) { + if (dbg) printf(" Free var %s\n", (char*) t->vars[i]->a_name); + } + + if (t->vars) + free(t->vars); + free(t); + Level--; + return parent; +} + + +/** + * Add a new variable to the given symbol table. + */ +void +_slang_add_variable(slang_var_table *t, slang_variable *v) +{ + assert(t); + t->vars = realloc(t->vars, (t->num_entries + 1) * sizeof(slang_variable *)); + t->vars[t->num_entries] = v; + t->num_entries++; +} + + +/** + * Look for variable by name in given table. + * If not found, parent table will be searched. + */ +slang_variable * +_slang_find_variable(const slang_var_table *t, slang_atom name) +{ + while (1) { + int i; + for (i = 0; i < t->num_entries; i++) { + if (t->vars[i]->a_name == name) + return t->vars[i]; + } + if (t->parent) + t = t->parent; + else + return NULL; + } +} + + +static GLint +alloc_reg(slang_var_table *t, GLint size, GLboolean isTemp) +{ + const GLuint sz4 = (size + 3) / 4; + GLuint i, j; + assert(size > 0); /* number of floats */ + + for (i = 0; i < MAX_PROGRAM_TEMPS; i++) { + GLuint found = 0; + for (j = 0; j < sz4; j++) { + if (!t->temps[i + j]) { + found++; + } + else { + break; + } + } + if (found == sz4) { + /* found block of size/4 free regs */ + for (j = 0; j < sz4; j++) + t->temps[i + j] = isTemp ? TEMP : VAR; + return i; + } + } + return -1; +} + + +/** + * Allocate temp register(s) for storing a variable. + */ +GLint +_slang_alloc_var(slang_var_table *t, GLint size) +{ + int i = alloc_reg(t, size, GL_FALSE); + if (dbg) printf("Alloc var %d (level %d)\n", i, t->level); + return i; +} + + +void +_slang_reserve_var(slang_var_table *t, GLint r, GLint size) +{ + const GLint sz4 = (size + 3) / 4; + GLint i; + for (i = 0; i < sz4; i++) { + t->temps[r + i] = VAR; + } +} + + +/** + * Allocate temp register(s) for storing an unnamed intermediate value. + */ +GLint +_slang_alloc_temp(slang_var_table *t, GLint size) +{ + int i = alloc_reg(t, size, GL_TRUE); + if (dbg) printf("Alloc temp %d (level %d)\n", i, t->level); + return i; +} + + +void +_slang_free_temp(slang_var_table *t, GLint r, GLint size) +{ + const GLuint sz4 = (size + 3) / 4; + GLuint i; + assert(size > 0); + assert(r >= 0); + assert(r < MAX_PROGRAM_TEMPS); + if (dbg) printf("Free temp %d (level %d)\n", r, t->level); + for (i = 0; i < sz4; i++) { + assert(t->temps[r + i] == TEMP); + t->temps[r + i] = FREE; + } +} + + +GLboolean +_slang_is_temp(slang_var_table *t, GLint r) +{ + assert(r >= 0); + assert(r < MAX_PROGRAM_TEMPS); + if (t->temps[r] == TEMP) + return GL_TRUE; + else + return GL_FALSE; +} diff --git a/src/mesa/shader/slang/slang_vartable.h b/src/mesa/shader/slang/slang_vartable.h new file mode 100644 index 0000000000..c8e37c94aa --- /dev/null +++ b/src/mesa/shader/slang/slang_vartable.h @@ -0,0 +1,38 @@ + +#ifndef SLANG_VARTABLE_H +#define SLANG_VARTABLE_H + + +typedef struct slang_var_table_ slang_var_table; + +struct slang_variable_; + +extern slang_var_table * +_slang_push_var_table(slang_var_table *parent); + +extern slang_var_table * +_slang_pop_var_table(slang_var_table *t); + +extern void +_slang_add_variable(slang_var_table *t, struct slang_variable_ *v); + +extern struct slang_variable_ * +_slang_find_variable(const slang_var_table *t, slang_atom name); + +extern GLint +_slang_alloc_var(slang_var_table *t, GLint size); + +extern void +_slang_reserve_var(slang_var_table *t, GLint r, GLint size); + +extern GLint +_slang_alloc_temp(slang_var_table *t, GLint size); + +extern void +_slang_free_temp(slang_var_table *t, GLint r, GLint size); + +extern GLboolean +_slang_is_temp(slang_var_table *t, GLint r); + + +#endif /* SLANG_VARTABLE_H */ diff --git a/src/mesa/sources b/src/mesa/sources index 19f43384ea..1b0474c14b 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -189,6 +189,7 @@ SLANG_SOURCES = \ shader/slang/slang_preprocess.c \ shader/slang/slang_simplify.c \ shader/slang/slang_storage.c \ + shader/slang/slang_vartable.c \ shader/slang/slang_print.c \ shader/slang/slang_utility.c -- cgit v1.2.3 From 223d7cb3c785ad58c869a3ee0fbf2f1d42c3310d Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 23 Jan 2007 16:37:51 -0700 Subject: fix g++ warnings/errors --- src/mesa/main/texenvprogram.c | 5 ++-- src/mesa/shader/arbprogram.c | 4 +-- src/mesa/shader/prog_parameter.c | 8 +++--- src/mesa/shader/prog_parameter.h | 4 +-- src/mesa/shader/prog_statevars.c | 2 +- src/mesa/shader/shader_api.c | 6 ++--- src/mesa/shader/slang/slang_codegen.c | 17 ++++++++----- src/mesa/shader/slang/slang_emit.c | 46 +++++++++++++++++------------------ src/mesa/shader/slang/slang_link2.c | 2 +- src/mesa/sources | 1 + src/mesa/swrast/s_fragprog.c | 7 +++--- 11 files changed, 54 insertions(+), 48 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 3cb2adbde2..b69e650159 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -1187,13 +1187,14 @@ static void cache_item( struct texenvprog_cache *cache, const struct state_key *key, void *data ) { - struct texenvprog_cache_item *c = MALLOC(sizeof(*c)); + struct texenvprog_cache_item *c + = (struct texenvprog_cache_item *) MALLOC(sizeof(*c)); c->hash = hash; c->key = _mesa_malloc(sizeof(*key)); memcpy(c->key, key, sizeof(*key)); - c->data = data; + c->data = (struct gl_fragment_program *) data; if (cache->n_items > cache->size * 1.5) { if (cache->size < 1000) diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c index f3b25da394..5583f16ce8 100644 --- a/src/mesa/shader/arbprogram.c +++ b/src/mesa/shader/arbprogram.c @@ -312,7 +312,7 @@ _mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count, const GLfloat *params) { GET_CURRENT_CONTEXT(ctx); - unsigned i; + GLint i; GLfloat * dest; ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -464,7 +464,7 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count, { GET_CURRENT_CONTEXT(ctx); struct gl_program *prog; - unsigned i; + GLint i; ASSERT_OUTSIDE_BEGIN_END(ctx); FLUSH_VERTICES(ctx, _NEW_PROGRAM); diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index 90118b6294..a87dafc598 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -217,7 +217,7 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, * constants because we rely on smearing (i.e. .yyyy or .zzzz). */ if (size == 1) { - for (pos = 0; pos < paramList->NumParameters; pos++) { + for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) { struct gl_program_parameter *p = paramList->Parameters + pos; if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) { /* ok, found room */ @@ -321,7 +321,7 @@ _mesa_add_attribute(struct gl_program_parameter_list *paramList, else { /* add */ gl_state_index state[STATE_LENGTH]; - state[0] = attrib; + state[0] = (gl_state_index) attrib; if (size < 0) size = 4; i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name, @@ -373,7 +373,7 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList, GLint index; /* Check if the state reference is already in the list */ - for (index = 0; index < paramList->NumParameters; index++) { + for (index = 0; index < (GLint) paramList->NumParameters; index++) { GLuint i, match = 0; for (i = 0; i < 6; i++) { if (paramList->Parameters[index].StateIndexes[i] == stateTokens[i]) { @@ -468,7 +468,7 @@ _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, */ GLboolean _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list, - const GLfloat v[], GLsizei vSize, + const GLfloat v[], GLuint vSize, GLint *posOut, GLuint *swizzleOut) { GLuint i; diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h index bfae071be0..459643f425 100644 --- a/src/mesa/shader/prog_parameter.h +++ b/src/mesa/shader/prog_parameter.h @@ -50,7 +50,7 @@ struct gl_program_parameter /** * A sequence of STATE_* tokens and integers to identify GL state. */ - GLuint StateIndexes[STATE_LENGTH]; + GLint StateIndexes[STATE_LENGTH]; }; @@ -127,7 +127,7 @@ _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, extern GLboolean _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list, - const GLfloat v[], GLsizei vSize, + const GLfloat v[], GLuint vSize, GLint *posOut, GLuint *swizzleOut); extern GLuint diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c index a0a00cfb95..3a54ab8c58 100644 --- a/src/mesa/shader/prog_statevars.c +++ b/src/mesa/shader/prog_statevars.c @@ -775,7 +775,7 @@ _mesa_load_state_parameters(GLcontext *ctx, for (i = 0; i < paramList->NumParameters; i++) { if (paramList->Parameters[i].Type == PROGRAM_STATE_VAR) { _mesa_fetch_state(ctx, - paramList->Parameters[i].StateIndexes, + (gl_state_index *) paramList->Parameters[i].StateIndexes, paramList->ParameterValues[i]); } } diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index c18bbcec4b..6bae17a905 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -518,7 +518,7 @@ _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); if (shProg) { - GLuint i; + GLint i; for (i = 0; i < maxCount && i < shProg->NumShaders; i++) { obj[i] = shProg->Shaders[i]->Name; } @@ -719,7 +719,7 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); if (shProg) { - GLuint i; + GLint i; if (location >= 0 && location < shProg->Uniforms->NumParameters) { for (i = 0; i < shProg->Uniforms->Parameters[location].Size; i++) { params[i] = shProg->Uniforms->ParameterValues[location][i]; @@ -883,7 +883,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, return; } - if (location < 0 || location >= shProg->Uniforms->NumParameters) { + if (location < 0 || location >= (GLint) shProg->Uniforms->NumParameters) { _mesa_error(ctx, GL_INVALID_VALUE, "glUniform(location)"); return; } diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index aba6813a8b..ff42db9def 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -661,7 +661,7 @@ static slang_operation * slang_inline_asm_function(slang_assemble_ctx *A, slang_function *fun, slang_operation *oper) { - const int numArgs = oper->num_children; + const GLuint numArgs = oper->num_children; const slang_operation *args = oper->children; GLuint i; slang_operation *inlined = slang_operation_new(1); @@ -1052,7 +1052,8 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, &inlined->children, inlined->num_children); lab->type = slang_oper_label; - lab->a_id = slang_atom_pool_atom(A->atoms, A->CurFunction->end_label); + lab->a_id = slang_atom_pool_atom(A->atoms, + (char *) A->CurFunction->end_label); } for (i = 0; i < totalArgs; i++) { @@ -1281,7 +1282,7 @@ _slang_gen_cond(slang_ir_node *n) static void print_funcs(struct slang_function_scope_ *scope, const char *name) { - int i; + GLuint i; for (i = 0; i < scope->num_functions; i++) { slang_function *f = &scope->functions[i]; if (!name || strcmp(name, (char*) f->header.a_name) == 0) @@ -1301,7 +1302,7 @@ print_funcs(struct slang_function_scope_ *scope, const char *name) static slang_function * _slang_first_function(struct slang_function_scope_ *scope, const char *name) { - int i; + GLuint i; for (i = 0; i < scope->num_functions; i++) { slang_function *f = &scope->functions[i]; if (strcmp(name, (char*) f->header.a_name) == 0) @@ -1800,7 +1801,9 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) slang_operation gotoOp; slang_operation_construct(&gotoOp); gotoOp.type = slang_oper_goto; - gotoOp.a_id = slang_atom_pool_atom(A->atoms, A->CurFunction->end_label); + /* XXX don't call function? */ + gotoOp.a_id = slang_atom_pool_atom(A->atoms, + (char *) A->CurFunction->end_label); /* assemble the new code */ n = _slang_gen_operation(A, &gotoOp); /* destroy temp code */ @@ -1855,7 +1858,9 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) jump = &block->children[1]; jump->type = slang_oper_goto; assert(A->CurFunction->end_label); - jump->a_id = slang_atom_pool_atom(A->atoms, A->CurFunction->end_label); + /* XXX don't call function? */ + jump->a_id = slang_atom_pool_atom(A->atoms, + (char *) A->CurFunction->end_label); #if 0 /* debug */ printf("NEW RETURN:\n"); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 036509c51c..82e8c0b158 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -83,35 +83,35 @@ static slang_ir_info IrInfo[] = { { IR_FLOOR, "IR_FLOOR", OPCODE_FLR, 4, 1 }, { IR_FRAC, "IR_FRAC", OPCODE_FRC, 4, 1 }, { IR_ABS, "IR_ABS", OPCODE_ABS, 4, 1 }, - { IR_NEG, "IR_NEG", 0/*spec case*/, 4, 1 }, + { IR_NEG, "IR_NEG", OPCODE_NOP/*spec case*/, 4, 1 }, { IR_DDX, "IR_DDX", OPCODE_DDX, 4, 1 }, { IR_DDX, "IR_DDY", OPCODE_DDX, 4, 1 }, { IR_SIN, "IR_SIN", OPCODE_SIN, 1, 1 }, { IR_COS, "IR_COS", OPCODE_COS, 1, 1 }, /* other */ - { IR_SEQ, "IR_SEQ", 0, 0, 0 }, - { IR_SCOPE, "IR_SCOPE", 0, 0, 0 }, - { IR_LABEL, "IR_LABEL", 0, 0, 0 }, - { IR_JUMP, "IR_JUMP", 0, 0, 0 }, - { IR_CJUMP0, "IR_CJUMP0", 0, 0, 0 }, - { IR_CJUMP1, "IR_CJUMP1", 0, 0, 0 }, - { IR_IF, "IR_IF", 0, 0, 0 }, - { IR_ELSE, "IR_ELSE", 0, 0, 0 }, - { IR_ENDIF, "IR_ENDIF", 0, 0, 0 }, - { IR_KILL, "IR_KILL", 0, 0, 0 }, - { IR_COND, "IR_COND", 0, 0, 0 }, - { IR_CALL, "IR_CALL", 0, 0, 0 }, - { IR_MOVE, "IR_MOVE", 0, 0, 1 }, - { IR_NOT, "IR_NOT", 0, 1, 1 }, - { IR_VAR, "IR_VAR", 0, 0, 0 }, - { IR_VAR_DECL, "IR_VAR_DECL", 0, 0, 0 }, + { IR_SEQ, "IR_SEQ", OPCODE_NOP, 0, 0 }, + { IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 }, + { IR_LABEL, "IR_LABEL", OPCODE_NOP, 0, 0 }, + { IR_JUMP, "IR_JUMP", OPCODE_NOP, 0, 0 }, + { IR_CJUMP0, "IR_CJUMP0", OPCODE_NOP, 0, 0 }, + { IR_CJUMP1, "IR_CJUMP1", OPCODE_NOP, 0, 0 }, + { IR_IF, "IR_IF", OPCODE_NOP, 0, 0 }, + { IR_ELSE, "IR_ELSE", OPCODE_NOP, 0, 0 }, + { IR_ENDIF, "IR_ENDIF", OPCODE_NOP, 0, 0 }, + { IR_KILL, "IR_KILL", OPCODE_NOP, 0, 0 }, + { IR_COND, "IR_COND", OPCODE_NOP, 0, 0 }, + { IR_CALL, "IR_CALL", OPCODE_NOP, 0, 0 }, + { IR_MOVE, "IR_MOVE", OPCODE_NOP, 0, 1 }, + { IR_NOT, "IR_NOT", OPCODE_NOP, 1, 1 }, + { IR_VAR, "IR_VAR", OPCODE_NOP, 0, 0 }, + { IR_VAR_DECL, "IR_VAR_DECL", OPCODE_NOP, 0, 0 }, { IR_TEX, "IR_TEX", OPCODE_TEX, 4, 1 }, { IR_TEXB, "IR_TEXB", OPCODE_TXB, 4, 1 }, { IR_TEXP, "IR_TEXP", OPCODE_TXP, 4, 1 }, - { IR_FLOAT, "IR_FLOAT", 0, 0, 0 }, - { IR_FIELD, "IR_FIELD", 0, 0, 0 }, - { IR_ELEMENT, "IR_ELEMENT", 0, 0, 0 }, - { IR_SWIZZLE, "IR_SWIZZLE", 0, 0, 0 }, + { IR_FLOAT, "IR_FLOAT", OPCODE_NOP, 0, 0 }, + { IR_FIELD, "IR_FIELD", OPCODE_NOP, 0, 0 }, + { IR_ELEMENT, "IR_ELEMENT", OPCODE_NOP, 0, 0 }, + { IR_SWIZZLE, "IR_SWIZZLE", OPCODE_NOP, 0, 0 }, { IR_NOP, NULL, OPCODE_NOP, 0, 0 } }; @@ -219,7 +219,7 @@ storage_string(const slang_ir_storage *st) sprintf(s, "%s[%d..%d]", files[st->File], st->Index, st->Index + st->Size - 1); #endif - assert(st->File < sizeof(files) / sizeof(files[0])); + assert(st->File < (GLint) (sizeof(files) / sizeof(files[0]))); sprintf(s, "%s[%d]", files[st->File], st->Index); return s; } @@ -966,7 +966,7 @@ emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) if (n->Children[1]->Opcode == IR_FLOAT) { /* OK, constant index */ const GLint arrayAddr = n->Children[0]->Store->Index; - const GLint index = n->Children[1]->Value[0]; + const GLint index = (GLint) n->Children[1]->Value[0]; n->Store->Index = arrayAddr + index; } else { diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c index 0a517aecc5..9676aa5fa1 100644 --- a/src/mesa/shader/slang/slang_link2.c +++ b/src/mesa/shader/slang/slang_link2.c @@ -133,7 +133,7 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog) static GLboolean -is_uniform(enum register_file file) +is_uniform(GLuint file) { return (file == PROGRAM_ENV_PARAM || file == PROGRAM_STATE_VAR || diff --git a/src/mesa/sources b/src/mesa/sources index 1b0474c14b..d0b7246ed6 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -182,6 +182,7 @@ SLANG_SOURCES = \ shader/slang/slang_error.c \ shader/slang/slang_execute.c \ shader/slang/slang_export.c \ + shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ shader/slang/slang_link.c \ diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 813345f4cd..ed82460669 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -200,8 +200,7 @@ fetch_vector4( GLcontext *ctx, const GLfloat *src = get_register_pointer(ctx, source, machine, program); ASSERT(src); - if (source->Swizzle == MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, - SWIZZLE_Z, SWIZZLE_W)) { + if (source->Swizzle == SWIZZLE_NOOP) { /* no swizzling */ COPY_4V(result, src); } @@ -1263,8 +1262,8 @@ execute_program( GLcontext *ctx, { GLfloat a[4], result[4]; fetch_vector1( ctx, &inst->SrcReg[0], machine, program, a ); - result[0] = (GLfloat)_mesa_cos(a[0]); - result[1] = (GLfloat)_mesa_sin(a[0]); + result[0] = (GLfloat) _mesa_cos(a[0]); + result[1] = (GLfloat) _mesa_sin(a[0]); result[2] = 0.0; /* undefined! */ result[3] = 0.0; /* undefined! */ store_vector4( inst, machine, result ); -- cgit v1.2.3 From 496aa47042527852ec232c712168fb7fe3c645c3 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 1 Feb 2007 09:52:26 -0700 Subject: remove slang_label.c until it's ready --- src/mesa/sources | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index d0b7246ed6..1b0474c14b 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -182,7 +182,6 @@ SLANG_SOURCES = \ shader/slang/slang_error.c \ shader/slang/slang_execute.c \ shader/slang/slang_export.c \ - shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ shader/slang/slang_link.c \ -- cgit v1.2.3 From 650d46a107f1a3c49cff93521f80ae84d30ecfe0 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 13:49:39 -0700 Subject: remove slang_execute.c, slang_execute_x86.c --- src/mesa/sources | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 1b0474c14b..db1d5e8e70 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -180,7 +180,6 @@ SLANG_SOURCES = \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ shader/slang/slang_error.c \ - shader/slang/slang_execute.c \ shader/slang/slang_export.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ @@ -201,8 +200,7 @@ ASM_C_SOURCES = \ x86/rtasm/x86sse.c \ sparc/sparc.c \ ppc/common_ppc.c \ - x86-64/x86-64.c \ - shader/slang/slang_execute_x86.c + x86-64/x86-64.c X86_SOURCES = \ x86/common_x86_asm.S \ -- cgit v1.2.3 From 8b60787e85a88216d1e56bf3fc5ae807d4f2392b Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 14:05:25 -0700 Subject: remove slang_link.c and slang_analyse.c --- src/mesa/sources | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index db1d5e8e70..a7936101ca 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -166,7 +166,6 @@ SHADER_SOURCES = \ shader/shader_api.c \ SLANG_SOURCES = \ - shader/slang/slang_analyse.c \ shader/slang/slang_assemble.c \ shader/slang/slang_assemble_assignment.c \ shader/slang/slang_assemble_conditional.c \ @@ -183,7 +182,6 @@ SLANG_SOURCES = \ shader/slang/slang_export.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ - shader/slang/slang_link.c \ shader/slang/slang_link2.c \ shader/slang/slang_preprocess.c \ shader/slang/slang_simplify.c \ -- cgit v1.2.3 From 1b24e2d5a7a7f97c179d7881a014f4aa025cacf7 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 14:24:24 -0700 Subject: remove slang_export.c and related code --- src/mesa/shader/slang/slang_assemble.c | 16 +----- src/mesa/shader/slang/slang_assemble_assignment.c | 5 -- src/mesa/shader/slang/slang_compile.c | 51 ----------------- src/mesa/shader/slang/slang_compile.h | 8 --- src/mesa/shader/slang/slang_compile_function.c | 46 ---------------- src/mesa/shader/slang/slang_compile_function.h | 6 -- src/mesa/shader/slang/slang_compile_variable.c | 67 ----------------------- src/mesa/shader/slang/slang_compile_variable.h | 5 -- src/mesa/shader/slang/slang_storage.c | 8 --- src/mesa/sources | 1 - 10 files changed, 1 insertion(+), 212 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c index e3b65a1238..e65bf38ad5 100644 --- a/src/mesa/shader/slang/slang_assemble.c +++ b/src/mesa/shader/slang/slang_assemble.c @@ -33,9 +33,8 @@ #include "slang_compile.h" #include "slang_storage.h" #include "slang_error.h" - #include "slang_print.h" -/*#include "assemble2.c"*/ + /* slang_assembly */ @@ -481,11 +480,6 @@ dereference_basic(slang_assemble_ctx * A, slang_storage_type type, case slang_stor_float: ty = slang_asm_float_deref; break; -#if 0/*defined(USE_X86_ASM) || defined(SLANG_X86)*/ - case slang_stor_vec4: - ty = slang_asm_vec4_deref; - break; -#endif default: _mesa_problem(NULL, "Unexpected arr->type in dereference_basic"); ty = slang_asm_none; @@ -829,14 +823,6 @@ equality_aggregate(slang_assemble_ctx * A, return GL_FALSE; } else { -#if 0/*defined(USE_X86_ASM) || defined(SLANG_X86)*/ - if (arr->type == slang_stor_vec4) { - if (!PLAB2(A->file, slang_asm_vec4_equal_int, - size + *index, *index)) - return GL_FALSE; - } - else -#endif if (!PLAB2(A->file, slang_asm_float_equal_int, size + *index, *index)) return GL_FALSE; diff --git a/src/mesa/shader/slang/slang_assemble_assignment.c b/src/mesa/shader/slang/slang_assemble_assignment.c index 93a1ef3a08..6efc0f558a 100644 --- a/src/mesa/shader/slang/slang_assemble_assignment.c +++ b/src/mesa/shader/slang/slang_assemble_assignment.c @@ -79,11 +79,6 @@ assign_basic(slang_assemble_ctx * A, slang_storage_type type, GLuint * index, case slang_stor_float: ty = slang_asm_float_copy; break; -#if 0/*defined(USE_X86_ASM) || defined(SLANG_X86)*/ - case slang_stor_vec4: - ty = slang_asm_vec4_copy; - break; -#endif default: _mesa_problem(NULL, "Unexpected arr->type in assign_basic"); ty = slang_asm_none; diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 8148c65a55..9f7f18167d 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -105,10 +105,6 @@ _slang_code_object_ctr(slang_code_object * self) #endif self->varpool.next_addr = 0; slang_atom_pool_construct(&self->atompool); - slang_export_data_table_ctr(&self->expdata); - self->expdata.atoms = &self->atompool; - slang_export_code_table_ctr(&self->expcode); - self->expcode.atoms = &self->atompool; } GLvoid @@ -123,8 +119,6 @@ _slang_code_object_dtr(slang_code_object * self) slang_assembly_file_destruct(&self->assembly); #endif slang_atom_pool_destruct(&self->atompool); - slang_export_data_table_dtr(&self->expdata); - slang_export_code_table_ctr(&self->expcode); } /* slang_info_log */ @@ -1730,9 +1724,6 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, A.space.structs = O->structs; A.space.vars = O->vars; A.program = O->program; -#if 0 - A.codegen = O->codegen; -#endif A.vartable = O->vartable; _slang_codegen_global_variable(&A, var, C->type); @@ -1890,9 +1881,6 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, A.space.structs = O->structs; A.space.vars = O->vars; A.program = O->program; -#if 0 - A.codegen = O->codegen; -#endif A.vartable = O->vartable; _slang_reset_error(); @@ -2115,12 +2103,6 @@ static const byte slang_vertex_builtin_gc[] = { #include "library/slang_vertex_builtin_gc.h" }; -#if 0 /*defined(USE_X86_ASM) || defined(SLANG_X86)*/ -static const byte slang_builtin_vec4_gc[] = { -#include "library/slang_builtin_vec4_gc.h" -}; -#endif - static GLboolean compile_object(grammar * id, const char *source, slang_code_object * object, slang_unit_type type, slang_info_log * infolog, @@ -2181,15 +2163,6 @@ compile_object(grammar * id, const char *source, slang_code_object * object, return GL_FALSE; } -#if 0/*defined(USE_X86_ASM) || defined(SLANG_X86)*/ - /* compile x86 4-component vector overrides, link to target */ - if (!compile_binary(slang_builtin_vec4_gc, - &object->builtin[SLANG_BUILTIN_VEC4], - slang_unit_fragment_builtin, infolog, NULL, - &object->builtin[SLANG_BUILTIN_TARGET])) - return GL_FALSE; -#endif - /* disable language extensions */ #if NEW_SLANG /* allow-built-ins */ grammar_set_reg8(*id, (const byte *) "parsing_builtin", 1); @@ -2205,24 +2178,6 @@ compile_object(grammar * id, const char *source, slang_code_object * object, } -#if 0 -static void -slang_create_uniforms(const slang_export_data_table *exports, - struct gl_program *program) -{ - /* XXX only add uniforms that are actually going to get used */ - GLuint i; - for (i = 0; i < exports->count; i++) { - if (exports->entries[i].access == slang_exp_uniform) { - const char *name = (char *) exports->entries[i].quant.name; - GLint j = _mesa_add_uniform(program->Parameters, name, 4); - assert(j >= 0); - } - } -} -#endif - - static GLboolean compile_shader(GLcontext *ctx, slang_code_object * object, slang_unit_type type, slang_info_log * infolog, @@ -2243,12 +2198,6 @@ compile_shader(GLcontext *ctx, slang_code_object * object, if (!success) return GL_FALSE; - if (!_slang_build_export_data_table(&object->expdata, &object->unit.vars)) - return GL_FALSE; - if (!_slang_build_export_code_table(&object->expcode, &object->unit.funs, - &object->unit)) - return GL_FALSE; - #if NEW_SLANG { slang_create_uniforms(&object->expdata, shader); diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index 450119d650..3ebe72eca4 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -27,7 +27,6 @@ #include "imports.h" #include "mtypes.h" -#include "slang_export.h" #include "slang_assemble.h" #include "slang_compile_variable.h" #include "slang_compile_struct.h" @@ -70,12 +69,7 @@ _slang_code_unit_dtr (slang_code_unit *); #define SLANG_BUILTIN_COMMON 1 #define SLANG_BUILTIN_TARGET 2 -#if 0/*defined(USE_X86_ASM) || defined(SLANG_X86)*/ -#define SLANG_BUILTIN_VEC4 3 -#define SLANG_BUILTIN_TOTAL 4 -#else #define SLANG_BUILTIN_TOTAL 3 -#endif typedef struct slang_code_object_ { @@ -84,8 +78,6 @@ typedef struct slang_code_object_ slang_assembly_file assembly; slang_var_pool varpool; slang_atom_pool atompool; - slang_export_data_table expdata; - slang_export_code_table expcode; } slang_code_object; extern GLvoid diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c index c9b33f3b2f..00a85c2e7d 100644 --- a/src/mesa/shader/slang/slang_compile_function.c +++ b/src/mesa/shader/slang/slang_compile_function.c @@ -214,49 +214,3 @@ slang_function_scope_find(slang_function_scope * funcs, slang_function * fun, return slang_function_scope_find(funcs->outer_scope, fun, 1); return NULL; } - -/* - * _slang_build_export_code_table() - */ - -GLboolean -_slang_build_export_code_table(slang_export_code_table * tbl, - slang_function_scope * funs, - slang_code_unit * unit) -{ - slang_atom mainAtom; - GLuint i; - - mainAtom = slang_atom_pool_atom(tbl->atoms, "main"); - if (mainAtom == SLANG_ATOM_NULL) - return GL_FALSE; - - for (i = 0; i < funs->num_functions; i++) { - if (funs->functions[i].header.a_name == mainAtom) { - slang_function *fun = &funs->functions[i]; - slang_export_code_entry *e; - slang_assemble_ctx A; - - e = slang_export_code_table_add(tbl); - if (e == NULL) - return GL_FALSE; - e->address = unit->object->assembly.count; - e->name = slang_atom_pool_atom(tbl->atoms, "@main"); - if (e->name == SLANG_ATOM_NULL) - return GL_FALSE; - - A.file = &unit->object->assembly; - A.atoms = &unit->object->atompool; - A.space.funcs = &unit->funs; - A.space.structs = &unit->structs; - A.space.vars = &unit->vars; - slang_assembly_file_push_label(&unit->object->assembly, - slang_asm_local_alloc, 20); - slang_assembly_file_push_label(&unit->object->assembly, - slang_asm_enter, 20); - _slang_assemble_function_call(&A, fun, NULL, 0, GL_FALSE); - slang_assembly_file_push(&unit->object->assembly, slang_asm_exit); - } - } - return GL_TRUE; -} diff --git a/src/mesa/shader/slang/slang_compile_function.h b/src/mesa/shader/slang/slang_compile_function.h index 8f0e3b326d..99a6b2a034 100644 --- a/src/mesa/shader/slang/slang_compile_function.h +++ b/src/mesa/shader/slang/slang_compile_function.h @@ -102,12 +102,6 @@ slang_function_scope_find_by_name(slang_function_scope *, slang_atom, int); extern slang_function * slang_function_scope_find(slang_function_scope *, slang_function *, int); -extern GLboolean -_slang_build_export_code_table(slang_export_code_table *, - slang_function_scope *, - struct slang_code_unit_ *); - - #ifdef __cplusplus } #endif diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c index b19615b085..c8ffaf296a 100644 --- a/src/mesa/shader/slang/slang_compile_variable.c +++ b/src/mesa/shader/slang/slang_compile_variable.c @@ -383,70 +383,3 @@ gl_type_from_specifier(const slang_type_specifier * type) return GL_FLOAT; } } - -static GLboolean -build_quant(slang_export_data_quant * q, const slang_variable * var) -{ - const slang_type_specifier *spec = &var->type.specifier; - - q->name = var->a_name; - q->size = var->size; - if (spec->type == slang_spec_array) { - q->array_len = var->array_len; -#if 1 - if (var->array_len > 0) -#endif - q->size /= var->array_len; - spec = spec->_array; - } - if (spec->type == slang_spec_struct) { - GLuint i; - - q->u.field_count = spec->_struct->fields->num_variables; - q->structure = (slang_export_data_quant *) - slang_alloc_malloc(q->u.field_count - * sizeof(slang_export_data_quant)); - if (q->structure == NULL) - return GL_FALSE; - - for (i = 0; i < q->u.field_count; i++) - slang_export_data_quant_ctr(&q->structure[i]); - for (i = 0; i < q->u.field_count; i++) { - if (!build_quant(&q->structure[i], - spec->_struct->fields->variables[i])) - return GL_FALSE; - } - } - else - q->u.basic_type = gl_type_from_specifier(spec); - return GL_TRUE; -} - -GLboolean -_slang_build_export_data_table(slang_export_data_table * tbl, - slang_variable_scope * vars) -{ - GLuint i; - - for (i = 0; i < vars->num_variables; i++) { - const slang_variable *var = vars->variables[i]; - slang_export_data_entry *e; - - e = slang_export_data_table_add(tbl); - if (e == NULL) - return GL_FALSE; - if (!build_quant(&e->quant, var)) - return GL_FALSE; - if (var->type.qualifier == slang_qual_uniform) - e->access = slang_exp_uniform; - else if (var->type.qualifier == slang_qual_attribute) - e->access = slang_exp_attribute; - else - e->access = slang_exp_varying; - e->address = var->address; - } - - if (vars->outer_scope != NULL) - return _slang_build_export_data_table(tbl, vars->outer_scope); - return GL_TRUE; -} diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h index 82800b32b5..841f9840a6 100644 --- a/src/mesa/shader/slang/slang_compile_variable.h +++ b/src/mesa/shader/slang/slang_compile_variable.h @@ -126,11 +126,6 @@ extern slang_variable * _slang_locate_variable(const slang_variable_scope *, const slang_atom a_name, GLboolean all); -extern GLboolean -_slang_build_export_data_table(slang_export_data_table *, - slang_variable_scope *); - - #ifdef __cplusplus } diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c index 899c36cbd3..472d08e6c1 100644 --- a/src/mesa/shader/slang/slang_storage.c +++ b/src/mesa/shader/slang/slang_storage.c @@ -180,21 +180,13 @@ _slang_aggregate_variable(slang_storage_aggregate * agg, case slang_spec_vec3: return aggregate_vector(agg, slang_stor_float, 3); case slang_spec_vec4: -#if 0 /*defined(USE_X86_ASM) || defined(SLANG_X86) */ - return aggregate_vector(agg, slang_stor_vec4, 1); -#else return aggregate_vector(agg, slang_stor_float, 4); -#endif case slang_spec_mat2: return aggregate_matrix(agg, slang_stor_float, 2); case slang_spec_mat3: return aggregate_matrix(agg, slang_stor_float, 3); case slang_spec_mat4: -#if 0 /*defined(USE_X86_ASM) || defined(SLANG_X86) */ - return aggregate_vector(agg, slang_stor_vec4, 4); -#else return aggregate_matrix(agg, slang_stor_float, 4); -#endif case slang_spec_sampler1D: case slang_spec_sampler2D: case slang_spec_sampler3D: diff --git a/src/mesa/sources b/src/mesa/sources index a7936101ca..9b77d21786 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -179,7 +179,6 @@ SLANG_SOURCES = \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ shader/slang/slang_error.c \ - shader/slang/slang_export.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ shader/slang/slang_link2.c \ -- cgit v1.2.3 From b94c14114f8d5ec7983be0e9d6f286232e183894 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 14:51:34 -0700 Subject: remove slang_assemble*.c files --- src/mesa/sources | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 9b77d21786..a7a40b3204 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -166,10 +166,6 @@ SHADER_SOURCES = \ shader/shader_api.c \ SLANG_SOURCES = \ - shader/slang/slang_assemble.c \ - shader/slang/slang_assemble_assignment.c \ - shader/slang/slang_assemble_conditional.c \ - shader/slang/slang_assemble_constructor.c \ shader/slang/slang_assemble_typeinfo.c \ shader/slang/slang_codegen.c \ shader/slang/slang_compile.c \ -- cgit v1.2.3 From f65091c94766b9a21abf29dfc17fa5e857a835b8 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 15:19:58 -0700 Subject: rename slang_assemble_typeinfo.[ch] to slang_typeinfo.[ch] --- src/mesa/shader/slang/slang_codegen.c | 2 +- src/mesa/shader/slang/slang_compile.h | 2 +- src/mesa/shader/slang/slang_storage.h | 2 +- src/mesa/shader/slang/slang_typeinfo.c | 2 +- src/mesa/sources | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d39cdd22a5..222bf113cc 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -30,7 +30,7 @@ #include "imports.h" #include "macros.h" -#include "slang_assemble_typeinfo.h" +#include "slang_typeinfo.h" #include "slang_codegen.h" #include "slang_compile.h" #include "slang_storage.h" diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index 0fe5443c7c..6e247d002c 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -27,7 +27,7 @@ #include "imports.h" #include "mtypes.h" -#include "slang_assemble_typeinfo.h" +#include "slang_typeinfo.h" #include "slang_compile_variable.h" #include "slang_compile_struct.h" #include "slang_compile_operation.h" diff --git a/src/mesa/shader/slang/slang_storage.h b/src/mesa/shader/slang/slang_storage.h index 642ffa38c4..c7380ebb60 100644 --- a/src/mesa/shader/slang/slang_storage.h +++ b/src/mesa/shader/slang/slang_storage.h @@ -26,7 +26,7 @@ #define SLANG_STORAGE_H #include "slang_compile.h" -#include "slang_assemble_typeinfo.h" +#include "slang_typeinfo.h" #if defined __cplusplus extern "C" { diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index eafc452972..fd5cd70a3c 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -29,7 +29,7 @@ */ #include "imports.h" -#include "slang_assemble_typeinfo.h" +#include "slang_typeinfo.h" #include "slang_compile.h" #include "slang_error.h" #include "prog_instruction.h" diff --git a/src/mesa/sources b/src/mesa/sources index a7a40b3204..98af7b3b75 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -166,7 +166,7 @@ SHADER_SOURCES = \ shader/shader_api.c \ SLANG_SOURCES = \ - shader/slang/slang_assemble_typeinfo.c \ + shader/slang/slang_typeinfo.c \ shader/slang/slang_codegen.c \ shader/slang/slang_compile.c \ shader/slang/slang_compile_function.c \ -- cgit v1.2.3 From 6c52dd38524a3f3edc48dcabee684bf94e605a22 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 15:22:05 -0700 Subject: rename slang_link2.c slang_link.c --- src/mesa/sources | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 98af7b3b75..a6bbbab009 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -166,7 +166,6 @@ SHADER_SOURCES = \ shader/shader_api.c \ SLANG_SOURCES = \ - shader/slang/slang_typeinfo.c \ shader/slang/slang_codegen.c \ shader/slang/slang_compile.c \ shader/slang/slang_compile_function.c \ @@ -177,12 +176,13 @@ SLANG_SOURCES = \ shader/slang/slang_error.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_library_texsample.c \ - shader/slang/slang_link2.c \ + shader/slang/slang_link.c \ shader/slang/slang_preprocess.c \ + shader/slang/slang_print.c \ shader/slang/slang_simplify.c \ shader/slang/slang_storage.c \ + shader/slang/slang_typeinfo.c \ shader/slang/slang_vartable.c \ - shader/slang/slang_print.c \ shader/slang/slang_utility.c ASM_C_SOURCES = \ -- cgit v1.2.3 From 884fdfeb2272802e3103321edfed9cb198950e90 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 15:23:38 -0700 Subject: remove slang_library_texsample.[ch] --- src/mesa/sources | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index a6bbbab009..4d8055b4bf 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -175,7 +175,6 @@ SLANG_SOURCES = \ shader/slang/slang_emit.c \ shader/slang/slang_error.c \ shader/slang/slang_library_noise.c \ - shader/slang/slang_library_texsample.c \ shader/slang/slang_link.c \ shader/slang/slang_preprocess.c \ shader/slang/slang_print.c \ -- cgit v1.2.3 From 5620392d67278714f7c2a5ccc3101334ac35ab3f Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 9 Feb 2007 15:40:15 -0700 Subject: add prog_debug.c --- src/mesa/sources | 1 + 1 file changed, 1 insertion(+) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 4d8055b4bf..b35e56abad 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -158,6 +158,7 @@ SHADER_SOURCES = \ shader/nvvertexec.c \ shader/nvvertparse.c \ shader/program.c \ + shader/prog_debug.c \ shader/prog_instruction.c \ shader/prog_parameter.c \ shader/prog_print.c \ -- cgit v1.2.3 From 48d65aabbc1e679fbf56fb7c4f7d4d702d43501a Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 20 Feb 2007 14:03:10 -0700 Subject: added slang_builtin.c --- src/mesa/sources | 1 + 1 file changed, 1 insertion(+) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index b35e56abad..55c282cad9 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -167,6 +167,7 @@ SHADER_SOURCES = \ shader/shader_api.c \ SLANG_SOURCES = \ + shader/slang/slang_builtin.c \ shader/slang/slang_codegen.c \ shader/slang/slang_compile.c \ shader/slang/slang_compile_function.c \ -- cgit v1.2.3 From ef64cda9786858c8247166ae2692fc043121b6f4 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 22 Feb 2007 16:00:31 -0700 Subject: remove nvvertexec.c, add prog_execute.c --- src/mesa/sources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index a15c5c479f..49d8dc997c 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -159,10 +159,10 @@ SHADER_SOURCES = \ shader/grammar/grammar_mesa.c \ shader/nvfragparse.c \ shader/nvprogram.c \ - shader/nvvertexec.c \ shader/nvvertparse.c \ shader/program.c \ shader/prog_debug.c \ + shader/prog_execute.c \ shader/prog_instruction.c \ shader/prog_parameter.c \ shader/prog_print.c \ -- cgit v1.2.3 From 308be21c2fe8e5d33bd63eca1d3e8250cd80199d Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 23 Feb 2007 10:04:18 -0700 Subject: added slang_label.c --- src/mesa/sources | 1 + 1 file changed, 1 insertion(+) (limited to 'src/mesa/sources') diff --git a/src/mesa/sources b/src/mesa/sources index 49d8dc997c..a7bbc02012 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -180,6 +180,7 @@ SLANG_SOURCES = \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ shader/slang/slang_error.c \ + shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_link.c \ shader/slang/slang_preprocess.c \ -- cgit v1.2.3 From c4ac5ac9d70bf89366f8d8798d038dbbc71d833f Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 26 Feb 2007 14:32:53 -0700 Subject: Overhaul of error handling. --- configs/linux-dri | 2 +- src/mesa/shader/slang/slang_codegen.c | 37 +++++----- src/mesa/shader/slang/slang_compile.c | 114 ++-------------------------- src/mesa/shader/slang/slang_compile.h | 13 ---- src/mesa/shader/slang/slang_emit.c | 18 +++-- src/mesa/shader/slang/slang_emit.h | 3 +- src/mesa/shader/slang/slang_preprocess.h | 23 +++--- src/mesa/shader/slang/slang_simplify.c | 6 +- src/mesa/shader/slang/slang_simplify.h | 3 +- src/mesa/shader/slang/slang_typeinfo.c | 123 +++++++++++++++++-------------- src/mesa/shader/slang/slang_typeinfo.h | 9 ++- src/mesa/sources | 2 +- 12 files changed, 129 insertions(+), 224 deletions(-) (limited to 'src/mesa/sources') diff --git a/configs/linux-dri b/configs/linux-dri index 5f945a73f1..1a9146e299 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -67,4 +67,4 @@ WINDOW_SYSTEM=dri # gamma are missing because they have not been converted to use the new # interface. DRI_DIRS = i810 i915tex i915 i965 mach64 mga r128 r200 r300 radeon s3v \ - savage sis tdfx trident unichrome ffb + savage sis tdfx trident unichrome ffb nouveau diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d239a97500..efd330106b 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -47,7 +47,6 @@ #include "slang_typeinfo.h" #include "slang_codegen.h" #include "slang_compile.h" -#include "slang_error.h" #include "slang_label.h" #include "slang_simplify.h" #include "slang_emit.h" @@ -1154,7 +1153,7 @@ make_writemask(const char *field) */ static slang_ir_node * _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, - slang_operation *dest) + slang_operation *dest) { const slang_asm_info *info; slang_ir_node *kids[3], *n; @@ -1280,15 +1279,15 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, * Use 'name' to find the function to call */ fun = _slang_locate_function(A->space.funcs, atom, params, param_count, - &A->space, A->atoms); + &A->space, A->atoms, A->log); if (!fun) { /* A function with exactly the right parameters/types was not found. * Try adapting the parameters. */ fun = _slang_first_function(A->space.funcs, name); - if (!_slang_adapt_call(oper, fun, &A->space, A->atoms)) { - RETURN_ERROR2("Undefined function (or no matching parameters)", - name, 0); + if (!_slang_adapt_call(oper, fun, &A->space, A->atoms, A->log)) { + slang_info_log_error(A->log, "Undefined function '%s'", name); + return NULL; } assert(fun); } @@ -1361,7 +1360,8 @@ _slang_gen_while(slang_assemble_ctx * A, const slang_operation *oper) if (loop->BranchNode == 0 && isConst && constTrue) { /* infinite loop detected */ A->CurLoop = prevLoop; /* clean-up */ - RETURN_ERROR("Infinite loop detected!", 0); + slang_info_log_error(A->log, "Infinite loop detected!"); + return NULL; } /* pop loop, restore prev */ @@ -1816,7 +1816,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) assert(oper->num_children == 1); var = new_var(A, oper, oper->a_id); if (!var) { - RETURN_ERROR2("Undefined variable:", varName, 0); + slang_info_log_error(A->log, "undefined variable '%s'", varName); + return NULL; } /* XXX make copy of this initializer? */ rhs = _slang_gen_operation(A, &oper->children[0]); @@ -1829,7 +1830,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *var, *init, *rhs; var = new_var(A, oper, oper->a_id); if (!var) { - RETURN_ERROR2("Undefined variable:", varName, 0); + slang_info_log_error(A->log, "undefined variable '%s'", varName); + return NULL; } #if 0 /* XXX make copy of this initializer? */ @@ -1870,7 +1872,8 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) slang_atom aVar = oper->var ? oper->var->a_name : oper->a_id; slang_ir_node *n = new_var(A, oper, aVar); if (!n) { - RETURN_ERROR2("Undefined variable:", (char *) aVar, 0); + slang_info_log_error(A->log, "undefined variable '%s'", (char *) aVar); + return NULL; } return n; } @@ -2045,7 +2048,7 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; GLuint swizzle; if (!_slang_is_swizzle((char *) oper->a_id, rows, &swz)) { - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(A->log, "Bad swizzle"); } swizzle = MAKE_SWIZZLE4(swz.swizzle[0], swz.swizzle[1], @@ -2063,7 +2066,7 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; GLuint swizzle; if (!_slang_is_swizzle((char *) oper->a_id, rows, &swz)) { - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(A->log, "Bad swizzle"); } swizzle = MAKE_SWIZZLE4(swz.swizzle[0], swz.swizzle[1], @@ -2122,7 +2125,7 @@ _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) index = (GLint) oper->children[1].literal[0]; if (oper->children[1].type != SLANG_OPER_LITERAL_INT || index >= max) { - RETURN_ERROR("Invalid array index for vector type", 0); + slang_info_log_error(A->log, "Invalid array index for vector type"); } n = _slang_gen_operation(A, &oper->children[0]); @@ -2243,12 +2246,12 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return _slang_gen_while(A, oper); case SLANG_OPER_BREAK: if (!A->CurLoop) { - RETURN_ERROR("'break' not in loop", 0); + slang_info_log_error(A->log, "'break' not in loop"); } return new_break(A->CurLoop); case SLANG_OPER_CONTINUE: if (!A->CurLoop) { - RETURN_ERROR("'continue' not in loop", 0); + slang_info_log_error(A->log, "'continue' not in loop"); } return new_cont(A->CurLoop); case SLANG_OPER_DISCARD: @@ -2621,7 +2624,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, n = new_seq(n, init); } - success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE); + success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE, A->log); _slang_free_ir_tree(n); } @@ -2709,7 +2712,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #endif /* Emit program instructions */ - success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE); + success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE, A->log); _slang_free_ir_tree(n); /* free codegen context */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index a1cae5d338..1a4c7d31f1 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -37,8 +37,8 @@ #include "slang_compile.h" #include "slang_preprocess.h" #include "slang_storage.h" -#include "slang_error.h" #include "slang_emit.h" +#include "slang_log.h" #include "slang_vartable.h" #include "slang_simplify.h" @@ -115,110 +115,6 @@ _slang_code_object_dtr(slang_code_object * self) slang_atom_pool_destruct(&self->atompool); } -/* slang_info_log */ - -static char *out_of_memory = "Error: Out of memory.\n"; - -void -slang_info_log_construct(slang_info_log * log) -{ - log->text = NULL; - log->dont_free_text = 0; -} - -void -slang_info_log_destruct(slang_info_log * log) -{ - if (!log->dont_free_text) - slang_alloc_free(log->text); -} - -static int -slang_info_log_message(slang_info_log * log, const char *prefix, - const char *msg) -{ - GLuint size; - - if (log->dont_free_text) - return 0; - size = slang_string_length(msg) + 2; - if (prefix != NULL) - size += slang_string_length(prefix) + 2; - if (log->text != NULL) { - GLuint old_len = slang_string_length(log->text); - log->text = (char *) - slang_alloc_realloc(log->text, old_len + 1, old_len + size); - } - else { - log->text = (char *) (slang_alloc_malloc(size)); - if (log->text != NULL) - log->text[0] = '\0'; - } - if (log->text == NULL) - return 0; - if (prefix != NULL) { - slang_string_concat(log->text, prefix); - slang_string_concat(log->text, ": "); - } - slang_string_concat(log->text, msg); - slang_string_concat(log->text, "\n"); -#if 1 - abort(); /* XXX temporary */ -#endif - return 1; -} - -int -slang_info_log_print(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - return slang_info_log_message(log, NULL, buf); -} - -int -slang_info_log_error(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - if (slang_info_log_message(log, "Error", buf)) - return 1; - slang_info_log_memory(log); - return 0; -} - -int -slang_info_log_warning(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - if (slang_info_log_message(log, "Warning", buf)) - return 1; - slang_info_log_memory(log); - return 0; -} - -void -slang_info_log_memory(slang_info_log * log) -{ - if (!slang_info_log_message(log, "Error", "Out of memory.")) { - log->dont_free_text = 1; - log->text = out_of_memory; - } - abort(); /* XXX temporary */ -} /* slang_parse_ctx */ @@ -1838,8 +1734,7 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, A.space.vars = O->vars; A.program = O->program; A.vartable = O->vartable; - - _slang_reset_error(); + A.log = C->L; _slang_codegen_function(&A, *parsed_func_ret); } @@ -2002,7 +1897,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, slang_string_free(&preprocessed); grammar_get_last_error((byte *) (buf), sizeof(buf), &pos); slang_info_log_error(infolog, buf); - RETURN_ERROR("syntax error (possibly in library code)", 0); + /* syntax error (possibly in library code) */ } slang_string_free(&preprocessed); @@ -2175,7 +2070,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) success = compile_shader(ctx, &obj, type, &info_log, shader); - if (success) { + if (success && !info_log.text) { #if 0 slang_create_uniforms(&object->expdata, shader); _mesa_print_program(program); @@ -2183,6 +2078,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) #endif } else { + success = GL_FALSE; /* XXX more work on info log needed here */ if (info_log.text) { if (shader->InfoLog) { diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index 7abb92bd3b..086e2d8dc4 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -88,19 +88,6 @@ _slang_code_object_ctr (slang_code_object *); extern GLvoid _slang_code_object_dtr (slang_code_object *); -typedef struct slang_info_log_ -{ - char *text; - int dont_free_text; -} slang_info_log; - -void slang_info_log_construct (slang_info_log *); -void slang_info_log_destruct (slang_info_log *); -int slang_info_log_print (slang_info_log *, const char *, ...); -int slang_info_log_error (slang_info_log *, const char *, ...); -int slang_info_log_warning (slang_info_log *, const char *, ...); -void slang_info_log_memory (slang_info_log *); - extern GLboolean _slang_compile (GLcontext *ctx, struct gl_shader *shader); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index f5b6fb4d65..b0776e9340 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -45,7 +45,6 @@ #include "prog_print.h" #include "slang_builtin.h" #include "slang_emit.h" -#include "slang_error.h" #define PEEPHOLE_OPTIMIZATIONS 1 @@ -1421,14 +1420,20 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) assert(n->Store->Index < 0); if (!n->Var || n->Var->isTemp) { /* a nameless/temporary variable, will be freed after first use */ - if (!_slang_alloc_temp(emitInfo->vt, n->Store)) - RETURN_ERROR("Ran out of registers, too many temporaries", 0); + if (!_slang_alloc_temp(emitInfo->vt, n->Store)) { + slang_info_log_error(emitInfo->log, + "Ran out of registers, too many temporaries"); + return NULL; + } } else { /* a regular variable */ _slang_add_variable(emitInfo->vt, n->Var); - if (!_slang_alloc_var(emitInfo->vt, n->Store)) - RETURN_ERROR("Ran out of registers, too many variables", 0); + if (!_slang_alloc_var(emitInfo->vt, n->Store)) { + slang_info_log_error(emitInfo->log, + "Ran out of registers, too many variables"); + return NULL; + } /* printf("IR_VAR_DECL %s %d store %p\n", (char*) n->Var->a_name, n->Store->Index, (void*) n->Store); @@ -1530,7 +1535,8 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) n->Store->Size, &n->Store->Swizzle); if (n->Store->Index < 0) { - RETURN_ERROR("Ran out of space for constants.", 0); + slang_info_log_error(emitInfo->log, "Ran out of space for constants"); + return NULL; } return NULL; diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h index 1b792402da..13ba6d7d6c 100644 --- a/src/mesa/shader/slang/slang_emit.h +++ b/src/mesa/shader/slang/slang_emit.h @@ -42,7 +42,8 @@ _slang_new_ir_storage(enum register_file file, GLint index, GLint size); extern GLboolean _slang_emit_code(slang_ir_node *n, slang_var_table *vartable, - struct gl_program *prog, GLboolean withEnd); + struct gl_program *prog, GLboolean withEnd, + slang_info_log *log); #endif /* SLANG_EMIT_H */ diff --git a/src/mesa/shader/slang/slang_preprocess.h b/src/mesa/shader/slang/slang_preprocess.h index f83e6e6e3f..d8eb12e4ff 100644 --- a/src/mesa/shader/slang/slang_preprocess.h +++ b/src/mesa/shader/slang/slang_preprocess.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.6 + * Version: 6.5.3 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2007 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"), @@ -22,24 +22,19 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined SLANG_PREPROCESS_H +#ifndef SLANG_PREPROCESS_H #define SLANG_PREPROCESS_H #include "slang_compile.h" +#include "slang_log.h" -#if defined __cplusplus -extern "C" { -#endif -GLboolean +extern GLboolean _slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *); -GLboolean -_slang_preprocess_directives (slang_string *output, const char *input, slang_info_log *); +extern GLboolean +_slang_preprocess_directives (slang_string *output, const char *input, + slang_info_log *); -#ifdef __cplusplus -} -#endif - -#endif +#endif /* SLANG_PREPROCESS_H */ diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 07b4ae2760..87b117874f 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -292,7 +292,7 @@ _slang_simplify(slang_operation *oper, GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, const slang_name_space * space, - slang_atom_pool * atoms) + slang_atom_pool * atoms, slang_info_log *log) { const GLboolean haveRetValue = _slang_function_has_return_value(fun); const int numParams = fun->param_count - haveRetValue; @@ -317,7 +317,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, - &argType, atoms)) { + &argType, atoms, log)) { slang_typeinfo_destruct(&argType); return GL_FALSE; } @@ -392,7 +392,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, - &argType, atoms)) { + &argType, atoms, log)) { slang_typeinfo_destruct(&argType); return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index d6979a800a..b3840ee9df 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -16,8 +16,7 @@ _slang_simplify(slang_operation *oper, extern GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, const slang_name_space * space, - slang_atom_pool * atoms); - + slang_atom_pool * atoms, slang_info_log *log); #endif /* SLANG_SIMPLIFY_H */ diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index bbcc1c740c..fe3834994d 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -31,7 +31,7 @@ #include "imports.h" #include "slang_typeinfo.h" #include "slang_compile.h" -#include "slang_error.h" +#include "slang_log.h" #include "prog_instruction.h" @@ -302,14 +302,15 @@ typeof_existing_function(const char *name, const slang_operation * params, GLuint num_params, const slang_name_space * space, slang_type_specifier * spec, - slang_atom_pool * atoms) + slang_atom_pool * atoms, + slang_info_log *log) { slang_atom atom; GLboolean exists; atom = slang_atom_pool_atom(atoms, name); if (!_slang_typeof_function(atom, params, num_params, space, spec, - &exists, atoms)) + &exists, atoms, log)) return GL_FALSE; return exists; } @@ -319,7 +320,7 @@ _slang_typeof_operation(const slang_assemble_ctx * A, const slang_operation * op, slang_typeinfo * ti) { - return _slang_typeof_operation_(op, &A->space, ti, A->atoms); + return _slang_typeof_operation_(op, &A->space, ti, A->atoms, A->log); } @@ -335,7 +336,8 @@ GLboolean _slang_typeof_operation_(const slang_operation * op, const slang_name_space * space, slang_typeinfo * ti, - slang_atom_pool * atoms) + slang_atom_pool * atoms, + slang_info_log *log) { ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; @@ -364,7 +366,7 @@ _slang_typeof_operation_(const slang_operation * op, case SLANG_OPER_DIVASSIGN: case SLANG_OPER_PREINCREMENT: case SLANG_OPER_PREDECREMENT: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) return GL_FALSE; break; case SLANG_OPER_LITERAL_BOOL: @@ -431,18 +433,24 @@ _slang_typeof_operation_(const slang_operation * op, { slang_variable *var; var = _slang_locate_variable(op->locals, op->a_id, GL_TRUE); - if (var == NULL) - RETURN_ERROR2("undefined variable", (char *) op->a_id, 0); - if (!slang_type_specifier_copy(&ti->spec, &var->type.specifier)) - RETURN_OUT_OF_MEMORY(); + if (!var) { + slang_info_log_error(log, "undefined variable '%s'", + (char *) op->a_id); + return GL_FALSE; + } + if (!slang_type_specifier_copy(&ti->spec, &var->type.specifier)) { + slang_info_log_memory(log); + return GL_FALSE; + } ti->can_be_referenced = GL_TRUE; ti->array_len = var->array_len; } break; case SLANG_OPER_SEQUENCE: /* TODO: check [0] and [1] if they match */ - if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms, log)) { + return GL_FALSE; + } ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; @@ -454,8 +462,9 @@ _slang_typeof_operation_(const slang_operation * op, /*case SLANG_OPER_ANDASSIGN: */ case SLANG_OPER_SELECT: /* TODO: check [1] and [2] if they match */ - if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms, log)) { + return GL_FALSE; + } ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; @@ -466,35 +475,35 @@ _slang_typeof_operation_(const slang_operation * op, /*case SLANG_OPER_RSHIFT: */ case SLANG_OPER_ADD: if (!typeof_existing_function("+", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_SUBTRACT: if (!typeof_existing_function("-", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_MULTIPLY: if (!typeof_existing_function("*", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_DIVIDE: if (!typeof_existing_function("/", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; /*case SLANG_OPER_MODULUS: */ case SLANG_OPER_PLUS: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) + return GL_FALSE; ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; case SLANG_OPER_MINUS: if (!typeof_existing_function("-", op->children, 1, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; /*case SLANG_OPER_COMPLEMENT: */ case SLANG_OPER_SUBSCRIPT: @@ -502,23 +511,24 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo _ti; if (!slang_typeinfo_construct(&_ti)) - RETURN_NIL(); - if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { + return GL_FALSE; + if (!_slang_typeof_operation_(op->children, space, &_ti, atoms, log)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } ti->can_be_referenced = _ti.can_be_referenced; if (_ti.spec.type == SLANG_SPEC_ARRAY) { if (!slang_type_specifier_copy(&ti->spec, _ti.spec._array)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } } else { if (!_slang_type_is_vector(_ti.spec.type) && !_slang_type_is_matrix(_ti.spec.type)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("cannot index a non-array type", 0); + slang_info_log_error(log, "cannot index a non-array type"); + return GL_FALSE; } ti->spec.type = _slang_type_base(_ti.spec.type); } @@ -530,8 +540,8 @@ _slang_typeof_operation_(const slang_operation * op, GLboolean exists; if (!_slang_typeof_function(op->a_id, op->children, op->num_children, - space, &ti->spec, &exists, atoms)) - RETURN_NIL(); + space, &ti->spec, &exists, atoms, log)) + return GL_FALSE; if (!exists) { slang_struct *s = slang_struct_scope_find(space->structs, op->a_id, GL_TRUE); @@ -540,14 +550,14 @@ _slang_typeof_operation_(const slang_operation * op, ti->spec._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); if (ti->spec._struct == NULL) - RETURN_NIL(); + return GL_FALSE; if (!slang_struct_construct(ti->spec._struct)) { slang_alloc_free(ti->spec._struct); ti->spec._struct = NULL; - RETURN_NIL(); + return GL_FALSE; } if (!slang_struct_copy(ti->spec._struct, s)) - RETURN_NIL(); + return GL_FALSE; } else { const char *name; @@ -555,8 +565,10 @@ _slang_typeof_operation_(const slang_operation * op, name = slang_atom_pool_id(atoms, op->a_id); type = slang_type_specifier_type_from_string(name); - if (type == SLANG_SPEC_VOID) - RETURN_ERROR2("function not found", name, 0); + if (type == SLANG_SPEC_VOID) { + slang_info_log_error(log, "undefined function '%s'", name); + return GL_FALSE; + } ti->spec.type = type; } } @@ -567,10 +579,10 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo _ti; if (!slang_typeinfo_construct(&_ti)) - RETURN_NIL(); - if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { + return GL_FALSE; + if (!_slang_typeof_operation_(op->children, space, &_ti, atoms, log)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } if (_ti.spec.type == SLANG_SPEC_STRUCT) { slang_variable *field; @@ -579,11 +591,11 @@ _slang_typeof_operation_(const slang_operation * op, GL_FALSE); if (field == NULL) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } if (!slang_type_specifier_copy(&ti->spec, &field->type.specifier)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } ti->can_be_referenced = _ti.can_be_referenced; } @@ -593,17 +605,19 @@ _slang_typeof_operation_(const slang_operation * op, slang_type_specifier_type base; /* determine the swizzle of the field expression */ -#if 000 +#if 000 /*XXX re-enable? */ if (!_slang_type_is_vector(_ti.spec.type)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("Can't swizzle scalar expression", 0); + slang_info_log_error(log, "Can't swizzle scalar expression"); + return GL_FALSE; } #endif rows = _slang_type_dim(_ti.spec.type); swizzle = slang_atom_pool_id(atoms, op->a_id); if (!_slang_is_swizzle(swizzle, rows, &ti->swz)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(log, "bad swizzle '%s'", swizzle); + return GL_FALSE; } ti->is_swizzled = GL_TRUE; ti->can_be_referenced = _ti.can_be_referenced @@ -674,13 +688,13 @@ _slang_typeof_operation_(const slang_operation * op, break; case SLANG_OPER_POSTINCREMENT: case SLANG_OPER_POSTDECREMENT: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) + return GL_FALSE; ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; default: - RETURN_NIL(); + return GL_FALSE; } return GL_TRUE; @@ -693,7 +707,8 @@ _slang_typeof_operation_(const slang_operation * op, slang_function * _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, const slang_operation * args, GLuint num_args, - const slang_name_space * space, slang_atom_pool * atoms) + const slang_name_space * space, slang_atom_pool * atoms, + slang_info_log *log) { GLuint i; @@ -713,7 +728,7 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, if (!slang_typeinfo_construct(&ti)) return NULL; - if (!_slang_typeof_operation_(&args[j], space, &ti, atoms)) { + if (!_slang_typeof_operation_(&args[j], space, &ti, atoms, log)) { slang_typeinfo_destruct(&ti); return NULL; } @@ -737,7 +752,7 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, } if (funcs->outer_scope != NULL) return _slang_locate_function(funcs->outer_scope, a_name, args, - num_args, space, atoms); + num_args, space, atoms, log); return NULL; } @@ -757,10 +772,10 @@ _slang_typeof_function(slang_atom a_name, const slang_operation * params, GLuint num_params, const slang_name_space * space, slang_type_specifier * spec, GLboolean * exists, - slang_atom_pool * atoms) + slang_atom_pool *atoms, slang_info_log *log) { slang_function *fun = _slang_locate_function(space->funcs, a_name, params, - num_params, space, atoms); + num_params, space, atoms, log); *exists = fun != NULL; if (!fun) return GL_TRUE; /* yes, not false */ diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index 3115b71e08..62cf0009d3 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -27,6 +27,7 @@ #include "imports.h" #include "mtypes.h" +#include "slang_log.h" #include "slang_utility.h" #include "slang_vartable.h" @@ -60,6 +61,7 @@ typedef struct slang_assemble_ctx_ slang_name_space space; struct gl_program *program; slang_var_table *vartable; + slang_info_log *log; struct slang_function_ *CurFunction; struct slang_ir_node_ *CurLoop; } slang_assemble_ctx; @@ -70,7 +72,7 @@ _slang_locate_function(const struct slang_function_scope_ *funcs, slang_atom name, const struct slang_operation_ *params, GLuint num_params, const slang_name_space *space, - slang_atom_pool *); + slang_atom_pool *atoms, slang_info_log *log); extern GLboolean @@ -170,7 +172,8 @@ _slang_typeof_operation(const slang_assemble_ctx *, extern GLboolean _slang_typeof_operation_(const struct slang_operation_ *, const slang_name_space *, - slang_typeinfo *, slang_atom_pool *); + slang_typeinfo *, slang_atom_pool *, + slang_info_log *log); /** * Retrieves type of a function prototype, if one exists. @@ -182,7 +185,7 @@ _slang_typeof_function(slang_atom a_name, const struct slang_operation_ *params, GLuint num_params, const slang_name_space *, slang_type_specifier *spec, GLboolean *exists, - slang_atom_pool *); + slang_atom_pool *, slang_info_log *log); extern GLboolean _slang_type_is_matrix(slang_type_specifier_type); diff --git a/src/mesa/sources b/src/mesa/sources index a7bbc02012..628599c3c5 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -179,10 +179,10 @@ SLANG_SOURCES = \ shader/slang/slang_compile_struct.c \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ - shader/slang/slang_error.c \ shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_link.c \ + shader/slang/slang_log.c \ shader/slang/slang_preprocess.c \ shader/slang/slang_print.c \ shader/slang/slang_simplify.c \ -- cgit v1.2.3 From dc3015f1574f26704c3498c56915b5570d777da4 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 24 Mar 2007 09:40:20 -0600 Subject: move some code into new slang_ir.c file --- src/mesa/shader/slang/slang_codegen.c | 22 +-- src/mesa/shader/slang/slang_emit.c | 315 +--------------------------------- src/mesa/shader/slang/slang_ir.h | 26 +++ src/mesa/sources | 1 + 4 files changed, 30 insertions(+), 334 deletions(-) (limited to 'src/mesa/sources') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 2eb509b4d1..2210b95ef2 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -402,24 +402,6 @@ static slang_asm_info AsmInfo[] = { }; -/** - * Recursively free an IR tree. - */ -static void -_slang_free_ir_tree(slang_ir_node *n) -{ -#if 1 - GLuint i; - if (!n) - return; - for (i = 0; i < 3; i++) - _slang_free_ir_tree(n->Children[i]); - /* Do not free n->List since it's a child elsewhere */ - free(n); -#endif -} - - static slang_ir_node * new_node3(slang_ir_opcode op, slang_ir_node *c0, slang_ir_node *c1, slang_ir_node *c2) @@ -1639,7 +1621,7 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) tree = new_seq(ifNode, tmpVar); tree = new_seq(tmpDecl, tree); - slang_print_ir(tree, 10); + /*_slang_print_ir_tree(tree, 10);*/ return tree; } @@ -2835,7 +2817,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #endif #if 0 printf("************* IR for %s *******\n", (char*)fun->header.a_name); - slang_print_ir(n, 0); + _slang_print_ir_tree(n, 0); #endif #if 0 printf("************* End codegen function ************\n\n"); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 6ec20daabb..ace68d1f05 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -66,102 +66,6 @@ typedef struct } slang_emit_info; -/** - * Assembly and IR info - */ -typedef struct -{ - slang_ir_opcode IrOpcode; - const char *IrName; - gl_inst_opcode InstOpcode; - GLuint ResultSize, NumParams; -} slang_ir_info; - - - -static const slang_ir_info IrInfo[] = { - /* binary ops */ - { IR_ADD, "IR_ADD", OPCODE_ADD, 4, 2 }, - { IR_SUB, "IR_SUB", OPCODE_SUB, 4, 2 }, - { IR_MUL, "IR_MUL", OPCODE_MUL, 4, 2 }, - { IR_DIV, "IR_DIV", OPCODE_NOP, 0, 2 }, /* XXX broke */ - { IR_DOT4, "IR_DOT_4", OPCODE_DP4, 1, 2 }, - { IR_DOT3, "IR_DOT_3", OPCODE_DP3, 1, 2 }, - { IR_CROSS, "IR_CROSS", OPCODE_XPD, 3, 2 }, - { IR_LRP, "IR_LRP", OPCODE_LRP, 4, 3 }, - { IR_MIN, "IR_MIN", OPCODE_MIN, 4, 2 }, - { IR_MAX, "IR_MAX", OPCODE_MAX, 4, 2 }, - { IR_CLAMP, "IR_CLAMP", OPCODE_NOP, 4, 3 }, /* special case: emit_clamp() */ - { IR_SEQUAL, "IR_SEQUAL", OPCODE_SEQ, 4, 2 }, - { IR_SNEQUAL, "IR_SNEQUAL", OPCODE_SNE, 4, 2 }, - { IR_SGE, "IR_SGE", OPCODE_SGE, 4, 2 }, - { IR_SGT, "IR_SGT", OPCODE_SGT, 4, 2 }, - { IR_SLE, "IR_SLE", OPCODE_SLE, 4, 2 }, - { IR_SLT, "IR_SLT", OPCODE_SLT, 4, 2 }, - { IR_POW, "IR_POW", OPCODE_POW, 1, 2 }, - /* unary ops */ - { IR_I_TO_F, "IR_I_TO_F", OPCODE_NOP, 1, 1 }, - { IR_F_TO_I, "IR_F_TO_I", OPCODE_INT, 4, 1 }, /* 4 floats to 4 ints */ - { IR_EXP, "IR_EXP", OPCODE_EXP, 1, 1 }, - { IR_EXP2, "IR_EXP2", OPCODE_EX2, 1, 1 }, - { IR_LOG2, "IR_LOG2", OPCODE_LG2, 1, 1 }, - { IR_RSQ, "IR_RSQ", OPCODE_RSQ, 1, 1 }, - { IR_RCP, "IR_RCP", OPCODE_RCP, 1, 1 }, - { IR_FLOOR, "IR_FLOOR", OPCODE_FLR, 4, 1 }, - { IR_FRAC, "IR_FRAC", OPCODE_FRC, 4, 1 }, - { IR_ABS, "IR_ABS", OPCODE_ABS, 4, 1 }, - { IR_NEG, "IR_NEG", OPCODE_NOP, 4, 1 }, /* special case: emit_negation() */ - { IR_DDX, "IR_DDX", OPCODE_DDX, 4, 1 }, - { IR_DDX, "IR_DDY", OPCODE_DDX, 4, 1 }, - { IR_SIN, "IR_SIN", OPCODE_SIN, 1, 1 }, - { IR_COS, "IR_COS", OPCODE_COS, 1, 1 }, - { IR_NOISE1, "IR_NOISE1", OPCODE_NOISE1, 1, 1 }, - { IR_NOISE2, "IR_NOISE2", OPCODE_NOISE2, 1, 1 }, - { IR_NOISE3, "IR_NOISE3", OPCODE_NOISE3, 1, 1 }, - { IR_NOISE4, "IR_NOISE4", OPCODE_NOISE4, 1, 1 }, - - /* other */ - { IR_SEQ, "IR_SEQ", OPCODE_NOP, 0, 0 }, - { IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 }, - { IR_LABEL, "IR_LABEL", OPCODE_NOP, 0, 0 }, - { IR_JUMP, "IR_JUMP", OPCODE_NOP, 0, 0 }, - { IR_IF, "IR_IF", OPCODE_NOP, 0, 0 }, - { IR_KILL, "IR_KILL", OPCODE_NOP, 0, 0 }, - { IR_COND, "IR_COND", OPCODE_NOP, 0, 0 }, - { IR_CALL, "IR_CALL", OPCODE_NOP, 0, 0 }, - { IR_MOVE, "IR_MOVE", OPCODE_NOP, 0, 1 }, - { IR_NOT, "IR_NOT", OPCODE_NOP, 1, 1 }, - { IR_VAR, "IR_VAR", OPCODE_NOP, 0, 0 }, - { IR_VAR_DECL, "IR_VAR_DECL", OPCODE_NOP, 0, 0 }, - { IR_TEX, "IR_TEX", OPCODE_TEX, 4, 1 }, - { IR_TEXB, "IR_TEXB", OPCODE_TXB, 4, 1 }, - { IR_TEXP, "IR_TEXP", OPCODE_TXP, 4, 1 }, - { IR_FLOAT, "IR_FLOAT", OPCODE_NOP, 0, 0 }, /* float literal */ - { IR_FIELD, "IR_FIELD", OPCODE_NOP, 0, 0 }, - { IR_ELEMENT, "IR_ELEMENT", OPCODE_NOP, 0, 0 }, - { IR_SWIZZLE, "IR_SWIZZLE", OPCODE_NOP, 0, 0 }, - { IR_NOP, NULL, OPCODE_NOP, 0, 0 } -}; - - -static const slang_ir_info * -slang_find_ir_info(slang_ir_opcode opcode) -{ - GLuint i; - for (i = 0; IrInfo[i].IrName; i++) { - if (IrInfo[i].IrOpcode == opcode) { - return IrInfo + i; - } - } - return NULL; -} - -static const char * -slang_ir_name(slang_ir_opcode opcode) -{ - return slang_find_ir_info(opcode)->IrName; -} - /** * Swizzle a swizzle. That is, return swz2(swz1) @@ -194,221 +98,6 @@ _slang_new_ir_storage(enum register_file file, GLint index, GLint size) } -static const char * -swizzle_string(GLuint swizzle) -{ - static char s[6]; - GLuint i; - s[0] = '.'; - for (i = 1; i < 5; i++) { - s[i] = "xyzw"[GET_SWZ(swizzle, i-1)]; - } - s[i] = 0; - return s; -} - -static const char * -writemask_string(GLuint writemask) -{ - static char s[6]; - GLuint i, j = 0; - s[j++] = '.'; - for (i = 0; i < 4; i++) { - if (writemask & (1 << i)) - s[j++] = "xyzw"[i]; - } - s[j] = 0; - return s; -} - -static const char * -storage_string(const slang_ir_storage *st) -{ - static const char *files[] = { - "TEMP", - "LOCAL_PARAM", - "ENV_PARAM", - "STATE", - "INPUT", - "OUTPUT", - "NAMED_PARAM", - "CONSTANT", - "UNIFORM", - "WRITE_ONLY", - "ADDRESS", - "SAMPLER", - "UNDEFINED" - }; - static char s[100]; -#if 0 - if (st->Size == 1) - sprintf(s, "%s[%d]", files[st->File], st->Index); - else - sprintf(s, "%s[%d..%d]", files[st->File], st->Index, - st->Index + st->Size - 1); -#endif - assert(st->File < (GLint) (sizeof(files) / sizeof(files[0]))); - sprintf(s, "%s[%d]", files[st->File], st->Index); - return s; -} - - -static void -spaces(int n) -{ - while (n-- > 0) { - printf(" "); - } -} - -#define IND 0 -void -slang_print_ir(const slang_ir_node *n, int indent) -{ - if (!n) - return; -#if !IND - if (n->Opcode != IR_SEQ) -#else - printf("%3d:", indent); -#endif - spaces(indent); - - switch (n->Opcode) { - case IR_SEQ: -#if IND - printf("SEQ at %p\n", (void*) n); -#endif - assert(n->Children[0]); - assert(n->Children[1]); - slang_print_ir(n->Children[0], indent + IND); - slang_print_ir(n->Children[1], indent + IND); - break; - case IR_SCOPE: - printf("NEW SCOPE\n"); - assert(!n->Children[1]); - slang_print_ir(n->Children[0], indent + 3); - break; - case IR_MOVE: - printf("MOVE (writemask = %s)\n", writemask_string(n->Writemask)); - slang_print_ir(n->Children[0], indent+3); - slang_print_ir(n->Children[1], indent+3); - break; - case IR_LABEL: - printf("LABEL: %s\n", n->Label->Name); - break; - case IR_COND: - printf("COND\n"); - slang_print_ir(n->Children[0], indent + 3); - break; - case IR_JUMP: - printf("JUMP %s\n", n->Label->Name); - break; - - case IR_IF: - printf("IF \n"); - slang_print_ir(n->Children[0], indent+3); - spaces(indent); - printf("THEN\n"); - slang_print_ir(n->Children[1], indent+3); - if (n->Children[2]) { - spaces(indent); - printf("ELSE\n"); - slang_print_ir(n->Children[2], indent+3); - } - spaces(indent); - printf("ENDIF\n"); - break; - - case IR_BEGIN_SUB: - printf("BEGIN_SUB\n"); - break; - case IR_END_SUB: - printf("END_SUB\n"); - break; - case IR_RETURN: - printf("RETURN\n"); - break; - case IR_CALL: - printf("CALL\n"); - break; - - case IR_LOOP: - printf("LOOP\n"); - slang_print_ir(n->Children[0], indent+3); - if (n->Children[1]) { - spaces(indent); - printf("TAIL:\n"); - slang_print_ir(n->Children[1], indent+3); - } - spaces(indent); - printf("ENDLOOP\n"); - break; - case IR_CONT: - printf("CONT\n"); - break; - case IR_BREAK: - printf("BREAK\n"); - break; - case IR_BREAK_IF_FALSE: - printf("BREAK_IF_FALSE\n"); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_BREAK_IF_TRUE: - printf("BREAK_IF_TRUE\n"); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_CONT_IF_FALSE: - printf("CONT_IF_FALSE\n"); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_CONT_IF_TRUE: - printf("CONT_IF_TRUE\n"); - slang_print_ir(n->Children[0], indent+3); - break; - - case IR_VAR: - printf("VAR %s%s at %s store %p\n", - (n->Var ? (char *) n->Var->a_name : "TEMP"), - swizzle_string(n->Store->Swizzle), - storage_string(n->Store), (void*) n->Store); - break; - case IR_VAR_DECL: - printf("VAR_DECL %s (%p) at %s store %p\n", - (n->Var ? (char *) n->Var->a_name : "TEMP"), - (void*) n->Var, storage_string(n->Store), - (void*) n->Store); - break; - case IR_FIELD: - printf("FIELD %s of\n", n->Field); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_FLOAT: - printf("FLOAT %g %g %g %g\n", - n->Value[0], n->Value[1], n->Value[2], n->Value[3]); - break; - case IR_I_TO_F: - printf("INT_TO_FLOAT\n"); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_F_TO_I: - printf("FLOAT_TO_INT\n"); - slang_print_ir(n->Children[0], indent+3); - break; - case IR_SWIZZLE: - printf("SWIZZLE %s of (store %p) \n", - swizzle_string(n->Store->Swizzle), (void*) n->Store); - slang_print_ir(n->Children[0], indent + 3); - break; - default: - printf("%s (%p, %p) (store %p)\n", slang_ir_name(n->Opcode), - (void*) n->Children[0], (void*) n->Children[1], (void*) n->Store); - slang_print_ir(n->Children[0], indent+3); - slang_print_ir(n->Children[1], indent+3); - } -} - - /** * Allocate temporary storage for an intermediate result (such as for * a multiply or add, etc. @@ -713,7 +402,7 @@ static struct prog_instruction * emit_arith(slang_emit_info *emitInfo, slang_ir_node *n) { struct prog_instruction *inst; - const slang_ir_info *info = slang_find_ir_info(n->Opcode); + const slang_ir_info *info = _slang_ir_info(n->Opcode); char *srcAnnot[3], *dstAnnot; GLuint i; @@ -1347,8 +1036,6 @@ emit_loop(slang_emit_info *emitInfo, slang_ir_node *n) GLuint beginInstLoc, tailInstLoc, endInstLoc; slang_ir_node *ir; - slang_print_ir(n, 10); - /* emit OPCODE_BGNLOOP */ beginInstLoc = prog->NumInstructions; if (emitInfo->EmitHighLevelInstructions) { diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h index 37dd38eaa5..2b7d822932 100644 --- a/src/mesa/shader/slang/slang_ir.h +++ b/src/mesa/shader/slang/slang_ir.h @@ -175,4 +175,30 @@ typedef struct slang_ir_node_ } slang_ir_node; + +/** + * Assembly and IR info + */ +typedef struct +{ + slang_ir_opcode IrOpcode; + const char *IrName; + gl_inst_opcode InstOpcode; + GLuint ResultSize, NumParams; +} slang_ir_info; + + + +extern const slang_ir_info * +_slang_ir_info(slang_ir_opcode opcode); + + +extern void +_slang_free_ir_tree(slang_ir_node *n); + + +extern void +_slang_print_ir_tree(const slang_ir_node *n, int indent); + + #endif /* SLANG_IR_H */ diff --git a/src/mesa/sources b/src/mesa/sources index 628599c3c5..73fd58125a 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -179,6 +179,7 @@ SLANG_SOURCES = \ shader/slang/slang_compile_struct.c \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ + shader/slang/slang_ir.c \ shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_link.c \ -- cgit v1.2.3