MethodCopyTexture.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.State;
  3. namespace Ryujinx.Graphics.Gpu.Engine
  4. {
  5. partial class Methods
  6. {
  7. private void CopyTexture(GpuState state, int argument)
  8. {
  9. var dstCopyTexture = state.Get<CopyTexture>(MethodOffset.CopyDstTexture);
  10. var srcCopyTexture = state.Get<CopyTexture>(MethodOffset.CopySrcTexture);
  11. Image.Texture srcTexture = _textureManager.FindOrCreateTexture(srcCopyTexture);
  12. if (srcTexture == null)
  13. {
  14. return;
  15. }
  16. // When the source texture that was found has a depth format,
  17. // we must enforce the target texture also has a depth format,
  18. // as copies between depth and color formats are not allowed.
  19. if (srcTexture.Format == Format.D32Float)
  20. {
  21. dstCopyTexture.Format = RtFormat.D32Float;
  22. }
  23. Image.Texture dstTexture = _textureManager.FindOrCreateTexture(dstCopyTexture);
  24. if (dstTexture == null)
  25. {
  26. return;
  27. }
  28. var control = state.Get<CopyTextureControl>(MethodOffset.CopyTextureControl);
  29. var region = state.Get<CopyRegion>(MethodOffset.CopyRegion);
  30. int srcX1 = (int)(region.SrcXF >> 32);
  31. int srcY1 = (int)(region.SrcYF >> 32);
  32. int srcX2 = (int)((region.SrcXF + region.SrcWidthRF * region.DstWidth) >> 32);
  33. int srcY2 = (int)((region.SrcYF + region.SrcHeightRF * region.DstHeight) >> 32);
  34. int dstX1 = region.DstX;
  35. int dstY1 = region.DstY;
  36. int dstX2 = region.DstX + region.DstWidth;
  37. int dstY2 = region.DstY + region.DstHeight;
  38. Extents2D srcRegion = new Extents2D(
  39. srcX1 / srcTexture.Info.SamplesInX,
  40. srcY1 / srcTexture.Info.SamplesInY,
  41. srcX2 / srcTexture.Info.SamplesInX,
  42. srcY2 / srcTexture.Info.SamplesInY);
  43. Extents2D dstRegion = new Extents2D(
  44. dstX1 / dstTexture.Info.SamplesInX,
  45. dstY1 / dstTexture.Info.SamplesInY,
  46. dstX2 / dstTexture.Info.SamplesInX,
  47. dstY2 / dstTexture.Info.SamplesInY);
  48. bool linearFilter = control.UnpackLinearFilter();
  49. srcTexture.HostTexture.CopyTo(dstTexture.HostTexture, srcRegion, dstRegion, linearFilter);
  50. dstTexture.Modified = true;
  51. }
  52. }
  53. }