3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
6 using SharpDX.Direct3D11;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Mathematics;
10 using SiliconStudio.Paradox.Shaders;
12 namespace SiliconStudio.
Paradox.Graphics
14 public partial class GraphicsDevice
16 private bool simulateReset =
false;
17 private const int ConstantBufferCount = SharpDX.Direct3D11.CommonShaderStage.ConstantBufferApiSlotCount;
18 private const int SamplerStateCount = SharpDX.Direct3D11.CommonShaderStage.SamplerSlotCount;
19 private const int ShaderResourceViewCount = SharpDX.Direct3D11.CommonShaderStage.InputResourceSlotCount;
20 private const int SimultaneousRenderTargetCount = SharpDX.Direct3D11.OutputMergerStage.SimultaneousRenderTargetCount;
21 private const int StageCount = 6;
22 private const int UnorderedAcccesViewCount = SharpDX.Direct3D11.ComputeShaderStage.UnorderedAccessViewSlotCount;
24 private readonly
Buffer[] constantBuffers =
new Buffer[StageCount*ConstantBufferCount];
25 private readonly SharpDX.Direct3D11.RenderTargetView[] currentRenderTargetViews =
new SharpDX.Direct3D11.RenderTargetView[SimultaneousRenderTargetCount];
26 private readonly SamplerState[] samplerStates =
new SamplerState[StageCount*SamplerStateCount];
27 private readonly SharpDX.Direct3D11.CommonShaderStage[] shaderStages =
new SharpDX.Direct3D11.CommonShaderStage[StageCount];
28 private readonly GraphicsResourceBase[] unorderedAccessViews =
new GraphicsResourceBase[UnorderedAcccesViewCount];
30 private SharpDX.Direct3D11.Device nativeDevice;
31 private SharpDX.Direct3D11.DeviceContext nativeDeviceContext;
32 private SharpDX.Direct3D11.InputAssemblerStage inputAssembler;
33 private SharpDX.Direct3D11.OutputMergerStage outputMerger;
35 private int actualRenderTargetViewCount;
36 private SharpDX.Direct3D11.DeviceCreationFlags creationFlags;
37 private EffectInputSignature currentEffectInputSignature;
38 private SharpDX.Direct3D11.InputLayout currentInputLayout;
39 private SharpDX.Direct3D11.RenderTargetView currentRenderTargetView;
40 private VertexArrayLayout currentVertexArrayLayout;
41 private SharpDX.ViewportF[] currentNativeViewports =
new SharpDX.ViewportF[16];
42 private Viewport[] currentViewports;
49 private GraphicsDevice(GraphicsDevice device)
52 Adapter = device.Adapter;
53 creationFlags = device.creationFlags;
54 Features = device.Features;
55 sharedDataPerDevice = device.sharedDataPerDevice;
56 InputLayoutManager = device.InputLayoutManager;
57 nativeDevice = device.NativeDevice;
58 nativeDeviceContext =
new SharpDX.Direct3D11.DeviceContext(NativeDevice).DisposeBy(
this);
60 IsDebugMode = device.IsDebugMode;
63 GraphicsResourceBase.SetDebugName(device, nativeDeviceContext,
"DeferredContext");
65 NeedWorkAroundForUpdateSubResource = !Features.HasDriverCommandLists;
67 primitiveQuad =
new PrimitiveQuad(
this).DisposeBy(
this);
72 private void SetDefaultStates()
88 simulateReset =
false;
89 return GraphicsDeviceStatus.Reset;
92 var result = NativeDevice.DeviceRemovedReason;
93 if (result == SharpDX.DXGI.ResultCode.DeviceRemoved)
95 return GraphicsDeviceStatus.Removed;
98 if (result == SharpDX.DXGI.ResultCode.DeviceReset)
100 return GraphicsDeviceStatus.Reset;
103 if (result == SharpDX.DXGI.ResultCode.DeviceHung)
105 return GraphicsDeviceStatus.Hung;
108 if (result == SharpDX.DXGI.ResultCode.DriverInternalError)
110 return GraphicsDeviceStatus.InternalError;
113 if (result == SharpDX.DXGI.ResultCode.InvalidCall)
115 return GraphicsDeviceStatus.InvalidCall;
120 return GraphicsDeviceStatus.Reset;
123 return GraphicsDeviceStatus.Normal;
131 public Viewport Viewport
135 return currentViewports[0];
143 internal InputLayoutManager InputLayoutManager {
get;
private set; }
149 internal SharpDX.Direct3D11.Device NativeDevice
161 internal SharpDX.Direct3D11.DeviceContext NativeDeviceContext
165 return nativeDeviceContext;
177 inputAssembler.PrimitiveTopology = (SharpDX.Direct3D.PrimitiveTopology)value;
181 public void ApplyPlatformSpecificParams(Effect effect)
197 public void BeginProfile(Color4 profileColor,
string name)
199 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
200 SharpDX.Direct3D.PixHelper.BeginEvent(
new SharpDX.ColorBGRA(profileColor.ToBgra()), name);
214 if (depthStencilBuffer == null)
throw new ArgumentNullException(
"depthStencilBuffer");
216 var
flags = ((options & DepthStencilClearOptions.DepthBuffer) != 0) ? SharpDX.Direct3D11.DepthStencilClearFlags.Depth : 0;
221 if (!depthStencilBuffer.HasStencil)
222 throw new InvalidOperationException(
string.Format(FrameworkResources.NoStencilBufferForDepthFormat, depthStencilBuffer.Description.Format));
223 flags |= SharpDX.Direct3D11.DepthStencilClearFlags.Stencil;
226 NativeDeviceContext.ClearDepthStencilView(depthStencilBuffer.NativeDepthStencilView,
flags, depth, stencil);
235 public unsafe
void Clear(RenderTarget renderTarget, Color4 color)
237 if (renderTarget == null)
throw new ArgumentNullException(
"renderTarget");
239 NativeDeviceContext.ClearRenderTargetView(renderTarget.NativeRenderTargetView, *(SharpDX.Color4*)&color);
249 public unsafe
void ClearReadWrite(
Buffer buffer, Vector4 value)
251 if (buffer == null)
throw new ArgumentNullException(
"buffer");
252 if (buffer.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"buffer");
254 NativeDeviceContext.ClearUnorderedAccessView(buffer.NativeUnorderedAccessView, *(SharpDX.Vector4*)&value);
264 public unsafe
void ClearReadWrite(
Buffer buffer, Int4 value)
266 if (buffer == null)
throw new ArgumentNullException(
"buffer");
267 if (buffer.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"buffer");
269 NativeDeviceContext.ClearUnorderedAccessView(buffer.NativeUnorderedAccessView, *(SharpDX.Int4*)&value);
279 public unsafe
void ClearReadWrite(
Buffer buffer, UInt4 value)
281 if (buffer == null)
throw new ArgumentNullException(
"buffer");
282 if (buffer.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"buffer");
284 NativeDeviceContext.ClearUnorderedAccessView(buffer.NativeUnorderedAccessView, *(SharpDX.Int4*)&value);
294 public unsafe
void ClearReadWrite(Texture texture, Vector4 value)
296 if (texture == null)
throw new ArgumentNullException(
"texture");
297 if (texture.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"texture");
299 NativeDeviceContext.ClearUnorderedAccessView(texture.NativeUnorderedAccessView, *(SharpDX.Vector4*)&value);
309 public unsafe
void ClearReadWrite(Texture texture, Int4 value)
311 if (texture == null)
throw new ArgumentNullException(
"texture");
312 if (texture.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"texture");
314 NativeDeviceContext.ClearUnorderedAccessView(texture.NativeUnorderedAccessView, *(SharpDX.Int4*)&value);
324 public unsafe
void ClearReadWrite(Texture texture, UInt4 value)
326 if (texture == null)
throw new ArgumentNullException(
"texture");
327 if (texture.NativeUnorderedAccessView == null)
throw new ArgumentException(
"Expecting buffer supporting UAV",
"texture");
329 NativeDeviceContext.ClearUnorderedAccessView(texture.NativeUnorderedAccessView, *(SharpDX.Int4*)&value);
332 public void ClearState()
334 NativeDeviceContext.ClearState();
335 for (
int i = 0; i < currentViewports.Length; i++)
336 currentViewports[i] =
new Viewport();
338 for (
int i = 0; i < samplerStates.Length; ++i)
339 samplerStates[i] = null;
340 for (
int i = 0; i < constantBuffers.Length; ++i)
341 constantBuffers[i] = null;
342 for (
int i = 0; i < unorderedAccessViews.Length; ++i)
343 unorderedAccessViews[i] = null;
344 for (
int i = 0; i < currentRenderTargetViews.Length; i++)
345 currentRenderTargetViews[i] = null;
347 currentEffectInputSignature = null;
348 currentVertexArrayLayout = null;
349 currentInputLayout = null;
350 CurrentEffect = null;
352 SetRenderTarget(DepthStencilBuffer, BackBuffer);
355 public void Copy(GraphicsResource source, GraphicsResource destination)
357 if (source == null)
throw new ArgumentNullException(
"source");
358 if (destination == null)
throw new ArgumentNullException(
"destination");
359 NativeDeviceContext.CopyResource(source.NativeResource, destination.NativeResource);
362 public void CopyRegion(GraphicsResource source,
int sourceSubresource, ResourceRegion? sourecRegion, GraphicsResource destination,
int destinationSubResource,
int dstX = 0,
int dstY = 0,
int dstZ = 0)
364 if (source == null)
throw new ArgumentNullException(
"source");
365 if (destination == null)
throw new ArgumentNullException(
"destination");
367 var nullableSharpDxRegion =
new SharpDX.Direct3D11.ResourceRegion?();
369 if (sourecRegion.HasValue)
371 var value = sourecRegion.Value;
372 nullableSharpDxRegion =
new SharpDX.Direct3D11.ResourceRegion(value.Left, value.Top, value.Front, value.Right, value.Bottom, value.Back);
375 NativeDeviceContext.CopySubresourceRegion(source.NativeResource, sourceSubresource, nullableSharpDxRegion, destination.NativeResource, destinationSubResource, dstX, dstY, dstZ);
379 public void CopyCount(
Buffer sourceBuffer,
Buffer destBuffer,
int offsetInBytes)
381 if (sourceBuffer == null)
throw new ArgumentNullException(
"sourceBuffer");
382 if (destBuffer == null)
throw new ArgumentNullException(
"destBuffer");
383 NativeDeviceContext.CopyStructureCount(destBuffer.NativeBuffer, offsetInBytes, sourceBuffer.NativeUnorderedAccessView);
387 public void Dispatch(
int threadCountX,
int threadCountY,
int threadCountZ)
389 NativeDeviceContext.Dispatch(threadCountX, threadCountY, threadCountZ);
397 public void Dispatch(
Buffer indirectBuffer,
int offsetInBytes)
399 if (indirectBuffer == null)
throw new ArgumentNullException(
"indirectBuffer");
400 NativeDeviceContext.DispatchIndirect(indirectBuffer.NativeBuffer, offsetInBytes);
409 public void Draw(
PrimitiveType primitiveType,
int vertexCount,
int startVertexLocation = 0)
411 PrepareDraw(primitiveType);
413 NativeDeviceContext.Draw(vertexCount, startVertexLocation);
422 PrepareDraw(primitiveType);
424 NativeDeviceContext.DrawAuto();
434 public void DrawIndexed(
PrimitiveType primitiveType,
int indexCount,
int startIndexLocation = 0,
int baseVertexLocation = 0)
436 PrepareDraw(primitiveType);
438 NativeDeviceContext.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation);
450 public void DrawIndexedInstanced(
PrimitiveType primitiveType,
int indexCountPerInstance,
int instanceCount,
int startIndexLocation = 0,
int baseVertexLocation = 0,
int startInstanceLocation = 0)
452 PrepareDraw(primitiveType);
454 NativeDeviceContext.DrawIndexedInstanced(indexCountPerInstance, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation);
463 public void DrawIndexedInstanced(
PrimitiveType primitiveType,
Buffer argumentsBuffer,
int alignedByteOffsetForArgs = 0)
465 if (argumentsBuffer == null)
throw new ArgumentNullException(
"argumentsBuffer");
467 PrepareDraw(primitiveType);
469 NativeDeviceContext.DrawIndexedInstancedIndirect(argumentsBuffer.NativeBuffer, alignedByteOffsetForArgs);
480 public void DrawInstanced(
PrimitiveType primitiveType,
int vertexCountPerInstance,
int instanceCount,
int startVertexLocation = 0,
int startInstanceLocation = 0)
482 PrepareDraw(primitiveType);
484 NativeDeviceContext.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation);
493 public void DrawInstanced(
PrimitiveType primitiveType,
Buffer argumentsBuffer,
int alignedByteOffsetForArgs = 0)
495 if (argumentsBuffer == null)
throw new ArgumentNullException(
"argumentsBuffer");
497 PrepareDraw(primitiveType);
499 NativeDeviceContext.DrawIndexedInstancedIndirect(argumentsBuffer.NativeBuffer, alignedByteOffsetForArgs);
506 public void EnableProfile(
bool enabledFlag)
508 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
509 SharpDX.Direct3D.PixHelper.AllowProfiling(enabledFlag);
523 public void EndProfile()
525 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
526 SharpDX.Direct3D.PixHelper.EndEvent();
534 public void ExecuteCommandList(ICommandList commandList)
536 if (commandList == null)
throw new ArgumentNullException(
"commandList");
538 NativeDeviceContext.ExecuteCommandList(((CommandList)commandList).NativeCommandList,
false);
539 commandList.Release();
546 public ICommandList FinishCommandList()
548 return new CommandList(NativeDeviceContext.FinishCommandList(
false));
561 public unsafe MappedResource MapSubresource(GraphicsResource resource,
int subResourceIndex,
MapMode mapMode,
bool doNotWait =
false,
int offsetInBytes = 0,
int lengthInBytes = 0)
563 if (resource == null)
throw new ArgumentNullException(
"resource");
564 SharpDX.DataBox dataBox = NativeDeviceContext.MapSubresource(resource.NativeResource, subResourceIndex, (
SharpDX.Direct3D11.MapMode)mapMode, doNotWait ? SharpDX.Direct3D11.MapFlags.DoNotWait : SharpDX.Direct3D11.MapFlags.None);
565 var databox = *(DataBox*)Interop.Cast(ref dataBox);
566 if (!dataBox.IsEmpty)
568 databox.DataPointer = (IntPtr)((byte*)databox.DataPointer + offsetInBytes);
570 return new MappedResource(resource, subResourceIndex, databox);
577 public GraphicsDevice NewDeferred()
579 return new GraphicsDevice(RootDevice);
585 public void ResetTargets()
587 for (
int i = 0; i < currentRenderTargetViews.Length; i++)
588 currentRenderTargetViews[i] = null;
589 actualRenderTargetViewCount = 0;
590 currentRenderTargetView = null;
591 outputMerger.ResetTargets();
598 public void SetBlendState(BlendState blendState)
600 if (blendState == null)
602 NativeDeviceContext.OutputMerger.SetBlendState(null, SharpDX.Color.White, -1);
606 NativeDeviceContext.OutputMerger.SetBlendState((SharpDX.Direct3D11.BlendState)blendState.NativeDeviceChild, ColorHelper.Convert(blendState.BlendFactor), blendState.MultiSampleMask);
616 public void SetBlendState(BlendState blendState, Color4 blendFactor,
int multiSampleMask = -1)
618 if (blendState == null)
620 NativeDeviceContext.OutputMerger.SetBlendState(null, ColorHelper.Convert(blendFactor), multiSampleMask);
624 NativeDeviceContext.OutputMerger.SetBlendState((SharpDX.Direct3D11.BlendState)blendState.NativeDeviceChild, ColorHelper.Convert(blendFactor), multiSampleMask);
634 public void SetBlendState(BlendState blendState, Color4 blendFactor, uint multiSampleMask = 0xFFFFFFFF)
636 SetBlendState(blendState, blendFactor, unchecked((
int)multiSampleMask));
644 public void SetDepthStencilState(DepthStencilState depthStencilState,
int stencilReference = 0)
646 NativeDeviceContext.OutputMerger.SetDepthStencilState(depthStencilState != null ? (SharpDX.Direct3D11.DepthStencilState)depthStencilState.NativeDeviceChild : null, stencilReference);
653 public void SetRasterizerState(RasterizerState rasterizerState)
655 NativeDeviceContext.Rasterizer.State = rasterizerState != null ? (SharpDX.Direct3D11.RasterizerState)rasterizerState.NativeDeviceChild : null;
663 public void SetRenderTarget(DepthStencilBuffer depthStencilView, RenderTarget renderTargetView)
665 CommonSetRenderTargets(depthStencilView, renderTargetView);
666 outputMerger.SetTargets(depthStencilView != null ? depthStencilView.NativeDepthStencilView : null, currentRenderTargetView);
675 public void SetRenderTargets(DepthStencilBuffer depthStencilView, params RenderTarget[] renderTargetViews)
677 if (renderTargetViews == null)
throw new ArgumentNullException(
"renderTargetViews");
678 CommonSetRenderTargets(depthStencilView, renderTargetViews);
679 outputMerger.SetTargets(depthStencilView != null ? depthStencilView.NativeDepthStencilView : null, actualRenderTargetViewCount, currentRenderTargetViews);
689 public void SetScissorRectangles(
int left,
int top,
int right,
int bottom)
691 NativeDeviceContext.Rasterizer.SetScissorRectangle(left, top, right, bottom);
698 public unsafe
void SetScissorRectangles(params
Rectangle[] scissorRectangles)
700 if (scissorRectangles == null)
throw new ArgumentNullException(
"scissorRectangles");
701 var localScissorRectangles =
new SharpDX.Rectangle[scissorRectangles.Length];
702 Utilities.Write((IntPtr)Interop.Fixed(localScissorRectangles), scissorRectangles, 0, scissorRectangles.Length);
703 NativeDeviceContext.Rasterizer.SetScissorRectangles(localScissorRectangles);
710 public void SetStreamTargets(params
Buffer[] buffers)
712 SharpDX.Direct3D11.StreamOutputBufferBinding[] streamOutputBufferBindings;
716 streamOutputBufferBindings =
new SharpDX.Direct3D11.StreamOutputBufferBinding[buffers.Length];
717 for (
int i = 0; i < buffers.Length; ++i)
718 streamOutputBufferBindings[i].
Buffer = buffers[i].NativeBuffer;
722 streamOutputBufferBindings = null;
725 NativeDeviceContext.StreamOutput.SetTargets(streamOutputBufferBindings);
732 public void SetVertexArrayObject(VertexArrayObject vertexArrayObject)
734 if (vertexArrayObject == null)
736 inputAssembler.InputLayout = null;
737 IntPtr vertexBufferPtr = IntPtr.Zero;
740 var ptrToNull =
new IntPtr(&vertexBufferPtr);
742 inputAssembler.SetVertexBuffers(0, 1, ptrToNull, ptrToNull, ptrToNull);
746 newVertexArrayObject = vertexArrayObject;
753 public void SetViewport(Viewport value)
755 SetViewport(0, value);
762 public void SetViewport(
int index, Viewport value)
764 currentViewports[index] = value;
767 Utilities.ReadOut(
new IntPtr(&value), out currentNativeViewports[index]);
769 nativeDeviceContext.Rasterizer.SetViewports(currentNativeViewports);
772 public void UnmapSubresource(MappedResource unmapped)
774 NativeDeviceContext.UnmapSubresource(unmapped.Resource.NativeResource, unmapped.SubResourceIndex);
780 public void UnsetReadWriteBuffers()
783 for (
int i = 0; i < UnorderedAcccesViewCount; i++)
785 SetUnorderedAccessView(
ShaderStage.Compute, i, null);
792 public void UnsetRenderTargets()
794 NativeDeviceContext.OutputMerger.ResetTargets();
797 public void SimulateReset()
799 simulateReset =
true;
811 throw new ArgumentException(
"Cannot use Stage.None",
"stage");
813 int stageIndex = (int)stage - 1;
815 int slotIndex = stageIndex*ConstantBufferCount + slot;
816 if (constantBuffers[slotIndex] != buffer)
818 constantBuffers[slotIndex] = buffer;
819 shaderStages[stageIndex].SetConstantBuffer(slot, buffer != null ? buffer.NativeBuffer : null);
829 internal void SetSamplerState(
ShaderStage stage,
int slot, SamplerState samplerState)
832 throw new ArgumentException(
"Cannot use Stage.None",
"stage");
833 int stageIndex = (int)stage - 1;
835 int slotIndex = stageIndex*SamplerStateCount + slot;
836 if (samplerStates[slotIndex] != samplerState)
838 samplerStates[slotIndex] = samplerState;
839 shaderStages[stageIndex].SetSampler(slot, samplerState != null ? (SharpDX.Direct3D11.SamplerState)samplerState.NativeDeviceChild : null);
849 internal void SetShaderResourceView(
ShaderStage stage,
int slot, GraphicsResource shaderResourceView)
851 shaderStages[(int)stage - 1].SetShaderResource(slot, shaderResourceView != null ? shaderResourceView.NativeShaderResourceView : null);
861 internal void SetUnorderedAccessView(
ShaderStage stage,
int slot, GraphicsResource unorderedAccessView)
864 throw new ArgumentException(
"Invalid stage.",
"stage");
866 NativeDeviceContext.ComputeShader.SetUnorderedAccessView(slot, unorderedAccessView != null ? unorderedAccessView.NativeUnorderedAccessView : null);
869 internal unsafe
void UpdateSubresource(GraphicsResource resource,
int subResourceIndex, DataBox databox)
871 if (resource == null)
throw new ArgumentNullException(
"resource");
872 NativeDeviceContext.UpdateSubresource(*(SharpDX.DataBox*)Interop.Cast(ref databox), resource.NativeResource, subResourceIndex);
875 internal unsafe
void UpdateSubresource(GraphicsResource resource,
int subResourceIndex, DataBox databox, ResourceRegion region)
877 if (resource == null)
throw new ArgumentNullException(
"resource");
878 NativeDeviceContext.UpdateSubresource(*(SharpDX.DataBox*)Interop.Cast(ref databox), resource.NativeResource, subResourceIndex, *(SharpDX.Direct3D11.ResourceRegion*)Interop.Cast(ref region));
881 private void CommonSetRenderTargets(DepthStencilBuffer depthStencilBuffer, RenderTarget rtv)
883 currentRenderTargetView = rtv != null ? rtv.NativeRenderTargetView : null;
887 SetViewport(
new Viewport(0, 0, rtv.Width, rtv.Height));
889 else if (depthStencilBuffer != null)
891 SetViewport(
new Viewport(0, 0, depthStencilBuffer.Description.Width, depthStencilBuffer.Description.Height));
895 private void CommonSetRenderTargets(DepthStencilBuffer depthStencilBuffer, RenderTarget[] renderTargets)
897 if (renderTargets.Length > currentRenderTargetViews.Length)
899 throw new ArgumentOutOfRangeException(
string.Format(
"RenderTargets count is exceeding maximum range [{0}]", renderTargets.Length),
"renderTargets");
902 RenderTarget rtv = renderTargets.Length > 0 ? renderTargets[0] : null;
904 for (
int i = 0; i < renderTargets.Length; i++)
905 currentRenderTargetViews[i] = renderTargets[i] != null ? renderTargets[i].NativeRenderTargetView : null;
906 actualRenderTargetViewCount = renderTargets.Length;
911 SetViewport(
new Viewport(0, 0, rtv.Width, rtv.Height));
913 else if (depthStencilBuffer != null)
915 SetViewport(
new Viewport(0, 0, depthStencilBuffer.Description.Width, depthStencilBuffer.Description.Height));
919 private void InitializeStages()
921 inputAssembler = nativeDeviceContext.InputAssembler;
922 outputMerger = nativeDeviceContext.OutputMerger;
923 shaderStages[(int)
ShaderStage.Vertex - 1] = nativeDeviceContext.VertexShader;
924 shaderStages[(
int)ShaderStage.Hull - 1] = nativeDeviceContext.HullShader;
925 shaderStages[(int)
ShaderStage.Domain - 1] = nativeDeviceContext.DomainShader;
926 shaderStages[(
int)ShaderStage.Geometry - 1] = nativeDeviceContext.GeometryShader;
927 shaderStages[(int)
ShaderStage.Pixel - 1] = nativeDeviceContext.PixelShader;
928 shaderStages[(
int)ShaderStage.Compute - 1] = nativeDeviceContext.ComputeShader;
931 private void InitializeFactories()
933 switch (Features.Profile)
935 case GraphicsProfile.Level_9_1:
936 case GraphicsProfile.Level_9_2:
937 case GraphicsProfile.Level_9_3:
938 currentViewports =
new Viewport[1];
941 currentViewports =
new Viewport[8];
944 currentNativeViewports =
new SharpDX.ViewportF[currentViewports.Length];
955 if (nativeDevice != null)
962 IsProfilingSupported =
true;
965 SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel();
969 nativeDevice =
new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels);
970 nativeDeviceContext = nativeDevice.ImmediateContext;
973 GraphicsResourceBase.SetDebugName(
this, nativeDeviceContext,
"ImmediateContext");
979 if (InputLayoutManager == null)
980 InputLayoutManager =
new InputLayoutManager(
this).DisposeBy(
this);
983 protected void DestroyPlatformDevice()
988 private void ReleaseDevice()
992 NativeDevice.ImmediateContext.Flush();
993 NativeDevice.ImmediateContext.Dispose();
997 var deviceDebug =
new DeviceDebug(NativeDevice);
998 deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
1001 currentInputLayout = null;
1002 currentEffectInputSignature = null;
1003 currentRenderTargetView = null;
1004 currentVertexArrayLayout = null;
1005 nativeDevice.Dispose();
1008 internal void OnDestroyed()
1011 InputLayoutManager.OnDestroyed();
1021 if (CurrentEffect == null)
1023 throw new InvalidOperationException(
"Cannot GraphicsDevice.Draw*() without an effect being previously applied with Effect.Apply() method");
1030 if (newVertexArrayObject == null)
1032 currentVertexArrayLayout = null;
1033 currentEffectInputSignature = null;
1034 currentInputLayout = null;
1038 VertexArrayLayout newVertexArrayLayout = newVertexArrayObject.Layout;
1039 EffectInputSignature newEffectInputSignature = CurrentEffect.InputSignature;
1042 if (!ReferenceEquals(newVertexArrayLayout, currentVertexArrayLayout) || !ReferenceEquals(newEffectInputSignature, currentEffectInputSignature))
1044 currentVertexArrayLayout = newVertexArrayLayout;
1045 currentEffectInputSignature = newEffectInputSignature;
1046 currentInputLayout = newVertexArrayObject.InputLayout;
1049 if (currentInputLayout == null || !ReferenceEquals(newEffectInputSignature, newVertexArrayObject.EffectInputSignature))
1051 currentInputLayout = InputLayoutManager.GetInputLayout(newEffectInputSignature, currentVertexArrayLayout);
1056 newVertexArrayObject.Apply(inputAssembler);
1060 inputAssembler.InputLayout = currentInputLayout;
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ DXGI_FORMAT _In_ DWORD flags
GraphicsDeviceStatus
Describes the current status of a GraphicsDevice.
SiliconStudio.Paradox.Graphics.Buffer Buffer
System.Windows.Shapes.Rectangle Rectangle
ShaderStage
Enum to specify shader stage.
SiliconStudio.Paradox.Graphics.PrimitiveType PrimitiveType
Creates a render target buffer.
MapMode
Describes how the cpu is accessing a GraphicsResource with the GraphicsDeviceContext.Map method.
GraphicsProfile
Identifies the set of supported devices for the demo based on device capabilities.
DepthStencilClearOptions
Specifies the buffer to use when calling Clear.