GlobalMemory.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. namespace Ryujinx.Graphics.Shader.Translation
  3. {
  4. static class GlobalMemory
  5. {
  6. private const int StorageDescsBaseOffset = 0x44; // In words.
  7. public const int StorageDescSize = 4; // In words.
  8. public const int StorageMaxCount = 16;
  9. public const int StorageDescsSize = StorageDescSize * StorageMaxCount;
  10. public const int UbeBaseOffset = 0x98; // In words.
  11. public const int UbeMaxCount = 9;
  12. public const int UbeDescsSize = StorageDescSize * UbeMaxCount;
  13. public const int UbeFirstCbuf = 8;
  14. public static bool UsesGlobalMemory(Instruction inst)
  15. {
  16. return (inst.IsAtomic() && IsGlobalMr(inst)) ||
  17. inst == Instruction.LoadGlobal ||
  18. inst == Instruction.StoreGlobal ||
  19. inst == Instruction.StoreGlobal16 ||
  20. inst == Instruction.StoreGlobal8;
  21. }
  22. private static bool IsGlobalMr(Instruction inst)
  23. {
  24. return (inst & Instruction.MrMask) == Instruction.MrGlobal;
  25. }
  26. public static int GetStorageCbOffset(ShaderStage stage, int slot)
  27. {
  28. return GetStorageBaseCbOffset(stage) + slot * StorageDescSize;
  29. }
  30. public static int GetStorageBaseCbOffset(ShaderStage stage)
  31. {
  32. return stage switch
  33. {
  34. ShaderStage.Compute => StorageDescsBaseOffset + 2 * StorageDescsSize,
  35. ShaderStage.Vertex => StorageDescsBaseOffset,
  36. ShaderStage.TessellationControl => StorageDescsBaseOffset + 1 * StorageDescsSize,
  37. ShaderStage.TessellationEvaluation => StorageDescsBaseOffset + 2 * StorageDescsSize,
  38. ShaderStage.Geometry => StorageDescsBaseOffset + 3 * StorageDescsSize,
  39. ShaderStage.Fragment => StorageDescsBaseOffset + 4 * StorageDescsSize,
  40. _ => 0
  41. };
  42. }
  43. }
  44. }