vkd3d-compiler is hardly the only program to print usage instructions on all invalid invocations, but it's rather annoying to have one's whole screen wiped due to a typo. It also makes it hard to notice the actual error messages printed on e.g. `vkd3d-compiler -x`.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index 4d7d628ca..4e56e8fa5 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -209,6 +209,7 @@ struct options enum vkd3d_shader_source_type source_type; enum vkd3d_shader_target_type target_type; bool preprocess_only; + bool print_help; bool print_version; bool print_source_types; bool print_target_types; @@ -446,6 +447,11 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->preprocess_only = true; break;
+ case 'h': + case OPTION_HELP: + options->print_help = true; + return true; + case OPTION_OUTPUT: case 'o': options->output_filename = optarg; @@ -623,9 +629,12 @@ int main(int argc, char **argv) int ret;
if (!parse_command_line(argc, argv, &options)) + return 1; + + if (options.print_help) { print_usage(argv[0]); - return 1; + return 0; }
if (options.print_version)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index 4e56e8fa5..5607c29d9 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -502,23 +502,6 @@ static bool parse_command_line(int argc, char **argv, struct options *options) if (options->target_type == VKD3D_SHADER_TARGET_NONE && !options->preprocess_only) options->target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
- if (options->print_target_types) - return true; - - if (!options->preprocess_only && !validate_target_type(options->source_type, options->target_type)) - { - fprintf(stderr, "Target type '%s' is invalid for source type '%s'.\n", - get_target_type_info(options->target_type)->name, - get_source_type_info(options->source_type)->name); - return false; - } - - if (!options->preprocess_only && options->source_type == VKD3D_SHADER_SOURCE_HLSL && !options->profile) - { - fprintf(stderr, "You need to specify a profile when compiling from HLSL source.\n"); - return false; - } - if (optind < argc) options->filename = argv[argc - 1];
@@ -657,6 +640,20 @@ int main(int argc, char **argv) return 0; }
+ if (!options.preprocess_only && !validate_target_type(options.source_type, options.target_type)) + { + fprintf(stderr, "Target type '%s' is invalid for source type '%s'.\n", + get_target_type_info(options.target_type)->name, + get_source_type_info(options.source_type)->name); + return 0; + } + + if (!options.preprocess_only && options.source_type == VKD3D_SHADER_SOURCE_HLSL && !options.profile) + { + fprintf(stderr, "You need to specify a profile when compiling from HLSL source.\n"); + return 0; + } + if (!(input = open_input(options.filename, &close_input))) goto done;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=104473
Your paranoid android.
=== debian11 (build log) ===
Task: Patch failed to apply
=== debian11 (build log) ===
Task: Patch failed to apply
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 68 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 14 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index 5607c29d9..55f82c114 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -20,6 +20,7 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif +#include <assert.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -49,6 +50,11 @@ enum OPTION_TEXT_FORMATTING, };
+#define MAKE_TAG(ch0, ch1, ch2, ch3) \ + ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ + ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 )) +#define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C') + static const struct source_type_info { enum vkd3d_shader_source_type type; @@ -497,11 +503,6 @@ static bool parse_command_line(int argc, char **argv, struct options *options) } }
- if (options->source_type == VKD3D_SHADER_SOURCE_NONE) - options->source_type = options->preprocess_only ? VKD3D_SHADER_SOURCE_HLSL : VKD3D_SHADER_SOURCE_DXBC_TPF; - if (options->target_type == VKD3D_SHADER_TARGET_NONE && !options->preprocess_only) - options->target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; - if (optind < argc) options->filename = argv[argc - 1];
@@ -640,6 +641,54 @@ int main(int argc, char **argv) return 0; }
+ if (!(input = open_input(options.filename, &close_input))) + goto done; + + if (!read_shader(&info.source, input)) + { + fprintf(stderr, "Failed to read input shader.\n"); + goto done; + } + + if (options.source_type == VKD3D_SHADER_SOURCE_NONE) + { + uint32_t token; + + if (options.preprocess_only) + { + options.source_type = VKD3D_SHADER_SOURCE_HLSL; + } + else if (info.source.size >= sizeof(token)) + { + memcpy(&token, info.source.code, info.source.size); + if (token == TAG_DXBC) + options.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; + else if ((token & 0xfffe0000) == 0xfffe0000) + options.source_type = VKD3D_SHADER_SOURCE_D3D_BYTECODE; + else + options.source_type = VKD3D_SHADER_SOURCE_HLSL; + } + } + + if (options.target_type == VKD3D_SHADER_TARGET_NONE && !options.preprocess_only) + { + switch (options.source_type) + { + case VKD3D_SHADER_SOURCE_D3D_BYTECODE: + case VKD3D_SHADER_SOURCE_DXBC_TPF: + options.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; + break; + + case VKD3D_SHADER_SOURCE_HLSL: + options.target_type = VKD3D_SHADER_TARGET_DXBC_TPF; + break; + + default: + assert(0); + break; + } + } + if (!options.preprocess_only && !validate_target_type(options.source_type, options.target_type)) { fprintf(stderr, "Target type '%s' is invalid for source type '%s'.\n", @@ -654,9 +703,6 @@ int main(int argc, char **argv) return 0; }
- if (!(input = open_input(options.filename, &close_input))) - goto done; - if (!options.filename && get_source_type_info(options.source_type)->is_binary && isatty(fileno(input))) { fprintf(stderr, "Input is a tty and input format is binary, exiting.\n" @@ -706,12 +752,6 @@ int main(int argc, char **argv) spirv_target_info.entry_point = options.entry_point; spirv_target_info.environment = VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0;
- if (!read_shader(&info.source, input)) - { - fprintf(stderr, "Failed to read input shader.\n"); - goto done; - } - if (options.preprocess_only) ret = vkd3d_shader_preprocess(&info, &output_code, &messages); else
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=104474
Your paranoid android.
=== debian11 (build log) ===
Task: Patch failed to apply
=== debian11 (build log) ===
Task: Patch failed to apply
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=104472
Your paranoid android.
=== debian11 (build log) ===
Task: Patch failed to apply
=== debian11 (build log) ===
Task: Patch failed to apply