mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
libs/vkd3d: Add support for device parent.
In order to hold a reference to IDXGIAdapter. Signed-off-by: Józef Kucia <jkucia@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
b1fc5039c8
commit
372bd56ade
@ -69,6 +69,7 @@ struct vkd3d_device_create_info
|
|||||||
const char * const *device_extensions;
|
const char * const *device_extensions;
|
||||||
uint32_t device_extension_count;
|
uint32_t device_extension_count;
|
||||||
|
|
||||||
|
IUnknown *parent;
|
||||||
LUID adapter_luid;
|
LUID adapter_luid;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ ULONG vkd3d_instance_incref(struct vkd3d_instance *instance);
|
|||||||
|
|
||||||
HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,
|
HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,
|
||||||
REFIID iid, void **device);
|
REFIID iid, void **device);
|
||||||
|
IUnknown *vkd3d_get_device_parent(ID3D12Device *device);
|
||||||
VkDevice vkd3d_get_vk_device(ID3D12Device *device);
|
VkDevice vkd3d_get_vk_device(ID3D12Device *device);
|
||||||
VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device);
|
VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device);
|
||||||
struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device);
|
struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device);
|
||||||
|
@ -1216,6 +1216,8 @@ static ULONG STDMETHODCALLTYPE d3d12_device_Release(ID3D12Device *iface)
|
|||||||
VK_CALL(vkDestroyPipelineCache(device->vk_device, device->vk_pipeline_cache, NULL));
|
VK_CALL(vkDestroyPipelineCache(device->vk_device, device->vk_pipeline_cache, NULL));
|
||||||
d3d12_device_destroy_vkd3d_queues(device);
|
d3d12_device_destroy_vkd3d_queues(device);
|
||||||
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
|
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
|
||||||
|
if (device->parent)
|
||||||
|
IUnknown_Release(device->parent);
|
||||||
vkd3d_instance_decref(device->vkd3d_instance);
|
vkd3d_instance_decref(device->vkd3d_instance);
|
||||||
|
|
||||||
vkd3d_free(device);
|
vkd3d_free(device);
|
||||||
@ -2174,6 +2176,9 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
|
|||||||
|
|
||||||
d3d12_device_init_pipeline_cache(device);
|
d3d12_device_init_pipeline_cache(device);
|
||||||
|
|
||||||
|
if ((device->parent = create_info->parent))
|
||||||
|
IUnknown_AddRef(device->parent);
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2199,6 +2204,13 @@ HRESULT d3d12_device_create(struct vkd3d_instance *instance,
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IUnknown *vkd3d_get_device_parent(ID3D12Device *device)
|
||||||
|
{
|
||||||
|
struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device);
|
||||||
|
|
||||||
|
return d3d12_device->parent;
|
||||||
|
}
|
||||||
|
|
||||||
VkDevice vkd3d_get_vk_device(ID3D12Device *device)
|
VkDevice vkd3d_get_vk_device(ID3D12Device *device)
|
||||||
{
|
{
|
||||||
struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device);
|
struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device);
|
||||||
|
@ -6,6 +6,7 @@ global:
|
|||||||
vkd3d_create_image_resource;
|
vkd3d_create_image_resource;
|
||||||
vkd3d_create_instance;
|
vkd3d_create_instance;
|
||||||
vkd3d_create_root_signature_deserializer;
|
vkd3d_create_root_signature_deserializer;
|
||||||
|
vkd3d_get_device_parent;
|
||||||
vkd3d_get_vk_device;
|
vkd3d_get_vk_device;
|
||||||
vkd3d_get_vk_format;
|
vkd3d_get_vk_format;
|
||||||
vkd3d_get_vk_physical_device;
|
vkd3d_get_vk_physical_device;
|
||||||
|
@ -666,6 +666,7 @@ struct d3d12_device
|
|||||||
vkd3d_create_thread_pfn create_thread;
|
vkd3d_create_thread_pfn create_thread;
|
||||||
vkd3d_join_thread_pfn join_thread;
|
vkd3d_join_thread_pfn join_thread;
|
||||||
|
|
||||||
|
IUnknown *parent;
|
||||||
LUID adapter_luid;
|
LUID adapter_luid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,13 @@
|
|||||||
#include "vkd3d_test.h"
|
#include "vkd3d_test.h"
|
||||||
#include <vkd3d.h>
|
#include <vkd3d.h>
|
||||||
|
|
||||||
|
static ULONG get_refcount(void *iface)
|
||||||
|
{
|
||||||
|
IUnknown *unk = iface;
|
||||||
|
IUnknown_AddRef(unk);
|
||||||
|
return IUnknown_Release(unk);
|
||||||
|
}
|
||||||
|
|
||||||
static ULONG resource_get_internal_refcount(ID3D12Resource *resource)
|
static ULONG resource_get_internal_refcount(ID3D12Resource *resource)
|
||||||
{
|
{
|
||||||
vkd3d_resource_incref(resource);
|
vkd3d_resource_incref(resource);
|
||||||
@ -561,6 +568,87 @@ static void test_adapter_luid(void)
|
|||||||
ok(!refcount, "Device has %u references left.\n", refcount);
|
ok(!refcount, "Device has %u references left.\n", refcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct parent
|
||||||
|
{
|
||||||
|
IUnknown IUnknown_iface;
|
||||||
|
LONG refcount;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct parent *parent_from_IUnknown(IUnknown *iface)
|
||||||
|
{
|
||||||
|
return CONTAINING_RECORD(iface, struct parent, IUnknown_iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT STDMETHODCALLTYPE parent_QueryInterface(IUnknown *iface,
|
||||||
|
REFIID iid, void **object)
|
||||||
|
{
|
||||||
|
if (IsEqualGUID(iid, &IID_IUnknown))
|
||||||
|
{
|
||||||
|
IUnknown_AddRef(iface);
|
||||||
|
*object = iface;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok(false, "Unexpected QueryInterface() call.\n");
|
||||||
|
return E_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ULONG STDMETHODCALLTYPE parent_AddRef(IUnknown *iface)
|
||||||
|
{
|
||||||
|
struct parent *parent = parent_from_IUnknown(iface);
|
||||||
|
|
||||||
|
return InterlockedIncrement(&parent->refcount);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ULONG STDMETHODCALLTYPE parent_Release(IUnknown *iface)
|
||||||
|
{
|
||||||
|
struct parent *parent = parent_from_IUnknown(iface);
|
||||||
|
|
||||||
|
return InterlockedDecrement(&parent->refcount);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct IUnknownVtbl parent_vtbl =
|
||||||
|
{
|
||||||
|
parent_QueryInterface,
|
||||||
|
parent_AddRef,
|
||||||
|
parent_Release,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void test_device_parent(void)
|
||||||
|
{
|
||||||
|
struct vkd3d_device_create_info create_info;
|
||||||
|
struct parent parent_impl;
|
||||||
|
ID3D12Device *device;
|
||||||
|
IUnknown *unknown;
|
||||||
|
IUnknown *parent;
|
||||||
|
ULONG refcount;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
parent_impl.IUnknown_iface.lpVtbl = &parent_vtbl;
|
||||||
|
parent_impl.refcount = 1;
|
||||||
|
parent = &parent_impl.IUnknown_iface;
|
||||||
|
|
||||||
|
refcount = get_refcount(parent);
|
||||||
|
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
|
||||||
|
|
||||||
|
create_info = device_default_create_info;
|
||||||
|
create_info.parent = parent;
|
||||||
|
hr = vkd3d_create_device(&create_info, &IID_ID3D12Device, (void **)&device);
|
||||||
|
ok(hr == S_OK, "Failed to create device, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
refcount = get_refcount(parent);
|
||||||
|
ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
|
||||||
|
|
||||||
|
unknown = vkd3d_get_device_parent(device);
|
||||||
|
ok(unknown == parent, "Got device parent %p, expected %p.\n", unknown, parent);
|
||||||
|
|
||||||
|
refcount = ID3D12Device_Release(device);
|
||||||
|
ok(!refcount, "Device has %u references left.\n", refcount);
|
||||||
|
|
||||||
|
refcount = get_refcount(parent);
|
||||||
|
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_vkd3d_queue(void)
|
static void test_vkd3d_queue(void)
|
||||||
{
|
{
|
||||||
ID3D12CommandQueue *direct_queue, *compute_queue, *copy_queue;
|
ID3D12CommandQueue *direct_queue, *compute_queue, *copy_queue;
|
||||||
@ -666,6 +754,7 @@ START_TEST(vkd3d_api)
|
|||||||
run_test(test_additional_device_extensions);
|
run_test(test_additional_device_extensions);
|
||||||
run_test(test_physical_device);
|
run_test(test_physical_device);
|
||||||
run_test(test_adapter_luid);
|
run_test(test_adapter_luid);
|
||||||
|
run_test(test_device_parent);
|
||||||
run_test(test_vkd3d_queue);
|
run_test(test_vkd3d_queue);
|
||||||
run_test(test_resource_internal_refcount);
|
run_test(test_resource_internal_refcount);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user