/// <summary> /// Constructs a new CPU texture 2D. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="texture">The target DX texture.</param> /// <param name="bufferFlags">The used buffer flags.</param> /// <param name="viewFlags">The used view flags.</param> internal CPUDirectXTexture2DArray( CPUAccelerator accelerator, Device d3dDevice, Texture2D texture, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator, d3dDevice, texture, bufferFlags, viewFlags) { var desc = texture.Description; var stagingDesc = new Texture2DDescription() { ArraySize = desc.ArraySize, MipLevels = 1, Format = desc.Format, OptionFlags = ResourceOptionFlags.None, SampleDescription = new global::SharpDX.DXGI.SampleDescription(1, 0), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write, Usage = ResourceUsage.Staging, Width = desc.Width, Height = desc.Height }; stagingTexture = new Texture2D(d3dDevice, stagingDesc); }
/// <summary> /// Constructs a new texture 2D with interop capabilities. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="texture">The width.</param> /// <param name="bufferFlags">The used buffer flags.</param> /// <param name="viewFlags">The used view flags.</param> protected DirectXTexture2D( Accelerator accelerator, Device d3dDevice, Texture2D texture, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator, d3dDevice, GetNumElements(texture), bufferFlags, viewFlags) { var desc = texture.Description; Width = desc.Width; Height = desc.Height; Format = desc.Format; this.texture = texture; if ((desc.BindFlags & BindFlags.RenderTarget) != 0) { targetView = new RenderTargetView(d3dDevice, texture); } if ((desc.BindFlags & BindFlags.ShaderResource) != 0) { ResourceView = new ShaderResourceView(d3dDevice, texture); } if ((desc.BindFlags & BindFlags.UnorderedAccess) != 0) { UnorderedAccessView = new UnorderedAccessView(d3dDevice, texture); } }
/// <summary> /// Creates a DX-compatible buffer for processing. /// </summary> /// <typeparam name="T">The element type of the buffer.</typeparam> /// <param name="numElements">The number of elements in the buffer.</param> /// <param name="bufferFlags">The buffer flags to use.</param> /// <param name="viewFlags">The view flags to use.</param> /// <returns>The created DX-compatible buffer.</returns> public DirectXBuffer <T> CreateBuffer <T>( int numElements, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) where T : unmanaged { return(CreateBuffer <T>( CreateDXBuffer <T>(numElements), bufferFlags, viewFlags)); }
/// <summary> /// Creates a new DX-compatible 2D texture for processing. /// </summary> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="format">The format of the texture.</param> /// <param name="bufferFlags">The buffer flags to use.</param> /// <param name="viewFlags">The view flags to use.</param> /// <returns>The created DX-compatible texture.</returns> public DirectXTexture2D CreateTexture2D( int width, int height, Format format, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) { return(CreateTexture2D( CreateDXTexture2D(width, height, format), bufferFlags, viewFlags)); }
/// <summary> /// Constructs a new Cuda texture 2D. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="texture">The target DX texture.</param> /// <param name="bufferFlags">The used buffer flags.</param> /// <param name="viewFlags">The used view flags.</param> internal CudaDirectXTexture2DArray( CudaAccelerator accelerator, Device d3dDevice, Texture2D texture, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator, d3dDevice, texture, bufferFlags, viewFlags) { CudaDirectXAccelerator.RegisterResource( texture, viewFlags, out cudaGraphicsResource); }
/// <summary> /// Constructs a new Cuda buffer. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="buffer">The target DX buffer.</param> /// <param name="bufferFlags">The buffer flags.</param> /// <param name="viewFlags">The used view flags</param> internal CudaDirectXBuffer( CudaAccelerator accelerator, Device d3dDevice, Buffer buffer, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator, d3dDevice, buffer, bufferFlags, viewFlags) { CudaDirectXAccelerator.RegisterResource( Buffer, viewFlags, out cudaGraphicsResource); }
/// <summary cref="DirectXInteropAccelerator.CreateTexture2D(Texture2D, DirectXBufferFlags, DirectXViewFlags)"/> public override DirectXTexture2D CreateTexture2D( Texture2D texture, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) { if (texture == null) { throw new ArgumentNullException(nameof(texture)); } return(new CudaDirectXTexture2D( CudaAccelerator, D3DDevice, texture, bufferFlags, viewFlags)); }
/// <summary cref="DirectXInteropAccelerator.CreateBuffer{T}(Buffer, DirectXBufferFlags, DirectXViewFlags)"/> public override DirectXBuffer <T> CreateBuffer <T>( Buffer buffer, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } return(new CudaDirectXBuffer <T>( CudaAccelerator, D3DDevice, buffer, bufferFlags, viewFlags)); }
/// <summary> /// Registers the resource with the given flags in the scope of the Cuda runtime system. /// </summary> /// <param name="resource">The resource to register.</param> /// <param name="viewFlags">The view flags to use.</param> /// <param name="cudaGraphicsResource">The resulting graphics resource.</param> internal static void RegisterResource( Resource resource, DirectXViewFlags viewFlags, out IntPtr cudaGraphicsResource) { CudaException.ThrowIfFailed( CudaNativeMethods.cuGraphicsD3D11RegisterResource( out cudaGraphicsResource, resource.NativePointer, CudaGraphicsRegisterFlags.None)); CudaException.ThrowIfFailed( CudaNativeMethods.cuGraphicsResourceSetMapFlags( cudaGraphicsResource, (CudaGraphicsMapFlags)viewFlags)); }
/// <summary> /// Constructs a new buffer for DX interop. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="numElements">The number of elements.</param> /// <param name="bufferFlags">The buffer flags.</param> /// <param name="viewFlags">The registration flags.</param> protected DirectXBuffer( Accelerator accelerator, Device d3dDevice, int numElements, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator) { if (numElements < 1) { throw new ArgumentOutOfRangeException(nameof(numElements)); } D3DDevice = d3dDevice; Length = numElements; BufferFlags = bufferFlags; ViewFlags = viewFlags; }
/// <summary> /// Convert the given view flags into a compatible MapMode. /// </summary> /// <param name="flags">The flags to convert.</param> /// <returns>The converted map mode.</returns> internal static MapMode ConvertToMapMode(DirectXViewFlags flags) { switch (flags) { case DirectXViewFlags.None: return(MapMode.ReadWrite); case DirectXViewFlags.ReadOnly: return(MapMode.Read); case DirectXViewFlags.WriteDiscard: return(MapMode.WriteDiscard); default: throw new ArgumentOutOfRangeException(nameof(flags)); } }
/// <summary> /// Constructs a new CPU buffer for DX interop. /// </summary> /// <param name="accelerator">The target accelerator.</param> /// <param name="d3dDevice">The target DX device.</param> /// <param name="buffer">The target DX buffer.</param> /// <param name="bufferFlags">The buffer flags.</param> /// <param name="viewFlags">The registration flags.</param> internal CPUDirectXBuffer( CPUAccelerator accelerator, Device d3dDevice, Buffer buffer, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) : base(accelerator, d3dDevice, buffer, bufferFlags, viewFlags) { cpuMemory = Accelerator.Allocate <T, Index1>(Length); var desc = new BufferDescription() { BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = ElementSize * Length, StructureByteStride = ElementSize, Usage = ResourceUsage.Staging, }; stagingBuffer = new Buffer(D3DDevice, desc); }
/// <summary> /// Creates a new DX-compatible 2D texture for processing. /// </summary> /// <param name="texture">The target DX texture.</param> /// <param name="bufferFlags">The buffer flags to use.</param> /// <param name="viewFlags">The view flags to use.</param> /// <returns>The created DX-compatible texture.</returns> public abstract DirectXTexture2D CreateTexture2D( Texture2D texture, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags);
/// <summary> /// Creates a DX-compatible buffer for processing. /// </summary> /// <typeparam name="T">The element type of the buffer.</typeparam> /// <param name="buffer">The target DX buffer.</param> /// <param name="bufferFlags">The buffer flags to use.</param> /// <param name="viewFlags">The view flags to use.</param> /// <returns>The created DX-compatible buffer.</returns> public abstract DirectXBuffer <T> CreateBuffer <T>( Buffer buffer, DirectXBufferFlags bufferFlags, DirectXViewFlags viewFlags) where T : unmanaged;