merge of glsl-compiler-1 branch

This commit is contained in:
Brian
2007-03-26 10:13:02 -06:00
311 changed files with 31449 additions and 49563 deletions

View File

@@ -28,11 +28,12 @@
#include "glheader.h"
#include "macros.h"
#include "enums.h"
#include "prog_parameter.h"
#include "prog_instruction.h"
#include "prog_print.h"
#include "prog_statevars.h"
#include "texenvprogram.h"
#include "shader/program.h"
#include "shader/program_instruction.h"
/**
* According to Glean's texCombine test, no more than 21 instructions
* are needed. Allow a few extra just in case.
@@ -410,31 +411,29 @@ static void release_temps( struct texenv_fragment_program *p )
}
static struct ureg register_param6( struct texenv_fragment_program *p,
static struct ureg register_param5( struct texenv_fragment_program *p,
GLint s0,
GLint s1,
GLint s2,
GLint s3,
GLint s4,
GLint s5)
GLint s4)
{
GLint tokens[6];
gl_state_index tokens[STATE_LENGTH];
GLuint idx;
tokens[0] = s0;
tokens[1] = s1;
tokens[2] = s2;
tokens[3] = s3;
tokens[4] = s4;
tokens[5] = s5;
idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens );
return make_ureg(PROGRAM_STATE_VAR, idx);
}
#define register_param1(p,s0) register_param6(p,s0,0,0,0,0,0)
#define register_param2(p,s0,s1) register_param6(p,s0,s1,0,0,0,0)
#define register_param3(p,s0,s1,s2) register_param6(p,s0,s1,s2,0,0,0)
#define register_param4(p,s0,s1,s2,s3) register_param6(p,s0,s1,s2,s3,0,0)
#define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
#define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
#define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
#define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
static struct ureg register_input( struct texenv_fragment_program *p, GLuint input )
@@ -523,7 +522,7 @@ static struct ureg emit_arith( struct texenv_fragment_program *p,
if (dest.file == PROGRAM_TEMPORARY)
p->alu_temps |= 1 << dest.idx;
p->program->NumAluInstructions++;
p->program->Base.NumAluInstructions++;
return dest;
}
@@ -545,7 +544,7 @@ static struct ureg emit_texld( struct texenv_fragment_program *p,
inst->TexSrcTarget = tex_idx;
inst->TexSrcUnit = tex_unit;
p->program->NumTexInstructions++;
p->program->Base.NumTexInstructions++;
/* Is this a texture indirection?
*/
@@ -553,7 +552,7 @@ static struct ureg emit_texld( struct texenv_fragment_program *p,
(p->temps_output & (1<<coord.idx))) ||
(dest.file == PROGRAM_TEMPORARY &&
(p->alu_temps & (1<<dest.idx)))) {
p->program->NumTexIndirections++;
p->program->Base.NumTexIndirections++;
p->temps_output = 1<<coord.idx;
p->alu_temps = 0;
assert(0); /* KW: texture env crossbar */
@@ -570,12 +569,14 @@ static struct ureg register_const4f( struct texenv_fragment_program *p,
GLfloat s3)
{
GLfloat values[4];
GLuint idx;
GLuint idx, swizzle;
values[0] = s0;
values[1] = s1;
values[2] = s2;
values[3] = s3;
idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4 );
idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4,
&swizzle );
ASSERT(swizzle == SWIZZLE_NOOP);
return make_ureg(PROGRAM_STATE_VAR, idx);
}
@@ -1010,9 +1011,9 @@ create_new_program(GLcontext *ctx, struct state_key *key,
*/
p.program->Base.Instructions = instBuffer;
p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB;
p.program->NumTexIndirections = 1; /* correct? */
p.program->NumTexInstructions = 0;
p.program->NumAluInstructions = 0;
p.program->Base.NumTexIndirections = 1; /* correct? */
p.program->Base.NumTexInstructions = 0;
p.program->Base.NumAluInstructions = 0;
p.program->Base.String = NULL;
p.program->Base.NumInstructions =
p.program->Base.NumTemporaries =
@@ -1083,13 +1084,13 @@ create_new_program(GLcontext *ctx, struct state_key *key,
} else
p.program->FogOption = GL_NONE;
if (p.program->NumTexIndirections > ctx->Const.FragmentProgram.MaxTexIndirections)
if (p.program->Base.NumTexIndirections > ctx->Const.FragmentProgram.MaxTexIndirections)
program_error(&p, "Exceeded max nr indirect texture lookups");
if (p.program->NumTexInstructions > ctx->Const.FragmentProgram.MaxTexInstructions)
if (p.program->Base.NumTexInstructions > ctx->Const.FragmentProgram.MaxTexInstructions)
program_error(&p, "Exceeded max TEX instructions");
if (p.program->NumAluInstructions > ctx->Const.FragmentProgram.MaxAluInstructions)
if (p.program->Base.NumAluInstructions > ctx->Const.FragmentProgram.MaxAluInstructions)
program_error(&p, "Exceeded max ALU instructions");
ASSERT(p.program->Base.NumInstructions <= MAX_INSTRUCTIONS);
@@ -1221,32 +1222,49 @@ static GLuint hash_key( const struct state_key *key )
return hash;
}
void _mesa_UpdateTexEnvProgram( GLcontext *ctx )
/**
* If _MaintainTexEnvProgram is set we'll generate a fragment program that
* implements the current texture env/combine mode.
* This function generates that program and puts it into effect.
*/
void
_mesa_UpdateTexEnvProgram( GLcontext *ctx )
{
struct state_key key;
GLuint hash;
const struct gl_fragment_program *prev = ctx->FragmentProgram._Current;
if (!ctx->FragmentProgram._Enabled) {
ASSERT(ctx->FragmentProgram._MaintainTexEnvProgram);
/* If a conventional fragment program/shader isn't in effect... */
if (!ctx->FragmentProgram._Enabled &&
!ctx->Shader.CurrentProgram) {
make_state_key(ctx, &key);
hash = hash_key(&key);
ctx->FragmentProgram._Current =
ctx->_TexEnvProgram =
search_cache(&ctx->Texture.env_fp_cache, hash, &key, sizeof(key));
if (!ctx->_TexEnvProgram) {
if (0) _mesa_printf("Building new texenv proggy for key %x\n", hash);
ctx->FragmentProgram._Current = ctx->_TexEnvProgram =
(struct gl_fragment_program *)
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
create_new_program(ctx, &key, ctx->_TexEnvProgram);
ctx->FragmentProgram._TexEnvProgram =
search_cache(&ctx->Texture.env_fp_cache, hash, &key, sizeof(key));
cache_item(&ctx->Texture.env_fp_cache, hash, &key, ctx->_TexEnvProgram);
} else {
if (0) _mesa_printf("Found existing texenv program for key %x\n", hash);
if (!ctx->FragmentProgram._TexEnvProgram) {
if (0)
_mesa_printf("Building new texenv proggy for key %x\n", hash);
/* create new tex env program */
ctx->FragmentProgram._Current =
ctx->FragmentProgram._TexEnvProgram =
(struct gl_fragment_program *)
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
create_new_program(ctx, &key, ctx->FragmentProgram._TexEnvProgram);
cache_item(&ctx->Texture.env_fp_cache, hash, &key,
ctx->FragmentProgram._TexEnvProgram);
}
else {
if (0)
_mesa_printf("Found existing texenv program for key %x\n", hash);
}
}
else {
@@ -1258,7 +1276,7 @@ void _mesa_UpdateTexEnvProgram( GLcontext *ctx )
*/
if (ctx->FragmentProgram._Current != prev && ctx->Driver.BindProgram) {
ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
(struct gl_program *) ctx->FragmentProgram._Current);
(struct gl_program *) ctx->FragmentProgram._Current);
}
}