Class GraphicsDevice
A virtual adapter that can be used for creating GPU resources (buffers, textures, states, shaders, etc), and to manipulate CommandLists.
public class GraphicsDevice : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder
- Inheritance
-
objectGraphicsDevice
- Implements
- Inherited Members
- Extension Methods
Constructors
GraphicsDevice(GraphicsAdapter, GraphicsProfile[], DeviceCreationFlags, WindowHandle)
Initializes a new instance of the GraphicsDevice class.
protected GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile[] graphicsProfiles, DeviceCreationFlags creationFlags, WindowHandle windowHandle)
Parameters
adapterGraphicsAdapterThe physical Graphics Adapter for which to create a Graphics Device.
graphicsProfilesGraphicsProfile[]A list of the graphics profiles to try, in order of preference. This parameter cannot be null, but if an empty array is passed, the default fallback profiles will be used.
The default fallback profiles are: Level_11_0, Level_10_1, Level_10_0, Level_9_3, Level_9_2, and Level_9_1.
creationFlagsDeviceCreationFlagsA combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.
windowHandleWindowHandleThe WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.
Exceptions
- ArgumentNullException
adapteris null.- ArgumentNullException
graphicsProfilesis null.
Fields
FrameDrawCalls
The number of draw calls made in the last frame.
public uint FrameDrawCalls
Field Value
FrameTriangleCount
The number of triangles drawn in the last frame.
public uint FrameTriangleCount
Field Value
Properties
Adapter
Gets the physical Graphics Adapter the Graphics Device is attached to.
public GraphicsAdapter Adapter { get; }
Property Value
BuffersMemory
Gets the amount of GPU memory currently allocated to Buffers, in bytes.
public long BuffersMemory { get; }
Property Value
ColorSpace
Gets or sets the default color space of the Graphics Device.
public ColorSpace ColorSpace { get; set; }
Property Value
Features
Gets the features supported by the Graphics Device.
public ref readonly GraphicsDeviceFeatures Features { get; }
Property Value
GraphicsDeviceStatus
Gets the current status of the Graphics Device.
public GraphicsDeviceStatus GraphicsDeviceStatus { get; }
Property Value
IsDebugMode
Gets a value indicating whether the Graphics Device is in "Debug mode".
public bool IsDebugMode { get; }
Property Value
IsDeferred
Gets a value indicating wether the Graphics Device allows for concurrent building and deferred submission of CommandLists.
public bool IsDeferred { get; }
Property Value
IsProfilingSupported
Gets a value indicating whether the Graphics Device supports GPU markers and profiling.
public bool IsProfilingSupported { get; }
Property Value
NativeDevice
Gets the internal Direct3D 11 Device.
public ComPtr<ID3D11Device> NativeDevice { get; }
Property Value
- ComPtr<ID3D11Device>
Remarks
If the reference is going to be kept, use ComPtr<T>.AddRef() to increment the internal reference count, and Silk.NET.Core.Native.ComPtr<T>.Dispose() when no longer needed to release the object.
Platform
Gets the graphics platform (and the graphics API) the Graphics Device is using.
public static GraphicsPlatform Platform { get; }
Property Value
Presenter
Gets or sets the current presenter used to display frames with the Graphics Device.
public virtual GraphicsPresenter Presenter { get; set; }
Property Value
RendererName
Gets a string that identifies the underlying device used by the Graphics Device to render.
public string RendererName { get; }
Property Value
Remarks
In the case of Direct3D and Vulkan, for example, this will return the name of the Graphics Adapter
(e.g. "nVIDIA GeForce RTX 2080"). Other platforms may return a different string.
SamplerStates
Gets the factory that can be used to retrieve commonly used Sampler States.
public SamplerStateFactory SamplerStates { get; }
Property Value
TextureMemory
Gets the amount of GPU memory currently allocated to Textures, in bytes.
public long TextureMemory { get; }
Property Value
TimestampFrequency
Gets the tick frquency of timestamp queries, in hertz.
public long TimestampFrequency { get; }
Property Value
Methods
Begin()
Marks the Graphics Device Context as active on the current thread.
public void Begin()
Destroy()
Disposes the object's resources.
protected override void Destroy()
Remarks
Override in a derived class to implement disposal logic specific to it.
This method is automatically called whenever a call to Dispose() (or to Release()) has decreased the internal reference count to zero, meaning no other objects (hopefully) hold a reference to this one and its resources can be safely released.
DestroyPlatformDevice()
Releases the platform-specific Graphics Device and all its associated resources.
protected void DestroyPlatformDevice()
EnableProfile(bool)
Enables or disables profiling.
public void EnableProfile(bool enabledFlag)
Parameters
End()
Marks the Graphics Device Context as inactive on the current thread.
public void End()
ExecuteCommandList(CompiledCommandList)
Executes a Compiled Command List.
public void ExecuteCommandList(CompiledCommandList commandList)
Parameters
commandListCompiledCommandListThe Compiled Command List to execute.
Remarks
A Compiled Command List is a list of commands that have been recorded for execution on the Graphics Device at a later time. This method executes the commands in the list. This is known as deferred execution.
Exceptions
- NotImplementedException
Deferred CommandList execution is not implemented for Direct3D 11.
ExecuteCommandLists(int, CompiledCommandList[])
Executes multiple Compiled Command Lists.
public void ExecuteCommandLists(int count, CompiledCommandList[] commandLists)
Parameters
countintThe number of Compiled Command Lists to execute.
commandListsCompiledCommandList[]The Compiled Command Lists to execute.
Remarks
A Compiled Command List is a list of commands that have been recorded for execution on the Graphics Device at a later time. This method executes the commands in the list. This is known as deferred execution.
Exceptions
- NotImplementedException
Deferred CommandList execution is not implemented for Direct3D 11.
GetOrCreateSharedData<T>(object, CreateSharedData<T>)
Gets a shared data object for the Graphics Device context with a delegate to create the shared data if it is not present.
public T GetOrCreateSharedData<T>(object key, GraphicsDevice.CreateSharedData<T> sharedDataCreator) where T : class, IDisposable
Parameters
keyobjectThe key that identifies the shared data.
sharedDataCreatorGraphicsDevice.CreateSharedData<T>A delegate that will be called to create the shared data.
Returns
- T
An instance of the shared data. It will be disposed by this GraphicsDevice instance.
Type Parameters
TType of the shared data to get or create.
New(DeviceCreationFlags, params GraphicsProfile[])
Creates a new GraphicsDevice.
public static GraphicsDevice New(DeviceCreationFlags creationFlags = DeviceCreationFlags.None, params GraphicsProfile[] graphicsProfiles)
Parameters
creationFlagsDeviceCreationFlagsA combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.
graphicsProfilesGraphicsProfile[]A list of the graphics profiles to try, in order of preference. This parameter cannot be null, but if an empty array is passed, the default fallback profiles will be used.
The default fallback profiles are: Level_11_0, Level_10_1, Level_10_0, Level_9_3, Level_9_2, and Level_9_1.
Returns
- GraphicsDevice
The new instance of GraphicsDevice.
Exceptions
- ArgumentNullException
graphicsProfilesis null.
New(GraphicsAdapter, DeviceCreationFlags, params GraphicsProfile[])
Creates a new GraphicsDevice.
public static GraphicsDevice New(GraphicsAdapter adapter, DeviceCreationFlags creationFlags = DeviceCreationFlags.None, params GraphicsProfile[] graphicsProfiles)
Parameters
adapterGraphicsAdapterThe Graphics Adapter the new device will use, or null to use the system's default adapter.
creationFlagsDeviceCreationFlagsA combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.
graphicsProfilesGraphicsProfile[]A list of the graphics profiles to try, in order of preference. This parameter cannot be null, but if an empty array is passed, the default fallback profiles will be used.
The default fallback profiles are: Level_11_0, Level_10_1, Level_10_0, Level_9_3, Level_9_2, and Level_9_1.
Returns
- GraphicsDevice
The new instance of GraphicsDevice.
Exceptions
- ArgumentNullException
adapteris null.- ArgumentNullException
graphicsProfilesis null.
New(GraphicsAdapter, DeviceCreationFlags, WindowHandle, params GraphicsProfile[])
Creates a new GraphicsDevice.
public static GraphicsDevice New(GraphicsAdapter adapter, DeviceCreationFlags creationFlags = DeviceCreationFlags.None, WindowHandle windowHandle = null, params GraphicsProfile[] graphicsProfiles)
Parameters
adapterGraphicsAdapterThe Graphics Adapter the new device will use, or null to use the system's default adapter.
creationFlagsDeviceCreationFlagsA combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.
windowHandleWindowHandleThe WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.
graphicsProfilesGraphicsProfile[]A list of the graphics profiles to try, in order of preference. This parameter cannot be null, but if an empty array is passed, the default fallback profiles will be used.
The default fallback profiles are: Level_11_0, Level_10_1, Level_10_0, Level_9_3, Level_9_2, and Level_9_1.
Returns
- GraphicsDevice
The new instance of GraphicsDevice.
Exceptions
- ArgumentNullException
adapteris null.- ArgumentNullException
graphicsProfilesis null.
Recreate(GraphicsAdapter, GraphicsProfile[], DeviceCreationFlags, WindowHandle)
Tries to create or reinitialize the Graphics Device.
public void Recreate(GraphicsAdapter adapter, GraphicsProfile[] graphicsProfiles, DeviceCreationFlags creationFlags, WindowHandle windowHandle)
Parameters
adapterGraphicsAdapterThe physical Graphics Adapter for which to recreate the Graphics Device.
graphicsProfilesGraphicsProfile[]A list of the graphics profiles to try, in order of preference. This parameter cannot be null, but if an empty array is passed, the default fallback profiles will be used.
The default fallback profiles are: Level_11_0, Level_10_1, Level_10_0, Level_9_3, Level_9_2, and Level_9_1.
creationFlagsDeviceCreationFlagsA combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.
windowHandleWindowHandleThe WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.
Exceptions
- ArgumentNullException
adapteris null.- ArgumentNullException
graphicsProfilesis null.
SimulateReset()
Sets the Graphics Device to simulate a situation in which the device is lost and then reset.
public void SimulateReset()
Events
DeviceInfoQueueMessage
Occurs when a message is received in the Graphics Device information queue.
public event GraphicsDevice.GraphicsDeviceInfoMessageHandler? DeviceInfoQueueMessage
Event Type
Remarks
This event is triggered when the Direct3D 11 InfoQueue receives a message. This only happens if the Graphics Device was created with the Debug flag.
Subscribe to this event to handle messages related to Graphics Device information. The event handler receives an argument of type Silk.NET.Direct3D11.Message, which contains the message data.
Disposing
Occurs while this component is disposing but before it is disposed.
public event EventHandler<EventArgs> Disposing