diff --git a/src/compiler/clc/clc.c b/src/compiler/clc/clc.c index da7e56c7cb2..d37c3adadad 100644 --- a/src/compiler/clc/clc.c +++ b/src/compiler/clc/clc.c @@ -88,105 +88,6 @@ clc_print_kernels_info(const struct clc_parsed_spirv *obj) } } -struct clc_libclc { - const nir_shader *libclc_nir; -}; - -struct clc_libclc * -clc_libclc_new(const struct clc_logger *logger, const struct clc_libclc_options *options) -{ - struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc); - if (!ctx) { - clc_error(logger, "D3D12: failed to allocate a clc_libclc"); - return NULL; - } - - const struct spirv_to_nir_options libclc_spirv_options = { - .environment = NIR_SPIRV_OPENCL, - .create_library = true, - .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, - .temp_addr_format = nir_address_format_32bit_offset_as_64bit, - .float_controls_execution_mode = FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32, - .caps = { - .address = true, - .float64 = true, - .int8 = true, - .int16 = true, - .int64 = true, - .kernel = true, - }, - }; - - glsl_type_singleton_init_or_ref(); - bool optimize = options && options->optimize; - nir_shader *s = - nir_load_libclc_shader(64, NULL, &libclc_spirv_options, options->nir_options, optimize); - if (!s) { - clc_error(logger, "D3D12: spirv_to_nir failed on libclc blob"); - ralloc_free(ctx); - return NULL; - } - - ralloc_steal(ctx, s); - ctx->libclc_nir = s; - - return ctx; -} - -void clc_free_libclc(struct clc_libclc *ctx) -{ - ralloc_free(ctx); - glsl_type_singleton_decref(); -} - -const nir_shader *clc_libclc_get_clc_shader(struct clc_libclc *ctx) -{ - return ctx->libclc_nir; -} - -void clc_libclc_serialize(struct clc_libclc *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_libclc_free_serialized(void *serialized) -{ - free(serialized); -} - -struct clc_libclc * -clc_libclc_deserialize(const void *serialized, size_t serialized_size) -{ - struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc); - if (!ctx) { - return NULL; - } - - glsl_type_singleton_init_or_ref(); - - struct blob_reader tmp; - blob_reader_init(&tmp, serialized, serialized_size); - - nir_shader *s = nir_deserialize(NULL, NULL, &tmp); - if (!s) { - ralloc_free(ctx); - return NULL; - } - - ralloc_steal(ctx, s); - ctx->libclc_nir = s; - - return ctx; -} - bool clc_compile_c_to_spir(const struct clc_compile_args *args, const struct clc_logger *logger, diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c index 8c21b04fd7d..0a90e85f59a 100644 --- a/src/microsoft/clc/clc_compiler.c +++ b/src/microsoft/clc/clc_compiler.c @@ -606,6 +606,105 @@ static bool shader_has_double(nir_shader *nir) return false; } +struct clc_libclc { + const nir_shader *libclc_nir; +}; + +struct clc_libclc * +clc_libclc_new(const struct clc_logger *logger, const struct clc_libclc_options *options) +{ + struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc); + if (!ctx) { + clc_error(logger, "D3D12: failed to allocate a clc_libclc"); + return NULL; + } + + const struct spirv_to_nir_options libclc_spirv_options = { + .environment = NIR_SPIRV_OPENCL, + .create_library = true, + .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, + .temp_addr_format = nir_address_format_32bit_offset_as_64bit, + .float_controls_execution_mode = FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32, + .caps = { + .address = true, + .float64 = true, + .int8 = true, + .int16 = true, + .int64 = true, + .kernel = true, + }, + }; + + glsl_type_singleton_init_or_ref(); + bool optimize = options && options->optimize; + nir_shader *s = + nir_load_libclc_shader(64, NULL, &libclc_spirv_options, options->nir_options, optimize); + if (!s) { + clc_error(logger, "D3D12: spirv_to_nir failed on libclc blob"); + ralloc_free(ctx); + return NULL; + } + + ralloc_steal(ctx, s); + ctx->libclc_nir = s; + + return ctx; +} + +void clc_free_libclc(struct clc_libclc *ctx) +{ + ralloc_free(ctx); + glsl_type_singleton_decref(); +} + +const nir_shader *clc_libclc_get_clc_shader(struct clc_libclc *ctx) +{ + return ctx->libclc_nir; +} + +void clc_libclc_serialize(struct clc_libclc *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_libclc_free_serialized(void *serialized) +{ + free(serialized); +} + +struct clc_libclc * +clc_libclc_deserialize(const void *serialized, size_t serialized_size) +{ + struct clc_libclc *ctx = rzalloc(NULL, struct clc_libclc); + if (!ctx) { + return NULL; + } + + glsl_type_singleton_init_or_ref(); + + struct blob_reader tmp; + blob_reader_init(&tmp, serialized, serialized_size); + + nir_shader *s = nir_deserialize(NULL, NULL, &tmp); + if (!s) { + ralloc_free(ctx); + return NULL; + } + + ralloc_steal(ctx, s); + ctx->libclc_nir = s; + + return ctx; +} + struct clc_libclc * clc_libclc_new_dxil(const struct clc_logger *logger, const struct clc_libclc_dxil_options *options)