Commit 29d4beac authored by Jesse Natalie's avatar Jesse Natalie Committed by Erik Faye-Lund
Browse files

microsoft/clc: Add exports for optimizing and serializing libclc

parent 41334358
......@@ -22,6 +22,7 @@
*/
#include "nir.h"
#include "nir_serialize.h"
#include "glsl_types.h"
#include "nir_types.h"
#include "nir_lower_libclc.h"
......@@ -632,6 +633,72 @@ clc_free_context(struct clc_context *ctx)
glsl_type_singleton_decref();
};
void clc_context_serialize(struct clc_context *context,
void **serialized,
size_t *serialized_size)
{
struct blob tmp;
blob_init(&tmp);
nir_serialize(&tmp, context->libclc_nir, true);
blob_finish_get_buffer(&tmp, serialized, serialized_size);
}
void clc_context_free_serialized(void *serialized)
{
free(serialized);
}
struct clc_context *
clc_context_deserialize(const void *serialized, size_t serialized_size)
{
struct clc_context *ctx = calloc(1, sizeof(*ctx));
if (!ctx) {
return NULL;
}
const struct nir_shader_compiler_options *libclc_nir_options =
dxil_get_nir_compiler_options();
glsl_type_singleton_init_or_ref();
struct blob_reader tmp;
blob_reader_init(&tmp, serialized, serialized_size);
ctx->libclc_nir = nir_deserialize(NULL, libclc_nir_options, &tmp);
if (!ctx->libclc_nir) {
free(ctx);
return NULL;
}
return ctx;
}
void clc_context_optimize(struct clc_context *context)
{
nir_shader *s = context->libclc_nir;
bool progress;
do {
progress = false;
NIR_PASS(progress, s, nir_split_var_copies);
NIR_PASS(progress, s, nir_opt_copy_prop_vars);
NIR_PASS(progress, s, nir_lower_var_copies);
NIR_PASS(progress, s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);
NIR_PASS(progress, s, nir_opt_dce);
NIR_PASS(progress, s, nir_opt_if, true);
NIR_PASS(progress, s, nir_opt_dead_cf);
NIR_PASS(progress, s, nir_opt_cse);
NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true);
NIR_PASS(progress, s, nir_opt_algebraic);
NIR_PASS(progress, s, nir_opt_constant_folding);
NIR_PASS(progress, s, nir_opt_undef);
NIR_PASS(progress, s, nir_lower_undef_to_zero);
NIR_PASS(progress, s, nir_opt_deref);
} while (progress);
}
struct clc_object *
clc_compile(struct clc_context *ctx,
const struct clc_compile_args *args,
......
......@@ -185,6 +185,11 @@ struct clc_context *clc_context_new(const struct clc_logger *logger);
void clc_free_context(struct clc_context *ctx);
void clc_context_optimize(struct clc_context *ctx);
void clc_context_serialize(struct clc_context *ctx, void **serialized, size_t *size);
void clc_context_free_serialized(void *serialized);
struct clc_context *clc_context_deserialize(void *serialized, size_t size);
struct clc_object *
clc_compile(struct clc_context *ctx,
const struct clc_compile_args *args,
......
EXPORTS
clc_context_new
clc_free_context
clc_context_optimize
clc_context_serialize
clc_context_free_serialized
clc_context_deserialize
clc_compile
clc_link
clc_free_object
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment