vkd3d: Implement private data for command queues.

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:
Józef Kucia 2019-01-03 14:23:01 +01:00 committed by Alexandre Julliard
parent 49e55dd639
commit d18360a8b7
5 changed files with 308 additions and 6 deletions

View File

@ -48,6 +48,9 @@ typedef int HRESULT;
# define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000E)
# define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057)
# define DXGI_ERROR_NOT_FOUND _HRESULT_TYPEDEF_(0x887a0002)
# define DXGI_ERROR_MORE_DATA _HRESULT_TYPEDEF_(0x887a0003)
/* Basic types */
typedef unsigned char BYTE;
typedef unsigned int DWORD;

View File

@ -4360,6 +4360,8 @@ static ULONG STDMETHODCALLTYPE d3d12_command_queue_Release(ID3D12CommandQueue *i
{
struct d3d12_device *device = command_queue->device;
vkd3d_private_store_destroy(&command_queue->private_store);
vkd3d_free(command_queue);
ID3D12Device_Release(&device->ID3D12Device_iface);
@ -4371,25 +4373,31 @@ static ULONG STDMETHODCALLTYPE d3d12_command_queue_Release(ID3D12CommandQueue *i
static HRESULT STDMETHODCALLTYPE d3d12_command_queue_GetPrivateData(ID3D12CommandQueue *iface,
REFGUID guid, UINT *data_size, void *data)
{
FIXME("iface %p, guid %s, data_size %p, data %p stub!", iface, debugstr_guid(guid), data_size, data);
struct d3d12_command_queue *command_queue = impl_from_ID3D12CommandQueue(iface);
return E_NOTIMPL;
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
return vkd3d_get_private_data(&command_queue->private_store, guid, data_size, data);
}
static HRESULT STDMETHODCALLTYPE d3d12_command_queue_SetPrivateData(ID3D12CommandQueue *iface,
REFGUID guid, UINT data_size, const void *data)
{
FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
struct d3d12_command_queue *command_queue = impl_from_ID3D12CommandQueue(iface);
return E_NOTIMPL;
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
return vkd3d_set_private_data(&command_queue->private_store, guid, data_size, data);
}
static HRESULT STDMETHODCALLTYPE d3d12_command_queue_SetPrivateDataInterface(ID3D12CommandQueue *iface,
REFGUID guid, const IUnknown *data)
{
FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
struct d3d12_command_queue *command_queue = impl_from_ID3D12CommandQueue(iface);
return E_NOTIMPL;
TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
return vkd3d_set_private_data_interface(&command_queue->private_store, guid, data);
}
static HRESULT STDMETHODCALLTYPE d3d12_command_queue_SetName(ID3D12CommandQueue *iface, const WCHAR *name)
@ -4673,6 +4681,8 @@ static HRESULT d3d12_command_queue_init(struct d3d12_command_queue *queue,
if (desc->Flags)
FIXME("Ignoring flags %#x.\n", desc->Flags);
vkd3d_private_store_init(&queue->private_store);
queue->device = device;
ID3D12Device_AddRef(&device->ID3D12Device_iface);

View File

@ -506,3 +506,103 @@ HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs,
TRACE("Loaded procs for VkDevice %p.\n", device);
return S_OK;
}
static struct vkd3d_private_data *vkd3d_private_store_get_private_data(
const struct vkd3d_private_store *store, const GUID *tag)
{
struct vkd3d_private_data *data;
LIST_FOR_EACH_ENTRY(data, &store->content, struct vkd3d_private_data, entry)
{
if (IsEqualGUID(&data->tag, tag))
return data;
}
return NULL;
}
static HRESULT vkd3d_private_store_set_private_data(struct vkd3d_private_store *store,
const GUID *tag, const void *data, unsigned int data_size, bool is_object)
{
struct vkd3d_private_data *d, *old_data;
const void *ptr = data;
if (is_object)
{
if (data_size != sizeof(IUnknown *))
return E_INVALIDARG;
ptr = &data;
}
if (!(d = vkd3d_malloc(offsetof(struct vkd3d_private_data, u.data[data_size]))))
return E_OUTOFMEMORY;
d->tag = *tag;
d->size = data_size;
d->is_object = is_object;
memcpy(d->u.data, ptr, data_size);
if (is_object)
IUnknown_AddRef(d->u.object);
if ((old_data = vkd3d_private_store_get_private_data(store, tag)))
vkd3d_private_data_destroy(old_data);
list_add_tail(&store->content, &d->entry);
return S_OK;
}
HRESULT vkd3d_get_private_data(struct vkd3d_private_store *store,
const GUID *tag, unsigned int *out_size, void *out)
{
const struct vkd3d_private_data *data;
unsigned int size;
if (!out_size)
return E_INVALIDARG;
if (!(data = vkd3d_private_store_get_private_data(store, tag)))
{
*out_size = 0;
return DXGI_ERROR_NOT_FOUND;
}
size = *out_size;
*out_size = data->size;
if (!out)
return S_OK;
if (size < data->size)
return DXGI_ERROR_MORE_DATA;
if (data->is_object)
IUnknown_AddRef(data->u.object);
memcpy(out, data->u.data, data->size);
return S_OK;
}
HRESULT vkd3d_set_private_data(struct vkd3d_private_store *store,
const GUID *tag, unsigned int data_size, const void *data)
{
struct vkd3d_private_data *d;
if (!data)
{
if (!(d = vkd3d_private_store_get_private_data(store, tag)))
return S_FALSE;
vkd3d_private_data_destroy(d);
return S_OK;
}
return vkd3d_private_store_set_private_data(store, tag, data, data_size, false);
}
HRESULT vkd3d_set_private_data_interface(struct vkd3d_private_store *store,
const GUID *tag, const IUnknown *object)
{
if (!object)
return vkd3d_set_private_data(store, tag, sizeof(object), &object);
return vkd3d_private_store_set_private_data(store, tag, object, sizeof(object), true);
}

View File

@ -163,6 +163,55 @@ void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocato
void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator,
D3D12_GPU_VIRTUAL_ADDRESS address) DECLSPEC_HIDDEN;
struct vkd3d_private_store
{
struct list content;
};
struct vkd3d_private_data
{
struct list entry;
GUID tag;
unsigned int size;
bool is_object;
union
{
BYTE data[1];
IUnknown *object;
} u;
};
static inline void vkd3d_private_data_destroy(struct vkd3d_private_data *data)
{
if (data->is_object)
IUnknown_Release(data->u.object);
list_remove(&data->entry);
vkd3d_free(data);
}
static inline void vkd3d_private_store_init(struct vkd3d_private_store *store)
{
list_init(&store->content);
}
static inline void vkd3d_private_store_destroy(struct vkd3d_private_store *store)
{
struct vkd3d_private_data *data, *cursor;
LIST_FOR_EACH_ENTRY_SAFE(data, cursor, &store->content, struct vkd3d_private_data, entry)
{
vkd3d_private_data_destroy(data);
}
}
HRESULT vkd3d_get_private_data(struct vkd3d_private_store *store,
const GUID *tag, unsigned int *out_size, void *out) DECLSPEC_HIDDEN;
HRESULT vkd3d_set_private_data(struct vkd3d_private_store *store,
const GUID *tag, unsigned int data_size, const void *data) DECLSPEC_HIDDEN;
HRESULT vkd3d_set_private_data_interface(struct vkd3d_private_store *store,
const GUID *tag, const IUnknown *object) DECLSPEC_HIDDEN;
/* ID3D12Fence */
struct d3d12_fence
{
@ -744,6 +793,8 @@ struct d3d12_command_queue
struct vkd3d_queue *vkd3d_queue;
struct d3d12_device *device;
struct vkd3d_private_store private_store;
};
HRESULT d3d12_command_queue_create(struct d3d12_device *device,

View File

@ -2557,6 +2557,143 @@ static void test_create_fence(void)
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
}
static void test_private_data(void)
{
D3D12_COMMAND_QUEUE_DESC queue_desc;
ULONG refcount, expected_refcount;
ID3D12CommandQueue *queue;
IUnknown *test_object;
ID3D12Device *device;
ID3D12Object *object;
unsigned int size;
IUnknown *ptr;
HRESULT hr;
static const GUID test_guid
= {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
static const GUID test_guid2
= {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
static const DWORD data[] = {1, 2, 3, 4};
if (!(device = create_device()))
{
skip("Failed to create device.\n");
return;
}
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queue_desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queue_desc.NodeMask = 0;
hr = ID3D12Device_CreateCommandQueue(device, &queue_desc, &IID_ID3D12CommandQueue, (void **)&queue);
ok(hr == S_OK, "Failed to create command queue, hr %#x.\n", hr);
hr = ID3D12CommandQueue_QueryInterface(queue, &IID_ID3D12Object, (void **)&object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ID3D12CommandQueue_Release(queue);
hr = ID3D12Object_SetPrivateData(object, &test_guid, 0, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateData(object, &test_guid, ~0u, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateData(object, &test_guid, ~0u, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
size = sizeof(ptr) * 2;
ptr = (IUnknown *)0xdeadbeef;
hr = ID3D12Object_GetPrivateData(object, &test_guid, &size, &ptr);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(!ptr, "Got unexpected pointer %p.\n", ptr);
ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
hr = ID3D12Device_CreateFence(device, 0, D3D12_FENCE_FLAG_NONE,
&IID_ID3D12Fence, (void **)&test_object);
ok(hr == S_OK, "Failed to create fence, hr %#x.\n", hr);
refcount = get_refcount(test_object);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, (IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
expected_refcount = refcount + 1;
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, (IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
--expected_refcount;
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, (IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
size = sizeof(data);
hr = ID3D12Object_SetPrivateData(object, &test_guid, size, data);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
hr = ID3D12Object_SetPrivateData(object, &test_guid, 42, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateData(object, &test_guid, 42, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = ID3D12Object_SetPrivateDataInterface(object, &test_guid, (IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
++expected_refcount;
size = 2 * sizeof(ptr);
ptr = NULL;
hr = ID3D12Object_GetPrivateData(object, &test_guid, &size, &ptr);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
++expected_refcount;
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
IUnknown_Release(ptr);
--expected_refcount;
ptr = (IUnknown *)0xdeadbeef;
size = 1;
hr = ID3D12Object_GetPrivateData(object, &test_guid, &size, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(ptr), "Got unexpected size %u.\n", size);
size = 2 * sizeof(ptr);
hr = ID3D12Object_GetPrivateData(object, &test_guid, &size, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(ptr), "Got unexpected size %u.\n", size);
refcount = get_refcount(test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
(unsigned int)refcount, (unsigned int)expected_refcount);
size = 1;
hr = ID3D12Object_GetPrivateData(object, &test_guid, &size, &ptr);
ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(object), "Got unexpected size %u.\n", size);
ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
size = 1;
hr = ID3D12Object_GetPrivateData(object, &test_guid2, &size, &ptr);
ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
ok(!size, "Got unexpected size %u.\n", size);
ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
ID3D12Object_Release(object);
refcount = IUnknown_Release(test_object);
ok(!refcount, "Test object has %u references left.\n", (unsigned int)refcount);
refcount = ID3D12Device_Release(device);
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
}
static void test_reset_command_allocator(void)
{
ID3D12CommandAllocator *command_allocator, *command_allocator2;
@ -22054,6 +22191,7 @@ START_TEST(d3d12)
run_test(test_create_compute_pipeline_state);
run_test(test_create_graphics_pipeline_state);
run_test(test_create_fence);
run_test(test_private_data);
run_test(test_reset_command_allocator);
run_test(test_cpu_signal_fence);
run_test(test_gpu_signal_fence);