Jump to content
  • Advertisement
Sign in to follow this  

DX11 [DX11] HLSL 5 setting SamplerState from within the shader isn't working

This topic is 2400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,
I'm having some trouble with a hlsl shader I've written for a deferred shader to do texture mapping onto a road in my game.
Basically I define a SamplerState at the top of my shader which I then use to sample my textures to map onto the surface.
I've defined it based on the MSDN documentation so that I shouldn't need to create and set and Samplers from within my C++ code and it can all be done from within the shader.
However when I run it, the sampler seems to be ignored. The directx debug gives the following warning:

D3D11: WARNING: ID3D11DeviceContext::Draw: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults. [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET ]

Here are the relevant code snippets from my shader:

// textures are passed in from my application
Texture2D widthMap : register ( t0 );
Texture2D lengthMap : register ( t1 );
// the sampler state defined in shader code so that my application
// doesn't have to
SamplerState MySampler
AddressU = Wrap;
AddressV = Wrap;
// pixel shader which samples the texture
POut PShader(PIn input)
output.colour = float4(lengthMap.Sample(MySampler, float2(input.texCoord.y, 0.0f)));
return output;

Ignore the dodgy texture coordinate - the premise for my texture sampling is to "build" the actual texture out of 2 textures which define the u colour and v colour - when both the u and v are filled in then I use the colour, otherwise that pixel is set to black - I'm using it to generate the road lines so that I can define any road line layout I want based on 2 very small textures.

I've dug through a few of the DirectX samples and I can see them declaring the SamplerState at the top just like I have and seem to have no such problems.
I've also tried declaring a samplerstate for each texture I want to sample and within each state I set the "Texture" field to the target texture. I changed it to the current version as this is how the directx samples seem to do it.

This problem is also present everywhere I sample a texture in my deferred shaders as well!

I've got no idea what I've missed. I can't see any settings that I need to set to tell DirectX to use what ever the shader itself supplies, as far as I was aware - declaring it in my shader should work fine.

I can post more examples of my shader files if needed.

Has anyone got any suggests???

Thanks very much!!

Share this post

Link to post
Share on other sites
Are you using the effect framework? If not, as far as I know, you'll need to create the sampler (with the desired settings) in the program side and bind it to the register.

Best regards!

Share this post

Link to post
Share on other sites
No I'm not.....goddamn it! I was hoping for a quick win.....Ok. Yeah it looks like you're right, just stumbled onto this post after reading your reply. It seems my google-fu is still not as strong as I'd hoped.
Thanks very much for the help!

Share this post

Link to post
Share on other sites
For all those that are interested - just found this post which discusses a nice way to deal with this situation, which is what I'm now going to do. The developer automatically sets up a set of SamplerState objects in their engine and set them in the shaders by default. The shaders have a common include containing the register references for all of these so that all shaders have access to set of samplers etc automatically.

[Edit:] Though I'd give a quick update - this method works fantastically - all my shaders now have immediate access to any samplers they might need and its simplified my some parts of my engine code a lot! Works perfectly.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!