Jump to content
  • Advertisement
Sign in to follow this  
Foxbane

DX11 Basic HLSL texture question

This topic is 494 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

Is the slot pointed to by a Texture2D/SamplerState in a pixel shader assigned at compile time and immutable?

So on the HLSL side I'd have:

Texture2D tex0 : register(t0);

Texture2D tex1 : register(t1);

SamplerState smp0 : register(s0);

SamplerState smp1 : register(s1);

And then on the host side:

context->PSSetShaderResource( 0, 1, textureA )

context->PSSetShaderResource( 1, 1, textureB )

context->PSSetSamplers( 0, 1, samplerA );

context->PSSetSamplers( 1, 1, samplerB );

When the program is run tex0 would refer to textureA, tex1 to textureB and so on with the samplers.

What if I wanted to switch them around on the HLSL side.  So in OpenGL I could do glUniform1i( tex0, 1 ) and glUniform( tex1, 0 ).  This would make tex0 refer to textureB and tex1 refer to textureA.  Can the same be done with DX11?  If so what is the call to modify tex0/tex0 - and the smp0/smp1?

Share this post


Link to post
Share on other sites
Advertisement

The first parameter to PSSetShaderResource() and PSSetSamplers() is the start slot (if the number of resources to bind is one, the only slot) to bind to the pipeline. In your case, if you wanted tex0 to refer to textureB you would call "context->PSSetShaderResource(0, 1, textureB);".

And, to be more specific, AFAIK you can't "switch them around" on the HLSL side. When you write "Texture2D tex0 : register(t0);" you specify that "tex0" will refer to the texture register with index 0. Then, it is up to you to bind the correct SRVs to that register on the C++ side. You can then change whatever you want to bind to that register, by calling XSSetShaderResource() with different start slots.

Share this post


Link to post
Share on other sites
2 hours ago, GuyWithBeard said:

And, to be more specific, AFAIK you can't "switch them around" on the HLSL side.

And that would be the answer!  Bummer.  Thanks.

Share this post


Link to post
Share on other sites

I'm not sure if you interpreted what he was saying correctly, if you wanted to swap your textures, you can do that via the API calls:

// Your original
context->PSSetSamplers( 0, 1, samplerA );
context->PSSetSamplers( 1, 1, samplerB );
// just swap'em
context->PSSetSamplers( 0, 1, samplerB );
context->PSSetSamplers( 1, 1, samplerA );

 

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!