public Result CopyTileMappings( ID3D11Resource destTiledResource, TiledResourceCoordinate destRegionStartCoordinate, ID3D11Resource sourceTiledResource, TiledResourceCoordinate sourceRegionStartCoordinate, TileRegionSize tileRegionSize) { return(CopyTileMappings(destTiledResource, destRegionStartCoordinate, sourceTiledResource, sourceRegionStartCoordinate, tileRegionSize, TileMappingFlags.None)); }
public HolographicGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, HolographicSpace holographicSpace) : base(device, presentationParameters) { if (GraphicsDevice.RenderTargetViewAllocator.DescriptorHeap.Description.DescriptorCount != BufferCount) { GraphicsDevice.RenderTargetViewAllocator.Dispose(); GraphicsDevice.RenderTargetViewAllocator = new DescriptorAllocator(GraphicsDevice, DescriptorHeapType.RenderTargetView, descriptorCount: BufferCount); } using (IDXGIDevice dxgiDevice = GraphicsDevice.NativeDirect3D11Device.QueryInterface <IDXGIDevice>()) { IDirect3DDevice direct3DInteropDevice = Direct3DInterop.CreateDirect3DDevice(dxgiDevice); HolographicSpace = holographicSpace; HolographicSpace.SetDirect3D11Device(direct3DInteropDevice); } HolographicDisplay = HolographicDisplay.GetDefault(); SpatialStationaryFrameOfReference = HolographicDisplay.SpatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation(); HolographicFrame = HolographicSpace.CreateNextFrame(); HolographicSurface = HolographicFrame.GetRenderingParameters(HolographicFrame.CurrentPrediction.CameraPoses[0]).Direct3D11BackBuffer; HolographicBackBuffer = GetHolographicBackBuffer(); renderTarget = CreateRenderTarget(); direct3D11RenderTarget = CreateDirect3D11RenderTarget(); }
public unsafe void ReadFromSubresource <T>( T[] destination, int destinationRowPitch, int destinationDepthPitch, ID3D11Resource sourceResource, int sourceSubresource, Box?sourceBox = null) where T : unmanaged { ReadFromSubresource( (IntPtr)Unsafe.AsPointer(ref destination[0]), destinationRowPitch, destinationDepthPitch, sourceResource, sourceSubresource, sourceBox); }
public unsafe void WriteToSubresource <T>( ID3D11Resource destinationResource, int destinationSubresource, Box destinationBox, T[] sourceData, int sourceRowPitch, int srcDepthPitch) where T : unmanaged { WriteToSubresource( destinationResource, destinationSubresource, destinationBox, (IntPtr)Unsafe.AsPointer(ref sourceData[0]), sourceRowPitch, srcDepthPitch ); }
public unsafe void WriteToSubresource <T>( ID3D11Resource destinationResource, int destinationSubresource, Box destinationBox, Span <T> sourceData, int sourceRowPitch, int srcDepthPitch) where T : unmanaged { fixed(void *dataPtr = sourceData) { WriteToSubresource(destinationResource, destinationSubresource, destinationBox, (IntPtr)dataPtr, sourceRowPitch, srcDepthPitch ); } }
public unsafe void ReadFromSubresource <T>( T[] destination, int destinationRowPitch, int destinationDepthPitch, ID3D11Resource sourceResource, int sourceSubresource, Box?sourceBox = null) where T : unmanaged { fixed(void *destinationPtr = &destination[0]) { ReadFromSubresource( (IntPtr)destinationPtr, destinationRowPitch, destinationDepthPitch, sourceResource, sourceSubresource, sourceBox); } }
public ID3D11RenderTargetView CreateRenderTargetView(ID3D11Resource resource) { HRESULT result; IntPtr renderTargetView; unsafe { result = D3D11DeviceBindings.CreateRenderTargetView_(_handle, resource.Handle, (D3D11RenderTargetViewDesc *)null, out renderTargetView); } result.Check(nameof(D3D11Device)); return(new D3D11RenderTargetView(renderTargetView)); }
public unsafe void WriteToSubresource <T>( ID3D11Resource destinationResource, int destinationSubresource, T[] sourceData, int sourceRowPitch, int srcDepthPitch) where T : unmanaged { fixed(void *sourceDataPtr = &sourceData[0]) { WriteToSubresource( destinationResource, destinationSubresource, null, (IntPtr)sourceDataPtr, sourceRowPitch, srcDepthPitch ); } }
public Result UnwrapUnderlyingResource <T>(ID3D11Resource resource, ComObject commandQueue, out T?resource12) where T : ComObject { Result result = UnwrapUnderlyingResource(resource, commandQueue, typeof(T).GUID, out IntPtr nativePtr); if (result.Success) { resource12 = MarshallingHelpers.FromPointer <T>(nativePtr); return(result); } resource12 = null; return(result); }
public static void Unmap(this ID3D11DeviceContext context, ID3D11Resource resource, int subResource) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } context.Unmap(resource, (uint)subResource); }
public Result UpdateTileMappings( ID3D11Resource tiledResource, TiledResourceCoordinate[] tiledResourceRegionStartCoordinates, TileRegionSize[] tiledResourceRegionSizes, ID3D11Buffer tilePool, TileRangeFlags[] rangeFlags, int[] tilePoolStartOffsets, int[] rangeTileCounts, TileMappingFlags flags = TileMappingFlags.None) { return(UpdateTileMappings(tiledResource, tiledResourceRegionStartCoordinates.Length, tiledResourceRegionStartCoordinates, tiledResourceRegionSizes, tilePool, rangeFlags.Length, rangeFlags, tilePoolStartOffsets, rangeTileCounts, flags)); }
public static D3D11_MAPPED_SUBRESOURCE Map(this ID3D11DeviceContext context, ID3D11Resource resource, int subResource, D3D11_MAP mapType, D3D11_MAP_FLAG mapFlag = 0) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } using (var ptr = new ComMemory(Marshal.SizeOf <D3D11_MAPPED_SUBRESOURCE>())) { context.Map(resource, (uint)subResource, mapType, (uint)mapFlag, ptr.Pointer).ThrowOnError(); return(ptr.ToStructure <D3D11_MAPPED_SUBRESOURCE>()); } }
public unsafe Result ReturnUnderlyingResource(ID3D11Resource resource11, ReadOnlySpan <ulong> signalValues, ReadOnlySpan <ComObject> fences) { if (signalValues.Length != fences.Length) { throw new ArgumentException($"{nameof(signalValues)} and {nameof(fences)} length must be the same"); } IntPtr *ppFences = stackalloc IntPtr[fences.Length]; for (int i = 0; i < fences.Length; i++) { ppFences[i] = (fences[i] == null) ? IntPtr.Zero : fences[i].NativePointer; } fixed(ulong *pSignalValues = signalValues) { return(ReturnUnderlyingResource(resource11, signalValues.Length, pSignalValues, ppFences)); } }
public static IComObject <ID3D11ShaderResourceView> CreateShaderResourceView(this ID3D11Device device, ID3D11Resource resource, D3D11_SHADER_RESOURCE_VIEW_DESC?desc = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } using (var mem = new ComMemory(desc)) { device.CreateShaderResourceView(resource, mem.Pointer, out var view).ThrowOnError(); return(new ComObject <ID3D11ShaderResourceView>(view)); } }
public ID3D11VideoProcessorOutputView CreateVideoProcessorOutputView(ID3D11Resource resource, ID3D11VideoProcessorEnumerator enumerator, VideoProcessorOutputViewDescription description) { CreateVideoProcessorOutputView(resource, enumerator, description, out ID3D11VideoProcessorOutputView view).CheckError(); return(view); }
public ID3D11VideoDecoderOutputView CreateVideoDecoderOutputView(ID3D11Resource resource, VideoDecoderOutputViewDescription description) { CreateVideoDecoderOutputView(resource, description, out ID3D11VideoDecoderOutputView view).CheckError(); return(view); }
public T UnwrapUnderlyingResource <T>(ID3D11Resource resource, ComObject commandQueue) where T : ComObject { UnwrapUnderlyingResource(resource, commandQueue, typeof(T).GUID, out IntPtr nativePtr).CheckError(); return(MarshallingHelpers.FromPointer <T>(nativePtr)); }
//private readonly Dictionary<TextureViewDescriptor, TextureViewD3D11> _views = new Dictionary<TextureViewDescriptor, TextureViewD3D11>(); public TextureD3D11(DeviceD3D11 device, ref TextureDescriptor descriptor, ID3D11Texture2D nativeTexture, Format dxgiFormat) : base(device, ref descriptor) { Resource = nativeTexture; DXGIFormat = dxgiFormat; }
public TextureD3D11(DeviceD3D11 device, ref TextureDescriptor descriptor) : base(device, ref descriptor) { // Create new one. DXGIFormat = descriptor.Format.ToDirectX(); var cpuFlags = CpuAccessFlags.None; var resourceUsage = Vortice.DirectX.Direct3D11.Usage.Default; var bindFlags = descriptor.Usage.ToDirectX(descriptor.Format); var optionFlags = ResourceOptionFlags.None; var arraySize = descriptor.ArrayLayers; if (descriptor.TextureType == TextureType.TextureCube) { arraySize *= 6; optionFlags = ResourceOptionFlags.TextureCube; } switch (descriptor.TextureType) { case TextureType.Texture1D: { var d3dTextureDesc = new Texture1DDescription() { Width = descriptor.Width, MipLevels = descriptor.MipLevels, ArraySize = descriptor.ArrayLayers, Format = DXGIFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, OptionFlags = optionFlags, }; Resource = device.D3D11Device.CreateTexture1D(d3dTextureDesc); } break; case TextureType.Texture2D: case TextureType.TextureCube: { var d3dTextureDesc = new Texture2DDescription() { Width = descriptor.Width, Height = descriptor.Height, MipLevels = descriptor.MipLevels, ArraySize = descriptor.ArrayLayers, Format = DXGIFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, SampleDescription = new SampleDescription((int)descriptor.Samples, 0), OptionFlags = optionFlags, }; Resource = device.D3D11Device.CreateTexture2D(d3dTextureDesc); } break; case TextureType.Texture3D: { var d3dTextureDesc = new Texture3DDescription() { Width = descriptor.Width, Height = descriptor.Height, Depth = descriptor.Depth, MipLevels = descriptor.MipLevels, Format = DXGIFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, OptionFlags = optionFlags, }; Resource = device.D3D11Device.CreateTexture3D(d3dTextureDesc); } break; } }
public ID3D11Texture2D?CaptureTexture(ID3D11Texture2D source) { ID3D11Texture2D?stagingTexture; var desc = source.Description; if (desc.ArraySize > 1 || desc.MipLevels > 1) { Console.WriteLine("WARNING: ScreenGrab does not support 2D arrays, cubemaps, or mipmaps; only the first surface is written. Consider using DirectXTex instead."); return(null); } if (desc.SampleDescription.Count > 1) { // MSAA content must be resolved before being copied to a staging texture desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; ID3D11Texture2D temp = Device.CreateTexture2D(desc); Format format = desc.Format; FormatSupport formatSupport = Device.CheckFormatSupport(format); if ((formatSupport & FormatSupport.MultisampleResolve) == FormatSupport.None) { return(null); } for (int item = 0; item < desc.ArraySize; ++item) { for (int level = 0; level < desc.MipLevels; ++level) { int index = ID3D11Resource.CalculateSubResourceIndex(level, item, desc.MipLevels); DeviceContext.ResolveSubresource(temp, index, source, index, format); } } desc.BindFlags = BindFlags.None; desc.OptionFlags &= ResourceOptionFlags.TextureCube; desc.CpuAccessFlags = CpuAccessFlags.Read; desc.Usage = ResourceUsage.Staging; stagingTexture = Device.CreateTexture2D(desc); DeviceContext.CopyResource(stagingTexture, temp); } else if ((desc.Usage == ResourceUsage.Staging) && ((desc.CpuAccessFlags & CpuAccessFlags.Read) != CpuAccessFlags.None)) { // Handle case where the source is already a staging texture we can use directly stagingTexture = source; } else { // Otherwise, create a staging texture from the non-MSAA source desc.BindFlags = 0; desc.OptionFlags &= ResourceOptionFlags.TextureCube; desc.CpuAccessFlags = CpuAccessFlags.Read; desc.Usage = ResourceUsage.Staging; stagingTexture = Device.CreateTexture2D(desc); DeviceContext.CopyResource(stagingTexture, source); } return(stagingTexture); }
public static IComObject <ID3D11DepthStencilView> CreateDepthStencilView(this ID3D11Device device, ID3D11Resource resource, D3D11_DEPTH_STENCIL_VIEW_DESC?desc = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } using (var mem = new ComMemory(desc)) { device.CreateDepthStencilView(resource, mem.Pointer, out var view).ThrowOnError(); return(new ComObject <ID3D11DepthStencilView>(view)); } }
public static IComObject <ID3D11UnorderedAccessView> CreateUnorderedAccessView(this ID3D11Device device, ID3D11Resource resource, D3D11_UNORDERED_ACCESS_VIEW_DESC?desc = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } using (var mem = new ComMemory(desc)) { device.CreateUnorderedAccessView(resource, mem.Pointer, out var view).ThrowOnError(); return(new ComObject <ID3D11UnorderedAccessView>(view)); } }
public Result CreateVideoDecoderOutputView(ID3D11Resource resource, VideoDecoderOutputViewDescription description, out ID3D11VideoDecoderOutputView view) { return(CreateVideoDecoderOutputView(resource, ref description, out view)); }
public void CopyTiles(ID3D11Resource tiledResource, TiledResourceCoordinate tileRegionStartCoordinate, TileRegionSize tileRegionSize, ID3D11Buffer buffer, ulong bufferStartOffsetInBytes) { CopyTiles(tiledResource, tileRegionStartCoordinate, tileRegionSize, buffer, bufferStartOffsetInBytes, TileCopyFlags.None); }