Delete and Get Data from Buffer

This commit is contained in:
Isaac Marovitz 2023-07-28 11:55:52 -04:00
parent db3c60f91f
commit 964233d458
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
2 changed files with 23 additions and 22 deletions

View File

@ -89,22 +89,7 @@ namespace Ryujinx.Graphics.Metal
public ITexture CreateTexture(TextureCreateInfo info)
{
MTLTextureDescriptor descriptor = new()
{
PixelFormat = FormatCapabilities.ConvertToMTLFormat(info.Format),
TextureType = info.Target.Convert(),
Width = (ulong)info.Width,
Height = (ulong)info.Height,
MipmapLevelCount = (ulong)info.Levels,
SampleCount = (ulong)info.Samples,
};
return CreateTextureView(info);
}
internal Texture CreateTextureView(TextureCreateInfo info)
{
throw new NotImplementedException();
return new Texture(_device, _pipeline, info);
}
public bool PrepareHostMapping(IntPtr address, ulong size)
@ -120,12 +105,14 @@ namespace Ryujinx.Graphics.Metal
public void DeleteBuffer(BufferHandle buffer)
{
throw new NotImplementedException();
MTLBuffer mtlBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref buffer));
mtlBuffer.SetPurgeableState(MTLPurgeableState.Empty);
}
public PinnedSpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)
public unsafe PinnedSpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)
{
throw new NotImplementedException();
MTLBuffer mtlBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref buffer));
return new PinnedSpan<byte>(IntPtr.Add(mtlBuffer.Contents, offset).ToPointer(), size);
}
public Capabilities GetCapabilities()

View File

@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Metal
public int Width => Info.Width;
public int Height => Info.Height;
public Texture(MTLDevice device, Pipeline pipeline, TextureCreateInfo info, int firstLayer, int firstLevel)
public Texture(MTLDevice device, Pipeline pipeline, TextureCreateInfo info)
{
_device = device;
_pipeline = pipeline;
@ -114,9 +114,23 @@ namespace Ryujinx.Graphics.Metal
throw new NotImplementedException();
}
public void SetData(SpanOrArray<byte> data, int layer, int level, Rectangle<int> region)
public unsafe void SetData(SpanOrArray<byte> data, int layer, int level, Rectangle<int> region)
{
throw new NotImplementedException();
// TODO: Figure out bytesPerRow
// For an ordinary or packed pixel format, the stride, in bytes, between rows of source data.
// For a compressed pixel format, the stride is the number of bytes from the beginning of one row of blocks to the beginning of the next.
if (MTLTexture.IsSparse)
ulong bytesPerRow = 0;
var mtlRegion = new MTLRegion
{
origin = new MTLOrigin { x = (ulong)region.X, y = (ulong)region.Y },
size = new MTLSize { width = (ulong)region.Width, height = (ulong)region.Height },
};
fixed (byte* pData = data.Span)
{
MTLTexture.ReplaceRegion(mtlRegion, (ulong)level, (ulong)layer, new IntPtr(pData), bytesPerRow, 0);
}
}
public void SetStorage(BufferRange buffer)