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