Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
Makefile.am | 2 +
include/private/vkd3d_blob.h | 27 +++++++
libs/vkd3d-common/blob.c | 137 ++++++++++++++++++++++++++++++++++
libs/vkd3d/vkd3d_main.c | 141 ++---------------------------------
libs/vkd3d/vkd3d_private.h | 1 +
5 files changed, 173 insertions(+), 135 deletions(-)
create mode 100644 include/private/vkd3d_blob.h
create mode 100644 libs/vkd3d-common/blob.c
diff --git a/Makefile.am b/Makefile.am
index 05403157..d0c7cd59 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,6 +64,7 @@ BUILT_SOURCES = $(widl_headers) \
noinst_LTLIBRARIES = libvkd3d-common.la
libvkd3d_common_la_SOURCES = \
include/private/vkd3d_debug.h \
+ libs/vkd3d-common/blob.c \
libs/vkd3d-common/debug.c \
libs/vkd3d-common/memory.c \
libs/vkd3d-common/utf8.c
@@ -93,6 +94,7 @@ EXTRA_libvkd3d_shader_la_DEPENDENCIES = $(srcdir)/libs/vkd3d-shader/vkd3d_shader
endif
libvkd3d_la_SOURCES = \
+ include/private/vkd3d_blob.h \
include/private/vkd3d_common.h \
include/private/vkd3d_debug.h \
include/private/vkd3d_memory.h \
diff --git a/include/private/vkd3d_blob.h b/include/private/vkd3d_blob.h
new file mode 100644
index 00000000..e78d3916
--- /dev/null
+++ b/include/private/vkd3d_blob.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017 Józef Kucia for CodeWeavers
+ *
+ * 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
+ */
+
+#ifndef __VKD3D_BLOB_H
+#define __VKD3D_BLOB_H
+
+#include "vkd3d_windows.h"
+#include "vkd3d_d3dcommon.h"
+
+HRESULT vkd3d_blob_create(void *buffer, SIZE_T size, ID3D10Blob **blob) DECLSPEC_HIDDEN;
+
+#endif /* __VKD3D_BLOB_H */
diff --git a/libs/vkd3d-common/blob.c b/libs/vkd3d-common/blob.c
new file mode 100644
index 00000000..c46abb55
--- /dev/null
+++ b/libs/vkd3d-common/blob.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2017 Józef Kucia for CodeWeavers
+ *
+ * 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
+ */
+
+#define COBJMACROS
+#define INITGUID
+#include "vkd3d.h"
+#include "vkd3d_blob.h"
+#include "vkd3d_debug.h"
+#include "vkd3d_memory.h"
+
+struct vkd3d_blob
+{
+ ID3D10Blob ID3DBlob_iface;
+ LONG refcount;
+
+ void *buffer;
+ SIZE_T size;
+};
+
+static struct vkd3d_blob *impl_from_ID3DBlob(ID3DBlob *iface)
+{
+ return CONTAINING_RECORD(iface, struct vkd3d_blob, ID3DBlob_iface);
+}
+
+static HRESULT STDMETHODCALLTYPE vkd3d_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_ID3DBlob)
+ || IsEqualGUID(riid, &IID_IUnknown))
+ {
+ ID3D10Blob_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 vkd3d_blob_AddRef(ID3DBlob *iface)
+{
+ struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
+ ULONG refcount = InterlockedIncrement(&blob->refcount);
+
+ TRACE("%p increasing refcount to %u.\n", blob, refcount);
+
+ return refcount;
+}
+
+static ULONG STDMETHODCALLTYPE vkd3d_blob_Release(ID3DBlob *iface)
+{
+ struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
+ ULONG refcount = InterlockedDecrement(&blob->refcount);
+
+ TRACE("%p decreasing refcount to %u.\n", blob, refcount);
+
+ if (!refcount)
+ {
+ vkd3d_free(blob->buffer);
+
+ vkd3d_free(blob);
+ }
+
+ return refcount;
+}
+
+static void * STDMETHODCALLTYPE vkd3d_blob_GetBufferPointer(ID3DBlob *iface)
+{
+ struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
+
+ TRACE("iface %p.\n", iface);
+
+ return blob->buffer;
+}
+
+static SIZE_T STDMETHODCALLTYPE vkd3d_blob_GetBufferSize(ID3DBlob *iface)
+{
+ struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
+
+ TRACE("iface %p.\n", iface);
+
+ return blob->size;
+}
+
+static const struct ID3D10BlobVtbl vkd3d_blob_vtbl =
+{
+ /* IUnknown methods */
+ vkd3d_blob_QueryInterface,
+ vkd3d_blob_AddRef,
+ vkd3d_blob_Release,
+ /* ID3DBlob methods */
+ vkd3d_blob_GetBufferPointer,
+ vkd3d_blob_GetBufferSize
+};
+
+static void vkd3d_blob_init(struct vkd3d_blob *blob, void *buffer, SIZE_T size)
+{
+ blob->ID3DBlob_iface.lpVtbl = &vkd3d_blob_vtbl;
+ blob->refcount = 1;
+
+ blob->buffer = buffer;
+ blob->size = size;
+}
+
+HRESULT vkd3d_blob_create(void *buffer, SIZE_T size, ID3D10Blob **blob)
+{
+ struct vkd3d_blob *object;
+
+ if (!(object = vkd3d_malloc(sizeof(*object))))
+ return E_OUTOFMEMORY;
+
+ vkd3d_blob_init(object, buffer, size);
+
+ TRACE("Created blob object %p.\n", object);
+
+ *blob = &object->ID3DBlob_iface;
+
+ return S_OK;
+}
diff --git a/libs/vkd3d/vkd3d_main.c b/libs/vkd3d/vkd3d_main.c
index 327cdf88..21d998bf 100644
--- a/libs/vkd3d/vkd3d_main.c
+++ b/libs/vkd3d/vkd3d_main.c
@@ -16,7 +16,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#define INITGUID
#include "vkd3d_private.h"
VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG");
@@ -423,126 +422,11 @@ HRESULT vkd3d_create_versioned_root_signature_deserializer(const void *data, SIZ
&IID_ID3D12VersionedRootSignatureDeserializer, iid, deserializer);
}
-/* ID3DBlob */
-struct d3d_blob
-{
- ID3D10Blob ID3DBlob_iface;
- LONG refcount;
-
- void *buffer;
- SIZE_T size;
-};
-
-static struct d3d_blob *impl_from_ID3DBlob(ID3DBlob *iface)
-{
- return CONTAINING_RECORD(iface, struct d3d_blob, ID3DBlob_iface);
-}
-
-static HRESULT STDMETHODCALLTYPE d3d_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_ID3DBlob)
- || IsEqualGUID(riid, &IID_IUnknown))
- {
- ID3D10Blob_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 d3d_blob_AddRef(ID3DBlob *iface)
-{
- struct d3d_blob *blob = impl_from_ID3DBlob(iface);
- ULONG refcount = InterlockedIncrement(&blob->refcount);
-
- TRACE("%p increasing refcount to %u.\n", blob, refcount);
-
- return refcount;
-}
-
-static ULONG STDMETHODCALLTYPE d3d_blob_Release(ID3DBlob *iface)
-{
- struct d3d_blob *blob = impl_from_ID3DBlob(iface);
- ULONG refcount = InterlockedDecrement(&blob->refcount);
-
- TRACE("%p decreasing refcount to %u.\n", blob, refcount);
-
- if (!refcount)
- {
- vkd3d_free(blob->buffer);
-
- vkd3d_free(blob);
- }
-
- return refcount;
-}
-
-static void * STDMETHODCALLTYPE d3d_blob_GetBufferPointer(ID3DBlob *iface)
-{
- struct d3d_blob *blob = impl_from_ID3DBlob(iface);
-
- TRACE("iface %p.\n", iface);
-
- return blob->buffer;
-}
-
-static SIZE_T STDMETHODCALLTYPE d3d_blob_GetBufferSize(ID3DBlob *iface)
-{
- struct d3d_blob *blob = impl_from_ID3DBlob(iface);
-
- TRACE("iface %p.\n", iface);
-
- return blob->size;
-}
-
-static const struct ID3D10BlobVtbl d3d_blob_vtbl =
-{
- /* IUnknown methods */
- d3d_blob_QueryInterface,
- d3d_blob_AddRef,
- d3d_blob_Release,
- /* ID3DBlob methods */
- d3d_blob_GetBufferPointer,
- d3d_blob_GetBufferSize
-};
-
-static void d3d_blob_init(struct d3d_blob *blob, void *buffer, SIZE_T size)
-{
- blob->ID3DBlob_iface.lpVtbl = &d3d_blob_vtbl;
- blob->refcount = 1;
-
- blob->buffer = buffer;
- blob->size = size;
-}
-
-static HRESULT d3d_blob_create(void *buffer, SIZE_T size, struct d3d_blob **blob)
-{
- struct d3d_blob *object;
-
- if (!(object = vkd3d_malloc(sizeof(*object))))
- return E_OUTOFMEMORY;
-
- d3d_blob_init(object, buffer, size);
-
- TRACE("Created blob object %p.\n", object);
-
- *blob = object;
-
- return S_OK;
-}
-
HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc,
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob)
{
struct vkd3d_shader_versioned_root_signature_desc vkd3d_desc;
struct vkd3d_shader_code dxbc;
- struct d3d_blob *blob_object;
char *messages;
HRESULT hr;
int ret;
@@ -571,25 +455,19 @@ HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc,
WARN("Failed to serialize root signature, vkd3d result %d.\n", ret);
if (error_blob && messages)
{
- if (FAILED(hr = d3d_blob_create(messages, strlen(messages), &blob_object)))
+ if (FAILED(hr = vkd3d_blob_create(messages, strlen(messages), error_blob)))
ERR("Failed to create error blob, hr %#x.\n", hr);
- else
- *error_blob = &blob_object->ID3DBlob_iface;
}
return hresult_from_vkd3d_result(ret);
}
vkd3d_shader_free_messages(messages);
- if (FAILED(hr = d3d_blob_create((void *)dxbc.code, dxbc.size, &blob_object)))
+ if (FAILED(hr = vkd3d_blob_create((void *)dxbc.code, dxbc.size, blob)))
{
WARN("Failed to create blob object, hr %#x.\n", hr);
vkd3d_shader_free_shader_code(&dxbc);
- return hr;
}
-
- *blob = &blob_object->ID3DBlob_iface;
-
- return S_OK;
+ return hr;
}
HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,
@@ -597,7 +475,6 @@ HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGN
{
const struct vkd3d_shader_versioned_root_signature_desc *vkd3d_desc;
struct vkd3d_shader_code dxbc;
- struct d3d_blob *blob_object;
char *messages;
HRESULT hr;
int ret;
@@ -619,23 +496,17 @@ HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGN
WARN("Failed to serialize root signature, vkd3d result %d.\n", ret);
if (error_blob && messages)
{
- if (FAILED(hr = d3d_blob_create(messages, strlen(messages), &blob_object)))
+ if (FAILED(hr = vkd3d_blob_create(messages, strlen(messages), error_blob)))
ERR("Failed to create error blob, hr %#x.\n", hr);
- else
- *error_blob = &blob_object->ID3DBlob_iface;
}
return hresult_from_vkd3d_result(ret);
}
vkd3d_shader_free_messages(messages);
- if (FAILED(hr = d3d_blob_create((void *)dxbc.code, dxbc.size, &blob_object)))
+ if (FAILED(hr = vkd3d_blob_create((void *)dxbc.code, dxbc.size, blob)))
{
WARN("Failed to create blob object, hr %#x.\n", hr);
vkd3d_shader_free_shader_code(&dxbc);
- return hr;
}
-
- *blob = &blob_object->ID3DBlob_iface;
-
- return S_OK;
+ return hr;
}
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 9f0982df..4af970c1 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -24,6 +24,7 @@
#define VK_NO_PROTOTYPES
#include "vkd3d_common.h"
+#include "vkd3d_blob.h"
#include "vkd3d_memory.h"
#include "vkd3d_utf8.h"
#include "list.h"
--
2.28.0