Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

[SlimDX] EffectInterface, clear shader resource array - how?

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

I've got problem clearing shader resource array using effect interface.

HLSL Code:

Texture2D Textures[3];

I'm using SlimDX, DirectX11. To access shader I'm using effect interface.
Setting variable is OK, I just call:

EffectResourceVariable Textures = Effect.GetVariableByName("Textures");

But I can't clear the variable (I need it, because Texture is used also as render target, so it can't be bound to shader when rendering into it)
I've tried:

Textures.SetResourceArray(new ShaderResourceView[] { null, null, null}, 0, 3); // throws NullReferenceException
Textures.SetResourceArray(new ShaderResourceView[] { null, null, null}); // throws NullReferenceException
Textures.SetResourceArray(null); // throws NullReferenceException
Textures.SetResource(null); // clears only first texture (see PIX)

Only functional way is:

Device.ImmediateContext.PixelShader.SetShaderResources(new ShaderResourceView[] { null, null, null }, 0 /* slot id */, 3 /* count */);

but it's unsatisfactory, I don't want to use this interface and I can't be sure if variable is in slot 0 or not.

When binding resource as Render target, and resource is also bind as shader resource, DX won't crash, but it's shown in PIX as warning, I want to get rid of this warnings. Also wan't to do things in DX right.

If it's not possible, is there some quick workaround (for example clearing all PS resource slots?)

Thank you.

PIX Warnings:

Message Render D3D11: WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 1 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]
Message Render D3D11: WARNING: ID3D11DeviceContext::OMSetRenderTargets[AndUnorderedAccessViews]: Forcing PS shader resource slot 1 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD ]

Share this post

Link to post
Share on other sites
Looking at the source (line 79 and 89) its understandable why NullReference is being thrown in the SetResourceArray (array can't be null, and it doesn't check if the element is null, unlike the source for the PixelShaderWrapper). So it looks like an issue that probably should be on the SlimDX issue tracker.

You may not have to unbind all resources - you could always ensure your texture array occupies the first n slots, and query the EffectType on the resource variable (GetVariableType), and use the EffectTypeDescription.Elements value as the count. This is bit of a guess though.

Edit: Another (harder) way of doing it of course is by using ShaderReflection, not only to inspect the # of elements, but also to get the bind point of the resources. :)

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!