ThreedClass.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. using Ryujinx.Graphics.Device;
  2. using Ryujinx.Graphics.GAL;
  3. using Ryujinx.Graphics.Gpu.Engine.GPFifo;
  4. using Ryujinx.Graphics.Gpu.Engine.InlineToMemory;
  5. using Ryujinx.Graphics.Gpu.Engine.Threed.Blender;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Runtime.CompilerServices;
  9. namespace Ryujinx.Graphics.Gpu.Engine.Threed
  10. {
  11. /// <summary>
  12. /// Represents a 3D engine class.
  13. /// </summary>
  14. class ThreedClass : IDeviceState
  15. {
  16. private readonly GpuContext _context;
  17. private readonly GPFifoClass _fifoClass;
  18. private readonly DeviceStateWithShadow<ThreedClassState> _state;
  19. private readonly InlineToMemoryClass _i2mClass;
  20. private readonly AdvancedBlendManager _blendManager;
  21. private readonly DrawManager _drawManager;
  22. private readonly SemaphoreUpdater _semaphoreUpdater;
  23. private readonly ConstantBufferUpdater _cbUpdater;
  24. private readonly StateUpdater _stateUpdater;
  25. /// <summary>
  26. /// Creates a new instance of the 3D engine class.
  27. /// </summary>
  28. /// <param name="context">GPU context</param>
  29. /// <param name="channel">GPU channel</param>
  30. public ThreedClass(GpuContext context, GpuChannel channel, GPFifoClass fifoClass)
  31. {
  32. _context = context;
  33. _fifoClass = fifoClass;
  34. _state = new DeviceStateWithShadow<ThreedClassState>(new Dictionary<string, RwCallback>
  35. {
  36. { nameof(ThreedClassState.LaunchDma), new RwCallback(LaunchDma, null) },
  37. { nameof(ThreedClassState.LoadInlineData), new RwCallback(LoadInlineData, null) },
  38. { nameof(ThreedClassState.SyncpointAction), new RwCallback(IncrementSyncpoint, null) },
  39. { nameof(ThreedClassState.InvalidateSamplerCacheNoWfi), new RwCallback(InvalidateSamplerCacheNoWfi, null) },
  40. { nameof(ThreedClassState.InvalidateTextureHeaderCacheNoWfi), new RwCallback(InvalidateTextureHeaderCacheNoWfi, null) },
  41. { nameof(ThreedClassState.TextureBarrier), new RwCallback(TextureBarrier, null) },
  42. { nameof(ThreedClassState.LoadBlendUcodeStart), new RwCallback(LoadBlendUcodeStart, null) },
  43. { nameof(ThreedClassState.LoadBlendUcodeInstruction), new RwCallback(LoadBlendUcodeInstruction, null) },
  44. { nameof(ThreedClassState.TextureBarrierTiled), new RwCallback(TextureBarrierTiled, null) },
  45. { nameof(ThreedClassState.DrawTextureSrcY), new RwCallback(DrawTexture, null) },
  46. { nameof(ThreedClassState.DrawVertexArrayBeginEndInstanceFirst), new RwCallback(DrawVertexArrayBeginEndInstanceFirst, null) },
  47. { nameof(ThreedClassState.DrawVertexArrayBeginEndInstanceSubsequent), new RwCallback(DrawVertexArrayBeginEndInstanceSubsequent, null) },
  48. { nameof(ThreedClassState.VbElementU8), new RwCallback(VbElementU8, null) },
  49. { nameof(ThreedClassState.VbElementU16), new RwCallback(VbElementU16, null) },
  50. { nameof(ThreedClassState.VbElementU32), new RwCallback(VbElementU32, null) },
  51. { nameof(ThreedClassState.ResetCounter), new RwCallback(ResetCounter, null) },
  52. { nameof(ThreedClassState.RenderEnableCondition), new RwCallback(null, Zero) },
  53. { nameof(ThreedClassState.DrawEnd), new RwCallback(DrawEnd, null) },
  54. { nameof(ThreedClassState.DrawBegin), new RwCallback(DrawBegin, null) },
  55. { nameof(ThreedClassState.DrawIndexBuffer32BeginEndInstanceFirst), new RwCallback(DrawIndexBuffer32BeginEndInstanceFirst, null) },
  56. { nameof(ThreedClassState.DrawIndexBuffer16BeginEndInstanceFirst), new RwCallback(DrawIndexBuffer16BeginEndInstanceFirst, null) },
  57. { nameof(ThreedClassState.DrawIndexBuffer8BeginEndInstanceFirst), new RwCallback(DrawIndexBuffer8BeginEndInstanceFirst, null) },
  58. { nameof(ThreedClassState.DrawIndexBuffer32BeginEndInstanceSubsequent), new RwCallback(DrawIndexBuffer32BeginEndInstanceSubsequent, null) },
  59. { nameof(ThreedClassState.DrawIndexBuffer16BeginEndInstanceSubsequent), new RwCallback(DrawIndexBuffer16BeginEndInstanceSubsequent, null) },
  60. { nameof(ThreedClassState.DrawIndexBuffer8BeginEndInstanceSubsequent), new RwCallback(DrawIndexBuffer8BeginEndInstanceSubsequent, null) },
  61. { nameof(ThreedClassState.IndexBufferCount), new RwCallback(SetIndexBufferCount, null) },
  62. { nameof(ThreedClassState.Clear), new RwCallback(Clear, null) },
  63. { nameof(ThreedClassState.SemaphoreControl), new RwCallback(Report, null) },
  64. { nameof(ThreedClassState.SetFalcon04), new RwCallback(SetFalcon04, null) },
  65. { nameof(ThreedClassState.UniformBufferUpdateData), new RwCallback(ConstantBufferUpdate, null) },
  66. { nameof(ThreedClassState.UniformBufferBindVertex), new RwCallback(ConstantBufferBindVertex, null) },
  67. { nameof(ThreedClassState.UniformBufferBindTessControl), new RwCallback(ConstantBufferBindTessControl, null) },
  68. { nameof(ThreedClassState.UniformBufferBindTessEvaluation), new RwCallback(ConstantBufferBindTessEvaluation, null) },
  69. { nameof(ThreedClassState.UniformBufferBindGeometry), new RwCallback(ConstantBufferBindGeometry, null) },
  70. { nameof(ThreedClassState.UniformBufferBindFragment), new RwCallback(ConstantBufferBindFragment, null) }
  71. });
  72. _i2mClass = new InlineToMemoryClass(context, channel, initializeState: false);
  73. var spec = new SpecializationStateUpdater(context);
  74. var drawState = new DrawState();
  75. _drawManager = new DrawManager(context, channel, _state, drawState, spec);
  76. _blendManager = new AdvancedBlendManager(_state);
  77. _semaphoreUpdater = new SemaphoreUpdater(context, channel, _state);
  78. _cbUpdater = new ConstantBufferUpdater(channel, _state);
  79. _stateUpdater = new StateUpdater(context, channel, _state, drawState, _blendManager, spec);
  80. // This defaults to "always", even without any register write.
  81. // Reads just return 0, regardless of what was set there.
  82. _state.State.RenderEnableCondition = Condition.Always;
  83. }
  84. /// <summary>
  85. /// Reads data from the class registers.
  86. /// </summary>
  87. /// <param name="offset">Register byte offset</param>
  88. /// <returns>Data at the specified offset</returns>
  89. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  90. public int Read(int offset) => _state.Read(offset);
  91. /// <summary>
  92. /// Writes data to the class registers.
  93. /// </summary>
  94. /// <param name="offset">Register byte offset</param>
  95. /// <param name="data">Data to be written</param>
  96. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  97. public void Write(int offset, int data)
  98. {
  99. _state.WriteWithRedundancyCheck(offset, data, out bool valueChanged);
  100. if (valueChanged)
  101. {
  102. _stateUpdater.SetDirty(offset);
  103. }
  104. }
  105. /// <summary>
  106. /// Sets the shadow ram control value of all sub-channels.
  107. /// </summary>
  108. /// <param name="control">New shadow ram control value</param>
  109. public void SetShadowRamControl(int control)
  110. {
  111. _state.State.SetMmeShadowRamControl = (uint)control;
  112. }
  113. /// <summary>
  114. /// Updates current host state for all registers modified since the last call to this method.
  115. /// </summary>
  116. public void UpdateState()
  117. {
  118. _fifoClass.CreatePendingSyncs();
  119. _cbUpdater.FlushUboDirty();
  120. _stateUpdater.Update();
  121. }
  122. /// <summary>
  123. /// Updates current host state for all registers modified since the last call to this method.
  124. /// </summary>
  125. /// <param name="mask">Mask where each bit set indicates that the respective state group index should be checked</param>
  126. public void UpdateState(ulong mask)
  127. {
  128. _stateUpdater.Update(mask);
  129. }
  130. /// <summary>
  131. /// Updates render targets (color and depth-stencil buffers) based on current render target state.
  132. /// </summary>
  133. /// <param name="updateFlags">Flags indicating which render targets should be updated and how</param>
  134. /// <param name="singleUse">If this is not -1, it indicates that only the given indexed target will be used.</param>
  135. public void UpdateRenderTargetState(RenderTargetUpdateFlags updateFlags, int singleUse = -1)
  136. {
  137. _stateUpdater.UpdateRenderTargetState(updateFlags, singleUse);
  138. }
  139. /// <summary>
  140. /// Updates scissor based on current render target state.
  141. /// </summary>
  142. public void UpdateScissorState()
  143. {
  144. _stateUpdater.UpdateScissorState();
  145. }
  146. /// <summary>
  147. /// Marks the entire state as dirty, forcing a full host state update before the next draw.
  148. /// </summary>
  149. public void ForceStateDirty()
  150. {
  151. _drawManager.ForceStateDirty();
  152. _stateUpdater.SetAllDirty();
  153. }
  154. /// <summary>
  155. /// Marks the specified register offset as dirty, forcing the associated state to update on the next draw.
  156. /// </summary>
  157. /// <param name="offset">Register offset</param>
  158. public void ForceStateDirty(int offset)
  159. {
  160. _stateUpdater.SetDirty(offset);
  161. }
  162. /// <summary>
  163. /// Forces the shaders to be rebound on the next draw.
  164. /// </summary>
  165. public void ForceShaderUpdate()
  166. {
  167. _stateUpdater.ForceShaderUpdate();
  168. }
  169. /// <summary>
  170. /// Create any syncs from WaitForIdle command that are currently pending.
  171. /// </summary>
  172. public void CreatePendingSyncs()
  173. {
  174. _fifoClass.CreatePendingSyncs();
  175. }
  176. /// <summary>
  177. /// Flushes any queued UBO updates.
  178. /// </summary>
  179. public void FlushUboDirty()
  180. {
  181. _cbUpdater.FlushUboDirty();
  182. }
  183. /// <summary>
  184. /// Perform any deferred draws.
  185. /// </summary>
  186. public void PerformDeferredDraws()
  187. {
  188. _drawManager.PerformDeferredDraws();
  189. }
  190. /// <summary>
  191. /// Updates the currently bound constant buffer.
  192. /// </summary>
  193. /// <param name="data">Data to be written to the buffer</param>
  194. public void ConstantBufferUpdate(ReadOnlySpan<int> data)
  195. {
  196. _cbUpdater.Update(data);
  197. }
  198. /// <summary>
  199. /// Launches the Inline-to-Memory DMA copy operation.
  200. /// </summary>
  201. /// <param name="argument">Method call argument</param>
  202. private void LaunchDma(int argument)
  203. {
  204. _i2mClass.LaunchDma(ref Unsafe.As<ThreedClassState, InlineToMemoryClassState>(ref _state.State), argument);
  205. }
  206. /// <summary>
  207. /// Pushes a block of data to the Inline-to-Memory engine.
  208. /// </summary>
  209. /// <param name="data">Data to push</param>
  210. public void LoadInlineData(ReadOnlySpan<int> data)
  211. {
  212. _i2mClass.LoadInlineData(data);
  213. }
  214. /// <summary>
  215. /// Pushes a word of data to the Inline-to-Memory engine.
  216. /// </summary>
  217. /// <param name="argument">Method call argument</param>
  218. private void LoadInlineData(int argument)
  219. {
  220. _i2mClass.LoadInlineData(argument);
  221. }
  222. /// <summary>
  223. /// Performs an incrementation on a syncpoint.
  224. /// </summary>
  225. /// <param name="argument">Method call argument</param>
  226. public void IncrementSyncpoint(int argument)
  227. {
  228. uint syncpointId = (uint)argument & 0xFFFF;
  229. _context.AdvanceSequence();
  230. _context.CreateHostSyncIfNeeded(true, true);
  231. _context.Renderer.UpdateCounters(); // Poll the query counters, the game may want an updated result.
  232. _context.Synchronization.IncrementSyncpoint(syncpointId);
  233. }
  234. /// <summary>
  235. /// Invalidates the cache with the sampler descriptors from the sampler pool.
  236. /// </summary>
  237. /// <param name="argument">Method call argument (unused)</param>
  238. private void InvalidateSamplerCacheNoWfi(int argument)
  239. {
  240. _context.AdvanceSequence();
  241. }
  242. /// <summary>
  243. /// Invalidates the cache with the texture descriptors from the texture pool.
  244. /// </summary>
  245. /// <param name="argument">Method call argument (unused)</param>
  246. private void InvalidateTextureHeaderCacheNoWfi(int argument)
  247. {
  248. _context.AdvanceSequence();
  249. }
  250. /// <summary>
  251. /// Issues a texture barrier.
  252. /// This waits until previous texture writes from the GPU to finish, before
  253. /// performing new operations with said textures.
  254. /// </summary>
  255. /// <param name="argument">Method call argument (unused)</param>
  256. private void TextureBarrier(int argument)
  257. {
  258. _context.Renderer.Pipeline.TextureBarrier();
  259. }
  260. /// <summary>
  261. /// Sets the start offset of the blend microcode in memory.
  262. /// </summary>
  263. /// <param name="argument">Method call argument</param>
  264. private void LoadBlendUcodeStart(int argument)
  265. {
  266. _blendManager.LoadBlendUcodeStart(argument);
  267. }
  268. /// <summary>
  269. /// Pushes one word of blend microcode.
  270. /// </summary>
  271. /// <param name="argument">Method call argument</param>
  272. private void LoadBlendUcodeInstruction(int argument)
  273. {
  274. _blendManager.LoadBlendUcodeInstruction(argument);
  275. }
  276. /// <summary>
  277. /// Issues a texture barrier.
  278. /// This waits until previous texture writes from the GPU to finish, before
  279. /// performing new operations with said textures.
  280. /// This performs a per-tile wait, it is only valid if both the previous write
  281. /// and current access has the same access patterns.
  282. /// This may be faster than the regular barrier on tile-based rasterizers.
  283. /// </summary>
  284. /// <param name="argument">Method call argument (unused)</param>
  285. private void TextureBarrierTiled(int argument)
  286. {
  287. _context.Renderer.Pipeline.TextureBarrierTiled();
  288. }
  289. /// <summary>
  290. /// Draws a texture, without needing to specify shader programs.
  291. /// </summary>
  292. /// <param name="argument">Method call argument</param>
  293. private void DrawTexture(int argument)
  294. {
  295. _drawManager.DrawTexture(this, argument);
  296. }
  297. /// <summary>
  298. /// Performs a non-indexed draw with the specified topology, index and count.
  299. /// </summary>
  300. /// <param name="argument">Method call argument</param>
  301. private void DrawVertexArrayBeginEndInstanceFirst(int argument)
  302. {
  303. _drawManager.DrawVertexArrayBeginEndInstanceFirst(this, argument);
  304. }
  305. /// <summary>
  306. /// Performs a non-indexed draw with the specified topology, index and count,
  307. /// while incrementing the current instance.
  308. /// </summary>
  309. /// <param name="argument">Method call argument</param>
  310. private void DrawVertexArrayBeginEndInstanceSubsequent(int argument)
  311. {
  312. _drawManager.DrawVertexArrayBeginEndInstanceSubsequent(this, argument);
  313. }
  314. /// <summary>
  315. /// Pushes four 8-bit index buffer elements.
  316. /// </summary>
  317. /// <param name="argument">Method call argument</param>
  318. private void VbElementU8(int argument)
  319. {
  320. _drawManager.VbElementU8(argument);
  321. }
  322. /// <summary>
  323. /// Pushes two 16-bit index buffer elements.
  324. /// </summary>
  325. /// <param name="argument">Method call argument</param>
  326. private void VbElementU16(int argument)
  327. {
  328. _drawManager.VbElementU16(argument);
  329. }
  330. /// <summary>
  331. /// Pushes one 32-bit index buffer element.
  332. /// </summary>
  333. /// <param name="argument">Method call argument</param>
  334. private void VbElementU32(int argument)
  335. {
  336. _drawManager.VbElementU32(argument);
  337. }
  338. /// <summary>
  339. /// Resets the value of an internal GPU counter back to zero.
  340. /// </summary>
  341. /// <param name="argument">Method call argument</param>
  342. private void ResetCounter(int argument)
  343. {
  344. _semaphoreUpdater.ResetCounter(argument);
  345. }
  346. /// <summary>
  347. /// Finishes the draw call.
  348. /// This draws geometry on the bound buffers based on the current GPU state.
  349. /// </summary>
  350. /// <param name="argument">Method call argument</param>
  351. private void DrawEnd(int argument)
  352. {
  353. _drawManager.DrawEnd(this, argument);
  354. }
  355. /// <summary>
  356. /// Starts draw.
  357. /// This sets primitive type and instanced draw parameters.
  358. /// </summary>
  359. /// <param name="argument">Method call argument</param>
  360. private void DrawBegin(int argument)
  361. {
  362. _drawManager.DrawBegin(argument);
  363. }
  364. /// <summary>
  365. /// Sets the index buffer count.
  366. /// This also sets internal state that indicates that the next draw is an indexed draw.
  367. /// </summary>
  368. /// <param name="argument">Method call argument</param>
  369. private void SetIndexBufferCount(int argument)
  370. {
  371. _drawManager.SetIndexBufferCount(argument);
  372. }
  373. /// <summary>
  374. /// Performs a indexed draw with 8-bit index buffer elements.
  375. /// </summary>
  376. /// <param name="argument">Method call argument</param>
  377. private void DrawIndexBuffer8BeginEndInstanceFirst(int argument)
  378. {
  379. _drawManager.DrawIndexBuffer8BeginEndInstanceFirst(this, argument);
  380. }
  381. /// <summary>
  382. /// Performs a indexed draw with 16-bit index buffer elements.
  383. /// </summary>
  384. /// <param name="argument">Method call argument</param>
  385. private void DrawIndexBuffer16BeginEndInstanceFirst(int argument)
  386. {
  387. _drawManager.DrawIndexBuffer16BeginEndInstanceFirst(this, argument);
  388. }
  389. /// <summary>
  390. /// Performs a indexed draw with 32-bit index buffer elements.
  391. /// </summary>
  392. /// <param name="argument">Method call argument</param>
  393. private void DrawIndexBuffer32BeginEndInstanceFirst(int argument)
  394. {
  395. _drawManager.DrawIndexBuffer32BeginEndInstanceFirst(this, argument);
  396. }
  397. /// <summary>
  398. /// Performs a indexed draw with 8-bit index buffer elements,
  399. /// while also pre-incrementing the current instance value.
  400. /// </summary>
  401. /// <param name="argument">Method call argument</param>
  402. private void DrawIndexBuffer8BeginEndInstanceSubsequent(int argument)
  403. {
  404. _drawManager.DrawIndexBuffer8BeginEndInstanceSubsequent(this, argument);
  405. }
  406. /// <summary>
  407. /// Performs a indexed draw with 16-bit index buffer elements,
  408. /// while also pre-incrementing the current instance value.
  409. /// </summary>
  410. /// <param name="argument">Method call argument</param>
  411. private void DrawIndexBuffer16BeginEndInstanceSubsequent(int argument)
  412. {
  413. _drawManager.DrawIndexBuffer16BeginEndInstanceSubsequent(this, argument);
  414. }
  415. /// <summary>
  416. /// Performs a indexed draw with 32-bit index buffer elements,
  417. /// while also pre-incrementing the current instance value.
  418. /// </summary>
  419. /// <param name="argument">Method call argument</param>
  420. private void DrawIndexBuffer32BeginEndInstanceSubsequent(int argument)
  421. {
  422. _drawManager.DrawIndexBuffer32BeginEndInstanceSubsequent(this, argument);
  423. }
  424. /// <summary>
  425. /// Clears the current color and depth-stencil buffers.
  426. /// Which buffers should be cleared is also specified on the argument.
  427. /// </summary>
  428. /// <param name="argument">Method call argument</param>
  429. private void Clear(int argument)
  430. {
  431. _drawManager.Clear(this, argument);
  432. }
  433. /// <summary>
  434. /// Writes a GPU counter to guest memory.
  435. /// </summary>
  436. /// <param name="argument">Method call argument</param>
  437. private void Report(int argument)
  438. {
  439. _semaphoreUpdater.Report(argument);
  440. }
  441. /// <summary>
  442. /// Performs high-level emulation of Falcon microcode function number "4".
  443. /// </summary>
  444. /// <param name="argument">Method call argument</param>
  445. private void SetFalcon04(int argument)
  446. {
  447. _state.State.SetMmeShadowScratch[0] = 1;
  448. }
  449. /// <summary>
  450. /// Updates the uniform buffer data with inline data.
  451. /// </summary>
  452. /// <param name="argument">New uniform buffer data word</param>
  453. private void ConstantBufferUpdate(int argument)
  454. {
  455. _cbUpdater.Update(argument);
  456. }
  457. /// <summary>
  458. /// Binds a uniform buffer for the vertex shader stage.
  459. /// </summary>
  460. /// <param name="argument">Method call argument</param>
  461. private void ConstantBufferBindVertex(int argument)
  462. {
  463. _cbUpdater.BindVertex(argument);
  464. }
  465. /// <summary>
  466. /// Binds a uniform buffer for the tessellation control shader stage.
  467. /// </summary>
  468. /// <param name="argument">Method call argument</param>
  469. private void ConstantBufferBindTessControl(int argument)
  470. {
  471. _cbUpdater.BindTessControl(argument);
  472. }
  473. /// <summary>
  474. /// Binds a uniform buffer for the tessellation evaluation shader stage.
  475. /// </summary>
  476. /// <param name="argument">Method call argument</param>
  477. private void ConstantBufferBindTessEvaluation(int argument)
  478. {
  479. _cbUpdater.BindTessEvaluation(argument);
  480. }
  481. /// <summary>
  482. /// Binds a uniform buffer for the geometry shader stage.
  483. /// </summary>
  484. /// <param name="argument">Method call argument</param>
  485. private void ConstantBufferBindGeometry(int argument)
  486. {
  487. _cbUpdater.BindGeometry(argument);
  488. }
  489. /// <summary>
  490. /// Binds a uniform buffer for the fragment shader stage.
  491. /// </summary>
  492. /// <param name="argument">Method call argument</param>
  493. private void ConstantBufferBindFragment(int argument)
  494. {
  495. _cbUpdater.BindFragment(argument);
  496. }
  497. /// <summary>
  498. /// Generic register read function that just returns 0.
  499. /// </summary>
  500. /// <returns>Zero</returns>
  501. private static int Zero()
  502. {
  503. return 0;
  504. }
  505. /// <summary>
  506. /// Performs a indexed or non-indexed draw.
  507. /// </summary>
  508. /// <param name="topology">Primitive topology</param>
  509. /// <param name="count">Index count for indexed draws, vertex count for non-indexed draws</param>
  510. /// <param name="instanceCount">Instance count</param>
  511. /// <param name="firstIndex">First index on the index buffer for indexed draws, ignored for non-indexed draws</param>
  512. /// <param name="firstVertex">First vertex on the vertex buffer</param>
  513. /// <param name="firstInstance">First instance</param>
  514. /// <param name="indexed">True if the draw is indexed, false otherwise</param>
  515. public void Draw(
  516. PrimitiveTopology topology,
  517. int count,
  518. int instanceCount,
  519. int firstIndex,
  520. int firstVertex,
  521. int firstInstance,
  522. bool indexed)
  523. {
  524. _drawManager.Draw(this, topology, count, instanceCount, firstIndex, firstVertex, firstInstance, indexed);
  525. }
  526. /// <summary>
  527. /// Performs a indirect draw, with parameters from a GPU buffer.
  528. /// </summary>
  529. /// <param name="topology">Primitive topology</param>
  530. /// <param name="indirectBufferAddress">Address of the buffer with the draw parameters, such as count, first index, etc</param>
  531. /// <param name="parameterBufferAddress">Address of the buffer with the draw count</param>
  532. /// <param name="maxDrawCount">Maximum number of draws that can be made</param>
  533. /// <param name="stride">Distance in bytes between each entry on the data pointed to by <paramref name="indirectBufferAddress"/></param>
  534. /// <param name="indexCount">Maximum number of indices that the draw can consume</param>
  535. /// <param name="drawType">Type of the indirect draw, which can be indexed or non-indexed, with or without a draw count</param>
  536. public void DrawIndirect(
  537. PrimitiveTopology topology,
  538. ulong indirectBufferAddress,
  539. ulong parameterBufferAddress,
  540. int maxDrawCount,
  541. int stride,
  542. int indexCount,
  543. IndirectDrawType drawType)
  544. {
  545. _drawManager.DrawIndirect(this, topology, indirectBufferAddress, parameterBufferAddress, maxDrawCount, stride, indexCount, drawType);
  546. }
  547. /// <summary>
  548. /// Clears the current color and depth-stencil buffers.
  549. /// Which buffers should be cleared can also specified with the arguments.
  550. /// </summary>
  551. /// <param name="argument">Method call argument</param>
  552. /// <param name="layerCount">For array and 3D textures, indicates how many layers should be cleared</param>
  553. public void Clear(int argument, int layerCount)
  554. {
  555. _drawManager.Clear(this, argument, layerCount);
  556. }
  557. }
  558. }