meta: leaking of BO with DrawPixels
[mesa.git] / src / mesa / drivers / common / meta.c
index cd898e26f6fbf98a63d0707aaf9b7be0efa5b14b..65362935320d320fdea94c400cd44cdd415d0d24 100644 (file)
@@ -42,6 +42,7 @@
 #include "main/buffers.h"
 #include "main/clear.h"
 #include "main/condrender.h"
+#include "main/draw.h"
 #include "main/depth.h"
 #include "main/enable.h"
 #include "main/fbobject.h"
@@ -88,6 +89,7 @@
 #include "util/bitscan.h"
 #include "util/ralloc.h"
 #include "compiler/nir/nir.h"
+#include "util/u_math.h"
 
 /** Return offset in bytes of the field within a vertex struct */
 #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
@@ -102,6 +104,8 @@ static void cleanup_temp_texture(struct gl_context *ctx,
                                  struct temp_texture *tex);
 static void meta_glsl_clear_cleanup(struct gl_context *ctx,
                                     struct clear_state *clear);
+static void meta_copypix_cleanup(struct gl_context *ctx,
+                                    struct copypix_state *copypix);
 static void meta_decompress_cleanup(struct gl_context *ctx,
                                     struct decompress_state *decompress);
 static void meta_drawpix_cleanup(struct gl_context *ctx,
@@ -125,7 +129,7 @@ _mesa_meta_framebuffer_texture_image(struct gl_context *ctx,
    assert(att);
 
    _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, texTarget,
-                             level, layer, false);
+                             level, att->NumSamples, layer, false);
 }
 
 static struct gl_shader *
@@ -377,7 +381,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                       offsetof(struct vertex, tex));
             _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(0),
                                      *buf_obj, 0, sizeof(struct vertex));
-            _mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_TEX(0));
+            _mesa_enable_vertex_array_attrib(ctx, array_obj,
+                                             VERT_ATTRIB_TEX(0));
          }
 
          if (color_size > 0) {
@@ -387,7 +392,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                       offsetof(struct vertex, r));
             _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_COLOR0,
                                      *buf_obj, 0, sizeof(struct vertex));
-            _mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_COLOR0);
+            _mesa_enable_vertex_array_attrib(ctx, array_obj,
+                                             VERT_ATTRIB_COLOR0);
          }
       }
    } else {
@@ -418,6 +424,7 @@ _mesa_meta_free(struct gl_context *ctx)
    _mesa_make_current(ctx, NULL, NULL);
    _mesa_meta_glsl_blit_cleanup(ctx, &ctx->Meta->Blit);
    meta_glsl_clear_cleanup(ctx, &ctx->Meta->Clear);
+   meta_copypix_cleanup(ctx, &ctx->Meta->CopyPix);
    _mesa_meta_glsl_generate_mipmap_cleanup(ctx, &ctx->Meta->Mipmap);
    cleanup_temp_texture(ctx, &ctx->Meta->TempTex);
    meta_decompress_cleanup(ctx, &ctx->Meta->Decompress);
@@ -1012,6 +1019,8 @@ _mesa_meta_end(struct gl_context *ctx)
 
          _mesa_reference_pipeline_object(ctx, &save->Pipeline, NULL);
       }
+
+      _mesa_update_vertex_processing_mode(ctx);
    }
 
    if (state & MESA_META_STENCIL_TEST) {
@@ -1239,7 +1248,7 @@ init_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
    else {
       /* use 2D texture, NPOT if possible */
       tex->Target = GL_TEXTURE_2D;
-      tex->MaxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+      tex->MaxSize = ctx->Const.MaxTextureSize;
       tex->NPOT = ctx->Extensions.ARB_texture_non_power_of_two;
    }
    tex->MinSize = 16;  /* 16 x 16 at least */
@@ -1459,6 +1468,8 @@ _mesa_meta_setup_drawpix_texture(struct gl_context *ctx,
          /* load image */
          _mesa_TexSubImage2D(tex->Target, 0,
                              0, 0, width, height, format, type, pixels);
+
+         _mesa_reference_buffer_object(ctx, &save_unpack_obj, NULL);
       }
    }
    else {
@@ -1589,6 +1600,17 @@ meta_glsl_clear_cleanup(struct gl_context *ctx, struct clear_state *clear)
    }
 }
 
+static void
+meta_copypix_cleanup(struct gl_context *ctx, struct copypix_state *copypix)
+{
+   if (copypix->VAO == 0)
+      return;
+   _mesa_DeleteVertexArrays(1, &copypix->VAO);
+   copypix->VAO = 0;
+   _mesa_reference_buffer_object(ctx, &copypix->buf_obj, NULL);
+}
+
+
 /**
  * Given a bitfield of BUFFER_BIT_x draw buffers, call glDrawBuffers to
  * set GL to only draw to those buffers.
@@ -1607,7 +1629,7 @@ _mesa_meta_drawbuffers_from_bitfield(GLbitfield bits)
    assert((bits & ~BUFFER_BITS_COLOR) == 0);
 
    /* Make sure we don't overflow any arrays. */
-   assert(_mesa_bitcount(bits) <= MAX_DRAW_BUFFERS);
+   assert(util_bitcount(bits) <= MAX_DRAW_BUFFERS);
 
    enums[0] = GL_NONE;
 
@@ -1647,7 +1669,7 @@ _mesa_meta_drawbuffers_and_colormask(struct gl_context *ctx, GLbitfield mask)
    assert((mask & ~BUFFER_BITS_COLOR) == 0);
 
    /* Make sure we don't overflow any arrays. */
-   assert(_mesa_bitcount(mask) <= MAX_DRAW_BUFFERS);
+   assert(util_bitcount(mask) <= MAX_DRAW_BUFFERS);
 
    enums[0] = GL_NONE;
 
@@ -3075,7 +3097,7 @@ decompress_texture_image(struct gl_context *ctx,
    /* alloc dest surface */
    if (width > decompress_fbo->Width || height > decompress_fbo->Height) {
       _mesa_renderbuffer_storage(ctx, decompress_fbo->rb, rbFormat,
-                                 width, height, 0);
+                                 width, height, 0, 0);
 
       /* Do the full completeness check to recompute
        * ctx->DrawBuffer->Width/Height.