2 * Copyright (c) 2007-2010 SlimDX Group
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "../ComObject.h"
26 #include "../dxgi/Adapter.h"
27 #include "../dxgi/Enums.h"
28 #include "../dxgi/SwapChainDxgi.h"
29 #include "../dxgi/SwapChainDescription.h"
30 #include "../math/Color4.h"
34 using System::Runtime::InteropServices::OutAttribute;
43 ref class DepthStencilView;
44 ref class GeometryShaderWrapper;
45 ref class InputAssemblerWrapper;
46 ref class InputLayout;
47 ref class OutputMergerWrapper;
49 ref class RasterizerWrapper;
50 ref class RenderTargetView;
52 ref class PixelShaderWrapper;
53 ref class ShaderResourceView;
54 ref class StreamOutputWrapper;
55 ref class VertexShaderWrapper;
56 value class CounterCapabilities;
57 value class CounterDescription;
58 value class CounterMetadata;
59 value class RenderTargetViewDescription;
60 value class ResourceRegion;
63 /// A virtual adapter for performing rendering.
65 /// <unmanaged>ID3D10Device</unmanaged>
66 public ref class Device : ComObject
68 COMOBJECT_CUSTOM(ID3D10Device, Device);
71 InputAssemblerWrapper^ m_InputAssembler;
72 OutputMergerWrapper^ m_OutputMerger;
73 StreamOutputWrapper^ m_StreamOutput;
74 RasterizerWrapper^ m_Rasterizer;
75 VertexShaderWrapper^ m_VertexShader;
76 PixelShaderWrapper^ m_PixelShader;
77 GeometryShaderWrapper^ m_GeometryShader;
80 //no-op ctor for use by Device1
83 void InitializeSubclasses();
87 /// The maximum number of multisample quality levels supported.
89 literal int MultisampleCountMaximum = D3D10_MAX_MULTISAMPLE_SAMPLE_COUNT;
92 /// Gets the device's input assembler interface.
94 property InputAssemblerWrapper^ InputAssembler
96 InputAssemblerWrapper^ get();
100 /// Gets the device's output merger interface.
102 property OutputMergerWrapper^ OutputMerger
104 OutputMergerWrapper^ get();
108 /// Gets the device's stream output interface.
110 property StreamOutputWrapper^ StreamOutput
112 StreamOutputWrapper^ get();
116 /// Gets the device's rasterizer interface.
118 property RasterizerWrapper^ Rasterizer
120 RasterizerWrapper^ get();
124 /// Gets the device's vertex shader interface.
126 property VertexShaderWrapper^ VertexShader
128 VertexShaderWrapper^ get();
132 /// Gets the device's pixel shader interface.
134 property PixelShaderWrapper^ PixelShader
136 PixelShaderWrapper^ get();
140 /// Gets the device's geometry shader interface.
142 property GeometryShaderWrapper^ GeometryShader
144 GeometryShaderWrapper^ get();
148 /// Gets the device's creation flags.
150 property DeviceCreationFlags CreationFlags
152 DeviceCreationFlags get();
155 property Result DeviceRemovedReason
161 /// Constructs a new Device object.
163 /// <param name="flags">Flags that indicate which device API layers to enable.</param>
164 Device( DeviceCreationFlags flags );
167 /// Constructs a new Device object.
169 /// <param name="driverType">The device driver type.</param>
170 /// <param name="flags">Flags that indicate which device API layers to enable.</param>
171 Device( DriverType driverType, DeviceCreationFlags flags );
174 /// Constructs a new Device object.
176 /// <param name="adapter">The display adapter to associate the device with when creating a hardware device.</param>
177 /// <param name="driverType">The device driver type.</param>
178 /// <param name="flags">Flags that indicate which device API layers to enable.</param>
179 Device( DXGI::Adapter^ adapter, DriverType driverType, DeviceCreationFlags flags );
182 /// Gets information about the device's performance counters.
184 /// <returns>Information about the device's performance counters.</returns>
185 CounterCapabilities GetCounterCapabilities();
188 /// Gets metadata (name, type, measurement units, et cetera) for a specific counter.
190 /// <param name="description">The description of the counter to retrieve information about.</param>
191 /// <returns>Metadata for the specified counter.</returns>
192 CounterMetadata GetCounterMetadata( CounterDescription description );
195 /// Gets information about the supported applications of a specified format.
197 /// <param name="format">The format to check support for.</param>
198 /// <returns>FormatSupport flags indicating usage contexts in which the specified format is supported.</returns>
199 FormatSupport CheckFormatSupport( DXGI::Format format );
202 /// Gets the number of quality levels supported during multisampling of resources using a specified format.
204 /// <param name="format">The format to check support for.</param>
205 /// <param name="sampleCount">The multisample count to check support for.</param>
206 /// <returns>The number of quality levels supported. 0 if an error occured
207 /// or if the format/samplecount pair is not supported.</returns>
208 int CheckMultisampleQualityLevels( DXGI::Format format, int sampleCount );
211 /// Gives the device access to a shared resource created on a different device.
213 /// <typeparam name="T">The type of the resource.</typeparam>
214 /// <param name="handle">A handle to the shared resource.</param>
215 /// <returns>The new reference to the shared resource.</returns>
216 generic<typename T> where T : ComObject
217 T OpenSharedResource(System::IntPtr handle);
220 /// Clears the specified depth-stencil resource.
222 /// <param name="view">The view of the resource to clear.</param>
223 /// <param name="flags">Flags indicating which parts of the resource to clear.</param>
224 /// <param name="depth">The depth value to clear to, if applicable.</param>
225 /// <param name="stencil">The stencil value to clear to, if applicable.</param>
226 void ClearDepthStencilView( DepthStencilView^ view, DepthStencilClearFlags flags, float depth, System::Byte stencil );
229 /// Clears the specified render target resource.
231 /// <param name="view">The view of the resource to clear.</param>
232 /// <param name="color">The color to clear to.</param>
233 void ClearRenderTargetView( RenderTargetView^ view, Color4 color );
236 /// Restores all device state to defaults.
241 /// Clears all resource bindings from the device.
243 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
244 Result ClearAllObjects();
247 /// Copies resource data using the GPU.
249 /// <param name="source">The source resource.</param>
250 /// <param name="destination">The destination resource.</param>
251 void CopyResource( Resource^ source, Resource^ destination );
254 /// Copies a portion of a resource's data using the GPU.
256 /// <param name="source">The source resource.</param>
257 /// <param name="sourceSubresource">The source subresource.</param>
258 /// <param name="region">The source region.</param>
259 /// <param name="destination">The destination resource.</param>
260 /// <param name="destinationSubresource">The destination subresource.</param>
261 /// <param name="x">The X offset between the source region origin and the destination location.</param>
262 /// <param name="y">The Y offset between the source region origin and the destination location.</param>
263 /// <param name="z">The Z offset between the source region origin and the destination location.</param>
264 void CopySubresourceRegion( Resource^ source, int sourceSubresource, ResourceRegion region, Resource^ destination, int destinationSubresource, int x, int y, int z );
267 /// Copies a multisampled resource into a non-multisampled resource.
269 /// <param name="source">The source resource.</param>
270 /// <param name="sourceSubresource">The source subresource.</param>
271 /// <param name="destination">The destination resource.</param>
272 /// <param name="destinationSubresource">The destination subresource.</param>
273 /// <param name="format">The format that indicates how the multisampled resource will be resolved.</param>
274 void ResolveSubresource( Resource^ source, int sourceSubresource, Resource^ destination, int destinationSubresource, DXGI::Format format );
277 /// Copies data from the CPU to to a non-mappable subresource region.
279 /// <param name="source">The source data.</param>
280 /// <param name="resource">The destination resource.</param>
281 /// <param name="subresource">The destination subresource.</param>
282 void UpdateSubresource( DataBox^ source, Resource^ resource, int subresource );
285 /// Copies data from the CPU to to a non-mappable subresource region.
287 /// <param name="source">The source data.</param>
288 /// <param name="resource">The destination resource.</param>
289 /// <param name="subresource">The destination subresource.</param>
290 /// <param name="region">The destination region within the resource.</param>
291 void UpdateSubresource( DataBox^ source, Resource^ resource, int subresource, ResourceRegion region );
294 /// Renders non-indexed, non-instanced primitive data.
296 /// <param name="vertexCount">The number of vertices to use.</param>
297 /// <param name="startVertexLocation">The index of the first vertex.</param>
298 void Draw( int vertexCount, int startVertexLocation );
301 /// Renders non-indexed, instanced primitive data.
303 /// <param name="vertexCountPerInstance">The number of vertices to use per index.</param>
304 /// <param name="instanceCount">The number of instances to render.</param>
305 /// <param name="startVertexLocation">The index of the first vertex.</param>
306 /// <param name="startInstanceLocation">The index of the first instance.</param>
307 void DrawInstanced( int vertexCountPerInstance, int instanceCount, int startVertexLocation, int startInstanceLocation );
310 /// Renders indexed, non-instanced primitive data.
312 /// <param name="indexCount">The number of indices to use.</param>
313 /// <param name="startIndexLocation">The index of the first index.</param>
314 /// <param name="baseVertexLocation">The index of the first vertex.</param>
315 void DrawIndexed( int indexCount, int startIndexLocation, int baseVertexLocation );
318 /// Renders indexed, instanced primitive data.
320 /// <param name="indexCountPerInstance">The number of indices to use per index.</param>
321 /// <param name="instanceCount">The number of instances to render.</param>
322 /// <param name="startIndexLocation">The index of the first index.</param>
323 /// <param name="baseVertexLocation">The index of the first vertex.</param>
324 /// <param name="startInstanceLocation">The index of the first instance.</param>
325 void DrawIndexedInstanced( int indexCountPerInstance, int instanceCount, int startIndexLocation, int baseVertexLocation, int startInstanceLocation );
328 /// Renders primitive data of an unknown size that was created by a geometry shader.
333 /// Sends queued commands in the command buffer to the GPU.
338 /// Generates mipmaps for the specified shader resource.
340 /// <param name="view">A view of the resource to generate mipmaps for.</param>
341 void GenerateMips( ShaderResourceView^ view );
343 void GetPredication( [Out] Predicate^ %predicate, [Out] bool %predicateValue );
346 /// Sets a rendering predicate.
348 /// <param name="predicate">The predicate to set.</param>
349 /// <param name="predicateValue">If true, rendering will be affected when the predicate's conditions are met. Otherwise,
350 /// rendering will be affected when the predicate's conditions are not met.</param>
351 void SetPredication( Predicate^ predicate, bool predicateValue );
354 /// Creates a new device and swap chain.
356 /// <param name="adapter">The display adapter to associate the device with when creating a hardware device.</param>
357 /// <param name="driverType">The device driver type.</param>
358 /// <param name="flags">Flags that indicate which device API layers to enable.</param>
359 /// <param name="swapChainDescription">Swap chain properties.</param>
360 /// <param name="device">The newly-created device.</param>
361 /// <param name="swapChain">The newly-created swap chain.</param>
362 /// <returns>A result code.</returns>
363 static Result CreateWithSwapChain( DXGI::Adapter^ adapter, DriverType driverType, DeviceCreationFlags flags, DXGI::SwapChainDescription swapChainDescription, [Out] Device^ %device, [Out] DXGI::SwapChain^ %swapChain );