Java Code Examples for org.lwjgl.PointerBuffer#get()

The following examples show how to use org.lwjgl.PointerBuffer#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LmdbLwjgl.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
@Setup(Trial)
@Override
public void setup(final BenchmarkParams b) throws IOException {
  super.setup(b, false);
  super.write();

  try (MemoryStack stack = stackPush()) {
    final PointerBuffer pp = stack.mallocPointer(1);

    E(mdb_txn_begin(env, NULL, MDB_RDONLY, pp));
    txn = pp.get(0);

    E(mdb_cursor_open(txn, db, pp));
    c = pp.get(0);
  }
}
 
Example 2
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
/**
 * This method will enumerate the physical devices (i.e. GPUs) the system has available for us, and will just return
 * the first one. 
 */
private static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = memAllocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    memFree(pPhysicalDeviceCount);
    memFree(pPhysicalDevices);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 
Example 3
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a list of the available platforms, filtered by the specified
 * filter.
 * <p>
 * Copied from the old release
 *
 * @return the available platforms
 */
private static long[] getPlatforms() {
    try (MemoryStack stack = MemoryStack.stackPush()) {

        final IntBuffer countBuffer = stack.callocInt(1);
        int errcode = CL10.clGetPlatformIDs(null, countBuffer);
        Utils.checkError(errcode, "clGetDeviceIDs");

        final int count = countBuffer.get();
        final PointerBuffer pointer = stack.callocPointer(count);

        errcode = CL10.clGetPlatformIDs(pointer, (IntBuffer) null);
        Utils.checkError(errcode, "clGetDeviceIDs");

        final long[] platformIDs = new long[count];
        for (int i = 0; i < count; i++) {
            platformIDs[i] = pointer.get();
        }

        return platformIDs;
    }
}
 
Example 4
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = memAllocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    cmdBufAllocateInfo.free();
    long commandBuffer = pCommandBuffer.get(0);
    memFree(pCommandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
 
Example 5
Source File: VkBuffer.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public void mapMemory(ByteBuffer buffer){
	
       PointerBuffer pData = memAllocPointer(1);
       int err = vkMapMemory(device, memory, 0, buffer.remaining(), 0, pData);
       
       long data = pData.get(0);
       memFree(pData);
       if (err != VK_SUCCESS) {
           throw new AssertionError("Failed to map buffer memory: " + VkUtil.translateVulkanResult(err));
       }
       
       memCopy(memAddress(buffer), data, buffer.remaining());
       memFree(buffer);
       vkUnmapMemory(device, memory);
}
 
Example 6
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 7
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 8
Source File: LwjglDevice.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long[] getMaximumWorkItemSizes() {
    int dim = (int) getMaximumWorkItemDimensions();
    PointerBuffer sizes = PointerBuffer.allocateDirect(dim);
    Info.clGetDeviceInfoPointers(device, CL10.CL_DEVICE_MAX_WORK_ITEM_SIZES, sizes);
    long[] sx = new long[dim];
    sizes.get(sx);
    return sx;
}
 
Example 9
Source File: LwjglPlatform.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: PhysicalDevice.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public PhysicalDevice(VkInstance vkInstance, long surface) {

		IntBuffer pPhysicalDeviceCount = memAllocInt(1);
        int err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, null);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get number of physical devices: " + VkUtil.translateVulkanResult(err));
        }
        
        log.info("Available Physical Devices: " + pPhysicalDeviceCount.get(0));
        
        PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
        err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, pPhysicalDevices);
        long physicalDevice = pPhysicalDevices.get(0);
       
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get physical devices: " + VkUtil.translateVulkanResult(err));
        }
        
        memFree(pPhysicalDeviceCount);
        memFree(pPhysicalDevices);
        
        handle =  new VkPhysicalDevice(physicalDevice, vkInstance);
        queueFamilies = new QueueFamilies(handle, surface);
        swapChainCapabilities = new SurfaceProperties(handle, surface);
        supportedExtensionNames = DeviceCapabilities.getPhysicalDeviceExtensionNamesSupport(handle);
        memoryProperties = VkPhysicalDeviceMemoryProperties.calloc();
        vkGetPhysicalDeviceMemoryProperties(handle, memoryProperties);
        
        properties = DeviceCapabilities.checkPhysicalDeviceProperties(handle);
        features = DeviceCapabilities.checkPhysicalDeviceFeatures(handle);
        
