diff options
author | Elie Tournier <[email protected]> | 2020-02-03 13:44:59 +0000 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-02-14 11:14:58 +0000 |
commit | efda2cfcf96b1071c18800ff3f878fe627359e8a (patch) | |
tree | c519f97660eac05e9508c6b3b9d6f83791151a66 /src/compiler | |
parent | eeb6d6112859c3ba41f1c8914d503bf1a3dd981d (diff) |
spirv2nir: Add kernel spirv support
Signed-off-by: Elie Tournier <[email protected]>
Reviewed-by: Erik Faye-Lund <[email protected]>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3678>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3678>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/spirv/spirv2nir.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/compiler/spirv/spirv2nir.c b/src/compiler/spirv/spirv2nir.c index 62bef2e4897..6bc946e9b5d 100644 --- a/src/compiler/spirv/spirv2nir.c +++ b/src/compiler/spirv/spirv2nir.c @@ -40,11 +40,65 @@ #include <stdio.h> #include <errno.h> #include <string.h> +#include <getopt.h> #define WORD_SIZE 4 +static gl_shader_stage +stage_to_enum(char *stage) +{ + if (!strcmp(stage, "vertex")) + return MESA_SHADER_VERTEX; + else if (!strcmp(stage, "tess-ctrl")) + return MESA_SHADER_TESS_CTRL; + else if (!strcmp(stage, "tess-eval")) + return MESA_SHADER_TESS_EVAL; + else if (!strcmp(stage, "geometry")) + return MESA_SHADER_GEOMETRY; + else if (!strcmp(stage, "fragment")) + return MESA_SHADER_FRAGMENT; + else if (!strcmp(stage, "compute")) + return MESA_SHADER_COMPUTE; + else if (!strcmp(stage, "kernel")) + return MESA_SHADER_KERNEL; + else + return MESA_SHADER_NONE; +} + int main(int argc, char **argv) { + gl_shader_stage shader_stage = MESA_SHADER_FRAGMENT; + char *entry_point = "main"; + int ch; + + static struct option long_options[] = + { + {"stage", required_argument, 0, 's'}, + {"entry", required_argument, 0, 'e'}, + {0, 0, 0, 0} + }; + + while ((ch = getopt_long(argc - 1, argv + 1, "s:e:", long_options, NULL)) != -1) + { + switch (ch) + { + case 's': + shader_stage = stage_to_enum(optarg); + if (shader_stage == MESA_SHADER_NONE) + { + fprintf(stderr, "Unknown stage %s\n", optarg); + return 1; + } + break; + case 'e': + entry_point = optarg; + break; + default: + fprintf(stderr, "Unrecognized option.\n"); + return 1; + } + } + int fd = open(argv[1], O_RDONLY); if (fd < 0) { @@ -75,9 +129,19 @@ int main(int argc, char **argv) glsl_type_singleton_init_or_ref(); struct spirv_to_nir_options spirv_opts = {0}; + if (shader_stage == MESA_SHADER_KERNEL) { + spirv_opts.environment = NIR_SPIRV_OPENCL; + spirv_opts.caps.address = true; + spirv_opts.caps.float64 = true; + spirv_opts.caps.int8 = true; + spirv_opts.caps.int16 = true; + spirv_opts.caps.int64 = true; + spirv_opts.caps.kernel = true; + spirv_opts.constant_as_global = true; + } nir_shader *nir = spirv_to_nir(map, word_count, NULL, 0, - MESA_SHADER_FRAGMENT, "main", + shader_stage, entry_point, &spirv_opts, NULL); if (nir) |