summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/CLInfoAccessor.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/jogamp/opencl/CLInfoAccessor.java')
-rw-r--r--src/com/jogamp/opencl/CLInfoAccessor.java60
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);
}