simplify IGL 2: Combine BindArrayData and DrawArrays calls into one Draw call: only supports triangle strips (already limitation with D3D9), assumes start is 0, binding and drawing are implicitly merged into a single call (in practice BindArrayData would just save the vertex pointer to some class level variable for DrawArrays, so this is just better all around)

This commit is contained in:
CasualPokePlayer 2023-08-11 15:33:08 -07:00
parent 64abeddc2b
commit 3622fe76f9
7 changed files with 22 additions and 90 deletions

View File

@ -94,15 +94,12 @@ namespace BizHawk.Bizware.BizwareGL
void EndScene(); void EndScene();
/// <summary> /// <summary>
/// Binds array data for use with the currently-bound pipeline's VertexLayout /// Draws based on the currently set pipeline
/// data contains vertexes based on the pipeline's VertexLayout
/// count is the vertex count
/// Vertexes must form triangle strips
/// </summary> /// </summary>
void BindArrayData(IntPtr pData); void Draw(IntPtr data, int count);
/// <summary>
/// Draws based on the currently set pipeline, VertexLayout and ArrayData.
/// Count is the VERT COUNT not the primitive count
/// </summary>
void DrawArrays(PrimitiveType mode, int first, int count);
/// <summary> /// <summary>
/// resolves the texture into a new BitmapBuffer /// resolves the texture into a new BitmapBuffer

View File

@ -37,10 +37,6 @@ namespace BizHawk.Bizware.BizwareGL
return null; return null;
} }
public void BindArrayData(IntPtr pData)
{
}
public void FreeTexture(Texture2d tex) public void FreeTexture(Texture2d tex)
{ {
var tw = (GDIPTextureWrapper)tex.Opaque; var tw = (GDIPTextureWrapper)tex.Opaque;
@ -88,7 +84,7 @@ namespace BizHawk.Bizware.BizwareGL
{ {
} }
public void DrawArrays(PrimitiveType mode, int first, int count) public void Draw(IntPtr data, int count)
{ {
} }

View File

@ -126,11 +126,9 @@ namespace BizHawk.Bizware.BizwareGL
pData[i++] = 1; pData[i] = v1; pData[i++] = 1; pData[i] = v1;
Owner.SetBlendState(Owner.BlendNoneCopy); Owner.SetBlendState(Owner.BlendNoneCopy);
Owner.BindArrayData(new(pData)); Owner.Draw(new(pData), 4);
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
} }
public IGL Owner { get; } public IGL Owner { get; }
private readonly VertexLayout VertexLayout; private readonly VertexLayout VertexLayout;

View File

@ -1,31 +0,0 @@
namespace BizHawk.Bizware.BizwareGL
{
public enum PrimitiveType
{
Points = 0x0000,
Lines = 0x0001,
LineLoop = 0x0002,
LineStrip = 0x0003,
Triangles = 0x0004,
TriangleStrip = 0x0005,
TriangleFan = 0x0006,
Quads = 0x0007,
QuadsExt = 0x0007,
QuadStrip = 0x0008,
Polygon = 0x0009,
LinesAdjacency = 0x000A,
LinesAdjacencyArb = 0x000A,
LinesAdjacencyExt = 0x000A,
LineStripAdjacency = 0x000B,
LineStripAdjacencyArb = 0x000B,
LineStripAdjacencyExt = 0x000B,
TrianglesAdjacency = 0x000C,
TrianglesAdjacencyArb = 0x000C,
TrianglesAdjacencyExt = 0x000C,
TriangleStripAdjacency = 0x000D,
TriangleStripAdjacencyArb = 0x000D,
TriangleStripAdjacencyExt = 0x000D,
Patches = 0x000E,
PatchesExt = 0x000E,
}
}

View File

