yay improvments

pull/12/head
hYdos 2020-03-03 15:43:19 +10:00
parent 40a9e3d7c7
commit 75f7f37b41
5 changed files with 43 additions and 77 deletions

View File

@ -1,54 +1,22 @@
package com.github.hydos.ginger; package com.github.hydos.ginger;
import java.io.IOException; import java.io.IOException;
import java.nio.IntBuffer; import java.nio.*;
import java.nio.LongBuffer;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.*;
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWVulkan;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import org.lwjgl.vulkan.EXTDebugReport; import org.lwjgl.vulkan.*;
import org.lwjgl.vulkan.KHRSwapchain;
import org.lwjgl.vulkan.VK12;
import org.lwjgl.vulkan.VkCommandBuffer;
import org.lwjgl.vulkan.VkCommandBufferAllocateInfo;
import org.lwjgl.vulkan.VkCommandBufferBeginInfo;
import org.lwjgl.vulkan.VkCommandPoolCreateInfo;
import org.lwjgl.vulkan.VkDescriptorBufferInfo;
import org.lwjgl.vulkan.VkDescriptorPoolCreateInfo;
import org.lwjgl.vulkan.VkDescriptorPoolSize;
import org.lwjgl.vulkan.VkDescriptorSetAllocateInfo;
import org.lwjgl.vulkan.VkDescriptorSetLayoutBinding;
import org.lwjgl.vulkan.VkDescriptorSetLayoutCreateInfo;
import org.lwjgl.vulkan.VkDevice;
import org.lwjgl.vulkan.VkFormatProperties;
import org.lwjgl.vulkan.VkInstance;
import org.lwjgl.vulkan.VkPhysicalDevice;
import org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties;
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
import org.lwjgl.vulkan.VkPresentInfoKHR;
import org.lwjgl.vulkan.VkQueue;
import org.lwjgl.vulkan.VkSemaphoreCreateInfo;
import org.lwjgl.vulkan.VkSubmitInfo;
import org.lwjgl.vulkan.VkWriteDescriptorSet;
import com.github.hydos.ginger.engine.common.info.RenderAPI; import com.github.hydos.ginger.engine.common.info.RenderAPI;
import com.github.hydos.ginger.engine.common.io.Window; import com.github.hydos.ginger.engine.common.io.Window;
import com.github.hydos.ginger.engine.vulkan.TempMethods; import com.github.hydos.ginger.engine.vulkan.*;
import com.github.hydos.ginger.engine.vulkan.VKConstants;
import com.github.hydos.ginger.engine.vulkan.api.VKGinger; import com.github.hydos.ginger.engine.vulkan.api.VKGinger;
import com.github.hydos.ginger.engine.vulkan.render.renderers.ExampleRenderer; import com.github.hydos.ginger.engine.vulkan.model.VKVertices;
import com.github.hydos.ginger.engine.vulkan.render.renderers.VKMasterRenderer; import com.github.hydos.ginger.engine.vulkan.render.renderers.*;
import com.github.hydos.ginger.engine.vulkan.render.ubo.Ubo; import com.github.hydos.ginger.engine.vulkan.render.ubo.*;
import com.github.hydos.ginger.engine.vulkan.render.ubo.UboDescriptor; import com.github.hydos.ginger.engine.vulkan.shaders.*;
import com.github.hydos.ginger.engine.vulkan.shaders.Pipeline; import com.github.hydos.ginger.engine.vulkan.utils.*;
import com.github.hydos.ginger.engine.vulkan.shaders.ShaderType;
import com.github.hydos.ginger.engine.vulkan.utils.VKDeviceProperties;
import com.github.hydos.ginger.engine.vulkan.utils.VKLoader;
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
/** @author hydos06 /** @author hydos06
* the non ARR vulkan test example */ * the non ARR vulkan test example */
@ -158,12 +126,6 @@ public class VulkanStarter
{ throw new AssertionError("Failed to submit command buffer: " + VKUtils.translateVulkanResult(err)); } { throw new AssertionError("Failed to submit command buffer: " + VKUtils.translateVulkanResult(err)); }
} }
public static class Vertices
{
public long verticesBuf;
public VkPipelineVertexInputStateCreateInfo createInfo;
}
private static long createDescriptorPool(VkDevice device) private static long createDescriptorPool(VkDevice device)
{ {
// We need to tell the API the number of max. requested descriptors per type // We need to tell the API the number of max. requested descriptors per type
@ -303,7 +265,7 @@ public class VulkanStarter
final VkQueue queue = createDeviceQueue(device, queueFamilyIndex); final VkQueue queue = createDeviceQueue(device, queueFamilyIndex);
final long renderPass = ExampleRenderer.createRenderPass(device, colorAndDepthFormatAndSpace.colorFormat, colorAndDepthFormatAndSpace.depthFormat); final long renderPass = ExampleRenderer.createRenderPass(device, colorAndDepthFormatAndSpace.colorFormat, colorAndDepthFormatAndSpace.depthFormat);
final long renderCommandPool = createCommandPool(device, queueFamilyIndex); final long renderCommandPool = createCommandPool(device, queueFamilyIndex);
Vertices vertices = TempMethods.createVertices(memoryProperties, device); VKVertices vertices = TempMethods.createVertices(memoryProperties, device);
Ubo ubo = new Ubo(memoryProperties, device); Ubo ubo = new Ubo(memoryProperties, device);
final long descriptorPool = createDescriptorPool(device); final long descriptorPool = createDescriptorPool(device);
final long descriptorSetLayout = createDescriptorSetLayout(device); final long descriptorSetLayout = createDescriptorSetLayout(device);
@ -341,7 +303,7 @@ public class VulkanStarter
if (renderCommandBuffers != null) if (renderCommandBuffers != null)
{ VK12.vkResetCommandPool(device, renderCommandPool, VKUtils.VK_FLAGS_NONE); } { VK12.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.vkVerticiesBuffer);
mustRecreate = false; mustRecreate = false;
} }
} }

