What are all the different HLSL sampler types for?
Asked Answered
S

2

10

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?

Scapegoat answered 19/8, 2009 at 17:37 Comment(0)
D
4

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.

December answered 19/8, 2009 at 20:16 Comment(3)
be warned, [email protected] is not actively monitored.Musa
Didn't know that, thanks. Well I've also rated and provided feedback to the article in question, so maybe that'll work.December
Thanks, glad I haven't lost it. I managed to dig out my old DX9 CHM and it had a much cleaner article. DX9 even does support sampler arrays, but you'd never know that from the newly botched MSDN page.Scapegoat
F
0

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".

Facia answered 24/2, 2014 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.