Search code examples
directx-11hlsl

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


I am currently writing an HLSL shader for a basic Gaussian blur. The shader code is straight forward, but I keep getting an error:

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

This tells me that line 19 in my code is the issue, and I believe it is either due to tex2D or Sampler in that particular line.

#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;
}

See below for notes about the code, and my questions.


Notes

I have to hand type my code into StackOverflow due to my code being on a computer without a connection. Therefore:

  • Any spelling or case errors present here do not exist in code.
  • The absence of values inside of offsets and weights is intentional.
    • This is because there are 21 values in each and I didn't feel like typing them all.
    • offsets is every integer from -10 to 10.
    • weights ranges from 0.01 to 0.25 and back to 0.01.
  • The line count here is smaller due to the absence mentioned prior.
    • The line number of the error here is 15.
    • The column range is 13 - 59 which encapsulates tex2D and Sampler.

My Questions

  • Am I using the wrong data type for Sampler in the tex2D call?
  • Is tex2D deprecated in DirectX 11?
  • What should I be using instead?
  • What am I doing wrong here as that is my only error.

Solution

  • After some extensive searching, I've found out that tex2D is no longer supported from ps_4_0 and up. Well, 4_0 will work in legacy mode, but it doesn't work it 5_0 which is what I am using.

    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)

    This has been replaced by Texture2D; the documentation is available for it. Below is an example from the mentioned documentation:

    // 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;
    

    To replace the tex2D call in my code:

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

    Also, note that the code in this post is for the horizontal pass of a Gaussian blur.