TextureWriter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using System;
  4. namespace Ryujinx.Core.Gpu
  5. {
  6. public static class TextureWriter
  7. {
  8. public static void Write(IAMemory Memory, Texture Texture, byte[] Data)
  9. {
  10. switch (Texture.Format)
  11. {
  12. case GalTextureFormat.A8B8G8R8: Write4Bpp(Memory, Texture, Data); break;
  13. default: throw new NotImplementedException(Texture.Format.ToString());
  14. }
  15. }
  16. private unsafe static void Write4Bpp(IAMemory Memory, Texture Texture, byte[] Data)
  17. {
  18. int Width = Texture.Width;
  19. int Height = Texture.Height;
  20. ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4);
  21. (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
  22. Memory,
  23. Texture.Position);
  24. fixed (byte* BuffPtr = Data)
  25. {
  26. long InOffs = 0;
  27. for (int Y = 0; Y < Height; Y++)
  28. for (int X = 0; X < Width; X++)
  29. {
  30. long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);
  31. int Pixel = *(int*)(BuffPtr + InOffs);
  32. CpuMem.WriteInt32Unchecked(Position + Offset, Pixel);
  33. InOffs += 4;
  34. }
  35. }
  36. }
  37. }
  38. }