From afe725924205417420c4e13cf8c1ed0da66feceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 7 Jun 2019 14:38:03 +0200 Subject: [PATCH] vkd3d: Introduce helper functions to call ID3D12Device methods. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d/command.c | 60 ++++++++++++++++---------------------- libs/vkd3d/resource.c | 52 ++++++++++++++------------------- libs/vkd3d/state.c | 25 +++++++--------- libs/vkd3d/vkd3d_private.h | 21 +++++++++++++ 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index a4659f70..f66bbe90 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -885,7 +885,7 @@ static ULONG STDMETHODCALLTYPE d3d12_fence_Release(ID3D12Fence *iface) ERR("Failed to destroy mutex, error %d.\n", rc); vkd3d_free(fence); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -932,14 +932,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetName(ID3D12Fence *iface, const W return name ? S_OK : E_INVALIDARG; } -static HRESULT STDMETHODCALLTYPE d3d12_fence_GetDevice(ID3D12Fence *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_fence_GetDevice(ID3D12Fence *iface, REFIID iid, void **device) { struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&fence->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(fence->device, iid, device); } static UINT64 STDMETHODCALLTYPE d3d12_fence_GetCompletedValue(ID3D12Fence *iface) @@ -1081,8 +1080,7 @@ static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device * return hr; } - fence->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(fence->device = device); return S_OK; } @@ -1517,7 +1515,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo vkd3d_free(allocator); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -1563,14 +1561,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_SetName(ID3D12CommandAl VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, name); } -static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_GetDevice(ID3D12CommandAllocator *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_GetDevice(ID3D12CommandAllocator *iface, REFIID iid, void **device) { struct d3d12_command_allocator *allocator = impl_from_ID3D12CommandAllocator(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&allocator->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(allocator->device, iid, device); } static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_Reset(ID3D12CommandAllocator *iface) @@ -1727,8 +1724,7 @@ static HRESULT d3d12_command_allocator_init(struct d3d12_command_allocator *allo allocator->current_command_list = NULL; - allocator->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(allocator->device = device); return S_OK; } @@ -2132,7 +2128,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_list_Release(ID3D12GraphicsCommandL vkd3d_free(list); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -2177,14 +2173,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_list_SetName(ID3D12GraphicsComman return name ? S_OK : E_INVALIDARG; } -static HRESULT STDMETHODCALLTYPE d3d12_command_list_GetDevice(ID3D12GraphicsCommandList1 *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_command_list_GetDevice(ID3D12GraphicsCommandList1 *iface, REFIID iid, void **device) { struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList1(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&list->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(list->device, iid, device); } static D3D12_COMMAND_LIST_TYPE STDMETHODCALLTYPE d3d12_command_list_GetType(ID3D12GraphicsCommandList1 *iface) @@ -5118,8 +5113,7 @@ static HRESULT d3d12_command_list_init(struct d3d12_command_list *list, struct d if (FAILED(hr = vkd3d_private_store_init(&list->private_store))) return hr; - list->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(list->device = device); list->allocator = allocator; @@ -5130,7 +5124,7 @@ static HRESULT d3d12_command_list_init(struct d3d12_command_list *list, struct d else { vkd3d_private_store_destroy(&list->private_store); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return hr; @@ -5228,7 +5222,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_queue_Release(ID3D12CommandQueue *i vkd3d_free(command_queue); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -5284,14 +5278,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_queue_SetName(ID3D12CommandQueue return hr; } -static HRESULT STDMETHODCALLTYPE d3d12_command_queue_GetDevice(ID3D12CommandQueue *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_command_queue_GetDevice(ID3D12CommandQueue *iface, REFIID iid, void **device) { struct d3d12_command_queue *command_queue = impl_from_ID3D12CommandQueue(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&command_queue->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(command_queue->device, iid, device); } static void STDMETHODCALLTYPE d3d12_command_queue_UpdateTileMappings(ID3D12CommandQueue *iface, @@ -5713,8 +5706,7 @@ static HRESULT d3d12_command_queue_init(struct d3d12_command_queue *queue, if (FAILED(hr = vkd3d_private_store_init(&queue->private_store))) return hr; - queue->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(queue->device = device); return S_OK; } @@ -5816,7 +5808,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_signature_Release(ID3D12CommandSign vkd3d_free((void *)signature->desc.pArgumentDescs); vkd3d_free(signature); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -5861,14 +5853,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_signature_SetName(ID3D12CommandSi return name ? S_OK : E_INVALIDARG; } -static HRESULT STDMETHODCALLTYPE d3d12_command_signature_GetDevice(ID3D12CommandSignature *iface, - REFIID iid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_command_signature_GetDevice(ID3D12CommandSignature *iface, REFIID iid, void **device) { struct d3d12_command_signature *signature = impl_from_ID3D12CommandSignature(iface); TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&signature->device->ID3D12Device_iface, iid, device); + return d3d12_device_query_interface(signature->device, iid, device); } static const struct ID3D12CommandSignatureVtbl d3d12_command_signature_vtbl = @@ -5942,8 +5933,7 @@ HRESULT d3d12_command_signature_create(struct d3d12_device *device, const D3D12_ return hr; } - object->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(object->device = device); TRACE("Created command signature %p.\n", object); diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 1e5f5f3c..15dac12a 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -174,7 +174,7 @@ static ULONG STDMETHODCALLTYPE d3d12_heap_Release(ID3D12Heap *iface) vkd3d_free(heap); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -220,14 +220,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_heap_SetName(ID3D12Heap *iface, const WCH VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, name); } -static HRESULT STDMETHODCALLTYPE d3d12_heap_GetDevice(ID3D12Heap *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_heap_GetDevice(ID3D12Heap *iface, REFIID iid, void **device) { struct d3d12_heap *heap = impl_from_ID3D12Heap(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&heap->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(heap->device, iid, device); } static D3D12_HEAP_DESC * STDMETHODCALLTYPE d3d12_heap_GetDesc(ID3D12Heap *iface, @@ -416,8 +415,7 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap, return hr; } - heap->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(heap->device = device); return S_OK; } @@ -929,7 +927,7 @@ static ULONG STDMETHODCALLTYPE d3d12_resource_AddRef(ID3D12Resource *iface) { struct d3d12_device *device = resource->device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(device); d3d12_resource_incref(resource); } @@ -949,7 +947,7 @@ static ULONG STDMETHODCALLTYPE d3d12_resource_Release(ID3D12Resource *iface) d3d12_resource_decref(resource); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -1007,14 +1005,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_SetName(ID3D12Resource *iface, c VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, name); } -static HRESULT STDMETHODCALLTYPE d3d12_resource_GetDevice(ID3D12Resource *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_resource_GetDevice(ID3D12Resource *iface, REFIID iid, void **device) { struct d3d12_resource *resource = impl_from_ID3D12Resource(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&resource->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(resource->device, iid, device); } static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT sub_resource, @@ -1419,8 +1416,7 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12 return hr; } - resource->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(resource->device = device); return S_OK; } @@ -1627,8 +1623,7 @@ HRESULT vkd3d_create_image_resource(ID3D12Device *device, return hr; } - object->device = d3d12_device; - ID3D12Device_AddRef(&d3d12_device->ID3D12Device_iface); + d3d12_device_add_ref(object->device = d3d12_device); TRACE("Created resource %p.\n", object); @@ -2953,7 +2948,7 @@ static ULONG STDMETHODCALLTYPE d3d12_descriptor_heap_Release(ID3D12DescriptorHea vkd3d_free(heap); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -2998,14 +2993,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_descriptor_heap_SetName(ID3D12DescriptorH return name ? S_OK : E_INVALIDARG; } -static HRESULT STDMETHODCALLTYPE d3d12_descriptor_heap_GetDevice(ID3D12DescriptorHeap *iface, - REFIID riid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_descriptor_heap_GetDevice(ID3D12DescriptorHeap *iface, REFIID iid, void **device) { struct d3d12_descriptor_heap *heap = impl_from_ID3D12DescriptorHeap(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&heap->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(heap->device, iid, device); } static D3D12_DESCRIPTOR_HEAP_DESC * STDMETHODCALLTYPE d3d12_descriptor_heap_GetDesc(ID3D12DescriptorHeap *iface, @@ -3075,8 +3069,7 @@ static HRESULT d3d12_descriptor_heap_init(struct d3d12_descriptor_heap *descript if (FAILED(hr = vkd3d_private_store_init(&descriptor_heap->private_store))) return hr; - descriptor_heap->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(descriptor_heap->device = device); return S_OK; } @@ -3088,7 +3081,7 @@ HRESULT d3d12_descriptor_heap_create(struct d3d12_device *device, struct d3d12_descriptor_heap *object; HRESULT hr; - if (!(descriptor_size = ID3D12Device_GetDescriptorHandleIncrementSize(&device->ID3D12Device_iface, desc->Type))) + if (!(descriptor_size = d3d12_device_get_descriptor_handle_increment_size(device, desc->Type))) { WARN("No descriptor size for descriptor type %#x.\n", desc->Type); return E_INVALIDARG; @@ -3183,7 +3176,7 @@ static ULONG STDMETHODCALLTYPE d3d12_query_heap_Release(ID3D12QueryHeap *iface) vkd3d_free(heap); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -3229,14 +3222,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_query_heap_SetName(ID3D12QueryHeap *iface VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, name); } -static HRESULT STDMETHODCALLTYPE d3d12_query_heap_GetDevice(ID3D12QueryHeap *iface, - REFIID iid, void **device) +static HRESULT STDMETHODCALLTYPE d3d12_query_heap_GetDevice(ID3D12QueryHeap *iface, REFIID iid, void **device) { struct d3d12_query_heap *heap = impl_from_ID3D12QueryHeap(iface); TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&heap->device->ID3D12Device_iface, iid, device); + return d3d12_device_query_interface(heap->device, iid, device); } static const struct ID3D12QueryHeapVtbl d3d12_query_heap_vtbl = @@ -3345,7 +3337,7 @@ HRESULT d3d12_query_heap_create(struct d3d12_device *device, const D3D12_QUERY_H return hresult_from_vk_result(vr); } - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(device); TRACE("Created query heap %p.\n", object); diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index eb2626d1..514fdc3a 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -118,7 +118,7 @@ static ULONG STDMETHODCALLTYPE d3d12_root_signature_Release(ID3D12RootSignature vkd3d_private_store_destroy(&root_signature->private_store); d3d12_root_signature_cleanup(root_signature, device); vkd3d_free(root_signature); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -164,13 +164,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_root_signature_SetName(ID3D12RootSignatur } static HRESULT STDMETHODCALLTYPE d3d12_root_signature_GetDevice(ID3D12RootSignature *iface, - REFIID riid, void **device) + REFIID iid, void **device) { struct d3d12_root_signature *root_signature = impl_from_ID3D12RootSignature(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&root_signature->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(root_signature->device, iid, device); } static const struct ID3D12RootSignatureVtbl d3d12_root_signature_vtbl = @@ -982,8 +982,7 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa if (FAILED(hr = vkd3d_private_store_init(&root_signature->private_store))) goto fail; - root_signature->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(root_signature->device = device); return S_OK; @@ -1331,7 +1330,7 @@ static ULONG STDMETHODCALLTYPE d3d12_pipeline_state_Release(ID3D12PipelineState vkd3d_free(state); - ID3D12Device_Release(&device->ID3D12Device_iface); + d3d12_device_release(device); } return refcount; @@ -1383,13 +1382,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_pipeline_state_SetName(ID3D12PipelineStat } static HRESULT STDMETHODCALLTYPE d3d12_pipeline_state_GetDevice(ID3D12PipelineState *iface, - REFIID riid, void **device) + REFIID iid, void **device) { struct d3d12_pipeline_state *state = impl_from_ID3D12PipelineState(iface); - TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device); + TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device); - return ID3D12Device_QueryInterface(&state->device->ID3D12Device_iface, riid, device); + return d3d12_device_query_interface(state->device, iid, device); } static HRESULT STDMETHODCALLTYPE d3d12_pipeline_state_GetCachedBlob(ID3D12PipelineState *iface, @@ -1646,8 +1645,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st } state->vk_bind_point = VK_PIPELINE_BIND_POINT_COMPUTE; - state->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(state->device = device); return S_OK; } @@ -2550,8 +2548,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s goto fail; state->vk_bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS; - state->device = device; - ID3D12Device_AddRef(&device->ID3D12Device_iface); + d3d12_device_add_ref(state->device = device); return S_OK; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 2d31cacc..e01e0050 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1036,6 +1036,27 @@ void d3d12_device_mark_as_removed(struct d3d12_device *device, HRESULT reason, const char *message, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; struct d3d12_device *unsafe_impl_from_ID3D12Device(ID3D12Device *iface) DECLSPEC_HIDDEN; +static inline HRESULT d3d12_device_query_interface(struct d3d12_device *device, REFIID iid, void **object) +{ + return ID3D12Device_QueryInterface(&device->ID3D12Device_iface, iid, object); +} + +static inline ULONG d3d12_device_add_ref(struct d3d12_device *device) +{ + return ID3D12Device_AddRef(&device->ID3D12Device_iface); +} + +static inline ULONG d3d12_device_release(struct d3d12_device *device) +{ + return ID3D12Device_Release(&device->ID3D12Device_iface); +} + +static inline unsigned int d3d12_device_get_descriptor_handle_increment_size(struct d3d12_device *device, + D3D12_DESCRIPTOR_HEAP_TYPE descriptor_type) +{ + return ID3D12Device_GetDescriptorHandleIncrementSize(&device->ID3D12Device_iface, descriptor_type); +} + /* utils */ struct vkd3d_format {