Module: Mesa
Branch: main
Commit: 27467700e9b82eb7e8fb0471a4f31ff642051bc8
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=27467700e9b82eb7e8fb0471a4f31ff642051bc8

Author: Jesse Natalie <[email protected]>
Date:   Mon Apr 19 06:00:50 2021 -0700

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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10322>

---

 src/microsoft/clc/clc_compiler.c     | 40 +++++++++++++++++++-----------------
 src/microsoft/clc/clc_compiler.h     | 26 +++++++++++------------
 src/microsoft/clc/clon12compiler.def | 10 ++++-----
 src/microsoft/clc/compute_test.cpp   | 23 ++++++++++-----------
 src/microsoft/clc/compute_test.h     |  2 +-
 5 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c
index 248c63654eb..2d439776a8e 100644
--- a/src/microsoft/clc/clc_compiler.c
+++ b/src/microsoft/clc/clc_compiler.c
@@ -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.
diff --git a/src/microsoft/clc/clc_compiler.h b/src/microsoft/clc/clc_compiler.h
index fc772605b49..442e463da21 100644
--- a/src/microsoft/clc/clc_compiler.h
+++ b/src/microsoft/clc/clc_compiler.h
@@ -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,
diff --git a/src/microsoft/clc/clon12compiler.def 
b/src/microsoft/clc/clon12compiler.def
index 924f7aa6723..faa5da32f89 100644
--- a/src/microsoft/clc/clon12compiler.def
+++ b/src/microsoft/clc/clon12compiler.def
@@ -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
diff --git a/src/microsoft/clc/compute_test.cpp 
b/src/microsoft/clc/compute_test.cpp
index d19ff21095b..85cf7ecb4d3 100644
--- a/src/microsoft/clc/compute_test.cpp
+++ b/src/microsoft/clc/compute_test.cpp
@@ -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!");
diff --git a/src/microsoft/clc/compute_test.h b/src/microsoft/clc/compute_test.h
index 11e7d1cc4d7..5fa666a6dfe 100644
--- a/src/microsoft/clc/compute_test.h
+++ b/src/microsoft/clc/compute_test.h
@@ -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;

Reply via email to