vkd3d: Make ID3DBlob implementation more accessible.

We're going to need this to implement other parts of the
API, so it should be in common code.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
This commit is contained in:
Philip Rebohle 2020-04-07 21:40:29 +02:00 committed by Hans-Kristian Arntzen
parent ecc46fe1ec
commit 20aa3c3c26
3 changed files with 116 additions and 114 deletions

View File

@ -1080,3 +1080,107 @@ HRESULT vkd3d_set_vk_object_name(struct d3d12_device *device, uint64_t vk_object
return hresult_from_vk_result(vr);
}
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;
}
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;
}

View File

@ -422,120 +422,6 @@ 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)
{

View File

@ -1470,6 +1470,18 @@ static inline unsigned int d3d12_device_get_descriptor_handle_increment_size(str
return ID3D12Device_GetDescriptorHandleIncrementSize(&device->ID3D12Device_iface, descriptor_type);
}
/* ID3DBlob */
struct d3d_blob
{
ID3D10Blob ID3DBlob_iface;
LONG refcount;
void *buffer;
SIZE_T size;
};
HRESULT d3d_blob_create(void *buffer, SIZE_T size, struct d3d_blob **blob);
/* utils */
enum vkd3d_format_type
{