//        log.info(properties.apiVersion());
//        log.info(properties.driverVersion());
//        log.info(properties.vendorID());
//        log.info(properties.deviceID());
//        log.info(properties.deviceType());
//        log.info(properties.deviceNameString());
	}
 
Example 11
Source File: LogicalDevice.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public VkQueue getDeviceQueue(int queueFamilyIndex, int queueIndex) {

      PointerBuffer pQueue = memAllocPointer(1);
      vkGetDeviceQueue(handle, queueFamilyIndex, queueIndex, pQueue);
      long queue = pQueue.get(0);
      memFree(pQueue);
      return new VkQueue(queue, handle);
  }
 
Example 12
Source File: LmdbLwjgl.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void setup(final BenchmarkParams b, final boolean sync) throws
    IOException {
  super.setup(b);

  try (MemoryStack stack = stackPush()) {
    final PointerBuffer pp = stack.mallocPointer(1);

    E(mdb_env_create(pp));
    env = pp.get(0);

    E(mdb_env_set_maxdbs(env, 1));
    E(mdb_env_set_maxreaders(env, 2));
    E(mdb_env_set_mapsize(env, mapSize(num, valSize)));

    // Open environment
    E(mdb_env_open(env, tmp.getPath(), envFlags(writeMap, sync), POSIX_MODE));

    // Open database
    E(mdb_txn_begin(env, NULL, 0, pp));
    final long txn = pp.get(0);

    final IntBuffer ip = stack.mallocInt(1);
    E(mdb_dbi_open(txn, "db", dbiFlags(intKey), ip));
    db = ip.get(0);

    mdb_txn_commit(txn);
  }
}
 
Example 13
Source File: SimpleDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example 14
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
private static VkQueue createDeviceQueue(VkDevice device, int queueFamilyIndex) {
    PointerBuffer pQueue = memAllocPointer(1);
    vkGetDeviceQueue(device, queueFamilyIndex, 0, pQueue);
    long queue = pQueue.get(0);
    memFree(pQueue);
    return new VkQueue(queue, device);
}
 
