st/mesa: Cache FBO texture's sampler view object.

This commit is contained in:
Michal Krol 2010-03-15 13:18:30 +01:00
parent 08189e6391
commit dbf20a1f0f
4 changed files with 31 additions and 0 deletions

View file

@ -103,6 +103,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
*/
pipe_surface_reference( &strb->surface, NULL );
pipe_texture_reference( &strb->texture, NULL );
pipe_sampler_view_reference(&strb->sampler_view, NULL);
/* Setup new texture template.
*/
@ -162,6 +163,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb)
ASSERT(strb);
pipe_surface_reference(&strb->surface, NULL);
pipe_texture_reference(&strb->texture, NULL);
pipe_sampler_view_reference(&strb->sampler_view, NULL);
free(strb->data);
free(strb);
}
@ -368,6 +370,8 @@ st_render_texture(GLcontext *ctx,
pipe_surface_reference(&strb->surface, NULL);
pipe_sampler_view_reference(&strb->sampler_view, st_get_stobj_sampler_view(stObj));
assert(strb->rtt_level <= strb->texture->last_level);
/* new surface for rendering into the texture */
@ -647,3 +651,14 @@ void st_init_fbo_functions(struct dd_function_table *functions)
functions->DrawBuffers = st_DrawBuffers;
functions->ReadBuffer = st_ReadBuffer;
}
struct pipe_sampler_view *
st_renderbuffer_get_sampler_view(struct st_renderbuffer *rb,
struct pipe_context *pipe)
{
if (!rb->sampler_view) {
rb->sampler_view = st_sampler_view_from_texture(pipe, rb->texture);
}
return rb->sampler_view;
}

View file

@ -39,6 +39,7 @@ struct st_renderbuffer
struct gl_renderbuffer Base;
struct pipe_texture *texture;
struct pipe_surface *surface; /* temporary view into texture */
struct pipe_sampler_view *sampler_view;
enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */
GLboolean defined; /**< defined contents? */
@ -55,6 +56,7 @@ struct st_renderbuffer
/** Render to texture state */
struct pipe_texture *texture_save;
struct pipe_surface *surface_save;
struct pipe_sampler_view *sampler_view_save;
};
@ -71,5 +73,9 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw);
extern void
st_init_fbo_functions(struct dd_function_table *functions);
extern struct pipe_sampler_view *
st_renderbuffer_get_sampler_view(struct st_renderbuffer *rb,
struct pipe_context *pipe);
#endif /* ST_CB_FBO_H */

View file

@ -197,6 +197,7 @@ st_set_framebuffer_surface(struct st_framebuffer *stfb,
/* replace the renderbuffer's surface/texture pointers */
pipe_surface_reference( &strb->surface, surf );
pipe_texture_reference( &strb->texture, surf->texture );
pipe_sampler_view_reference(&strb->sampler_view, NULL);
if (ctx) {
/* If ctx isn't set, we've likely not made current yet.

View file

@ -528,14 +528,21 @@ st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex,
/* save the renderbuffer's surface/texture info */
pipe_texture_reference(&strb->texture_save, strb->texture);
pipe_surface_reference(&strb->surface_save, strb->surface);
pipe_sampler_view_reference(&strb->sampler_view_save, strb->sampler_view);
/* plug in new surface/texture info */
pipe_texture_reference(&strb->texture, stImage->pt);
/* XXX: Shouldn't we release reference to old surface here?
*/
strb->surface = screen->get_tex_surface(screen, strb->texture,
face, level, slice,
(PIPE_BUFFER_USAGE_GPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE));
pipe_sampler_view_reference(&strb->sampler_view, NULL);
st->dirty.st |= ST_NEW_FRAMEBUFFER;
return 1;
@ -565,9 +572,11 @@ st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
/* free tex surface, restore original */
pipe_surface_reference(&strb->surface, strb->surface_save);
pipe_texture_reference(&strb->texture, strb->texture_save);
pipe_sampler_view_reference(&strb->sampler_view, strb->sampler_view_save);
pipe_surface_reference(&strb->surface_save, NULL);
pipe_texture_reference(&strb->texture_save, NULL);
pipe_sampler_view_reference(&strb->sampler_view, NULL);
st->dirty.st |= ST_NEW_FRAMEBUFFER;