vkd3d-compiler: Introduce an option to specify the origin of fragment coordinates.

This commit is contained in:
Henri Verbeet 2023-11-05 00:12:00 +01:00 committed by Alexandre Julliard
parent e7eec3e023
commit 557b32a504
Notes: Alexandre Julliard 2023-11-10 00:08:58 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/457

View File

@ -40,6 +40,7 @@ enum
OPTION_HELP = CHAR_MAX + 1, OPTION_HELP = CHAR_MAX + 1,
OPTION_BUFFER_UAV, OPTION_BUFFER_UAV,
OPTION_ENTRY, OPTION_ENTRY,
OPTION_FRAGMENT_COORDINATE_ORIGIN,
OPTION_MATRIX_STORAGE_ORDER, OPTION_MATRIX_STORAGE_ORDER,
OPTION_OUTPUT, OPTION_OUTPUT,
OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_SOURCE_TYPES,
@ -189,6 +190,11 @@ static void print_usage(const char *program_name)
" optionally prefixed by '+' or '-'. Valid flags are\n" " optionally prefixed by '+' or '-'. Valid flags are\n"
" 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n" " 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n"
" The 'indent' and 'header' flags are enabled by default.\n" " The 'indent' and 'header' flags are enabled by default.\n"
" --fragment-coordinate-origin=<origin>\n"
" Specify the origin of fragment coordinates for SPIR-V\n"
" targets. Valid values are 'upper-left' (default) and\n"
" 'lower-left'. The only value supported by Vulkan\n"
" environments is 'upper-left'.\n"
" --matrix-storage-order=<order>\n" " --matrix-storage-order=<order>\n"
" Specify the default matrix storage order. Valid values\n" " Specify the default matrix storage order. Valid values\n"
" are 'column' (default) and 'row'.\n" " are 'column' (default) and 'row'.\n"
@ -337,6 +343,24 @@ static bool parse_formatting(uint32_t *formatting, bool *colour, char *arg)
return true; return true;
} }
static bool parse_fragment_coordinate_origin(enum vkd3d_shader_compile_option_fragment_coordinate_origin *origin,
const char *arg)
{
if (!strcmp(arg, "upper-left"))
{
*origin = VKD3D_SHADER_COMPILE_OPTION_FRAGMENT_COORDINATE_ORIGIN_UPPER_LEFT;
return true;
}
if (!strcmp(arg, "lower-left"))
{
*origin = VKD3D_SHADER_COMPILE_OPTION_FRAGMENT_COORDINATE_ORIGIN_LOWER_LEFT;
return true;
}
return false;
}
static bool parse_matrix_storage_order(enum vkd3d_shader_compile_option_pack_matrix_order *order, const char *arg) static bool parse_matrix_storage_order(enum vkd3d_shader_compile_option_pack_matrix_order *order, const char *arg)
{ {
if (!strcmp(arg, "column")) if (!strcmp(arg, "column"))
@ -441,25 +465,27 @@ static bool validate_target_type(
static bool parse_command_line(int argc, char **argv, struct options *options) 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_pack_matrix_order pack_matrix_order;
enum vkd3d_shader_compile_option_fragment_coordinate_origin origin;
enum vkd3d_shader_compile_option_buffer_uav buffer_uav; enum vkd3d_shader_compile_option_buffer_uav buffer_uav;
unsigned int compat_options = 0; unsigned int compat_options = 0;
int option; int option;
static struct option long_options[] = static struct option long_options[] =
{ {
{"help", no_argument, NULL, OPTION_HELP}, {"help", no_argument, NULL, OPTION_HELP},
{"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV},
{"entry", required_argument, NULL, OPTION_ENTRY}, {"entry", required_argument, NULL, OPTION_ENTRY},
{"matrix-storage-order", required_argument, NULL, OPTION_MATRIX_STORAGE_ORDER}, {"fragment-coordinate-origin", required_argument, NULL, OPTION_FRAGMENT_COORDINATE_ORIGIN},
{"output", required_argument, NULL, OPTION_OUTPUT}, {"matrix-storage-order", required_argument, NULL, OPTION_MATRIX_STORAGE_ORDER},
{"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, {"output", required_argument, NULL, OPTION_OUTPUT},
{"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING},
{"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES}, {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES},
{"profile", required_argument, NULL, OPTION_PROFILE}, {"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES},
{"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, {"profile", required_argument, NULL, OPTION_PROFILE},
{"version", no_argument, NULL, OPTION_VERSION}, {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG},
{"semantic-compat-map", no_argument, NULL, OPTION_SEMANTIC_COMPAT_MAP}, {"version", no_argument, NULL, OPTION_VERSION},
{NULL, 0, NULL, 0}, {"semantic-compat-map", no_argument, NULL, OPTION_SEMANTIC_COMPAT_MAP},
{NULL, 0, NULL, 0},
}; };
memset(options, 0, sizeof(*options)); memset(options, 0, sizeof(*options));
@ -501,6 +527,15 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
options->preprocess_only = true; options->preprocess_only = true;
break; break;
case OPTION_FRAGMENT_COORDINATE_ORIGIN:
if (!parse_fragment_coordinate_origin(&origin, optarg))
{
fprintf(stderr, "Invalid fragment coordinate origin '%s' specified.\n", optarg);
return false;
}
add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_FRAGMENT_COORDINATE_ORIGIN, origin);
break;
case 'h': case 'h':
case OPTION_HELP: case OPTION_HELP:
options->print_help = true; options->print_help = true;