gallium: Check for OOM condition when creating a sampler view.
[mesa.git] / src / gallium / drivers / i965 / brw_pipe_sampler.c
index ef6c1bb3155a04ab0a4a2535d6eecb27bdc31267..d2aa2bc9f3579d9669ac5e7fdd83de87373479b0 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
+#include "util/u_inlines.h"
 
 #include "brw_context.h"
 #include "brw_defines.h"
@@ -113,14 +114,12 @@ brw_create_sampler_state( struct pipe_context *pipe,
 
    /* XXX: anisotropy logic slightly changed: 
     */
-   if (template->max_anisotropy > 1.0) {
+   if (template->max_anisotropy > 1) {
       sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC; 
       sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC;
 
-      if (template->max_anisotropy > 2.0) {
-        sampler->ss3.max_aniso = MIN2((template->max_anisotropy - 2) / 2,
-                                      BRW_ANISORATIO_16);
-      }
+      sampler->ss3.max_aniso = MIN2((template->max_anisotropy - 2) / 2,
+                                    BRW_ANISORATIO_16);
    }
 
    sampler->ss1.r_wrap_mode = translate_wrap_mode(template->wrap_r);
@@ -184,26 +183,26 @@ static void brw_delete_sampler_state(struct pipe_context *pipe,
    FREE(cso);
 }
 
-static void brw_set_sampler_textures(struct pipe_context *pipe,
-                                    unsigned num,
-                                    struct pipe_texture **texture)
+static void brw_set_fragment_sampler_views(struct pipe_context *pipe,
+                                           unsigned num,
+                                           struct pipe_sampler_view **views)
 {
    struct brw_context *brw = brw_context(pipe);
    int i;
 
    for (i = 0; i < num; i++)
-      pipe_texture_reference(&brw->curr.texture[i], texture[i]);
+      pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], views[i]);
 
-   for (i = num; i < brw->curr.num_textures; i++)
-      pipe_texture_reference(&brw->curr.texture[i], NULL);
+   for (i = num; i < brw->curr.num_fragment_sampler_views; i++)
+      pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], NULL);
 
-   brw->curr.num_textures = num;
+   brw->curr.num_fragment_sampler_views = num;
    brw->state.dirty.mesa |= PIPE_NEW_BOUND_TEXTURES;
 }
 
-static void brw_set_vertex_sampler_textures(struct pipe_context *pipe,
-                                            unsigned num,
-                                            struct pipe_texture **texture)
+static void brw_set_vertex_sampler_views(struct pipe_context *pipe,
+                                         unsigned num,
+                                         struct pipe_sampler_view **views)
 {
 }
 
@@ -213,17 +212,47 @@ static void brw_bind_vertex_sampler_state(struct pipe_context *pipe,
 }
 
 
+static struct pipe_sampler_view *
+brw_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);
+
+   if (view) {
+      *view = *templ;
+      view->reference.count = 1;
+      view->texture = NULL;
+      pipe_texture_reference(&view->texture, texture);
+      view->context = pipe;
+   }
+
+   return view;
+}
+
+
+static void
+brw_sampler_view_destroy(struct pipe_context *pipe,
+                         struct pipe_sampler_view *view)
+{
+   pipe_texture_reference(&view->texture, NULL);
+   FREE(view);
+}
+
+
 void brw_pipe_sampler_init( struct brw_context *brw )
 {
    brw->base.create_sampler_state = brw_create_sampler_state;
    brw->base.delete_sampler_state = brw_delete_sampler_state;
 
-   brw->base.set_fragment_sampler_textures = brw_set_sampler_textures;
+   brw->base.set_fragment_sampler_views = brw_set_fragment_sampler_views;
    brw->base.bind_fragment_sampler_states = brw_bind_sampler_state;
 
-   brw->base.set_vertex_sampler_textures = brw_set_vertex_sampler_textures;
+   brw->base.set_vertex_sampler_views = brw_set_vertex_sampler_views;
    brw->base.bind_vertex_sampler_states = brw_bind_vertex_sampler_state;
 
+   brw->base.create_sampler_view = brw_create_sampler_view;
+   brw->base.sampler_view_destroy = brw_sampler_view_destroy;
 }
 void brw_pipe_sampler_cleanup( struct brw_context *brw )
 {