|
@@ -19,7 +19,6 @@ class MeshBatch extends MultiMaterial {
|
|
|
static var MAX_BUFFER_ELEMENTS = 4096;
|
|
|
static var MAX_STORAGE_BUFFER_ELEMENTS = 128 * 1024 * 1024 >> 2;
|
|
|
static var BATCH_START_FMT = hxd.BufferFormat.make([{ name : "Batch_Start", type : DFloat }]);
|
|
|
- static var INDIRECT_DRAW_ARGUMENTS_FMT = hxd.BufferFormat.make([{ name : "", type : DVec4 }, { name : "", type : DFloat }]);
|
|
|
|
|
|
var instanced : h3d.prim.Instanced;
|
|
|
var dataPasses : BatchData;
|
|
@@ -95,8 +94,6 @@ class MeshBatch extends MultiMaterial {
|
|
|
function gpuUpdateEnabled() return meshBatchFlags.has(EnableGpuUpdate);
|
|
|
function getMaxElements() return storageBufferEnabled() ? MAX_STORAGE_BUFFER_ELEMENTS : MAX_BUFFER_ELEMENTS;
|
|
|
function hasPrimitiveOffset() return meshBatchFlags.has(HasPrimitiveOffset);
|
|
|
- function useCommandBuffer() return false;
|
|
|
- function useCountBuffer() return false;
|
|
|
|
|
|
public function begin( emitCountTip = -1 ) : Int {
|
|
|
instanceCount = 0;
|
|
@@ -335,26 +332,7 @@ class MeshBatch extends MultiMaterial {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ( useCommandBuffer() ) {
|
|
|
- var commandCountAllocated = hxd.Math.imin( hxd.Math.nextPOT( count ), p.maxInstance );
|
|
|
- if ( p.commandBuffers == null) {
|
|
|
- p.commandBuffers = [];
|
|
|
- if ( useCountBuffer() )
|
|
|
- p.countBuffers = [];
|
|
|
- }
|
|
|
- var buf = p.commandBuffers[index];
|
|
|
- if ( buf == null ) {
|
|
|
- buf = alloc.allocBuffer( commandCountAllocated, INDIRECT_DRAW_ARGUMENTS_FMT, UniformReadWrite );
|
|
|
- p.commandBuffers[index] = buf;
|
|
|
- if ( useCountBuffer() )
|
|
|
- p.countBuffers[index] = alloc.allocBuffer( 1, hxd.BufferFormat.VEC4_DATA, UniformReadWrite );
|
|
|
- }
|
|
|
- else if ( buf.vertices < commandCountAllocated ) {
|
|
|
- alloc.disposeBuffer( buf );
|
|
|
- buf = alloc.allocBuffer( commandCountAllocated, INDIRECT_DRAW_ARGUMENTS_FMT, UniformReadWrite );
|
|
|
- p.commandBuffers[index] = buf;
|
|
|
- }
|
|
|
- }
|
|
|
+ onFlushBuffer(p, index, count);
|
|
|
|
|
|
start += count;
|
|
|
index++;
|
|
@@ -384,6 +362,8 @@ class MeshBatch extends MultiMaterial {
|
|
|
needUpload = false;
|
|
|
}
|
|
|
|
|
|
+ function onFlushBuffer(p : BatchData, index : Int, count : Int) {}
|
|
|
+
|
|
|
function onFlushPass(p : BatchData) {}
|
|
|
|
|
|
function syncData( batch : BatchData ) {
|
|
@@ -503,15 +483,9 @@ class MeshBatch extends MultiMaterial {
|
|
|
else
|
|
|
p.shader.Batch_Buffer = p.buffers[bufferIndex];
|
|
|
|
|
|
- if( p.instanceBuffers == null ) {
|
|
|
- var count = hxd.Math.imin( instanceCount - p.maxInstance * bufferIndex, p.maxInstance );
|
|
|
- instanced.setCommand(p.matIndex, instanced.screenRatioToLod(curScreenRatio), count);
|
|
|
- if ( useCommandBuffer() ) {
|
|
|
- @:privateAccess instanced.commands.data = p.commandBuffers[bufferIndex].vbuf;
|
|
|
- if ( useCountBuffer() )
|
|
|
- @:privateAccess instanced.commands.countBuffer = p.countBuffers[bufferIndex].vbuf;
|
|
|
- }
|
|
|
- } else
|
|
|
+ if( p.instanceBuffers == null )
|
|
|
+ setPassCommand(p, bufferIndex);
|
|
|
+ else
|
|
|
instanced.commands = p.instanceBuffers[bufferIndex];
|
|
|
|
|
|
break;
|
|
@@ -525,6 +499,11 @@ class MeshBatch extends MultiMaterial {
|
|
|
ctx.drawPass.index = prev;
|
|
|
}
|
|
|
|
|
|
+ function setPassCommand(p : BatchData, bufferIndex : Int) {
|
|
|
+ var count = hxd.Math.imin( instanceCount - p.maxInstance * bufferIndex, p.maxInstance );
|
|
|
+ instanced.setCommand(p.matIndex, instanced.screenRatioToLod(curScreenRatio), count);
|
|
|
+ }
|
|
|
+
|
|
|
override function calcScreenRatio(ctx:RenderContext) {
|
|
|
curScreenRatio = getPrimitive().getBounds().dimension() / ( 2.0 * hxd.Math.max(lodDistance, 0.0001) );
|
|
|
}
|
|
@@ -590,8 +569,6 @@ class BatchData {
|
|
|
public var shader : hxsl.BatchShader;
|
|
|
public var shaders : Array<hxsl.Shader>;
|
|
|
public var pass : h3d.mat.Pass;
|
|
|
- public var commandBuffers : Array<h3d.Buffer>;
|
|
|
- public var countBuffers : Array<h3d.Buffer>;
|
|
|
public var next : BatchData;
|
|
|
|
|
|
public function new() {
|
|
@@ -599,16 +576,6 @@ class BatchData {
|
|
|
|
|
|
public function clean() {
|
|
|
var alloc = hxd.impl.Allocator.get();
|
|
|
- if ( commandBuffers != null ) {
|
|
|
- for ( buf in commandBuffers )
|
|
|
- alloc.disposeBuffer(buf);
|
|
|
- commandBuffers = null;
|
|
|
- }
|
|
|
- if ( countBuffers != null ) {
|
|
|
- for ( buf in countBuffers )
|
|
|
- alloc.disposeBuffer(buf);
|
|
|
- countBuffers = null;
|
|
|
- }
|
|
|
|
|
|
pass.removeShader(shader);
|
|
|
for( b in buffers )
|