clc: Move libclc helpers back to microsoft/clc

These were intended to be shared with (e.g.) rusticl, but they're
unused and I expect they will continue to be. The spirv options
are also hardcoded to be what CLOn12 expects.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26803>
This commit is contained in:
Jesse Natalie 2023-12-12 13:34:41 -08:00 committed by Marge Bot
parent a6658e3dc6
commit 6468c6a80b
2 changed files with 99 additions and 99 deletions

View file

@ -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,

View file

@ -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)