title: Understanding the "sampler array index must be a literal expression" error in ComputeShaders
body: <p>Let's say I have a compute shader that retrieves data from a Texture2DArray using the Id of the group like this:</p>
  
  <pre><code>Texture2DArray&lt;float4&gt; gTextureArray[2];
  [numthreads(32, 1, 1)]
  void Kernel(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadID)
  {
      float3 tmp = gTextureArray[GroupID.x].Load(int4(GroupThreadID.x,GroupThreadID.x,0,0)).rgb;
  
      ....
  }
  </code></pre>
  
  <p>And let's say I launch it like this <code>deviceContext-&gt;Dispatch(2, 0, 0);</code></p>
  
  <p>So, 2 groups, 32 threads each that read pixel values from a Texture2DArray. All the threads in GroupID.x = 0 will read values from gTextureArray[0] and all the threads in GroupID.y = 0 will read values from gTextureArray[1]. It turns out I can't compile that simple code, instead I get this compile error <code>error X3512: sampler array index must be a literal expression</code></p>
  
  <p>Now, I know I can do this instead:</p>
  
  <pre><code>Texture2DArray&lt;float4&gt; gTextureArray[2];
  [numthreads(32, 1, 1)]
  void Kernel(uint3 GroupID : SV_GroupID, uint3 GroupThreadID : SV_GroupThreadID)
  {
      float3 tmp = float3(0,0,0);
      if(GroupID.x == 0)
          tmp = gTextureArray[0].Load(int4(GroupThreadID.x,GroupThreadID.x,0,0)).rgb;
      else if(GroupID.x == 1)
          tmp = gTextureArray[1].Load(int4(GroupThreadID.x,GroupThreadID.x,0,0)).rgb;
  
      ....
  }
  </code></pre>
  
  <p>Or use a switch in case I have lots of groups so it doesn't look that much awful (it still does)</p>
  
  <p>Notice how there is no warp divergence since all threads in each group will go one branch or the other. My question is, am I missing something here? Why does HLSL not support that kind of indexing since I can not see any divergence or other problems, at least in this case?</p>