Переглянути джерело

GPUMeshBatch : Fix oversized commandBuffer when using subParts

TothBenoit 1 місяць тому
батько
коміт
b30a8b4363
1 змінених файлів з 4 додано та 1 видалено
  1. 4 1
      h3d/scene/GPUMeshBatch.hx

+ 4 - 1
h3d/scene/GPUMeshBatch.hx

@@ -217,7 +217,9 @@ class GPUMeshBatch extends MeshBatch {
 		computeShader.matInfos = matInfos;
 		computeShader.matInfos = matInfos;
 		computeShader.instanceCount = instanceCount;
 		computeShader.instanceCount = instanceCount;
 
 
+		var commandCountNeeded : Int
 		if ( emittedSubParts != null ) {
 		if ( emittedSubParts != null ) {
+			commandCountNeeded = instanceCount;
 			var computeShader : h3d.shader.InstanceIndirect.SubPartInstanceIndirect = cast computeShader;
 			var computeShader : h3d.shader.InstanceIndirect.SubPartInstanceIndirect = cast computeShader;
 			computeShader.subPartCount = emittedSubParts.length;
 			computeShader.subPartCount = emittedSubParts.length;
 			computeShader.subPartInfos = subPartsInfos;
 			computeShader.subPartInfos = subPartsInfos;
@@ -227,6 +229,7 @@ class GPUMeshBatch extends MeshBatch {
 			while ( maxSubPartsElement > computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT )
 			while ( maxSubPartsElement > computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT )
 				computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT = computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT + 16;
 				computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT = computeShader.MAX_SUB_PART_BUFFER_ELEMENT_COUNT + 16;
 		} else {
 		} else {
+			commandCountNeeded = instanceCount * materialCount;
 			var computeShader : h3d.shader.InstanceIndirect = cast computeShader;
 			var computeShader : h3d.shader.InstanceIndirect = cast computeShader;
 			computeShader.radius = prim.getBounds().dimension() * 0.5;
 			computeShader.radius = prim.getBounds().dimension() * 0.5;
 			computeShader.lodCount = lodCount;
 			computeShader.lodCount = lodCount;
@@ -234,7 +237,7 @@ class GPUMeshBatch extends MeshBatch {
 		}
 		}
 
 
 		var alloc = hxd.impl.Allocator.get();
 		var alloc = hxd.impl.Allocator.get();
-		var commandCountAllocated = hxd.Math.nextPOT( instanceCount * materialCount );
+		var commandCountAllocated = hxd.Math.nextPOT( commandCountNeeded );
 		if ( commandBuffer == null ) {
 		if ( commandBuffer == null ) {
 			commandBuffer = alloc.allocBuffer( commandCountAllocated, INDIRECT_DRAW_ARGUMENTS_FMT, UniformReadWrite );
 			commandBuffer = alloc.allocBuffer( commandCountAllocated, INDIRECT_DRAW_ARGUMENTS_FMT, UniformReadWrite );
 			gpuCounter = new h3d.GPUCounter();
 			gpuCounter = new h3d.GPUCounter();