From a00a9613b80cb95c83f70176776eb2b2c8e03ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mora?= Date: Tue, 14 Jul 2020 15:14:06 +0200 Subject: [PATCH] Use MemoryChunk --- .../vsand/loader/Board1BufferLoader.java | 23 +---- .../vsand/loader/Board2BufferLoader.java | 23 +---- .../vsand/loader/ChunkBufferLoader.java | 23 +---- .../loader/ConfigurationBufferLoader.java | 9 +- .../loader/TransformationBufferLoader.java | 9 +- .../src/main/resources/Application.vsand | 86 ++++++++++--------- 6 files changed, 63 insertions(+), 110 deletions(-) diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board1BufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board1BufferLoader.java index 8886e7c6..491aaaf1 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board1BufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board1BufferLoader.java @@ -1,23 +1,19 @@ package org.sheepy.vsand.loader; -import org.lwjgl.system.MemoryUtil; import org.sheepy.lily.core.api.adapter.annotation.Adapter; -import org.sheepy.lily.core.api.adapter.annotation.Dispose; import org.sheepy.lily.core.api.adapter.annotation.Load; import org.sheepy.lily.core.api.extender.IExtender; import org.sheepy.lily.core.api.extender.ModelExtender; import org.sheepy.lily.core.api.util.ModelUtil; -import org.sheepy.lily.vulkan.model.resource.Buffer; +import org.sheepy.lily.vulkan.model.resource.StaticBuffer; import org.sheepy.vsand.model.VSandApplication; -import java.nio.ByteBuffer; - -@ModelExtender(scope = Buffer.class, name = "Board Buffer 1") +@ModelExtender(scope = StaticBuffer.class, name = "Board Buffer 1") @Adapter(singleton = true, lazy = false) public final class Board1BufferLoader implements IExtender { @Load - private static void load(Buffer buffer) + private static void load(StaticBuffer buffer) { final var application = (VSandApplication) ModelUtil.getApplication(buffer); final var size = application.getSize(); @@ -27,18 +23,5 @@ private static void load(Buffer buffer) final int sizeByte = sizeBoard * Integer.BYTES; buffer.setSize(sizeByte); - - // Fill the board buffer with Void matter (0) - final ByteBuffer bBuffer = MemoryUtil.memCalloc(sizeByte); - bBuffer.position(sizeByte); - bBuffer.flip(); - buffer.setData(bBuffer); - } - - @Dispose - private static void dispose(Buffer buffer) - { - MemoryUtil.memFree(buffer.getData()); - buffer.setData(null); } } diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board2BufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board2BufferLoader.java index 3ce1bb28..ac901993 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board2BufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/Board2BufferLoader.java @@ -1,23 +1,19 @@ package org.sheepy.vsand.loader; -import java.nio.ByteBuffer; - -import org.lwjgl.system.MemoryUtil; import org.sheepy.lily.core.api.adapter.annotation.Adapter; -import org.sheepy.lily.core.api.adapter.annotation.Dispose; import org.sheepy.lily.core.api.adapter.annotation.Load; import org.sheepy.lily.core.api.extender.IExtender; import org.sheepy.lily.core.api.extender.ModelExtender; import org.sheepy.lily.core.api.util.ModelUtil; -import org.sheepy.lily.vulkan.model.resource.Buffer; +import org.sheepy.lily.vulkan.model.resource.StaticBuffer; import org.sheepy.vsand.model.VSandApplication; -@ModelExtender(scope = Buffer.class, name = "Board Buffer 2") +@ModelExtender(scope = StaticBuffer.class, name = "Board Buffer 2") @Adapter(singleton = true, lazy = false) public final class Board2BufferLoader implements IExtender { @Load - private static void load(Buffer buffer) + private static void load(StaticBuffer buffer) { final var application = (VSandApplication) ModelUtil.getApplication(buffer); final var size = application.getSize(); @@ -27,18 +23,5 @@ private static void load(Buffer buffer) final int sizeByte = sizeBoard * Integer.BYTES; buffer.setSize(sizeByte); - - // Fill the board buffer with Void matter (0) - final ByteBuffer bBuffer = MemoryUtil.memCalloc(sizeByte); - bBuffer.position(sizeByte); - bBuffer.flip(); - buffer.setData(bBuffer); - } - - @Dispose - private static void dispose(Buffer buffer) - { - MemoryUtil.memFree(buffer.getData()); - buffer.setData(null); } } diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ChunkBufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ChunkBufferLoader.java index 1185256a..a7f7e3c1 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ChunkBufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ChunkBufferLoader.java @@ -1,23 +1,19 @@ package org.sheepy.vsand.loader; -import org.lwjgl.system.MemoryUtil; import org.sheepy.lily.core.api.adapter.annotation.Adapter; -import org.sheepy.lily.core.api.adapter.annotation.Dispose; import org.sheepy.lily.core.api.adapter.annotation.Load; import org.sheepy.lily.core.api.extender.IExtender; import org.sheepy.lily.core.api.extender.ModelExtender; import org.sheepy.lily.core.api.util.ModelUtil; -import org.sheepy.lily.vulkan.model.resource.Buffer; +import org.sheepy.lily.vulkan.model.resource.StaticBuffer; import org.sheepy.vsand.model.VSandApplication; -import java.nio.ByteBuffer; - -@ModelExtender(scope = Buffer.class, name = "Chunk Buffer") +@ModelExtender(scope = StaticBuffer.class, name = "Chunk Buffer") @Adapter(singleton = true, lazy = false) public final class ChunkBufferLoader implements IExtender { @Load - private static void load(Buffer buffer) + private static void load(StaticBuffer buffer) { final var application = (VSandApplication) ModelUtil.getApplication(buffer); final var size = application.getSize(); @@ -27,18 +23,5 @@ private static void load(Buffer buffer) final int sizeByte = sizeChunks * Integer.BYTES; buffer.setSize(sizeByte); - - // Fill the board buffer with Void matter (0) - final ByteBuffer bBuffer = MemoryUtil.memCalloc(sizeByte); - bBuffer.position(sizeByte); - bBuffer.flip(); - buffer.setData(bBuffer); - } - - @Dispose - private static void dispose(Buffer buffer) - { - MemoryUtil.memFree(buffer.getData()); - buffer.setData(null); } } diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ConfigurationBufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ConfigurationBufferLoader.java index 51f2d70c..1523c35c 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ConfigurationBufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/ConfigurationBufferLoader.java @@ -7,20 +7,20 @@ import org.sheepy.lily.core.api.adapter.annotation.Load; import org.sheepy.lily.core.api.extender.IExtender; import org.sheepy.lily.core.api.extender.ModelExtender; -import org.sheepy.lily.vulkan.model.resource.Buffer; +import org.sheepy.lily.vulkan.model.resource.DataBuffer; import org.sheepy.vsand.model.Material; import org.sheepy.vsand.model.VSandApplication; import java.nio.ByteBuffer; -@ModelExtender(scope = Buffer.class, name = "Configuration") +@ModelExtender(scope = DataBuffer.class, name = "Configuration") @Adapter(singleton = true, lazy = false) public final class ConfigurationBufferLoader implements IExtender { private static final int UNIT_BYTES = 8 * Integer.BYTES; @Load - private static void load(Buffer buffer) + private static void load(DataBuffer buffer) { final var application = (VSandApplication) EcoreUtil.getRootContainer(buffer); final var materials = application.getMaterials().getMaterials(); @@ -45,12 +45,11 @@ private static void load(Buffer buffer) } bBuffer.flip(); - buffer.setSize(size); buffer.setData(bBuffer); } @Dispose - private static void dispose(Buffer buffer) + private static void dispose(DataBuffer buffer) { MemoryUtil.memFree(buffer.getData()); buffer.setData(null); diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/TransformationBufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/TransformationBufferLoader.java index d5e4166e..b65f31ff 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/TransformationBufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/loader/TransformationBufferLoader.java @@ -7,16 +7,16 @@ import org.sheepy.lily.core.api.adapter.annotation.Load; import org.sheepy.lily.core.api.extender.IExtender; import org.sheepy.lily.core.api.extender.ModelExtender; -import org.sheepy.lily.vulkan.model.resource.Buffer; +import org.sheepy.lily.vulkan.model.resource.DataBuffer; import org.sheepy.vsand.model.VSandApplication; import org.sheepy.vsand.util.TransformationUtil; -@ModelExtender(scope = Buffer.class, name = "Transformation") +@ModelExtender(scope = DataBuffer.class, name = "Transformation") @Adapter(singleton = true, lazy = false) public final class TransformationBufferLoader implements IExtender { @Load - private static void load(Buffer buffer) + private static void load(DataBuffer buffer) { final var application = (VSandApplication) EcoreUtil.getRootContainer(buffer); final int[] transfoArray = TransformationUtil.toArray(application); @@ -29,12 +29,11 @@ private static void load(Buffer buffer) byteBuffer.position(size); byteBuffer.flip(); - buffer.setSize(size); buffer.setData(byteBuffer); } @Dispose - private static void dispose(Buffer buffer) + private static void dispose(DataBuffer buffer) { MemoryUtil.memFree(buffer.getData()); buffer.setData(null); diff --git a/org.sheepy.vsand/src/main/resources/Application.vsand b/org.sheepy.vsand/src/main/resources/Application.vsand index 03ec9b59..c6d544b9 100644 --- a/org.sheepy.vsand/src/main/resources/Application.vsand +++ b/org.sheepy.vsand/src/main/resources/Application.vsand @@ -13,26 +13,6 @@ - - STORAGE_BUFFER_BIT - TRANSFER_DST_BIT - - - STORAGE_BUFFER_BIT - TRANSFER_DST_BIT - - - STORAGE_BUFFER_BIT - TRANSFER_DST_BIT - - - UNIFORM_BUFFER_BIT - TRANSFER_DST_BIT - - - TRANSFER_DST_BIT - UNIFORM_BUFFER_BIT - @@ -47,21 +27,47 @@ + + + + STORAGE_BUFFER_BIT + TRANSFER_DST_BIT + + + STORAGE_BUFFER_BIT + TRANSFER_DST_BIT + + + STORAGE_BUFFER_BIT + TRANSFER_DST_BIT + + + + + UNIFORM_BUFFER_BIT + TRANSFER_DST_BIT + + + UNIFORM_BUFFER_BIT + TRANSFER_DST_BIT + + + - + COMPUTE_BIT - + COMPUTE_BIT - + COMPUTE_BIT - + COMPUTE_BIT - + COMPUTE_BIT @@ -70,9 +76,9 @@ - + - + @@ -83,17 +89,17 @@ SHADER_READ_BIT SHADER_WRITE_BIT - + SHADER_READ_BIT SHADER_WRITE_BIT - + SHADER_READ_BIT SHADER_WRITE_BIT - + @@ -105,28 +111,28 @@ COMPUTE_BIT - + SHADER_READ_BIT SHADER_WRITE_BIT - + SHADER_READ_BIT SHADER_WRITE_BIT - + SHADER_READ_BIT SHADER_WRITE_BIT - + - + COMPUTE_BIT @@ -139,9 +145,9 @@ COMPUTE_BIT - + - + @@ -158,17 +164,17 @@ SHADER_WRITE_BIT SHADER_READ_BIT - + SHADER_WRITE_BIT SHADER_READ_BIT - + SHADER_WRITE_BIT SHADER_READ_BIT - +