Ver Fonte

Add GPUCounter helper to works with atomicAdd in shaders and readback values.

borisrp há 4 meses atrás
pai
commit
074512f11c
1 ficheiros alterados com 25 adições e 0 exclusões
  1. 25 0
      h3d/GPUCounter.hx

+ 25 - 0
h3d/GPUCounter.hx

@@ -0,0 +1,25 @@
+package h3d;
+
+class GPUCounter {
+	public var buffer(default, null) : h3d.Buffer;
+	var accessor : haxe.io.Bytes;
+
+	public function new() {
+		buffer = new h3d.Buffer(1,hxd.BufferFormat.INDEX32, [ReadWriteBuffer]);
+		accessor = haxe.io.Bytes.alloc(4);
+	}
+
+	public function dispose(){
+		buffer.dispose();
+	}
+
+	public function get() : Int {
+		buffer.readBytes(accessor, 0, 1);
+		return accessor.getInt32(0);
+	}
+
+	public function reset(){
+		accessor.setInt32(0, 0);
+		buffer.uploadBytes(accessor, 0,1);
+	}
+}