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.


Disposing of Textures with DebugNames


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
3 replies to this topic

#1 ericrrichards22   Members   -  Reputation: 811

Like
0Likes
Like

Posted 31 October 2013 - 12:56 PM

When creating ShaderResourceViews in my engine, I've started assigning them DebugName properties to assist in debugging, using the VS 2013 graphics debugger.  I've noticed that since I've started doing this, the underlying Texture objects aren't getting disposed of correctly, and SlimDX complains of memory leaks when the program closes.  The code to create a ShaderResourceView looks like this:

CubeMapSRV = ShaderResourceView.FromFile(device, filename);
CubeMapSRV.Resource.DebugName = "sky cubemap";

The code to dispose of the ShaderResourceView looks like this:

if (CubeMapSRV != null){
    CubeMapSRV.Dispose();
    CubeMapSRV = null;
}

The object creation stack trace printed by SlimDX is indicating that it is the CubeMapSRV.Resource.DebugName assignment that is leaking; specifically, the underlying Texture object.  Is assigning the DebugName creating a reference to the Texture somewhere that is hidden from me?


Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22


Sponsor:

#2 unbird   Crossbones+   -  Reputation: 5990

Like
1Likes
Like

Posted 31 October 2013 - 01:38 PM

Hmmm, one could either consider this a bug in the implementation or a wrong usage of the Resource property. Usually a D3D11 API GetWhatEver functions increases the reference counter (see remarks of ID3D11View::GetResource). This happens when reading the C# property. I don't see a Release/Dispose counterpart here, so you need to do one yourself. Should work fine when doing that immediately after setting the debug name.

Alternatives:
- Use textures explicitly and don't directly create SRVs.
- Use the debug name on the SRV, not the texture

#3 Bacterius   Crossbones+   -  Reputation: 9262

Like
1Likes
Like

Posted 31 October 2013 - 03:40 PM

I ran into the same problem a few days ago. As unbird mentions you must dispose of any device resource you acquire a reference to by calling Get* functions. One thing to remember is that Dispose() does not destroy the resource, it simply decreases the reference count and invalidates said reference, the resource itself is only destroyed when it hits zero. So in theory this should work:

using (Resource resource = CubeMapSRV.Resource)
{
    resource.DebugName = "sky cubemap";
}

In practice, I prefer to avoid messing around with reference counters and instead created a helper class which stores a resource and provides non-reference-counted access to SRV's, RTV's, UAV's, ... By the way, this problem also applies to ImmediateContext and a bunch of other stuff, and you don't need to set variables to null after disposing them. I think the underlying issue is that the C# memory management model does not quite map to how DirectX works, so you need to be a bit more careful with what you do to avoid making incorrect assumptions.


Edited by Bacterius, 31 October 2013 - 03:42 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#4 ericrrichards22   Members   -  Reputation: 811

Like
0Likes
Like

Posted 01 November 2013 - 07:11 AM

Thanks for the explanations.  I've ended up going with assigning the DebugName inside a using, as Bacterius suggested.  Disposing of the SRV's Resource property also works, but I found it a little more cumbersome.
 

you don't need to set variables to null after disposing them

 

Mainly, I am doing this in order to make sure I'm not accessing anything after it's been disposed; the bulk of my SlimDX ComObjects are bound up in my game objects, so for all intents and purposes, when I Dispose of a game object, I want it to return the game object to a completely uninitialized state.


Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22





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