Browse Source

GPU track alloc without compilation flag.

clementlandrin 1 năm trước cách đây
mục cha
commit
bf45c519f4

+ 1 - 7
h2d/Graphics.hx

@@ -36,16 +36,12 @@ private class GraphicsContent extends h3d.prim.Primitive {
 	var buffers : Array<{ buf : hxd.FloatBuffer, vbuf : h3d.Buffer, idx : hxd.IndexBuffer, ibuf : h3d.Indexes, state : BatchDrawState }>;
 	var buffers : Array<{ buf : hxd.FloatBuffer, vbuf : h3d.Buffer, idx : hxd.IndexBuffer, ibuf : h3d.Indexes, state : BatchDrawState }>;
 	var bufferDirty : Bool;
 	var bufferDirty : Bool;
 	var indexDirty : Bool;
 	var indexDirty : Bool;
-	#if track_alloc
 	var allocPos : hxd.impl.AllocPos;
 	var allocPos : hxd.impl.AllocPos;
-	#end
 
 
 	public function new() {
 	public function new() {
 		buffers = [];
 		buffers = [];
 		state = new BatchDrawState();
 		state = new BatchDrawState();
-		#if track_alloc
-		this.allocPos = new hxd.impl.AllocPos();
-		#end
+		this.allocPos = hxd.impl.AllocPos.make();
 	}
 	}
 
 
 	public inline function addIndex(i) {
 	public inline function addIndex(i) {
@@ -88,9 +84,7 @@ private class GraphicsContent extends h3d.prim.Primitive {
 		if (index.length <= 0) return ;
 		if (index.length <= 0) return ;
 		var alloc = Allocator.get();
 		var alloc = Allocator.get();
 		buffer = alloc.ofFloats(tmp, hxd.BufferFormat.H2D);
 		buffer = alloc.ofFloats(tmp, hxd.BufferFormat.H2D);
-		#if track_alloc
 		@:privateAccess buffer.allocPos = allocPos;
 		@:privateAccess buffer.allocPos = allocPos;
-		#end
 		indexes = alloc.ofIndexes(index);
 		indexes = alloc.ofIndexes(index);
 		for( b in buffers ) {
 		for( b in buffers ) {
 			if( b.vbuf == null || b.vbuf.isDisposed() ) b.vbuf = alloc.ofFloats(b.buf, hxd.BufferFormat.H2D);
 			if( b.vbuf == null || b.vbuf.isDisposed() ) b.vbuf = alloc.ofFloats(b.buf, hxd.BufferFormat.H2D);

+ 1 - 6
h3d/Buffer.hx

@@ -27,10 +27,7 @@ enum BufferFlag {
 class Buffer {
 class Buffer {
 	public static var GUID = 0;
 	public static var GUID = 0;
 	public var id : Int;
 	public var id : Int;
-	#if track_alloc
 	var allocPos : hxd.impl.AllocPos;
 	var allocPos : hxd.impl.AllocPos;
-	var allocNext : Buffer;
-	#end
 	var engine : h3d.Engine;
 	var engine : h3d.Engine;
 	var lastFrame : Int;
 	var lastFrame : Int;
 
 
@@ -44,9 +41,7 @@ class Buffer {
 		this.vertices = vertices;
 		this.vertices = vertices;
 		this.format = format;
 		this.format = format;
 		this.flags = new haxe.EnumFlags();
 		this.flags = new haxe.EnumFlags();
-		#if track_alloc
-		this.allocPos = new hxd.impl.AllocPos();
-		#end
+		this.allocPos = hxd.impl.AllocPos.make();
 		if( flags != null )
 		if( flags != null )
 			for( f in flags )
 			for( f in flags )
 				this.flags.set(f);
 				this.flags.set(f);

+ 9 - 7
h3d/impl/MemoryManager.hx

@@ -32,6 +32,10 @@ class MemoryManager {
 		initIndexes();
 		initIndexes();
 	}
 	}
 
 
+	public static function enableTrackAlloc(?b : Bool) {
+		@:privateAccess hxd.impl.AllocPos.ENABLED = b != null ? b : true; 
+	}
+
 	function initIndexes() {
 	function initIndexes() {
 		var indices = new hxd.IndexBuffer();
 		var indices = new hxd.IndexBuffer();
 		for( i in 0...SIZE ) indices.push(i);
 		for( i in 0...SIZE ) indices.push(i);
@@ -263,9 +267,6 @@ class MemoryManager {
 	 */
 	 */
 	@:access(h3d.Buffer)
 	@:access(h3d.Buffer)
 	public function allocStats() : Array<{ position : String, count : Int, tex : Bool, size : Int, stacks : Array<{ stack : String, count : Int, size : Int }> }> {
 	public function allocStats() : Array<{ position : String, count : Int, tex : Bool, size : Int, stacks : Array<{ stack : String, count : Int, size : Int }> }> {
-		#if !track_alloc
-		return [];
-		#else
 		var h = new Map();
 		var h = new Map();
 		var all = [];
 		var all = [];
 		inline function addStack( a : hxd.impl.AllocPos, stacks : Array<{ stack : String, count : Int, size : Int }>, size : Int ) {
 		inline function addStack( a : hxd.impl.AllocPos, stacks : Array<{ stack : String, count : Int, size : Int }>, size : Int ) {
@@ -280,6 +281,8 @@ class MemoryManager {
 				stacks.push({ stack : stackStr, count : 1, size : size });
 				stacks.push({ stack : stackStr, count : 1, size : size });
 		}
 		}
 		for( t in textures ) {
 		for( t in textures ) {
+			if ( t.allocPos == null )
+				continue;
 			var key = "$"+t.allocPos.position;
 			var key = "$"+t.allocPos.position;
 			var inf = h.get(key);
 			var inf = h.get(key);
 			if( inf == null ) {
 			if( inf == null ) {
@@ -293,7 +296,9 @@ class MemoryManager {
 			addStack(t.allocPos, inf.stacks, size);
 			addStack(t.allocPos, inf.stacks, size);
 		}
 		}
 		for( b in buffers ) {
 		for( b in buffers ) {
-			var key = b.allocPos == null ? "null" : b.allocPos.position;
+			if ( b.allocPos == null )
+				continue;
+			var key = b.allocPos.position;
 			var inf = h.get(key);
 			var inf = h.get(key);
 			if( inf == null ) {
 			if( inf == null ) {
 				inf = { position : key, count : 0, size : 0, tex : false, stacks : [] };
 				inf = { position : key, count : 0, size : 0, tex : false, stacks : [] };
@@ -307,8 +312,5 @@ class MemoryManager {
 		}
 		}
 		all.sort(function(a, b) return b.size - a.size);
 		all.sort(function(a, b) return b.size - a.size);
 		return all;
 		return all;
-		#end
 	}
 	}
-
-
 }
 }

+ 1 - 7
h3d/mat/Texture.hx

@@ -22,9 +22,7 @@ class Texture {
 
 
 	var t : h3d.impl.Driver.Texture;
 	var t : h3d.impl.Driver.Texture;
 	var mem : h3d.impl.MemoryManager;
 	var mem : h3d.impl.MemoryManager;
-	#if track_alloc
 	var allocPos : hxd.impl.AllocPos;
 	var allocPos : hxd.impl.AllocPos;
-	#end
 	public var id(default, null) : Int;
 	public var id(default, null) : Int;
 	public var name(default, null) : String;
 	public var name(default, null) : String;
 	public var width(default, null) : Int;
 	public var width(default, null) : Int;
@@ -117,9 +115,7 @@ class Texture {
 		this.filter = Linear;
 		this.filter = Linear;
 		this.wrap = DEFAULT_WRAP;
 		this.wrap = DEFAULT_WRAP;
 		bits &= 0x7FFF;
 		bits &= 0x7FFF;
-		#if track_alloc
-		this.allocPos = new hxd.impl.AllocPos();
-		#end
+		this.allocPos = hxd.impl.AllocPos.make();
 		if( !this.flags.has(NoAlloc) && (!isDepth() || width > 0) ) alloc();
 		if( !this.flags.has(NoAlloc) && (!isDepth() || width > 0) ) alloc();
 	}
 	}
 
 
@@ -196,9 +192,7 @@ class Texture {
 		var str = name;
 		var str = name;
 		if( name == null ) {
 		if( name == null ) {
 			str = "Texture_" + id;
 			str = "Texture_" + id;
-			#if track_alloc
 			if( allocPos != null ) str += "(" + allocPos.position + ")";
 			if( allocPos != null ) str += "(" + allocPos.position + ")";
-			#end
 		}
 		}
 		return str+"("+width+"x"+height+")";
 		return str+"("+width+"x"+height+")";
 	}
 	}

+ 1 - 7
h3d/prim/BigPrimitive.hx

@@ -16,9 +16,7 @@ class BigPrimitive extends Primitive {
 	var idxPos : Int = 0;
 	var idxPos : Int = 0;
 	var startIndex : Int = 0;
 	var startIndex : Int = 0;
 	var flushing : Bool;
 	var flushing : Bool;
-	#if track_alloc
 	var allocPos : hxd.impl.AllocPos;
 	var allocPos : hxd.impl.AllocPos;
-	#end
 
 
 	var allocator : hxd.impl.Allocator;
 	var allocator : hxd.impl.Allocator;
 
 
@@ -35,9 +33,7 @@ class BigPrimitive extends Primitive {
 		bounds = new h3d.col.Bounds();
 		bounds = new h3d.col.Bounds();
 		this.allocator = alloc;
 		this.allocator = alloc;
 		if( format.stride < 3 ) throw "Minimum stride = 3";
 		if( format.stride < 3 ) throw "Minimum stride = 3";
-		#if track_alloc
-		allocPos = new hxd.impl.AllocPos();
-		#end
+		allocPos = hxd.impl.AllocPos.make();
 	}
 	}
 
 
 	/**
 	/**
@@ -136,11 +132,9 @@ class BigPrimitive extends Primitive {
 
 
 				allIndexes.push(idx);
 				allIndexes.push(idx);
 				flushing = false;
 				flushing = false;
-				#if track_alloc
 				@:privateAccess b.allocPos = allocPos;
 				@:privateAccess b.allocPos = allocPos;
 				var idx : h3d.Buffer = idx;
 				var idx : h3d.Buffer = idx;
 				@:privateAccess idx.allocPos = allocPos;
 				@:privateAccess idx.allocPos = allocPos;
-				#end
 			}
 			}
 			if( PREV_BUFFER == null || PREV_BUFFER.length < tmpBuf.length )
 			if( PREV_BUFFER == null || PREV_BUFFER.length < tmpBuf.length )
 				PREV_BUFFER = tmpBuf;
 				PREV_BUFFER = tmpBuf;

+ 10 - 6
hxd/impl/AllocPos.hx

@@ -1,15 +1,20 @@
 package hxd.impl;
 package hxd.impl;
 
 
-typedef AllocPos = #if track_alloc AllocPosImpl #else {} #end
+class AllocPos {
 
 
-#if track_alloc
-class AllocPosImpl {
+	static var ENABLED : Bool = false;
 
 
 	public var position : String;
 	public var position : String;
 	public var stack : Array<String> = [];
 	public var stack : Array<String> = [];
 	public static var ENGINE_PACKAGES = ["h3d","hxd","h2d","haxe","sys","hrt" /* HIDE */];
 	public static var ENGINE_PACKAGES = ["h3d","hxd","h2d","haxe","sys","hrt" /* HIDE */];
 
 
-	public function new() {
+	public static function make() {
+		if ( !ENABLED )
+			return null;
+		return new AllocPos();
+	}
+	
+	function new() {
 		var curStack = haxe.CallStack.callStack();
 		var curStack = haxe.CallStack.callStack();
 		curStack.shift();
 		curStack.shift();
 		for( s in curStack ) {
 		for( s in curStack ) {
@@ -34,5 +39,4 @@ class AllocPosImpl {
 		if( position == null ) position = stack[0];
 		if( position == null ) position = stack[0];
 	}
 	}
 
 
-}
-#end
+}