mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-21 07:52:20 +00:00
Finish SetData /w region
This commit is contained in:
parent
66d575965c
commit
8b21447018
1 changed files with 15 additions and 9 deletions
|
@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
public MTLTexture MTLTexture;
|
public MTLTexture MTLTexture;
|
||||||
public TextureCreateInfo Info => Info;
|
public TextureCreateInfo Info => _info;
|
||||||
public int Width => Info.Width;
|
public int Width => Info.Width;
|
||||||
public int Height => Info.Height;
|
public int Height => Info.Height;
|
||||||
|
|
||||||
|
@ -114,22 +114,28 @@ namespace Ryujinx.Graphics.Metal
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void SetData(SpanOrArray<byte> data, int layer, int level, Rectangle<int> region)
|
public void SetData(SpanOrArray<byte> data, int layer, int level, Rectangle<int> region)
|
||||||
{
|
{
|
||||||
// TODO: Figure out bytesPerRow
|
ulong bytesPerRow = (ulong)(Info.Width * Info.BytesPerPixel);
|
||||||
// For an ordinary or packed pixel format, the stride, in bytes, between rows of source data.
|
ulong bytesPerImage = 0;
|
||||||
// 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)
|
if (MTLTexture.TextureType == MTLTextureType.Type3D)
|
||||||
ulong bytesPerRow = 0;
|
{
|
||||||
|
bytesPerImage = bytesPerRow * (ulong)Info.Height;
|
||||||
|
}
|
||||||
|
|
||||||
var mtlRegion = new MTLRegion
|
var mtlRegion = new MTLRegion
|
||||||
{
|
{
|
||||||
origin = new MTLOrigin { x = (ulong)region.X, y = (ulong)region.Y },
|
origin = new MTLOrigin { x = (ulong)region.X, y = (ulong)region.Y },
|
||||||
size = new MTLSize { width = (ulong)region.Width, height = (ulong)region.Height },
|
size = new MTLSize { width = (ulong)region.Width, height = (ulong)region.Height },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
fixed (byte* pData = data.Span)
|
fixed (byte* pData = data.Span)
|
||||||
{
|
{
|
||||||
MTLTexture.ReplaceRegion(mtlRegion, (ulong)level, (ulong)layer, new IntPtr(pData), bytesPerRow, 0);
|
MTLTexture.ReplaceRegion(mtlRegion, (ulong)level, (ulong)layer, new IntPtr(pData), bytesPerRow, bytesPerImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue