2024-05-29 15:21:59 +00:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using SharpMetal.Metal;
|
|
|
|
using System;
|
|
|
|
using System.Buffers;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Metal
|
|
|
|
{
|
|
|
|
[SupportedOSPlatform("macos")]
|
2024-06-19 22:13:55 +00:00
|
|
|
class TextureBuffer : ITexture
|
2024-05-29 15:21:59 +00:00
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
private readonly MetalRenderer _renderer;
|
|
|
|
|
|
|
|
private BufferHandle _bufferHandle;
|
2024-05-29 15:21:59 +00:00
|
|
|
private int _offset;
|
|
|
|
private int _size;
|
|
|
|
|
2024-06-19 22:13:55 +00:00
|
|
|
private int _bufferCount;
|
|
|
|
|
|
|
|
public int Width { get; }
|
|
|
|
public int Height { get; }
|
|
|
|
|
|
|
|
public MTLPixelFormat MtlFormat { get; }
|
2024-05-29 15:21:59 +00:00
|
|
|
|
2024-06-19 22:13:55 +00:00
|
|
|
public TextureBuffer(MetalRenderer renderer, TextureCreateInfo info)
|
2024-05-29 15:21:59 +00:00
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
_renderer = renderer;
|
|
|
|
Width = info.Width;
|
|
|
|
Height = info.Height;
|
|
|
|
MtlFormat = FormatTable.GetFormat(info.Format);
|
2024-05-29 15:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyTo(ITexture destination, int firstLayer, int firstLevel)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyTo(ITexture destination, int srcLayer, int dstLayer, int srcLevel, int dstLevel)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PinnedSpan<byte> GetData()
|
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
return _renderer.GetBufferData(_bufferHandle, _offset, _size);
|
2024-05-29 15:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public PinnedSpan<byte> GetData(int layer, int level)
|
|
|
|
{
|
|
|
|
return GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyTo(BufferRange range, int layer, int level, int stride)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2024-06-19 22:13:55 +00:00
|
|
|
public void Release()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:21:59 +00:00
|
|
|
public void SetData(IMemoryOwner<byte> data)
|
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
_renderer.SetBufferData(_bufferHandle, _offset, data.Memory.Span);
|
2024-05-29 15:21:59 +00:00
|
|
|
data.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData(IMemoryOwner<byte> data, int layer, int level)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData(IMemoryOwner<byte> data, int layer, int level, Rectangle<int> region)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetStorage(BufferRange buffer)
|
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
if (_bufferHandle == buffer.Handle &&
|
|
|
|
_offset == buffer.Offset &&
|
|
|
|
_size == buffer.Size &&
|
|
|
|
_bufferCount == _renderer.BufferManager.BufferCount)
|
2024-05-29 15:21:59 +00:00
|
|
|
{
|
2024-06-19 22:13:55 +00:00
|
|
|
return;
|
2024-05-29 15:21:59 +00:00
|
|
|
}
|
2024-06-19 22:13:55 +00:00
|
|
|
|
|
|
|
_bufferHandle = buffer.Handle;
|
|
|
|
_offset = buffer.Offset;
|
|
|
|
_size = buffer.Size;
|
|
|
|
_bufferCount = _renderer.BufferManager.BufferCount;
|
|
|
|
|
|
|
|
Release();
|
2024-05-29 15:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|