RenderGraphDriver.hx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package h3d.impl;
  2. import h3d.impl.Driver;
  3. #if render_graph
  4. class RenderGraphDriver extends Driver {
  5. var d : Driver;
  6. var loggedShaders = new Map<Int,Bool>();
  7. var currentShader : hxsl.RuntimeShader;
  8. public var logLines : Array<String> = null;
  9. public function new( driver : Driver ) {
  10. this.d = driver;
  11. logEnable = true;
  12. driver.logEnable = true;
  13. }
  14. override function hasFeature( f : Feature ) {
  15. return d.hasFeature(f);
  16. }
  17. override function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) {
  18. return d.isSupportedFormat(fmt);
  19. }
  20. override function isDisposed() {
  21. return d.isDisposed();
  22. }
  23. override function dispose() {
  24. d.dispose();
  25. }
  26. override function begin( frame : Int ) {
  27. d.begin(frame);
  28. }
  29. override function clear( ?color : h3d.Vector4, ?depth : Float, ?stencil : Int ) {
  30. h3d.impl.RenderGraph.clearTarget();
  31. d.clear(color, depth, stencil);
  32. }
  33. override function captureRenderBuffer( pixels : hxd.Pixels ) {
  34. d.captureRenderBuffer(pixels);
  35. }
  36. override function getDriverName( details : Bool ) {
  37. return "RenderGraphDriver " + d.getDriverName(details);
  38. }
  39. override function init( onCreate : Bool -> Void, forceSoftware = false ) {
  40. d.init(function(b) {
  41. log('OnCreate $b');
  42. onCreate(b);
  43. },forceSoftware);
  44. }
  45. override function resize( width : Int, height : Int ) {
  46. d.resize(width, height);
  47. }
  48. override function selectShader( shader : hxsl.RuntimeShader ) {
  49. currentShader = shader;
  50. return d.selectShader(shader);
  51. }
  52. override function getNativeShaderCode( shader ) {
  53. return d.getNativeShaderCode(shader);
  54. }
  55. override function selectMaterial( pass : h3d.mat.Pass ) {
  56. d.selectMaterial(pass);
  57. }
  58. override function uploadShaderBuffers( buffers : h3d.shader.Buffers, which : h3d.shader.Buffers.BufferKind ) {
  59. uploadBuffer(buffers, currentShader.vertex, buffers.vertex, which);
  60. if ( currentShader.fragment != null )
  61. uploadBuffer(buffers, currentShader.fragment, buffers.fragment, which);
  62. d.uploadShaderBuffers(buffers, which);
  63. }
  64. function uploadBuffer( buffer : h3d.shader.Buffers, s : hxsl.RuntimeShader.RuntimeShaderData, buf : h3d.shader.Buffers.ShaderBuffers, which : h3d.shader.Buffers.BufferKind ) {
  65. switch( which ) {
  66. case Globals:
  67. case Params:
  68. case Buffers:
  69. case Textures:
  70. inline function logVars( s : hxsl.RuntimeShader.RuntimeShaderData, buf : h3d.shader.Buffers.ShaderBuffers ) {
  71. var t = s.textures;
  72. while( t != null ) {
  73. RenderGraph.sampleTexture(buf.tex[t.pos]);
  74. log('Set ${s.kind.getName()} Texture@${t.pos} ' + t.name);
  75. t = t.next;
  76. }
  77. }
  78. logVars(s, buf);
  79. }
  80. }
  81. override function selectBuffer( buffer : Buffer ) {
  82. d.selectBuffer(buffer);
  83. }
  84. override function selectMultiBuffers( formats : hxd.BufferFormat.MultiFormat, buffers : Array<Buffer> ) {
  85. d.selectMultiBuffers(formats,buffers);
  86. }
  87. override function draw( ibuf : h3d.Buffer, startIndex : Int, ntriangles : Int ) {
  88. d.draw(ibuf, startIndex, ntriangles);
  89. }
  90. override function drawInstanced( ibuf, commands ) {
  91. d.drawInstanced(ibuf, commands);
  92. }
  93. override function flushShaderBuffers() {
  94. d.flushShaderBuffers();
  95. }
  96. override function setRenderZone( x : Int, y : Int, width : Int, height : Int ) {
  97. d.setRenderZone(x, y, width, height);
  98. }
  99. override function setRenderTarget( tex : Null<h3d.mat.Texture>, face = 0, mipMap = 0, depthBinding : h3d.Engine.DepthBinding = ReadWrite ) {
  100. h3d.impl.RenderGraph.setTarget(tex, face, mipMap, depthBinding);
  101. d.setRenderTarget(tex, face);
  102. }
  103. override function setRenderTargets( textures : Array<h3d.mat.Texture>, depthBinding : h3d.Engine.DepthBinding = ReadWrite ) {
  104. h3d.impl.RenderGraph.setTargets(textures, depthBinding);
  105. d.setRenderTargets(textures);
  106. }
  107. override function setDepth( depthBuffer : h3d.mat.Texture ) {
  108. h3d.impl.RenderGraph.setDepth(depthBuffer);
  109. d.setDepth(depthBuffer);
  110. }
  111. override function end() {
  112. d.end();
  113. }
  114. override function present() {
  115. d.present();
  116. }
  117. override function setDebug( b : Bool ) {
  118. d.setDebug(b);
  119. }
  120. override function allocTexture( t : h3d.mat.Texture ) : Texture {
  121. return d.allocTexture(t);
  122. }
  123. override function allocDepthBuffer( t : h3d.mat.Texture ) : Texture {
  124. return d.allocDepthBuffer(t);
  125. }
  126. override function allocBuffer( b : Buffer ) : GPUBuffer {
  127. return d.allocBuffer(b);
  128. }
  129. override function allocInstanceBuffer(b, bytes) {
  130. d.allocInstanceBuffer(b, bytes);
  131. }
  132. override function uploadInstanceBufferBytes(b, startVertex, vertexCount, buf, bufPos) {
  133. d.uploadInstanceBufferBytes(b, startVertex, vertexCount, buf, bufPos);
  134. }
  135. override function disposeTexture( t : h3d.mat.Texture ) {
  136. d.disposeTexture(t);
  137. }
  138. override function disposeDepthBuffer(t : h3d.mat.Texture ) {
  139. d.disposeDepthBuffer(t);
  140. }
  141. override function disposeBuffer( b : h3d.Buffer ) {
  142. d.disposeBuffer(b);
  143. }
  144. override function disposeInstanceBuffer(b) {
  145. d.disposeInstanceBuffer(b);
  146. }
  147. override function uploadIndexData(i, startIndice, indiceCount, buf, bufPos) {
  148. d.uploadIndexData(i, startIndice, indiceCount, buf, bufPos);
  149. }
  150. override function uploadBufferData( b : h3d.Buffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
  151. d.uploadBufferData(b, startVertex, vertexCount, buf, bufPos);
  152. }
  153. override function uploadBufferBytes( b : h3d.Buffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  154. d.uploadBufferBytes(b, startVertex, vertexCount, buf, bufPos);
  155. }
  156. override function readBufferBytes( b : h3d.Buffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  157. d.readBufferBytes(b, startVertex, vertexCount, buf, bufPos);
  158. }
  159. override function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
  160. d.uploadTextureBitmap(t, bmp, mipLevel, side);
  161. }
  162. override function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
  163. d.uploadTexturePixels(t, pixels, mipLevel, side);
  164. }
  165. override function computeDispatch( x : Int = 1, y : Int = 1, z : Int = 1, barrier : Bool = true ) {
  166. d.computeDispatch(x, y, z, barrier);
  167. }
  168. override function getDefaultDepthBuffer() {
  169. return d.getDefaultDepthBuffer();
  170. }
  171. override function capturePixels(tex, layer, mipLevel, ?region) {
  172. return d.capturePixels(tex, layer, mipLevel, region);
  173. }
  174. override function copyTexture(from, to) {
  175. return d.copyTexture(from, to);
  176. }
  177. override function allocQuery(queryKind) {
  178. return d.allocQuery(queryKind);
  179. }
  180. override function deleteQuery(q) {
  181. d.deleteQuery(q);
  182. }
  183. override function beginQuery(q : Query) {
  184. d.beginQuery(q);
  185. }
  186. override function endQuery(q) {
  187. d.endQuery(q);
  188. }
  189. override function queryResultAvailable(q) {
  190. return d.queryResultAvailable(q);
  191. }
  192. override function queryResult( q : Query ) {
  193. return d.queryResult(q);
  194. }
  195. }
  196. #end