[PATCH vkd3d 1/5] vkd3d-compiler: Add an option to list the supported source types.
Henri Verbeet
hverbeet at codeweavers.com
Tue Aug 11 06:06:36 CDT 2020
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
programs/vkd3d-compiler/main.c | 91 +++++++++++++++++++++++++++++++++---------
1 file changed, 73 insertions(+), 18 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c
index e2f9ae5..4a889f0 100644
--- a/programs/vkd3d-compiler/main.c
+++ b/programs/vkd3d-compiler/main.c
@@ -34,10 +34,24 @@ enum
OPTION_HELP = CHAR_MAX + 1,
OPTION_BUFFER_UAV,
OPTION_OUTPUT,
+ OPTION_PRINT_SOURCE_TYPES,
OPTION_STRIP_DEBUG,
OPTION_VERSION,
};
+static const struct
+{
+ enum vkd3d_shader_source_type type;
+ const char *name;
+ const char *description;
+}
+source_type_info[] =
+{
+ {VKD3D_SHADER_SOURCE_DXBC_TPF,
+ "dxbc-tpf", "A 'Tokenized Program Format' shader embedded in a DXBC container.\n"
+ " This is the format used for Direct3D shader model 4 and 5 shaders."},
+};
+
static bool read_shader(struct vkd3d_shader_code *shader, const char *filename)
{
struct stat st;
@@ -101,17 +115,18 @@ static void print_usage(const char *program_name)
static const char usage[] =
"[options...] file\n"
"Options:\n"
- " -h, --help Display this information and exit.\n"
- " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n"
- " Valid values are 'buffer-texture' (default) and\n"
- " 'storage-buffer'.\n"
- " -o, --output=<file> Write the output to <file>.\n"
- " --strip-debug Strip debug information from the output.\n"
- " -V, --version Display version information and exit.\n"
- " -x <type> Specify the type of the source. Valid values are\n"
- " 'dxbc-tpf' and 'none'.\n"
- " -- Stop option processing. Any subsequent argument is\n"
- " interpreted as a filename.\n";
+ " -h, --help Display this information and exit.\n"
+ " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n"
+ " Valid values are 'buffer-texture' (default) and\n"
+ " 'storage-buffer'.\n"
+ " -o, --output=<file> Write the output to <file>.\n"
+ " --print-source-types Display the supported source types and exit.\n"
+ " --strip-debug Strip debug information from the output.\n"
+ " -V, --version Display version information and exit.\n"
+ " -x <type> Specify the type of the source. Valid values are\n"
+ " 'dxbc-tpf' and 'none'.\n"
+ " -- Stop option processing. Any subsequent argument is\n"
+ " interpreted as a filename.\n";
fprintf(stderr, "Usage: %s %s", program_name, usage);
}
@@ -122,6 +137,7 @@ struct options
const char *output_filename;
enum vkd3d_shader_source_type source_type;
bool print_version;
+ bool print_source_types;
struct vkd3d_shader_compile_option compile_options[MAX_COMPILE_OPTIONS];
unsigned int compile_option_count;
@@ -174,9 +190,17 @@ static bool parse_buffer_uav(enum vkd3d_shader_compile_option_buffer_uav *buffer
static enum vkd3d_shader_source_type parse_source_type(const char *source)
{
- if (!strcmp(source, "dxbc-tpf") || !strcmp(source, "none"))
+ unsigned int i;
+
+ if (!strcmp(source, "none"))
return VKD3D_SHADER_SOURCE_DXBC_TPF;
+ for (i = 0; i < ARRAY_SIZE(source_type_info); ++i)
+ {
+ if (!strcmp(source, source_type_info[i].name))
+ return source_type_info[i].type;
+ }
+
return VKD3D_SHADER_SOURCE_NONE;
}
@@ -187,12 +211,13 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
static struct option long_options[] =
{
- {"help", no_argument, NULL, OPTION_HELP},
- {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV},
- {"output", required_argument, NULL, OPTION_OUTPUT},
- {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG},
- {"version", no_argument, NULL, OPTION_VERSION},
- {NULL, 0, NULL, 0},
+ {"help", no_argument, NULL, OPTION_HELP},
+ {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV},
+ {"output", required_argument, NULL, OPTION_OUTPUT},
+ {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES},
+ {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG},
+ {"version", no_argument, NULL, OPTION_VERSION},
+ {NULL, 0, NULL, 0},
};
memset(options, 0, sizeof(*options));
@@ -219,6 +244,10 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
options->output_filename = optarg;
break;
+ case OPTION_PRINT_SOURCE_TYPES:
+ options->print_source_types = true;
+ return true;
+
case OPTION_STRIP_DEBUG:
add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG, 1);
break;
@@ -249,6 +278,26 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
return true;
}
+static void print_source_types(void)
+{
+ const enum vkd3d_shader_source_type *source_types;
+ unsigned int count, i, j;
+
+ source_types = vkd3d_shader_get_supported_source_types(&count);
+ fputs("Supported source types:\n", stdout);
+ for (i = 0; i < count; ++i)
+ {
+ for (j = 0; j < ARRAY_SIZE(source_type_info); ++j)
+ {
+ if (source_types[i] == source_type_info[j].type)
+ {
+ fprintf(stdout, " %s %s\n", source_type_info[j].name, source_type_info[j].description);
+ break;
+ }
+ }
+ }
+}
+
int main(int argc, char **argv)
{
struct vkd3d_shader_compile_info info;
@@ -271,6 +320,12 @@ int main(int argc, char **argv)
return 0;
}
+ if (options.print_source_types)
+ {
+ print_source_types();
+ return 0;
+ }
+
info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
info.next = NULL;
info.source_type = options.source_type;
--
2.11.0
More information about the wine-devel
mailing list