From 8515fcbc70a0fcdd9cb28e329b1bff485c5f3916 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Fri, 21 Jun 2024 11:26:38 -0500 Subject: [PATCH] vkd3d-utils: Add a D3DCompile2VKD3D() that allows configuring DLL version. This would allow us to use vkd3d-utils directly in Wine [with the exception of D3D_COMPILE_STANDARD_FILE_INCLUDE, but we can simply pass the ID3DInclude object to D3DCompile2VKD3D().] --- include/vkd3d_utils.h | 22 ++++++++++++++++++ libs/vkd3d-utils/vkd3d_utils.map | 1 + libs/vkd3d-utils/vkd3d_utils_main.c | 35 ++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/include/vkd3d_utils.h b/include/vkd3d_utils.h index 65e17276..4814fc6e 100644 --- a/include/vkd3d_utils.h +++ b/include/vkd3d_utils.h @@ -77,6 +77,12 @@ VKD3D_UTILS_API HRESULT WINAPI D3D12SerializeVersionedRootSignature(const D3D12_ VKD3D_UTILS_API HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages); +/** + * D3DCompile2() targets the behaviour of d3dcompiler_47.dll. To target the + * behaviour of other d3dcompiler versions, use D3DCompile2VKD3D(). + * + * \since 1.3 + */ VKD3D_UTILS_API HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT flags, UINT effect_flags, UINT secondary_flags, @@ -122,6 +128,22 @@ VKD3D_UTILS_API HRESULT WINAPI D3DDisassemble(const void *data, /** \since 1.11 */ VKD3D_UTILS_API HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID iid, void **reflection); +/** + * As D3DCompile2(), but with an extra argument that allows targeting + * different d3dcompiler versions. + * + * \param compiler_version The d3dcompiler version to target. This should be + * set to the numerical value in the d3dcompiler library name. E.g. to target + * the behaviour of d3dcompiler_36.dll, set this parameter to 36. + * + * \since 1.14 + */ +VKD3D_UTILS_API HRESULT WINAPI D3DCompile2VKD3D(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, + const char *target, UINT flags, UINT effect_flags, UINT secondary_flags, + const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, + ID3DBlob **error_messages, unsigned int compiler_version); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/libs/vkd3d-utils/vkd3d_utils.map b/libs/vkd3d-utils/vkd3d_utils.map index c422c0ca..115b17a8 100644 --- a/libs/vkd3d-utils/vkd3d_utils.map +++ b/libs/vkd3d-utils/vkd3d_utils.map @@ -10,6 +10,7 @@ global: D3D12SerializeVersionedRootSignature; D3DCompile; D3DCompile2; + D3DCompile2VKD3D; D3DCreateBlob; D3DDisassemble; D3DGetBlobPart; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index b690aeb5..a36d93cc 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -235,15 +235,15 @@ static enum vkd3d_shader_target_type get_target_for_profile(const char *profile) return VKD3D_SHADER_TARGET_DXBC_TPF; } -HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, +HRESULT WINAPI D3DCompile2VKD3D(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) + ID3DBlob **messages_blob, unsigned int compiler_version) { struct vkd3d_shader_preprocess_info preprocess_info; struct vkd3d_shader_hlsl_source_info hlsl_info; - struct vkd3d_shader_compile_option options[5]; + struct vkd3d_shader_compile_option options[6]; struct vkd3d_shader_compile_info compile_info; struct vkd3d_shader_compile_option *option; struct vkd3d_shader_code byte_code; @@ -254,10 +254,10 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen TRACE("data %p, data_size %"PRIuPTR", 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 %"PRIuPTR", shader_blob %p, messages_blob %p.\n", + "secondary_data_size %"PRIuPTR", shader_blob %p, messages_blob %p, compiler_version %u.\n", data, (uintptr_t)data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point), debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data, - (uintptr_t)secondary_data_size, shader_blob, messages_blob); + (uintptr_t)secondary_data_size, shader_blob, messages_blob, compiler_version); if (flags & ~(D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)) FIXME("Ignoring flags %#x.\n", flags); @@ -336,6 +336,13 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen option->value = true; } + if (compiler_version <= 39) + { + option = &options[compile_info.option_count++]; + option->name = VKD3D_SHADER_COMPILE_OPTION_INCLUDE_EMPTY_BUFFERS_IN_EFFECTS; + option->value = true; + } + ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages); if (messages && messages_blob) @@ -376,6 +383,24 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen return hresult_from_vkd3d_result(ret); } +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) +{ + TRACE("data %p, data_size %"PRIuPTR", 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 %"PRIuPTR", shader_blob %p, messages_blob %p.\n", + data, (uintptr_t)data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point), + debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data, + (uintptr_t)secondary_data_size, shader_blob, messages_blob); + + return D3DCompile2VKD3D(data, data_size, filename, macros, include, + entry_point, profile, flags, effect_flags, secondary_flags, + secondary_data, secondary_data_size, shader_blob, messages_blob, 47); +} + HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint, const char *profile, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages)