Skip to content

Commit

Permalink
Use MemoryChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealrann committed Jul 14, 2020
1 parent e0f59b8 commit a00a961
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
86 changes: 46 additions & 40 deletions org.sheepy.vsand/src/main/resources/Application.vsand
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@
</resourcePkg>
<processes xsi:type="compute:ComputeProcess" name="Board Compute" waitingFenceDuringAcquire="true" resetAllowed="true">
<resourcePkg>
<resources xsi:type="resource:Buffer" name="Board Buffer 1">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</resources>
<resources xsi:type="resource:Buffer" name="Board Buffer 2">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</resources>
<resources xsi:type="resource:Buffer" name="Chunk Buffer">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</resources>
<resources xsi:type="resource:Buffer" name="Configuration">
<usages>UNIFORM_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</resources>
<resources xsi:type="resource:Buffer" name="Transformation">
<usages>TRANSFER_DST_BIT</usages>
<usages>UNIFORM_BUFFER_BIT</usages>
</resources>
<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"/>
<constants name="MaterialCount" size="4"/>
Expand All @@ -47,21 +27,47 @@
</resources>
<resources xsi:type="model:BoardConstantBuffer"/>
<resources xsi:type="resource:ConstantBuffer" name="MaterialCount"/>
<resources xsi:type="resource:MemoryChunk">
<parts xsi:type="resource:BufferMemory" name="Board">
<buffers xsi:type="resource:StaticBuffer" name="Board Buffer 1" initWithZero="true">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</buffers>
<buffers xsi:type="resource:StaticBuffer" name="Board Buffer 2" initWithZero="true">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</buffers>
<buffers xsi:type="resource:StaticBuffer" name="Chunk Buffer" initWithZero="true">
<usages>STORAGE_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</buffers>
</parts>
<parts xsi:type="resource:BufferMemory" name="Data">
<buffers xsi:type="resource:DataBuffer" name="Configuration">
<usages>UNIFORM_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</buffers>
<buffers xsi:type="resource:DataBuffer" name="Transformation">
<usages>UNIFORM_BUFFER_BIT</usages>
<usages>TRANSFER_DST_BIT</usages>
</buffers>
</parts>
</resources>
</resourcePkg>
<descriptorPkg>
<descriptors xsi:type="resource:BufferDescriptor" name="Chunk" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.2">
<descriptors xsi:type="resource:BufferDescriptor" name="Chunk" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.5/@parts.0/@buffers.2">
<shaderStages>COMPUTE_BIT</shaderStages>
</descriptors>
<descriptors xsi:type="resource:BufferDescriptor" name="Board1" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.0">
<descriptors xsi:type="resource:BufferDescriptor" name="Board1" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.5/@parts.0/@buffers.0">
<shaderStages>COMPUTE_BIT</shaderStages>
</descriptors>
<descriptors xsi:type="resource:BufferDescriptor" name="Board2" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.1">
<descriptors xsi:type="resource:BufferDescriptor" name="Board2" type="STORAGE_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.5/@parts.0/@buffers.1">
<shaderStages>COMPUTE_BIT</shaderStages>
</descriptors>
<descriptors xsi:type="resource:BufferDescriptor" name="Config" type="UNIFORM_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.3">
<descriptors xsi:type="resource:BufferDescriptor" name="Config" type="UNIFORM_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.5/@parts.1/@buffers.0">
<shaderStages>COMPUTE_BIT</shaderStages>
</descriptors>
<descriptors xsi:type="resource:BufferDescriptor" name="Transfo" type="UNIFORM_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.4">
<descriptors xsi:type="resource:BufferDescriptor" name="Transfo" type="UNIFORM_BUFFER" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.5/@parts.1/@buffers.1">
<shaderStages>COMPUTE_BIT</shaderStages>
</descriptors>
<descriptors xsi:type="resource:ImageDescriptor" name="BoardImage" type="STORAGE_IMAGE" image="//@engines.0/@resourcePkg/@resources.0">
Expand All @@ -70,9 +76,9 @@
</descriptorPkg>
<descriptorPool/>
<pipelinePkg>
<pipelines xsi:type="compute:ComputePipeline" name="Draw" enabled="false" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.9" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.0/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.5">
<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>
<resources xsi:type="model:DrawConstantBuffer" boardConstantBuffer="//@engines.0/@processes.0/@resourcePkg/@resources.8"/>
<resources xsi:type="model:DrawConstantBuffer" boardConstantBuffer="//@engines.0/@processes.0/@resourcePkg/@resources.3"/>
</resourcePkg>
<taskPkgs>
<tasks xsi:type="process:BindDescriptorSets" descriptorSets="//@engines.0/@processes.0/@pipelinePkg/@pipelines.0/@descriptorPool/@descriptorSets.0" bindPoint="COMPUTE"/>
Expand All @@ -83,17 +89,17 @@
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.0"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.2"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.1"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
</tasks>
<tasks xsi:type="compute:DispatchTask" name="Draw" workgroupCountX="78" workgroupCountY="44"/>
Expand All @@ -105,28 +111,28 @@
<stages>COMPUTE_BIT</stages>
</pushConstantRanges>
</pipelines>
<pipelines xsi:type="compute:ComputePipeline" name="Step" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.9" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.1/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.6">
<pipelines xsi:type="compute:ComputePipeline" name="Step" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.4" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.1/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.1">
<taskPkgs>
<tasks xsi:type="process:BindDescriptorSets" descriptorSets="//@engines.0/@processes.0/@pipelinePkg/@pipelines.1/@descriptorPool/@descriptorSets.0" bindPoint="COMPUTE"/>
<tasks xsi:type="process:PipelineBarrier" srcStage="COMPUTE_SHADER_BIT" dstStage="COMPUTE_SHADER_BIT">
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.1"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.2"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_READ_BIT</srcAccessMask>
<dstAccessMask>SHADER_WRITE_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.0"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
</tasks>
<tasks xsi:type="process:CompositeTask" name="Update Board">
<tasks xsi:type="process:PushConstantBuffer" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.8">
<tasks xsi:type="process:PushConstantBuffer" buffer="//@engines.0/@processes.0/@resourcePkg/@resources.3">
<stages>COMPUTE_BIT</stages>
</tasks>
<tasks xsi:type="compute:DispatchTask" name="Board update" workgroupCountX="78" workgroupCountY="44"/>
Expand All @@ -139,9 +145,9 @@
<stages>COMPUTE_BIT</stages>
</pushConstantRanges>
</pipelines>
<pipelines xsi:type="compute:ComputePipeline" name="Board to Pixel" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.9" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.2/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.7">
<pipelines xsi:type="compute:ComputePipeline" name="Board to Pixel" specializationData="//@engines.0/@processes.0/@resourcePkg/@resources.4" layout="//@engines.0/@processes.0/@pipelinePkg/@pipelines.2/@descriptorPool/@descriptorSets.0" shader="//@engines.0/@processes.0/@resourcePkg/@resources.2">
<resourcePkg>
<resources xsi:type="model:PixelConstantBuffer" boardConstantBuffer="//@engines.0/@processes.0/@resourcePkg/@resources.8"/>
<resources xsi:type="model:PixelConstantBuffer" boardConstantBuffer="//@engines.0/@processes.0/@resourcePkg/@resources.3"/>
</resourcePkg>
<taskPkgs>
<tasks xsi:type="process:BindDescriptorSets" descriptorSets="//@engines.0/@processes.0/@pipelinePkg/@pipelines.2/@descriptorPool/@descriptorSets.0" bindPoint="COMPUTE"/>
Expand All @@ -158,17 +164,17 @@
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_WRITE_BIT</srcAccessMask>
<dstAccessMask>SHADER_READ_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.0"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_WRITE_BIT</srcAccessMask>
<dstAccessMask>SHADER_READ_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.2"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
<barriers xsi:type="resource:BufferBarrier">
<srcAccessMask>SHADER_WRITE_BIT</srcAccessMask>
<dstAccessMask>SHADER_READ_BIT</dstAccessMask>
<buffers xsi:type="resource:FixedBufferReference" buffers="//@engines.0/@processes.0/@resourcePkg/@resources.1"/>
<buffers xsi:type="resource:FixedBufferReference"/>
</barriers>
</tasks>
<tasks xsi:type="compute:DispatchTask" workgroupCountX="78" workgroupCountY="44"/>
Expand Down

0 comments on commit a00a961

Please sign in to comment.