Table of Contents

Class GraphicsDevice

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

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
object
GraphicsDevice
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

adapter GraphicsAdapter

The physical Graphics Adapter for which to create a Graphics Device.

graphicsProfiles GraphicsProfile[]

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.

creationFlags DeviceCreationFlags

A combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.

windowHandle WindowHandle

The WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.

Exceptions

ArgumentNullException

adapter is null.

ArgumentNullException

graphicsProfiles is null.

Fields

FrameDrawCalls

The number of draw calls made in the last frame.

public uint FrameDrawCalls

Field Value

uint

FrameTriangleCount

The number of triangles drawn in the last frame.

public uint FrameTriangleCount

Field Value

uint

Properties

Adapter

Gets the physical Graphics Adapter the Graphics Device is attached to.

public GraphicsAdapter Adapter { get; }

Property Value

GraphicsAdapter

BuffersMemory

Gets the amount of GPU memory currently allocated to Buffers, in bytes.

public long BuffersMemory { get; }

Property Value

long

ColorSpace

Gets or sets the default color space of the Graphics Device.

public ColorSpace ColorSpace { get; set; }

Property Value

ColorSpace

Features

Gets the features supported by the Graphics Device.

public ref readonly GraphicsDeviceFeatures Features { get; }

Property Value

GraphicsDeviceFeatures

GraphicsDeviceStatus

Gets the current status of the Graphics Device.

public GraphicsDeviceStatus GraphicsDeviceStatus { get; }

Property Value

GraphicsDeviceStatus

IsDebugMode

Gets a value indicating whether the Graphics Device is in "Debug mode".

public bool IsDebugMode { get; }

Property Value

bool

true if the Graphics Device is initialized in "Debug mode"; otherwise, false.

IsDeferred

Gets a value indicating wether the Graphics Device allows for concurrent building and deferred submission of CommandLists.

public bool IsDeferred { get; }

Property Value

bool

true if the Graphics Device allows deferred execution; otherwise, false.

IsProfilingSupported

Gets a value indicating whether the Graphics Device supports GPU markers and profiling.

public bool IsProfilingSupported { get; }

Property Value

bool

true if the Graphics Device allows profiling and creating GPU markers; otherwise, false.

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

GraphicsPlatform

Presenter

Gets or sets the current presenter used to display frames with the Graphics Device.

public virtual GraphicsPresenter Presenter { get; set; }

Property Value

GraphicsPresenter

RendererName

Gets a string that identifies the underlying device used by the Graphics Device to render.

public string RendererName { get; }

Property Value

string

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

SamplerStateFactory

TextureMemory

Gets the amount of GPU memory currently allocated to Textures, in bytes.

public long TextureMemory { get; }

Property Value

long

TimestampFrequency

Gets the tick frquency of timestamp queries, in hertz.

public long TimestampFrequency { get; }

Property Value

long

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

enabledFlag bool

true to enable profiling; false to disable it.

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

commandList CompiledCommandList

The 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

count int

The number of Compiled Command Lists to execute.

commandLists CompiledCommandList[]

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

key object

The key that identifies the shared data.

sharedDataCreator GraphicsDevice.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

T

Type 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

creationFlags DeviceCreationFlags

A combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.

graphicsProfiles GraphicsProfile[]

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

graphicsProfiles is null.

New(GraphicsAdapter, DeviceCreationFlags, params GraphicsProfile[])

Creates a new GraphicsDevice.

public static GraphicsDevice New(GraphicsAdapter adapter, DeviceCreationFlags creationFlags = DeviceCreationFlags.None, params GraphicsProfile[] graphicsProfiles)

Parameters

adapter GraphicsAdapter

The Graphics Adapter the new device will use, or null to use the system's default adapter.

creationFlags DeviceCreationFlags

A combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.

graphicsProfiles GraphicsProfile[]

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

adapter is null.

ArgumentNullException

graphicsProfiles is 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

adapter GraphicsAdapter

The Graphics Adapter the new device will use, or null to use the system's default adapter.

creationFlags DeviceCreationFlags

A combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.

windowHandle WindowHandle

The WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.

graphicsProfiles GraphicsProfile[]

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

adapter is null.

ArgumentNullException

graphicsProfiles is 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

adapter GraphicsAdapter

The physical Graphics Adapter for which to recreate the Graphics Device.

graphicsProfiles GraphicsProfile[]

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.

creationFlags DeviceCreationFlags

A combination of DeviceCreationFlags flags that determines how the Graphics Device will be created.

windowHandle WindowHandle

The WindowHandle specifying the window the Graphics Device will present to, or null if the device should not depend on a window.

Exceptions

ArgumentNullException

adapter is null.

ArgumentNullException

graphicsProfiles is 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

GraphicsDevice.GraphicsDeviceInfoMessageHandler

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

Event Type

EventHandler<EventArgs>