@ -18,9 +18,6 @@ using SharpDX.Mathematics.Interop;
using static SDL2.SDL; using static SDL2.SDL;
using BizPrimitiveType = BizHawk.Bizware.BizwareGL.PrimitiveType;
using D3D9PrimitiveType = SharpDX.Direct3D9.PrimitiveType;
// todo - do a better job selecting shader model? base on caps somehow? try several and catch compilation exceptions (yuck, exceptions) // todo - do a better job selecting shader model? base on caps somehow? try several and catch compilation exceptions (yuck, exceptions)
namespace BizHawk.Bizware.Graphics namespace BizHawk.Bizware.Graphics
{ {
@ -927,7 +924,7 @@ namespace BizHawk.Bizware.Graphics
return ret; return ret;
} }
private delegate void DrawPrimitiveUPDelegate(Device device, D3D9PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride); private delegate void DrawPrimitiveUPDelegate(Device device, PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride);
private static readonly Lazy<DrawPrimitiveUPDelegate> _drawPrimitiveUP = new(() => private static readonly Lazy<DrawPrimitiveUPDelegate> _drawPrimitiveUP = new(() =>
{ {
@ -935,23 +932,12 @@ namespace BizHawk.Bizware.Graphics
return (DrawPrimitiveUPDelegate)Delegate.CreateDelegate(typeof(DrawPrimitiveUPDelegate), mi!); return (DrawPrimitiveUPDelegate)Delegate.CreateDelegate(typeof(DrawPrimitiveUPDelegate), mi!);
}); });
private void DrawPrimitiveUP(D3D9PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride) private void DrawPrimitiveUP(PrimitiveType primitiveType, int primitiveCount, IntPtr vertexStreamZeroDataRef, int vertexStreamZeroStride)
=> _drawPrimitiveUP.Value(_device, primitiveType, primitiveCount, vertexStreamZeroDataRef, vertexStreamZeroStride); => _drawPrimitiveUP.Value(_device, primitiveType, primitiveCount, vertexStreamZeroDataRef, vertexStreamZeroStride);
/// <exception cref="NotSupportedException"><paramref name="mode"/> is not <see cref="BizwareGL.PrimitiveType.TriangleStrip"/></exception> public void Draw(IntPtr data, int count)
public void DrawArrays(BizPrimitiveType mode, int first, int count)
{ {
if (mode != BizPrimitiveType.TriangleStrip)
{
throw new NotSupportedException();
}
// for tristrip
var primCount = count - 2;
var pw = (PipelineWrapper)_currPipeline.Opaque; var pw = (PipelineWrapper)_currPipeline.Opaque;
var stride = pw.VertexStride;
var ptr = _pVertexData + first * stride;
// this is stupid, sharpdx only public exposes DrawUserPrimatives // this is stupid, sharpdx only public exposes DrawUserPrimatives
// why is this bad? it takes in an array of T // why is this bad? it takes in an array of T
@ -959,12 +945,9 @@ namespace BizHawk.Bizware.Graphics
// since stride for us is just completely variable, this is no good // since stride for us is just completely variable, this is no good
// DrawPrimitiveUP is internal so we have to use this hack to use it directly // DrawPrimitiveUP is internal so we have to use this hack to use it directly
DrawPrimitiveUP(D3D9PrimitiveType.TriangleStrip, primCount, ptr, stride); DrawPrimitiveUP(PrimitiveType.TriangleStrip, count - 2, _pVertexData, pw.VertexStride);
} }
public void BindArrayData(IntPtr pData)
=> _pVertexData = pData;
public void BeginScene() public void BeginScene()
{ {
_device.BeginScene(); _device.BeginScene();

View File

@ -300,8 +300,7 @@ namespace BizHawk.Bizware.Graphics
}; };
PrepDrawSubrectInternal(art.BaseTexture); PrepDrawSubrectInternal(art.BaseTexture);
Owner.BindArrayData(new(data)); Owner.Draw(new(data), 4);
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
} }
private void PrepDrawSubrectInternal(Texture2d tex) private void PrepDrawSubrectInternal(Texture2d tex)
@ -361,9 +360,7 @@ namespace BizHawk.Bizware.Graphics
pData[30] = CornerColors[3].Z; pData[30] = CornerColors[3].Z;
pData[31] = CornerColors[3].W; pData[31] = CornerColors[3].W;
Owner.BindArrayData(new(pData)); Owner.Draw(new(pData), 4);
Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
#if DEBUG #if DEBUG
Debug.Assert(BlendStateSet); Debug.Assert(BlendStateSet);
#endif #endif

