使用采样器和直接索引访问之间的区别

时间:2018-08-21 12:05:29

标签: directx shader hlsl compute-shader

如果我的计算着色器中有纹理输入,那么除了使用插值法以及使用索引与归一化坐标之外,使用索引运算符[]或使用采样器之间是否有显着差异?如果不需要插值,使用采样器时会不会有明显的性能损失?

RWTexture3D<float4> Output;
Texture3D<float4> Input;
SamplerState samplerInput;

[numthreads(8, 8, 8)]
void main(uint3 id : SV_DispatchThreadID)
{
    float width, height, depth;
    Output.GetDimensions(width, height, depth);
    float3 dimensions = float3(width, height, depth);
    float3 coords = id.xyz / dimensions;
    float4 value;

    // Sampler:
    value = Input.SampleLevel(samplerInput, coords, 0);

    // Index operator:
    value = Input[id];

    // ...
}

0 个答案:

没有答案