GlobalMemory.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  20. private static bool IsGlobalMr(Instruction inst)
  21. {
  22. return (inst & Instruction.MrMask) == Instruction.MrGlobal;
  23. }
  24. public static int GetStorageCbOffset(ShaderStage stage, int slot)
  25. {
  26. return GetStorageBaseCbOffset(stage) + slot * StorageDescSize;
  27. }
  28. public static int GetStorageBaseCbOffset(ShaderStage stage)
  29. {
  30. return stage switch
  31. {
  32. ShaderStage.Compute => StorageDescsBaseOffset + 2 * StorageDescsSize,
  33. ShaderStage.Vertex => StorageDescsBaseOffset,
  34. ShaderStage.TessellationControl => StorageDescsBaseOffset + 1 * StorageDescsSize,
  35. ShaderStage.TessellationEvaluation => StorageDescsBaseOffset + 2 * StorageDescsSize,
  36. ShaderStage.Geometry => StorageDescsBaseOffset + 3 * StorageDescsSize,
  37. ShaderStage.Fragment => StorageDescsBaseOffset + 4 * StorageDescsSize,
  38. _ => 0
  39. };
  40. }
  41. }
  42. }