Jump to content

  • Log In with Google      Sign In   
  • Create Account


[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

Like
0Likes
Like

Posted 29 December 2011 - 09:26 AM

Hi,
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");
Textures.SetResourceArray(args);

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.
Andy

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 ]


Sponsor:

#2 Starnick   Members   -  Reputation: 1165

Like
2Likes
Like

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.



PARTNERS