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 ]