From ccf107dff1450def80654a0fb44db654c0bcb2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mora?= Date: Mon, 17 Jun 2019 10:07:31 +0200 Subject: [PATCH] Headless benchmark --- Lily-Vulkan | 2 +- build.gradle | 2 +- .../org/sheepy/vsand/model/VSandPackage.java | 9 ++++ .../vsand/VSandHeadlessBenchmarkLauncher.java | 20 ++++++++ .../java/org/sheepy/vsand/VSandMainLoop.java | 51 +++++++++++-------- .../constants/VSandPushConstantAdapter.java | 14 +++-- 6 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandHeadlessBenchmarkLauncher.java diff --git a/Lily-Vulkan b/Lily-Vulkan index 2b352054..06563d13 160000 --- a/Lily-Vulkan +++ b/Lily-Vulkan @@ -1 +1 @@ -Subproject commit 2b352054eb9dbd570283da6da256721bd7bf94f6 +Subproject commit 06563d13944e40c25dc8b425bcb1f33c097078ae diff --git a/build.gradle b/build.gradle index db7280db..93aaf20c 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ subprojects { apply plugin: 'eclipse' apply plugin: "org.javamodularity.moduleplugin" - version "1.2.1" + version "1.2.2" sourceCompatibility = 11 targetCompatibility = 11 diff --git a/org.sheepy.vsand/src/generated/java/org/sheepy/vsand/model/VSandPackage.java b/org.sheepy.vsand/src/generated/java/org/sheepy/vsand/model/VSandPackage.java index ef252f18..e01fc2c0 100644 --- a/org.sheepy.vsand/src/generated/java/org/sheepy/vsand/model/VSandPackage.java +++ b/org.sheepy.vsand/src/generated/java/org/sheepy/vsand/model/VSandPackage.java @@ -123,6 +123,15 @@ public interface VSandPackage extends EPackage */ int VSAND_APPLICATION__RESIZEABLE = ApplicationPackage.APPLICATION__RESIZEABLE; + /** + * The feature id for the 'Headless' attribute. + * + * + * @generated + * @ordered + */ + int VSAND_APPLICATION__HEADLESS = ApplicationPackage.APPLICATION__HEADLESS; + /** * The feature id for the 'Title' attribute. * diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandHeadlessBenchmarkLauncher.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandHeadlessBenchmarkLauncher.java new file mode 100644 index 00000000..f05f21e9 --- /dev/null +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandHeadlessBenchmarkLauncher.java @@ -0,0 +1,20 @@ +package org.sheepy.vsand; + +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.sheepy.lily.core.api.application.ApplicationLauncher; +import org.sheepy.lily.vulkan.model.VulkanEngine; + +public class VSandHeadlessBenchmarkLauncher +{ + public static void main(String[] args) + { + final var application = VSandBenchmarkLauncher.createTestApplication(); + application.setHeadless(true); + final var vulkanEngine = (VulkanEngine) application.getEngines().get(0); + EcoreUtil.delete(vulkanEngine.getProcesses().get(1)); + + final var mainLoop = VSandMainLoop.createBenchmark(application, 1400); + + ApplicationLauncher.launch(application, mainLoop); + } +} diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java index 21626982..5a3d0783 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java @@ -56,25 +56,33 @@ public void load(Application _application) { final var vulkanEngine = (VulkanEngine) application.getEngines().get(0); engineAdapter = IVulkanEngineAdapter.adapt(vulkanEngine); - final Window window = engineAdapter.getWindow(); - frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9); - inputManager = engineAdapter.getInputManager(); + if (application.isHeadless() == false) + { + final Window window = engineAdapter.getWindow(); + frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9); + inputManager = engineAdapter.getInputManager(); + if (benchmarkMode == false) + { + final var boardSize = new Vector2i(application.getSize()); + final var mainDrawManager = new DrawManager(application, inputManager, boardSize); + final var secondaryDrawManager = new DrawManager(application, inputManager, + boardSize); + final var vsandInputManager = new VSandInputManager(window, application, + mainDrawManager, secondaryDrawManager); + inputManager.addListener(vsandInputManager); + } + } gatherProcesses(vulkanEngine); - final var boardSize = new Vector2i(application.getSize()); - final var mainDrawManager = new DrawManager(application, inputManager, boardSize); - final var secondaryDrawManager = new DrawManager(application, inputManager, boardSize); + startNs = System.nanoTime(); + nextRenderDate = System.nanoTime() + frameDurationNs; + - if (benchmarkMode == false) + if (benchmarkMode == true) { - final var vsandInputManager = new VSandInputManager(window, application, - mainDrawManager, secondaryDrawManager); - inputManager.addListener(vsandInputManager); + System.out.println("VSand benchmark is running..."); } - - startNs = System.nanoTime(); - nextRenderDate = System.nanoTime() + frameDurationNs; } private void gatherProcesses(VulkanEngine vulkanEngine) @@ -106,16 +114,19 @@ public void step(Application _application) application.setPaused(true); } - if (benchmarkMode == false) + if (renderProcessAdapter != null) { - renderProcessAdapter.prepareNextAndExecute(); - } - else - { - if (nextRenderDate < System.nanoTime()) + if (benchmarkMode == false) { renderProcessAdapter.prepareNextAndExecute(); - nextRenderDate = System.nanoTime() + frameDurationNs; + } + else + { + if (nextRenderDate < System.nanoTime()) + { + renderProcessAdapter.prepareNextAndExecute(); + nextRenderDate = System.nanoTime() + frameDurationNs; + } } } diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/constants/VSandPushConstantAdapter.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/constants/VSandPushConstantAdapter.java index d758a3f8..4fe31915 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/constants/VSandPushConstantAdapter.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/constants/VSandPushConstantAdapter.java @@ -93,9 +93,17 @@ public void updateBuffer() buffer.putInt(application.isShowSleepZones() ? 1 : 0); buffer.putInt(size.getSize() >> 1); - final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition()); - buffer.putInt(cursorPosition.x); - buffer.putInt(cursorPosition.y); + if (inputManager != null) + { + final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition()); + buffer.putInt(cursorPosition.x); + buffer.putInt(cursorPosition.y); + } + else + { + buffer.putInt(0); + buffer.putInt(0); + } final Material mainMaterial = application.getMainMaterial(); final int index = application.getMaterials().getMaterials().indexOf(mainMaterial);