ECToo / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

DirectX11: Cannot unset shader resource array using SetResourceArray on EffectVariable #855

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using version: release September 2011

HLSL Code:
Texture2D Textures[3];

C# Code:
EffectResourceVariable Textures = Effect.GetVariableByName("Textures");
Textures.SetResourceArray(args); // No problem here

...

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)

Discussion here: 
http://www.gamedev.net/topic/617672-slimdx-effectinterface-clear-shader-resource
-array-how/

This is source:
Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ 
views, int offset, int count )
{
    Utilities::CheckArrayBounds(views, offset, count);

    stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
    for (int i = 0; i < count; i++)
        nativeViews[i] = views[i + offset]->InternalPointer;

    HRESULT hr = m_Pointer->SetResourceArray(&nativeViews[0], 0, count);
    return RECORD_D3D11(hr);
}

Something like this could possibly fix the problem (checking view and setting 
value to NULL should do the trick):
Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ 
views, int offset, int count )
{
    Utilities::CheckArrayBounds(views, offset, count);

    stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
    for (int i = 0; i < count; i++)
        nativeViews[i] = views[i + offset] != null ? views[i + offset]->InternalPointer : 0;

    HRESULT hr = m_Pointer->SetResourceArray(&nativeViews[0], 0, count);
    return RECORD_D3D11(hr);
}

Original issue reported on code.google.com by Pik...@gmail.com on 29 Dec 2011 at 10:11

GoogleCodeExporter commented 9 years ago
Of course "nullptr" instead of "null" (we're in C++/CLI)

Original comment by Pik...@gmail.com on 29 Dec 2011 at 10:12

GoogleCodeExporter commented 9 years ago

Original comment by Mike.Popoloski on 30 Dec 2011 at 3:40

GoogleCodeExporter commented 9 years ago
Milestone.

Original comment by Mike.Popoloski on 30 Dec 2011 at 3:47

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r2160.

Original comment by Mike.Popoloski on 1 Jan 2012 at 6:03