microsoft/clc: Clean up clc_context

1. Rename it to libclc to match what it is
2. Make it opaque externally
3. Remove it from non-essential entrypoints (compile/link)

Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10322>
This commit is contained in:
Jesse Natalie 2021-04-19 06:00:50 -07:00 committed by Marge Bot
parent 24b096035f
commit 27467700e9
5 changed files with 50 additions and 51 deletions

View file

@ -451,7 +451,7 @@ clc_lower_nonnormalized_samplers(nir_shader *nir,
static void
clc_context_optimize(nir_shader *s)
clc_libclc_optimize(nir_shader *s)
{
bool progress;
do {
@ -475,12 +475,16 @@ clc_context_optimize(nir_shader *s)
} while (progress);
}
struct clc_context *
clc_context_new(const struct clc_logger *logger, const struct clc_context_options *options)
struct clc_libclc {
const void *libclc_nir;
};
struct clc_libclc *
clc_libclc_new(const struct clc_logger *logger, const struct clc_libclc_options *options)
{
struct clc_context *ctx = rzalloc(NULL, struct clc_context);
struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc);
if (!ctx) {
clc_error(logger, "D3D12: failed to allocate a clc_context");
clc_error(logger, "D3D12: failed to allocate a clc_libclc");
return NULL;
}
@ -513,7 +517,7 @@ clc_context_new(const struct clc_logger *logger, const struct clc_context_option
}
if (options && options->optimize)
clc_context_optimize(s);
clc_libclc_optimize(s);
ralloc_steal(ctx, s);
ctx->libclc_nir = s;
@ -522,13 +526,13 @@ clc_context_new(const struct clc_logger *logger, const struct clc_context_option
}
void
clc_free_context(struct clc_context *ctx)
clc_free_libclc(struct clc_libclc *ctx)
{
ralloc_free(ctx);
glsl_type_singleton_decref();
};
void clc_context_serialize(struct clc_context *context,
void clc_libclc_serialize(struct clc_libclc *context,
void **serialized,
size_t *serialized_size)
{
@ -539,15 +543,15 @@ void clc_context_serialize(struct clc_context *context,
blob_finish_get_buffer(&tmp, serialized, serialized_size);
}
void clc_context_free_serialized(void *serialized)
void clc_libclc_free_serialized(void *serialized)
{
free(serialized);
}
struct clc_context *
clc_context_deserialize(const void *serialized, size_t serialized_size)
struct clc_libclc *
clc_libclc_deserialize(const void *serialized, size_t serialized_size)
{
struct clc_context *ctx = rzalloc(NULL, struct clc_context);
struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc);
if (!ctx) {
return NULL;
}
@ -572,8 +576,7 @@ struct clc_context *
}
struct clc_object *
clc_compile(struct clc_context *ctx,
const struct clc_compile_args *args,
clc_compile(const struct clc_compile_args *args,
const struct clc_logger *logger)
{
struct clc_object *obj;
@ -598,8 +601,7 @@ clc_compile(struct clc_context *ctx,
}
struct clc_object *
clc_link(struct clc_context *ctx,
const struct clc_linker_args *args,
clc_link(const struct clc_linker_args *args,
const struct clc_logger *logger)
{
struct clc_object *out_obj;
@ -1010,7 +1012,7 @@ scale_fdiv(nir_shader *nir)
}
struct clc_dxil_object *
clc_to_dxil(struct clc_context *ctx,
clc_to_dxil(struct clc_libclc *lib,
const struct clc_object *obj,
const char *entrypoint,
const struct clc_runtime_kernel_conf *conf,
@ -1039,7 +1041,7 @@ clc_to_dxil(struct clc_context *ctx,
const struct spirv_to_nir_options spirv_options = {
.environment = NIR_SPIRV_OPENCL,
.clc_shader = ctx->libclc_nir,
.clc_shader = lib->libclc_nir,
.constant_addr_format = nir_address_format_32bit_index_offset_pack64,
.global_addr_format = nir_address_format_32bit_index_offset_pack64,
.shared_addr_format = nir_address_format_32bit_offset_as_64bit,
@ -1116,7 +1118,7 @@ clc_to_dxil(struct clc_context *ctx,
// according to the comment on nir_inline_functions
NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_lower_libclc, ctx->libclc_nir);
NIR_PASS_V(nir, nir_lower_libclc, lib->libclc_nir);
NIR_PASS_V(nir, nir_inline_functions);
// Pick off the single entrypoint that we want.

View file

@ -187,30 +187,28 @@ struct clc_dxil_object {
} binary;
};
struct clc_context {
const void *libclc_nir;
};
struct clc_libclc;
struct clc_context_options {
struct clc_libclc_options {
unsigned optimize;
};
struct clc_context *clc_context_new(const struct clc_logger *logger, const struct clc_context_options *options);
struct clc_libclc *clc_libclc_new(const struct clc_logger *logger, const struct clc_libclc_options *options);
void clc_free_libclc(struct clc_libclc *lib);
void clc_libclc_serialize(struct clc_libclc *lib, void **serialized, size_t *size);
void clc_libclc_free_serialized(void *serialized);
struct clc_libclc *clc_libclc_deserialize(void *serialized, size_t size);
void clc_free_context(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,
clc_compile(const struct clc_compile_args *args,
const struct clc_logger *logger);
struct clc_object *
clc_link(struct clc_context *ctx,
const struct clc_linker_args *args,
clc_link(const struct clc_linker_args *args,
const struct clc_logger *logger);
void clc_free_object(struct clc_object *obj);
@ -237,7 +235,7 @@ struct clc_runtime_kernel_conf {
};
struct clc_dxil_object *
clc_to_dxil(struct clc_context *ctx,
clc_to_dxil(struct clc_libclc *ctx,
const struct clc_object *obj,
const char *entrypoint,
const struct clc_runtime_kernel_conf *conf,

View file

@ -1,9 +1,9 @@
EXPORTS
clc_context_new
clc_free_context
clc_context_serialize
clc_context_free_serialized
clc_context_deserialize
clc_libclc_new
clc_free_libclc
clc_libclc_serialize
clc_libclc_free_serialized
clc_libclc_deserialize
clc_compile
clc_link
clc_free_object

View file

@ -48,8 +48,8 @@ enum compute_test_debug_flags {
static const struct debug_named_value compute_debug_options[] = {
{ "experimental_shaders", COMPUTE_DEBUG_EXPERIMENTAL_SHADERS, "Enable experimental shaders" },
{ "use_hw_d3d", COMPUTE_DEBUG_USE_HW_D3D, "Use a hardware D3D device" },
{ "optimize_libclc", COMPUTE_DEBUG_OPTIMIZE_LIBCLC, "Optimize the clc_context before using it" },
{ "serialize_libclc", COMPUTE_DEBUG_SERIALIZE_LIBCLC, "Serialize and deserialize the clc_context" },
{ "optimize_libclc", COMPUTE_DEBUG_OPTIMIZE_LIBCLC, "Optimize the clc_libclc before using it" },
{ "serialize_libclc", COMPUTE_DEBUG_SERIALIZE_LIBCLC, "Serialize and deserialize the clc_libclc" },
DEBUG_NAMED_VALUE_END
};
@ -617,31 +617,31 @@ ComputeTest::run_shader_with_raw_args(Shader shader,
void
ComputeTest::SetUp()
{
static struct clc_context *compiler_ctx_g = nullptr;
static struct clc_libclc *compiler_ctx_g = nullptr;
if (!compiler_ctx_g) {
clc_context_options options = { };
clc_libclc_options options = { };
options.optimize = (debug_get_option_debug_compute() & COMPUTE_DEBUG_OPTIMIZE_LIBCLC) != 0;
compiler_ctx_g = clc_context_new(&logger, &options);
compiler_ctx_g = clc_libclc_new(&logger, &options);
if (!compiler_ctx_g)
throw runtime_error("failed to create CLC compiler context");
if (debug_get_option_debug_compute() & COMPUTE_DEBUG_SERIALIZE_LIBCLC) {
void *serialized = nullptr;
size_t serialized_size = 0;
clc_context_serialize(compiler_ctx_g, &serialized, &serialized_size);
clc_libclc_serialize(compiler_ctx_g, &serialized, &serialized_size);
if (!serialized)
throw runtime_error("failed to serialize CLC compiler context");
clc_free_context(compiler_ctx_g);
clc_free_libclc(compiler_ctx_g);
compiler_ctx_g = nullptr;
compiler_ctx_g = clc_context_deserialize(serialized, serialized_size);
compiler_ctx_g = clc_libclc_deserialize(serialized, serialized_size);
if (!compiler_ctx_g)
throw runtime_error("failed to deserialize CLC compiler context");
clc_context_free_serialized(serialized);
clc_libclc_free_serialized(serialized);
}
}
compiler_ctx = compiler_ctx_g;
@ -803,7 +803,7 @@ ComputeTest::compile(const std::vector<const char *> &sources,
for (unsigned i = 0; i < sources.size(); i++) {
args.source.value = sources[i];
auto obj = clc_compile(compiler_ctx, &args, &logger);
auto obj = clc_compile(&args, &logger);
if (!obj)
throw runtime_error("failed to compile object!");
@ -830,8 +830,7 @@ ComputeTest::link(const std::vector<Shader> &sources,
link_args.in_objs = objs.data();
link_args.num_in_objs = (unsigned)objs.size();
link_args.create_library = create_library;
struct clc_object *obj = clc_link(compiler_ctx,
&link_args,
struct clc_object *obj = clc_link(&link_args,
&logger);
if (!obj)
throw runtime_error("failed to link objects!");

View file

@ -314,7 +314,7 @@ protected:
ID3D12GraphicsCommandList *cmdlist;
ID3D12DescriptorHeap *uav_heap;
struct clc_context *compiler_ctx;
struct clc_libclc *compiler_ctx;
UINT uav_heap_incr;
int fence_value;