From 6b64e2968996a2128ed23cd39864efdb6faaf142 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Wed, 17 Nov 2021 22:12:44 +0900 Subject: [PATCH 1/2] Save a test kernel for later experimentation. --- src/sig/TestKernel.java | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/sig/TestKernel.java diff --git a/src/sig/TestKernel.java b/src/sig/TestKernel.java new file mode 100644 index 0000000..e57529c --- /dev/null +++ b/src/sig/TestKernel.java @@ -0,0 +1,75 @@ +package sig; + +import java.util.Arrays; + +import com.aparapi.Kernel; +import com.aparapi.Range; +import com.aparapi.device.Device; + +public class TestKernel extends Kernel{ + + int[] a,b; + float[] sum; + boolean[] test; + final int val=55555555; + + TestKernel(int[] a,int[] b,float[] sum,boolean[] test) { + this.a=a; + this.b=b; + this.sum=sum; + this.test=test; + } + + public static void main(String[] args) { + int size = 1024; + + final int[] a = new int[size]; + int[] b = new int[size]; + + for (int i = 0; i < size; i++) { + a[i] = (int) (Math.random() * 100); + b[i] = (int) (Math.random() * 100); + } + + float[] sum = new float[size]; + + TestKernel kernel = new TestKernel(a,b,sum,new boolean[]{true}); + + //System.out.println("Start..."); + kernel.execute(Range.create(size)); + //System.out.println("Running..."); + //size=5; + kernel.b[0]=50; + kernel.b[1]=45; + /*for (int i = 0; i < size; i++) { + b[i] = (int) (Math.random() * 100); + }*/ + long timer1=System.nanoTime(); + for (int i=0;i<900;i++) { + kernel.execute(Range.create(size)); + } + + + System.out.println((System.nanoTime()-timer1)+"ns"); + kernel.dispose(); + System.out.println(Arrays.toString(sum)); + timer1=System.nanoTime(); + for (int j=0;j<900;j++) { + for (int i=0;i Date: Wed, 17 Nov 2021 22:47:02 +0900 Subject: [PATCH 2/2] Fix threading issues. --- src/sig/Panel.java | 30 ++++++++++++++---------------- src/sig/SigRenderer.java | 5 ++--- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/sig/Panel.java b/src/sig/Panel.java index 6fa0fc3..fe38e44 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -33,8 +33,8 @@ public class Panel extends JPanel implements Runnable { private MemoryImageSource mImageProducer; private ColorModel cm; private Thread thread; - Thread[] workerThread = new Thread[8]; - String[][] keySets = new String[8][]; + Thread[] workerThread = new Thread[9]; + String[][] keySets = new String[9][]; ConcurrentLinkedQueue newTris = new ConcurrentLinkedQueue<>(); List accumulatedTris = new ArrayList(); public static ConcurrentLinkedQueue accumulatedTris1 = new ConcurrentLinkedQueue<>(); @@ -134,15 +134,7 @@ public class Panel extends JPanel implements Runnable { int currentSet=0; for (String key : SigRenderer.blockGrid.keySet()) { if (currentPiece==0) { - if (currentSet==7) { - if (SigRenderer.blockGrid.size()%8==0) { - keySets[currentSet] = new String[pieces]; - } else { - keySets[currentSet] = new String[SigRenderer.blockGrid.size()%8]; - } - } else { - keySets[currentSet] = new String[pieces]; - } + keySets[currentSet] = new String[pieces]; } keySets[currentSet][currentPiece]=key; currentPiece++; @@ -167,16 +159,22 @@ public class Panel extends JPanel implements Runnable { accumulatedTris1.clear(); } final Matrix matWorld2 = matWorld; - for (int i=0;i<8;i++) { + for (int i=0;i<9;i++) { final int id=i; workerThread[i] = new Thread(){ @Override public void run() { ConcurrentLinkedQueue newTris = new ConcurrentLinkedQueue<>(); - for (String key : keySets[id]) { - Block b = SigRenderer.blockGrid.get(key); - for (Triangle t : b.block.prepareRender(b)) { - prepareTriForRender(matWorld2, matView, t, newTris); + if (keySets[id]!=null) { + for (String key : keySets[id]) { + if (key!=null) { + Block b = SigRenderer.blockGrid.get(key); + if (b!=null) { + for (Triangle t : b.block.prepareRender(b)) { + prepareTriForRender(matWorld2, matView, t, newTris); + } + } + } } } if (renderFirst) { diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index ff9eec8..00a7db6 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -36,7 +36,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene public static boolean windowActive=true; public static boolean WIREFRAME = false; - public static boolean PROFILING = true; + public static boolean PROFILING = false; public static boolean FLYING_MODE = false; public static int SCREEN_WIDTH=1280; public static int SCREEN_HEIGHT=720; @@ -402,8 +402,6 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene for (int x=0;x<64;x++) { for (int z=0;z<64;z++) { addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH); - addBlock(new Vector(x,1,z),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH); - //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); /*for (int y=1;y