Skip to content

Commit

Permalink
Fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealrann committed Jul 15, 2020
1 parent 0c0e9df commit eba5865
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
3 changes: 2 additions & 1 deletion org.sheepy.vsand/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ run {

application {
mainModule = 'org.sheepy.vsand'
mainClass = 'org.sheepy.vsand.VSandApplicationLauncher'
// mainClass = 'org.sheepy.vsand.VSandApplicationLauncher'
mainClass = 'org.sheepy.vsand.VSandBenchmarkLauncher'
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.sheepy.lily.core.api.LilyLauncher;
import org.sheepy.lily.core.api.util.DebugUtil;
import org.sheepy.lily.vulkan.model.VulkanEngine;
import org.sheepy.lily.vulkan.model.process.graphic.GraphicProcess;
import org.sheepy.vsand.logic.VSandMainLoop;
import org.sheepy.vsand.model.DrawCommand;
import org.sheepy.vsand.model.Material;
Expand All @@ -18,9 +21,15 @@ public class VSandBenchmarkLauncher

public static void main(String[] args) throws IOException
{
DebugUtil.parseMainArgs(args);

final var application = createTestApplication();
final var mainLoop = VSandMainLoop.createBenchmark(application, DEFAULT_ITERATION_COUNT);

final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
final var graphicProcess = (GraphicProcess) vulkanEngine.getProcesses().get(1);
graphicProcess.getExecutionManager().getWaitForExecution().clear();

final var mainLoop = VSandMainLoop.createBenchmark(application, DEFAULT_ITERATION_COUNT);
LilyLauncher.launch(application, mainLoop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.eclipse.emf.ecore.util.EcoreUtil;
import org.sheepy.lily.core.api.LilyLauncher;
import org.sheepy.lily.core.api.util.DebugUtil;
import org.sheepy.lily.vulkan.model.VulkanEngine;
import org.sheepy.vsand.logic.VSandMainLoop;

Expand All @@ -11,10 +12,12 @@ public class VSandHeadlessBenchmarkLauncher
{
public static void main(String[] args) throws IOException
{
DebugUtil.parseMainArgs(args);

final var application = VSandBenchmarkLauncher.createTestApplication();
application.setScene(null);
final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
EcoreUtil.delete(vulkanEngine.getProcesses().get(1));
EcoreUtil.delete(vulkanEngine.getProcesses().get(1), true);

final var mainLoop = VSandMainLoop.createBenchmark(application, VSandBenchmarkLauncher.DEFAULT_ITERATION_COUNT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sheepy.lily.vulkan.model.process.IPipelineTask;
import org.sheepy.lily.vulkan.model.process.compute.ComputePipeline;
import org.sheepy.lily.vulkan.model.process.compute.ComputeProcess;
import org.sheepy.lily.vulkan.model.process.graphic.GraphicProcess;
import org.sheepy.vsand.model.VSandApplication;
import org.sheepy.vsand.util.FPSCounter;

Expand Down Expand Up @@ -66,9 +67,9 @@ public void run()
{
renderProcessAdapter.run();
}
else if (renderProcessAdapter != null)
else
{
if (nextRenderDate < System.nanoTime())
if (renderProcessAdapter != null && nextRenderDate < System.nanoTime())
{
renderProcessAdapter.run();
nextRenderDate = System.nanoTime() + frameDurationNs;
Expand Down Expand Up @@ -96,7 +97,8 @@ private void load()
final var boardToPixelPipeline = (ComputePipeline) (boardProcess.getPipelinePkg().getPipelines().get(2));
boardProcessAdapter = boardProcess.adaptNotNull(IProcessAdapter.class);
boardImageBarrier = boardToPixelPipeline.getTaskPkgs().get(0).getTasks().get(2);
renderProcessAdapter = processes.get(1).adaptNotNull(IProcessAdapter.class);
final var graphicProcess = processes.size() > 1 ? (GraphicProcess) processes.get(1) : null;
renderProcessAdapter = graphicProcess != null ? graphicProcess.adaptNotNull(IProcessAdapter.class) : null;

final var engineAdapter = vulkanEngine.adapt(IVulkanEngineAdapter.class);
final var window = engineAdapter.getWindow();
Expand Down
46 changes: 27 additions & 19 deletions org.sheepy.vsand/src/main/java/org/sheepy/vsand/util/BoardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,43 @@ public final class BoardUtil
public static Vector2ic toBoardPosition(Vector2fc mousePos, VSandApplication application)
{
final var boardSize = application.getSize();
final var sceneSize = application.getScene().getSize();
final float boardWidth = boardSize.x();
final float boardHeight = boardSize.y();
final float width = sceneSize.x();
final float height = sceneSize.y();

if (width != boardWidth || height != boardHeight)
if(application.getScene() != null)
{
final float scale = Math.min(width / boardWidth, height / boardHeight);
final int dstWidth = (int) Math.ceil(scale * boardWidth);
final int dstHeight = (int) Math.ceil(scale * boardHeight);
final var sceneSize = application.getScene().getSize();
final float boardWidth = boardSize.x();
final float boardHeight = boardSize.y();
final float width = sceneSize.x();
final float height = sceneSize.y();

int xOffset = 0;
int yOffset = 0;
if (dstWidth < width)
if (width != boardWidth || height != boardHeight)
{
xOffset = (int) ((width - dstWidth) / 2f);
final float scale = Math.min(width / boardWidth, height / boardHeight);
final int dstWidth = (int) Math.ceil(scale * boardWidth);
final int dstHeight = (int) Math.ceil(scale * boardHeight);

int xOffset = 0;
int yOffset = 0;
if (dstWidth < width)
{
xOffset = (int) ((width - dstWidth) / 2f);
}
if (dstHeight < height)
{
yOffset = (int) ((height - dstHeight) / 2f);
}
final int x = (int) ((mousePos.x() - xOffset) * (boardWidth / dstWidth));
final int y = (int) ((mousePos.y() - yOffset) * (boardHeight / dstHeight));
return new Vector2i(x, y);
}
if (dstHeight < height)
else
{
yOffset = (int) ((height - dstHeight) / 2f);
return new Vector2i((int) mousePos.x(), (int) mousePos.y());
}
final int x = (int) ((mousePos.x() - xOffset) * (boardWidth / dstWidth));
final int y = (int) ((mousePos.y() - yOffset) * (boardHeight / dstHeight));
return new Vector2i(x, y);
}
else
{
return new Vector2i((int) mousePos.x(), (int) mousePos.y());
return boardSize;
}
}
}
8 changes: 4 additions & 4 deletions org.sheepy.vsand/src/main/resources/Application.vsand
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</initialLayout>
</resources>
</resourcePkg>
<processes xsi:type="compute:ComputeProcess" name="Board Compute" waitingFenceDuringAcquire="true" resetAllowed="true">
<processes xsi:type="compute:ComputeProcess" name="Board Compute" resetAllowed="true">
<resourcePkg>
<resources xsi:type="resource:Shader" name="draw" stage="COMPUTE_BIT">
<file xsi:type="resource_1:StringModuleResource" name="" path="draw.comp.spv" moduleName="org.sheepy.vsand"/>
Expand Down Expand Up @@ -75,6 +75,7 @@
</descriptors>
</descriptorPkg>
<descriptorPool/>
<executionManager xsi:type="compute:ComputeExecutionManager" waitForExecution="//@engines.0/@processes.0/@executionManager" waitedBy="//@engines.0/@processes.1/@executionManager //@engines.0/@processes.0/@executionManager"/>
<pipelinePkg>
<pipelines xsi:type="compute:ComputePipeline" name="Draw" enabled="false" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.4" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.0/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.0">
<resourcePkg>
Expand Down Expand Up @@ -154,7 +155,7 @@
<tasks xsi:type="process:PushConstantBuffer" name="" buffer="//@engines.0/@processes.0/@pipelinePkg/@pipelines.2/@resourcePkg/@resources.0">
<stages>COMPUTE_BIT</stages>
</tasks>
<tasks xsi:type="process:PipelineBarrier" srcStage="TRANSFER_BIT" dstStage="COMPUTE_SHADER_BIT" srcQueue="//@engines.0/@processes.1" dstQueue="//@engines.0/@processes.0">
<tasks xsi:type="process:PipelineBarrier" srcStage="TRANSFER_BIT" dstStage="COMPUTE_SHADER_BIT">
<barriers xsi:type="resource:ImageBarrier" srcLayout="TRANSFER_SRC_OPTIMAL" dstLayout="GENERAL" image="//@engines.0/@resourcePkg/@resources.0">
<srcAccessMask>TRANSFER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
Expand Down Expand Up @@ -188,10 +189,10 @@
</pipelines>
</pipelinePkg>
<configuration/>
<executionManager/>
</processes>
<processes xsi:type="graphic:GraphicProcess" resetAllowed="true">
<descriptorPool/>
<executionManager xsi:type="graphic:GraphicExecutionManager" waitForExecution="//@engines.0/@processes.0/@executionManager"/>
<configuration acquireWaitStage="COMPUTE_SHADER_BIT">
<swapchainConfiguration requiredSwapImageCount="2" allowingAccessFromCompute="true">
<swapImageUsages>ColorAttachment</swapImageUsages>
Expand All @@ -205,7 +206,6 @@
<renderPass/>
<imageViews/>
</configuration>
<executionManager/>
<attachmentPkg/>
</processes>
</engines>
Expand Down

0 comments on commit eba5865

Please sign in to comment.