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().]
This commit is contained in:
Elizabeth Figura 2024-06-21 11:26:38 -05:00 committed by Henri Verbeet
parent 6d28cc131b
commit 8515fcbc70
Notes: Henri Verbeet 2024-09-03 17:17:14 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/963
3 changed files with 53 additions and 5 deletions

View File

@ -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, 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 D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
const char *target, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages); 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, 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 D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
const char *target, UINT flags, UINT effect_flags, UINT secondary_flags, 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 */ /** \since 1.11 */
VKD3D_UTILS_API HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID iid, void **reflection); 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 #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -10,6 +10,7 @@ global:
D3D12SerializeVersionedRootSignature; D3D12SerializeVersionedRootSignature;
D3DCompile; D3DCompile;
D3DCompile2; D3DCompile2;
D3DCompile2VKD3D;
D3DCreateBlob; D3DCreateBlob;
D3DDisassemble; D3DDisassemble;
D3DGetBlobPart; D3DGetBlobPart;

View File

@ -235,15 +235,15 @@ static enum vkd3d_shader_target_type get_target_for_profile(const char *profile)
return VKD3D_SHADER_TARGET_DXBC_TPF; 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 D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags, const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob, 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_preprocess_info preprocess_info;
struct vkd3d_shader_hlsl_source_info hlsl_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_info compile_info;
struct vkd3d_shader_compile_option *option; struct vkd3d_shader_compile_option *option;
struct vkd3d_shader_code byte_code; 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, " 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, " "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), data, (uintptr_t)data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point),
debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data, 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)) if (flags & ~(D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR))
FIXME("Ignoring flags %#x.\n", flags); 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; 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); ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);
if (messages && messages_blob) 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); 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, HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint, const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint,
const char *profile, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages) const char *profile, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages)