Trigger tgsi compilation for fragment programs.

Not sure the generated program looks correct though...
This commit is contained in:
Keith Whitwell
2007-07-19 20:24:55 +01:00
parent 6101fe641c
commit 4824c342c8
12 changed files with 152 additions and 40 deletions

View File

@@ -121,8 +121,11 @@ struct pipe_clip_state {
GLuint nr;
};
struct pipe_fs_state {
struct gl_fragment_program *fp;
GLuint inputs_read; /* FRAG_ATTRIB_* */
const struct tgsi_token *tokens;
};
struct pipe_constant_buffer {

View File

@@ -28,7 +28,6 @@
#include "main/glheader.h"
#include "main/macros.h"
#include "main/enums.h"
#include "shader/program.h"
#include "vf/vf.h"
#include "pipe/draw/draw_context.h"
@@ -68,8 +67,7 @@ static const GLuint frag_to_vf[FRAG_ATTRIB_MAX] =
*/
static void calculate_vertex_layout( struct softpipe_context *softpipe )
{
struct gl_fragment_program *fp = softpipe->fs.fp;
const GLuint inputsRead = fp->Base.InputsRead;
const GLuint inputsRead = softpipe->fs.inputs_read;
GLuint slot_to_vf_attr[VF_ATTRIB_MAX];
GLbitfield attr_mask = 0x0;
GLuint i;

View File

@@ -400,12 +400,16 @@ tgsi_dump(
GLuint deflt = !(flags & TGSI_DUMP_NO_DEFAULT);
{
#if 0
static GLuint counter = 0;
char buffer[64];
sprintf( buffer, "sbir-dump-%.4u.txt", counter++ );
dump.file = fopen( buffer, "wt" );
#else
dump.file = stderr;
dump.tabs = 0;
#endif
}
tgsi_parse_init( &parse, tokens );

View File

@@ -5,6 +5,8 @@
extern "C" {
#endif // defined __cplusplus
struct tgsi_token;
GLboolean
tgsi_mesa_compile_fp_program(
const struct gl_fragment_program *program,

View File

@@ -206,6 +206,7 @@ STATETRACKER_SOURCES = \
state_tracker/st_atom_clip.c \
state_tracker/st_atom_depth.c \
state_tracker/st_atom_fs.c \
state_tracker/st_atom_vs.c \
state_tracker/st_atom_framebuffer.c \
state_tracker/st_atom_sampler.c \
state_tracker/st_atom_scissor.c \

View File

@@ -46,6 +46,7 @@ static const struct st_tracked_state *atoms[] =
&st_update_clear_color,
&st_update_depth,
&st_update_clip,
&st_update_vs,
&st_update_fs,
&st_update_setup,
&st_update_polygon_stipple,

View File

@@ -49,6 +49,7 @@ const struct st_tracked_state st_update_clip;
const struct st_tracked_state st_update_clear_color;
const struct st_tracked_state st_update_depth;
const struct st_tracked_state st_update_fs;
const struct st_tracked_state st_update_vs;
const struct st_tracked_state st_update_setup;
const struct st_tracked_state st_update_polygon_stipple;
const struct st_tracked_state st_update_viewport;

View File

@@ -32,15 +32,38 @@
#include "st_context.h"
#include "pipe/p_context.h"
#include "st_atom.h"
#include "st_program.h"
#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
#include "pipe/tgsi/core/tgsi_dump.h"
static void compile_fs( struct st_context *st,
struct st_fragment_program *fs )
{
/* XXX: fix static allocation of tokens:
*/
tgsi_mesa_compile_fp_program( &fs->Base, fs->tokens, ST_FP_MAX_TOKENS );
tgsi_dump( fs->tokens, TGSI_DUMP_VERBOSE );
}
static void update_fs( struct st_context *st )
{
struct pipe_fs_state fs;
struct st_fragment_program *fp = st_fragment_program(st->ctx->FragmentProgram._Current);
fs.fp = st->ctx->FragmentProgram._Current;
memset( &fs, 0, sizeof(fs) );
if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) {
if (fp->dirty)
compile_fs( st, fp );
fs.inputs_read = fp->Base.Base.InputsRead;
fs.tokens = &fp->tokens[0];
if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 ||
fp->dirty)
{
fp->dirty = 0;
st->state.fs = fs;
st->pipe->set_fs_state(st->pipe, &fs);
}

View File

@@ -0,0 +1,49 @@
/**************************************************************************
*
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
* 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"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/*
* Authors:
* Keith Whitwell <keith@tungstengraphics.com>
*/
#include "st_context.h"
#include "pipe/p_context.h"
#include "st_atom.h"
static void update_vs( struct st_context *st )
{
}
const struct st_tracked_state st_update_vs = {
.dirty = {
.mesa = 0,
.st = ST_NEW_VERTEX_PROGRAM,
},
.update = update_vs
};

View File

@@ -52,6 +52,7 @@ static void st_bind_program( GLcontext *ctx,
switch (target) {
case GL_VERTEX_PROGRAM_ARB:
st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
break;
case GL_FRAGMENT_PROGRAM_ARB:
st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
@@ -66,16 +67,23 @@ static struct gl_program *st_new_program( GLcontext *ctx,
struct st_context *st = st_context(ctx);
switch (target) {
case GL_VERTEX_PROGRAM_ARB:
return _mesa_init_vertex_program(ctx,
CALLOC_STRUCT(gl_vertex_program),
case GL_VERTEX_PROGRAM_ARB: {
struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
prog->id = st->program_id++;
prog->dirty = 1;
return _mesa_init_vertex_program( ctx,
&prog->Base,
target,
id);
id );
}
case GL_FRAGMENT_PROGRAM_ARB: {
struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
prog->id = st->program_id++;
prog->dirty = 1;
return _mesa_init_fragment_program( ctx,
&prog->Base,
@@ -106,40 +114,25 @@ static void st_program_string_notify( GLcontext *ctx,
GLenum target,
struct gl_program *prog )
{
if (target == GL_FRAGMENT_PROGRAM_ARB) {
struct st_context *st = st_context(ctx);
if (prog == &st->ctx->FragmentProgram._Current->Base)
{
struct st_fragment_program *p =
(struct st_fragment_program *) prog;
if (target == GL_FRAGMENT_PROGRAM_ARB) {
struct st_fragment_program *p = (struct st_fragment_program *)prog;
if (prog == &ctx->FragmentProgram._Current->Base)
st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
p->id = st->program_id++;
#if 0
p->param_state = p->Base.Base.Parameters->StateFlags;
p->translated = 0;
#endif
/* Gack! do this in the compiler:
*/
if (p->Base.FogOption) {
/* add extra instructions to do fog, then turn off FogOption field */
_mesa_append_fog_code(ctx, &p->Base);
p->Base.FogOption = GL_NONE;
}
/* XXX: Not hooked-up yet. */
{
struct tgsi_token tokens[1024];
tgsi_mesa_compile_fp_program( prog, tokens, 1024 );
tgsi_dump( tokens, TGSI_DUMP_VERBOSE );
}
}
}
else if (target == GL_VERTEX_PROGRAM_ARB) {
struct st_vertex_program *p = (struct st_vertex_program *)prog;
if (prog == &ctx->VertexProgram._Current->Base)
st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
p->id = st->program_id++;
p->param_state = p->Base.Base.Parameters->StateFlags;
/* Also tell tnl about it:
*/

View File

@@ -40,6 +40,7 @@ struct st_fragment_program;
#define ST_NEW_MESA 0x1 /* Mesa state has changed */
#define ST_NEW_FRAGMENT_PROGRAM 0x2
#define ST_NEW_VERTEX_PROGRAM 0x4
struct st_state_flags {
GLuint mesa;

View File

@@ -34,6 +34,12 @@
#ifndef ST_PROGRAM_H
#define ST_PROGRAM_H
#include "mtypes.h"
#include "pipe/tgsi/core/tgsi_token.h"
#define ST_FP_MAX_TOKENS 1024
struct st_fragment_program
{
struct gl_fragment_program Base;
@@ -43,6 +49,11 @@ struct st_fragment_program
* ProgramStringNotify changes.
*/
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
GLboolean dirty;
#if 0
GLfloat (*cbuffer)[4];
GLuint nr_constants;
@@ -56,13 +67,38 @@ struct st_fragment_program
const GLfloat *values; /* Pointer to tracked values */
} *param;
GLuint nr_params;
#endif
GLuint param_state;
#endif
};
struct st_vertex_program
{
struct gl_vertex_program Base;
GLboolean error; /* If program is malformed for any reason. */
GLuint id; /* String id, for tracking
* ProgramStringNotify changes.
*/
GLboolean dirty;
GLuint param_state;
};
void st_init_cb_program( struct st_context *st );
void st_destroy_cb_program( struct st_context *st );
static inline struct st_fragment_program *
st_fragment_program( struct gl_fragment_program *fp )
{
return (struct st_fragment_program *)fp;
}
static inline struct st_vertex_program *
st_vertex_program( struct gl_vertex_program *vp )
{
return (struct st_vertex_program *)vp;
}
#endif