TextureWriter.cs 1.5 KB

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