Skip to content

Commit

Permalink
MP1-5154: Core: Updated VertexBuffer performance/cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Jul 10, 2023
1 parent 1c76c9b commit b0abcbd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
20 changes: 10 additions & 10 deletions mediaportal/Core/Player/BDOSDRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private enum BD_OVERLAY_PLANE
/// </summary>
private VertexBuffer _vertexBuffer;

private LockFlags _vertexBufferLock;

/// <summary>
/// Array containing interactive and presentation graphics overlay textures
/// </summary>
Expand Down Expand Up @@ -219,16 +221,17 @@ private void CreateVertexBuffer(int wx, int wy, int wwidth, int wheight)
{
if (_vertexBuffer == null)
{
Usage usage = Usage.None;
Usage usage;
if (OSInfo.OSInfo.VistaOrLater())
{
this._vertexBufferLock = LockFlags.Discard;
usage = Usage.Dynamic | Usage.WriteOnly;
}
//_vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedTextured),
// 4, GUIGraphicsContext.DX9Device,
// usage,
// CustomVertex.TransformedTextured.Format,
// GUIGraphicsContext.GetTexturePoolType());
else
{
this._vertexBufferLock = LockFlags.None;
usage = Usage.None;
}

_vertexBuffer = new VertexBuffer(GUIGraphicsContext.DX9Device,
Util.CustomVertex.TransformedTextured.StrideSize * 4,
Expand All @@ -241,11 +244,9 @@ private void CreateVertexBuffer(int wx, int wy, int wwidth, int wheight)

if (_wx != wx || _wy != wy || _wwidth != wwidth || _wheight != wheight)
{
//CustomVertex.TransformedTextured[] verts = (CustomVertex.TransformedTextured[])_vertexBuffer.Lock(0, 0);

unsafe
{
Util.CustomVertex.TransformedTextured* verts = (Util.CustomVertex.TransformedTextured*)_vertexBuffer.LockToPointer(0, 0, LockFlags.None);
Util.CustomVertex.TransformedTextured* verts = (Util.CustomVertex.TransformedTextured*)_vertexBuffer.LockToPointer(0, 0, this._vertexBufferLock);
// upper left
verts[0] = new Util.CustomVertex.TransformedTextured(wx, wy, 0, 1, 0, 0);

Expand All @@ -258,7 +259,6 @@ private void CreateVertexBuffer(int wx, int wy, int wwidth, int wheight)
// lower right
verts[3] = new Util.CustomVertex.TransformedTextured(wx + wwidth, wy + wheight, 0, 1, 1, 1);

//_vertexBuffer.SetData(verts, 0, LockFlags.None);
_vertexBuffer.Unlock();

}
Expand Down
17 changes: 15 additions & 2 deletions mediaportal/Core/Player/PlaneScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class PlaneScene : IVMR9PresentCallback, IRenderLayer
private VMR9Util _vmr9Util = null;
private VertexBuffer[] _vertexBuffers;
private IntPtr _textureAddress;
private LockFlags _vertexBufferLock;

private CropSettings _cropSettings;
private bool updateCrop = false; // indicates that _cropSettings has been updated
Expand Down Expand Up @@ -135,13 +136,25 @@ public PlaneScene(VMR9Util util)
_textureAddress = IntPtr.Zero;
_vmr9Util = util;

Usage usage;
if (OSInfo.OSInfo.VistaOrLater())
{
this._vertexBufferLock = LockFlags.Discard;
usage = Usage.Dynamic | Usage.WriteOnly;
}
else
{
this._vertexBufferLock = LockFlags.None;
usage = Usage.None;
}

// Number of vertex buffers must be same as numer of segments in non-linear stretch
_vertexBuffers = new VertexBuffer[nlsSourcePartitioning.Length];
for (int i = 0; i < _vertexBuffers.Length; i++)
{
_vertexBuffers[i] = new VertexBuffer(GUIGraphicsContext.DX9Device,
CustomVertex.TransformedColoredTextured.StrideSize * 4,
Usage.None,
usage,
CustomVertex.TransformedColoredTextured.Format,
GUIGraphicsContext.GetTexturePoolType());
}
Expand Down Expand Up @@ -1995,7 +2008,7 @@ private void DrawTextureSegment(VertexBuffer vertexBuffer, float srcX, float src
{
unsafe
{
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)vertexBuffer.LockToPointer(0, 0, LockFlags.None);
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)vertexBuffer.LockToPointer(0, 0, this._vertexBufferLock);

float fVideoWidth = (float)GUIGraphicsContext.VideoSize.Width;
float fVideoHeight = (float)GUIGraphicsContext.VideoSize.Height;
Expand Down
60 changes: 42 additions & 18 deletions mediaportal/Core/Util/Picture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,22 @@ public static void RenderImage(Texture texture, float x, float y, float nw, floa
VertexBuffer m_vbBuffer = null;
try
{
//m_vbBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured),
// 4, GUIGraphicsContext.DX9Device,
// 0, CustomVertex.TransformedColoredTextured.Format,
// GUIGraphicsContext.GetTexturePoolType());
Usage usage;
LockFlags lockFlags;
if (OSInfo.OSInfo.VistaOrLater())
{
lockFlags = LockFlags.Discard;
usage = Usage.Dynamic | Usage.WriteOnly;
}
else
{
lockFlags = LockFlags.None;
usage = Usage.None;
}

m_vbBuffer = new VertexBuffer(GUIGraphicsContext.DX9Device,
CustomVertex.TransformedColoredTextured.StrideSize * 4,
Usage.None,
usage,
CustomVertex.TransformedColoredTextured.Format,
GUIGraphicsContext.GetTexturePoolType());

Expand Down Expand Up @@ -403,7 +411,7 @@ public static void RenderImage(Texture texture, float x, float y, float nw, floa

unsafe
{
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, LockFlags.None);
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, lockFlags);
// Lock the buffer (which will return our structs)
verts[0].X = x - 0.5f;
verts[0].Y = y + nh - 0.5f;
Expand Down Expand Up @@ -510,14 +518,22 @@ public static void RenderImage(Texture texture, int x, int y, int nw, int nh, in
VertexBuffer m_vbBuffer = null;
try
{
//m_vbBuffer = new VertexBuffer(typeof (CustomVertex.TransformedColoredTextured),
// 4, GUIGraphicsContext.DX9Device,
// 0, CustomVertex.TransformedColoredTextured.Format,
// GUIGraphicsContext.GetTexturePoolType());
Usage usage;
LockFlags lockFlags;
if (OSInfo.OSInfo.VistaOrLater())
{
lockFlags = LockFlags.Discard;
usage = Usage.Dynamic | Usage.WriteOnly;
}
else
{
lockFlags = LockFlags.None;
usage = Usage.None;
}

m_vbBuffer = new VertexBuffer(GUIGraphicsContext.DX9Device,
CustomVertex.TransformedColoredTextured.StrideSize * 4,
Usage.None,
usage,
CustomVertex.TransformedColoredTextured.Format,
GUIGraphicsContext.GetTexturePoolType());

Expand Down Expand Up @@ -565,7 +581,7 @@ public static void RenderImage(Texture texture, int x, int y, int nw, int nh, in

unsafe
{
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, LockFlags.None);
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, lockFlags);

// Lock the buffer (which will return our structs)
verts[0].X = x - 0.5f;
Expand Down Expand Up @@ -672,14 +688,22 @@ public static void RenderImage(Texture texture, float x, float y, float nw, floa
VertexBuffer m_vbBuffer = null;
try
{
//m_vbBuffer = new VertexBuffer(typeof (CustomVertex.TransformedColoredTextured),
// 4, GUIGraphicsContext.DX9Device,
// 0, CustomVertex.TransformedColoredTextured.Format,
// GUIGraphicsContext.GetTexturePoolType());
Usage usage;
LockFlags lockFlags;
if (OSInfo.OSInfo.VistaOrLater())
{
lockFlags = LockFlags.Discard;
usage = Usage.Dynamic | Usage.WriteOnly;
}
else
{
lockFlags = LockFlags.None;
usage = Usage.None;
}

m_vbBuffer = new VertexBuffer(GUIGraphicsContext.DX9Device,
CustomVertex.TransformedColoredTextured.StrideSize * 4,
Usage.None,
usage,
CustomVertex.TransformedColoredTextured.Format,
GUIGraphicsContext.GetTexturePoolType());

Expand Down Expand Up @@ -726,7 +750,7 @@ public static void RenderImage(Texture texture, float x, float y, float nw, floa

unsafe
{
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, LockFlags.None);
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)m_vbBuffer.LockToPointer(0, 0, lockFlags);

// Lock the buffer (which will return our structs)
verts[0].X = x - 0.5f;
Expand Down

0 comments on commit b0abcbd

Please sign in to comment.