gallium: implement full reference counting for vertex/fragment programs

Use _mesa_reference_vert/fragprog() wherever we assign program pointers.
Fixes a memory corruption bug found with glean/api2 test.
Another memory bug involving shaders yet to be fixed...
This commit is contained in:
Brian
2008-05-06 22:13:06 -06:00
parent 10f6ae0355
commit 103ae5d16f
11 changed files with 170 additions and 74 deletions

View File

@@ -150,8 +150,6 @@ int MESA_DEBUG_FLAGS = 0;
/* ubyte -> float conversion */ /* ubyte -> float conversion */
GLfloat _mesa_ubyte_to_float_color_tab[256]; GLfloat _mesa_ubyte_to_float_color_tab[256];
static void
free_shared_state( GLcontext *ctx, struct gl_shared_state *ss );
/** /**
@@ -423,12 +421,14 @@ alloc_shared_state( GLcontext *ctx )
#endif #endif
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
ss->DefaultVertexProgram = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); ss->DefaultVertexProgram = (struct gl_vertex_program *)
ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
if (!ss->DefaultVertexProgram) if (!ss->DefaultVertexProgram)
goto cleanup; goto cleanup;
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
ss->DefaultFragmentProgram = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); ss->DefaultFragmentProgram = (struct gl_fragment_program *)
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
if (!ss->DefaultFragmentProgram) if (!ss->DefaultFragmentProgram)
goto cleanup; goto cleanup;
#endif #endif
@@ -513,12 +513,10 @@ alloc_shared_state( GLcontext *ctx )
_mesa_DeleteHashTable(ss->Programs); _mesa_DeleteHashTable(ss->Programs);
#endif #endif
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
if (ss->DefaultVertexProgram) _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram);
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
if (ss->DefaultFragmentProgram) _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram);
#endif #endif
#if FEATURE_ATI_fragment_shader #if FEATURE_ATI_fragment_shader
if (ss->DefaultFragmentShader) if (ss->DefaultFragmentShader)
@@ -695,10 +693,10 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
_mesa_DeleteHashTable(ss->Programs); _mesa_DeleteHashTable(ss->Programs);
#endif #endif
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram); _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram); _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
#endif #endif
#if FEATURE_ATI_fragment_shader #if FEATURE_ATI_fragment_shader
@@ -1190,6 +1188,14 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_unreference_framebuffer(&ctx->ReadBuffer); _mesa_unreference_framebuffer(&ctx->ReadBuffer);
} }
_mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
_mesa_free_lighting_data( ctx ); _mesa_free_lighting_data( ctx );
_mesa_free_eval_data( ctx ); _mesa_free_eval_data( ctx );
_mesa_free_texture_data( ctx ); _mesa_free_texture_data( ctx );

View File

@@ -2203,10 +2203,10 @@ struct gl_shared_state
/*@{*/ /*@{*/
struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */ struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
struct gl_program *DefaultVertexProgram; struct gl_vertex_program *DefaultVertexProgram;
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
struct gl_program *DefaultFragmentProgram; struct gl_fragment_program *DefaultFragmentProgram;
#endif #endif
/*@}*/ /*@}*/

View File

