st/mesa: set compressed_data to NULL when freed
[mesa.git] / src / mesa / state_tracker / st_texture.c
index 58636286eefbe4431a3fa12ecb8e1dc0165a532b..a2a310daab4cfe640209edb8ac57441c09bbe58c 100644 (file)
@@ -1,8 +1,8 @@
 /**************************************************************************
- * 
+ *
  * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * distribute, sub license, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@@ -22,7 +22,7 @@
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
+ *
  **************************************************************************/
 
 #include <stdio.h>
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "util/u_rect.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "tgsi/tgsi_from_mesa.h"
 
 
 #define DBG if(0) printf
 struct pipe_resource *
 st_texture_create(struct st_context *st,
                   enum pipe_texture_target target,
-                 enum pipe_format format,
-                 GLuint last_level,
-                 GLuint width0,
-                 GLuint height0,
-                 GLuint depth0,
+                  enum pipe_format format,
+                  GLuint last_level,
+                  GLuint width0,
+                  GLuint height0,
+                  GLuint depth0,
                   GLuint layers,
                   GLuint nr_samples,
-                  GLuint bind )
+                  GLuint bind)
 {
    struct pipe_resource pt, *newtex;
    struct pipe_screen *screen = st->pipe->screen;
@@ -78,7 +79,7 @@ st_texture_create(struct st_context *st,
        (int) target, util_format_name(format), last_level);
 
    assert(format);
-   assert(screen->is_format_supported(screen, format, target, 0,
+   assert(screen->is_format_supported(screen, format, target, 0, 0,
                                       PIPE_BIND_SAMPLER_VIEW));
 
    memset(&pt, 0, sizeof(pt));
@@ -94,6 +95,7 @@ st_texture_create(struct st_context *st,
    /* only set this for OpenGL textures, not renderbuffers */
    pt.flags = PIPE_RESOURCE_FLAG_TEXTURING_MORE_LIKELY;
    pt.nr_samples = nr_samples;
+   pt.nr_storage_samples = nr_samples;
 
    newtex = screen->resource_create(screen, &pt);
 
@@ -205,9 +207,9 @@ st_texture_match_image(struct st_context *st,
    unsigned ptWidth;
    uint16_t ptHeight, ptDepth, ptLayers;
 
-   /* Images with borders are never pulled into mipmap textures. 
+   /* Images with borders are never pulled into mipmap textures.
     */
-   if (image->Border) 
+   if (image->Border)
       return GL_FALSE;
 
    /* Check if this image's format matches the established texture's format.
@@ -315,6 +317,7 @@ st_texture_image_unmap(struct st_context *st,
    *transfer = NULL;
 }
 
+
 /**
  * For debug only: get/print center pixel in the src resource.
  */
@@ -412,8 +415,8 @@ st_create_color_map_texture(struct gl_context *ctx)
 
    /* find an RGBA texture format */
    format = st_choose_format(st, GL_RGBA, GL_NONE, GL_NONE,
-                             PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW,
-                             FALSE);
+                             PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW,
+                             false, false);
 
    /* create texture for color map/table */
    pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
@@ -421,6 +424,7 @@ st_create_color_map_texture(struct gl_context *ctx)
    return pt;
 }
 
+
 /**
  * Destroy bound texture handles for the given stage.
  */
@@ -510,12 +514,15 @@ st_create_texture_handle_from_unit(struct st_context *st,
 {
    struct pipe_context *pipe = st->pipe;
    struct pipe_sampler_view *view;
-   struct pipe_sampler_state sampler;
+   struct pipe_sampler_state sampler = {0};
 
-   if (!st_update_single_texture(st, &view, texUnit, prog->sh.data->Version))
+   /* TODO: Clarify the interaction of ARB_bindless_texture and EXT_texture_sRGB_decode */
+   st_update_single_texture(st, &view, texUnit, prog->sh.data->Version >= 130, true);
+   if (!view)
       return 0;
 
-   st_convert_sampler_from_unit(st, &sampler, texUnit);
+   if (view->target != PIPE_BUFFER)
+      st_convert_sampler_from_unit(st, &sampler, texUnit);
 
    assert(st->ctx->Texture.Unit[texUnit]._Current);
 
@@ -533,7 +540,7 @@ st_create_image_handle_from_unit(struct st_context *st,
    struct pipe_context *pipe = st->pipe;
    struct pipe_image_view img;
 
-   st_convert_image_from_unit(st, &img, imgUnit);
+   st_convert_image_from_unit(st, &img, imgUnit, GL_READ_WRITE);
 
    return pipe->create_image_handle(pipe, &img);
 }
@@ -546,7 +553,7 @@ void
 st_make_bound_samplers_resident(struct st_context *st,
                                 struct gl_program *prog)
 {
-   enum pipe_shader_type shader = st_shader_stage_to_ptarget(prog->info.stage);
+   enum pipe_shader_type shader = pipe_shader_type_from_mesa(prog->info.stage);
    struct st_bound_handles *bound_handles = &st->bound_texture_handles[shader];
    struct pipe_context *pipe = st->pipe;
    GLuint64 handle;
@@ -593,7 +600,7 @@ void
 st_make_bound_images_resident(struct st_context *st,
                               struct gl_program *prog)
 {
-   enum pipe_shader_type shader = st_shader_stage_to_ptarget(prog->info.stage);
+   enum pipe_shader_type shader = pipe_shader_type_from_mesa(prog->info.stage);
    struct st_bound_handles *bound_handles = &st->bound_image_handles[shader];
    struct pipe_context *pipe = st->pipe;
    GLuint64 handle;