Example 15
Source File: SimpleDemo.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("AWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example 16
Source File: EGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
protected void initStatic() {
	if(egl_display != 0) return;

	egl_display = EGL10.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
	EGL10.eglInitialize(egl_display, new int[] {1}, new int[] {1});
	EGLCapabilities caps = EGL.createDisplayCapabilities(egl_display);

	if(debug && caps.EGL_KHR_debug) setEGLDebugFunction(true, true, true, true);

	if(!caps.EGL14 || !EGL12.eglBindAPI(EGL14.EGL_OPENGL_API)) throw new Error("could not bind OpenGL");

	int[] attrs = {EGL13.EGL_CONFORMANT, EGL14.EGL_OPENGL_BIT,
			EGL10.EGL_STENCIL_SIZE, 1,
			EGL10.EGL_NONE};
	PointerBuffer cfgs = BufferUtils.createPointerBuffer(1);
	int[] num_config = new int[1];

	EGL10.eglChooseConfig(egl_display, attrs, cfgs, num_config);
	if(num_config[0] == 0) throw new Error("could not found egl configs!");
	egl_config = cfgs.get(0);

	int i = debug ? 0 : 4;
	while(egl_context == 0 && ctx_attrs.length > i) {
		int[] current_ctx_attrs = ctx_attrs[i];

		egl_context = EGL10.eglCreateContext(egl_display, egl_config, 0, current_ctx_attrs);
		i++;
		if(egl_context != 0 && EGL10.eglGetError() != EGL10.EGL_SUCCESS) {
			EGL10.eglDestroyContext(egl_display, egl_context);
			egl_context = 0;
		}
	}
}
 
Example 17
Source File: VulkanInstance.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public VulkanInstance(PointerBuffer ppEnabledLayerNames) {

PointerBuffer requiredExtensions = glfwGetRequiredInstanceExtensions();
      if (requiredExtensions == null) {
          throw new AssertionError("Failed to find list of required Vulkan extensions");
      }

      ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
      
      // +1 due to VK_EXT_DEBUG_REPORT_EXTENSION
      PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
      ppEnabledExtensionNames.put(requiredExtensions);
      ppEnabledExtensionNames.put(VK_EXT_DEBUG_REPORT_EXTENSION);
      ppEnabledExtensionNames.flip();
      
      VkApplicationInfo appInfo = VkApplicationInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
              .pApplicationName(memUTF8("Vulkan Demo"))
              .pEngineName(memUTF8("OREON ENGINE"))
              .apiVersion(VK_MAKE_VERSION(1, 1, 77));
      
      VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
              .pNext(0)
              .pApplicationInfo(appInfo)
              .ppEnabledExtensionNames(ppEnabledExtensionNames)
              .ppEnabledLayerNames(ppEnabledLayerNames);
      PointerBuffer pInstance = memAllocPointer(1);
      int err = vkCreateInstance(pCreateInfo, null, pInstance);
  
      if (err != VK_SUCCESS) {
          throw new AssertionError("Failed to create VkInstance: " + VkUtil.translateVulkanResult(err));
      }
      
      handle = new VkInstance(pInstance.get(0), pCreateInfo);
      
      pCreateInfo.free();
      memFree(pInstance);
      memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
      memFree(ppEnabledExtensionNames);
      memFree(appInfo.pApplicationName());
      memFree(appInfo.pEngineName());
      appInfo.free();
      
      VkDebugReportCallbackEXT debugCallback = new VkDebugReportCallbackEXT() {
          public int invoke(int flags, int objectType, long object, long location, int messageCode, long pLayerPrefix, long pMessage, long pUserData) {
              System.err.println("ERROR OCCURED: " + VkDebugReportCallbackEXT.getString(pMessage));
              return 0;
          }
      };
      
      debugCallbackHandle = setupDebugging(handle, VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT, debugCallback);
  }
 
Example 18
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) {
    IntBuffer pQueueFamilyPropertyCount = memAllocInt(1);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
    int queueCount = pQueueFamilyPropertyCount.get(0);
    VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.calloc(queueCount);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
    memFree(pQueueFamilyPropertyCount);
    int graphicsQueueFamilyIndex;
    for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) {
        if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0)
            break;
    }
    queueProps.free();
    FloatBuffer pQueuePriorities = memAllocFloat(1).put(0.0f);
    pQueuePriorities.flip();
    VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.calloc(1)
            .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
            .queueFamilyIndex(graphicsQueueFamilyIndex)
            .pQueuePriorities(pQueuePriorities);

    PointerBuffer extensions = memAllocPointer(1);
    ByteBuffer VK_KHR_SWAPCHAIN_EXTENSION = memUTF8(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
    extensions.put(VK_KHR_SWAPCHAIN_EXTENSION);
    extensions.flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();

    VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO)
            .pNext(NULL)
            .pQueueCreateInfos(queueCreateInfo)
            .ppEnabledExtensionNames(extensions)
            .ppEnabledLayerNames(ppEnabledLayerNames);

    PointerBuffer pDevice = memAllocPointer(1);
    int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice);
    long device = pDevice.get(0);
    memFree(pDevice);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create device: " + translateVulkanResult(err));
    }

    DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily();
    ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo);
    ret.queueFamilyIndex = graphicsQueueFamilyIndex;

    deviceCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_KHR_SWAPCHAIN_EXTENSION);
    memFree(extensions);
    memFree(pQueuePriorities);
    return ret;
}
 
Example 19
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the pointer value at the specified offset.
 */
public long pointerValue(int offset) {
    return PointerBuffer.get(buffer, offset);
}
 
Example 20
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
/**
 * Create a Vulkan {@link VkInstance} using LWJGL 3.
 * <p>
 * The {@link VkInstance} represents a handle to the Vulkan API and we need that instance for about everything we do.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(3)
      .put(VK_KHR_SURFACE_EXTENSION)
      .put(VK_KHR_OS_SURFACE_EXTENSION)
      .put(VK_EXT_DEBUG_REPORT_EXTENSION)
      .flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(NULL)
            .pApplicationInfo(appInfo)
            .ppEnabledExtensionNames(ppEnabledExtensionNames)
            .ppEnabledLayerNames(ppEnabledLayerNames);
    PointerBuffer pInstance = memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    long instance = pInstance.get(0);
    memFree(pInstance);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    pCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}