diff --git a/src/intel/compiler/brw_kernel.c b/src/intel/compiler/brw_kernel.c index a85dc583a58..ed8bc81f826 100644 --- a/src/intel/compiler/brw_kernel.c +++ b/src/intel/compiler/brw_kernel.c @@ -23,6 +23,7 @@ #include "brw_kernel.h" #include "brw_nir.h" +#include "elk/elk_nir_options.h" #include "intel_nir.h" #include "intel_nir.h" @@ -587,8 +588,8 @@ cleanup_llvm17_scratch(nir_shader *nir) } nir_shader * -brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size, - bool llvm17_wa) +brw_nir_from_spirv(void *mem_ctx, unsigned gfx_version, const uint32_t *spirv, + size_t spirv_size, bool llvm17_wa) { struct spirv_to_nir_options spirv_options = { .environment = NIR_SPIRV_OPENCL, @@ -625,9 +626,15 @@ brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size, }; assert(spirv_size % 4 == 0); + + assert(gfx_version); + const nir_shader_compiler_options *nir_options = + gfx_version >= 9 ? &brw_scalar_nir_options + : &elk_scalar_nir_options; + nir_shader *nir = spirv_to_nir(spirv, spirv_size / 4, NULL, 0, MESA_SHADER_KERNEL, - "library", &spirv_options, &brw_scalar_nir_options); + "library", &spirv_options, nir_options); nir_validate_shader(nir, "after spirv_to_nir"); nir_validate_ssa_dominance(nir, "after spirv_to_nir"); ralloc_steal(mem_ctx, nir); diff --git a/src/intel/compiler/brw_kernel.h b/src/intel/compiler/brw_kernel.h index fb1289872d5..f251d5d16ad 100644 --- a/src/intel/compiler/brw_kernel.h +++ b/src/intel/compiler/brw_kernel.h @@ -68,8 +68,8 @@ brw_kernel_from_spirv(struct brw_compiler *compiler, char **error_str); nir_shader * -brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size, - bool llvm17_wa); +brw_nir_from_spirv(void *mem_ctx, unsigned gfx_version, + const uint32_t *spirv, size_t spirv_size, bool llvm17_wa); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/intel/compiler/intel_clc.c b/src/intel/compiler/intel_clc.c index 6e7ba453eaf..c0b38cc6810 100644 --- a/src/intel/compiler/intel_clc.c +++ b/src/intel/compiler/intel_clc.c @@ -285,6 +285,7 @@ print_usage(char *exec_name, FILE *f) " -i, --in Specify one input filename. Accepted multiple times.\n" " -s, --spv Specify the output filename for spirv.\n" " -n, --nir Specify whether to output serialized NIR instead of ISA.\n" +" -g, --gfx-version Specify the Gfx version used for NIR output.\n" " -t, --text Specify the output filename for the parsed text\n" " -v, --verbose Print more information during compilation.\n" " -M, --llvm-version Print LLVM version.\n" @@ -301,6 +302,8 @@ struct intel_clc_params { char *txt_outfile; char *prefix; + unsigned gfx_version; + bool output_nir; bool print_info; bool llvm17_wa; @@ -359,7 +362,7 @@ output_nir(const struct intel_clc_params *params, struct clc_binary *binary) spirv_library_to_nir_builder(fp, binary->data, binary->size / 4, &spirv_options); - nir_shader *nir = brw_nir_from_spirv(params->mem_ctx, + nir_shader *nir = brw_nir_from_spirv(params->mem_ctx, params->gfx_version, binary->data, binary->size, params->llvm17_wa); if (!nir) { @@ -460,6 +463,7 @@ int main(int argc, char **argv) {"out", required_argument, 0, 'o'}, {"spv", required_argument, 0, 's'}, {"text", required_argument, 0, 't'}, + {"gfx-version", required_argument, 0, 'g'}, {"nir", no_argument, 0, 'n'}, {"llvm17-wa", no_argument, 0, 'L'}, {"llvm-version", no_argument, 0, 'M'}, @@ -482,7 +486,7 @@ int main(int argc, char **argv) util_dynarray_init(&input_files, params.mem_ctx); int ch; - while ((ch = getopt_long(argc, argv, "he:p:s:t:i:no:MLv", long_options, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "he:p:s:t:i:no:MLvg:", long_options, NULL)) != -1) { switch (ch) { @@ -519,6 +523,9 @@ int main(int argc, char **argv) case 'M': print_llvm_version(stdout); return EXIT_SUCCESS; + case 'g': + params.gfx_version = strtoul(optarg, NULL, 10); + break; case OPT_PREFIX: params.prefix = optarg; break; @@ -610,6 +617,12 @@ int main(int argc, char **argv) glsl_type_singleton_init_or_ref(); if (params.output_nir) { + if (params.gfx_version == 0) { + fprintf(stderr, "No target Gfx version specified.\n"); + print_usage(argv[0], stderr); + goto fail; + } + exit_code = output_nir(¶ms, &spirv_obj); } else { if (params.platform == NULL) { @@ -634,6 +647,12 @@ int main(int argc, char **argv) goto fail; } + if (params.gfx_version) { + fprintf(stderr, "WARNING: Ignorining unnecessary parameter for " + "gfx version, using version based on platform.\n"); + /* Keep going. */ + } + if (params.entry_point == NULL) { fprintf(stderr, "No entry-point name specified.\n"); print_usage(argv[0], stderr); diff --git a/src/intel/compiler/meson.build b/src/intel/compiler/meson.build index fa20d21479e..0ae71d1875d 100644 --- a/src/intel/compiler/meson.build +++ b/src/intel/compiler/meson.build @@ -190,7 +190,14 @@ if get_option('intel-clc') == 'system' elif with_intel_clc prog_intel_clc = executable( 'intel_clc', - ['intel_clc.c', 'brw_kernel.c'], + [ + 'intel_clc.c', + 'brw_kernel.c', + + # Use just the nir_options part of ELK instead of fully linking. + 'elk/elk_nir_options.h', + 'elk/elk_nir_options.c', + ], link_with : [ libintel_compiler_brw, libintel_common,libisl, ], diff --git a/src/intel/shaders/meson.build b/src/intel/shaders/meson.build index 2b613ddc5c4..be98e67d43a 100644 --- a/src/intel/shaders/meson.build +++ b/src/intel/shaders/meson.build @@ -55,6 +55,7 @@ foreach gen : intel_shaders_gens output : 'intel_gfx@0@_shaders_code.h'.format(gen[1]), command : [ prog_intel_clc, intel_shaders_clc_wa_args, '--nir', + '--gfx-version=@0@'.format(gen[0] / 10), '--prefix', 'gfx@0@_intel_shaders'.format(gen[1]), prepended_input_args, '-o', '@OUTPUT@', '--', '-cl-std=cl2.0', '-D__OPENCL_VERSION__=200',