Binding shader resources

Started by
1 comment, last by iskatsu 11 years ago

Hello everyone.

Recently I have been lurking in DirectX 11 documentation and found interesting thing: PSSetShaderResources function keeps textures bound to graphics pipeline. So I have made up a common header for every shader program which looks like this:


// Defines:
// Object color type
#define OBJECT_COLOR_TYPE_COLORED 0
#define OBJECT_COLOR_TYPE_TEXTURED 1
#define USE_NORMAL_MAP 1
#define USE_SHADOW_MAP 1
#define USE_DIFFUSE_MAP 1
#define USE_AMBIENT_MAP 1
#define USE_LIGHT_MAP 1
// Textures:
Texture2D NormalMap : register(t0);
Texture2D ShadowMap : register(t1);
Texture2D DiffuseMap : register(t2);
Texture2D AmbientMap : register(t3);
Texture2D LightMap : register(t4);
// Sampler states:
SamplerState LinearSampler : register(s0);
 

Now, I'm trying to update textures per primitive draw call. In example, if the object uses different from previous drawn primitive diffuse color map, I call PSSetShaderResources(2, 1 , resources). Where `resources` is an array, containing single element - shader resource view for new diffuse map texture. But when I have implemented this in my engine, it doesn't render texture maps anymore. All of my shader programs are including this common file.
So I'm curious, does DX11 really keep those textures bound to pipeline until I free them? Or do their shader representations actually become undefined if I call PSSetShader() or change render target?
Advertisement

Any resources stay bound to the context until you overwrite them, or call ClearState. If I were you, I would use the VS 2012 graphics debugger (or PIX, or Nsight, or AMD GPU PerfStudio) to capture a frame so that you can when and where the textures are getting bound and unbound. This should let you track down where your bug is.

Any resources stay bound to the context until you overwrite them, or call ClearState. If I were you, I would use the VS 2012 graphics debugger (or PIX, or Nsight, or AMD GPU PerfStudio) to capture a frame so that you can when and where the textures are getting bound and unbound. This should let you track down where your bug is.

Thank you for response.

I don't know why, but my VS2012 graphics debugger has very strange behavior - it doesn't debug shader code (may be because I compile them from .fx files at runtime, not from .hlsl by means of fxc.exe?), unable to capture screen when I re-size my window. In my current situation VS2012GD just captures black screens (but my application window actually shows something, it's not completely black) and does not allow me to target those captured black screenshots to look at their statistics gathered... Is it only me, or VS2012 graphics debugger is very, well, bugged? Also, how can I use PIX with Windows 8 SDK DX11 code? I tried, but unfortunately couldn't setup it.

This topic is closed to new replies.

Advertisement