private static long[] createFramebuffers(VkDevice device, Swapchain swapchain, long renderPass, int width, int height) { LongBuffer attachments = stackMallocLong(1); VkFramebufferCreateInfo fci = VkFramebufferCreateInfo.callocStack() .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) .pAttachments(attachments) .flags(VK_FLAGS_NONE) .height(height) .width(width) .layers(1) .pNext(NULL) .renderPass(renderPass); // Create a framebuffer for each swapchain image long[] framebuffers = new long[swapchain.images.length]; LongBuffer pFramebuffer = stackMallocLong(1); for (int i = 0; i < swapchain.images.length; i++) { attachments.put(0, swapchain.imageViews[i]); int err = vkCreateFramebuffer(device, fci, null, pFramebuffer); long framebuffer = pFramebuffer.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create framebuffer: " + translateVulkanResult(err)); } framebuffers[i] = framebuffer; } return framebuffers; }
private 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: " + VKUtil.translateVulkanResult(err)); } return new VkCommandBuffer(commandBuffer, device); }
private static long loadShader(String filePath, VkDevice device) throws IOException { ByteBuffer shaderCode = ResourceLoader.ioResourceToByteBuffer(filePath, 1024); int err; VkShaderModuleCreateInfo moduleCreateInfo = VkShaderModuleCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO) .pNext(0) .pCode(shaderCode) .flags(0); LongBuffer pShaderModule = memAllocLong(1); err = vkCreateShaderModule(device, moduleCreateInfo, null, pShaderModule); long shaderModule = pShaderModule.get(0); memFree(pShaderModule); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create shader module: " + VKUtil.translateVulkanResult(err)); } return shaderModule; }
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); }
private static long createCommandPool(VkDevice device, int queueNodeIndex) { VkCommandPoolCreateInfo cmdPoolInfo = VkCommandPoolCreateInfo.callocStack() .sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO) .queueFamilyIndex(queueNodeIndex) .flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); LongBuffer pCmdPool = stackMallocLong(1); int err = vkCreateCommandPool(device, cmdPoolInfo, null, pCmdPool); long commandPool = pCmdPool.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create command pool: " + translateVulkanResult(err)); } return commandPool; }
@NoTransform private static VkQueue createDeviceQueue(VkDevice device, int queueFamilyIndex) { PointerBuffer pQueue = stackMallocPointer(1); vkGetDeviceQueue(device, queueFamilyIndex, 0, pQueue); long queue = pQueue.get(0); return new VkQueue(queue, device); }
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) { VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.callocStack() .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO) .commandPool(commandPool) .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY) .commandBufferCount(1); PointerBuffer pCommandBuffer = stackMallocPointer(1); int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer); long commandBuffer = pCommandBuffer.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err)); } return new VkCommandBuffer(commandBuffer, device); }
private static long createClearRenderPass(VkDevice device, int colorFormat) { VkAttachmentDescription.Buffer attachments = VkAttachmentDescription.callocStack(1) .format(colorFormat) .samples(VK_SAMPLE_COUNT_1_BIT) .loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR) .storeOp(VK_ATTACHMENT_STORE_OP_STORE) .stencilLoadOp(VK_ATTACHMENT_LOAD_OP_DONT_CARE) .stencilStoreOp(VK_ATTACHMENT_STORE_OP_DONT_CARE) .initialLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .finalLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkAttachmentReference.Buffer colorReference = VkAttachmentReference.callocStack(1) .attachment(0) .layout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkSubpassDescription.Buffer subpass = VkSubpassDescription.callocStack(1) .pipelineBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS) .flags(VK_FLAGS_NONE) .pInputAttachments(null) .colorAttachmentCount(colorReference.remaining()) .pColorAttachments(colorReference) .pResolveAttachments(null) .pDepthStencilAttachment(null) .pPreserveAttachments(null); VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.callocStack() .sType(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO) .pNext(NULL) .pAttachments(attachments) .pSubpasses(subpass) .pDependencies(null); LongBuffer pRenderPass = stackMallocLong(1); int err = vkCreateRenderPass(device, renderPassInfo, null, pRenderPass); long renderPass = pRenderPass.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create clear render pass: " + translateVulkanResult(err)); } return renderPass; }
private long createCommandPool(VkDevice device, int queueNodeIndex) { VkCommandPoolCreateInfo cmdPoolInfo = VkCommandPoolCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO) .queueFamilyIndex(queueNodeIndex) .flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); LongBuffer pCmdPool = memAllocLong(1); int err = vkCreateCommandPool(device, cmdPoolInfo, null, pCmdPool); long commandPool = pCmdPool.get(0); cmdPoolInfo.free(); memFree(pCmdPool); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create command pool: " + VKUtil.translateVulkanResult(err)); } return commandPool; }
private 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); }
private long[] createFramebuffers(VkDevice device, Swapchain swapchain, long renderPass, int width, int height) { LongBuffer attachments = memAllocLong(1); VkFramebufferCreateInfo fci = VkFramebufferCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) .pAttachments(attachments) .flags(0) .height(height) .width(width) .layers(1) .pNext(0) .renderPass(renderPass); // Create a framebuffer for each swapchain image long[] framebuffers = new long[swapchain.images.length]; LongBuffer pFramebuffer = memAllocLong(1); for (int i = 0; i < swapchain.images.length; i++) { attachments.put(0, swapchain.imageViews[i]); int err = vkCreateFramebuffer(device, fci, null, pFramebuffer); long framebuffer = pFramebuffer.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create framebuffer: " + VKUtil.translateVulkanResult(err)); } framebuffers[i] = framebuffer; } memFree(attachments); memFree(pFramebuffer); fci.free(); return framebuffers; }
private VkPipelineShaderStageCreateInfo loadShader(VkDevice device, String classPath, int stage) throws IOException { VkPipelineShaderStageCreateInfo shaderStage = VkPipelineShaderStageCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) .stage(stage) .module(loadShader(classPath, device)) .pName(memUTF8("main")); return shaderStage; }
private static long createCommandPool(VkDevice device, int queueNodeIndex) { VkCommandPoolCreateInfo cmdPoolInfo = VkCommandPoolCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO) .queueFamilyIndex(queueNodeIndex) .flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); LongBuffer pCmdPool = memAllocLong(1); int err = vkCreateCommandPool(device, cmdPoolInfo, null, pCmdPool); long commandPool = pCmdPool.get(0); cmdPoolInfo.free(); memFree(pCmdPool); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create command pool: " + translateVulkanResult(err)); } return commandPool; }
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); }
private static long[] createFramebuffers(VkDevice device, Swapchain swapchain, long renderPass, int width, int height) { LongBuffer attachments = memAllocLong(1); VkFramebufferCreateInfo fci = VkFramebufferCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) .pAttachments(attachments) .flags(VK_FLAGS_NONE) .height(height) .width(width) .layers(1) .pNext(NULL) .renderPass(renderPass); // Create a framebuffer for each swapchain image long[] framebuffers = new long[swapchain.images.length]; LongBuffer pFramebuffer = memAllocLong(1); for (int i = 0; i < swapchain.images.length; i++) { attachments.put(0, swapchain.imageViews[i]); int err = vkCreateFramebuffer(device, fci, null, pFramebuffer); long framebuffer = pFramebuffer.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create framebuffer: " + translateVulkanResult(err)); } framebuffers[i] = framebuffer; } memFree(attachments); memFree(pFramebuffer); fci.free(); return framebuffers; }
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) { IntBuffer pQueueFamilyPropertyCount = stackMallocInt(1); vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null); int queueCount = pQueueFamilyPropertyCount.get(0); VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.callocStack(queueCount); vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps); int graphicsQueueFamilyIndex; for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) { if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0) break; } VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.callocStack(1) .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO) .queueFamilyIndex(graphicsQueueFamilyIndex) .pQueuePriorities(stackFloats(0.0f)); PointerBuffer extensions = stackMallocPointer(1); ByteBuffer VK_KHR_SWAPCHAIN_EXTENSION = stackUTF8(VK_KHR_SWAPCHAIN_EXTENSION_NAME); extensions.put(VK_KHR_SWAPCHAIN_EXTENSION); extensions.flip(); PointerBuffer ppEnabledLayerNames = stackMallocPointer(layers.length); for (int i = 0; validation && i < layers.length; i++) ppEnabledLayerNames.put(layers[i]); ppEnabledLayerNames.flip(); VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.callocStack() .sType(VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) .pNext(NULL) .pQueueCreateInfos(queueCreateInfo) .ppEnabledExtensionNames(extensions) .ppEnabledLayerNames(ppEnabledLayerNames); PointerBuffer pDevice = stackMallocPointer(1); int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice); long device = pDevice.get(0); 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; return ret; }
void recreate(VkCommandBuffer setupCommandBuffer, VkDevice device, VkPhysicalDevice physicalDevice, long surface, ColorFormatAndSpace colorFormatAndSpace, VkQueue queue, long renderPass, long renderCommandPool, long pipeline, Vertices vertices) { // Begin the setup command buffer (the one we will use for swapchain/framebuffer creation) VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO) .pNext(0); int err = vkBeginCommandBuffer(setupCommandBuffer, cmdBufInfo); cmdBufInfo.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to begin setup command buffer: " + VKUtil.translateVulkanResult(err)); } long oldChain = swapchain != null ? swapchain.swapchainHandle : VK_NULL_HANDLE; // Create the swapchain (this will also add a memory barrier to initialize the framebuffer images) swapchain = createSwapChain(device, physicalDevice, surface, oldChain, setupCommandBuffer, width, height, colorFormatAndSpace.colorFormat, colorFormatAndSpace.colorSpace); err = vkEndCommandBuffer(setupCommandBuffer); if (err != VK_SUCCESS) { throw new AssertionError("Failed to end setup command buffer: " + VKUtil.translateVulkanResult(err)); } submitCommandBuffer(queue, setupCommandBuffer); vkQueueWaitIdle(queue); if (framebuffers != null) { for (int i = 0; i < framebuffers.length; i++) vkDestroyFramebuffer(device, framebuffers[i], null); } framebuffers = createFramebuffers(device, swapchain, renderPass, width, height); // Create render command buffers if (renderCommandBuffers != null) { vkResetCommandPool(device, renderCommandPool, 0); } renderCommandBuffers = createRenderCommandBuffers(device, renderCommandPool, framebuffers, renderPass, width, height, pipeline, vertices.verticesBuf); mustRecreate = false; }
private 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(0) .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: " + VKUtil.translateVulkanResult(err)); } VkPhysicalDeviceMemoryProperties memoryProperties = VkPhysicalDeviceMemoryProperties.calloc(); vkGetPhysicalDeviceMemoryProperties(physicalDevice, memoryProperties); DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily(); ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo); ret.queueFamilyIndex = graphicsQueueFamilyIndex; ret.memoryProperties = memoryProperties; deviceCreateInfo.free(); memFree(ppEnabledLayerNames); memFree(VK_KHR_SWAPCHAIN_EXTENSION); memFree(extensions); memFree(pQueuePriorities); return ret; }
private long createRenderPass(VkDevice device, int colorFormat) { VkAttachmentDescription.Buffer attachments = VkAttachmentDescription.calloc(1) .format(colorFormat) .samples(VK_SAMPLE_COUNT_1_BIT) .loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR) .storeOp(VK_ATTACHMENT_STORE_OP_STORE) .stencilLoadOp(VK_ATTACHMENT_LOAD_OP_DONT_CARE) .stencilStoreOp(VK_ATTACHMENT_STORE_OP_DONT_CARE) .initialLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .finalLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkAttachmentReference.Buffer colorReference = VkAttachmentReference.calloc(1) .attachment(0) .layout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkSubpassDescription.Buffer subpass = VkSubpassDescription.calloc(1) .pipelineBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS) .flags(0) .pInputAttachments(null) .colorAttachmentCount(colorReference.remaining()) .pColorAttachments(colorReference) // <- only color attachment .pResolveAttachments(null) .pDepthStencilAttachment(null) .pPreserveAttachments(null); VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO) .pNext(0) .pAttachments(attachments) .pSubpasses(subpass) .pDependencies(null); LongBuffer pRenderPass = memAllocLong(1); int err = vkCreateRenderPass(device, renderPassInfo, null, pRenderPass); long renderPass = pRenderPass.get(0); memFree(pRenderPass); renderPassInfo.free(); colorReference.free(); subpass.free(); attachments.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create clear render pass: " + VKUtil.translateVulkanResult(err)); } return renderPass; }
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; }
private static long createClearRenderPass(VkDevice device, int colorFormat) { VkAttachmentDescription.Buffer attachments = VkAttachmentDescription.calloc(1) .format(colorFormat) .samples(VK_SAMPLE_COUNT_1_BIT) .loadOp(VK_ATTACHMENT_LOAD_OP_CLEAR) .storeOp(VK_ATTACHMENT_STORE_OP_STORE) .stencilLoadOp(VK_ATTACHMENT_LOAD_OP_DONT_CARE) .stencilStoreOp(VK_ATTACHMENT_STORE_OP_DONT_CARE) .initialLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .finalLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkAttachmentReference.Buffer colorReference = VkAttachmentReference.calloc(1) .attachment(0) .layout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkSubpassDescription.Buffer subpass = VkSubpassDescription.calloc(1) .pipelineBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS) .flags(VK_FLAGS_NONE) .pInputAttachments(null) .colorAttachmentCount(colorReference.remaining()) .pColorAttachments(colorReference) .pResolveAttachments(null) .pDepthStencilAttachment(null) .pPreserveAttachments(null); VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO) .pNext(NULL) .pAttachments(attachments) .pSubpasses(subpass) .pDependencies(null); LongBuffer pRenderPass = memAllocLong(1); int err = vkCreateRenderPass(device, renderPassInfo, null, pRenderPass); long renderPass = pRenderPass.get(0); memFree(pRenderPass); renderPassInfo.free(); colorReference.free(); subpass.free(); attachments.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create clear render pass: " + translateVulkanResult(err)); } return renderPass; }