From b8fe76a8b507ccee58831885f7fbdca1f6047371 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 4 Apr 2023 10:52:15 +0200 Subject: [PATCH] d3dcompiler: Store DXBC sections as vkd3d_shader_dxbc_section_desc structures. --- configure | 8 ++++---- configure.ac | 2 +- dlls/d3d10/Makefile.in | 1 + dlls/d3dcompiler_43/blob.c | 12 ++++++------ dlls/d3dcompiler_43/compiler.c | 2 -- dlls/d3dcompiler_43/d3dcompiler_private.h | 11 +++-------- dlls/d3dcompiler_43/reflection.c | 17 +++++++++-------- dlls/d3dcompiler_43/utils.c | 16 ++++++++-------- 8 files changed, 32 insertions(+), 37 deletions(-) diff --git a/configure b/configure index a14f614e43c..836437fb89a 100755 --- a/configure +++ b/configure @@ -12891,8 +12891,8 @@ then : else $as_nop : fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for vkd3d_shader_compile in MinGW -lvkd3d-shader" >&5 -printf %s "checking for vkd3d_shader_compile in MinGW -lvkd3d-shader... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for vkd3d_shader_serialize_dxbc in MinGW -lvkd3d-shader" >&5 +printf %s "checking for vkd3d_shader_serialize_dxbc in MinGW -lvkd3d-shader... " >&6; } if test ${ac_cv_mingw_lib_vkd3d_shader+y} then : printf %s "(cached) " >&6 @@ -12909,11 +12909,11 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ -char vkd3d_shader_compile (); +char vkd3d_shader_serialize_dxbc (); int main (void) { -return vkd3d_shader_compile (); +return vkd3d_shader_serialize_dxbc (); ; return 0; } diff --git a/configure.ac b/configure.ac index c4f34e9e851..fde3f29c770 100644 --- a/configure.ac +++ b/configure.ac @@ -1089,7 +1089,7 @@ then if test "$ac_cv_mingw_header_vkd3d_h" = "yes" -a "$ac_cv_mingw_header_vkd3d_shader_h" = "yes" then WINE_CHECK_MINGW_LIB(vkd3d,vkd3d_set_log_callback,[:],[:],[$VKD3D_PE_LIBS]) - WINE_CHECK_MINGW_LIB(vkd3d-shader,vkd3d_shader_compile,[:],[:],[$VKD3D_PE_LIBS]) + WINE_CHECK_MINGW_LIB(vkd3d-shader,vkd3d_shader_serialize_dxbc,[:],[:],[$VKD3D_PE_LIBS]) if test "$ac_cv_mingw_lib_vkd3d" = "no" -o "$ac_cv_mingw_lib_vkd3d_shader" = "no" then VKD3D_PE_CFLAGS="" diff --git a/dlls/d3d10/Makefile.in b/dlls/d3d10/Makefile.in index 1b869f47f6c..df46aa3dff4 100644 --- a/dlls/d3d10/Makefile.in +++ b/dlls/d3d10/Makefile.in @@ -3,6 +3,7 @@ IMPORTLIB = d3d10 IMPORTS = uuid d3d10core d3dcompiler dxgi EXTRADEFS = -DD3D_COMPILER_VERSION=0 PARENTSRC = ../d3dcompiler_43 +EXTRAINCL = $(VKD3D_PE_CFLAGS) C_SRCS = \ d3d10_main.c \ diff --git a/dlls/d3dcompiler_43/blob.c b/dlls/d3dcompiler_43/blob.c index 3477469f9c3..ea52d4de77c 100644 --- a/dlls/d3dcompiler_43/blob.c +++ b/dlls/d3dcompiler_43/blob.c @@ -250,11 +250,11 @@ static HRESULT d3dcompiler_get_blob_part(const void *data, SIZE_T data_size, D3D for (i = 0; i < src_dxbc.count; ++i) { - struct dxbc_section *section = &src_dxbc.sections[i]; + const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc.sections[i]; if (check_blob_part(section->tag, part)) { - hr = dxbc_add_section(&dst_dxbc, section->tag, section->data, section->data_size); + hr = dxbc_add_section(&dst_dxbc, section->tag, section->data.code, section->data.size); if (FAILED(hr)) { dxbc_destroy(&src_dxbc); @@ -304,10 +304,10 @@ static HRESULT d3dcompiler_get_blob_part(const void *data, SIZE_T data_size, D3D if (count == 1 && (part == D3D_BLOB_DEBUG_INFO || part == D3D_BLOB_LEGACY_SHADER || part == D3D_BLOB_XNA_PREPASS_SHADER || part == D3D_BLOB_XNA_SHADER)) { - hr = D3DCreateBlob(dst_dxbc.sections[0].data_size, blob); + hr = D3DCreateBlob(dst_dxbc.sections[0].data.size, blob); if (SUCCEEDED(hr)) { - memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.sections[0].data, dst_dxbc.sections[0].data_size); + memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.sections[0].data.code, dst_dxbc.sections[0].data.size); } else { @@ -391,11 +391,11 @@ static HRESULT d3dcompiler_strip_shader(const void *data, SIZE_T data_size, UINT for (i = 0; i < src_dxbc.count; ++i) { - struct dxbc_section *section = &src_dxbc.sections[i]; + const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc.sections[i]; if (check_blob_strip(section->tag, flags)) { - hr = dxbc_add_section(&dst_dxbc, section->tag, section->data, section->data_size); + hr = dxbc_add_section(&dst_dxbc, section->tag, section->data.code, section->data.size); if (FAILED(hr)) { dxbc_destroy(&src_dxbc); diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index a7926785184..069ff992c22 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -25,8 +25,6 @@ #include "d3dcompiler_private.h" -#include - WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler); static HRESULT hresult_from_vkd3d_result(int vkd3d_result) diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 5f9f6c87647..8edaef4f018 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -38,6 +38,8 @@ #include #include +#include + /* * This doesn't belong here, but for some functions it is possible to return that value, * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx @@ -551,18 +553,11 @@ void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN; #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P') #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S') -struct dxbc_section -{ - DWORD tag; - const char *data; - DWORD data_size; -}; - struct dxbc { UINT size; UINT count; - struct dxbc_section *sections; + struct vkd3d_shader_dxbc_section_desc *sections; }; HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/reflection.c b/dlls/d3dcompiler_43/reflection.c index 0fa0dc16839..b83ede073cd 100644 --- a/dlls/d3dcompiler_43/reflection.c +++ b/dlls/d3dcompiler_43/reflection.c @@ -1681,12 +1681,13 @@ err_out: return hr; } -static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section) +static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, + const struct vkd3d_shader_dxbc_section_desc *section) { enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size; + const char *ptr = section->data.code; D3D11_SIGNATURE_PARAMETER_DESC *d; unsigned int string_data_offset; - const char *ptr = section->data; unsigned int string_data_size; unsigned int i, count; char *string_data; @@ -1723,7 +1724,7 @@ static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature * /* 2 u32s for the header, element_size for each element. */ string_data_offset = 2 * sizeof(uint32_t) + count * element_size * sizeof(uint32_t); - string_data_size = section->data_size - string_data_offset; + string_data_size = section->data.size - string_data_offset; string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size); if (!string_data) @@ -1732,7 +1733,7 @@ static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature * HeapFree(GetProcessHeap(), 0, d); return E_OUTOFMEMORY; } - memcpy(string_data, section->data + string_data_offset, string_data_size); + memcpy(string_data, (const char *)section->data.code + string_data_offset, string_data_size); for (i = 0; i < count; ++i) { @@ -1876,12 +1877,12 @@ static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_refl for (i = 0; i < src_dxbc.count; ++i) { - struct dxbc_section *section = &src_dxbc.sections[i]; + const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc.sections[i]; switch (section->tag) { case TAG_RDEF: - hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size); + hr = d3dcompiler_parse_rdef(reflection, section->data.code, section->data.size); if (FAILED(hr)) { WARN("Failed to parse RDEF section.\n"); @@ -1943,7 +1944,7 @@ static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_refl case TAG_SHEX: case TAG_SHDR: - hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size); + hr = d3dcompiler_parse_shdr(reflection, section->data.code, section->data.size); if (FAILED(hr)) { WARN("Failed to parse SHDR section.\n"); @@ -1952,7 +1953,7 @@ static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_refl break; case TAG_STAT: - hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size); + hr = d3dcompiler_parse_stat(reflection, section->data.code, section->data.size); if (FAILED(hr)) { WARN("Failed to parse section STAT.\n"); diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 9a6be8db923..9a8bdaccb1b 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -538,7 +538,7 @@ HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t if (dxbc->count >= dxbc->size) { - struct dxbc_section *new_sections; + struct vkd3d_shader_dxbc_section_desc *new_sections; DWORD new_size = dxbc->size << 1; new_sections = HeapReAlloc(GetProcessHeap(), 0, dxbc->sections, new_size * sizeof(*dxbc->sections)); @@ -553,8 +553,8 @@ HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t } dxbc->sections[dxbc->count].tag = tag; - dxbc->sections[dxbc->count].data_size = data_size; - dxbc->sections[dxbc->count].data = data; + dxbc->sections[dxbc->count].data.size = data_size; + dxbc->sections[dxbc->count].data.code = data; ++dxbc->count; return S_OK; @@ -670,7 +670,7 @@ HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) for (i = 0; i < dxbc->count; ++i) { - size += 12 + dxbc->sections[i].data_size; + size += 12 + dxbc->sections[i].data.size; } hr = D3DCreateBlob(size, &object); @@ -703,16 +703,16 @@ HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) for (i = 0; i < dxbc->count; ++i) { write_u32(&ptr, offset); - offset += 8 + dxbc->sections[i].data_size; + offset += 8 + dxbc->sections[i].data.size; } /* write the chunks */ for (i = 0; i < dxbc->count; ++i) { write_u32(&ptr, dxbc->sections[i].tag); - write_u32(&ptr, dxbc->sections[i].data_size); - memcpy(ptr, dxbc->sections[i].data, dxbc->sections[i].data_size); - ptr += dxbc->sections[i].data_size; + write_u32(&ptr, dxbc->sections[i].data.size); + memcpy(ptr, dxbc->sections[i].data.code, dxbc->sections[i].data.size); + ptr += dxbc->sections[i].data.size; } TRACE("Created ID3DBlob %p\n", object);