From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- include/vkd3d_shader.h | 12 ++++ libs/vkd3d-shader/hlsl.c | 19 ++++++ libs/vkd3d-shader/vkd3d_shader_main.c | 3 + libs/vkd3d-utils/vkd3d_utils_main.c | 84 +++++++++++++++++---------- programs/vkd3d-compiler/main.c | 9 +++ 5 files changed, 97 insertions(+), 30 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 94f79c7c7..7e4c46b50 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -734,6 +734,18 @@ enum vkd3d_shader_target_type * An 'OpenGL Shading Language' shader. \since 1.3 */ VKD3D_SHADER_TARGET_GLSL, + /** + * Binary format used by Direct3D 9 effects. \since 1.10 + */ + VKD3D_SHADER_TARGET_D3D_FX, + /** + * Binary format used by Direct3D 10.x effects. \since 1.10 + */ + VKD3D_SHADER_TARGET_DXBC_FX, + /** + * Binary format used by Direct3D 11.x effects. \since 1.10 + */ + VKD3D_SHADER_TARGET_FX,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE), }; diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1d3fd0f7d..14088a188 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3645,6 +3645,25 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d "The '%s' target profile is incompatible with the 'dxbc-tpf' target type.", profile->name); return VKD3D_ERROR_INVALID_ARGUMENT; } + else if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_FX && strcmp(profile->name, "fx_2_0")) + { + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, + "The '%s' target profile is incompatible with the 'd3d-fx' target type.", profile->name); + return VKD3D_ERROR_INVALID_ARGUMENT; + } + else if (compile_info->target_type == VKD3D_SHADER_TARGET_DXBC_FX && !(profile->major_version == 4 + && profile->type == VKD3D_SHADER_TYPE_EFFECT)) + { + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, + "The '%s' target profile is incompatible with the 'dxbc-fx' target type.", profile->name); + return VKD3D_ERROR_INVALID_ARGUMENT; + } + else if (compile_info->target_type == VKD3D_SHADER_TARGET_FX && strcmp(profile->name, "fx_5_0")) + { + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, + "The '%s' target profile is incompatible with the 'fx' target type.", profile->name); + return VKD3D_ERROR_INVALID_ARGUMENT; + }
if (!hlsl_ctx_init(&ctx, compile_info, profile, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY; diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 28d647b3d..780733b31 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1724,6 +1724,9 @@ const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types( { VKD3D_SHADER_TARGET_D3D_BYTECODE, VKD3D_SHADER_TARGET_DXBC_TPF, + VKD3D_SHADER_TARGET_D3D_FX, + VKD3D_SHADER_TARGET_DXBC_FX, + VKD3D_SHADER_TARGET_FX, };
static const enum vkd3d_shader_target_type d3dbc_types[] = diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 306674cd1..27ac0c663 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -179,28 +179,12 @@ static void close_include(const struct vkd3d_shader_code *code, void *context) ID3DInclude_Close(iface, code->code); }
-HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, - const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point, - const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags, - const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob, - ID3DBlob **messages_blob) +static enum vkd3d_shader_target_type get_target_for_profile(const char *profile) { - struct vkd3d_shader_preprocess_info preprocess_info; - struct vkd3d_shader_hlsl_source_info hlsl_info; - 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; - const D3D_SHADER_MACRO *macro; size_t profile_len, i; - char *messages; - HRESULT hr; - int ret;
static const char * const d3dbc_profiles[] = { - "fx_2_", - "ps.1.", "ps.2.", "ps.3.", @@ -220,6 +204,58 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen "tx_1_", };
+ static const struct fx_profile + { + const char *name; + enum vkd3d_shader_target_type target; + } + fx_profiles[] = + { + { "fx_2_0", VKD3D_SHADER_TARGET_D3D_FX }, + { "fx_4_0", VKD3D_SHADER_TARGET_DXBC_FX }, + { "fx_4_1", VKD3D_SHADER_TARGET_DXBC_FX }, + { "fx_5_0", VKD3D_SHADER_TARGET_FX }, + }; + + profile_len = strlen(profile); + for (i = 0; i < ARRAY_SIZE(d3dbc_profiles); ++i) + { + size_t len = strlen(d3dbc_profiles[i]); + + if (len <= profile_len && !memcmp(profile, d3dbc_profiles[i], len)) + { + return VKD3D_SHADER_TARGET_D3D_BYTECODE; + } + } + + for (i = 0; i < ARRAY_SIZE(fx_profiles); ++i) + { + if (!strcmp(profile, fx_profiles[i].name)) + { + return fx_profiles[i].target; + } + } + + return VKD3D_SHADER_TARGET_DXBC_TPF; +} + +HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point, + const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags, + const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob, + ID3DBlob **messages_blob) +{ + struct vkd3d_shader_preprocess_info preprocess_info; + struct vkd3d_shader_hlsl_source_info hlsl_info; + 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; + const D3D_SHADER_MACRO *macro; + char *messages; + HRESULT hr; + int ret; + TRACE("data %p, data_size %lu, filename %s, macros %p, include %p, entry_point %s, " "profile %s, flags %#x, effect_flags %#x, secondary_flags %#x, secondary_data %p, " "secondary_data_size %lu, shader_blob %p, messages_blob %p.\n", @@ -246,24 +282,12 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen compile_info.source.code = data; compile_info.source.size = data_size; compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL; - compile_info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF; + compile_info.target_type = get_target_for_profile(profile); compile_info.options = options; compile_info.option_count = 1; compile_info.log_level = VKD3D_SHADER_LOG_INFO; compile_info.source_name = filename;
- profile_len = strlen(profile); - for (i = 0; i < ARRAY_SIZE(d3dbc_profiles); ++i) - { - size_t len = strlen(d3dbc_profiles[i]); - - if (len <= profile_len && !memcmp(profile, d3dbc_profiles[i], len)) - { - compile_info.target_type = VKD3D_SHADER_TARGET_D3D_BYTECODE; - break; - } - } - preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO; preprocess_info.next = &hlsl_info; preprocess_info.macros = (const struct vkd3d_shader_macro *)macros; diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index 2e5f2b977..4d66467b2 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -105,6 +105,15 @@ target_type_info[] = "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.\n", true}, + {VKD3D_SHADER_TARGET_D3D_FX, + "d3d-fx", "Binary format used by Direct3D 9 effects.\n", + true}, + {VKD3D_SHADER_TARGET_DXBC_FX, + "dxbc-fx", "Binary format used by Direct3D 10.x effects. DXBC is used as a container.\n", + true}, + {VKD3D_SHADER_TARGET_FX, + "fx", "Binary format used by Direct3D 11 effects.\n", + true}, {VKD3D_SHADER_TARGET_GLSL, "glsl", "An 'OpenGL Shading Language' shader.\n", false}