@@ -982,16 +982,20 @@ update_program(GLcontext *ctx)
#endif #endif
if (shProg && shProg->LinkStatus && shProg->FragmentProgram) { if (shProg && shProg->LinkStatus && shProg->FragmentProgram) {
/* user-defined fragment shader */ /* user-defined fragment shader */
ctx->FragmentProgram._Current = shProg->FragmentProgram; _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
shProg->FragmentProgram);
} }
else if (ctx->FragmentProgram._Enabled) { else if (ctx->FragmentProgram._Enabled) {
/* use user-defined fragment program */ /* use user-defined fragment program */
ctx->FragmentProgram._Current = ctx->FragmentProgram.Current; _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
ctx->FragmentProgram.Current);
} }
else if (ctx->FragmentProgram._MaintainTexEnvProgram) { else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
/* fragment program generated from fixed-function state */ /* fragment program generated from fixed-function state */
ctx->FragmentProgram._Current = _mesa_get_fixed_func_fragment_program(ctx); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
ctx->FragmentProgram._TexEnvProgram = ctx->FragmentProgram._Current; _mesa_get_fixed_func_fragment_program(ctx));
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
ctx->FragmentProgram._Current);
/* XXX get rid of this confusing stuff someday? */ /* XXX get rid of this confusing stuff someday? */
ctx->FragmentProgram._Active = ctx->FragmentProgram._Enabled; ctx->FragmentProgram._Active = ctx->FragmentProgram._Enabled;
@@ -1000,7 +1004,7 @@ update_program(GLcontext *ctx)
} }
else { else {
/* no fragment program */ /* no fragment program */
ctx->FragmentProgram._Current = NULL; _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
} }
if (ctx->FragmentProgram._Current != prevFP && ctx->Driver.BindProgram) { if (ctx->FragmentProgram._Current != prevFP && ctx->Driver.BindProgram) {
@@ -1013,24 +1017,28 @@ update_program(GLcontext *ctx)
**/ **/
#if 1 #if 1
/* XXX get rid of this someday? */ /* XXX get rid of this someday? */
ctx->VertexProgram._TnlProgram = NULL; _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
#endif #endif
if (shProg && shProg->LinkStatus && shProg->VertexProgram) { if (shProg && shProg->LinkStatus && shProg->VertexProgram) {
/* user-defined vertex shader */ /* user-defined vertex shader */
ctx->VertexProgram._Current = shProg->VertexProgram; _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
shProg->VertexProgram);
} }
else if (ctx->VertexProgram._Enabled) { else if (ctx->VertexProgram._Enabled) {
/* use user-defined vertex program */ /* use user-defined vertex program */
ctx->VertexProgram._Current = ctx->VertexProgram.Current; _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
ctx->VertexProgram.Current);
} }
else if (ctx->VertexProgram._MaintainTnlProgram) { else if (ctx->VertexProgram._MaintainTnlProgram) {
/* vertex program generated from fixed-function state */ /* vertex program generated from fixed-function state */
ctx->VertexProgram._Current = _mesa_get_fixed_func_vertex_program(ctx); _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
ctx->VertexProgram._TnlProgram = ctx->VertexProgram._Current; _mesa_get_fixed_func_vertex_program(ctx));
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram,
ctx->VertexProgram._Current);
} }
else { else {
/* no vertex program / used fixed-function code */ /* no vertex program / used fixed-function code */
ctx->VertexProgram._Current = NULL; _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
} }
if (ctx->VertexProgram._Current != prevVP && ctx->Driver.BindProgram) { if (ctx->VertexProgram._Current != prevVP && ctx->Driver.BindProgram) {

View File

@@ -30,6 +30,7 @@
#include "main/mtypes.h" #include "main/mtypes.h"
#include "main/imports.h" #include "main/imports.h"
#include "shader/prog_cache.h" #include "shader/prog_cache.h"
#include "shader/program.h"
struct cache_item struct cache_item
@@ -109,7 +110,7 @@ clear_cache(GLcontext *ctx, struct gl_program_cache *cache)
for (c = cache->items[i]; c; c = next) { for (c = cache->items[i]; c; c = next) {
next = c->next; next = c->next;
_mesa_free(c->key); _mesa_free(c->key);
ctx->Driver.DeleteProgram(ctx, c->program); _mesa_reference_program(ctx, &c->program, NULL);
_mesa_free(c); _mesa_free(c);
} }
cache->items[i] = NULL; cache->items[i] = NULL;
@@ -177,7 +178,7 @@ _mesa_program_cache_insert(GLcontext *ctx,
c->key = _mesa_malloc(keysize); c->key = _mesa_malloc(keysize);
memcpy(c->key, key, keysize); memcpy(c->key, key, keysize);
c->program = program; c->program = program; /* no refcount change */
if (cache->n_items > cache->size * 1.5) { if (cache->n_items > cache->size * 1.5) {
if (cache->size < 1000) if (cache->size < 1000)

View File

@@ -60,9 +60,9 @@ _mesa_init_program(GLcontext *ctx)
ctx->VertexProgram.Enabled = GL_FALSE; ctx->VertexProgram.Enabled = GL_FALSE;
ctx->VertexProgram.PointSizeEnabled = GL_FALSE; ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
ctx->VertexProgram.TwoSideEnabled = GL_FALSE; ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
ctx->VertexProgram.Current = (struct gl_vertex_program *) ctx->Shared->DefaultVertexProgram; _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
ctx->Shared->DefaultVertexProgram);
assert(ctx->VertexProgram.Current); assert(ctx->VertexProgram.Current);
ctx->VertexProgram.Current->Base.RefCount++;
for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) { for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) {
ctx->VertexProgram.TrackMatrix[i] = GL_NONE; ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV; ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
@@ -72,9 +72,9 @@ _mesa_init_program(GLcontext *ctx)
#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
ctx->FragmentProgram.Enabled = GL_FALSE; ctx->FragmentProgram.Enabled = GL_FALSE;
ctx->FragmentProgram.Current = (struct gl_fragment_program *) ctx->Shared->DefaultFragmentProgram; _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
ctx->Shared->DefaultFragmentProgram);
assert(ctx->FragmentProgram.Current); assert(ctx->FragmentProgram.Current);
ctx->FragmentProgram.Current->Base.RefCount++;
ctx->FragmentProgram.Cache = _mesa_new_program_cache(); ctx->FragmentProgram.Cache = _mesa_new_program_cache();
#endif #endif
@@ -96,19 +96,11 @@ void
_mesa_free_program_data(GLcontext *ctx) _mesa_free_program_data(GLcontext *ctx)
{ {
#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
if (ctx->VertexProgram.Current) { _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
ctx->VertexProgram.Current->Base.RefCount--;
if (ctx->VertexProgram.Current->Base.RefCount <= 0)
ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
}
_mesa_delete_program_cache(ctx, ctx->VertexProgram.Cache); _mesa_delete_program_cache(ctx, ctx->VertexProgram.Cache);
#endif #endif
#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
if (ctx->FragmentProgram.Current) { _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
ctx->FragmentProgram.Current->Base.RefCount--;
if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
}
_mesa_delete_program_cache(ctx, ctx->FragmentProgram.Cache); _mesa_delete_program_cache(ctx, ctx->FragmentProgram.Cache);
#endif #endif
/* XXX probably move this stuff */ /* XXX probably move this stuff */
@@ -325,6 +317,59 @@ _mesa_lookup_program(GLcontext *ctx, GLuint id)
} }
/**
* Reference counting for vertex/fragment programs
*/
void
_mesa_reference_program(GLcontext *ctx,
struct gl_program **ptr,
struct gl_program *prog)
{
assert(ptr);
if (*ptr && prog) {
/* sanity check */
ASSERT((*ptr)->Target == prog->Target);
}
if (*ptr == prog) {
return; /* no change */
}
if (*ptr) {
GLboolean deleteFlag;
/*_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);
#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);
}
*ptr = NULL;
}
assert(!*ptr);
if (prog) {
/*_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);
#endif
/*_glthread_UNLOCK_MUTEX(prog->Mutex);*/
}
*ptr = prog;
}
/** /**
* Return a copy of a program. * Return a copy of a program.
* XXX Problem here if the program object is actually OO-derivation * XXX Problem here if the program object is actually OO-derivation
@@ -340,8 +385,9 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog)
return NULL; return NULL;
assert(clone->Target == prog->Target); assert(clone->Target == prog->Target);
assert(clone->RefCount == 1);
clone->String = (GLubyte *) _mesa_strdup((char *) prog->String); clone->String = (GLubyte *) _mesa_strdup((char *) prog->String);
clone->RefCount = 1;
clone->Format = prog->Format; clone->Format = prog->Format;
clone->Instructions = _mesa_alloc_instructions(prog->NumInstructions); clone->Instructions = _mesa_alloc_instructions(prog->NumInstructions);
if (!clone->Instructions) { if (!clone->Instructions) {
@@ -704,9 +750,9 @@ _mesa_BindProgram(GLenum target, GLuint id)
/* Bind a default program */ /* Bind a default program */
newProg = NULL; newProg = NULL;
if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */ if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */
newProg = ctx->Shared->DefaultVertexProgram; newProg = &ctx->Shared->DefaultVertexProgram->Base;
else else
newProg = ctx->Shared->DefaultFragmentProgram; newProg = &ctx->Shared->DefaultFragmentProgram->Base;
} }
else { else {
/* Bind a user program */ /* Bind a user program */
@@ -734,26 +780,16 @@ _mesa_BindProgram(GLenum target, GLuint id)
return; return;
} }
/* unbind/delete oldProg */
if (curProg->Id != 0) {
/* decrement refcount on previously bound fragment program */
curProg->RefCount--;
/* and delete if refcount goes below one */
if (curProg->RefCount <= 0) {
/* the program ID was already removed from the hash table */
ctx->Driver.DeleteProgram(ctx, curProg);
}
}
/* bind newProg */ /* bind newProg */
if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */ if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */
ctx->VertexProgram.Current = (struct gl_vertex_program *) newProg; _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
(struct gl_vertex_program *) newProg);
} }
else if (target == GL_FRAGMENT_PROGRAM_NV || else if (target == GL_FRAGMENT_PROGRAM_NV ||
target == GL_FRAGMENT_PROGRAM_ARB) { target == GL_FRAGMENT_PROGRAM_ARB) {
ctx->FragmentProgram.Current = (struct gl_fragment_program *) newProg; _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
(struct gl_fragment_program *) newProg);
} }
newProg->RefCount++;
/* Never null pointers */ /* Never null pointers */
ASSERT(ctx->VertexProgram.Current); ASSERT(ctx->VertexProgram.Current);
@@ -811,10 +847,7 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
} }
/* The ID is immediately available for re-use now */ /* The ID is immediately available for re-use now */
_mesa_HashRemove(ctx->Shared->Programs, ids[i]); _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
prog->RefCount--; _mesa_reference_program(ctx, &prog, NULL);
if (prog->RefCount <= 0) {
ctx->Driver.DeleteProgram(ctx, prog);
}
} }
} }
} }

