DebugName for SharpDX.Toolkit.Buffer

I am still learning a lot about building DirectX based applications, and I am using Visual Studio Graphics Debugger more extensively. But when your program grows to much it may get kind of hard to track all your resources. There is a nice feature of DirectX that helps you with that, it is a possibility to name your objects. Later you may find them by name in Graphics Object Table.

For example, in my SharpDX.Toolkit based solution I am creating a constant buffer and assigning it a DebugName.

constData = new GS_CONSTANT_BUF_DATA
    slideX = 0.0f,
    sinPi075 = (float)Math.Sin(Math.PI * 0.75),
    cosPi075 = (float)Math.Cos(Math.PI * 0.75),
    scaleK = 0.01f
_effect.ConstantBuffers[0].Set<GS_CONSTANT_BUF_DATA>(0, constData);
_effect.ConstantBuffers[0].IsDirty = true;    
((SharpDX.Direct3D11.Resource)_effect.ConstantBuffers[0]).DebugName = "my constant buffer";

The last line is where the magic happens. As the SharpDX.Direct3D11.Buffer object does not have a DebugName property it has to be casted to a SharpDX.Direct3D11.Resource. Then you can set its value to whatever ANSI string you want. In the Graphics Object Table it will be visible like in the screen below.


DebugName in use in Graphics Object Table

NOTE: In another piece of my code using Name property worked perfectly fine.

indexBuffer = SharpDX.Toolkit.Graphics.Buffer.Index.New(graphicsDevice, indices, resourceUsage);
indexBuffer.Name = bufferName + " Index";
DebugName in Graphics Object Table using Name property

DebugName in Graphics Object Table using Name property

Leave a Reply