diff options
author | Sven Gothel <[email protected]> | 2011-05-18 03:51:10 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-05-18 03:51:10 +0200 |
commit | 773060662ef81707f70c447b71e664635ac45e2a (patch) | |
tree | f52c9e24b80902b08422005192df5b525f85489b /src/com/jogamp/opencl/CLInfoAccessor.java | |
parent | eceed6e10c7d6cb19e8ad3c1bf5ea20450d6fae1 (diff) | |
parent | f12e3a9d7ac644abc98a51dc51786cf7c5b67851 (diff) |
resolve conflicts
Diffstat (limited to 'src/com/jogamp/opencl/CLInfoAccessor.java')
-rw-r--r-- | src/com/jogamp/opencl/CLInfoAccessor.java | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLInfoAccessor.java index 08f8d8a2..08d7305e 100644 --- a/src/com/jogamp/opencl/CLInfoAccessor.java +++ b/src/com/jogamp/opencl/CLInfoAccessor.java @@ -28,12 +28,13 @@ package com.jogamp.opencl; -import com.jogamp.common.nio.Buffers; -import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.nio.NativeSizeBuffer; +import com.jogamp.common.os.Platform; import com.jogamp.opencl.util.CLUtil; import java.nio.Buffer; import java.nio.ByteBuffer; +import static com.jogamp.common.nio.Buffers.*; import static com.jogamp.opencl.CLException.*; /** @@ -43,26 +44,28 @@ import static com.jogamp.opencl.CLException.*; */ abstract class CLInfoAccessor { + private static final int BB_SIZE = 512; + protected final static ThreadLocal<ByteBuffer> localBB = new ThreadLocal<ByteBuffer>() { @Override protected ByteBuffer initialValue() { - return Buffers.newDirectByteBuffer(512); + return newDirectByteBuffer(BB_SIZE); } }; - protected final static ThreadLocal<PointerBuffer> localPB = new ThreadLocal<PointerBuffer>() { + protected final static ThreadLocal<NativeSizeBuffer> localNSB = new ThreadLocal<NativeSizeBuffer>() { @Override - protected PointerBuffer initialValue() { - return PointerBuffer.allocateDirect(1); + protected NativeSizeBuffer initialValue() { + return NativeSizeBuffer.allocateDirect(1); } }; public final long getLong(int key) { - ByteBuffer buffer = localBB.get(); + ByteBuffer buffer = getBB(8).putLong(0, 0); int ret = getInfo(key, 8, buffer, null); checkForError(ret, "error while asking for info value"); @@ -71,12 +74,16 @@ abstract class CLInfoAccessor { public final String getString(int key) { - ByteBuffer buffer = localBB.get(); - PointerBuffer sizeBuffer = localPB.get(); - int ret = getInfo(key, buffer.capacity(), buffer, sizeBuffer); + NativeSizeBuffer sizeBuffer = getNSB(); + int ret = getInfo(key, 0, null, sizeBuffer); checkForError(ret, "error while asking for info string"); int clSize = (int)sizeBuffer.get(0); + ByteBuffer buffer = getBB(clSize); + + ret = getInfo(key, buffer.capacity(), buffer, null); + checkForError(ret, "error while asking for info string"); + byte[] array = new byte[clSize]; buffer.get(array).rewind(); @@ -84,7 +91,38 @@ abstract class CLInfoAccessor { } - protected abstract int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet); + public final int[] getInts(int key, int n) { + + ByteBuffer buffer = getBB(n * (Platform.is32Bit()?4:8)); + int ret = getInfo(key, buffer.capacity(), buffer, null); + checkForError(ret, "error while asking for info value"); + + int[] array = new int[n]; + for(int i = 0; i < array.length; i++) { + if(Platform.is32Bit()) { + array[i] = buffer.getInt(); + }else{ + array[i] = (int)buffer.getLong(); + } + } + buffer.rewind(); + + return array; + } + + protected ByteBuffer getBB(int minCapacity) { + if(minCapacity > BB_SIZE) { + return newDirectByteBuffer(minCapacity); + }else{ + return localBB.get(); + } + } + + protected NativeSizeBuffer getNSB() { + return localNSB.get(); + } + + protected abstract int getInfo(int name, long valueSize, Buffer value, NativeSizeBuffer valueSizeRet); } |