TextureHandle.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Runtime.CompilerServices;
  2. namespace Ryujinx.Graphics.Shader
  3. {
  4. public enum TextureHandleType
  5. {
  6. CombinedSampler = 0, // Must be 0.
  7. SeparateSamplerHandle = 1,
  8. SeparateSamplerId = 2
  9. }
  10. public static class TextureHandle
  11. {
  12. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  13. public static int PackSlots(int cbufSlot0, int cbufSlot1)
  14. {
  15. return cbufSlot0 | ((cbufSlot1 + 1) << 16);
  16. }
  17. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  18. public static (int, int) UnpackSlots(int slots, int defaultTextureBufferIndex)
  19. {
  20. int textureBufferIndex;
  21. int samplerBufferIndex;
  22. if (slots < 0)
  23. {
  24. textureBufferIndex = defaultTextureBufferIndex;
  25. samplerBufferIndex = textureBufferIndex;
  26. }
  27. else
  28. {
  29. uint high = (uint)slots >> 16;
  30. textureBufferIndex = (ushort)slots;
  31. samplerBufferIndex = high != 0 ? (int)high - 1 : textureBufferIndex;
  32. }
  33. return (textureBufferIndex, samplerBufferIndex);
  34. }
  35. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  36. public static int PackOffsets(int cbufOffset0, int cbufOffset1, TextureHandleType type)
  37. {
  38. return cbufOffset0 | (cbufOffset1 << 14) | ((int)type << 28);
  39. }
  40. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  41. public static (int, int, TextureHandleType) UnpackOffsets(int handle)
  42. {
  43. return (handle & 0x3fff, (handle >> 14) & 0x3fff, (TextureHandleType)((uint)handle >> 28));
  44. }
  45. }
  46. }