2019-10-13 06:02:07 +00:00
|
|
|
using Ryujinx.Graphics.Gpu.State;
|
|
|
|
using Ryujinx.Graphics.Gpu.Image;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine
|
|
|
|
{
|
|
|
|
partial class Methods
|
|
|
|
{
|
|
|
|
private bool _drawIndexed;
|
|
|
|
|
|
|
|
private int _firstIndex;
|
|
|
|
private int _indexCount;
|
|
|
|
|
|
|
|
private bool _instancedHasState;
|
|
|
|
private bool _instancedIndexed;
|
|
|
|
|
|
|
|
private int _instancedFirstIndex;
|
|
|
|
private int _instancedFirstVertex;
|
|
|
|
private int _instancedFirstInstance;
|
|
|
|
private int _instancedIndexCount;
|
|
|
|
private int _instancedDrawStateFirst;
|
|
|
|
private int _instancedDrawStateCount;
|
|
|
|
|
|
|
|
private int _instanceIndex;
|
|
|
|
|
|
|
|
public PrimitiveType PrimitiveType { get; private set; }
|
|
|
|
|
|
|
|
private void DrawEnd(int argument)
|
|
|
|
{
|
|
|
|
UpdateState();
|
|
|
|
|
|
|
|
bool instanced = _vsUsesInstanceId || _isAnyVbInstanced;
|
|
|
|
|
|
|
|
if (instanced)
|
|
|
|
{
|
|
|
|
if (!_instancedHasState)
|
|
|
|
{
|
|
|
|
_instancedHasState = true;
|
|
|
|
|
|
|
|
_instancedIndexed = _drawIndexed;
|
|
|
|
|
|
|
|
_instancedFirstIndex = _firstIndex;
|
2019-10-26 17:50:52 +00:00
|
|
|
_instancedFirstVertex = _context.State.Get<int>(MethodOffset.FirstVertex);
|
|
|
|
_instancedFirstInstance = _context.State.Get<int>(MethodOffset.FirstInstance);
|
2019-10-13 06:02:07 +00:00
|
|
|
|
|
|
|
_instancedIndexCount = _indexCount;
|
|
|
|
|
2019-10-26 17:50:52 +00:00
|
|
|
var drawState = _context.State.Get<VertexBufferDrawState>(MethodOffset.VertexBufferDrawState);
|
2019-10-13 06:02:07 +00:00
|
|
|
|
|
|
|
_instancedDrawStateFirst = drawState.First;
|
|
|
|
_instancedDrawStateCount = drawState.Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-26 17:50:52 +00:00
|
|
|
int firstInstance = _context.State.Get<int>(MethodOffset.FirstInstance);
|
2019-10-13 06:02:07 +00:00
|
|
|
|
|
|
|
if (_drawIndexed)
|
|
|
|
{
|
|
|
|
_drawIndexed = false;
|
|
|
|
|
2019-10-26 17:50:52 +00:00
|
|
|
int firstVertex = _context.State.Get<int>(MethodOffset.FirstVertex);
|
2019-10-13 06:02:07 +00:00
|
|
|
|
2019-10-18 02:41:18 +00:00
|
|
|
_context.Renderer.Pipeline.DrawIndexed(
|
2019-10-13 06:02:07 +00:00
|
|
|
_indexCount,
|
|
|
|
1,
|
|
|
|
_firstIndex,
|
|
|
|
firstVertex,
|
|
|
|
firstInstance);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-26 17:50:52 +00:00
|
|
|
var drawState = _context.State.Get<VertexBufferDrawState>(MethodOffset.VertexBufferDrawState);
|
2019-10-13 06:02:07 +00:00
|
|
|
|
2019-10-18 02:41:18 +00:00
|
|
|
_context.Renderer.Pipeline.Draw(
|
2019-10-13 06:02:07 +00:00
|
|
|
drawState.Count,
|
|
|
|
1,
|
|
|
|
drawState.First,
|
|
|
|
firstInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawBegin(int argument)
|
|
|
|
{
|
|
|
|
PrimitiveType type = (PrimitiveType)(argument & 0xffff);
|
|
|
|
|
2019-10-18 02:41:18 +00:00
|
|
|
_context.Renderer.Pipeline.SetPrimitiveTopology(type.Convert());
|
2019-10-13 06:02:07 +00:00
|
|
|
|
|
|
|
PrimitiveType = type;
|
|
|
|
|
|
|
|
if ((argument & (1 << 26)) != 0)
|
|
|
|
{
|
|
|
|
_instanceIndex++;
|
|
|
|
}
|
|
|
|
else if ((argument & (1 << 27)) == 0)
|
|
|
|
{
|
|
|
|
_instanceIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-26 17:50:52 +00:00
|
|
|
private void SetIndexBufferCount(int argument)
|
2019-10-13 06:02:07 +00:00
|
|
|
{
|
|
|
|
_drawIndexed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PerformDeferredDraws()
|
|
|
|
{
|
|
|
|
// Perform any pending instanced draw.
|
|
|
|
if (_instancedHasState)
|
|
|
|
{
|
|
|
|
_instancedHasState = false;
|
|
|
|
|
|
|
|
if (_instancedIndexed)
|
|
|
|
{
|
2019-10-18 02:41:18 +00:00
|
|
|
_context.Renderer.Pipeline.DrawIndexed(
|
2019-10-13 06:02:07 +00:00
|
|
|
_instancedIndexCount,
|
|
|
|
_instanceIndex + 1,
|
|
|
|
_instancedFirstIndex,
|
|
|
|
_instancedFirstVertex,
|
|
|
|
_instancedFirstInstance);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-18 02:41:18 +00:00
|
|
|
_context.Renderer.Pipeline.Draw(
|
2019-10-13 06:02:07 +00:00
|
|
|
_instancedDrawStateCount,
|
|
|
|
_instanceIndex + 1,
|
|
|
|
_instancedDrawStateFirst,
|
|
|
|
_instancedFirstInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|