2010-08-15 15:05:31 +00:00
|
|
|
/*
|
|
|
|
* Direct3D blob file
|
|
|
|
*
|
|
|
|
* Copyright 2010 Rico Schüller
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d3dcompiler_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
|
|
|
|
|
2011-04-01 13:00:04 +00:00
|
|
|
struct d3dcompiler_blob
|
|
|
|
{
|
|
|
|
ID3DBlob ID3DBlob_iface;
|
|
|
|
LONG refcount;
|
|
|
|
|
|
|
|
SIZE_T size;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2010-12-21 10:05:49 +00:00
|
|
|
static inline struct d3dcompiler_blob *impl_from_ID3DBlob(ID3DBlob *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct d3dcompiler_blob, ID3DBlob_iface);
|
|
|
|
}
|
|
|
|
|
2010-08-15 15:05:31 +00:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3dcompiler_blob_QueryInterface(ID3DBlob *iface, REFIID riid, void **object)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_ID3D10Blob)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3dcompiler_blob_AddRef(ID3DBlob *iface)
|
|
|
|
{
|
2010-12-21 10:05:49 +00:00
|
|
|
struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface);
|
2010-08-15 15:05:31 +00:00
|
|
|
ULONG refcount = InterlockedIncrement(&blob->refcount);
|
|
|
|
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("%p increasing refcount to %lu.\n", blob, refcount);
|
2010-08-15 15:05:31 +00:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3dcompiler_blob_Release(ID3DBlob *iface)
|
|
|
|
{
|
2010-12-21 10:05:49 +00:00
|
|
|
struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface);
|
2010-08-15 15:05:31 +00:00
|
|
|
ULONG refcount = InterlockedDecrement(&blob->refcount);
|
|
|
|
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("%p decreasing refcount to %lu.\n", blob, refcount);
|
2010-08-15 15:05:31 +00:00
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, blob->data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ID3DBlob methods */
|
|
|
|
|
|
|
|
static void * STDMETHODCALLTYPE d3dcompiler_blob_GetBufferPointer(ID3DBlob *iface)
|
|
|
|
{
|
2010-12-21 10:05:49 +00:00
|
|
|
struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface);
|
2010-08-15 15:05:34 +00:00
|
|
|
|
|
|
|
TRACE("iface %p\n", iface);
|
2010-08-15 15:05:31 +00:00
|
|
|
|
2010-08-15 15:05:34 +00:00
|
|
|
return blob->data;
|
2010-08-15 15:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SIZE_T STDMETHODCALLTYPE d3dcompiler_blob_GetBufferSize(ID3DBlob *iface)
|
|
|
|
{
|
2010-12-21 10:05:49 +00:00
|
|
|
struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface);
|
2010-08-15 15:05:40 +00:00
|
|
|
|
|
|
|
TRACE("iface %p\n", iface);
|
2010-08-15 15:05:31 +00:00
|
|
|
|
2010-08-15 15:05:40 +00:00
|
|
|
return blob->size;
|
2010-08-15 15:05:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 11:05:48 +00:00
|
|
|
static const struct ID3D10BlobVtbl d3dcompiler_blob_vtbl =
|
2010-08-15 15:05:31 +00:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
d3dcompiler_blob_QueryInterface,
|
|
|
|
d3dcompiler_blob_AddRef,
|
|
|
|
d3dcompiler_blob_Release,
|
|
|
|
/* ID3DBlob methods */
|
|
|
|
d3dcompiler_blob_GetBufferPointer,
|
|
|
|
d3dcompiler_blob_GetBufferSize,
|
|
|
|
};
|
|
|
|
|
2011-04-01 13:00:04 +00:00
|
|
|
static HRESULT d3dcompiler_blob_init(struct d3dcompiler_blob *blob, SIZE_T data_size)
|
2010-08-15 15:05:31 +00:00
|
|
|
{
|
2010-12-21 10:05:49 +00:00
|
|
|
blob->ID3DBlob_iface.lpVtbl = &d3dcompiler_blob_vtbl;
|
2010-08-15 15:05:31 +00:00
|
|
|
blob->refcount = 1;
|
|
|
|
blob->size = data_size;
|
|
|
|
|
|
|
|
blob->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data_size);
|
|
|
|
if (!blob->data)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate D3D blob data memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2010-10-03 13:11:54 +00:00
|
|
|
|
2011-04-01 13:00:04 +00:00
|
|
|
HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob)
|
|
|
|
{
|
|
|
|
struct d3dcompiler_blob *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data_size %Iu, blob %p.\n", data_size, blob);
|
2011-04-01 13:00:04 +00:00
|
|
|
|
|
|
|
if (!blob)
|
|
|
|
{
|
|
|
|
WARN("Invalid blob specified.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = d3dcompiler_blob_init(object, data_size);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
WARN("Failed to initialize blob, hr %#lx.\n", hr);
|
2011-04-01 13:00:04 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:00:16 +00:00
|
|
|
*blob = &object->ID3DBlob_iface;
|
2011-04-01 13:00:04 +00:00
|
|
|
|
2011-04-01 13:00:16 +00:00
|
|
|
TRACE("Created ID3DBlob %p\n", *blob);
|
2011-04-01 13:00:04 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-03 13:12:00 +00:00
|
|
|
static BOOL check_blob_part(DWORD tag, D3D_BLOB_PART part)
|
|
|
|
{
|
|
|
|
BOOL add = FALSE;
|
|
|
|
|
|
|
|
switch(part)
|
|
|
|
{
|
|
|
|
case D3D_BLOB_INPUT_SIGNATURE_BLOB:
|
|
|
|
if (tag == TAG_ISGN) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:06 +00:00
|
|
|
case D3D_BLOB_OUTPUT_SIGNATURE_BLOB:
|
2010-12-12 20:48:25 +00:00
|
|
|
if (tag == TAG_OSGN || tag == TAG_OSG5) add = TRUE;
|
2010-10-03 13:12:06 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:12 +00:00
|
|
|
case D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB:
|
2010-12-12 20:48:25 +00:00
|
|
|
if (tag == TAG_ISGN || tag == TAG_OSGN || tag == TAG_OSG5) add = TRUE;
|
2010-10-03 13:12:12 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-12 17:24:44 +00:00
|
|
|
case D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB:
|
|
|
|
if (tag == TAG_PCSG) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-12 17:24:52 +00:00
|
|
|
case D3D_BLOB_ALL_SIGNATURE_BLOB:
|
2010-12-12 20:48:25 +00:00
|
|
|
if (tag == TAG_ISGN || tag == TAG_OSGN || tag == TAG_OSG5 || tag == TAG_PCSG) add = TRUE;
|
2010-10-12 17:24:52 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:17 +00:00
|
|
|
case D3D_BLOB_DEBUG_INFO:
|
|
|
|
if (tag == TAG_SDBG) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-12 17:24:55 +00:00
|
|
|
case D3D_BLOB_LEGACY_SHADER:
|
|
|
|
if (tag == TAG_Aon9) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-12 17:24:59 +00:00
|
|
|
case D3D_BLOB_XNA_PREPASS_SHADER:
|
|
|
|
if (tag == TAG_XNAP) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-12 17:25:02 +00:00
|
|
|
case D3D_BLOB_XNA_SHADER:
|
|
|
|
if (tag == TAG_XNAS) add = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:00 +00:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled D3D_BLOB_PART %s.\n", debug_d3dcompiler_d3d_blob_part(part));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s tag %s\n", add ? "Add" : "Skip", debugstr_an((const char *)&tag, 4));
|
|
|
|
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:00:19 +00:00
|
|
|
static HRESULT d3dcompiler_get_blob_part(const void *data, SIZE_T data_size, D3D_BLOB_PART part, UINT flags, ID3DBlob **blob)
|
2010-10-03 13:11:54 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
const struct vkd3d_shader_code src_dxbc = {.code = data, .size = data_size};
|
2023-04-04 08:52:15 +00:00
|
|
|
struct vkd3d_shader_dxbc_section_desc *sections;
|
2023-04-04 08:52:15 +00:00
|
|
|
struct vkd3d_shader_dxbc_desc src_dxbc_desc;
|
2023-04-04 08:52:15 +00:00
|
|
|
struct vkd3d_shader_code dst_dxbc;
|
|
|
|
unsigned int section_count, i;
|
2010-10-03 13:11:54 +00:00
|
|
|
HRESULT hr;
|
2023-04-04 08:52:15 +00:00
|
|
|
int ret;
|
2010-10-03 13:11:54 +00:00
|
|
|
|
2023-04-11 15:44:39 +00:00
|
|
|
if (!data || data_size < DXBC_HEADER_SIZE || flags || !blob)
|
2010-10-03 13:11:54 +00:00
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
WARN("Invalid arguments: data %p, data_size %Iu, flags %#x, blob %p.\n", data, data_size, flags, blob);
|
2010-10-03 13:11:54 +00:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (part > D3D_BLOB_TEST_COMPILE_PERF
|
|
|
|
|| (part < D3D_BLOB_TEST_ALTERNATE_SHADER && part > D3D_BLOB_XNA_SHADER))
|
|
|
|
{
|
|
|
|
WARN("Invalid D3D_BLOB_PART: part %s\n", debug_d3dcompiler_d3d_blob_part(part));
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if ((ret = vkd3d_shader_parse_dxbc(&src_dxbc, 0, &src_dxbc_desc, NULL)) < 0)
|
2010-10-03 13:11:54 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
WARN("Failed to parse source data, ret %d.\n", ret);
|
|
|
|
return E_FAIL;
|
2010-10-03 13:11:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if (!(sections = calloc(src_dxbc_desc.section_count, sizeof(*sections))))
|
2010-10-03 13:12:00 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
ERR("Failed to allocate sections memory.\n");
|
2023-04-04 08:52:15 +00:00
|
|
|
vkd3d_shader_free_dxbc(&src_dxbc_desc);
|
2023-04-04 08:52:15 +00:00
|
|
|
return E_OUTOFMEMORY;
|
2010-10-03 13:12:00 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
for (i = 0, section_count = 0; i < src_dxbc_desc.section_count; ++i)
|
2010-10-03 13:12:00 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
const struct vkd3d_shader_dxbc_section_desc *src_section = &src_dxbc_desc.sections[i];
|
2010-10-03 13:12:00 +00:00
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if (check_blob_part(src_section->tag, part))
|
|
|
|
sections[section_count++] = *src_section;
|
|
|
|
}
|
2010-10-03 13:12:00 +00:00
|
|
|
|
|
|
|
switch(part)
|
|
|
|
{
|
|
|
|
case D3D_BLOB_INPUT_SIGNATURE_BLOB:
|
2010-10-03 13:12:06 +00:00
|
|
|
case D3D_BLOB_OUTPUT_SIGNATURE_BLOB:
|
2010-10-12 17:24:44 +00:00
|
|
|
case D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB:
|
2010-10-03 13:12:17 +00:00
|
|
|
case D3D_BLOB_DEBUG_INFO:
|
2010-10-12 17:24:55 +00:00
|
|
|
case D3D_BLOB_LEGACY_SHADER:
|
2010-10-12 17:24:59 +00:00
|
|
|
case D3D_BLOB_XNA_PREPASS_SHADER:
|
2010-10-12 17:25:02 +00:00
|
|
|
case D3D_BLOB_XNA_SHADER:
|
2023-04-04 08:52:15 +00:00
|
|
|
if (section_count != 1)
|
|
|
|
section_count = 0;
|
2010-10-03 13:12:00 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:12 +00:00
|
|
|
case D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB:
|
2023-04-04 08:52:15 +00:00
|
|
|
if (section_count != 2)
|
|
|
|
section_count = 0;
|
2010-10-12 17:24:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D_BLOB_ALL_SIGNATURE_BLOB:
|
2023-04-04 08:52:15 +00:00
|
|
|
if (section_count != 3)
|
|
|
|
section_count = 0;
|
2010-10-03 13:12:12 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-03 13:12:00 +00:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled D3D_BLOB_PART %s.\n", debug_d3dcompiler_d3d_blob_part(part));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if (!section_count)
|
2010-10-03 13:12:00 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
WARN("Nothing to write into the blob.\n");
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto done;
|
2010-10-03 13:12:00 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 13:12:17 +00:00
|
|
|
/* some parts aren't full DXBCs, they contain only the data */
|
2023-04-04 08:52:15 +00:00
|
|
|
if (section_count == 1 && (part == D3D_BLOB_DEBUG_INFO || part == D3D_BLOB_LEGACY_SHADER
|
|
|
|
|| part == D3D_BLOB_XNA_PREPASS_SHADER || part == D3D_BLOB_XNA_SHADER))
|
2010-10-03 13:11:54 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
dst_dxbc = sections[0].data;
|
2010-10-03 13:12:17 +00:00
|
|
|
}
|
2023-04-04 08:52:15 +00:00
|
|
|
else if ((ret = vkd3d_shader_serialize_dxbc(section_count, sections, &dst_dxbc, NULL) < 0))
|
2010-10-03 13:12:17 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
WARN("Failed to serialise DXBC, ret %d.\n", ret);
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto done;
|
2010-10-03 13:11:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if (FAILED(hr = D3DCreateBlob(dst_dxbc.size, blob)))
|
|
|
|
WARN("Failed to create blob, hr %#lx.\n", hr);
|
|
|
|
else
|
|
|
|
memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.code, dst_dxbc.size);
|
|
|
|
if (dst_dxbc.code != sections[0].data.code)
|
|
|
|
vkd3d_shader_free_shader_code(&dst_dxbc);
|
|
|
|
|
|
|
|
done:
|
|
|
|
free(sections);
|
2023-04-04 08:52:15 +00:00
|
|
|
vkd3d_shader_free_dxbc(&src_dxbc_desc);
|
2010-10-03 13:11:54 +00:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2010-10-12 17:25:26 +00:00
|
|
|
|
|
|
|
static BOOL check_blob_strip(DWORD tag, UINT flags)
|
|
|
|
{
|
|
|
|
BOOL add = TRUE;
|
|
|
|
|
|
|
|
if (flags & D3DCOMPILER_STRIP_TEST_BLOBS) FIXME("Unhandled flag D3DCOMPILER_STRIP_TEST_BLOBS.\n");
|
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
{
|
|
|
|
case TAG_RDEF:
|
|
|
|
case TAG_STAT:
|
|
|
|
if (flags & D3DCOMPILER_STRIP_REFLECTION_DATA) add = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG_SDBG:
|
|
|
|
if (flags & D3DCOMPILER_STRIP_DEBUG_INFO) add = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s tag %s\n", add ? "Add" : "Skip", debugstr_an((const char *)&tag, 4));
|
|
|
|
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:00:19 +00:00
|
|
|
static HRESULT d3dcompiler_strip_shader(const void *data, SIZE_T data_size, UINT flags, ID3DBlob **blob)
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2023-04-04 08:52:16 +00:00
|
|
|
const struct vkd3d_shader_code src_dxbc = {.code = data, .size = data_size};
|
2023-04-04 08:52:15 +00:00
|
|
|
struct vkd3d_shader_dxbc_section_desc *sections;
|
2023-04-04 08:52:16 +00:00
|
|
|
struct vkd3d_shader_dxbc_desc src_dxbc_desc;
|
2023-04-04 08:52:15 +00:00
|
|
|
struct vkd3d_shader_code dst_dxbc;
|
|
|
|
unsigned int section_count, i;
|
2010-10-12 17:25:26 +00:00
|
|
|
HRESULT hr;
|
2023-04-04 08:52:15 +00:00
|
|
|
int ret;
|
2010-10-12 17:25:26 +00:00
|
|
|
|
|
|
|
if (!blob)
|
|
|
|
{
|
|
|
|
WARN("NULL for blob specified\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:58:01 +00:00
|
|
|
if (!data || data_size < DXBC_HEADER_SIZE)
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
WARN("Invalid arguments: data %p, data_size %Iu.\n", data, data_size);
|
2010-10-12 17:25:26 +00:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:16 +00:00
|
|
|
if ((ret = vkd3d_shader_parse_dxbc(&src_dxbc, 0, &src_dxbc_desc, NULL)) < 0)
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2023-04-04 08:52:16 +00:00
|
|
|
WARN("Failed to parse source data, ret %d.\n", ret);
|
|
|
|
return E_FAIL;
|
2010-10-12 17:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* src_dxbc.count >= dst_dxbc.count */
|
2023-04-04 08:52:16 +00:00
|
|
|
if (!(sections = calloc(src_dxbc_desc.section_count, sizeof(*sections))))
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
ERR("Failed to allocate sections memory.\n");
|
2023-04-04 08:52:16 +00:00
|
|
|
vkd3d_shader_free_dxbc(&src_dxbc_desc);
|
2023-04-04 08:52:15 +00:00
|
|
|
return E_OUTOFMEMORY;
|
2010-10-12 17:25:26 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:16 +00:00
|
|
|
for (i = 0, section_count = 0; i < src_dxbc_desc.section_count; ++i)
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2023-04-04 08:52:16 +00:00
|
|
|
const struct vkd3d_shader_dxbc_section_desc *src_section = &src_dxbc_desc.sections[i];
|
2023-04-04 08:52:15 +00:00
|
|
|
|
|
|
|
if (check_blob_strip(src_section->tag, flags))
|
|
|
|
sections[section_count++] = *src_section;
|
2010-10-12 17:25:26 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if ((ret = vkd3d_shader_serialize_dxbc(section_count, sections, &dst_dxbc, NULL) < 0))
|
2010-10-12 17:25:26 +00:00
|
|
|
{
|
2023-04-04 08:52:15 +00:00
|
|
|
WARN("Failed to serialise DXBC, ret %d.\n", ret);
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto done;
|
2010-10-12 17:25:26 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:52:15 +00:00
|
|
|
if (FAILED(hr = D3DCreateBlob(dst_dxbc.size, blob)))
|
|
|
|
WARN("Failed to create blob, hr %#lx.\n", hr);
|
|
|
|
else
|
|
|
|
memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.code, dst_dxbc.size);
|
|
|
|
vkd3d_shader_free_shader_code(&dst_dxbc);
|
|
|
|
|
|
|
|
done:
|
|
|
|
free(sections);
|
2023-04-04 08:52:16 +00:00
|
|
|
vkd3d_shader_free_dxbc(&src_dxbc_desc);
|
2010-10-12 17:25:26 +00:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
HRESULT WINAPI D3DGetBlobPart(const void *data, SIZE_T data_size, D3D_BLOB_PART part, UINT flags, ID3DBlob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, part %s, flags %#x, blob %p.\n", data,
|
2011-04-01 13:00:19 +00:00
|
|
|
data_size, debug_d3dcompiler_d3d_blob_part(part), flags, blob);
|
|
|
|
|
|
|
|
return d3dcompiler_get_blob_part(data, data_size, part, flags, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DGetInputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, blob %p.\n", data, data_size, blob);
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_INPUT_SIGNATURE_BLOB, 0, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DGetOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, blob %p.\n", data, data_size, blob);
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_OUTPUT_SIGNATURE_BLOB, 0, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DGetInputAndOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, blob %p.\n", data, data_size, blob);
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB, 0, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DGetDebugInfo(const void *data, SIZE_T data_size, ID3DBlob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, blob %p.\n", data, data_size, blob);
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_DEBUG_INFO, 0, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DStripShader(const void *data, SIZE_T data_size, UINT flags, ID3D10Blob **blob)
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
TRACE("data %p, data_size %Iu, flags %#x, blob %p.\n", data, data_size, flags, blob);
|
2011-04-01 13:00:19 +00:00
|
|
|
|
|
|
|
return d3dcompiler_strip_shader(data, data_size, flags, blob);
|
|
|
|
}
|
2015-10-18 03:19:53 +00:00
|
|
|
|
|
|
|
HRESULT WINAPI D3DReadFileToBlob(const WCHAR *filename, ID3DBlob **contents)
|
|
|
|
{
|
2019-05-07 20:42:24 +00:00
|
|
|
struct d3dcompiler_blob *object;
|
|
|
|
SIZE_T data_size;
|
|
|
|
DWORD read_size;
|
|
|
|
HANDLE file;
|
|
|
|
HRESULT hr;
|
2015-10-18 03:19:53 +00:00
|
|
|
|
2019-05-07 20:42:24 +00:00
|
|
|
TRACE("filename %s, contents %p.\n", debugstr_w(filename), contents);
|
|
|
|
|
|
|
|
file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
data_size = GetFileSize(file, NULL);
|
|
|
|
if (data_size == INVALID_FILE_SIZE)
|
|
|
|
{
|
|
|
|
CloseHandle(file);
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
|
|
|
{
|
|
|
|
CloseHandle(file);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = d3dcompiler_blob_init(object, data_size)))
|
|
|
|
{
|
2022-02-08 18:48:48 +00:00
|
|
|
WARN("Failed to initialise blob, hr %#lx.\n", hr);
|
2019-05-07 20:42:24 +00:00
|
|
|
CloseHandle(file);
|
|
|
|
heap_free(object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReadFile(file, object->data, data_size, &read_size, NULL) || (read_size != data_size))
|
|
|
|
{
|
|
|
|
WARN("Failed to read file contents.\n");
|
|
|
|
CloseHandle(file);
|
|
|
|
heap_free(object->data);
|
|
|
|
heap_free(object);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
CloseHandle(file);
|
|
|
|
object->size = read_size;
|
|
|
|
|
|
|
|
*contents = &object->ID3DBlob_iface;
|
|
|
|
|
|
|
|
TRACE("Returning ID3DBlob %p.\n", *contents);
|
|
|
|
|
|
|
|
return S_OK;
|
2015-10-18 03:19:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 21:37:14 +00:00
|
|
|
HRESULT WINAPI D3DWriteBlobToFile(ID3DBlob *blob, const WCHAR *filename, BOOL overwrite)
|
2015-10-18 03:19:53 +00:00
|
|
|
{
|
2022-01-26 21:37:14 +00:00
|
|
|
DWORD written_size;
|
|
|
|
SIZE_T data_size;
|
|
|
|
HANDLE file;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("blob %p, filename %s, overwrite %#x.\n", blob, debugstr_w(filename), overwrite);
|
|
|
|
|
|
|
|
file = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, overwrite ? CREATE_ALWAYS : CREATE_NEW,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2015-10-18 03:19:53 +00:00
|
|
|
|
2022-01-26 21:37:14 +00:00
|
|
|
data_size = ID3D10Blob_GetBufferSize(blob);
|
|
|
|
ret = WriteFile(file, ID3D10Blob_GetBufferPointer(blob), data_size, &written_size, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
if (!ret || data_size != written_size)
|
|
|
|
{
|
|
|
|
WARN("Failed to write blob contents.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2015-10-18 03:19:53 +00:00
|
|
|
}
|