nir/tests: Simplify the mem_ctx setup in our unit tests.

These all make a simple shader and free it at the end, that can be our
mem_ctx.

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7323>
This commit is contained in:
Eric Anholt
2020-10-26 11:22:49 -07:00
parent 5b9c7586f4
commit 2f372572a1
4 changed files with 19 additions and 30 deletions

View File

@@ -67,19 +67,16 @@ protected:
std::vector<nir_intrinsic_instr *> stores;
void *mem_ctx;
nir_builder *b;
nir_builder *b, _b;
};
nir_builder_test::nir_builder_test()
{
glsl_type_singleton_init_or_ref();
mem_ctx = ralloc_context(NULL);
static const nir_shader_compiler_options options = { };
b = rzalloc(mem_ctx, nir_builder);
*b = nir_builder_init_simple_shader(mem_ctx, MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(NULL, MESA_SHADER_COMPUTE, &options);
b = &_b;
}
nir_builder_test::~nir_builder_test()
@@ -89,7 +86,7 @@ nir_builder_test::~nir_builder_test()
nir_print_shader(b->shader, stdout);
}
ralloc_free(mem_ctx);
ralloc_free(b->shader);
glsl_type_singleton_decref();
}

View File

@@ -78,9 +78,7 @@ protected:
std::string swizzle(nir_alu_instr *instr, int src);
void *mem_ctx;
nir_builder *b;
nir_builder *b, _b;
std::map<unsigned, nir_alu_instr*> movs;
std::map<unsigned, nir_alu_src*> loads;
std::map<unsigned, nir_ssa_def*> res_map;
@@ -90,10 +88,9 @@ nir_load_store_vectorize_test::nir_load_store_vectorize_test()
{
glsl_type_singleton_init_or_ref();
mem_ctx = ralloc_context(NULL);
static const nir_shader_compiler_options options = { };
b = rzalloc(mem_ctx, nir_builder);
*b = nir_builder_init_simple_shader(mem_ctx, MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(NULL, MESA_SHADER_COMPUTE, &options);
b = &_b;
}
nir_load_store_vectorize_test::~nir_load_store_vectorize_test()
@@ -103,7 +100,7 @@ nir_load_store_vectorize_test::~nir_load_store_vectorize_test()
nir_print_shader(b->shader, stdout);
}
ralloc_free(mem_ctx);
ralloc_free(b->shader);
glsl_type_singleton_decref();
}

View File

@@ -38,8 +38,7 @@ protected:
nir_alu_instr *get_last_alu(nir_shader *);
void ASSERT_SWIZZLE_EQ(nir_alu_instr *, nir_alu_instr *, unsigned count, unsigned src);
void *mem_ctx;
nir_builder *b;
nir_builder *b, _b;
nir_shader *dup;
const nir_shader_compiler_options options;
};
@@ -49,10 +48,8 @@ nir_serialize_test::nir_serialize_test()
{
glsl_type_singleton_init_or_ref();
mem_ctx = ralloc_context(NULL);
b = rzalloc(mem_ctx, nir_builder);
*b = nir_builder_init_simple_shader(mem_ctx, MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(NULL, MESA_SHADER_COMPUTE, &options);
b = &_b;
}
nir_serialize_test::~nir_serialize_test()
@@ -65,7 +62,7 @@ nir_serialize_test::~nir_serialize_test()
nir_print_shader(dup, stdout);
}
ralloc_free(mem_ctx);
ralloc_free(b->shader);
glsl_type_singleton_decref();
}
@@ -79,7 +76,7 @@ nir_serialize_test::serialize() {
nir_serialize(&blob, b->shader, false);
blob_reader_init(&reader, blob.data, blob.size);
nir_shader *cloned = nir_deserialize(mem_ctx, &options, &reader);
nir_shader *cloned = nir_deserialize(b->shader, &options, &reader);
blob_finish(&blob);
dup = cloned;

View File

@@ -92,21 +92,19 @@ protected:
nir_deref_instr *get_deref(nir_deref_type deref_type,
unsigned index);
void *mem_ctx;
void *lin_ctx;
nir_builder *b;
nir_builder *b, _b;
};
nir_vars_test::nir_vars_test()
{
glsl_type_singleton_init_or_ref();
mem_ctx = ralloc_context(NULL);
lin_ctx = linear_alloc_parent(mem_ctx, 0);
static const nir_shader_compiler_options options = { };
b = rzalloc(mem_ctx, nir_builder);
*b = nir_builder_init_simple_shader(mem_ctx, MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(NULL, MESA_SHADER_COMPUTE, &options);
b = &_b;
lin_ctx = linear_alloc_parent(b->shader, 0);
}
nir_vars_test::~nir_vars_test()
@@ -116,7 +114,7 @@ nir_vars_test::~nir_vars_test()
nir_print_shader(b->shader, stdout);
}
ralloc_free(mem_ctx);
ralloc_free(b->shader);
glsl_type_singleton_decref();
}
@@ -1840,7 +1838,7 @@ TEST_F(nir_split_vars_test, simple_no_split_array_struct)
struct glsl_struct_field field;
field.type = glsl_float_type();
field.name = ralloc_asprintf(b, "field1");
field.name = ralloc_asprintf(b->shader, "field1");
field.location = -1;
field.offset = 0;