VtgAsCompute.cs
1 using Ryujinx.Graphics.GAL; 2 using Ryujinx.Graphics.Gpu.Shader; 3 using System; 4 5 namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw 6 { 7 /// <summary> 8 /// Vertex, tessellation and geometry as compute shader draw manager. 9 /// </summary> 10 class VtgAsCompute : IDisposable 11 { 12 private readonly GpuContext _context; 13 private readonly GpuChannel _channel; 14 private readonly DeviceStateWithShadow<ThreedClassState> _state; 15 private readonly VtgAsComputeContext _vacContext; 16 17 /// <summary> 18 /// Creates a new instance of the vertex, tessellation and geometry as compute shader draw manager. 19 /// </summary> 20 /// <param name="context">GPU context</param> 21 /// <param name="channel">GPU channel</param> 22 /// <param name="state">3D engine state</param> 23 public VtgAsCompute(GpuContext context, GpuChannel channel, DeviceStateWithShadow<ThreedClassState> state) 24 { 25 _context = context; 26 _channel = channel; 27 _state = state; 28 _vacContext = new(context); 29 } 30 31 /// <summary> 32 /// Emulates the pre-rasterization stages of a draw operation using a compute shader. 33 /// </summary> 34 /// <param name="engine">3D engine</param> 35 /// <param name="vertexAsCompute">Vertex shader converted to compute</param> 36 /// <param name="geometryAsCompute">Optional geometry shader converted to compute</param> 37 /// <param name="vertexPassthroughProgram">Fragment shader with a vertex passthrough shader to feed the compute output into the fragment stage</param> 38 /// <param name="topology">Primitive topology of the draw</param> 39 /// <param name="count">Index or vertex count of the draw</param> 40 /// <param name="instanceCount">Instance count</param> 41 /// <param name="firstIndex">First index on the index buffer, for indexed draws</param> 42 /// <param name="firstVertex">First vertex on the vertex buffer</param> 43 /// <param name="firstInstance">First instance</param> 44 /// <param name="indexed">Whether the draw is indexed</param> 45 public void DrawAsCompute( 46 ThreedClass engine, 47 ShaderAsCompute vertexAsCompute, 48 ShaderAsCompute geometryAsCompute, 49 IProgram vertexPassthroughProgram, 50 PrimitiveTopology topology, 51 int count, 52 int instanceCount, 53 int firstIndex, 54 int firstVertex, 55 int firstInstance, 56 bool indexed) 57 { 58 VtgAsComputeState state = new( 59 _context, 60 _channel, 61 _state, 62 _vacContext, 63 engine, 64 vertexAsCompute, 65 geometryAsCompute, 66 vertexPassthroughProgram, 67 topology, 68 count, 69 instanceCount, 70 firstIndex, 71 firstVertex, 72 firstInstance, 73 indexed); 74 75 state.RunVertex(); 76 state.RunGeometry(); 77 state.RunFragment(); 78 79 _vacContext.FreeBuffers(); 80 } 81 82 protected virtual void Dispose(bool disposing) 83 { 84 if (disposing) 85 { 86 _vacContext.Dispose(); 87 } 88 } 89 90 public void Dispose() 91 { 92 Dispose(true); 93 GC.SuppressFinalize(this); 94 } 95 } 96 }