From a5e13cf53ec2dc47e831739bb1764143a4e9d63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Wed, 5 Oct 2016 15:56:27 +0200 Subject: [PATCH] libs/vkd3d: Implement d3d12_fence_Signal(). --- libs/vkd3d/command.c | 41 ++++++++++++++++++++++++++++++++++---- libs/vkd3d/vkd3d_private.h | 2 ++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index a359827e..f4d68a59 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -65,6 +65,7 @@ static ULONG STDMETHODCALLTYPE d3d12_fence_Release(ID3D12Fence *iface) { struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); ULONG refcount = InterlockedDecrement(&fence->refcount); + int rc; TRACE("%p decreasing refcount to %u.\n", fence, refcount); @@ -72,6 +73,8 @@ static ULONG STDMETHODCALLTYPE d3d12_fence_Release(ID3D12Fence *iface) { struct d3d12_device *device = fence->device; + if ((rc = pthread_mutex_destroy(&fence->mutex))) + ERR("Failed to destroy mutex, error %d.\n", rc); vkd3d_free(fence); ID3D12Device_Release(&device->ID3D12Device_iface); @@ -126,10 +129,19 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_GetDevice(ID3D12Fence *iface, static UINT64 STDMETHODCALLTYPE d3d12_fence_GetCompletedValue(ID3D12Fence *iface) { struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); + UINT64 completed_value; + int rc; TRACE("iface %p.\n", iface); - return fence->value; + if ((rc = pthread_mutex_lock(&fence->mutex))) + { + ERR("Failed to lock mutex, error %d.\n", rc); + return 0; + } + completed_value = fence->value; + pthread_mutex_unlock(&fence->mutex); + return completed_value; } static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *iface, @@ -142,9 +154,20 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *i static HRESULT STDMETHODCALLTYPE d3d12_fence_Signal(ID3D12Fence *iface, UINT64 value) { - FIXME("iface %p, value %s stub!\n", iface, debugstr_uint64(value)); + struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); + int rc; - return E_NOTIMPL; + TRACE("iface %p, value %s.\n", iface, debugstr_uint64(value)); + + if ((rc = pthread_mutex_lock(&fence->mutex))) + { + ERR("Failed to lock mutex, error %d.\n", rc); + return E_FAIL; + } + fence->value = value; + pthread_mutex_unlock(&fence->mutex); + + return S_OK; } static const struct ID3D12FenceVtbl d3d12_fence_vtbl = @@ -166,19 +189,29 @@ static const struct ID3D12FenceVtbl d3d12_fence_vtbl = d3d12_fence_Signal, }; -static void d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device *device, +static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device *device, UINT64 initial_value, D3D12_FENCE_FLAGS flags) { + int rc; + fence->ID3D12Fence_iface.lpVtbl = &d3d12_fence_vtbl; fence->refcount = 1; fence->value = initial_value; + if ((rc = pthread_mutex_init(&fence->mutex, NULL))) + { + ERR("Failed to initialize mutex, error %d.\n", rc); + return E_FAIL; + } + if (flags) FIXME("Ignoring flags %#x.\n", flags); fence->device = device; ID3D12Device_AddRef(&device->ID3D12Device_iface); + + return S_OK; } HRESULT d3d12_fence_create(struct d3d12_device *device, diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 000d39c1..78694e93 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -32,6 +32,7 @@ #include "d3d12.h" #include +#include #define VKD3D_DESCRIPTOR_MAGIC_FREE 0x00000000u #define VKD3D_DESCRIPTOR_MAGIC_RTV 0x00565452u @@ -52,6 +53,7 @@ struct d3d12_fence ULONG refcount; UINT64 value; + pthread_mutex_t mutex; struct d3d12_device *device; };