Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 pikacc   Members   -  Reputation: 109


Posted 29 December 2011 - 09:26 AM

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 ]


#2 Starnick   Members   -  Reputation: 1231


Posted 29 December 2011 - 03:00 PM

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. :)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.