using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Shader; using System; namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw { /// /// Vertex, tessellation and geometry as compute shader draw manager. /// class VtgAsCompute : IDisposable { private readonly GpuContext _context; private readonly GpuChannel _channel; private readonly DeviceStateWithShadow _state; private readonly VtgAsComputeContext _vacContext; /// /// Creates a new instance of the vertex, tessellation and geometry as compute shader draw manager. /// /// GPU context /// GPU channel /// 3D engine state public VtgAsCompute(GpuContext context, GpuChannel channel, DeviceStateWithShadow state) { _context = context; _channel = channel; _state = state; _vacContext = new(context); } /// /// Emulates the pre-rasterization stages of a draw operation using a compute shader. /// /// 3D engine /// Vertex shader converted to compute /// Optional geometry shader converted to compute /// Fragment shader with a vertex passthrough shader to feed the compute output into the fragment stage /// Primitive topology of the draw /// Index or vertex count of the draw /// Instance count /// First index on the index buffer, for indexed draws /// First vertex on the vertex buffer /// First instance /// Whether the draw is indexed public void DrawAsCompute( ThreedClass engine, ShaderAsCompute vertexAsCompute, ShaderAsCompute geometryAsCompute, IProgram vertexPassthroughProgram, PrimitiveTopology topology, int count, int instanceCount, int firstIndex, int firstVertex, int firstInstance, bool indexed) { VtgAsComputeState state = new( _context, _channel, _state, _vacContext, engine, vertexAsCompute, geometryAsCompute, vertexPassthroughProgram, topology, count, instanceCount, firstIndex, firstVertex, firstInstance, indexed); state.RunVertex(); state.RunGeometry(); state.RunFragment(); _vacContext.FreeBuffers(); } protected virtual void Dispose(bool disposing) { if (disposing) { _vacContext.Dispose(); } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } } }