|
@@ -2222,22 +2222,26 @@ extern "C" EXPORT uint32_t device_texture_get_shared_handle(gs_texture_t *tex)
|
|
|
return tex2d->isShared ? tex2d->sharedHandle : GS_INVALID_HANDLE;
|
|
|
}
|
|
|
|
|
|
-extern "C" EXPORT int device_texture_acquire_sync(gs_texture_t *tex,
|
|
|
- uint64_t key, uint32_t ms)
|
|
|
+int device_texture_acquire_sync(gs_texture_t *tex, uint64_t key, uint32_t ms)
|
|
|
{
|
|
|
gs_texture_2d *tex2d = reinterpret_cast<gs_texture_2d *>(tex);
|
|
|
if (tex->type != GS_TEXTURE_2D)
|
|
|
return -1;
|
|
|
|
|
|
+ if (tex2d->acquired)
|
|
|
+ return 0;
|
|
|
+
|
|
|
ComQIPtr<IDXGIKeyedMutex> keyedMutex(tex2d->texture);
|
|
|
if (!keyedMutex)
|
|
|
return -1;
|
|
|
|
|
|
HRESULT hr = keyedMutex->AcquireSync(key, ms);
|
|
|
- if (hr == S_OK)
|
|
|
+ if (hr == S_OK) {
|
|
|
+ tex2d->acquired = true;
|
|
|
return 0;
|
|
|
- else if (hr == WAIT_TIMEOUT)
|
|
|
+ } else if (hr == WAIT_TIMEOUT) {
|
|
|
return ETIMEDOUT;
|
|
|
+ }
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
@@ -2249,12 +2253,20 @@ extern "C" EXPORT int device_texture_release_sync(gs_texture_t *tex,
|
|
|
if (tex->type != GS_TEXTURE_2D)
|
|
|
return -1;
|
|
|
|
|
|
+ if (!tex2d->acquired)
|
|
|
+ return 0;
|
|
|
+
|
|
|
ComQIPtr<IDXGIKeyedMutex> keyedMutex(tex2d->texture);
|
|
|
if (!keyedMutex)
|
|
|
return -1;
|
|
|
|
|
|
HRESULT hr = keyedMutex->ReleaseSync(key);
|
|
|
- return hr == S_OK ? 0 : -1;
|
|
|
+ if (hr == S_OK) {
|
|
|
+ tex2d->acquired = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
extern "C" EXPORT bool device_texture_create_nv12(gs_device_t *device,
|