IT RENDERS RAHHHHHHHHHH COLOURS CAN BE SHOWN, AAAAND UPDATED LIVE OH YEAHHH THIS IS CAUSE FOR CELEBRATION
This commit is contained in:
parent
4e606e094a
commit
7428616d5c
8 changed files with 65 additions and 17 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package net.halbear.Terrain4J.EngineCore.Display;
|
package net.halbear.Terrain4J.EngineCore.Display;
|
||||||
|
|
||||||
|
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||||
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
||||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||||
|
|
@ -15,7 +16,6 @@ import org.lwjgl.vulkan.VkCommandBufferSubmitInfo;
|
||||||
import org.lwjgl.vulkan.VkSemaphoreSubmitInfo;
|
import org.lwjgl.vulkan.VkSemaphoreSubmitInfo;
|
||||||
import org.tinylog.Logger;
|
import org.tinylog.Logger;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.lwjgl.vulkan.VK13.VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT;
|
import static org.lwjgl.vulkan.VK13.VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT;
|
||||||
|
|
@ -36,7 +36,7 @@ public class Render {
|
||||||
|
|
||||||
public Render(EngineInstance engineInstance) {
|
public Render(EngineInstance engineInstance) {
|
||||||
RendererContext = new VulkanContext(engineInstance.window());
|
RendererContext = new VulkanContext(engineInstance.window());
|
||||||
|
CurrentFrame = 0;
|
||||||
GraphicsQueue = new Queue.GraphicsQueue(RendererContext, 0);
|
GraphicsQueue = new Queue.GraphicsQueue(RendererContext, 0);
|
||||||
PresentQueue = new Queue.PresentQueue(RendererContext, 0);
|
PresentQueue = new Queue.PresentQueue(RendererContext, 0);
|
||||||
CommandPools= new CommandPool[VulkanUtils.MAX_IN_FLIGHT];
|
CommandPools= new CommandPool[VulkanUtils.MAX_IN_FLIGHT];
|
||||||
|
|
@ -68,19 +68,25 @@ public class Render {
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
RendererContext.GetDevice().waitIdle();
|
RendererContext.GetDevice().waitIdle();
|
||||||
|
Logger.debug("Waiting Vulkan Context");
|
||||||
sceneRender.cleanup();
|
sceneRender.cleanup();
|
||||||
|
Logger.debug("Dynamic Renderer Cleaned up");
|
||||||
Arrays.asList(RenderCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
Arrays.asList(RenderCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
||||||
|
Logger.debug("Render Semaphores cleaned up");
|
||||||
Arrays.asList(PresentCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
Arrays.asList(PresentCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
||||||
|
Logger.debug("Present Semaphores cleaned up");
|
||||||
Arrays.asList(Fences).forEach(i->i.cleanup(RendererContext));
|
Arrays.asList(Fences).forEach(i->i.cleanup(RendererContext));
|
||||||
|
Logger.debug("Fences cleaned up");
|
||||||
for(int i = 0; i < CommandPools.length; i++){
|
for(int i = 0; i < CommandPools.length; i++){
|
||||||
CommandBuffers[i].cleanup(RendererContext, CommandPools[i]);
|
CommandBuffers[i].cleanup(RendererContext, CommandPools[i]);
|
||||||
CommandPools[i].cleanup(RendererContext);
|
CommandPools[i].cleanup(RendererContext);
|
||||||
}
|
}
|
||||||
|
Logger.debug("Command pools cleaned up");
|
||||||
RendererContext.cleanup();
|
RendererContext.cleanup();
|
||||||
}
|
}
|
||||||
public void render(EngineInstance engineInstance){
|
public void render(EngineInstance engineInstance){
|
||||||
SwapChain swapChain = RendererContext.GetSwapChain();
|
SwapChain swapChain = RendererContext.GetSwapChain();
|
||||||
WaitForFence(CurrentFrame);
|
WaitForFence(CurrentFrame); //problem child found
|
||||||
var CommandPool = CommandPools[CurrentFrame];
|
var CommandPool = CommandPools[CurrentFrame];
|
||||||
var CommandBuffer = CommandBuffers[CurrentFrame];
|
var CommandBuffer = CommandBuffers[CurrentFrame];
|
||||||
RecordingStart(CommandPool, CommandBuffer);
|
RecordingStart(CommandPool, CommandBuffer);
|
||||||
|
|
@ -94,7 +100,10 @@ public class Render {
|
||||||
swapChain.PresentImage(PresentQueue, RenderCompleteSemaphores[ImageIndex],ImageIndex);
|
swapChain.PresentImage(PresentQueue, RenderCompleteSemaphores[ImageIndex],ImageIndex);
|
||||||
CurrentFrame = (CurrentFrame + 1) % VulkanUtils.MAX_IN_FLIGHT;
|
CurrentFrame = (CurrentFrame + 1) % VulkanUtils.MAX_IN_FLIGHT;
|
||||||
}
|
}
|
||||||
|
private void ResetFence(int currentFrame){
|
||||||
|
var fence = Fences[currentFrame];
|
||||||
|
fence.Reset(RendererContext);
|
||||||
|
}
|
||||||
private void WaitForFence(int currentFrame){
|
private void WaitForFence(int currentFrame){
|
||||||
var fence = Fences[currentFrame];
|
var fence = Fences[currentFrame];
|
||||||
fence.FenceWait(RendererContext);
|
fence.FenceWait(RendererContext);
|
||||||
|
|
@ -114,8 +123,8 @@ public class Render {
|
||||||
VkSemaphoreSubmitInfo.Buffer SemaphoreSignals = VkSemaphoreSubmitInfo.calloc(1, MemStack)
|
VkSemaphoreSubmitInfo.Buffer SemaphoreSignals = VkSemaphoreSubmitInfo.calloc(1, MemStack)
|
||||||
.sType$Default()
|
.sType$Default()
|
||||||
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)
|
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)
|
||||||
.semaphore(RenderCompleteSemaphores[currentFrame].GetSemaphore());
|
.semaphore(RenderCompleteSemaphores[ImageIndex].GetSemaphore());
|
||||||
GraphicsQueue.Sumbit(Commands, SemaphoreWait, SemaphoreSignals, fence);
|
GraphicsQueue.Submit(Commands, SemaphoreWait, SemaphoreSignals, fence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class RenderThread implements Runnable {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
int TotalFrames = 0;
|
||||||
PrimaryRuntime.ThreadsOpen++;
|
PrimaryRuntime.ThreadsOpen++;
|
||||||
long InitialTime = System.nanoTime();
|
long InitialTime = System.nanoTime();
|
||||||
double FrameDiff =0;
|
double FrameDiff =0;
|
||||||
|
|
@ -55,11 +56,12 @@ public class RenderThread implements Runnable {
|
||||||
Frames++;
|
Frames++;
|
||||||
if (SecondCounter >= 1000000000L){
|
if (SecondCounter >= 1000000000L){
|
||||||
SecondCounter = 0;
|
SecondCounter = 0;
|
||||||
EngineConfig.FrameRate_RENDERTHREAD = Frames;
|
//EngineConfig.FrameRate_RENDERTHREAD = Frames;
|
||||||
Logger.info("Render FPS: " + Frames);
|
Logger.info("Render FPS: " + Frames);
|
||||||
Frames = 0;
|
Frames = 0;
|
||||||
}
|
}
|
||||||
render.render(PrimaryRuntime.GetEngineInstance());
|
render.render(PrimaryRuntime.GetEngineInstance());
|
||||||
|
TotalFrames++;
|
||||||
FrameDiff = 0;
|
FrameDiff = 0;
|
||||||
}
|
}
|
||||||
InitialTime = now;
|
InitialTime = now;
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class CommandBuffer {
|
||||||
var Commands = VkCommandBufferSubmitInfo.calloc(1, MemStack)
|
var Commands = VkCommandBufferSubmitInfo.calloc(1, MemStack)
|
||||||
.sType$Default()
|
.sType$Default()
|
||||||
.commandBuffer(VulkanCommandBuffer);
|
.commandBuffer(VulkanCommandBuffer);
|
||||||
queue.Sumbit(Commands, null, null, fence);
|
queue.Submit(Commands, null, null, fence);
|
||||||
}
|
}
|
||||||
fence.FenceWait(vulkanContext);
|
fence.FenceWait(vulkanContext);
|
||||||
fence.cleanup(vulkanContext);
|
fence.cleanup(vulkanContext);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ public class Fence {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup(VulkanContext vulkanContext){
|
public void cleanup(VulkanContext vulkanContext){
|
||||||
Logger.debug("Destroying Vulkan Fence");
|
|
||||||
vkDestroyFence(vulkanContext.GetDevice().FetchVulkanDevice(), VulkanFence, null);
|
vkDestroyFence(vulkanContext.GetDevice().FetchVulkanDevice(), VulkanFence, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class Queue {
|
||||||
vkQueueWaitIdle(VulkanQueue);
|
vkQueueWaitIdle(VulkanQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Sumbit(VkCommandBufferSubmitInfo.Buffer CommandBuffers, VkSemaphoreSubmitInfo.Buffer WaitSemaphores, VkSemaphoreSubmitInfo.Buffer SignalSemaphores, Fence fence){
|
public void Submit(VkCommandBufferSubmitInfo.Buffer CommandBuffers, VkSemaphoreSubmitInfo.Buffer WaitSemaphores, VkSemaphoreSubmitInfo.Buffer SignalSemaphores, Fence fence){
|
||||||
try(var MemStack = MemoryStack.stackPush()){
|
try(var MemStack = MemoryStack.stackPush()){
|
||||||
var SubmitInfo = VkSubmitInfo2.calloc(1, MemStack)
|
var SubmitInfo = VkSubmitInfo2.calloc(1, MemStack)
|
||||||
.sType$Default()
|
.sType$Default()
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen;
|
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen;
|
||||||
|
|
||||||
import net.halbear.Terrain4J.EngineCore.Display.Render;
|
import net.halbear.Terrain4J.EngineCore.Display.Render;
|
||||||
|
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||||
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
||||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
import org.lwjgl.vulkan.*;
|
import org.lwjgl.vulkan.*;
|
||||||
|
import org.tinylog.Logger;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
@ -16,16 +18,50 @@ import static org.lwjgl.vulkan.VK10.*;
|
||||||
import static org.lwjgl.vulkan.VK13.*;
|
import static org.lwjgl.vulkan.VK13.*;
|
||||||
|
|
||||||
public class SceneRender { //dynamic rendering;
|
public class SceneRender { //dynamic rendering;
|
||||||
private final VkClearValue ClearValueColour;
|
private VkClearValue ClearValueColour;
|
||||||
private VkRenderingAttachmentInfo.Buffer[] AttachmentInfoColour;
|
private VkRenderingAttachmentInfo.Buffer[] AttachmentInfoColour;
|
||||||
private VkRenderingInfo[] RenderInfo;
|
private VkRenderingInfo[] RenderInfo;
|
||||||
|
private float R = 0f;
|
||||||
|
private float G = 0.5f;
|
||||||
|
private float B = 0.7f;
|
||||||
|
private boolean Rb = false;
|
||||||
|
private boolean Gb = true;
|
||||||
|
private boolean Bb = false;
|
||||||
public SceneRender(VulkanContext vulkanContext){
|
public SceneRender(VulkanContext vulkanContext){
|
||||||
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,0.5f).float32(1,0.7f).float32(2,0.9f).float32(3,1.0f));
|
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,R).float32(1,G).float32(2,B).float32(3,1.0f));
|
||||||
|
AttachmentInfoColour = CreateColourAttachmentsInfo(vulkanContext,ClearValueColour);
|
||||||
|
RenderInfo = CreateRenderInfo(vulkanContext, AttachmentInfoColour);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateColours(VulkanContext vulkanContext){
|
||||||
|
if (Gb){
|
||||||
|
if (G < 1.0f && Math.random() <0.5) G+=0.0005f;
|
||||||
|
else if (G >= 1.0f) Gb = false;
|
||||||
|
} else{
|
||||||
|
if (G >0.0f&& Math.random() <0.5) G-=0.0005f;
|
||||||
|
else if (G <= 0.0f) Gb = true;
|
||||||
|
}
|
||||||
|
if (Rb){
|
||||||
|
if (R < 1.0f&& Math.random() <0.3) R+=0.0005f;
|
||||||
|
else if (R >= 1.0f) Rb = false;
|
||||||
|
} else{
|
||||||
|
if (R >0.0f&& Math.random() <0.3) R-=0.0005f;
|
||||||
|
else if (R <= 0.0f) Rb = true;
|
||||||
|
}
|
||||||
|
if (Bb){
|
||||||
|
if (B < 1.0f&& Math.random() <0.7) B+=0.0005f;
|
||||||
|
else if (B >= 1.0f) Bb = false;
|
||||||
|
} else{
|
||||||
|
if (B >0.0f&& Math.random() <0.7) B-=0.0005f;
|
||||||
|
else if (B <= 0.0f) Bb = true;
|
||||||
|
}
|
||||||
|
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,R).float32(1,G).float32(2,B).float32(3,1.0f));
|
||||||
AttachmentInfoColour = CreateColourAttachmentsInfo(vulkanContext,ClearValueColour);
|
AttachmentInfoColour = CreateColourAttachmentsInfo(vulkanContext,ClearValueColour);
|
||||||
RenderInfo = CreateRenderInfo(vulkanContext, AttachmentInfoColour);
|
RenderInfo = CreateRenderInfo(vulkanContext, AttachmentInfoColour);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(VulkanContext vulkanContext, CommandBuffer commandBuffer, int ImageIndex){
|
public void Render(VulkanContext vulkanContext, CommandBuffer commandBuffer, int ImageIndex){
|
||||||
|
EngineConfig.FrameRate_RENDERTHREAD++;
|
||||||
try(var MemStack = MemoryStack.stackPush()){
|
try(var MemStack = MemoryStack.stackPush()){
|
||||||
SwapChain swapChain = vulkanContext.GetSwapChain();
|
SwapChain swapChain = vulkanContext.GetSwapChain();
|
||||||
long SwapChainImage = swapChain.GetVulkanImageView(ImageIndex).GetVulkanImage();
|
long SwapChainImage = swapChain.GetVulkanImageView(ImageIndex).GetVulkanImage();
|
||||||
|
|
@ -34,7 +70,7 @@ public class SceneRender { //dynamic rendering;
|
||||||
VulkanUtils.ImageBarrier(MemStack, CommandHandle, SwapChainImage,
|
VulkanUtils.ImageBarrier(MemStack, CommandHandle, SwapChainImage,
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
VK_ACCESS_2_NONE,VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,VK_IMAGE_ASPECT_COLOR_BIT);
|
VK_ACCESS_2_NONE, VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||||
vkCmdBeginRendering(CommandHandle, RenderInfo[ImageIndex]);
|
vkCmdBeginRendering(CommandHandle, RenderInfo[ImageIndex]);
|
||||||
vkCmdEndRendering(CommandHandle);
|
vkCmdEndRendering(CommandHandle);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ public class SwapChain {
|
||||||
return Math.min(RequestedImages, MaxImages);
|
return Math.min(RequestedImages, MaxImages);
|
||||||
}
|
}
|
||||||
ReturnValue = Math.max(ReturnValue, MinImages);
|
ReturnValue = Math.max(ReturnValue, MinImages);
|
||||||
Logger.debug("Requested Image Count: [{}]\nReceived [{}] Images\nSurfaceCapabilities-> MaxImgs:[{}] MinImgs:[{}] ",RequestedImages,ReturnValue,MaxImages,MinImages);
|
|
||||||
return ReturnValue;
|
return ReturnValue;
|
||||||
}
|
}
|
||||||
public static VkExtent2D CalculateSwapChainExtent(Window window, VkSurfaceCapabilitiesKHR SurfaceCapabilities){
|
public static VkExtent2D CalculateSwapChainExtent(Window window, VkSurfaceCapabilitiesKHR SurfaceCapabilities){
|
||||||
|
|
@ -109,7 +108,7 @@ public class SwapChain {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
||||||
Logger.warn("Suboptimal surface properties match, not fatal");
|
//Logger.warn("Suboptimal surface properties match, not fatal");
|
||||||
} else if (Error != VK_SUCCESS){
|
} else if (Error != VK_SUCCESS){
|
||||||
throw new RuntimeException("Failed to fetch next image in the swapchain: " + Error);
|
throw new RuntimeException("Failed to fetch next image in the swapchain: " + Error);
|
||||||
}
|
}
|
||||||
|
|
@ -129,9 +128,12 @@ public class SwapChain {
|
||||||
int Error = KHRSwapchain.vkQueuePresentKHR(queue.GetVulkanQueue(), Present);
|
int Error = KHRSwapchain.vkQueuePresentKHR(queue.GetVulkanQueue(), Present);
|
||||||
if (Error == KHRSwapchain.VK_ERROR_OUT_OF_DATE_KHR){
|
if (Error == KHRSwapchain.VK_ERROR_OUT_OF_DATE_KHR){
|
||||||
resize = true;
|
resize = true;
|
||||||
|
//Logger.debug("Detected Resize");
|
||||||
|
//vkQueueWaitIdle(queue.GetVulkanQueue());
|
||||||
} else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
} else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
||||||
Logger.warn("Suboptimal surface properties match, not fatal");
|
//Logger.warn("Suboptimal surface properties match, not fatal");
|
||||||
} else if (Error != VK_SUCCESS){
|
} else if (Error != VK_SUCCESS){
|
||||||
|
Logger.debug("Failure in Present Image");
|
||||||
throw new RuntimeException("failed to present KHR: " + Error);
|
throw new RuntimeException("failed to present KHR: " + Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ cap_main_to_tickrate=false
|
||||||
#Vulkan Debugging toggle
|
#Vulkan Debugging toggle
|
||||||
vkValidated=true
|
vkValidated=true
|
||||||
|
|
||||||
vsync=true
|
vsync=false
|
||||||
RequestedImages=3
|
RequestedImages=3
|
||||||
#This is the name of the GPU you want the engine to use
|
#This is the name of the GPU you want the engine to use
|
||||||
PhysicalDeviceName=
|
PhysicalDeviceName=
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue