Skip to content

Commit

Permalink
possible fix for multithreaded NV_DX_interop on radeon
Browse files Browse the repository at this point in the history
add threadid to identify open devices
  • Loading branch information
redrezo committed Jan 7, 2021
1 parent 596fed9 commit d2333f6
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ public class NVDXInteropDevice {
public final Win32.HANDLE hDevice;
private Win32.IDirect3DDevice9Ex dxDevice;
private long glContext;
private long threadId;

private NVDXInteropDevice(Win32.HANDLE hDevice) {
this.hDevice = hDevice;
}

@Override
public String toString() {
return "NVDXInteropDevice " + hDevice + " / " + dxDevice + " / " + glContext;
return "NVDXInteropDevice " + hDevice + " / " + dxDevice + " / " + glContext + " / " + threadId;
}

private int usageCount = 0;
Expand All @@ -44,16 +45,21 @@ public String toString() {

public static NVDXInteropDevice openDevice(Win32.IDirect3DDevice9Ex dxDevice) throws WindowsError {
synchronized (devices) {
long threadId = Thread.currentThread().getId();
long glContext = GL.getCurrentContext();
NVDXInteropDevice device = null;
Optional<NVDXInteropDevice> existing = devices.stream().filter(dev -> dev.glContext == glContext && dev.dxDevice.address == dxDevice.address).findFirst();
Optional<NVDXInteropDevice> existing = devices.stream().filter(dev ->
dev.glContext == glContext &&
dev.dxDevice.address == dxDevice.address &&
dev.threadId == threadId).findFirst();
if (existing.isPresent()) {
device = existing.get();
}
else {
device = new NVDXInteropDevice(NVDXInterop.wglDXOpenDeviceNV(dxDevice));
device.glContext = glContext;
device.dxDevice = dxDevice;
device.threadId = threadId;
devices.add(device);
}

Expand All @@ -69,7 +75,6 @@ public static NVDXInteropDevice openDevice(Win32.IDirect3DDevice9Ex dxDevice) th
public void closeDevice() throws WindowsError {
synchronized (devices) {
usageCount--;

if (usageCount == 0) {
NVDXInterop.wglDXCloseDeviceNV(hDevice);
devices.remove(this);
Expand Down

0 comments on commit d2333f6

Please sign in to comment.