internal GraphicsDeviceFeatures(Direct3D11.Device device) { mapFeaturesPerFormat = new FeaturesPerFormat[256]; // Check global features Level = device.FeatureLevel; HasComputeShaders = device.CheckFeatureSupport(Feature.ComputeShaders); HasDoublePrecision = device.CheckFeatureSupport(Feature.ShaderDoubles); device.CheckThreadingSupport(out HasMultiThreadingConcurrentResources, out this.HasDriverCommandLists); // Check features for each DXGI.Format foreach (var format in Enum.GetValues(typeof(DXGI.Format))) { var dxgiFormat = (DXGI.Format)format; var maximumMSAA = MSAALevel.None; var computeShaderFormatSupport = ComputeShaderFormatSupport.None; var formatSupport = FormatSupport.None; if (!ObsoleteFormatToExcludes.Contains(dxgiFormat)) { maximumMSAA = GetMaximumMSAASampleCount(device, dxgiFormat); if (HasComputeShaders) { computeShaderFormatSupport = device.CheckComputeShaderFormatSupport(dxgiFormat); } formatSupport = device.CheckFormatSupport(dxgiFormat); } mapFeaturesPerFormat[(int)dxgiFormat] = new FeaturesPerFormat(dxgiFormat, maximumMSAA, computeShaderFormatSupport, formatSupport); } }
/// <summary> /// Creates a new texture with the specified generic texture description. /// </summary> /// <param name="graphicsDevice">The graphics device.</param> /// <param name="description">The description.</param> /// <returns>A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags.</returns> public static Texture New(Direct3D11.Device graphicsDevice, TextureDescription description) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } if ((description.BindFlags & BindFlags.RenderTarget) != 0) { throw new NotSupportedException("RenderTarget is not supported."); } else if ((description.BindFlags & BindFlags.DepthStencil) != 0) { throw new NotSupportedException("DepthStencil is not supported."); } else { switch (description.Dimension) { case TextureDimension.Texture1D: return(Texture1D.New(graphicsDevice, description)); case TextureDimension.Texture2D: return(Texture2D.New(graphicsDevice, description)); case TextureDimension.Texture3D: return(Texture3D.New(graphicsDevice, description)); case TextureDimension.TextureCube: return(TextureCube.New(graphicsDevice, description)); } } return(null); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="description"></param> protected Texture(Direct3D11.Device device, TextureDescription description) : base(device) { Description = description; IsBlockCompressed = FormatHelper.IsCompressed(description.Format); RowStride = this.Description.Width * ((PixelFormat)this.Description.Format).SizeInBytes; DepthStride = RowStride * this.Description.Height; }
public void TestException() { // Device is implicitly created with a DXGI Factory / Adapter var device = new Direct3D11.Device(DriverType.Hardware); // Create another DXGI Factory var factory = new SharpDX.DXGI.Factory1(); try { // This call should raise a DXGI_ERROR_INVALID_CALL: // The reason is the SwapChain must be created with a d3d device that was created with the same factory // Because we were creating the D3D11 device without a DXGI factory, it is associated with another factory. var swapChain = new SwapChain( factory, device, new SwapChainDescription() { BufferCount = 1, Flags = SwapChainFlags.None, IsWindowed = false, ModeDescription = new ModeDescription(1024, 768, new Rational(60, 1), Format.R8G8B8A8_UNorm), SampleDescription = new SampleDescription(1, 0), OutputHandle = IntPtr.Zero, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }); } catch (SharpDXException exception) { Assert.AreEqual(exception.Descriptor.NativeApiCode, "DXGI_ERROR_INVALID_CALL"); } }
public InputSignatureManager(GraphicsDevice device, byte[] byteCode, Dictionary<VertexInputLayout, InputLayoutPair> contextCache, Dictionary<VertexInputLayout, InputLayoutPair> deviceCache) { this.device = device; Bytecode = byteCode; ContextCache = contextCache; DeviceCache = deviceCache; }
/// <summary> /// Loads a texture from a stream. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="stream">The stream to load the texture from.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="usage">Usage of the resource. Default is <see cref="ResourceUsage.Immutable"/> </param> /// <returns>A texture</returns> public static Texture Load(Direct3D11.Device device, Stream stream, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { stream.Position = 0; var image = Image.Load(stream); if (image == null) { stream.Position = 0; return(null); } try { switch (image.Description.Dimension) { case TextureDimension.Texture1D: return(Texture1D.New(device, image, flags, usage)); case TextureDimension.Texture2D: return(Texture2D.New(device, image, flags, usage)); case TextureDimension.Texture3D: return(Texture3D.New(device, image, flags, usage)); case TextureDimension.TextureCube: return(TextureCube.New(device, image, flags, usage)); } } finally { image.Dispose(); stream.Position = 0; } throw new InvalidOperationException("Dimension not supported"); }
internal RenderTarget2D(Direct3D11.Device device, Direct3D11.Texture2D texture, RenderTargetView renderTargetView = null, bool pureRenderTarget = false) : base(device, texture) { this.pureRenderTarget = pureRenderTarget; this.customRenderTargetView = renderTargetView; Initialize(Resource); }
internal DepthStencilBuffer(Direct3D11.Device device, Direct3D11.Texture2D texture, DepthFormat depthFormat) : base(device, texture) { DepthFormat = depthFormat; DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil); Initialize(Resource); HasReadOnlyView = InitializeViewsDelayed(); DepthStencilView = new DepthStencilViewSelector(this); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="description"></param> protected Texture(Direct3D11.Device device, TextureDescription description) : base(device) { Description = description; IsBlockCompressed = FormatHelper.IsCompressed(description.Format); RowStride = this.Description.Width * ((PixelFormat)this.Description.Format).SizeInBytes; DepthStride = RowStride * this.Description.Height; ShaderResourceView = new ShaderResourceViewSelector(this); RenderTargetView = new RenderTargetViewSelector(this); UnorderedAccessView = new UnorderedAccessViewSelector(this); mipmapDescriptions = Image.CalculateMipMapDescription(description); }
/// <summary> /// /// </summary> public ConstantBuffer(Direct3D11.Device device) : this(device, new Direct3D11.BufferDescription { Usage = Direct3D11.ResourceUsage.Default, BindFlags = Direct3D11.BindFlags.ConstantBuffer, CpuAccessFlags = Direct3D11.CpuAccessFlags.None, OptionFlags = Direct3D11.ResourceOptionFlags.None, StructureByteStride = 0 }) { }
/// <summary> /// Gets the maximum MSAA sample count for a particular <see cref="PixelFormat" />. /// </summary> /// <param name="device">The device.</param> /// <param name="pixelFormat">The pixelFormat.</param> /// <returns>The maximum multisample count for this pixel pixelFormat</returns> /// <msdn-id>ff476499</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CheckMultisampleQualityLevels([In] DXGI_FORMAT Format,[In] unsigned int SampleCount,[Out] unsigned int* pNumQualityLevels)</unmanaged> /// <unmanaged-short>ID3D11Device::CheckMultisampleQualityLevels</unmanaged-short> private static MSAALevel GetMaximumMSAASampleCount(Direct3D11.Device device, PixelFormat pixelFormat) { int maxCount = 1; for (int i = 1; i <= 8; i *= 2) { if (device.CheckMultisampleQualityLevels(pixelFormat, i) != 0) { maxCount = i; } } return((MSAALevel)maxCount); }
/// <summary> /// /// </summary> public ConstantBuffer(Direct3D11.Device device, Direct3D11.BufferDescription desc) { desc.SizeInBytes = Marshal.SizeOf(typeof(T)); if (device == null) { throw new ArgumentNullException("device"); } this.m_device = device; //_device.AddReference(); m_buffer = new Direct3D11.Buffer(device, desc); m_dataStream = new DataStream(desc.SizeInBytes, true, true); }
/// <summary> /// /// </summary> private void Dispose(bool disposing) { if (m_device == null) { return; } if (disposing) { m_dataStream.Dispose(); } // NOTE: SharpDX 1.3 requires explicit Dispose() of all resource m_device.Dispose(); m_buffer.Dispose(); m_device = null; m_buffer = null; }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="device"></param> /// <param name="range"></param> /// <returns></returns> public static Direct3D11.Buffer CreateBuffer <T>(this Direct3D11.Device device, T[] range) where T : struct { int sizeInBytes = Marshal.SizeOf(typeof(T)); using (var stream = new DataStream(range.Length * sizeInBytes, true, true)) { stream.WriteRange(range); stream.Position = 0; return(new Direct3D11.Buffer(device, stream, new Direct3D11.BufferDescription { BindFlags = Direct3D11.BindFlags.VertexBuffer, SizeInBytes = (int)stream.Length, CpuAccessFlags = Direct3D11.CpuAccessFlags.None, OptionFlags = Direct3D11.ResourceOptionFlags.None, StructureByteStride = 0, Usage = Direct3D11.ResourceUsage.Default, })); } }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="w"></param> /// <param name="h"></param> /// <param name="flags"></param> /// <param name="format"></param> /// <param name="options"></param> /// <returns></returns> public static Direct3D11.Texture2D CreateTexture2D(this Direct3D11.Device device, int w, int h, Direct3D11.BindFlags flags = Direct3D11.BindFlags.RenderTarget | Direct3D11.BindFlags.ShaderResource, Format format = Format.B8G8R8A8_UNorm, Direct3D11.ResourceOptionFlags options = Direct3D11.ResourceOptionFlags.Shared) { var colordesc = new Direct3D11.Texture2DDescription { BindFlags = flags, Format = format, Width = w, Height = h, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = Direct3D11.ResourceUsage.Default, OptionFlags = options, CpuAccessFlags = Direct3D11.CpuAccessFlags.None, ArraySize = 1 }; return(new Direct3D11.Texture2D(device, colordesc)); }
/// <summary> /// Specialised constructor for use only by derived classes. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="texture">The texture.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> protected internal Texture1DBase(Direct3D11.Device device, Direct3D11.Texture1D texture) : base(device, texture.Description) { Resource = texture; Initialize(Resource); }
/// <summary> /// Initializes a new instance of the <see cref="Texture2DBase" /> class. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description2D">The description.</param> /// <param name="dataBoxes">A variable-length parameters list containing data rectangles.</param> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> protected internal Texture2DBase(Direct3D11.Device device, Texture2DDescription description2D, DataBox[] dataBoxes) : base(device, description2D) { Resource = new Direct3D11.Texture2D(device, description2D, dataBoxes); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description1D">The description.</param> /// <param name="dataBox">A variable-length parameters list containing data rectangles.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> protected internal Texture1DBase(Direct3D11.Device device, Texture1DDescription description1D, DataBox[] dataBox) : base(device, description1D) { Resource = new Direct3D11.Texture1D(device, description1D, dataBox); Initialize(Resource); }
/// <summary> /// Specialised constructor for use only by derived classes. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="texture">The texture.</param> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> protected internal Texture2DBase(Direct3D11.Device device, Direct3D11.Texture2D texture) : base(device, texture.Description) { Resource = texture; }
internal RenderTarget2D(Direct3D11.Device device, Texture2DDescription description2D) : base(device, description2D) { Initialize(Resource); }
public InputSignatureManager(GraphicsDevice device, byte[] byteCode) { this.device = device; Bytecode = byteCode; Cache = new Dictionary<VertexInputLayout, InputLayoutPair>(); }
public InputSignatureManager(GraphicsDevice device, byte[] byteCode) { this.device = device; Bytecode = byteCode; Cache = new Dictionary <VertexInputLayout, InputLayoutPair>(); }
internal RenderTargetCube(Direct3D11.Device device, Texture2DDescription description2D, params DataBox[] dataBoxes) : base(device, description2D, dataBoxes) { Initialize(Resource); }
internal RenderTargetCube(Direct3D11.Device device, Direct3D11.Texture2D texture) : base(device, texture) { Initialize(Resource); }
/// <summary> /// Creates a new <see cref="RenderTargetCube" />. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="size">The size (in pixels) of the top-level faces of the cube texture.</param> /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns>A new instance of <see cref="RenderTargetCube" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(Direct3D11.Device device, int size, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource) { return(new RenderTargetCube(device, NewRenderTargetDescription(size, format, flags | TextureFlags.RenderTarget, mipCount))); }
/// <summary> /// Creates a new <see cref="RenderTargetCube" /> with a single mipmap. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="size">The size (in pixels) of the top-level faces of the cube texture.</param> /// <param name="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns>A new instance of <see cref="RenderTargetCube" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(Direct3D11.Device device, int size, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource) { return(New(device, size, false, format, flags | TextureFlags.RenderTarget)); }
/// <summary> /// Loads a texture from a file. /// </summary> /// <param name="device">Specify the device used to load and create a texture from a file.</param> /// <param name="filePath">The file to load the texture from.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="usage">Usage of the resource. Default is <see cref="ResourceUsage.Immutable"/> </param> /// <returns>A texture</returns> public static Texture Load(Direct3D11.Device device, string filePath, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { using (var stream = new NativeFileStream(filePath, NativeFileMode.Open, NativeFileAccess.Read)) return(Load(device, stream, flags, usage)); }
/// <summary> /// Initializes a new instance of the <see cref="Texture3DBase" /> class. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description3D">The description.</param> /// <msdn-id>ff476522</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> protected internal Texture3DBase(Direct3D11.Device device, Texture3DDescription description3D) : base(device, description3D) { Resource = new Direct3D11.Texture3D(device, description3D); Initialize(Resource); }
/// <summary> /// Initializes a new instance of the <see cref="Texture3DBase" /> class. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description3D">The description.</param> /// <param name="dataRectangles">A variable-length parameters list containing data rectangles.</param> /// <msdn-id>ff476522</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> protected internal Texture3DBase(Direct3D11.Device device, Texture3DDescription description3D, DataBox[] dataRectangles) : base(device, description3D) { Resource = new Direct3D11.Texture3D(device, description3D, dataRectangles); Initialize(Resource); }
/// <summary> /// Creates a new <see cref="RenderTargetCube"/> from a <see cref="Texture2DDescription"/>. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description">The description.</param> /// <returns> /// A new instance of <see cref="RenderTargetCube"/> class. /// </returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(Direct3D11.Device device, Texture2DDescription description) { return(new RenderTargetCube(device, description)); }
/// <summary> /// Creates a new <see cref="RenderTargetCube"/> from a <see cref="Direct3D11.Texture2D"/>. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="texture">The native texture <see cref="Direct3D11.Texture2D"/>.</param> /// <returns> /// A new instance of <see cref="RenderTargetCube"/> class. /// </returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(Direct3D11.Device device, Direct3D11.Texture2D texture) { return(new RenderTargetCube(device, texture)); }