diff options
author | Michael Bien <[email protected]> | 2011-05-12 04:05:23 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-05-12 04:05:23 +0200 |
commit | 9159e65a631af39942579cf2258fc20aab4814e5 (patch) | |
tree | 7b42a72bc723e04c5e7e368245cbf50ed556dfa0 /src/com/jogamp/opencl/CLInfoAccessor.java | |
parent | d9066dda35bc633f8b910ab56b8cbcfff61e6662 (diff) |
moved all cl calls to CLInfoAccessor (CLDevice and CLPlatform).
Diffstat (limited to 'src/com/jogamp/opencl/CLInfoAccessor.java')
-rw-r--r-- | src/com/jogamp/opencl/CLInfoAccessor.java | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLInfoAccessor.java index 5f6694b2..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.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,15 +44,17 @@ 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<NativeSizeBuffer> localPB = new ThreadLocal<NativeSizeBuffer>() { + protected final static ThreadLocal<NativeSizeBuffer> localNSB = new ThreadLocal<NativeSizeBuffer>() { @Override protected NativeSizeBuffer initialValue() { @@ -62,7 +65,7 @@ abstract class CLInfoAccessor { 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(); - NativeSizeBuffer 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,6 +91,37 @@ abstract class CLInfoAccessor { } + 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); |