Skip to content

Commit

Permalink
Created frame sync objects
Browse files Browse the repository at this point in the history
  • Loading branch information
MarconZet committed Oct 30, 2019
1 parent 57705de commit b327ad0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class GraphicsConfig {
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
public static final int DESCRIPTOR_POOL_MAX_SETS = 100;
public static final int MAX_FRAMES_IN_FLIGHT = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.warpgame.engine.graphics.command;

import net.warpgame.engine.graphics.core.Device;
import net.warpgame.engine.graphics.utility.Destroyable;
import net.warpgame.engine.graphics.utility.VulkanAssertionError;
import org.lwjgl.BufferUtils;
import org.lwjgl.vulkan.VkSemaphoreCreateInfo;

import java.nio.LongBuffer;

import static org.lwjgl.vulkan.VK10.*;

/**
* @author MarconZet
* Created 30.10.2019
*/
public class Semaphore implements Destroyable {
private long semaphore;

private Device device;

public Semaphore(Device device) {
this.device = device;
create();
}

@Override
public void destroy() {
vkDestroySemaphore(device.get(), semaphore, null);
}

private void create(){
VkSemaphoreCreateInfo semaphoreCreateInfo = VkSemaphoreCreateInfo.create()
.sType(VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO);
LongBuffer pointer = BufferUtils.createLongBuffer(1);
int err = vkCreateSemaphore(device.get(), semaphoreCreateInfo, null, pointer);
if (err != VK_SUCCESS) {
throw new VulkanAssertionError("Failed to create semaphore", err);
}
this.semaphore = pointer.get();
}

public long get(){
return this.semaphore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ public class RecordingTask extends EngineTask {
private GraphicsPipeline graphicsPipeline;
private Device device;

public RecordingTask(DescriptorPool descriptorPool, GraphicsQueue graphicsQueue, Device device, SceneHolder sceneHolder) {
public RecordingTask(DescriptorPool descriptorPool, GraphicsQueue graphicsQueue, Device device, SceneHolder sceneHolder, RenderPass renderPass, SwapChain swapChain, GraphicsPipeline graphicsPipeline) {
this.descriptorPool = descriptorPool;
this.graphicsQueue = graphicsQueue;
this.device = device;
this.renderPass = renderPass;
this.swapChain = swapChain;
this.graphicsPipeline = graphicsPipeline;
this.recreate = true;
this.sceneHolder = sceneHolder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.warpgame.engine.graphics.rendering;

import net.warpgame.engine.core.context.service.Profile;
import net.warpgame.engine.core.context.service.Service;
import net.warpgame.engine.core.context.task.RegisterTask;
import net.warpgame.engine.core.execution.task.EngineTask;
import net.warpgame.engine.graphics.command.Fence;
import net.warpgame.engine.graphics.command.Semaphore;
import net.warpgame.engine.graphics.core.Device;

import static net.warpgame.engine.graphics.GraphicsConfig.MAX_FRAMES_IN_FLIGHT;
import static org.lwjgl.vulkan.VK10.VK_FENCE_CREATE_SIGNALED_BIT;

/**
* @author MarconZet
* Created 30.10.2019
*/

@Service
@Profile("graphics")
@RegisterTask(thread = "graphics")
public class VulkanRenderTask extends EngineTask {

private Semaphore[] imageAvailableSemaphore;
private Semaphore[] renderFinishedSemaphore;
private Fence[] inFlightFences;

private Device device;

public VulkanRenderTask(Device device) {
this.device = device;
}

@Override
protected void onInit() {
imageAvailableSemaphore = new Semaphore[MAX_FRAMES_IN_FLIGHT];
renderFinishedSemaphore = new Semaphore[MAX_FRAMES_IN_FLIGHT];
inFlightFences = new Fence[MAX_FRAMES_IN_FLIGHT];

for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
imageAvailableSemaphore[i] = new Semaphore(device);
renderFinishedSemaphore[i] = new Semaphore(device);
inFlightFences[i] = new Fence(device, VK_FENCE_CREATE_SIGNALED_BIT);
}
}

@Override
public void update(int delta) {

}

@Override
protected void onClose() {
for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
imageAvailableSemaphore[i].destroy();
renderFinishedSemaphore[i].destroy();
inFlightFences[i].destroy();
}
}

}

0 comments on commit b327ad0

Please sign in to comment.