st/mesa: Cache FBO texture's sampler view object.
authorMichal Krol <michal@vmware.com>
Mon, 15 Mar 2010 12:18:30 +0000 (13:18 +0100)
committerMichal Krol <michal@vmware.com>
Mon, 15 Mar 2010 12:22:40 +0000 (13:22 +0100)
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_fbo.h
src/mesa/state_tracker/st_framebuffer.c
src/mesa/state_tracker/st_texture.c

index abf0c8d6cb1d0bc3549486087e1305c2899482ff..b219763beab339033320905a74639530a2a8f30c 100644 (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;
+}
index bea6eb89c3ecf0b7782df89757c37bc7efd7af6a..7a45a608fe120d3d541c6fcbd3fcbbb6f864284c 100644 (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 */
index 0a91183f89dd3a0d75b04caf9dbc9eefb4196e98..d3c43bbc68a7b180532b380c164021d71a764d12 100644 (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.
index 10a38befb41548484d2dc2db02244c4dcd0e5777..ef97d873e5076fa9ffb69bdddc6e953e4d4d6cab 100644 (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;