-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
graphics/src/main/java/net/warpgame/engine/graphics/command/Semaphore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
graphics/src/main/java/net/warpgame/engine/graphics/rendering/VulkanRenderTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |