intel-clc: Use correct set of nir_options when building for Gfx8

Use the correct set of nir_options when building for Gfx8.  Note this is
only used in the NIR codepath.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27563>
This commit is contained in:
Caio Oliveira 2024-02-14 15:59:45 -08:00 committed by Marge Bot
parent c83f92087b
commit 2bc18fe46f
5 changed files with 42 additions and 8 deletions

View file

@ -23,6 +23,7 @@
#include "brw_kernel.h" #include "brw_kernel.h"
#include "brw_nir.h" #include "brw_nir.h"
#include "elk/elk_nir_options.h"
#include "intel_nir.h" #include "intel_nir.h"
#include "intel_nir.h" #include "intel_nir.h"
@ -587,8 +588,8 @@ cleanup_llvm17_scratch(nir_shader *nir)
} }
nir_shader * nir_shader *
brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size, brw_nir_from_spirv(void *mem_ctx, unsigned gfx_version, const uint32_t *spirv,
bool llvm17_wa) size_t spirv_size, bool llvm17_wa)
{ {
struct spirv_to_nir_options spirv_options = { struct spirv_to_nir_options spirv_options = {
.environment = NIR_SPIRV_OPENCL, .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(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 = nir_shader *nir =
spirv_to_nir(spirv, spirv_size / 4, NULL, 0, MESA_SHADER_KERNEL, 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_shader(nir, "after spirv_to_nir");
nir_validate_ssa_dominance(nir, "after spirv_to_nir"); nir_validate_ssa_dominance(nir, "after spirv_to_nir");
ralloc_steal(mem_ctx, nir); ralloc_steal(mem_ctx, nir);

View file

@ -68,8 +68,8 @@ brw_kernel_from_spirv(struct brw_compiler *compiler,
char **error_str); char **error_str);
nir_shader * nir_shader *
brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size, brw_nir_from_spirv(void *mem_ctx, unsigned gfx_version,
bool llvm17_wa); const uint32_t *spirv, size_t spirv_size, bool llvm17_wa);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View file

@ -285,6 +285,7 @@ print_usage(char *exec_name, FILE *f)
" -i, --in <filename> Specify one input filename. Accepted multiple times.\n" " -i, --in <filename> Specify one input filename. Accepted multiple times.\n"
" -s, --spv <filename> Specify the output filename for spirv.\n" " -s, --spv <filename> Specify the output filename for spirv.\n"
" -n, --nir Specify whether to output serialized NIR instead of ISA.\n" " -n, --nir Specify whether to output serialized NIR instead of ISA.\n"
" -g, --gfx-version <ver> Specify the Gfx version used for NIR output.\n"
" -t, --text <filename> Specify the output filename for the parsed text\n" " -t, --text <filename> Specify the output filename for the parsed text\n"
" -v, --verbose Print more information during compilation.\n" " -v, --verbose Print more information during compilation.\n"
" -M, --llvm-version Print LLVM version.\n" " -M, --llvm-version Print LLVM version.\n"
@ -301,6 +302,8 @@ struct intel_clc_params {
char *txt_outfile; char *txt_outfile;
char *prefix; char *prefix;
unsigned gfx_version;
bool output_nir; bool output_nir;
bool print_info; bool print_info;
bool llvm17_wa; 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_library_to_nir_builder(fp, binary->data, binary->size / 4,
&spirv_options); &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, binary->data, binary->size,
params->llvm17_wa); params->llvm17_wa);
if (!nir) { if (!nir) {
@ -460,6 +463,7 @@ int main(int argc, char **argv)
{"out", required_argument, 0, 'o'}, {"out", required_argument, 0, 'o'},
{"spv", required_argument, 0, 's'}, {"spv", required_argument, 0, 's'},
{"text", required_argument, 0, 't'}, {"text", required_argument, 0, 't'},
{"gfx-version", required_argument, 0, 'g'},
{"nir", no_argument, 0, 'n'}, {"nir", no_argument, 0, 'n'},
{"llvm17-wa", no_argument, 0, 'L'}, {"llvm17-wa", no_argument, 0, 'L'},
{"llvm-version", no_argument, 0, 'M'}, {"llvm-version", no_argument, 0, 'M'},
@ -482,7 +486,7 @@ int main(int argc, char **argv)
util_dynarray_init(&input_files, params.mem_ctx); util_dynarray_init(&input_files, params.mem_ctx);
int ch; 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) switch (ch)
{ {
@ -519,6 +523,9 @@ int main(int argc, char **argv)
case 'M': case 'M':
print_llvm_version(stdout); print_llvm_version(stdout);
return EXIT_SUCCESS; return EXIT_SUCCESS;
case 'g':
params.gfx_version = strtoul(optarg, NULL, 10);
break;
case OPT_PREFIX: case OPT_PREFIX:
params.prefix = optarg; params.prefix = optarg;
break; break;
@ -610,6 +617,12 @@ int main(int argc, char **argv)
glsl_type_singleton_init_or_ref(); glsl_type_singleton_init_or_ref();
if (params.output_nir) { 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(&params, &spirv_obj); exit_code = output_nir(&params, &spirv_obj);
} else { } else {
if (params.platform == NULL) { if (params.platform == NULL) {
@ -634,6 +647,12 @@ int main(int argc, char **argv)
goto fail; 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) { if (params.entry_point == NULL) {
fprintf(stderr, "No entry-point name specified.\n"); fprintf(stderr, "No entry-point name specified.\n");
print_usage(argv[0], stderr); print_usage(argv[0], stderr);

View file

@ -190,7 +190,14 @@ if get_option('intel-clc') == 'system'
elif with_intel_clc elif with_intel_clc
prog_intel_clc = executable( prog_intel_clc = executable(
'intel_clc', '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 : [ link_with : [
libintel_compiler_brw, libintel_common,libisl, libintel_compiler_brw, libintel_common,libisl,
], ],

View file

@ -55,6 +55,7 @@ foreach gen : intel_shaders_gens
output : 'intel_gfx@0@_shaders_code.h'.format(gen[1]), output : 'intel_gfx@0@_shaders_code.h'.format(gen[1]),
command : [ command : [
prog_intel_clc, intel_shaders_clc_wa_args, '--nir', prog_intel_clc, intel_shaders_clc_wa_args, '--nir',
'--gfx-version=@0@'.format(gen[0] / 10),
'--prefix', 'gfx@0@_intel_shaders'.format(gen[1]), '--prefix', 'gfx@0@_intel_shaders'.format(gen[1]),
prepended_input_args, '-o', '@OUTPUT@', '--', prepended_input_args, '-o', '@OUTPUT@', '--',
'-cl-std=cl2.0', '-D__OPENCL_VERSION__=200', '-cl-std=cl2.0', '-D__OPENCL_VERSION__=200',