Question

I'm working with DX9/SM3 at the moment, and the MSDN documentation on HLSL samplers seems to be sorely lacking in explaining how to use the different sampler types. What's worse is they try to cover DX9 and DX10 in a single article, so they jumble together all the keywords:

sampler Name = SamplerType { Texture = <texture_variable>; [state_name = state_value;] ... };

...

SamplerType

[in] The sampler type, which is one of the following: sampler, sampler1D, sampler2D, sampler3D, samplerCUBE, sampler_state, SamplerState.

Differences between Direct3D 9 and Direct3D 10:

Direct3D 10 supports one additional sampler type: SamplerComparisonState.

I get the feeling that contrary to this writeup, SamplerState is DX10 only. Virtually all the code I see uses sampler_state for SamplerType. A quick example from BasicHLSL (DX9):

sampler MeshTextureSampler =
sampler_state
{
    Texture = <g_MeshTexture>;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

Why do all the different _SamplerType_s exist and when would you use, say, sampler or sampler2D instead of sampler_state? You need to be explicit when fetching anyhow, e.g. tex2D, texCUBE, so what is going on here?

Was it helpful?

Solution

You're right. That is very odd.

It seems as if the documentation on the DirectX 9 syntax is wrong. I'm by no means an expert on either HLSL or DirectX, but I've always only seen samplers in DirectX 9 being declared like this:

SamplerType Name = sampler_state{   Texture = <texture_variable>;   [state_name = state_value;]   ... }; 

I might be missing something but to me the above syntax makes more sense than the one in the documentation. You declare a sampler with a given type, and specifies the sampler state.

UPDATE: Apparently it IS wrong. I've started a thread on the official forums and so far I've only gotten a confirmation that it is wrong. I've also sent a mail directly to the DirectX team. Just to be on the safe side.

OTHER TIPS

sampler Name = SamplerType { Texture = ; [state_name = state_value;]};

It is correct! The declaration is valid only for effects.

EDIT: the official forums are on MSDN. You can post a suggestion or an error using "Community Additions".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top