Single-line "if"-statements
parent
e84b8139b3
commit
a00ba1dcee
|
@ -22,6 +22,7 @@ import com.github.hydos.ginger.engine.vulkan.memory.VKMemory;
|
||||||
import com.github.hydos.ginger.engine.vulkan.render.ubo.*;
|
import com.github.hydos.ginger.engine.vulkan.render.ubo.*;
|
||||||
import com.github.hydos.ginger.engine.vulkan.shaders.Pipeline;
|
import com.github.hydos.ginger.engine.vulkan.shaders.Pipeline;
|
||||||
import com.github.hydos.ginger.engine.vulkan.utils.*;
|
import com.github.hydos.ginger.engine.vulkan.utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author hydos06
|
* @author hydos06
|
||||||
|
@ -129,16 +130,12 @@ public class VulkanStarter
|
||||||
err = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pFormatCount, surfFormats);
|
err = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pFormatCount, surfFormats);
|
||||||
memFree(pFormatCount);
|
memFree(pFormatCount);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS)
|
||||||
{ throw new AssertionError("Failed to query physical device surface formats: " + VKUtils.translateVulkanResult(err)); }
|
throw new AssertionError("Failed to query physical device surface formats: " + VKUtils.translateVulkanResult(err));
|
||||||
int colorFormat;
|
int colorFormat;
|
||||||
if (formatCount == 1 && surfFormats.get(0).format() == VK_FORMAT_UNDEFINED)
|
if (formatCount == 1 && surfFormats.get(0).format() == VK_FORMAT_UNDEFINED)
|
||||||
{
|
|
||||||
colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
colorFormat = surfFormats.get(0).format();
|
colorFormat = surfFormats.get(0).format();
|
||||||
}
|
|
||||||
int colorSpace = surfFormats.get(0).colorSpace();
|
int colorSpace = surfFormats.get(0).colorSpace();
|
||||||
surfFormats.free();
|
surfFormats.free();
|
||||||
// Find suitable depth format
|
// Find suitable depth format
|
||||||
|
@ -163,8 +160,7 @@ public class VulkanStarter
|
||||||
long commandPool = pCmdPool.get(0);
|
long commandPool = pCmdPool.get(0);
|
||||||
cmdPoolInfo.free();
|
cmdPoolInfo.free();
|
||||||
memFree(pCmdPool);
|
memFree(pCmdPool);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create command pool: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create command pool: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
return commandPool;
|
return commandPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +185,7 @@ public class VulkanStarter
|
||||||
cmdBufAllocateInfo.free();
|
cmdBufAllocateInfo.free();
|
||||||
long commandBuffer = pCommandBuffer.get(0);
|
long commandBuffer = pCommandBuffer.get(0);
|
||||||
memFree(pCommandBuffer);
|
memFree(pCommandBuffer);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to allocate command buffer: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to allocate command buffer: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
return new VkCommandBuffer(commandBuffer, device);
|
return new VkCommandBuffer(commandBuffer, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,18 +203,15 @@ public class VulkanStarter
|
||||||
// Get physical device surface properties and formats
|
// Get physical device surface properties and formats
|
||||||
VkSurfaceCapabilitiesKHR surfCaps = VkSurfaceCapabilitiesKHR.calloc();
|
VkSurfaceCapabilitiesKHR surfCaps = VkSurfaceCapabilitiesKHR.calloc();
|
||||||
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, surfCaps);
|
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, surfCaps);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to get physical device surface capabilities: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to get physical device surface capabilities: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
IntBuffer pPresentModeCount = memAllocInt(1);
|
IntBuffer pPresentModeCount = memAllocInt(1);
|
||||||
err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, null);
|
err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, null);
|
||||||
int presentModeCount = pPresentModeCount.get(0);
|
int presentModeCount = pPresentModeCount.get(0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to get number of physical device surface presentation modes: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to get number of physical device surface presentation modes: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
IntBuffer pPresentModes = memAllocInt(presentModeCount);
|
IntBuffer pPresentModes = memAllocInt(presentModeCount);
|
||||||
err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
|
err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
|
||||||
memFree(pPresentModeCount);
|
memFree(pPresentModeCount);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to get physical device surface presentation modes: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to get physical device surface presentation modes: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Try to use mailbox mode. Low latency and non-tearing
|
// Try to use mailbox mode. Low latency and non-tearing
|
||||||
int swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
int swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
for (int i = 0; i < presentModeCount; i++)
|
for (int i = 0; i < presentModeCount; i++)
|
||||||
|
@ -230,13 +222,13 @@ public class VulkanStarter
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((swapchainPresentMode != VK_PRESENT_MODE_MAILBOX_KHR) && (pPresentModes.get(i) == VK_PRESENT_MODE_IMMEDIATE_KHR))
|
if ((swapchainPresentMode != VK_PRESENT_MODE_MAILBOX_KHR) && (pPresentModes.get(i) == VK_PRESENT_MODE_IMMEDIATE_KHR))
|
||||||
{ swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; }
|
swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||||
}
|
}
|
||||||
memFree(pPresentModes);
|
memFree(pPresentModes);
|
||||||
// Determine the number of images
|
// Determine the number of images
|
||||||
int desiredNumberOfSwapchainImages = surfCaps.minImageCount() + 1;
|
int desiredNumberOfSwapchainImages = surfCaps.minImageCount() + 1;
|
||||||
if ((surfCaps.maxImageCount() > 0) && (desiredNumberOfSwapchainImages > surfCaps.maxImageCount()))
|
if ((surfCaps.maxImageCount() > 0) && (desiredNumberOfSwapchainImages > surfCaps.maxImageCount()))
|
||||||
{ desiredNumberOfSwapchainImages = surfCaps.maxImageCount(); }
|
desiredNumberOfSwapchainImages = surfCaps.maxImageCount();
|
||||||
VkExtent2D currentExtent = surfCaps.currentExtent();
|
VkExtent2D currentExtent = surfCaps.currentExtent();
|
||||||
int currentWidth = currentExtent.width();
|
int currentWidth = currentExtent.width();
|
||||||
int currentHeight = currentExtent.height();
|
int currentHeight = currentExtent.height();
|
||||||
|
@ -252,13 +244,8 @@ public class VulkanStarter
|
||||||
}
|
}
|
||||||
int preTransform;
|
int preTransform;
|
||||||
if ((surfCaps.supportedTransforms() & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) != 0)
|
if ((surfCaps.supportedTransforms() & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) != 0)
|
||||||
{
|
|
||||||
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||||
}
|
else preTransform = surfCaps.currentTransform();
|
||||||
else
|
|
||||||
{
|
|
||||||
preTransform = surfCaps.currentTransform();
|
|
||||||
}
|
|
||||||
surfCaps.free();
|
surfCaps.free();
|
||||||
VkSwapchainCreateInfoKHR swapchainCI = VkSwapchainCreateInfoKHR.calloc()
|
VkSwapchainCreateInfoKHR swapchainCI = VkSwapchainCreateInfoKHR.calloc()
|
||||||
.sType(VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR)
|
.sType(VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR)
|
||||||
|
@ -282,21 +269,17 @@ public class VulkanStarter
|
||||||
swapchainCI.free();
|
swapchainCI.free();
|
||||||
long swapChain = pSwapChain.get(0);
|
long swapChain = pSwapChain.get(0);
|
||||||
memFree(pSwapChain);
|
memFree(pSwapChain);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create swap chain: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create swap chain: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// If we just re-created an existing swapchain, we should destroy the old swapchain at this point.
|
// If we just re-created an existing swapchain, we should destroy the old swapchain at this point.
|
||||||
// Note: destroying the swapchain also cleans up all its associated presentable images once the platform is done with them.
|
// Note: destroying the swapchain also cleans up all its associated presentable images once the platform is done with them.
|
||||||
if (oldSwapChain != VK_NULL_HANDLE)
|
if (oldSwapChain != VK_NULL_HANDLE) vkDestroySwapchainKHR(device, oldSwapChain, null);
|
||||||
{ vkDestroySwapchainKHR(device, oldSwapChain, null); }
|
|
||||||
IntBuffer pImageCount = memAllocInt(1);
|
IntBuffer pImageCount = memAllocInt(1);
|
||||||
err = vkGetSwapchainImagesKHR(device, swapChain, pImageCount, null);
|
err = vkGetSwapchainImagesKHR(device, swapChain, pImageCount, null);
|
||||||
int imageCount = pImageCount.get(0);
|
int imageCount = pImageCount.get(0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to get number of swapchain images: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to get number of swapchain images: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
LongBuffer pSwapchainImages = memAllocLong(imageCount);
|
LongBuffer pSwapchainImages = memAllocLong(imageCount);
|
||||||
err = vkGetSwapchainImagesKHR(device, swapChain, pImageCount, pSwapchainImages);
|
err = vkGetSwapchainImagesKHR(device, swapChain, pImageCount, pSwapchainImages);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to get swapchain images: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to get swapchain images: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
memFree(pImageCount);
|
memFree(pImageCount);
|
||||||
long[] images = new long[imageCount];
|
long[] images = new long[imageCount];
|
||||||
long[] imageViews = new long[imageCount];
|
long[] imageViews = new long[imageCount];
|
||||||
|
@ -315,8 +298,7 @@ public class VulkanStarter
|
||||||
colorAttachmentView.image(images[i]);
|
colorAttachmentView.image(images[i]);
|
||||||
err = vkCreateImageView(device, colorAttachmentView, null, pBufferView);
|
err = vkCreateImageView(device, colorAttachmentView, null, pBufferView);
|
||||||
imageViews[i] = pBufferView.get(0);
|
imageViews[i] = pBufferView.get(0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create image view: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create image view: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
}
|
}
|
||||||
colorAttachmentView.free();
|
colorAttachmentView.free();
|
||||||
memFree(pBufferView);
|
memFree(pBufferView);
|
||||||
|
@ -330,6 +312,7 @@ public class VulkanStarter
|
||||||
|
|
||||||
private static class DepthStencil
|
private static class DepthStencil
|
||||||
{
|
{
|
||||||
|
// What is this? - Caroline
|
||||||
long view;
|
long view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,8 +345,7 @@ public class VulkanStarter
|
||||||
long depthStencilImage = pDepthStencilImage.get(0);
|
long depthStencilImage = pDepthStencilImage.get(0);
|
||||||
memFree(pDepthStencilImage);
|
memFree(pDepthStencilImage);
|
||||||
imageCreateInfo.free();
|
imageCreateInfo.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create depth-stencil image: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create depth-stencil image: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
vkGetImageMemoryRequirements(device, depthStencilImage, memReqs);
|
vkGetImageMemoryRequirements(device, depthStencilImage, memReqs);
|
||||||
mem_alloc.allocationSize(memReqs.size());
|
mem_alloc.allocationSize(memReqs.size());
|
||||||
IntBuffer pMemoryTypeIndex = memAllocInt(1);
|
IntBuffer pMemoryTypeIndex = memAllocInt(1);
|
||||||
|
@ -375,19 +357,16 @@ public class VulkanStarter
|
||||||
long depthStencilMem = pDepthStencilMem.get(0);
|
long depthStencilMem = pDepthStencilMem.get(0);
|
||||||
memFree(pDepthStencilMem);
|
memFree(pDepthStencilMem);
|
||||||
mem_alloc.free();
|
mem_alloc.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create depth-stencil memory: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create depth-stencil memory: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
err = vkBindImageMemory(device, depthStencilImage, depthStencilMem, 0);
|
err = vkBindImageMemory(device, depthStencilImage, depthStencilMem, 0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to bind depth-stencil image to memory: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to bind depth-stencil image to memory: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
depthStencilViewCreateInfo.image(depthStencilImage);
|
depthStencilViewCreateInfo.image(depthStencilImage);
|
||||||
LongBuffer pDepthStencilView = memAllocLong(1);
|
LongBuffer pDepthStencilView = memAllocLong(1);
|
||||||
err = vkCreateImageView(device, depthStencilViewCreateInfo, null, pDepthStencilView);
|
err = vkCreateImageView(device, depthStencilViewCreateInfo, null, pDepthStencilView);
|
||||||
long depthStencilView = pDepthStencilView.get(0);
|
long depthStencilView = pDepthStencilView.get(0);
|
||||||
memFree(pDepthStencilView);
|
memFree(pDepthStencilView);
|
||||||
depthStencilViewCreateInfo.free();
|
depthStencilViewCreateInfo.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create depth-stencil image view: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create depth-stencil image view: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
DepthStencil ret = new DepthStencil();
|
DepthStencil ret = new DepthStencil();
|
||||||
ret.view = depthStencilView;
|
ret.view = depthStencilView;
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -439,8 +418,7 @@ public class VulkanStarter
|
||||||
colorReference.free();
|
colorReference.free();
|
||||||
subpass.free();
|
subpass.free();
|
||||||
attachments.free();
|
attachments.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create clear render pass: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create clear render pass: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
return renderPass;
|
return renderPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,8 +441,7 @@ public class VulkanStarter
|
||||||
attachments.put(0, swapchain.imageViews[i]);
|
attachments.put(0, swapchain.imageViews[i]);
|
||||||
int err = vkCreateFramebuffer(device, fci, null, pFramebuffer);
|
int err = vkCreateFramebuffer(device, fci, null, pFramebuffer);
|
||||||
long framebuffer = pFramebuffer.get(0);
|
long framebuffer = pFramebuffer.get(0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create framebuffer: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create framebuffer: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
framebuffers[i] = framebuffer;
|
framebuffers[i] = framebuffer;
|
||||||
}
|
}
|
||||||
memFree(attachments);
|
memFree(attachments);
|
||||||
|
@ -487,7 +464,7 @@ public class VulkanStarter
|
||||||
memFree(pCommandBuffers);
|
memFree(pCommandBuffers);
|
||||||
submitInfo.free();
|
submitInfo.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS)
|
||||||
{ throw new AssertionError("Failed to submit command buffer: " + VKUtils.translateVulkanResult(err)); }
|
throw new AssertionError("Failed to submit command buffer: " + VKUtils.translateVulkanResult(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Vertices
|
private static class Vertices
|
||||||
|
@ -523,8 +500,7 @@ public class VulkanStarter
|
||||||
long verticesBuf = pBuffer.get(0);
|
long verticesBuf = pBuffer.get(0);
|
||||||
memFree(pBuffer);
|
memFree(pBuffer);
|
||||||
bufInfo.free();
|
bufInfo.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create vertex buffer: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create vertex buffer: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
vkGetBufferMemoryRequirements(device, verticesBuf, memReqs);
|
vkGetBufferMemoryRequirements(device, verticesBuf, memReqs);
|
||||||
memAlloc.allocationSize(memReqs.size());
|
memAlloc.allocationSize(memReqs.size());
|
||||||
IntBuffer memoryTypeIndex = memAllocInt(1);
|
IntBuffer memoryTypeIndex = memAllocInt(1);
|
||||||
|
@ -536,21 +512,18 @@ public class VulkanStarter
|
||||||
err = vkAllocateMemory(device, memAlloc, null, pMemory);
|
err = vkAllocateMemory(device, memAlloc, null, pMemory);
|
||||||
long verticesMem = pMemory.get(0);
|
long verticesMem = pMemory.get(0);
|
||||||
memFree(pMemory);
|
memFree(pMemory);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to allocate vertex memory: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to allocate vertex memory: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
PointerBuffer pData = memAllocPointer(1);
|
PointerBuffer pData = memAllocPointer(1);
|
||||||
err = vkMapMemory(device, verticesMem, 0, vertexBuffer.remaining(), 0, pData);
|
err = vkMapMemory(device, verticesMem, 0, vertexBuffer.remaining(), 0, pData);
|
||||||
memAlloc.free();
|
memAlloc.free();
|
||||||
long data = pData.get(0);
|
long data = pData.get(0);
|
||||||
memFree(pData);
|
memFree(pData);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to map vertex memory: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to map vertex memory: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
memCopy(memAddress(vertexBuffer), data, vertexBuffer.remaining());
|
memCopy(memAddress(vertexBuffer), data, vertexBuffer.remaining());
|
||||||
memFree(vertexBuffer);
|
memFree(vertexBuffer);
|
||||||
vkUnmapMemory(device, verticesMem);
|
vkUnmapMemory(device, verticesMem);
|
||||||
err = vkBindBufferMemory(device, verticesBuf, verticesMem, 0);
|
err = vkBindBufferMemory(device, verticesBuf, verticesMem, 0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to bind memory to vertex buffer: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to bind memory to vertex buffer: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Binding description
|
// Binding description
|
||||||
VkVertexInputBindingDescription.Buffer bindingDescriptor = VkVertexInputBindingDescription.calloc(1)
|
VkVertexInputBindingDescription.Buffer bindingDescriptor = VkVertexInputBindingDescription.calloc(1)
|
||||||
.binding(0) // <- we bind our vertex buffer to point 0
|
.binding(0) // <- we bind our vertex buffer to point 0
|
||||||
|
@ -608,8 +581,7 @@ public class VulkanStarter
|
||||||
memFree(pDescriptorPool);
|
memFree(pDescriptorPool);
|
||||||
descriptorPoolInfo.free();
|
descriptorPoolInfo.free();
|
||||||
typeCounts.free();
|
typeCounts.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create descriptor pool: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create descriptor pool: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
return descriptorPool;
|
return descriptorPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,8 +599,7 @@ public class VulkanStarter
|
||||||
memFree(pDescriptorSet);
|
memFree(pDescriptorSet);
|
||||||
allocInfo.free();
|
allocInfo.free();
|
||||||
memFree(pDescriptorSetLayout);
|
memFree(pDescriptorSetLayout);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create descriptor set: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create descriptor set: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Update descriptor sets determining the shader binding points
|
// Update descriptor sets determining the shader binding points
|
||||||
// For every binding point used in a shader there needs to be one
|
// For every binding point used in a shader there needs to be one
|
||||||
// descriptor set matching that binding point
|
// descriptor set matching that binding point
|
||||||
|
@ -669,8 +640,7 @@ public class VulkanStarter
|
||||||
memFree(pDescriptorSetLayout);
|
memFree(pDescriptorSetLayout);
|
||||||
descriptorLayout.free();
|
descriptorLayout.free();
|
||||||
layoutBinding.free();
|
layoutBinding.free();
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create descriptor set layout: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create descriptor set layout: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
return descriptorSetLayout;
|
return descriptorSetLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,7 +654,7 @@ public class VulkanStarter
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException
|
||||||
{
|
{
|
||||||
Window.create(1200, 600, "Vulkan Ginger3D", 60, RenderAPI.Vulkan);
|
Window.create(1280, 720, "Vulkan Ginger3D", 60, RenderAPI.Vulkan);
|
||||||
/* Look for instance extensions */
|
/* Look for instance extensions */
|
||||||
PointerBuffer requiredExtensions = glfwGetRequiredInstanceExtensions();
|
PointerBuffer requiredExtensions = glfwGetRequiredInstanceExtensions();
|
||||||
if (requiredExtensions == null)
|
if (requiredExtensions == null)
|
||||||
|
@ -756,8 +726,7 @@ public class VulkanStarter
|
||||||
vkDestroyFramebuffer(device, framebuffers[i], null); }
|
vkDestroyFramebuffer(device, framebuffers[i], null); }
|
||||||
framebuffers = createFramebuffers(device, swapchain, renderPass, Window.getWidth(), Window.getHeight(), depthStencil);
|
framebuffers = createFramebuffers(device, swapchain, renderPass, Window.getWidth(), Window.getHeight(), depthStencil);
|
||||||
// Create render command buffers
|
// Create render command buffers
|
||||||
if (renderCommandBuffers != null)
|
if (renderCommandBuffers != null) vkResetCommandPool(device, renderCommandPool, VKUtils.VK_FLAGS_NONE);
|
||||||
{ vkResetCommandPool(device, renderCommandPool, VKUtils.VK_FLAGS_NONE); }
|
|
||||||
renderCommandBuffers = VKUtils.initRenderCommandBuffers(device, renderCommandPool, framebuffers, renderPass, Window.getWidth(), Window.getHeight(), pipeline, descriptorSet,
|
renderCommandBuffers = VKUtils.initRenderCommandBuffers(device, renderCommandPool, framebuffers, renderPass, Window.getWidth(), Window.getHeight(), pipeline, descriptorSet,
|
||||||
vertices.verticesBuf);
|
vertices.verticesBuf);
|
||||||
mustRecreate = false;
|
mustRecreate = false;
|
||||||
|
@ -769,8 +738,7 @@ public class VulkanStarter
|
||||||
{
|
{
|
||||||
public void invoke(long window, int width, int height)
|
public void invoke(long window, int width, int height)
|
||||||
{
|
{
|
||||||
if (width <= 0 || height <= 0)
|
if (width <= 0 || height <= 0) return;
|
||||||
return;
|
|
||||||
swapchainRecreator.mustRecreate = true;
|
swapchainRecreator.mustRecreate = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -812,22 +780,18 @@ public class VulkanStarter
|
||||||
// Handle window messages. Resize events happen exactly here.
|
// Handle window messages. Resize events happen exactly here.
|
||||||
// So it is safe to use the new swapchain images and framebuffers afterwards.
|
// So it is safe to use the new swapchain images and framebuffers afterwards.
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
if (swapchainRecreator.mustRecreate)
|
if (swapchainRecreator.mustRecreate) swapchainRecreator.recreate();
|
||||||
swapchainRecreator.recreate();
|
|
||||||
// Create a semaphore to wait for the swapchain to acquire the next image
|
// Create a semaphore to wait for the swapchain to acquire the next image
|
||||||
err = vkCreateSemaphore(device, semaphoreCreateInfo, null, pImageAcquiredSemaphore);
|
err = vkCreateSemaphore(device, semaphoreCreateInfo, null, pImageAcquiredSemaphore);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create image acquired semaphore: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create image acquired semaphore: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Create a semaphore to wait for the render to complete, before presenting
|
// Create a semaphore to wait for the render to complete, before presenting
|
||||||
err = vkCreateSemaphore(device, semaphoreCreateInfo, null, pRenderCompleteSemaphore);
|
err = vkCreateSemaphore(device, semaphoreCreateInfo, null, pRenderCompleteSemaphore);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to create render complete semaphore: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to create render complete semaphore: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Get next image from the swap chain (back/front buffer).
|
// Get next image from the swap chain (back/front buffer).
|
||||||
// This will setup the imageAquiredSemaphore to be signalled when the operation is complete
|
// This will setup the imageAquiredSemaphore to be signalled when the operation is complete
|
||||||
err = vkAcquireNextImageKHR(device, swapchain.swapchainHandle, VKConstants.MAX_UNSIGNED_INT, pImageAcquiredSemaphore.get(0), VK_NULL_HANDLE, pImageIndex);
|
err = vkAcquireNextImageKHR(device, swapchain.swapchainHandle, VKConstants.MAX_UNSIGNED_INT, pImageAcquiredSemaphore.get(0), VK_NULL_HANDLE, pImageIndex);
|
||||||
currentBuffer = pImageIndex.get(0);
|
currentBuffer = pImageIndex.get(0);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to acquire next swapchain image: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to acquire next swapchain image: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Select the command buffer for the current framebuffer image/attachment
|
// Select the command buffer for the current framebuffer image/attachment
|
||||||
pCommandBuffers.put(0, renderCommandBuffers[currentBuffer]);
|
pCommandBuffers.put(0, renderCommandBuffers[currentBuffer]);
|
||||||
// Update UBO
|
// Update UBO
|
||||||
|
@ -837,14 +801,12 @@ public class VulkanStarter
|
||||||
ubo.updateUbo(device, time);
|
ubo.updateUbo(device, time);
|
||||||
// Submit to the graphics queue
|
// Submit to the graphics queue
|
||||||
err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
|
err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to submit render queue: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to submit render queue: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Present the current buffer to the swap chain
|
// Present the current buffer to the swap chain
|
||||||
// This will display the image
|
// This will display the image
|
||||||
pSwapchains.put(0, swapchain.swapchainHandle);
|
pSwapchains.put(0, swapchain.swapchainHandle);
|
||||||
err = vkQueuePresentKHR(queue, presentInfo);
|
err = vkQueuePresentKHR(queue, presentInfo);
|
||||||
if (err != VK_SUCCESS)
|
if (err != VK_SUCCESS) throw new AssertionError("Failed to present the swapchain image: " + VKUtils.translateVulkanResult(err));
|
||||||
{ throw new AssertionError("Failed to present the swapchain image: " + VKUtils.translateVulkanResult(err)); }
|
|
||||||
// Create and submit post present barrier
|
// Create and submit post present barrier
|
||||||
vkQueueWaitIdle(queue);
|
vkQueueWaitIdle(queue);
|
||||||
// Destroy this semaphore (we will create a new one in the next frame)
|
// Destroy this semaphore (we will create a new one in the next frame)
|
||||||
|
|
Loading…
Reference in New Issue