nv50: update to handle new sampler view state
[mesa.git] / src / gallium / drivers / nv50 / nv50_state.c
index 8e5f1662eacb7343d7fbf567ff1f95cf755cbf90..dd457c0f00f6f32f299db3aaf5aedfd976384849 100644 (file)
@@ -238,6 +238,9 @@ nv50_sampler_state_create(struct pipe_context *pipe,
        return (void *)sso;
 }
 
+/* type == 0 for VPs, 1 for GPs, 2 for FPs, which is how the
+ * relevant tesla methods are indexed (NV50TCL_BIND_TSC etc.)
+ */
 static INLINE void
 nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
                        unsigned nr, void **sampler)
@@ -253,13 +256,13 @@ nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
 static void
 nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
 {
-       nv50_sampler_state_bind(pipe, PIPE_SHADER_VERTEX, nr, s);
+       nv50_sampler_state_bind(pipe, 0, nr, s);
 }
 
 static void
 nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
 {
-       nv50_sampler_state_bind(pipe, PIPE_SHADER_FRAGMENT, nr, s);
+       nv50_sampler_state_bind(pipe, 2, nr, s);
 }
 
 static void
@@ -269,24 +272,21 @@ nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
 }
 
 static INLINE void
-nv50_set_sampler_views(struct pipe_context *pipe,
-                      unsigned type,
+nv50_set_sampler_views(struct pipe_context *pipe, unsigned p,
                       unsigned nr,
                       struct pipe_sampler_view **views)
 {
        struct nv50_context *nv50 = nv50_context(pipe);
        unsigned i;
 
-       for (i = 0; i < nr; i++) {
-               pipe_sampler_view_reference(&nv50->sampler_views[type][i], views[i]);
-               pipe_texture_reference((void *)&nv50->miptree[type][i], views[i]->texture);
-       }
-       for (i = nr; i < nv50->miptree_nr[type]; i++) {
-               pipe_sampler_view_reference(&nv50->sampler_views[type][i], NULL);
-               pipe_texture_reference((void *)&nv50->miptree[type][i], NULL);
-       }
+       for (i = 0; i < nr; i++)
+               pipe_sampler_view_reference(&nv50->sampler_views[p][i],
+                                           views[i]);
 
-       nv50->miptree_nr[type] = nr;
+       for (i = nr; i < nv50->sampler_view_nr[p]; i++)
+               pipe_sampler_view_reference(&nv50->sampler_views[p][i], NULL);
+
+       nv50->sampler_view_nr[p] = nr;
        nv50->dirty |= NV50_NEW_TEXTURE;
 }
 
@@ -295,7 +295,7 @@ nv50_set_vp_sampler_views(struct pipe_context *pipe,
                          unsigned nr,
                          struct pipe_sampler_view **views)
 {
-       nv50_set_sampler_views(pipe, PIPE_SHADER_VERTEX, nr, views);
+       nv50_set_sampler_views(pipe, 0, nr, views);
 }
 
 static void
@@ -303,7 +303,15 @@ nv50_set_fp_sampler_views(struct pipe_context *pipe,
                          unsigned nr,
                          struct pipe_sampler_view **views)
 {
-       nv50_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, nr, views);
+       nv50_set_sampler_views(pipe, 2, nr, views);
+}
+
+static void
+nv50_sampler_view_destroy(struct pipe_context *pipe,
+                         struct pipe_sampler_view *view)
+{
+       pipe_texture_reference(&view->texture, NULL);
+       FREE(nv50_sampler_view(view));
 }
 
 static struct pipe_sampler_view *
@@ -311,26 +319,22 @@ nv50_create_sampler_view(struct pipe_context *pipe,
                         struct pipe_texture *texture,
                         const struct pipe_sampler_view *templ)
 {
-       struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
+       struct nv50_sampler_view *view = CALLOC_STRUCT(nv50_sampler_view);
 
-       *view = *templ;
-       view->reference.count = 1;
-       view->texture = NULL;
-       pipe_texture_reference(&view->texture, texture);
-       view->context = pipe;
+       view->pipe = *templ;
+       view->pipe.reference.count = 1;
+       view->pipe.texture = NULL;
+       pipe_texture_reference(&view->pipe.texture, texture);
+       view->pipe.context = pipe;
 
-       return view;
+       if (!nv50_tex_construct(view)) {
+               nv50_sampler_view_destroy(pipe, &view->pipe);
+               return NULL;
+       }
+       return &view->pipe;
 }
 
 
-static void
-nv50_sampler_view_destroy(struct pipe_context *pipe,
-                         struct pipe_sampler_view *view)
-{
-       pipe_texture_reference(&view->texture, NULL);
-       FREE(view);
-}
-
 static void *
 nv50_rasterizer_state_create(struct pipe_context *pipe,
                             const struct pipe_rasterizer_state *cso)