image-processing - 你如何计算 HLSL 中的指令?

标签 image-processing hlsl

当我使用下面的代码时:


#define MAX_RADIUS 55
#define KERNEL_SIZE (MAX_RADIUS * 2 + 1)
...
float[] kernel[KERNEL_RADIUS];
...
float4 PS_GaussianBlur(float2 texCoord : TEXCOORD) : COLOR0
{
    float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);

    //add the right side offset pixels to the color
    for (int i = 0; i < MAX_RADIUS; i++)
    {
        if(kernel[i] != 0) //this will improve performance for lower filter radius's, but increases const register num
            color += tex2D(colorMap, texCoord + offsets[i]) * kernel[i];
    }
    //add the left side offset pixels to the color
    for (int j = 0; j < MAX_RADIUS; j++)
    {
        if(kernel[i] != 0)
            color += tex2D(colorMap, texCoord - offsets[j]) * kernel[j];
    }
    //finally add the weight of the original pixel to the color
    color += tex2D(colorMap, texCoord) * kernel[MAX_RADIUS];

    return color;
}

if(kernel[i] != 0) 显着增加了使用的指令数量!

所以我的问题是:是什么增加了指令数?为什么在只有 110 条指令长的循环中使用 if 语句会使指令数增加 400 多条?

编辑:以上问题已编辑。当它真的是指令时,我错误地认为寄存器被占用了。但是,这个问题仍然适用。什么会导致 2 个 for 循环(每个循环长度为 55)将指令数增加超过 400,而循环中仅添加 1 个 if 语句?

最佳答案

fxc 会给你一个指令计数。但实际上,你应该用另一种方式来做这件事。试试双向滤波器,一个通过 U,另一个通过 V?

关于image-processing - 你如何计算 HLSL 中的指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852644/

相关文章:

Android:如何在同一个 fragment 着色器中使用 samplerExternalOES 和 sampler2D

image-processing - 谁能解释一下hq2x算法的原理?

python - 从图像中删除网格

xna - 八叉树光线转换/光线跟踪 - 无递归的最佳光线/叶子交叉点

c# - HLSL/XNA 环境光纹理与多 channel 照明混合

c++ - HLSL 法线贴图矩阵乘法

image-processing - "semantic segmentation"与 "segmentation"和 "scene labeling"相比是什么?

debugging - NSight 图形调试无法启动

c++ - 如何在 C++/DirectX 和 HLSL 之间共享结构?

matlab - Matlab中的手写字符模板匹配