当不在 dx9 兼容模式下时,DX9 风格的特性被禁用了吗?

DX9 style intristics are disabled when not in dx9 compatibility mode?

我目前正在为基本的高斯模糊编写 HLSL 着色器。着色器代码很简单,但我一直收到错误消息:

DX9 style intristics are disabled when not in dx9 compatibility mode. (LN#: 19)

这告诉我代码中的第 19 行是问题所在,我认为这是由于该特定行中的 tex2DSampler

#include "Common.hlsl"

Texture2D Texture0 : register(t0);
SamplerState Sampler : register(s0);

float4 PSMain(PixelShaderInput pixel) : SV_Target {
    float2 uv = pixel.TextureUV; // This is TEXCOORD0.
    float4 result = 0.0f;

    float offsets[21] = { ... };
    float weights[21] = { ... };

    // Blur horizontally.
    for (int x = 0; x < 21; x++)
        result += tex2D(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];

    return result;
}

有关代码的注释和我的问题,请参阅下文。


备注

由于我的代码位于未连接的计算机上,因此我必须将我的代码手动输入到 Whosebug 中。因此:


我的问题

经过广泛搜索后,我发现 ps_4_0 及更高版本不再支持 tex2D。好吧,4_0 将在旧模式下工作,但它不起作用 5_0,这正是我正在使用的。

Shader Model : Supported

Shader Model 4 : yes (pixel shader only), but you must use the legacy compile option when compiling.
Shader Model 3 (DirectX HLSL) : yes (pixel shader only)
Shader Model 2 (DirectX HLSL) : yes (pixel shader only)
Shader Model 1 (DirectX HLSL) : yes (pixel shader only)

这已被替换为Texture2Ddocumentation 可用。以下是上述文档中的示例:

// Object Declarations
Texture2D g_MeshTexture;    
SamplerState MeshTextureSampler
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};

struct VS_OUTPUT
{
    float4 Position   : SV_POSITION; 
    float4 Diffuse    : COLOR0;
    float2 TextureUV  : TEXCOORD0; 
};

VS_OUTPUT In;

// Shader body calling the intrinsic function
Output.RGBColor = g_MeshTexture.Sample(MeshTextureSampler, In.TextureUV) * In.Diffuse;

替换我的代码中的 tex2D 调用:

result += Texture0.Sample(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];

此外,请注意此 post 中的代码用于高斯模糊的水平传递。