aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/jogamp/opencl/CLKernel.java40
-rw-r--r--test/com/jogamp/opencl/CLProgramTest.java7
2 files changed, 45 insertions, 2 deletions
diff --git a/src/com/jogamp/opencl/CLKernel.java b/src/com/jogamp/opencl/CLKernel.java
index 57ef316..8a3a44b 100644
--- a/src/com/jogamp/opencl/CLKernel.java
+++ b/src/com/jogamp/opencl/CLKernel.java
@@ -110,6 +110,12 @@ public class CLKernel extends CLObjectResource implements Cloneable {
return this;
}
+ public CLKernel putArg(short value) {
+ setArg(argIndex, value);
+ argIndex++;
+ return this;
+ }
+
public CLKernel putArg(int value) {
setArg(argIndex, value);
argIndex++;
@@ -171,6 +177,11 @@ public class CLKernel extends CLObjectResource implements Cloneable {
return this;
}
+ public CLKernel setArg(int argumentIndex, short value) {
+ setArgument(argumentIndex, 2, wrap(value));
+ return this;
+ }
+
public CLKernel setArg(int argumentIndex, int value) {
setArgument(argumentIndex, 4, wrap(value));
return this;
@@ -209,6 +220,31 @@ public class CLKernel extends CLObjectResource implements Cloneable {
return this;
}
+ public CLKernel setArgs(Object... values) {
+ if(values == null || values.length == 0) {
+ throw new IllegalArgumentException("values array was empty or null.");
+ }
+ for (int i = 0; i < values.length; i++) {
+ Object value = values[i];
+ if(value instanceof CLMemory<?>) {
+ setArg(i, (CLMemory<?>)value);
+ }else if(value instanceof Short) {
+ setArg(i, (Short)value);
+ }else if(value instanceof Integer) {
+ setArg(i, (Integer)value);
+ }else if(value instanceof Long) {
+ setArg(i, (Long)value);
+ }else if(value instanceof Float) {
+ setArg(i, (Float)value);
+ }else if(value instanceof Double) {
+ setArg(i, (Double)value);
+ }else{
+ throw new IllegalArgumentException(value + " is not a valid argument.");
+ }
+ }
+ return this;
+ }
+
private void setArgs(int startIndex, CLMemory<?>... values) {
for (int i = 0; i < values.length; i++) {
setArg(i+startIndex, values[i]);
@@ -259,6 +295,10 @@ public class CLKernel extends CLObjectResource implements Cloneable {
return buffer.putDouble(0, value);
}
+ private Buffer wrap(short value) {
+ return buffer.putShort(0, value);
+ }
+
private Buffer wrap(int value) {
return buffer.putInt(0, value);
}
diff --git a/test/com/jogamp/opencl/CLProgramTest.java b/test/com/jogamp/opencl/CLProgramTest.java
index 4d3b0cf..d083c77 100644
--- a/test/com/jogamp/opencl/CLProgramTest.java
+++ b/test/com/jogamp/opencl/CLProgramTest.java
@@ -270,7 +270,7 @@ public class CLProgramTest {
@Test
public void kernelTest() {
- String source = "__attribute__((reqd_work_group_size(1, 1, 1))) kernel void foo(float a, int b) { }\n";
+ String source = "__attribute__((reqd_work_group_size(1, 1, 1))) kernel void foo(float a, int b, short c) { }\n";
CLContext context = CLContext.create();
@@ -297,13 +297,16 @@ public class CLProgramTest {
kernel.putArg(2);
assertEquals(2, kernel.position());
+
+ kernel.putArg((short)3);
+ assertEquals(3, kernel.position());
try{
kernel.putArg(3);
fail("exception not thrown");
}catch (IndexOutOfBoundsException expected){ }
- assertEquals(2, kernel.position());
+ assertEquals(3, kernel.position());
assertEquals(0, kernel.rewind().position());
}finally{