Prechádzať zdrojové kódy

Add possibility to call a computeDispatch without automatic memoryBarrier. Manual control may improve performances.

borisrp 2 dní pred
rodič
commit
5b8a71655d

+ 4 - 3
h3d/impl/DX12Driver.hx

@@ -2547,13 +2547,14 @@ class DX12Driver extends h3d.impl.Driver {
 		}
 	}
 
-	override function computeDispatch( x : Int = 1, y : Int = 1, z : Int = 1 ) {
+	override function computeDispatch( x : Int = 1, y : Int = 1, z : Int = 1, barrier : Bool = true ) {
 		flushTransitions();
 		frame.commandList.dispatch(x,y,z);
-		uavBarrier();
+		if( barrier )
+			memoryBarrier();
 	}
 
-	function uavBarrier() {
+	override function memoryBarrier() {
 		var barrier = tmp.barrier;
 		barrier.resource = null;
 		@:privateAccess barrier.type = UAV;

+ 5 - 1
h3d/impl/Driver.hx

@@ -309,7 +309,11 @@ class Driver {
 
 	// --- COMPUTE
 
-	public function computeDispatch( x : Int = 1, y : Int = 1, z : Int = 1 ) {
+	public function computeDispatch( x : Int = 1, y : Int = 1, z : Int = 1, barrier: Bool = true ) {
+		throw "Compute shaders are not implemented on this platform";
+	}
+
+	public function memoryBarrier(){
 		throw "Compute shaders are not implemented on this platform";
 	}
 

+ 6 - 1
h3d/impl/GlDriver.hx

@@ -2040,8 +2040,13 @@ class GlDriver extends Driver {
 
 	#if hl
 
-	override function computeDispatch(x:Int = 1, y:Int = 1, z:Int = 1) {
+	override function computeDispatch(x:Int = 1, y:Int = 1, z:Int = 1, barrier:Bool = true) {
 		GL.dispatchCompute(x,y,z);
+		if( barrier )
+			memoryBarrier();
+	}
+
+	override function memoryBarrier(){
 		GL.memoryBarrier(GL.BUFFER_UPDATE_BARRIER_BIT | GL.TEXTURE_FETCH_BARRIER_BIT);
 	}
 

+ 6 - 2
h3d/scene/RenderContext.hx

@@ -174,7 +174,11 @@ class RenderContext extends h3d.impl.RenderContext {
 		computeLink = list;
 	}
 
-	public function computeDispatch( ?shader : hxsl.Shader, x = 1, y = 1, z = 1 ) {
+	public function memoryBarrier(){
+		engine.driver.memoryBarrier();
+	}
+
+	public function computeDispatch( ?shader : hxsl.Shader, x = 1, y = 1, z = 1, barrier : Bool = true) {
 		if ( x <= 0 || y <= 0 || z <= 0 )
 			throw "Can't use zero or negative work groups count";
 
@@ -199,7 +203,7 @@ class RenderContext extends h3d.impl.RenderContext {
 		engine.uploadShaderBuffers(buf, Globals);
 		fillParams(buf, rt, computeLink, true);
 		engine.uploadInstanceShaderBuffers(buf);
-		engine.driver.computeDispatch(x,y,z);
+		engine.driver.computeDispatch(x,y,z, barrier);
 		@:privateAccess engine.dispatches++;
 		if ( computeLink == tmpComputeLink )
 			tmpComputeLink.s = null;