GlobalMemory.cs 2.1 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, StorageKind storageKind)
  15. {
  16. return (inst.IsAtomic() && storageKind == StorageKind.GlobalMemory) ||
  17. inst == Instruction.LoadGlobal ||
  18. inst == Instruction.StoreGlobal ||
  19. inst == Instruction.StoreGlobal16 ||
  20. inst == Instruction.StoreGlobal8;
  21. }
  22. public static int GetStorageCbOffset(ShaderStage stage, int slot)
  23. {
  24. return GetStorageBaseCbOffset(stage) + slot * StorageDescSize;
  25. }
  26. public static int GetStorageBaseCbOffset(ShaderStage stage)
  27. {
  28. return stage switch
  29. {
  30. ShaderStage.Compute => StorageDescsBaseOffset + 2 * StorageDescsSize,
  31. ShaderStage.Vertex => StorageDescsBaseOffset,
  32. ShaderStage.TessellationControl => StorageDescsBaseOffset + 1 * StorageDescsSize,
  33. ShaderStage.TessellationEvaluation => StorageDescsBaseOffset + 2 * StorageDescsSize,
  34. ShaderStage.Geometry => StorageDescsBaseOffset + 3 * StorageDescsSize,
  35. ShaderStage.Fragment => StorageDescsBaseOffset + 4 * StorageDescsSize,
  36. _ => 0
  37. };
  38. }
  39. public static int GetConstantUbeOffset(int slot)
  40. {
  41. return UbeBaseOffset + slot * StorageDescSize;
  42. }
  43. }
  44. }