View File

@ -1,37 +1,20 @@
package com.github.hydos.ginger.engine.vulkan; package com.github.hydos.ginger.engine.vulkan;
import static org.lwjgl.system.MemoryUtil.memAddress; import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.MemoryUtil.memAlloc;
import static org.lwjgl.system.MemoryUtil.memAllocInt;
import static org.lwjgl.system.MemoryUtil.memAllocLong;
import static org.lwjgl.system.MemoryUtil.memAllocPointer;
import static org.lwjgl.system.MemoryUtil.memCopy;
import static org.lwjgl.system.MemoryUtil.memFree;
import java.nio.ByteBuffer; import java.nio.*;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.vulkan.VK12; import org.lwjgl.vulkan.*;
import org.lwjgl.vulkan.VkBufferCreateInfo;
import org.lwjgl.vulkan.VkDevice;
import org.lwjgl.vulkan.VkMemoryAllocateInfo;
import org.lwjgl.vulkan.VkMemoryRequirements;
import org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties;
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
import org.lwjgl.vulkan.VkVertexInputAttributeDescription;
import org.lwjgl.vulkan.VkVertexInputBindingDescription;
import com.github.hydos.ginger.VulkanStarter.Vertices;
import com.github.hydos.ginger.engine.vulkan.memory.VKMemory; import com.github.hydos.ginger.engine.vulkan.memory.VKMemory;
import com.github.hydos.ginger.engine.vulkan.model.VKVertices;
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils; import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
public class TempMethods public class TempMethods
{ {
public static Vertices createVertices(VkPhysicalDeviceMemoryProperties deviceMemoryProperties, VkDevice device) public static VKVertices createVertices(VkPhysicalDeviceMemoryProperties deviceMemoryProperties, VkDevice device)
{ {
ByteBuffer vertexBuffer = memAlloc(2 * 3 * (3 + 3) * 4); ByteBuffer vertexBuffer = memAlloc(2 * 3 * (3 + 3) * 4);
FloatBuffer fb = vertexBuffer.asFloatBuffer(); FloatBuffer fb = vertexBuffer.asFloatBuffer();
@ -111,9 +94,9 @@ public class TempMethods
vi.sType(VK12.VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO); vi.sType(VK12.VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO);
vi.pVertexBindingDescriptions(bindingDescriptor); vi.pVertexBindingDescriptions(bindingDescriptor);
vi.pVertexAttributeDescriptions(attributeDescriptions); vi.pVertexAttributeDescriptions(attributeDescriptions);
Vertices ret = new Vertices(); VKVertices ret = new VKVertices();
ret.createInfo = vi; ret.createInfo = vi;
ret.verticesBuf = verticesBuf; ret.vkVerticiesBuffer = verticesBuf;
return ret; return ret;
} }

View File

@ -0,0 +1,11 @@
package com.github.hydos.ginger.engine.vulkan.model;
public class VKModelConverter
{
public VKVertices toVKVerticies()
{
return null;
}
}

View File

@ -0,0 +1,10 @@
package com.github.hydos.ginger.engine.vulkan.model;
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
public class VKVertices
{
public long vkVerticiesBuffer;
public VkPipelineVertexInputStateCreateInfo createInfo;
public float[] commonVerticies;
}

View File

@ -32,8 +32,8 @@ import org.lwjgl.vulkan.VkVertexInputBindingDescription;
import com.github.hydos.ginger.VulkanStarter.DepthStencil; import com.github.hydos.ginger.VulkanStarter.DepthStencil;
import com.github.hydos.ginger.VulkanStarter.Swapchain; import com.github.hydos.ginger.VulkanStarter.Swapchain;
import com.github.hydos.ginger.VulkanStarter.Vertices;
import com.github.hydos.ginger.engine.vulkan.memory.VKMemory; import com.github.hydos.ginger.engine.vulkan.memory.VKMemory;
import com.github.hydos.ginger.engine.vulkan.model.VKVertices;
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils; import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
public class ExampleRenderer public class ExampleRenderer
@ -119,7 +119,7 @@ public class ExampleRenderer
return framebuffers; return framebuffers;
} }
public static Vertices createVertices(VkPhysicalDeviceMemoryProperties deviceMemoryProperties, VkDevice device) public static VKVertices createVertices(VkPhysicalDeviceMemoryProperties deviceMemoryProperties, VkDevice device)
{ {
ByteBuffer vertexBuffer = memAlloc(2 * 3 * (3 + 3) * 4); ByteBuffer vertexBuffer = memAlloc(2 * 3 * (3 + 3) * 4);
FloatBuffer fb = vertexBuffer.asFloatBuffer(); FloatBuffer fb = vertexBuffer.asFloatBuffer();
@ -199,9 +199,9 @@ public class ExampleRenderer
vi.sType(VK12.VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO); vi.sType(VK12.VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO);
vi.pVertexBindingDescriptions(bindingDescriptor); vi.pVertexBindingDescriptions(bindingDescriptor);
vi.pVertexAttributeDescriptions(attributeDescriptions); vi.pVertexAttributeDescriptions(attributeDescriptions);
Vertices ret = new Vertices(); VKVertices ret = new VKVertices();
ret.createInfo = vi; ret.createInfo = vi;
ret.verticesBuf = verticesBuf; ret.vkVerticiesBuffer = verticesBuf;
return ret; return ret;
} }
} }