diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index f112e7c7..94f79c7c 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -154,6 +154,25 @@ enum vkd3d_shader_compile_option_pack_matrix_order VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER), }; +/** Individual options to enable various backward compatibility features. \since 1.10 */ +enum vkd3d_shader_compile_option_backward_compatibility +{ + /** + * Causes compiler to convert SM1-3 semantics to corresponding System Value semantics, + * when compiling HLSL sources for SM4+ targets. + * + * This option does the following conversions: + * + * - POSITION to SV_Position for vertex shader outputs, pixel shader inputs, + * and geometry shader inputs and outputs; + * - COLORN to SV_TargetN for pixel shader outputs; + * - DEPTH to SV_Depth for pixel shader outputs. + */ + VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES = 0x00000001, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY), +}; + enum vkd3d_shader_compile_option_name { /** @@ -193,6 +212,14 @@ enum vkd3d_shader_compile_option_name * \since 1.9 */ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER = 0x00000007, + /** + * This option is used to enable various backward compatibility features. + * + * \a value is a mask of values from enum vkd3d_shader_compile_option_backward_compatibility. + * + * \since 1.10 + */ + VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY = 0x00000008, VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_NAME), }; diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index b42e3088..2d383bc2 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3421,6 +3421,10 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compil else if (option->value == VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR) ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR; } + else if (option->name == VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY) + { + ctx->semantic_compat_mapping = option->value & VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES; + } } return true; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 9f1a3fe2..9e83b8b7 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -862,6 +862,8 @@ struct hlsl_ctx uint32_t in_state_block : 1; /* Whether the numthreads() attribute has been provided in the entry-point function. */ uint32_t found_numthreads : 1; + + bool semantic_compat_mapping; }; struct hlsl_resource_load_params diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index bf4c03c0..845b4423 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -2762,20 +2762,21 @@ bool hlsl_sm4_usage_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semant {"position", true, VKD3D_SHADER_TYPE_VERTEX, D3D_NAME_POSITION}, {"sv_position", true, VKD3D_SHADER_TYPE_VERTEX, D3D_NAME_POSITION}, }; + bool needs_compat_mapping = ascii_strncasecmp(semantic->name, "sv_", 3); for (i = 0; i < ARRAY_SIZE(semantics); ++i) { if (!ascii_strcasecmp(semantic->name, semantics[i].name) && output == semantics[i].output - && ctx->profile->type == semantics[i].shader_type - && !ascii_strncasecmp(semantic->name, "sv_", 3)) + && (ctx->semantic_compat_mapping == needs_compat_mapping || !needs_compat_mapping) + && ctx->profile->type == semantics[i].shader_type) { *usage = semantics[i].usage; return true; } } - if (!ascii_strncasecmp(semantic->name, "sv_", 3)) + if (!needs_compat_mapping) return false; *usage = D3D_NAME_UNDEFINED; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 45b1a0ce..ed0f637c 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -187,7 +187,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen { struct vkd3d_shader_preprocess_info preprocess_info; struct vkd3d_shader_hlsl_source_info hlsl_info; - struct vkd3d_shader_compile_option options[3]; + struct vkd3d_shader_compile_option options[4]; struct vkd3d_shader_compile_info compile_info; struct vkd3d_shader_compile_option *option; struct vkd3d_shader_code byte_code; @@ -302,6 +302,13 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR; } + if (flags & D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY) + { + option = &options[compile_info.option_count++]; + option->name = VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY; + option->value = VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES; + } + ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages); if (messages && messages_blob) diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index eea0c3ab..fbc81078 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -35,7 +35,7 @@ #include #endif -#define MAX_COMPILE_OPTIONS 5 +#define MAX_COMPILE_OPTIONS 6 enum { @@ -47,6 +47,7 @@ enum OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, OPTION_PROFILE, + OPTION_SEMANTIC_COMPAT_MAP, OPTION_STRIP_DEBUG, OPTION_VERSION, OPTION_TEXT_FORMATTING, @@ -186,6 +187,8 @@ static void print_usage(const char *program_name) " --matrix-storage-order=\n" " Specify default matrix storage order. Valid values are\n" " 'column' (default) and 'row'.\n" + " --semantic-compat-map Enable semantic mapping compatibility mode to use SM4+ system values\n" + " instead of SM1-3 style semantic names when compiling from HLSL sources.\n" " -e, --entry= Use as the entry point (default is \"main\").\n" " -E Preprocess the source code instead of compiling it.\n" " -o, --output= Write the output to . If is '-' or no\n" @@ -439,6 +442,7 @@ 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; + unsigned int compat_options = 0; int option; static struct option long_options[] = @@ -454,6 +458,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options) {"profile", required_argument, NULL, OPTION_PROFILE}, {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, {"version", no_argument, NULL, OPTION_VERSION}, + {"semantic-compat-map", no_argument, NULL, OPTION_SEMANTIC_COMPAT_MAP}, {NULL, 0, NULL, 0}, }; @@ -533,6 +538,10 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->print_target_types = true; break; + case OPTION_SEMANTIC_COMPAT_MAP: + compat_options |= VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES; + break; + case OPTION_STRIP_DEBUG: add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG, 1); break; @@ -555,6 +564,9 @@ static bool parse_command_line(int argc, char **argv, struct options *options) } } + if (compat_options) + add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY, compat_options); + if (optind < argc) options->filename = argv[argc - 1];