DrawManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.Engine.Types;
  3. using System;
  4. namespace Ryujinx.Graphics.Gpu.Engine.Threed
  5. {
  6. /// <summary>
  7. /// Draw manager.
  8. /// </summary>
  9. class DrawManager
  10. {
  11. private readonly GpuContext _context;
  12. private readonly GpuChannel _channel;
  13. private readonly DeviceStateWithShadow<ThreedClassState> _state;
  14. private readonly DrawState _drawState;
  15. private bool _topologySet;
  16. private bool _instancedDrawPending;
  17. private bool _instancedIndexed;
  18. private bool _instancedIndexedInline;
  19. private int _instancedFirstIndex;
  20. private int _instancedFirstVertex;
  21. private int _instancedFirstInstance;
  22. private int _instancedIndexCount;
  23. private int _instancedDrawStateFirst;
  24. private int _instancedDrawStateCount;
  25. private int _instanceIndex;
  26. private const int IndexBufferCountMethodOffset = 0x5f8;
  27. /// <summary>
  28. /// Creates a new instance of the draw manager.
  29. /// </summary>
  30. /// <param name="context">GPU context</param>
  31. /// <param name="channel">GPU channel</param>
  32. /// <param name="state">Channel state</param>
  33. /// <param name="drawState">Draw state</param>
  34. public DrawManager(GpuContext context, GpuChannel channel, DeviceStateWithShadow<ThreedClassState> state, DrawState drawState)
  35. {
  36. _context = context;
  37. _channel = channel;
  38. _state = state;
  39. _drawState = drawState;
  40. }
  41. /// <summary>
  42. /// Marks the entire state as dirty, forcing a full host state update before the next draw.
  43. /// </summary>
  44. public void ForceStateDirty()
  45. {
  46. _topologySet = false;
  47. }
  48. /// <summary>
  49. /// Pushes four 8-bit index buffer elements.
  50. /// </summary>
  51. /// <param name="argument">Method call argument</param>
  52. public void VbElementU8(int argument)
  53. {
  54. _drawState.IbStreamer.VbElementU8(_context.Renderer, argument);
  55. }
  56. /// <summary>
  57. /// Pushes two 16-bit index buffer elements.
  58. /// </summary>
  59. /// <param name="argument">Method call argument</param>
  60. public void VbElementU16(int argument)
  61. {
  62. _drawState.IbStreamer.VbElementU16(_context.Renderer, argument);
  63. }
  64. /// <summary>
  65. /// Pushes one 32-bit index buffer element.
  66. /// </summary>
  67. /// <param name="argument">Method call argument</param>
  68. public void VbElementU32(int argument)
  69. {
  70. _drawState.IbStreamer.VbElementU32(_context.Renderer, argument);
  71. }
  72. /// <summary>
  73. /// Finishes the draw call.
  74. /// This draws geometry on the bound buffers based on the current GPU state.
  75. /// </summary>
  76. /// <param name="engine">3D engine where this method is being called</param>
  77. /// <param name="argument">Method call argument</param>
  78. public void DrawEnd(ThreedClass engine, int argument)
  79. {
  80. DrawEnd(engine, _state.State.IndexBufferState.First, (int)_state.State.IndexBufferCount);
  81. }
  82. /// <summary>
  83. /// Finishes the draw call.
  84. /// This draws geometry on the bound buffers based on the current GPU state.
  85. /// </summary>
  86. /// <param name="engine">3D engine where this method is being called</param>
  87. /// <param name="firstIndex">Index of the first index buffer element used on the draw</param>
  88. /// <param name="indexCount">Number of index buffer elements used on the draw</param>
  89. private void DrawEnd(ThreedClass engine, int firstIndex, int indexCount)
  90. {
  91. ConditionalRenderEnabled renderEnable = ConditionalRendering.GetRenderEnable(
  92. _context,
  93. _channel.MemoryManager,
  94. _state.State.RenderEnableAddress,
  95. _state.State.RenderEnableCondition);
  96. if (renderEnable == ConditionalRenderEnabled.False || _instancedDrawPending)
  97. {
  98. if (renderEnable == ConditionalRenderEnabled.False)
  99. {
  100. PerformDeferredDraws();
  101. }
  102. _drawState.DrawIndexed = false;
  103. if (renderEnable == ConditionalRenderEnabled.Host)
  104. {
  105. _context.Renderer.Pipeline.EndHostConditionalRendering();
  106. }
  107. return;
  108. }
  109. _drawState.FirstIndex = firstIndex;
  110. _drawState.IndexCount = indexCount;
  111. engine.UpdateState();
  112. bool instanced = _drawState.VsUsesInstanceId || _drawState.IsAnyVbInstanced;
  113. if (instanced)
  114. {
  115. _instancedDrawPending = true;
  116. int ibCount = _drawState.IbStreamer.InlineIndexCount;
  117. _instancedIndexed = _drawState.DrawIndexed;
  118. _instancedIndexedInline = ibCount != 0;
  119. _instancedFirstIndex = firstIndex;
  120. _instancedFirstVertex = (int)_state.State.FirstVertex;
  121. _instancedFirstInstance = (int)_state.State.FirstInstance;
  122. _instancedIndexCount = ibCount != 0 ? ibCount : indexCount;
  123. var drawState = _state.State.VertexBufferDrawState;
  124. _instancedDrawStateFirst = drawState.First;
  125. _instancedDrawStateCount = drawState.Count;
  126. _drawState.DrawIndexed = false;
  127. if (renderEnable == ConditionalRenderEnabled.Host)
  128. {
  129. _context.Renderer.Pipeline.EndHostConditionalRendering();
  130. }
  131. return;
  132. }
  133. int firstInstance = (int)_state.State.FirstInstance;
  134. int inlineIndexCount = _drawState.IbStreamer.GetAndResetInlineIndexCount();
  135. if (inlineIndexCount != 0)
  136. {
  137. int firstVertex = (int)_state.State.FirstVertex;
  138. BufferRange br = new BufferRange(_drawState.IbStreamer.GetInlineIndexBuffer(), 0, inlineIndexCount * 4);
  139. _channel.BufferManager.SetIndexBuffer(br, IndexType.UInt);
  140. _context.Renderer.Pipeline.DrawIndexed(inlineIndexCount, 1, firstIndex, firstVertex, firstInstance);
  141. }
  142. else if (_drawState.DrawIndexed)
  143. {
  144. int firstVertex = (int)_state.State.FirstVertex;
  145. _context.Renderer.Pipeline.DrawIndexed(indexCount, 1, firstIndex, firstVertex, firstInstance);
  146. }
  147. else
  148. {
  149. var drawState = _state.State.VertexBufferDrawState;
  150. _context.Renderer.Pipeline.Draw(drawState.Count, 1, drawState.First, firstInstance);
  151. }
  152. _drawState.DrawIndexed = false;
  153. if (renderEnable == ConditionalRenderEnabled.Host)
  154. {
  155. _context.Renderer.Pipeline.EndHostConditionalRendering();
  156. }
  157. }
  158. /// <summary>
  159. /// Starts draw.
  160. /// This sets primitive type and instanced draw parameters.
  161. /// </summary>
  162. /// <param name="argument">Method call argument</param>
  163. public void DrawBegin(int argument)
  164. {
  165. bool incrementInstance = (argument & (1 << 26)) != 0;
  166. bool resetInstance = (argument & (1 << 27)) == 0;
  167. if (_state.State.PrimitiveTypeOverrideEnable)
  168. {
  169. PrimitiveTypeOverride typeOverride = _state.State.PrimitiveTypeOverride;
  170. DrawBegin(incrementInstance, resetInstance, typeOverride.Convert());
  171. }
  172. else
  173. {
  174. PrimitiveType type = (PrimitiveType)(argument & 0xffff);
  175. DrawBegin(incrementInstance, resetInstance, type.Convert());
  176. }
  177. }
  178. /// <summary>
  179. /// Starts draw.
  180. /// This sets primitive type and instanced draw parameters.
  181. /// </summary>
  182. /// <param name="incrementInstance">Indicates if the current instance should be incremented</param>
  183. /// <param name="resetInstance">Indicates if the current instance should be set to zero</param>
  184. /// <param name="topology">Primitive topology</param>
  185. private void DrawBegin(bool incrementInstance, bool resetInstance, PrimitiveTopology topology)
  186. {
  187. if (incrementInstance)
  188. {
  189. _instanceIndex++;
  190. }
  191. else if (resetInstance)
  192. {
  193. PerformDeferredDraws();
  194. _instanceIndex = 0;
  195. }
  196. if (_drawState.Topology != topology || !_topologySet)
  197. {
  198. _context.Renderer.Pipeline.SetPrimitiveTopology(topology);
  199. _drawState.Topology = topology;
  200. _topologySet = true;
  201. }
  202. }
  203. /// <summary>
  204. /// Sets the index buffer count.
  205. /// This also sets internal state that indicates that the next draw is an indexed draw.
  206. /// </summary>
  207. /// <param name="argument">Method call argument</param>
  208. public void SetIndexBufferCount(int argument)
  209. {
  210. _drawState.DrawIndexed = true;
  211. }
  212. /// <summary>
  213. /// Performs a indexed draw with a low number of index buffer elements.
  214. /// </summary>
  215. /// <param name="engine">3D engine where this method is being called</param>
  216. /// <param name="argument">Method call argument</param>
  217. public void DrawIndexedSmall(ThreedClass engine, int argument)
  218. {
  219. DrawIndexedSmall(engine, argument, false);
  220. }
  221. /// <summary>
  222. /// Performs a indexed draw with a low number of index buffer elements.
  223. /// </summary>
  224. /// <param name="engine">3D engine where this method is being called</param>
  225. /// <param name="argument">Method call argument</param>
  226. public void DrawIndexedSmall2(ThreedClass engine, int argument)
  227. {
  228. DrawIndexedSmall(engine, argument);
  229. }
  230. /// <summary>
  231. /// Performs a indexed draw with a low number of index buffer elements,
  232. /// while also pre-incrementing the current instance value.
  233. /// </summary>
  234. /// <param name="engine">3D engine where this method is being called</param>
  235. /// <param name="argument">Method call argument</param>
  236. public void DrawIndexedSmallIncInstance(ThreedClass engine, int argument)
  237. {
  238. DrawIndexedSmall(engine, argument, true);
  239. }
  240. /// <summary>
  241. /// Performs a indexed draw with a low number of index buffer elements,
  242. /// while also pre-incrementing the current instance value.
  243. /// </summary>
  244. /// <param name="engine">3D engine where this method is being called</param>
  245. /// <param name="argument">Method call argument</param>
  246. public void DrawIndexedSmallIncInstance2(ThreedClass engine, int argument)
  247. {
  248. DrawIndexedSmallIncInstance(engine, argument);
  249. }
  250. /// <summary>
  251. /// Performs a indexed draw with a low number of index buffer elements,
  252. /// while optionally also pre-incrementing the current instance value.
  253. /// </summary>
  254. /// <param name="engine">3D engine where this method is being called</param>
  255. /// <param name="argument">Method call argument</param>
  256. /// <param name="instanced">True to increment the current instance value, false otherwise</param>
  257. private void DrawIndexedSmall(ThreedClass engine, int argument, bool instanced)
  258. {
  259. PrimitiveTypeOverride typeOverride = _state.State.PrimitiveTypeOverride;
  260. DrawBegin(instanced, !instanced, typeOverride.Convert());
  261. int firstIndex = argument & 0xffff;
  262. int indexCount = (argument >> 16) & 0xfff;
  263. bool oldDrawIndexed = _drawState.DrawIndexed;
  264. _drawState.DrawIndexed = true;
  265. engine.ForceStateDirty(IndexBufferCountMethodOffset * 4);
  266. DrawEnd(engine, firstIndex, indexCount);
  267. _drawState.DrawIndexed = oldDrawIndexed;
  268. }
  269. /// <summary>
  270. /// Performs a texture draw with a source texture and sampler ID, along with source
  271. /// and destination coordinates and sizes.
  272. /// </summary>
  273. /// <param name="engine">3D engine where this method is being called</param>
  274. /// <param name="argument">Method call argument</param>
  275. public void DrawTexture(ThreedClass engine, int argument)
  276. {
  277. static float FixedToFloat(int fixedValue)
  278. {
  279. return fixedValue * (1f / 4096);
  280. }
  281. float dstX0 = FixedToFloat(_state.State.DrawTextureDstX);
  282. float dstY0 = FixedToFloat(_state.State.DrawTextureDstY);
  283. float dstWidth = FixedToFloat(_state.State.DrawTextureDstWidth);
  284. float dstHeight = FixedToFloat(_state.State.DrawTextureDstHeight);
  285. // TODO: Confirm behaviour on hardware.
  286. // When this is active, the origin appears to be on the bottom.
  287. if (_state.State.YControl.HasFlag(YControl.NegateY))
  288. {
  289. dstY0 -= dstHeight;
  290. }
  291. float dstX1 = dstX0 + dstWidth;
  292. float dstY1 = dstY0 + dstHeight;
  293. float srcX0 = FixedToFloat(_state.State.DrawTextureSrcX);
  294. float srcY0 = FixedToFloat(_state.State.DrawTextureSrcY);
  295. float srcX1 = ((float)_state.State.DrawTextureDuDx / (1UL << 32)) * dstWidth + srcX0;
  296. float srcY1 = ((float)_state.State.DrawTextureDvDy / (1UL << 32)) * dstHeight + srcY0;
  297. engine.UpdateState();
  298. int textureId = _state.State.DrawTextureTextureId;
  299. int samplerId = _state.State.DrawTextureSamplerId;
  300. (var texture, var sampler) = _channel.TextureManager.GetGraphicsTextureAndSampler(textureId, samplerId);
  301. srcX0 *= texture.ScaleFactor;
  302. srcY0 *= texture.ScaleFactor;
  303. srcX1 *= texture.ScaleFactor;
  304. srcY1 *= texture.ScaleFactor;
  305. float dstScale = _channel.TextureManager.RenderTargetScale;
  306. dstX0 *= dstScale;
  307. dstY0 *= dstScale;
  308. dstX1 *= dstScale;
  309. dstY1 *= dstScale;
  310. _context.Renderer.Pipeline.DrawTexture(
  311. texture?.HostTexture,
  312. sampler?.GetHostSampler(texture),
  313. new Extents2DF(srcX0, srcY0, srcX1, srcY1),
  314. new Extents2DF(dstX0, dstY0, dstX1, dstY1));
  315. }
  316. /// <summary>
  317. /// Performs a indirect multi-draw, with parameters from a GPU buffer.
  318. /// </summary>
  319. /// <param name="engine">3D engine where this method is being called</param>
  320. /// <param name="topology">Primitive topology</param>
  321. /// <param name="indirectBuffer">GPU buffer with the draw parameters, such as count, first index, etc</param>
  322. /// <param name="parameterBuffer">GPU buffer with the draw count</param>
  323. /// <param name="maxDrawCount">Maximum number of draws that can be made</param>
  324. /// <param name="stride">Distance in bytes between each element on the <paramref name="indirectBuffer"/> array</param>
  325. public void MultiDrawIndirectCount(
  326. ThreedClass engine,
  327. int indexCount,
  328. PrimitiveTopology topology,
  329. BufferRange indirectBuffer,
  330. BufferRange parameterBuffer,
  331. int maxDrawCount,
  332. int stride)
  333. {
  334. engine.Write(IndexBufferCountMethodOffset * 4, indexCount);
  335. _context.Renderer.Pipeline.SetPrimitiveTopology(topology);
  336. _drawState.Topology = topology;
  337. _topologySet = true;
  338. ConditionalRenderEnabled renderEnable = ConditionalRendering.GetRenderEnable(
  339. _context,
  340. _channel.MemoryManager,
  341. _state.State.RenderEnableAddress,
  342. _state.State.RenderEnableCondition);
  343. if (renderEnable == ConditionalRenderEnabled.False)
  344. {
  345. _drawState.DrawIndexed = false;
  346. return;
  347. }
  348. _drawState.FirstIndex = _state.State.IndexBufferState.First;
  349. _drawState.IndexCount = indexCount;
  350. engine.UpdateState();
  351. if (_drawState.DrawIndexed)
  352. {
  353. _context.Renderer.Pipeline.MultiDrawIndexedIndirectCount(indirectBuffer, parameterBuffer, maxDrawCount, stride);
  354. }
  355. else
  356. {
  357. _context.Renderer.Pipeline.MultiDrawIndirectCount(indirectBuffer, parameterBuffer, maxDrawCount, stride);
  358. }
  359. _drawState.DrawIndexed = false;
  360. if (renderEnable == ConditionalRenderEnabled.Host)
  361. {
  362. _context.Renderer.Pipeline.EndHostConditionalRendering();
  363. }
  364. }
  365. /// <summary>
  366. /// Perform any deferred draws.
  367. /// This is used for instanced draws.
  368. /// Since each instance is a separate draw, we defer the draw and accumulate the instance count.
  369. /// Once we detect the last instanced draw, then we perform the host instanced draw,
  370. /// with the accumulated instance count.
  371. /// </summary>
  372. public void PerformDeferredDraws()
  373. {
  374. // Perform any pending instanced draw.
  375. if (_instancedDrawPending)
  376. {
  377. _instancedDrawPending = false;
  378. bool indexedInline = _instancedIndexedInline;
  379. if (_instancedIndexed || indexedInline)
  380. {
  381. if (indexedInline)
  382. {
  383. int inlineIndexCount = _drawState.IbStreamer.GetAndResetInlineIndexCount();
  384. BufferRange br = new BufferRange(_drawState.IbStreamer.GetInlineIndexBuffer(), 0, inlineIndexCount * 4);
  385. _channel.BufferManager.SetIndexBuffer(br, IndexType.UInt);
  386. }
  387. _context.Renderer.Pipeline.DrawIndexed(
  388. _instancedIndexCount,
  389. _instanceIndex + 1,
  390. _instancedFirstIndex,
  391. _instancedFirstVertex,
  392. _instancedFirstInstance);
  393. }
  394. else
  395. {
  396. _context.Renderer.Pipeline.Draw(
  397. _instancedDrawStateCount,
  398. _instanceIndex + 1,
  399. _instancedDrawStateFirst,
  400. _instancedFirstInstance);
  401. }
  402. }
  403. }
  404. /// <summary>
  405. /// Clears the current color and depth-stencil buffers.
  406. /// Which buffers should be cleared can also be specified with the argument.
  407. /// </summary>
  408. /// <param name="engine">3D engine where this method is being called</param>
  409. /// <param name="argument">Method call argument</param>
  410. public void Clear(ThreedClass engine, int argument)
  411. {
  412. Clear(engine, argument, 1);
  413. }
  414. /// <summary>
  415. /// Clears the current color and depth-stencil buffers.
  416. /// Which buffers should be cleared can also specified with the arguments.
  417. /// </summary>
  418. /// <param name="engine">3D engine where this method is being called</param>
  419. /// <param name="argument">Method call argument</param>
  420. /// <param name="layerCount">For array and 3D textures, indicates how many layers should be cleared</param>
  421. public void Clear(ThreedClass engine, int argument, int layerCount)
  422. {
  423. ConditionalRenderEnabled renderEnable = ConditionalRendering.GetRenderEnable(
  424. _context,
  425. _channel.MemoryManager,
  426. _state.State.RenderEnableAddress,
  427. _state.State.RenderEnableCondition);
  428. if (renderEnable == ConditionalRenderEnabled.False)
  429. {
  430. return;
  431. }
  432. int index = (argument >> 6) & 0xf;
  433. int layer = (argument >> 10) & 0x3ff;
  434. engine.UpdateRenderTargetState(useControl: false, layered: layer != 0 || layerCount > 1, singleUse: index);
  435. // If there is a mismatch on the host clip region and the one explicitly defined by the guest
  436. // on the screen scissor state, then we need to force only one texture to be bound to avoid
  437. // host clipping.
  438. var screenScissorState = _state.State.ScreenScissorState;
  439. // Must happen after UpdateRenderTargetState to have up-to-date clip region values.
  440. bool clipMismatch = (screenScissorState.X | screenScissorState.Y) != 0 ||
  441. screenScissorState.Width != _channel.TextureManager.ClipRegionWidth ||
  442. screenScissorState.Height != _channel.TextureManager.ClipRegionHeight;
  443. bool clearAffectedByStencilMask = (_state.State.ClearFlags & 1) != 0;
  444. bool clearAffectedByScissor = (_state.State.ClearFlags & 0x100) != 0;
  445. bool needsCustomScissor = !clearAffectedByScissor || clipMismatch;
  446. // Scissor and rasterizer discard also affect clears.
  447. ulong updateMask = 1UL << StateUpdater.RasterizerStateIndex;
  448. if (!needsCustomScissor)
  449. {
  450. updateMask |= 1UL << StateUpdater.ScissorStateIndex;
  451. }
  452. engine.UpdateState(updateMask);
  453. if (needsCustomScissor)
  454. {
  455. int scissorX = screenScissorState.X;
  456. int scissorY = screenScissorState.Y;
  457. int scissorW = screenScissorState.Width;
  458. int scissorH = screenScissorState.Height;
  459. if (clearAffectedByScissor && _state.State.ScissorState[0].Enable)
  460. {
  461. ref var scissorState = ref _state.State.ScissorState[0];
  462. scissorX = Math.Max(scissorX, scissorState.X1);
  463. scissorY = Math.Max(scissorY, scissorState.Y1);
  464. scissorW = Math.Min(scissorW, scissorState.X2 - scissorState.X1);
  465. scissorH = Math.Min(scissorH, scissorState.Y2 - scissorState.Y1);
  466. }
  467. float scale = _channel.TextureManager.RenderTargetScale;
  468. if (scale != 1f)
  469. {
  470. scissorX = (int)(scissorX * scale);
  471. scissorY = (int)(scissorY * scale);
  472. scissorW = (int)MathF.Ceiling(scissorW * scale);
  473. scissorH = (int)MathF.Ceiling(scissorH * scale);
  474. }
  475. Span<Rectangle<int>> scissors = stackalloc Rectangle<int>[]
  476. {
  477. new Rectangle<int>(scissorX, scissorY, scissorW, scissorH)
  478. };
  479. _context.Renderer.Pipeline.SetScissors(scissors);
  480. }
  481. if (clipMismatch)
  482. {
  483. _channel.TextureManager.UpdateRenderTarget(index);
  484. }
  485. else
  486. {
  487. _channel.TextureManager.UpdateRenderTargets();
  488. }
  489. bool clearDepth = (argument & 1) != 0;
  490. bool clearStencil = (argument & 2) != 0;
  491. uint componentMask = (uint)((argument >> 2) & 0xf);
  492. if (componentMask != 0)
  493. {
  494. var clearColor = _state.State.ClearColors;
  495. ColorF color = new ColorF(clearColor.Red, clearColor.Green, clearColor.Blue, clearColor.Alpha);
  496. _context.Renderer.Pipeline.ClearRenderTargetColor(index, layer, layerCount, componentMask, color);
  497. }
  498. if (clearDepth || clearStencil)
  499. {
  500. float depthValue = _state.State.ClearDepthValue;
  501. int stencilValue = (int)_state.State.ClearStencilValue;
  502. int stencilMask = 0;
  503. if (clearStencil)
  504. {
  505. stencilMask = clearAffectedByStencilMask ? _state.State.StencilTestState.FrontMask : 0xff;
  506. }
  507. if (clipMismatch)
  508. {
  509. _channel.TextureManager.UpdateRenderTargetDepthStencil();
  510. }
  511. _context.Renderer.Pipeline.ClearRenderTargetDepthStencil(
  512. layer,
  513. layerCount,
  514. depthValue,
  515. clearDepth,
  516. stencilValue,
  517. stencilMask);
  518. }
  519. if (needsCustomScissor)
  520. {
  521. engine.UpdateScissorState();
  522. }
  523. engine.UpdateRenderTargetState(useControl: true);
  524. if (renderEnable == ConditionalRenderEnabled.Host)
  525. {
  526. _context.Renderer.Pipeline.EndHostConditionalRendering();
  527. }
  528. }
  529. }
  530. }