glsl: don't use ralloc for blob creation
authorTimothy Arceri <tarceri@itsqueeze.com>
Fri, 10 Mar 2017 00:30:01 +0000 (11:30 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 12 Mar 2017 22:50:19 +0000 (09:50 +1100)
There is no need to use ralloc here.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/compiler/glsl/blob.c
src/compiler/glsl/blob.h
src/compiler/glsl/shader_cache.cpp
src/compiler/glsl/tests/blob_test.c
src/mesa/state_tracker/st_shader_cache.c

index 14dc69092f0c73d287160c0ec54cef435e08850b..769ebf1a0232fd81cb79c10ce855d3f650a15b13 100644 (file)
@@ -24,7 +24,6 @@
 #include <string.h>
 
 #include "main/macros.h"
-#include "util/ralloc.h"
 #include "blob.h"
 
 #define BLOB_INITIAL_SIZE 4096
@@ -49,7 +48,7 @@ grow_to_fit(struct blob *blob, size_t additional)
 
    to_allocate = MAX2(to_allocate, blob->allocated + additional);
 
-   new_data = reralloc_size(blob, blob->data, to_allocate);
+   new_data = realloc(blob->data, to_allocate);
    if (new_data == NULL)
       return false;
 
@@ -88,11 +87,9 @@ align_blob_reader(struct blob_reader *blob, size_t alignment)
 }
 
 struct blob *
-blob_create(void *mem_ctx)
+blob_create()
 {
-   struct blob *blob;
-
-   blob = ralloc(mem_ctx, struct blob);
+   struct blob *blob = (struct blob *) malloc(sizeof(struct blob));
    if (blob == NULL)
       return NULL;
 
index 21fa43dad37addd9b5f2be46636bf86853f64874..6d21ffdefe33940325b759ad0a8dc96498eef09e 100644 (file)
@@ -73,12 +73,12 @@ struct blob_reader {
 };
 
 /**
- * Create a new, empty blob, belonging to \mem_ctx.
+ * Create a new, empty blob.
  *
  * \return The new blob, (or NULL in case of allocation failure).
  */
 struct blob *
-blob_create(void *mem_ctx);
+blob_create(void);
 
 /**
  * Add some unstructured, fixed-size data to a blob.
index 6e56d86f2ffb98c2f42299920119b22cb39ce87d..7d8d63ba9e7ee35eff03e84b859e294deeb40f03 100644 (file)
@@ -1224,7 +1224,7 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
    if (*prog->data->sha1 == 0)
       return;
 
-   struct blob *metadata = blob_create(NULL);
+   struct blob *metadata = blob_create();
 
    write_uniforms(metadata, prog);
 
@@ -1272,7 +1272,7 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    disk_cache_put(cache, prog->data->sha1, metadata->data, metadata->size);
 
-   ralloc_free(metadata);
+   free(metadata);
 
    if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
       fprintf(stderr, "putting program metadata in cache: %s\n",
index 09114b144ad0d096ed14e2d306ed58f8972b0943..01b5ef0b2f074cec09608da8797b3a2ae685269f 100644 (file)
@@ -118,14 +118,13 @@ expect_equal_bytes(uint8_t *expected, uint8_t *actual,
 static void
 test_write_and_read_functions (void)
 {
-   void *ctx = ralloc_context(NULL);
    struct blob *blob;
    struct blob_reader reader;
    uint8_t *reserved;
    size_t str_offset, uint_offset;
    uint8_t reserve_buf[sizeof(reserve_test_str)];
 
-   blob = blob_create(ctx);
+   blob = blob_create();
 
    /*** Test blob by writing one of every possible kind of value. */
 
@@ -185,20 +184,19 @@ test_write_and_read_functions (void)
                 "read_consumes_all_bytes");
    expect_equal(false, reader.overrun, "read_does_not_overrun");
 
-   ralloc_free(ctx);
+   free(blob);
 }
 
 /* Test that data values are written and read with proper alignment. */
 static void
 test_alignment(void)
 {
-   void *ctx = ralloc_context(NULL);
    struct blob *blob;
    struct blob_reader reader;
    uint8_t bytes[] = "ABCDEFGHIJKLMNOP";
    size_t delta, last, num_bytes;
 
-   blob = blob_create(ctx);
+   blob = blob_create();
 
    /* First, write an intptr value to the blob and capture that size. This is
     * the expected offset between any pair of intptr values (if written with
@@ -244,19 +242,18 @@ test_alignment(void)
                    "aligned read of intptr_t");
    }
 
-   ralloc_free(ctx);
+   free(blob);
 }
 
 /* Test that we detect overrun. */
 static void
 test_overrun(void)
 {
-   void *ctx =ralloc_context(NULL);
    struct blob *blob;
    struct blob_reader reader;
    uint32_t value = 0xdeadbeef;
 
-   blob = blob_create(ctx);
+   blob = blob_create();
 
    blob_write_uint32(blob, value);
 
@@ -267,7 +264,7 @@ test_overrun(void)
    expect_equal(0, blob_read_uint32(&reader), "read at overrun");
    expect_equal(true, reader.overrun, "overrun flag set");
 
-   ralloc_free(ctx);
+   free(blob);
 }
 
 /* Test that we can read and write some large objects, (exercising the code in
@@ -284,7 +281,7 @@ test_big_objects(void)
    size_t i;
    char *buf;
 
-   blob = blob_create(ctx);
+   blob = blob_create();
 
    /* Initialize our buffer. */
    buf = ralloc_size(ctx, size);
@@ -311,6 +308,7 @@ test_big_objects(void)
    expect_equal(false, reader.overrun,
                 "overrun flag not set reading large objects");
 
+   free(blob);
    ralloc_free(ctx);
 }
 
index f22380ce729c4e2f09d4f8fc5fbacecabb92c73f..43831947b235d81a2b99e8a3a32fcc4070311efb 100644 (file)
@@ -68,7 +68,7 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
       return;
 
    unsigned char *sha1;
-   struct blob *blob = blob_create(NULL);
+   struct blob *blob = blob_create();
 
    switch (prog->info.stage) {
    case MESA_SHADER_VERTEX: {
@@ -134,7 +134,7 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
               _mesa_shader_stage_to_string(prog->info.stage), sha1_buf);
    }
 
-   ralloc_free(blob);
+   free(blob);
 }
 
 static void