View File

@@ -83,6 +83,28 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog);
extern struct gl_program * extern struct gl_program *
_mesa_lookup_program(GLcontext *ctx, GLuint id); _mesa_lookup_program(GLcontext *ctx, GLuint id);
extern void
_mesa_reference_program(GLcontext *ctx,
struct gl_program **ptr,
struct gl_program *prog);
static INLINE void
_mesa_reference_vertprog(GLcontext *ctx,
struct gl_vertex_program **ptr,
struct gl_vertex_program *prog)
{
_mesa_reference_program(ctx, (struct gl_program **) ptr,
(struct gl_program *) prog);
}
static INLINE void
_mesa_reference_fragprog(GLcontext *ctx,
struct gl_fragment_program **ptr,
struct gl_fragment_program *prog)
{
_mesa_reference_program(ctx, (struct gl_program **) ptr,
(struct gl_program *) prog);
}
extern struct gl_program * extern struct gl_program *
_mesa_clone_program(GLcontext *ctx, const struct gl_program *prog); _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog);

View File

@@ -80,8 +80,7 @@ _mesa_clear_shader_program_data(GLcontext *ctx,
* original/unlinked program. * original/unlinked program.
*/ */
shProg->VertexProgram->Base.Parameters = NULL; shProg->VertexProgram->Base.Parameters = NULL;
ctx->Driver.DeleteProgram(ctx, &shProg->VertexProgram->Base); _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL);
shProg->VertexProgram = NULL;
} }
if (shProg->FragmentProgram) { if (shProg->FragmentProgram) {
@@ -89,8 +88,7 @@ _mesa_clear_shader_program_data(GLcontext *ctx,
* original/unlinked program. * original/unlinked program.
*/ */
shProg->FragmentProgram->Base.Parameters = NULL; shProg->FragmentProgram->Base.Parameters = NULL;
ctx->Driver.DeleteProgram(ctx, &shProg->FragmentProgram->Base); _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
shProg->FragmentProgram = NULL;
} }
if (shProg->Uniforms) { if (shProg->Uniforms) {

View File

@@ -410,19 +410,19 @@ _slang_link(GLcontext *ctx,
* changing src/dst registers after merging the uniforms and varying vars. * changing src/dst registers after merging the uniforms and varying vars.
*/ */
if (vertProg) { if (vertProg) {
shProg->VertexProgram _mesa_reference_vertprog(ctx, &shProg->VertexProgram,
= vertex_program(_mesa_clone_program(ctx, &vertProg->Base)); vertex_program(_mesa_clone_program(ctx, &vertProg->Base)));
} }
else { else {
shProg->VertexProgram = NULL; _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL);
} }
if (fragProg) { if (fragProg) {
shProg->FragmentProgram _mesa_reference_fragprog(ctx, &shProg->FragmentProgram,
= fragment_program(_mesa_clone_program(ctx, &fragProg->Base)); fragment_program(_mesa_clone_program(ctx, &fragProg->Base)));
} }
else { else {
shProg->FragmentProgram = NULL; _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
} }
/* link varying vars */ /* link varying vars */

View File

@@ -39,6 +39,7 @@
#include "main/imports.h" #include "main/imports.h"
#include "main/mtypes.h" #include "main/mtypes.h"
#include "shader/program.h"
#include "pipe/p_context.h" #include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h" #include "pipe/p_shader_tokens.h"
@@ -264,14 +265,16 @@ update_linkage( struct st_context *st )
*/ */
assert(st->ctx->VertexProgram._Current); assert(st->ctx->VertexProgram._Current);
stvp = st_vertex_program(st->ctx->VertexProgram._Current); stvp = st_vertex_program(st->ctx->VertexProgram._Current);
assert(stvp->Base.Base.Target == GL_VERTEX_PROGRAM_ARB);
assert(st->ctx->FragmentProgram._Current); assert(st->ctx->FragmentProgram._Current);
stfp = st_fragment_program(st->ctx->FragmentProgram._Current); stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
assert(stfp->Base.Base.Target == GL_FRAGMENT_PROGRAM_ARB);
xvp = find_translated_vp(st, stvp, stfp); xvp = find_translated_vp(st, stvp, stfp);
st->vp = stvp; st_reference_vertprog(st, &st->vp, stvp);
st->fp = stfp; st_reference_fragprog(st, &st->fp, stfp);
cso_set_vertex_shader_handle(st->cso_context, stvp->driver_shader); cso_set_vertex_shader_handle(st->cso_context, stvp->driver_shader);
cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader); cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader);

View File

@@ -158,6 +158,9 @@ static void st_destroy_context_priv( struct st_context *st )
{ {
uint i; uint i;
st_reference_fragprog(st, &st->fp, NULL);
st_reference_vertprog(st, &st->vp, NULL);
draw_destroy(st->draw); draw_destroy(st->draw);
st_destroy_atoms( st ); st_destroy_atoms( st );
st_destroy_draw( st ); st_destroy_draw( st );

View File

@@ -34,7 +34,8 @@
#ifndef ST_PROGRAM_H #ifndef ST_PROGRAM_H
#define ST_PROGRAM_H #define ST_PROGRAM_H
#include "mtypes.h" #include "main/mtypes.h"
#include "shader/program.h"
#include "pipe/p_shader_tokens.h" #include "pipe/p_shader_tokens.h"
@@ -115,6 +116,27 @@ st_vertex_program( struct gl_vertex_program *vp )
} }
static INLINE void
st_reference_vertprog(struct st_context *st,
struct st_vertex_program **ptr,
struct st_vertex_program *prog)
{
_mesa_reference_program(st->ctx,
(struct gl_program **) ptr,
(struct gl_program *) prog);
}
static INLINE void
st_reference_fragprog(struct st_context *st,
struct st_fragment_program **ptr,
struct st_fragment_program *prog)
{
_mesa_reference_program(st->ctx,
(struct gl_program **) ptr,
(struct gl_program *) prog);
}
extern void extern void
st_translate_fragment_program(struct st_context *st, st_translate_fragment_program(struct st_context *st,
struct st_fragment_program *fp, struct st_fragment_program *fp,