Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextureXR.hlsl 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef UNITY_TEXTUREXR_INCLUDED
  2. #define UNITY_TEXTUREXR_INCLUDED
  3. // single-pass instancing is the default VR method for SRPs
  4. // multi-pass is working but not recommended due to lower performance
  5. // single-pass multi-view is not yet supported
  6. // single-pass doule-wide is deprecated
  7. // Must be in sync with C# with property useTexArray in TextureXR.cs
  8. #if (defined(SHADER_API_D3D11) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_GAMECORE)) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_METAL)
  9. #define UNITY_TEXTURE2D_X_ARRAY_SUPPORTED
  10. #endif
  11. // Validate supported platforms
  12. #if defined(STEREO_INSTANCING_ON) && !defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED)
  13. #error Single-pass instancing is not supported on this platform (see UNITY_TEXTURE2D_X_ARRAY_SUPPORTED).
  14. #endif
  15. #if defined(UNITY_SINGLE_PASS_STEREO)
  16. #error Single-pass (double-wide) is not compatible with TextureXR.hlsl.
  17. #endif
  18. // Control if TEXTURE2D_X macros will expand to texture arrays
  19. #if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && !defined(DISABLE_TEXTURE2D_X_ARRAY)
  20. #define USE_TEXTURE2D_X_AS_ARRAY
  21. #endif
  22. // Early defines for single-pass instancing
  23. #if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED)
  24. #define UNITY_STEREO_INSTANCING_ENABLED
  25. #endif
  26. // Workaround for lack of multi compile in compute/ray shaders
  27. #if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && (defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING))
  28. #define UNITY_STEREO_INSTANCING_ENABLED
  29. #endif
  30. // Define to override default rendering matrices
  31. #if defined(UNITY_STEREO_INSTANCING_ENABLED)
  32. #define USING_STEREO_MATRICES
  33. #endif
  34. // Helper macros to handle XR single-pass with Texture2DArray
  35. // With single-pass instancing, unity_StereoEyeIndex is used to select the eye in the current context.
  36. // Otherwise, the index is statically set to 0
  37. #if defined(USE_TEXTURE2D_X_AS_ARRAY)
  38. // Only single-pass stereo instancing used array indexing
  39. #if defined(UNITY_STEREO_INSTANCING_ENABLED)
  40. #define SLICE_ARRAY_INDEX unity_StereoEyeIndex
  41. #else
  42. #define SLICE_ARRAY_INDEX 0
  43. #endif
  44. #define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, SLICE_ARRAY_INDEX)
  45. #define INDEX_TEXTURE2D_ARRAY_X(slot) ((slot) * _XRViewCount + SLICE_ARRAY_INDEX)
  46. #define TEXTURE2D_X TEXTURE2D_ARRAY
  47. #define TEXTURE2D_X_PARAM TEXTURE2D_ARRAY_PARAM
  48. #define TEXTURE2D_X_ARGS TEXTURE2D_ARRAY_ARGS
  49. #define TEXTURE2D_X_HALF TEXTURE2D_ARRAY_HALF
  50. #define TEXTURE2D_X_FLOAT TEXTURE2D_ARRAY_FLOAT
  51. #define TEXTURE2D_X_UINT(textureName) Texture2DArray<uint> textureName
  52. #define TEXTURE2D_X_UINT2(textureName) Texture2DArray<uint2> textureName
  53. #define TEXTURE2D_X_UINT4(textureName) Texture2DArray<uint4> textureName
  54. //Using explicit sample count of 1 to force DXC to actually reflect the texture as MS. The actual count appears to be irrelevant and any 2D MS texture array should bind to it
  55. #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMSArray<type, 1> textureName
  56. #define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName)
  57. #define TYPED_TEXTURE2D_X(type, textureName) TYPED_TEXTURE2D_ARRAY(type, textureName)
  58. #define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, SLICE_ARRAY_INDEX)
  59. #define LOAD_TEXTURE2D_X_MSAA(textureName, unCoord2, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, SLICE_ARRAY_INDEX, sampleIndex)
  60. #define LOAD_TEXTURE2D_X_LOD(textureName, unCoord2, lod) LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, SLICE_ARRAY_INDEX, lod)
  61. #define SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
  62. #define SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, SLICE_ARRAY_INDEX, lod)
  63. #define GATHER_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
  64. #define GATHER_RED_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_RED_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
  65. #define GATHER_GREEN_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_GREEN_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
  66. #define GATHER_BLUE_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_BLUE_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
  67. #define GATHER_ALPHA_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_ALPHA_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
  68. #else
  69. #define SLICE_ARRAY_INDEX 0
  70. #define COORD_TEXTURE2D_X(pixelCoord) pixelCoord
  71. #define INDEX_TEXTURE2D_ARRAY_X(slot) (slot)
  72. #define TEXTURE2D_X TEXTURE2D
  73. #define TEXTURE2D_X_PARAM TEXTURE2D_PARAM
  74. #define TEXTURE2D_X_ARGS TEXTURE2D_ARGS
  75. #define TEXTURE2D_X_HALF TEXTURE2D_HALF
  76. #define TEXTURE2D_X_FLOAT TEXTURE2D_FLOAT
  77. #define TEXTURE2D_X_UINT(textureName) Texture2D<uint> textureName
  78. #define TEXTURE2D_X_UINT2(textureName) Texture2D<uint2> textureName
  79. #define TEXTURE2D_X_UINT4(textureName) Texture2D<uint4> textureName
  80. //Using explicit sample count of 1 to force DXC to actually reflect the texture as MS. The actual count appears to be irrelevant and any 2D MS texture should bind to it
  81. #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMS<type, 1> textureName
  82. #define RW_TEXTURE2D_X RW_TEXTURE2D
  83. #define TYPED_TEXTURE2D_X TYPED_TEXTURE2D
  84. #define LOAD_TEXTURE2D_X LOAD_TEXTURE2D
  85. #define LOAD_TEXTURE2D_X_MSAA LOAD_TEXTURE2D_MSAA
  86. #define LOAD_TEXTURE2D_X_LOD LOAD_TEXTURE2D_LOD
  87. #define SAMPLE_TEXTURE2D_X SAMPLE_TEXTURE2D
  88. #define SAMPLE_TEXTURE2D_X_LOD SAMPLE_TEXTURE2D_LOD
  89. #define GATHER_TEXTURE2D_X GATHER_TEXTURE2D
  90. #define GATHER_RED_TEXTURE2D_X GATHER_RED_TEXTURE2D
  91. #define GATHER_GREEN_TEXTURE2D_X GATHER_GREEN_TEXTURE2D
  92. #define GATHER_BLUE_TEXTURE2D_X GATHER_BLUE_TEXTURE2D
  93. #define GATHER_ALPHA_TEXTURE2D_X GATHER_ALPHA_TEXTURE2D
  94. #endif
  95. // see Unity\Shaders\Includes\UnityShaderVariables.cginc for impl used by the C++ renderer
  96. #if defined(USING_STEREO_MATRICES) && defined(UNITY_STEREO_INSTANCING_ENABLED)
  97. static uint unity_StereoEyeIndex;
  98. #else
  99. #define unity_StereoEyeIndex 0
  100. #endif
  101. // Helper macro to assign view index during compute/ray pass (usually from SV_DispatchThreadID or DispatchRaysIndex())
  102. #if defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING)
  103. #if defined(UNITY_STEREO_INSTANCING_ENABLED)
  104. #define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex) unity_StereoEyeIndex = viewIndex;
  105. #else
  106. #define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex)
  107. #endif
  108. // Backward compatibility
  109. #define UNITY_STEREO_ASSIGN_COMPUTE_EYE_INDEX UNITY_XR_ASSIGN_VIEW_INDEX
  110. #endif
  111. #endif // UNITY_TEXTUREXR_INCLUDED