From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- programs/vkd3d-compiler/main.c | 111 +++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 40 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index b94272a5..23a5357e 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -35,13 +35,14 @@ #include <term.h> #endif
-#define MAX_COMPILE_OPTIONS 4 +#define MAX_COMPILE_OPTIONS 5
enum { OPTION_HELP = CHAR_MAX + 1, OPTION_BUFFER_UAV, OPTION_ENTRY, + OPTION_MATRIX_STORAGE_ORDER, OPTION_OUTPUT, OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, @@ -177,34 +178,36 @@ 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" - " -b <type> Specify the target type. Use --print-target-types to\n" - " list the valid and default target types for a given\n" - " source type.\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" - " -e, --entry=<name> Use <name> as the entry point (default is "main").\n" - " -E Preprocess the source code instead of compiling it.\n" - " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" - " output file is specified, output will be written to\n" - " standard output.\n" - " --formatting=<flags> Specify the formatting options for text output.\n" - " <flags> is a comma separated list of formatting flags,\n" - " optionally prefixed by '+' or '-'. Valid flags are\n" - " 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n" - " The 'indent' and 'header' flags are enabled by default.\n" - " --print-source-types Display the supported source types and exit.\n" - " --print-target-types Display the supported target types for the specified\n" - " source type and exit.\n" - " -p, --profile=<name> Specify the target shader profile for HLSL shaders.\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. Use --print-source-types\n" - " to list valid source types. The default source type is\n" - " automatically detected from the input shader.\n" - " -- Stop option processing. Any subsequent argument is\n" - " interpreted as a filename.\n" + " -h, --help Display this information and exit.\n" + " -b <type> Specify the target type. Use --print-target-types to\n" + " list the valid and default target types for a given\n" + " source type.\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" + " --matrix-storage-order=<order> Specify default matrix storage order. Valid values are\n" + " 'column' (default) and 'row'.\n" + " -e, --entry=<name> Use <name> as the entry point (default is "main").\n" + " -E Preprocess the source code instead of compiling it.\n" + " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" + " output file is specified, output will be written to\n" + " standard output.\n" + " --formatting=<flags> Specify the formatting options for text output.\n" + " <flags> is a comma separated list of formatting flags,\n" + " optionally prefixed by '+' or '-'. Valid flags are\n" + " 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n" + " The 'indent' and 'header' flags are enabled by default.\n" + " --print-source-types Display the supported source types and exit.\n" + " --print-target-types Display the supported target types for the specified\n" + " source type and exit.\n" + " -p, --profile=<name> Specify the target shader profile for HLSL shaders.\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. Use --print-source-types\n" + " to list valid source types. The default source type is\n" + " automatically detected from the input shader.\n" + " -- Stop option processing. Any subsequent argument is\n" + " interpreted as a filename.\n" "\n" "If the input file is '-' or not specified, input will be read from standard\n" "input.\n"; @@ -332,6 +335,23 @@ static bool parse_formatting(uint32_t *formatting, bool *colour, char *arg) return true; }
+static bool parse_matrix_storage_order(enum vkd3d_shader_compile_option_pack_matrix_order *order, const char *arg) +{ + if (!strcmp(arg, "column")) + { + *order = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR; + return true; + } + + if (!strcmp(arg, "row")) + { + *order = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR; + return true; + } + + return false; +} + static enum vkd3d_shader_source_type parse_source_type(const char *source) { unsigned int i; @@ -418,22 +438,24 @@ static bool validate_target_type(
static bool parse_command_line(int argc, char **argv, struct options *options) { + enum vkd3d_shader_compile_option_pack_matrix_order pack_matrix_order; enum vkd3d_shader_compile_option_buffer_uav buffer_uav; int option;
static struct option long_options[] = { - {"help", no_argument, NULL, OPTION_HELP}, - {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, - {"entry", required_argument, NULL, OPTION_ENTRY}, - {"output", required_argument, NULL, OPTION_OUTPUT}, - {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, - {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, - {"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES}, - {"profile", required_argument, NULL, OPTION_PROFILE}, - {"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}, + {"entry", required_argument, NULL, OPTION_ENTRY}, + {"matrix-storage-order", required_argument, NULL, OPTION_MATRIX_STORAGE_ORDER}, + {"output", required_argument, NULL, OPTION_OUTPUT}, + {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, + {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, + {"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES}, + {"profile", required_argument, NULL, OPTION_PROFILE}, + {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, + {"version", no_argument, NULL, OPTION_VERSION}, + {NULL, 0, NULL, 0}, };
memset(options, 0, sizeof(*options)); @@ -485,6 +507,15 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->output_filename = optarg; break;
+ case OPTION_MATRIX_STORAGE_ORDER: + if (!parse_matrix_storage_order(&pack_matrix_order, optarg)) + { + fprintf(stderr, "Invalid matrix storage order '%s' specified.\n", optarg); + return false; + } + add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER, pack_matrix_order); + break; + case OPTION_PROFILE: case 'p': options->profile = optarg;