View File

@ -19,14 +19,11 @@ using BizHawk.Common;
using Silk.NET.OpenGL.Legacy; using Silk.NET.OpenGL.Legacy;
using BizPrimitiveType = BizHawk.Bizware.BizwareGL.PrimitiveType;
using BizShader = BizHawk.Bizware.BizwareGL.Shader; using BizShader = BizHawk.Bizware.BizwareGL.Shader;
using BizTextureMagFilter = BizHawk.Bizware.BizwareGL.TextureMagFilter; using BizTextureMagFilter = BizHawk.Bizware.BizwareGL.TextureMagFilter;
using BizTextureMinFilter = BizHawk.Bizware.BizwareGL.TextureMinFilter; using BizTextureMinFilter = BizHawk.Bizware.BizwareGL.TextureMinFilter;
using GLPrimitiveType = Silk.NET.OpenGL.Legacy.PrimitiveType;
using GLVertexAttribPointerType = Silk.NET.OpenGL.Legacy.VertexAttribPointerType; using GLVertexAttribPointerType = Silk.NET.OpenGL.Legacy.VertexAttribPointerType;
namespace BizHawk.Bizware.Graphics namespace BizHawk.Bizware.Graphics
@ -369,11 +366,6 @@ namespace BizHawk.Bizware.Graphics
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)mode); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)mode);
} }
private IntPtr pVertexData;
public void BindArrayData(IntPtr pData)
=> pVertexData = pData;
private void LegacyBindArrayData(VertexLayout vertexLayout, IntPtr pData) private void LegacyBindArrayData(VertexLayout vertexLayout, IntPtr pData)
{ {
// DEPRECATED CRAP USED, NEEDED FOR ANCIENT SHADERS // DEPRECATED CRAP USED, NEEDED FOR ANCIENT SHADERS
@ -426,19 +418,19 @@ namespace BizHawk.Bizware.Graphics
#pragma warning restore CS0612 #pragma warning restore CS0612
} }
public void DrawArrays(BizPrimitiveType mode, int first, int count) public void Draw(IntPtr data, int count)
{ {
var vertexLayout = _currPipeline?.VertexLayout; if (_currPipeline == null)
if (vertexLayout == null || pVertexData == IntPtr.Zero)
{ {
throw new InvalidOperationException($"Tried to {nameof(DrawArrays)} without bound vertex info!"); throw new InvalidOperationException($"Tried to {nameof(Draw)} without pipeline!");
} }
var vertexLayout = _currPipeline.VertexLayout;
if (_currPipeline.Memo != "xgui") if (_currPipeline.Memo != "xgui")
{ {
LegacyBindArrayData(vertexLayout, pVertexData); LegacyBindArrayData(vertexLayout, data);
GL.DrawArrays((GLPrimitiveType)mode, first, (uint)count); // these are the same enum GL.DrawArrays(PrimitiveType.TriangleStrip, 0, (uint)count);
return; return;
} }
@ -451,7 +443,7 @@ namespace BizHawk.Bizware.Graphics
unsafe unsafe
{ {
GL.BufferData(GLEnum.ArrayBuffer, new UIntPtr((uint)(count * stride)), (pVertexData + first * stride).ToPointer(), GLEnum.StaticDraw); GL.BufferData(GLEnum.ArrayBuffer, new UIntPtr((uint)(count * stride)), data.ToPointer(), GLEnum.StaticDraw);
foreach (var (i, item) in vertexLayout.Items) foreach (var (i, item) in vertexLayout.Items)
{ {
@ -466,7 +458,7 @@ namespace BizHawk.Bizware.Graphics
} }
} }
GL.DrawArrays((GLPrimitiveType)mode, first, (uint)count); // these are the same enum GL.DrawArrays(PrimitiveType.TriangleStrip, 0, (uint)count);
foreach (var (i, _) in vertexLayout.Items) foreach (var (i, _) in vertexLayout.Items)
{ {