public static LongBuffer createLongBuffer(List<DescriptorSetLayout> descriptorSetLayouts){ if (descriptorSetLayouts.size() == 0){ log.error("createLongBuffer: descriptorSetLayouts empty"); } LongBuffer descriptorSetLayoutsBuffer = memAllocLong(descriptorSetLayouts.size()); for (DescriptorSetLayout layout : descriptorSetLayouts){ descriptorSetLayoutsBuffer.put(layout.getHandle()); } descriptorSetLayoutsBuffer.flip(); return descriptorSetLayoutsBuffer; }
public void bindVertexInputCmd(long vertexBuffer){ LongBuffer offsets = memAllocLong(1); offsets.put(0, 0L); LongBuffer pVertexBuffers = memAllocLong(1); pVertexBuffers.put(0, vertexBuffer); vkCmdBindVertexBuffers(handle, 0, pVertexBuffers, offsets); memFree(pVertexBuffers); memFree(offsets); }
public void createFrameBuffers(long renderPass){ frameBuffers = new ArrayList<>(swapChainImages.size()); for (VkImageView imageView : swapChainImageViews){ LongBuffer pAttachments = memAllocLong(1); pAttachments.put(0, imageView.getHandle()); VkFrameBuffer frameBuffer = new VkFrameBuffer(device, extent.width(), extent.height(), 1, pAttachments, renderPass); frameBuffers.add(frameBuffer); } }
public void bindVertexInputCmd(long vertexBuffer, long indexBuffer){ LongBuffer offsets = memAllocLong(1); offsets.put(0, 0L); LongBuffer pVertexBuffers = memAllocLong(1); pVertexBuffers.put(0, vertexBuffer); vkCmdBindVertexBuffers(handle, 0, pVertexBuffers, offsets); vkCmdBindIndexBuffer(handle, indexBuffer, 0, VK_INDEX_TYPE_UINT32); memFree(pVertexBuffers); memFree(offsets); }
public void createImages(){ IntBuffer pImageCount = memAllocInt(1); int err = vkGetSwapchainImagesKHR(device, handle, pImageCount, null); int imageCount = pImageCount.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to get number of swapchain images: " + VkUtil.translateVulkanResult(err)); } LongBuffer pSwapchainImages = memAllocLong(imageCount); err = vkGetSwapchainImagesKHR(device, handle, pImageCount, pSwapchainImages); if (err != VK_SUCCESS) { throw new AssertionError("Failed to get swapchain images: " + VkUtil.translateVulkanResult(err)); } swapChainImages = new ArrayList<>(imageCount); for (int i = 0; i < imageCount; i++) { swapChainImages.add(pSwapchainImages.get(i)); } memFree(pImageCount); memFree(pSwapchainImages); }
public VkSemaphore(VkDevice device) { this.device = device; VkSemaphoreCreateInfo semaphoreCreateInfo = VkSemaphoreCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO) .pNext(0) .flags(0); handlePointer = memAllocLong(1); int err = vkCreateSemaphore(device, semaphoreCreateInfo, null, handlePointer); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create semaphore: " + VkUtil.translateVulkanResult(err)); } handle = handlePointer.get(0); semaphoreCreateInfo.free(); }
public Fence(VkDevice device) { this.device = device; VkFenceCreateInfo createInfo = VkFenceCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_FENCE_CREATE_INFO) .pNext(0) .flags(VK_FENCE_CREATE_SIGNALED_BIT); pHandle = memAllocLong(1); VkUtil.vkCheckResult(vkCreateFence(device, createInfo, null, pHandle)); handle = pHandle.get(0); createInfo.free(); }
public CommandPool(VkDevice device, int queueFamilyIndex){ this.device = device; VkCommandPoolCreateInfo cmdPoolInfo = VkCommandPoolCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO) .queueFamilyIndex(queueFamilyIndex) .flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); LongBuffer pCmdPool = memAllocLong(1); int err = vkCreateCommandPool(device, cmdPoolInfo, null, pCmdPool); handle = pCmdPool.get(0); cmdPoolInfo.free(); memFree(pCmdPool); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create command pool: " + VkUtil.translateVulkanResult(err)); } }
public DescriptorSet(VkDevice device, long descriptorPool, LongBuffer layouts) { this.device = device; this.descriptorPool = descriptorPool; VkDescriptorSetAllocateInfo allocateInfo = VkDescriptorSetAllocateInfo.calloc() .sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO) .descriptorPool(descriptorPool) .pSetLayouts(layouts); LongBuffer pDescriptorSet = memAllocLong(1); int err = vkAllocateDescriptorSets(device, allocateInfo, pDescriptorSet); handle = pDescriptorSet.get(0); allocateInfo.free(); memFree(pDescriptorSet); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create Descriptor Set: " + VkUtil.translateVulkanResult(err)); } }
public void setLayout(LongBuffer pLayouts){ VkPipelineLayoutCreateInfo pipelineLayout = VkPipelineLayoutCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO) .pNext(0) .pSetLayouts(pLayouts) .pPushConstantRanges(pushConstantRange); LongBuffer pPipelineLayout = memAllocLong(1); int err = vkCreatePipelineLayout(device, pipelineLayout, null, pPipelineLayout); layoutHandle = pPipelineLayout.get(0); memFree(pPipelineLayout); pipelineLayout.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create pipeline layout: " + VkUtil.translateVulkanResult(err)); } }
public void createComputePipeline(ShaderModule shader){ VkComputePipelineCreateInfo.Buffer pipelineCreateInfo = VkComputePipelineCreateInfo.calloc(1) .sType(VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO) .stage(shader.getShaderStageInfo()) .layout(layoutHandle); LongBuffer pPipelines = memAllocLong(1); VkUtil.vkCheckResult(vkCreateComputePipelines(device, VK_NULL_HANDLE, pipelineCreateInfo, null, pPipelines)); handle = pPipelines.get(0); pipelineCreateInfo.free(); }
public void draw(VkQueue queue, VkSemaphore waitSemaphore){ int err = vkAcquireNextImageKHR(device, handle, UINT64_MAX, imageAcquiredSemaphore.getHandle(), VK_NULL_HANDLE, pAcquiredImageIndex); if (err != VK_SUCCESS) { throw new AssertionError("Failed to acquire next swapchain image: " + VkUtil.translateVulkanResult(err)); } CommandBuffer currentRenderCommandBuffer = renderCommandBuffers.get(pAcquiredImageIndex.get(0)); IntBuffer pWaitDstStageMask = memAllocInt(2); pWaitDstStageMask.put(0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); pWaitDstStageMask.put(1, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); LongBuffer pWaitSemaphores = memAllocLong(2); pWaitSemaphores.put(0, imageAcquiredSemaphore.getHandle()); pWaitSemaphores.put(1, waitSemaphore.getHandle()); submitInfo.setCommandBuffers(currentRenderCommandBuffer.getHandlePointer()); submitInfo.setWaitDstStageMask(pWaitDstStageMask); submitInfo.setWaitSemaphores(pWaitSemaphores); submitInfo.submit(queue); VkUtil.vkCheckResult(vkQueuePresentKHR(queue, presentInfo)); }
private void createShaderModule(String filePath) { ByteBuffer shaderCode = null; try { shaderCode = ResourceLoader.ioResourceToByteBuffer(filePath, 1024); } catch (IOException e) { e.printStackTrace(); } 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); handle = pShaderModule.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create shader module: " + VkUtil.translateVulkanResult(err)); } memFree(pShaderModule); moduleCreateInfo.free(); }
public void create(){ layoutBindings.flip(); VkDescriptorSetLayoutCreateInfo layoutInfo = VkDescriptorSetLayoutCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) .pBindings(layoutBindings) .flags(0); handlePointer = memAllocLong(1); int err = vkCreateDescriptorSetLayout(device, layoutInfo, null, handlePointer); handle = handlePointer.get(0); layoutBindings.clear(); layoutBindings.free(); layoutInfo.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create DescriptorSetLayout: " + VkUtil.translateVulkanResult(err)); } }
private long setupDebugging(VkInstance instance, int flags, VkDebugReportCallbackEXT callback) { VkDebugReportCallbackCreateInfoEXT debugCreateInfo = VkDebugReportCallbackCreateInfoEXT.calloc() .sType(VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT) .pNext(0) .pfnCallback(callback) .pUserData(0) .flags(flags); LongBuffer pCallback = memAllocLong(1); int err = vkCreateDebugReportCallbackEXT(instance, debugCreateInfo, null, pCallback); long callbackHandle = pCallback.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create VkInstance: " + VkUtil.translateVulkanResult(err)); } memFree(pCallback); debugCreateInfo.free(); return callbackHandle; }
public VkBuffer(VkDevice device, int size, int usage){ this.device = device; VkBufferCreateInfo bufInfo = VkBufferCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO) .pNext(0) .size(size) .usage(usage) .sharingMode(VK_SHARING_MODE_EXCLUSIVE) .flags(0); LongBuffer pBuffer = memAllocLong(1); int err = vkCreateBuffer(this.device, bufInfo, null, pBuffer); handle = pBuffer.get(0); memFree(pBuffer); bufInfo.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create buffer: " + VkUtil.translateVulkanResult(err)); } }
public void create() { poolSizes.flip(); VkDescriptorPoolCreateInfo createInfo = VkDescriptorPoolCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO) .pPoolSizes(poolSizes) .maxSets(maxSets) .flags(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT); LongBuffer pDescriptorPool = memAllocLong(1); int err = vkCreateDescriptorPool(device, createInfo, null, pDescriptorPool); handle = pDescriptorPool.get(0); poolSizes.free(); createInfo.free(); memFree(pDescriptorPool); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create Descriptor pool: " + VkUtil.translateVulkanResult(err)); } }
.memoryTypeIndex(memoryTypeIndex.get(0)); LongBuffer pMemory = memAllocLong(1); int err = vkAllocateMemory(device, memAlloc, null, pMemory); memory = pMemory.get(0);
.memoryTypeIndex(memoryTypeIndex.get(0)); LongBuffer pMemory = memAllocLong(1); int err = vkAllocateMemory(device, memAlloc, null, pMemory); memory = pMemory.get(0);
public VkFrameBuffer(VkDevice device, int width, int height, int layers, LongBuffer pAttachments, long renderPass) { this.device = device; VkFramebufferCreateInfo framebufferInfo = VkFramebufferCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) .pAttachments(pAttachments) .flags(0) .height(height) .width(width) .layers(layers) .pNext(0) .renderPass(renderPass); LongBuffer pFramebuffer = memAllocLong(1); int err = vkCreateFramebuffer(device, framebufferInfo, null, pFramebuffer); if (err != VK_SUCCESS) { throw new AssertionError("Failed to create framebuffer: " + VkUtil.translateVulkanResult(err)); } handle = pFramebuffer.get(0); framebufferInfo.free(); memFree(pFramebuffer); memFree(pAttachments); }