diff options
Diffstat (limited to 'src/mesa/shader')
-rw-r--r-- | src/mesa/shader/arbprogparse.c | 23 | ||||
-rw-r--r-- | src/mesa/shader/arbprogram.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/descrip.mms | 95 | ||||
-rw-r--r-- | src/mesa/shader/grammar/grammar_crt.c | 10 | ||||
-rw-r--r-- | src/mesa/shader/grammar/sources | 8 | ||||
-rw-r--r-- | src/mesa/shader/nvfragparse.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/nvprogram.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/prog_execute.c | 3 | ||||
-rw-r--r-- | src/mesa/shader/prog_statevars.c | 119 | ||||
-rw-r--r-- | src/mesa/shader/prog_statevars.h | 13 | ||||
-rw-r--r-- | src/mesa/shader/prog_uniform.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/program.c | 122 | ||||
-rw-r--r-- | src/mesa/shader/program.h | 16 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.c | 53 | ||||
-rw-r--r-- | src/mesa/shader/slang/descrip.mms | 68 | ||||
-rw-r--r--[-rwxr-xr-x] | src/mesa/shader/slang/library/slang_pp_directives.syn | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/mesa/shader/slang/library/slang_pp_expression.syn | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/mesa/shader/slang/library/slang_version.syn | 0 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_link.c | 1 | ||||
-rw-r--r-- | src/mesa/shader/slang/sources | 44 | ||||
-rw-r--r-- | src/mesa/shader/sources | 28 |
21 files changed, 458 insertions, 157 deletions
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 4d89d057c7d..536404bf978 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -53,23 +53,17 @@ having three separate program parameter arrays. #include "main/glheader.h" #include "main/imports.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/mtypes.h" #include "shader/grammar/grammar_mesa.h" #include "arbprogparse.h" #include "program.h" #include "programopt.h" #include "prog_parameter.h" #include "prog_statevars.h" -#include "main/context.h" -#include "main/macros.h" -#include "main/mtypes.h" #include "prog_instruction.h" - -/* For ARB programs, use the NV instruction limits */ -#define MAX_INSTRUCTIONS MAX2(MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS, \ - MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS) - - /** * This is basically a union of the vertex_program and fragment_program * structs that we can use to parse the program into @@ -3443,6 +3437,8 @@ parse_instructions(GLcontext * ctx, const GLubyte * inst, : ctx->Const.VertexProgram.MaxInstructions; GLint err = 0; + ASSERT(MAX_PROGRAM_INSTRUCTIONS >= maxInst); + Program->MajorVersion = (GLuint) * inst++; Program->MinorVersion = (GLuint) * inst++; @@ -3796,7 +3792,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, /* Initialize the arb_program struct */ program->Base.String = strz; - program->Base.Instructions = _mesa_alloc_instructions(MAX_INSTRUCTIONS); + program->Base.Instructions = _mesa_alloc_instructions(MAX_PROGRAM_INSTRUCTIONS); program->Base.NumInstructions = program->Base.NumTemporaries = program->Base.NumParameters = @@ -3841,12 +3837,12 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, _mesa_free (parsed); - /* Reallocate the instruction array from size [MAX_INSTRUCTIONS] + /* Reallocate the instruction array from size [MAX_PROGRAM_INSTRUCTIONS] * to size [ap.Base.NumInstructions]. */ program->Base.Instructions = _mesa_realloc_instructions(program->Base.Instructions, - MAX_INSTRUCTIONS, + MAX_PROGRAM_INSTRUCTIONS, program->Base.NumInstructions); return !err; @@ -3899,6 +3895,9 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, program->FogOption = ap.FogOption; program->UsesKill = ap.UsesKill; + if (program->FogOption) + program->Base.InputsRead |= FRAG_BIT_FOGC; + if (program->Base.Instructions) _mesa_free(program->Base.Instructions); program->Base.Instructions = ap.Base.Instructions; diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c index beb5deea505..760dac23993 100644 --- a/src/mesa/shader/arbprogram.c +++ b/src/mesa/shader/arbprogram.c @@ -30,13 +30,13 @@ #include "main/glheader.h" -#include "arbprogram.h" -#include "arbprogparse.h" #include "main/context.h" #include "main/hash.h" #include "main/imports.h" #include "main/macros.h" #include "main/mtypes.h" +#include "arbprogram.h" +#include "arbprogparse.h" #include "program.h" diff --git a/src/mesa/shader/descrip.mms b/src/mesa/shader/descrip.mms new file mode 100644 index 00000000000..19bafd48302 --- /dev/null +++ b/src/mesa/shader/descrip.mms @@ -0,0 +1,95 @@ +# Makefile for core library for VMS +# contributed by Jouk Jansen [email protected] +# Last revision : 29 September 2008 +.first + define gl [---.include.gl] + define math [-.math] + define swrast [-.swrast] + define array_cache [-.array_cache] + define glapi [-.glapi] + define main [-.main] + define shader [-.shader] + +.include [---]mms-config. + +##### MACROS ##### + +VPATH = RCS + +INCDIR = [---.include],[.grammar],[-.main],[-.glapi],[.slang] +LIBDIR = [---.lib] +CFLAGS = /include=($(INCDIR),[])/define=(PTHREADS=1,"__extension__=")/name=(as_is,short)/float=ieee/ieee=denorm + +SOURCES = \ + atifragshader.c \ + arbprogparse.c \ + arbprogram.c \ + nvfragparse.c \ + nvprogram.c \ + nvvertparse.c \ + program.c \ + programopt.c \ + prog_debug.c \ + prog_execute.c \ + prog_instruction.c \ + prog_parameter.c \ + prog_print.c \ + prog_cache.c \ + prog_statevars.c \ + shader_api.c prog_uniform.c + +OBJECTS = \ + atifragshader.obj,\ + arbprogparse.obj,\ + arbprogram.obj,\ + nvfragparse.obj,\ + nvprogram.obj,\ + nvvertparse.obj,\ + program.obj,\ + programopt.obj,\ + prog_debug.obj,\ + prog_execute.obj,\ + prog_instruction.obj,\ + prog_parameter.obj,\ + prog_print.obj,\ + prog_statevars.obj,\ + shader_api.obj,prog_uniform.obj,prog_cache.obj + +##### RULES ##### + +VERSION=Mesa V3.4 + +##### TARGETS ##### +all : + $(MMS)$(MMSQUALIFIERS) $(LIBDIR)$(GL_LIB) + set def [.slang] + $(MMS)$(MMSQUALIFIERS) + set def [-.grammar] + $(MMS)$(MMSQUALIFIERS) + set def [-] + +# Make the library +$(LIBDIR)$(GL_LIB) : $(OBJECTS) + @ library $(LIBDIR)$(GL_LIB) $(OBJECTS) + +clean : + purge + delete *.obj;* + +atifragshader.obj : atifragshader.c +arbprogparse.obj : arbprogparse.c +arbprogram.obj : arbprogram.c +nvfragparse.obj : nvfragparse.c +nvprogram.obj : nvprogram.c +nvvertparse.obj : nvvertparse.c +program.obj : program.c +programopt. obj : programopt.c +prog_debug.obj : prog_debug.c +prog_execute.obj : prog_execute.c +prog_instruction.obj : prog_instruction.c +prog_parameter.obj : prog_parameter.c +prog_print.obj : prog_print.c +prog_statevars.obj : prog_statevars.c +shader_api.obj : shader_api.c +prog_uniform.obj : prog_uniform.c +prog_cache.obj : prog_cache.c diff --git a/src/mesa/shader/grammar/grammar_crt.c b/src/mesa/shader/grammar/grammar_crt.c index bdf2da9b2e2..d2c95d1c8e7 100644 --- a/src/mesa/shader/grammar/grammar_crt.c +++ b/src/mesa/shader/grammar/grammar_crt.c @@ -10,17 +10,17 @@ void grammar_alloc_free (void *ptr) free (ptr); } -void *grammar_alloc_malloc (unsigned int size) +void *grammar_alloc_malloc (size_t size) { return malloc (size); } -void *grammar_alloc_realloc (void *ptr, unsigned int old_size, unsigned int size) +void *grammar_alloc_realloc (void *ptr, size_t old_size, size_t size) { return realloc (ptr, size); } -void *grammar_memory_copy (void *dst, const void * src, unsigned int size) +void *grammar_memory_copy (void *dst, const void * src, size_t size) { return memcpy (dst, src, size); } @@ -30,7 +30,7 @@ int grammar_string_compare (const byte *str1, const byte *str2) return strcmp ((const char *) str1, (const char *) str2); } -int grammar_string_compare_n (const byte *str1, const byte *str2, unsigned int n) +int grammar_string_compare_n (const byte *str1, const byte *str2, size_t n) { return strncmp ((const char *) str1, (const char *) str2, n); } @@ -40,7 +40,7 @@ byte *grammar_string_copy (byte *dst, const byte *src) return (byte *) strcpy ((char *) dst, (const char *) src); } -byte *grammar_string_copy_n (byte *dst, const byte *src, unsigned int n) +byte *grammar_string_copy_n (byte *dst, const byte *src, size_t n) { return (byte *) strncpy ((char *) dst, (const char *) src, n); } diff --git a/src/mesa/shader/grammar/sources b/src/mesa/shader/grammar/sources deleted file mode 100644 index a6bbfd3ffd3..00000000000 --- a/src/mesa/shader/grammar/sources +++ /dev/null @@ -1,8 +0,0 @@ -MESA_SHADER_GRAMMAR_SOURCES = \ -grammar_mesa.c - -MESA_SHADER_GRAMMAR_HEADERS = \ -grammar.c \ -grammar.h \ -grammar_mesa.h \ -grammar_syn.h diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index a2a7a5f3f49..20e47813729 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -41,10 +41,10 @@ #include "main/context.h" #include "main/imports.h" #include "main/macros.h" +#include "program.h" #include "prog_parameter.h" #include "prog_instruction.h" #include "nvfragparse.h" -#include "program.h" #define INPUT_1V 1 diff --git a/src/mesa/shader/nvprogram.c b/src/mesa/shader/nvprogram.c index d656d4b28b6..88272fff3ff 100644 --- a/src/mesa/shader/nvprogram.c +++ b/src/mesa/shader/nvprogram.c @@ -42,12 +42,12 @@ #include "main/hash.h" #include "main/imports.h" #include "main/macros.h" +#include "program.h" #include "prog_parameter.h" #include "prog_instruction.h" #include "nvfragparse.h" #include "nvvertparse.h" #include "nvprogram.h" -#include "program.h" diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c index 768e936d5f6..23648f3f4ca 100644 --- a/src/mesa/shader/prog_execute.c +++ b/src/mesa/shader/prog_execute.c @@ -91,7 +91,8 @@ get_register_pointer(const struct prog_src_register *source, const struct gl_program_parameter_list *params; ASSERT(source->File == PROGRAM_LOCAL_PARAM || source->File == PROGRAM_CONSTANT || - source->File == PROGRAM_STATE_VAR); + source->File == PROGRAM_STATE_VAR || + source->File == PROGRAM_UNIFORM); params = machine->CurProgram->Parameters; if (reg < 0 || reg >= (GLint)params->NumParameters) return ZeroVec; diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c index 9cc33fa2c11..34c47413506 100644 --- a/src/mesa/shader/prog_statevars.c +++ b/src/mesa/shader/prog_statevars.c @@ -131,7 +131,7 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], ADD_3V(value, p, eye_z); NORMALIZE_3FV(value); value[3] = 1.0; - } + } return; default: _mesa_problem(ctx, "Invalid light state in fetch_state"); @@ -235,11 +235,11 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], } } case STATE_TEXENV_COLOR: - { + { /* state[1] is the texture unit */ const GLuint unit = (GLuint) state[1]; COPY_4V(value, ctx->Texture.Unit[unit].EnvColor); - } + } return; case STATE_FOG_COLOR: COPY_4V(value, ctx->Fog.Color); @@ -369,7 +369,7 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], } } return; - + case STATE_VERTEX_PROGRAM: { /* state[1] = {STATE_ENV, STATE_LOCAL} */ @@ -475,7 +475,6 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], } - case STATE_PT_SCALE: value[0] = ctx->Pixel.RedScale; value[1] = ctx->Pixel.GreenScale; @@ -494,6 +493,19 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], case STATE_PCM_BIAS: COPY_4V(value, ctx->Pixel.PostColorMatrixBias); break; + case STATE_SHADOW_AMBIENT: + { + const int unit = (int) state[2]; + const struct gl_texture_object *texObj + = ctx->Texture.Unit[unit]._Current; + if (texObj) { + value[0] = texObj->ShadowAmbient; + value[1] = texObj->ShadowAmbient; + value[2] = texObj->ShadowAmbient; + value[3] = texObj->ShadowAmbient; + } + } + return; /* XXX: make sure new tokens added here are also handled in the * _mesa_program_state_flags() switch, below. @@ -578,6 +590,7 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH]) return _NEW_MODELVIEW; case STATE_TEXRECT_SCALE: + case STATE_SHADOW_AMBIENT: return _NEW_TEXTURE; case STATE_FOG_PARAMS_OPTIMIZED: return _NEW_FOG; @@ -768,6 +781,9 @@ append_token(char *dst, gl_state_index k) case STATE_PCM_BIAS: append(dst, "PCMbias"); break; + case STATE_SHADOW_AMBIENT: + append(dst, "ShadowAmbient"); + break; default: ; } @@ -918,10 +934,101 @@ _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, + _mesa_fetch_state(ctx, (gl_state_index *) paramList->Parameters[i].StateIndexes, paramList->ParameterValues[i]); } } } + +/** + * Copy the 16 elements of a matrix into four consecutive program + * registers starting at 'pos'. + */ +static void +load_matrix(GLfloat registers[][4], GLuint pos, const GLfloat mat[16]) +{ + GLuint i; + for (i = 0; i < 4; i++) { + registers[pos + i][0] = mat[0 + i]; + registers[pos + i][1] = mat[4 + i]; + registers[pos + i][2] = mat[8 + i]; + registers[pos + i][3] = mat[12 + i]; + } +} + + +/** + * As above, but transpose the matrix. + */ +static void +load_transpose_matrix(GLfloat registers[][4], GLuint pos, + const GLfloat mat[16]) +{ + MEMCPY(registers[pos], mat, 16 * sizeof(GLfloat)); +} + + +/** + * Load current vertex program's parameter registers with tracked + * matrices (if NV program). This only needs to be done per + * glBegin/glEnd, not per-vertex. + */ +void +_mesa_load_tracked_matrices(GLcontext *ctx) +{ + GLuint i; + + for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) { + /* point 'mat' at source matrix */ + GLmatrix *mat; + if (ctx->VertexProgram.TrackMatrix[i] == GL_MODELVIEW) { + mat = ctx->ModelviewMatrixStack.Top; + } + else if (ctx->VertexProgram.TrackMatrix[i] == GL_PROJECTION) { + mat = ctx->ProjectionMatrixStack.Top; + } + else if (ctx->VertexProgram.TrackMatrix[i] == GL_TEXTURE) { + mat = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top; + } + else if (ctx->VertexProgram.TrackMatrix[i] == GL_COLOR) { + mat = ctx->ColorMatrixStack.Top; + } + else if (ctx->VertexProgram.TrackMatrix[i]==GL_MODELVIEW_PROJECTION_NV) { + /* XXX verify the combined matrix is up to date */ + mat = &ctx->_ModelProjectMatrix; + } + else if (ctx->VertexProgram.TrackMatrix[i] >= GL_MATRIX0_NV && + ctx->VertexProgram.TrackMatrix[i] <= GL_MATRIX7_NV) { + GLuint n = ctx->VertexProgram.TrackMatrix[i] - GL_MATRIX0_NV; + ASSERT(n < MAX_PROGRAM_MATRICES); + mat = ctx->ProgramMatrixStack[n].Top; + } + else { + /* no matrix is tracked, but we leave the register values as-is */ + assert(ctx->VertexProgram.TrackMatrix[i] == GL_NONE); + continue; + } + + /* load the matrix values into sequential registers */ + if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_IDENTITY_NV) { + load_matrix(ctx->VertexProgram.Parameters, i*4, mat->m); + } + else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_INVERSE_NV) { + _math_matrix_analyse(mat); /* update the inverse */ + ASSERT(!_math_matrix_is_dirty(mat)); + load_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv); + } + else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_TRANSPOSE_NV) { + load_transpose_matrix(ctx->VertexProgram.Parameters, i*4, mat->m); + } + else { + assert(ctx->VertexProgram.TrackMatrixTransform[i] + == GL_INVERSE_TRANSPOSE_NV); + _math_matrix_analyse(mat); /* update the inverse */ + ASSERT(!_math_matrix_is_dirty(mat)); + load_transpose_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv); + } + } +} diff --git a/src/mesa/shader/prog_statevars.h b/src/mesa/shader/prog_statevars.h index 1f728c64e80..72e51f40314 100644 --- a/src/mesa/shader/prog_statevars.h +++ b/src/mesa/shader/prog_statevars.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 + * Version: 7.1 * - * 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"), @@ -77,7 +77,7 @@ typedef enum gl_state_index_ { STATE_SPECULAR, STATE_EMISSION, STATE_SHININESS, - STATE_HALF_VECTOR, + STATE_HALF_VECTOR, STATE_POSITION, STATE_ATTENUATION, @@ -94,7 +94,7 @@ typedef enum gl_state_index_ { STATE_TEXGEN_OBJECT_Q, STATE_TEXENV_COLOR, - + STATE_DEPTH_RANGE, STATE_VERTEX_PROGRAM, @@ -116,6 +116,7 @@ typedef enum gl_state_index_ { STATE_PT_BIAS, /**< Pixel transfer RGBA bias */ STATE_PCM_SCALE, /**< Post color matrix RGBA scale */ STATE_PCM_BIAS, /**< Post color matrix RGBA bias */ + STATE_SHADOW_AMBIENT, /**< ARB_shadow_ambient fail value; token[2] is texture unit index */ STATE_INTERNAL_DRIVER /* first available state index for drivers (must be last) */ } gl_state_index; @@ -134,4 +135,8 @@ extern char * _mesa_program_state_string(const gl_state_index state[STATE_LENGTH]); +extern void +_mesa_load_tracked_matrices(GLcontext *ctx); + + #endif /* PROG_STATEVARS_H */ diff --git a/src/mesa/shader/prog_uniform.c b/src/mesa/shader/prog_uniform.c index a0aa615c5f6..11f2e3e561c 100644 --- a/src/mesa/shader/prog_uniform.c +++ b/src/mesa/shader/prog_uniform.c @@ -135,8 +135,8 @@ _mesa_longest_uniform_name(const struct gl_uniform_list *list) GLint max = 0; GLuint i; for (i = 0; list && i < list->NumUniforms; i++) { - GLuint len = _mesa_strlen(list->Uniforms[i].Name); - if (len > (GLuint)max) + GLint len = (GLint)_mesa_strlen(list->Uniforms[i].Name); + if (len > max) max = len; } return max; diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 723c46ee8cf..37962f0e9bb 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -121,6 +121,43 @@ _mesa_free_program_data(GLcontext *ctx) /** + * Update the default program objects in the given context to reference those + * specified in the shared state and release those referencing the old + * shared state. + */ +void +_mesa_update_default_objects_program(GLcontext *ctx) +{ +#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + (struct gl_vertex_program *) + ctx->Shared->DefaultVertexProgram); + assert(ctx->VertexProgram.Current); +#endif + +#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, + (struct gl_fragment_program *) + ctx->Shared->DefaultFragmentProgram); + assert(ctx->FragmentProgram.Current); +#endif + + /* XXX probably move this stuff */ +#if FEATURE_ATI_fragment_shader + if (ctx->ATIFragmentShader.Current) { + ctx->ATIFragmentShader.Current->RefCount--; + if (ctx->ATIFragmentShader.Current->RefCount <= 0) { + _mesa_free(ctx->ATIFragmentShader.Current); + } + } + ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) ctx->Shared->DefaultFragmentShader; + assert(ctx->ATIFragmentShader.Current); + ctx->ATIFragmentShader.Current->RefCount++; +#endif +} + + +/** * Set the vertex/fragment program error state (position and error string). * This is generally called from within the parsers. */ @@ -211,7 +248,7 @@ struct gl_program * _mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog, GLenum target, GLuint id) { - if (prog) + if (prog) return _mesa_init_program_struct( ctx, &prog->Base, target, id ); else return NULL; @@ -225,7 +262,7 @@ struct gl_program * _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, GLenum target, GLuint id) { - if (prog) + if (prog) return _mesa_init_program_struct( ctx, &prog->Base, target, id ); else return NULL; @@ -238,7 +275,7 @@ _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a * device driver function to implement OO deriviation with additional * types not understood by this function. - * + * * \param ctx context * \param id program id/number * \param target program target/type @@ -247,19 +284,23 @@ _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, struct gl_program * _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) { + struct gl_program *prog; switch (target) { case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */ - return _mesa_init_vertex_program(ctx, CALLOC_STRUCT(gl_vertex_program), + prog = _mesa_init_vertex_program(ctx, CALLOC_STRUCT(gl_vertex_program), target, id ); + break; case GL_FRAGMENT_PROGRAM_NV: case GL_FRAGMENT_PROGRAM_ARB: - return _mesa_init_fragment_program(ctx, + prog =_mesa_init_fragment_program(ctx, CALLOC_STRUCT(gl_fragment_program), target, id ); + break; default: _mesa_problem(ctx, "bad target in _mesa_new_program"); - return NULL; + prog = NULL; } + return prog; } @@ -278,7 +319,7 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog) if (prog == &_mesa_DummyProgram) return; - + if (prog->String) _mesa_free(prog->String); @@ -331,7 +372,11 @@ _mesa_reference_program(GLcontext *ctx, assert(ptr); if (*ptr && prog) { /* sanity check */ - ASSERT((*ptr)->Target == prog->Target); + if ((*ptr)->Target == GL_VERTEX_PROGRAM_ARB) + ASSERT(prog->Target == GL_VERTEX_PROGRAM_ARB); + else if ((*ptr)->Target == GL_FRAGMENT_PROGRAM_ARB) + ASSERT(prog->Target == GL_FRAGMENT_PROGRAM_ARB || + prog->Target == GL_FRAGMENT_PROGRAM_NV); } if (*ptr == prog) { return; /* no change */ @@ -341,15 +386,17 @@ _mesa_reference_program(GLcontext *ctx, /*_glthread_LOCK_MUTEX((*ptr)->Mutex);*/ #if 0 - printf("Program %p %u 0x%x Refcount-- to %d\n", - *ptr, (*ptr)->Id, (*ptr)->Target, (*ptr)->RefCount - 1); + printf("Program %p ID=%u Target=%s Refcount-- to %d\n", + *ptr, (*ptr)->Id, + ((*ptr)->Target == GL_VERTEX_PROGRAM_ARB ? "VP" : "FP"), + (*ptr)->RefCount - 1); #endif ASSERT((*ptr)->RefCount > 0); (*ptr)->RefCount--; deleteFlag = ((*ptr)->RefCount == 0); /*_glthread_UNLOCK_MUTEX((*ptr)->Mutex);*/ - + if (deleteFlag) { ASSERT(ctx); ctx->Driver.DeleteProgram(ctx, *ptr); @@ -363,8 +410,10 @@ _mesa_reference_program(GLcontext *ctx, /*_glthread_LOCK_MUTEX(prog->Mutex);*/ prog->RefCount++; #if 0 - printf("Program %p %u 0x%x Refcount++ to %d\n", - prog, prog->Id, prog->Target, prog->RefCount); + printf("Program %p ID=%u Target=%s Refcount++ to %d\n", + prog, prog->Id, + (prog->Target == GL_VERTEX_PROGRAM_ARB ? "VP" : "FP"), + prog->RefCount); #endif /*_glthread_UNLOCK_MUTEX(prog->Mutex);*/ } @@ -402,6 +451,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) clone->InputsRead = prog->InputsRead; clone->OutputsWritten = prog->OutputsWritten; clone->SamplersUsed = prog->SamplersUsed; + clone->ShadowSamplers = prog->ShadowSamplers; memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed)); if (prog->Parameters) @@ -504,6 +554,52 @@ _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count) return GL_TRUE; } +/** + * Delete 'count' instructions at 'start' in the given program. + * Adjust branch targets accordingly. + */ +GLboolean +_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count) +{ + const GLuint origLen = prog->NumInstructions; + const GLuint newLen = origLen - count; + struct prog_instruction *newInst; + GLuint i; + + /* adjust branches */ + for (i = 0; i < prog->NumInstructions; i++) { + struct prog_instruction *inst = prog->Instructions + i; + if (inst->BranchTarget > 0) { + if (inst->BranchTarget >= start) { + inst->BranchTarget -= count; + } + } + } + + /* Alloc storage for new instructions */ + newInst = _mesa_alloc_instructions(newLen); + if (!newInst) { + return GL_FALSE; + } + + /* Copy 'start' instructions into new instruction buffer */ + _mesa_copy_instructions(newInst, prog->Instructions, start); + + /* Copy the remaining/tail instructions to new inst buffer */ + _mesa_copy_instructions(newInst + start, + prog->Instructions + start + count, + newLen - start); + + /* free old instructions */ + _mesa_free_instructions(prog->Instructions, origLen); + + /* install new instructions */ + prog->Instructions = newInst; + prog->NumInstructions = newLen; + + return GL_TRUE; +} + /** * Search instructions for registers that match (oldFile, oldIndex), diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h index f8bd63233ed..48176162c35 100644 --- a/src/mesa/shader/program.h +++ b/src/mesa/shader/program.h @@ -53,6 +53,9 @@ extern void _mesa_free_program_data(GLcontext *ctx); extern void +_mesa_update_default_objects_program(GLcontext *ctx); + +extern void _mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string); extern const GLubyte * @@ -60,13 +63,13 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, GLint *line, GLint *col); -extern struct gl_program * -_mesa_init_vertex_program(GLcontext *ctx, - struct gl_vertex_program *prog, +extern struct gl_program * +_mesa_init_vertex_program(GLcontext *ctx, + struct gl_vertex_program *prog, GLenum target, GLuint id); -extern struct gl_program * -_mesa_init_fragment_program(GLcontext *ctx, +extern struct gl_program * +_mesa_init_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog, GLenum target, GLuint id); @@ -108,6 +111,9 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog); extern GLboolean _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count); +extern GLboolean +_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count); + extern struct gl_program * _mesa_combine_programs(GLcontext *ctx, const struct gl_program *progA, diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 7af502a84cb..7a8501dcdd3 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -39,15 +39,15 @@ #include "main/context.h" #include "main/hash.h" #include "main/macros.h" -#include "program.h" -#include "prog_parameter.h" -#include "prog_print.h" -#include "prog_statevars.h" -#include "prog_uniform.h" +#include "shader/program.h" +#include "shader/prog_parameter.h" +#include "shader/prog_print.h" +#include "shader/prog_statevars.h" +#include "shader/prog_uniform.h" #include "shader/shader_api.h" #include "shader/slang/slang_compile.h" #include "shader/slang/slang_link.h" - +#include "glapi/dispatch.h" #ifndef GL_PROGRAM_BINARY_LENGTH_OES @@ -455,7 +455,13 @@ _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) n = shProg->NumShaders; for (i = 0; i < n; i++) { if (shProg->Shaders[i] == sh) { - /* already attached */ + /* The shader is already attched to this program. The + * GL_ARB_shader_objects spec says: + * + * "The error INVALID_OPERATION is generated by AttachObjectARB + * if <obj> is already attached to <containerObj>." + */ + _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader"); return; } } @@ -517,7 +523,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, { struct gl_shader_program *shProg; const GLint size = -1; /* unknown size */ - GLint i; + GLint i, oldIndex; GLenum datatype = GL_FLOAT_VEC4; shProg = _mesa_lookup_shader_program_err(ctx, program, @@ -540,6 +546,14 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, return; } + if (shProg->LinkStatus) { + /* get current index/location for the attribute */ + oldIndex = _mesa_get_attrib_location(ctx, program, name); + } + else { + oldIndex = -1; + } + /* this will replace the current value if it's already in the list */ i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index); if (i < 0) { @@ -911,24 +925,15 @@ _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, static GLuint _mesa_get_handle(GLcontext *ctx, GLenum pname) { -#if 0 - GET_CURRENT_CONTEXT(ctx); - - switch (pname) { - case GL_PROGRAM_OBJECT_ARB: - { - struct gl2_program_intf **pro = ctx->Shader.CurrentProgram; - - if (pro != NULL) - return (**pro)._container._generic. - GetName((struct gl2_generic_intf **) (pro)); - } - break; - default: + GLint handle = 0; + + if (pname == GL_PROGRAM_OBJECT_ARB) { + CALL_GetIntegerv(ctx->Exec, (GL_CURRENT_PROGRAM, &handle)); + } else { _mesa_error(ctx, GL_INVALID_ENUM, "glGetHandleARB"); } -#endif - return 0; + + return handle; } diff --git a/src/mesa/shader/slang/descrip.mms b/src/mesa/shader/slang/descrip.mms new file mode 100644 index 00000000000..6eefbcf5bdd --- /dev/null +++ b/src/mesa/shader/slang/descrip.mms @@ -0,0 +1,68 @@ +# Makefile for core library for VMS +# contributed by Jouk Jansen [email protected] +# Last revision : 3 October 2007 + +.first + define gl [----.include.gl] + define math [--.math] + define swrast [--.swrast] + define array_cache [--.array_cache] + define main [--.main] + define glapi [--.glapi] + define shader [--.shader] + +.include [----]mms-config. + +##### MACROS ##### + +VPATH = RCS + +INCDIR = [----.include],[--.main],[--.glapi],[-.slang],[-.grammar],[-] +LIBDIR = [----.lib] +CFLAGS = /include=($(INCDIR),[])/define=(PTHREADS=1)/name=(as_is,short)/float=ieee/ieee=denorm + +SOURCES = \ + slang_compile.c,slang_preprocess.c + +OBJECTS = slang_builtin.obj,slang_codegen.obj,slang_compile.obj,\ + slang_compile_function.obj,slang_compile_operation.obj,\ + slang_compile_struct.obj,slang_compile_variable.obj,slang_emit.obj,\ + slang_ir.obj,slang_label.obj,slang_library_noise.obj,slang_link.obj,\ + slang_log.obj,slang_mem.obj,slang_preprocess.obj,slang_print.obj,\ + slang_simplify.obj,slang_storage.obj,slang_typeinfo.obj,\ + slang_utility.obj,slang_vartable.obj + +##### RULES ##### + +VERSION=Mesa V3.4 + +##### TARGETS ##### +# Make the library +$(LIBDIR)$(GL_LIB) : $(OBJECTS) + @ library $(LIBDIR)$(GL_LIB) $(OBJECTS) + +clean : + purge + delete *.obj;* + +slang_builtin.obj : slang_builtin.c +slang_codegen.obj : slang_codegen.c +slang_compile.obj : slang_compile.c +slang_compile_function.obj : slang_compile_function.c +slang_compile_operation.obj : slang_compile_operation.c +slang_compile_struct.obj : slang_compile_struct.c +slang_compile_variable.obj : slang_compile_variable.c +slang_emit.obj : slang_emit.c +slang_ir.obj : slang_ir.c +slang_label.obj : slang_label.c +slang_library_noise.obj : slang_library_noise.c +slang_link.obj : slang_link.c +slang_log.obj : slang_log.c +slang_mem.obj : slang_mem.c +slang_preprocess.obj : slang_preprocess.c +slang_print.obj : slang_print.c +slang_simplify.obj : slang_simplify.c +slang_storage.obj : slang_storage.c +slang_typeinfo.obj : slang_typeinfo.c +slang_utility.obj : slang_utility.c +slang_vartable.obj : slang_vartable.c diff --git a/src/mesa/shader/slang/library/slang_pp_directives.syn b/src/mesa/shader/slang/library/slang_pp_directives.syn index d4a321034d1..d4a321034d1 100755..100644 --- a/src/mesa/shader/slang/library/slang_pp_directives.syn +++ b/src/mesa/shader/slang/library/slang_pp_directives.syn diff --git a/src/mesa/shader/slang/library/slang_pp_expression.syn b/src/mesa/shader/slang/library/slang_pp_expression.syn index bfdb220bf5c..bfdb220bf5c 100755..100644 --- a/src/mesa/shader/slang/library/slang_pp_expression.syn +++ b/src/mesa/shader/slang/library/slang_pp_expression.syn diff --git a/src/mesa/shader/slang/library/slang_version.syn b/src/mesa/shader/slang/library/slang_version.syn index aaf8bef342f..aaf8bef342f 100755..100644 --- a/src/mesa/shader/slang/library/slang_version.syn +++ b/src/mesa/shader/slang/library/slang_version.syn diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 511e7406159..2074e842094 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -419,7 +419,6 @@ _slang_update_inputs_outputs(struct gl_program *prog) maxAddrReg = MAX2(maxAddrReg, inst->DstReg.Index + 1); } } - prog->NumAddressRegs = maxAddrReg; } diff --git a/src/mesa/shader/slang/sources b/src/mesa/shader/slang/sources deleted file mode 100644 index 00d617fa8af..00000000000 --- a/src/mesa/shader/slang/sources +++ /dev/null @@ -1,44 +0,0 @@ -MESA_SHADER_SLANG_SOURCES = \ -slang_analyse.c \ -slang_assemble_assignment.c \ -slang_assemble.c \ -slang_assemble_conditional.c \ -slang_assemble_constructor.c \ -slang_assemble_typeinfo.c \ -slang_compile.c \ -slang_compile_function.c \ -slang_compile_operation.c \ -slang_compile_struct.c \ -slang_compile_variable.c \ -slang_execute.c \ -slang_execute_x86.c \ -slang_export.c \ -slang_library_texsample.c \ -slang_library_noise.c \ -slang_link.c \ -slang_preprocess.c \ -slang_storage.c \ -slang_utility.c - -MESA_SHADER_SLANG_HEADERS = \ -slang_analyse.h \ -slang_assemble.h \ -slang_assemble_assignment.h \ -slang_assemble_conditional.h \ -slang_assemble_constructor.h \ -slang_assemble_typeinfo.h \ -slang_compile.h \ -slang_compile_function.h \ -slang_compile_operation.h \ -slang_compile_struct.h \ -slang_compile_variable.h \ -slang_execute.h \ -slang_export.h \ -slang_library_noise.h \ -slang_library_texsample.h \ -slang_link.h \ -slang_mesa.h \ -slang_preprocess.h \ -slang_storage.h \ -slang_utility.h \ -traverse_wrap.h diff --git a/src/mesa/shader/sources b/src/mesa/shader/sources deleted file mode 100644 index 27871872766..00000000000 --- a/src/mesa/shader/sources +++ /dev/null @@ -1,28 +0,0 @@ -# List of source files in this directory used for X.org xserver build -MESA_SHADER_SOURCES = \ -arbprogparse.c \ -arbprogram.c \ -atifragshader.c \ -nvfragparse.c \ -nvprogram.c \ -nvvertexec.c \ -nvvertparse.c \ -program.c \ -programopt.c \ -shaderobjects.c \ -shaderobjects_3dlabs.c - -MESA_SHADER_HEADERS = \ -arbprogparse.h \ -arbprogram.h \ -arbprogram_syn.h \ -atifragshader.h \ -nvfragparse.h \ -nvprogram.h \ -nvvertexec.h \ -nvvertparse.h \ -programopt.h \ -program.h \ -program_instruction.h \ -shaderobjects.h \ -shaderobjects_3dlabs.h |