From f4cbe3f220735d65e50849c10a14234531e64a2e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 21 Jan 2025 12:14:06 +0900 Subject: [PATCH] [qfcc] Ensure compute shaders set all local_size elements The default value is 1, and the assumption in target_spirv is that if the first one is set, all are set, but the source code doesn't need to set any explicitly. --- tools/qfcc/include/glsl-lang.h | 1 + tools/qfcc/source/glsl-parse.y | 1 + tools/qfcc/source/glsl-sub_comp.c | 26 ++++++++++++++++++++++++++ tools/qfcc/source/qc-parse.y | 3 ++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/include/glsl-lang.h b/tools/qfcc/include/glsl-lang.h index 8f8b38142..7cbdbda02 100644 --- a/tools/qfcc/include/glsl-lang.h +++ b/tools/qfcc/include/glsl-lang.h @@ -42,6 +42,7 @@ typedef struct defspace_s defspace_t; typedef struct rua_ctx_s rua_ctx_t; void glsl_init_comp (rua_ctx_t *ctx); +int glsl_finish_comp (const char *file, rua_ctx_t *ctx); void glsl_init_vert (rua_ctx_t *ctx); void glsl_init_tesc (rua_ctx_t *ctx); void glsl_init_tese (rua_ctx_t *ctx); diff --git a/tools/qfcc/source/glsl-parse.y b/tools/qfcc/source/glsl-parse.y index 348fae2a7..762c6727a 100644 --- a/tools/qfcc/source/glsl-parse.y +++ b/tools/qfcc/source/glsl-parse.y @@ -1948,6 +1948,7 @@ language_t lang_glsl_comp = { .default_float = true, .init = glsl_init_comp, .parse = glsl_yyparse, + .finish = glsl_finish_comp, .extension = glsl_extension, .version = glsl_version, .on_include = glsl_on_include, diff --git a/tools/qfcc/source/glsl-sub_comp.c b/tools/qfcc/source/glsl-sub_comp.c index 881652f1c..5cfecaada 100644 --- a/tools/qfcc/source/glsl-sub_comp.c +++ b/tools/qfcc/source/glsl-sub_comp.c @@ -35,7 +35,9 @@ #include "tools/qfcc/include/def.h" #include "tools/qfcc/include/diagnostic.h" #include "tools/qfcc/include/glsl-lang.h" +#include "tools/qfcc/include/qfcc.h" #include "tools/qfcc/include/shared.h" +#include "tools/qfcc/include/spirv.h" #include "tools/qfcc/include/strpool.h" #include "tools/qfcc/include/symtab.h" #include "tools/qfcc/include/type.h" @@ -52,3 +54,27 @@ glsl_sublang_t glsl_comp_sublanguage = { .interface_default_names = glsl_comp_interface_default_names, .model_name = "GLCompute", }; + +int +glsl_finish_comp (const char *file, rua_ctx_t *ctx) +{ + if (!pr.module || !pr.module->entry_points) { + return 1; + } + const expr_t *size = nullptr; + for (int i = 0; i < 3; i++) { + if (!pr.module->entry_points->local_size[i]) { + size = new_int_expr (1, false); + break; + } + } + if (size) { + for (int i = 0; i < 3; i++) { + if (!pr.module->entry_points->local_size[i]) { + pr.module->entry_points->local_size[i] = size; + break; + } + } + } + return 1; +} diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 6590753e7..12a57264d 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -3261,7 +3261,8 @@ qc_parse_string (const char *str, rua_ctx_t *ctx) return ret; } -static int qc_finish (const char *file, rua_ctx_t *ctx) +static int +qc_finish (const char *file, rua_ctx_t *ctx) { if (options.frames_files) { write_frame_macros (va (0, "%s.frame", file_basename (file, 0)));