Say I have an array of data which does not change during the entire execution of a program, e.g. the Poisson Disk used for shadow mapping in the following code snippet:
const uint sampleCount = 16;
static float2 poissonDisk[sampleCount] =
{
float2(0.2770745f, 0.6951455f),
float2(0.1874257f, -0.02561589f),
float2(-0.3381929f, 0.8713168f),
float2(0.5867746f, 0.1087471f),
float2(-0.3078699f, 0.188545f),
float2(0.7993396f, 0.4595091f),
float2(-0.09242552f, 0.5260149f),
float2(0.3657553f, -0.5329605f),
float2(-0.3829718f, -0.2476171f),
float2(-0.01085108f, -0.6966301f),
float2(0.8404155f, -0.3543923f),
float2(-0.5186161f, -0.7624033f),
float2(-0.8135794f, 0.2328489f),
float2(-0.784665f, -0.2434929f),
float2(0.9920505f, 0.0855163f),
float2(-0.687256f, 0.6711345f)
};
float shadow = 0.0f;
float calculatedDepth = input.shadowPos.z - 0.002f;
float2 shadowTexCoord = float2(input.shadowPos.x * 0.5f + 0.5f, -input.shadowPos.y * 0.5f + 0.5f);
for (uint i = 0; i < sampleCount; i++)
{
if (!shadowTexture.SampleCmp(depthSampler, shadowTexCoord + poissonDisk[i] / 700.0f,
calculatedDepth))
{
shadow += 0.5f / sampleCount;
}
}
What is the most efficient way of declaring it?
Options:
1) Send it to the GPU in a const buffer but the data will never change during the program.
2) Declare it as a local array as it is declared now. In this case does it get created on the GPU's stack every time the shader is executed or is GPU smart enough to move it to its 'static memory' and define it only once.
3) Put the static keyword in front. In this case, it should only be defined once right?
4) There are const global variables in OpenGL is there such an alternative in D3D?
5) Something else
Thanks for any advice.