Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / python / st_device.c
index 45e78417500e505b34625674da5d0f9a78cc5867..135acad45e16775c48e73a4094a0aa0bef8d3e58 100644 (file)
 #include "pipe/p_shader_tokens.h"
 #include "util/u_inlines.h"
 #include "cso_cache/cso_context.h"
+#include "util/u_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "util/u_sampler.h"
 #include "util/u_simple_shaders.h"
-#include "trace/tr_screen.h"
-#include "trace/tr_context.h"
+#include "trace/tr_public.h"
 
 #include "st_device.h"
 #include "st_winsys.h"
@@ -75,43 +76,34 @@ st_device_destroy(struct st_device *st_dev)
 }
 
 
-static struct st_device *
-st_device_create_from_st_winsys(const struct st_winsys *st_ws) 
+struct st_device *
+st_device_create(boolean hardware)
 {
+   struct pipe_screen *screen;
    struct st_device *st_dev;
-   
-   if(!st_ws->screen_create)
-      return NULL;
-   
+
+   if (hardware)
+      screen = st_hardware_screen_create();
+   else
+      screen = st_software_screen_create("softpipe");
+
+   screen = trace_screen_create(screen);
+   if (!screen)
+      goto no_screen;
+
    st_dev = CALLOC_STRUCT(st_device);
-   if(!st_dev)
-      return NULL;
+   if (!st_dev)
+      goto no_device;
    
    pipe_reference_init(&st_dev->reference, 1);
-   st_dev->st_ws = st_ws;
-   
-   st_dev->real_screen = st_ws->screen_create();
-   if(!st_dev->real_screen) {
-      st_device_destroy(st_dev);
-      return NULL;
-   }
-
-   st_dev->screen = trace_screen_create(st_dev->real_screen);
-   if(!st_dev->screen) {
-      st_device_destroy(st_dev);
-      return NULL;
-   }
+   st_dev->screen = screen;
    
    return st_dev;
-}
-
 
-struct st_device *
-st_device_create(boolean hardware) {
-   if(hardware)
-      return st_device_create_from_st_winsys(&st_hardpipe_winsys);
-   else
-      return st_device_create_from_st_winsys(&st_softpipe_winsys);
+no_device:
+   screen->destroy(screen);
+no_screen:
+   return NULL;
 }
 
 
@@ -134,10 +126,10 @@ st_context_destroy(struct st_context *st_ctx)
          st_ctx->pipe->destroy(st_ctx->pipe);
       
       for(i = 0; i < PIPE_MAX_SAMPLERS; ++i)
-         pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], NULL);
+         pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL);
       for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
-         pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], NULL);
-      pipe_texture_reference(&st_ctx->default_texture, NULL);
+         pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL);
+      pipe_resource_reference(&st_ctx->default_texture, NULL);
 
       FREE(st_ctx);
       
@@ -237,9 +229,11 @@ st_context_create(struct st_device *st_dev)
 
    /* default textures */
    {
+      struct pipe_context *pipe = st_ctx->pipe;
       struct pipe_screen *screen = st_dev->screen;
-      struct pipe_texture templat;
-      struct pipe_transfer *transfer;
+      struct pipe_resource templat;
+      struct pipe_sampler_view view_templ;
+      struct pipe_sampler_view *view;
       unsigned i;
 
       memset( &templat, 0, sizeof( templat ) );
@@ -250,33 +244,43 @@ st_context_create(struct st_device *st_dev)
       templat.depth0 = 1;
       templat.last_level = 0;
    
-      st_ctx->default_texture = screen->texture_create( screen, &templat );
+      st_ctx->default_texture = screen->resource_create( screen, &templat );
       if(st_ctx->default_texture) {
-         transfer = screen->get_tex_transfer(screen,
-                                             st_ctx->default_texture,
-                                             0, 0, 0,
-                                             PIPE_TRANSFER_WRITE,
-                                             0, 0,
-                                             st_ctx->default_texture->width0,
-                                             st_ctx->default_texture->height0);
-         if (transfer) {
-            uint32_t *map;
-            map = (uint32_t *) screen->transfer_map(screen, transfer);
-            if(map) {
-               *map = 0x00000000;
-               screen->transfer_unmap(screen, transfer);
-            }
-            screen->tex_transfer_destroy(transfer);
-         }
+        struct pipe_box box;
+        uint32_t zero = 0;
+        
+        u_box_origin_2d( 1, 1, &box );
+
+        pipe->transfer_inline_write(pipe,
+                                    st_ctx->default_texture,
+                                    u_subresource(0,0),
+                                    PIPE_TRANSFER_WRITE,
+                                    &box,
+                                    &zero,
+                                    sizeof zero,
+                                    0);
       }
-   
+
+      u_sampler_view_default_template(&view_templ,
+                                      st_ctx->default_texture,
+                                      st_ctx->default_texture->format);
+      view = st_ctx->pipe->create_sampler_view(st_ctx->pipe,
+                                               st_ctx->default_texture,
+                                               &view_templ);
+
       for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
-         pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], st_ctx->default_texture);
+         pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view);
       for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
-         pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], st_ctx->default_texture);
-      
-      cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->fragment_sampler_textures);
-      cso_set_vertex_sampler_textures(st_ctx->cso, PIPE_MAX_VERTEX_SAMPLERS, st_ctx->vertex_sampler_textures);
+         pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view);
+
+      st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe,
+                                               PIPE_MAX_SAMPLERS,
+                                               st_ctx->fragment_sampler_views);
+      st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe,
+                                             PIPE_MAX_VERTEX_SAMPLERS,
+                                             st_ctx->vertex_sampler_views);
+
+      pipe_sampler_view_reference(&view, NULL);
    }
    
    /* vertex shader */