mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d: Move the ID3DBlob implementation to vkd3d-common.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
56cd4a94d5
commit
e5fea6ade0
@ -64,6 +64,7 @@ BUILT_SOURCES = $(widl_headers) \
|
|||||||
noinst_LTLIBRARIES = libvkd3d-common.la
|
noinst_LTLIBRARIES = libvkd3d-common.la
|
||||||
libvkd3d_common_la_SOURCES = \
|
libvkd3d_common_la_SOURCES = \
|
||||||
include/private/vkd3d_debug.h \
|
include/private/vkd3d_debug.h \
|
||||||
|
libs/vkd3d-common/blob.c \
|
||||||
libs/vkd3d-common/debug.c \
|
libs/vkd3d-common/debug.c \
|
||||||
libs/vkd3d-common/memory.c \
|
libs/vkd3d-common/memory.c \
|
||||||
libs/vkd3d-common/utf8.c
|
libs/vkd3d-common/utf8.c
|
||||||
@ -93,6 +94,7 @@ EXTRA_libvkd3d_shader_la_DEPENDENCIES = $(srcdir)/libs/vkd3d-shader/vkd3d_shader
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
libvkd3d_la_SOURCES = \
|
libvkd3d_la_SOURCES = \
|
||||||
|
include/private/vkd3d_blob.h \
|
||||||
include/private/vkd3d_common.h \
|
include/private/vkd3d_common.h \
|
||||||
include/private/vkd3d_debug.h \
|
include/private/vkd3d_debug.h \
|
||||||
include/private/vkd3d_memory.h \
|
include/private/vkd3d_memory.h \
|
||||||
|
27
include/private/vkd3d_blob.h
Normal file
27
include/private/vkd3d_blob.h
Normal file
@ -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 */
|
137
libs/vkd3d-common/blob.c
Normal file
137
libs/vkd3d-common/blob.c
Normal file
@ -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;
|
||||||
|
}
|
@ -16,7 +16,6 @@
|
|||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define INITGUID
|
|
||||||
#include "vkd3d_private.h"
|
#include "vkd3d_private.h"
|
||||||
|
|
||||||
VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG");
|
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);
|
&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,
|
HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc,
|
||||||
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob)
|
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob)
|
||||||
{
|
{
|
||||||
struct vkd3d_shader_versioned_root_signature_desc vkd3d_desc;
|
struct vkd3d_shader_versioned_root_signature_desc vkd3d_desc;
|
||||||
struct vkd3d_shader_code dxbc;
|
struct vkd3d_shader_code dxbc;
|
||||||
struct d3d_blob *blob_object;
|
|
||||||
char *messages;
|
char *messages;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
int ret;
|
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);
|
WARN("Failed to serialize root signature, vkd3d result %d.\n", ret);
|
||||||
if (error_blob && messages)
|
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);
|
ERR("Failed to create error blob, hr %#x.\n", hr);
|
||||||
else
|
|
||||||
*error_blob = &blob_object->ID3DBlob_iface;
|
|
||||||
}
|
}
|
||||||
return hresult_from_vkd3d_result(ret);
|
return hresult_from_vkd3d_result(ret);
|
||||||
}
|
}
|
||||||
vkd3d_shader_free_messages(messages);
|
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);
|
WARN("Failed to create blob object, hr %#x.\n", hr);
|
||||||
vkd3d_shader_free_shader_code(&dxbc);
|
vkd3d_shader_free_shader_code(&dxbc);
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
|
return hr;
|
||||||
*blob = &blob_object->ID3DBlob_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,
|
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;
|
const struct vkd3d_shader_versioned_root_signature_desc *vkd3d_desc;
|
||||||
struct vkd3d_shader_code dxbc;
|
struct vkd3d_shader_code dxbc;
|
||||||
struct d3d_blob *blob_object;
|
|
||||||
char *messages;
|
char *messages;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
int ret;
|
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);
|
WARN("Failed to serialize root signature, vkd3d result %d.\n", ret);
|
||||||
if (error_blob && messages)
|
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);
|
ERR("Failed to create error blob, hr %#x.\n", hr);
|
||||||
else
|
|
||||||
*error_blob = &blob_object->ID3DBlob_iface;
|
|
||||||
}
|
}
|
||||||
return hresult_from_vkd3d_result(ret);
|
return hresult_from_vkd3d_result(ret);
|
||||||
}
|
}
|
||||||
vkd3d_shader_free_messages(messages);
|
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);
|
WARN("Failed to create blob object, hr %#x.\n", hr);
|
||||||
vkd3d_shader_free_shader_code(&dxbc);
|
vkd3d_shader_free_shader_code(&dxbc);
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
|
return hr;
|
||||||
*blob = &blob_object->ID3DBlob_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
|
|
||||||
#include "vkd3d_common.h"
|
#include "vkd3d_common.h"
|
||||||
|
#include "vkd3d_blob.h"
|
||||||
#include "vkd3d_memory.h"
|
#include "vkd3d_memory.h"
|
||||||
#include "vkd3d_utf8.h"
|
#include "vkd3d_utf8.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
Reference in New Issue
Block a user