Search in sources :

Example 11 with PointerBuffer

use of org.lwjgl.PointerBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglProgram method build.

@Override
public void build(String args, Device... devices) throws KernelCompilationException {
    PointerBuffer deviceList = null;
    if (devices != null) {
        deviceList = PointerBuffer.allocateDirect(devices.length);
        deviceList.rewind();
        for (Device d : devices) {
            deviceList.put(((LwjglDevice) d).getDevice());
        }
        deviceList.flip();
    }
    int ret = CL10.clBuildProgram(program, deviceList, args, null, 0);
    if (ret != CL10.CL_SUCCESS) {
        String log = Log();
        LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log);
        if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) {
            throw new KernelCompilationException("Failed to build program", ret, log);
        } else {
            Utils.checkError(ret, "clBuildProgram");
        }
    } else {
        LOG.log(Level.INFO, "Program compiled:\n{0}", Log());
    }
}
Also used : PointerBuffer(org.lwjgl.PointerBuffer)

Example 12 with PointerBuffer

use of org.lwjgl.PointerBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglPlatform method getDevices.

/**
     * Returns a list of the available devices on this platform that match the
     * specified type, filtered by the specified filter.
     * 
     * Copied from the old release.
     *
     * @param device_type the device type
     * @param filter the device filter
     *
     * @return the available devices
     */
private long[] getDevices(int device_type) {
    int[] count = new int[1];
    int errcode = CL10.clGetDeviceIDs(platform, device_type, null, count);
    if (errcode == CL10.CL_DEVICE_NOT_FOUND) {
        return new long[0];
    }
    Utils.checkError(errcode, "clGetDeviceIDs");
    int num_devices = count[0];
    if (num_devices == 0) {
        return new long[0];
    }
    PointerBuffer devices = PointerBuffer.allocateDirect(num_devices);
    errcode = CL10.clGetDeviceIDs(platform, device_type, devices, (IntBuffer) null);
    Utils.checkError(errcode, "clGetDeviceIDs");
    long[] deviceIDs = new long[num_devices];
    devices.rewind();
    for (int i = 0; i < num_devices; i++) {
        deviceIDs[i] = devices.get();
    }
    return deviceIDs;
}
Also used : IntBuffer(java.nio.IntBuffer) PointerBuffer(org.lwjgl.PointerBuffer)

Example 13 with PointerBuffer

use of org.lwjgl.PointerBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglProgram method getBinary.

@Override
public ByteBuffer getBinary(Device d) {
    //throw new UnsupportedOperationException("Not supported yet, would crash the JVM");
    LwjglDevice device = (LwjglDevice) d;
    int numDevices = Info.clGetProgramInfoInt(program, CL10.CL_PROGRAM_NUM_DEVICES);
    PointerBuffer devices = PointerBuffer.allocateDirect(numDevices);
    int ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_DEVICES, devices, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_DEVICES");
    int index = -1;
    for (int i = 0; i < numDevices; ++i) {
        if (devices.get(i) == device.getDevice()) {
            index = i;
        }
    }
    if (index == -1) {
        throw new com.jme3.opencl.OpenCLException("Program was not built against the specified device " + device);
    }
    PointerBuffer sizes = PointerBuffer.allocateDirect(numDevices);
    ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARY_SIZES, sizes, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARY_SIZES");
    int size = (int) sizes.get(index);
    PointerBuffer binaryPointers = PointerBuffer.allocateDirect(numDevices);
    for (int i = 0; i < binaryPointers.capacity(); ++i) {
        binaryPointers.put(0L);
    }
    binaryPointers.rewind();
    ByteBuffer binaries = ByteBuffer.allocateDirect(size);
    binaryPointers.put(index, binaries);
    //Fixme: why the hell does this line throw a segfault ?!?
    ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null);
    Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES");
    return binaries;
}
Also used : PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 14 with PointerBuffer

use of org.lwjgl.PointerBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglProgram method createAllKernels.

@Override
public Kernel[] createAllKernels() {
    Utils.tempBuffers[0].b16i.rewind();
    int ret = CL10.clCreateKernelsInProgram(program, null, Utils.tempBuffers[0].b16i);
    Utils.checkError(ret, "clCreateKernelsInProgram");
    int count = Utils.tempBuffers[0].b16i.get(0);
    PointerBuffer buf = PointerBuffer.allocateDirect(count);
    ret = CL10.clCreateKernelsInProgram(program, buf, (IntBuffer) null);
    Utils.checkError(ret, "clCreateKernelsInProgram");
    Kernel[] kx = new Kernel[count];
    for (int i = 0; i < count; ++i) {
        kx[i] = new LwjglKernel(buf.get());
    }
    return kx;
}
Also used : IntBuffer(java.nio.IntBuffer) PointerBuffer(org.lwjgl.PointerBuffer)

Example 15 with PointerBuffer

use of org.lwjgl.PointerBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method getPlatforms.

/**
     * Returns a list of the available platforms, filtered by the specified
     * filter.
     *
     * Copied from the old release
     *
     * @return the available platforms
     */
private static long[] getPlatforms() {
    int[] count = new int[1];
    int errcode = CL10.clGetPlatformIDs(null, count);
    Utils.checkError(errcode, "clGetDeviceIDs");
    int num_platforms = count[0];
    if (num_platforms == 0) {
        return new long[0];
    }
    PointerBuffer platforms = PointerBuffer.allocateDirect(num_platforms);
    errcode = CL10.clGetPlatformIDs(platforms, (IntBuffer) null);
    Utils.checkError(errcode, "clGetDeviceIDs");
    platforms.rewind();
    long[] platformIDs = new long[num_platforms];
    for (int i = 0; i < num_platforms; i++) {
        platformIDs[i] = platforms.get();
    }
    return platformIDs;
}
Also used : IntBuffer(java.nio.IntBuffer) PointerBuffer(org.lwjgl.PointerBuffer)

Aggregations

PointerBuffer (org.lwjgl.PointerBuffer)20 IntBuffer (java.nio.IntBuffer)3 ByteBuffer (java.nio.ByteBuffer)2 Monitor (com.badlogic.gdx.Graphics.Monitor)1 Lwjgl3Monitor (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics.Lwjgl3Monitor)1 LWJGLException (org.lwjgl.LWJGLException)1 CLBufferRegion (org.lwjgl.opencl.api.CLBufferRegion)1