/// <summary> /// Копирует данные из неуправляемого ресурса ( Используемого в Компюте шейдере) в управляемый ресурс обычного шейдера. /// </summary> /// <param name="device">Устройстов используемое для отрисовки 3д</param> /// <param name="srv">ShaderResourceView с данными тестуры в который будем копировать данные UnorderedAccessView.</param> /// <param name="uav">UnorderedAccessView из которого будем брать данные</param> public static void CopyUAVToSRV(SharpDX.Direct3D11.Device device, ref SharpDX.Direct3D11.ShaderResourceView srv, SharpDX.Direct3D11.UnorderedAccessView uav) { using (var t = srv.ResourceAs <Texture2D>()) { using (var t2 = uav.ResourceAs <SharpDX.Direct3D11.Texture2D>()) { // Copy the texture for the resource to the typeless texture device.ImmediateContext.CopyResource(t2, t); } } }
/// <summary> /// Получает Bimap из ShaderResourceView (Ресурса с текстурой для шейдера). /// </summary> /// <param name="srv">Ресурс текстуры шейдера</param> /// <param name="renderTarger"> 2d рендертаргет который будет рисовать этот битмап</param> /// <returns>Битмапу с данными</returns> public static SharpDX.Direct2D1.Bitmap GetBitmapFromSRV(SharpDX.Direct3D11.ShaderResourceView srv, RenderTarget renderTarger) { using (var texture = srv.ResourceAs <Texture2D>()) using (var surface = texture.QueryInterface <Surface>()) { var bitmap = new SharpDX.Direct2D1.Bitmap(renderTarger, surface, new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat( Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied))); return(bitmap); } }
public void BeginBatch(ShaderResourceView texSRV) { Debug.Assert(_initialized); _batchTexSRV = texSRV; var tex = _batchTexSRV.ResourceAs<Texture2D>(); { var texDesc = tex.Description; _texWidth = texDesc.Width; _texHeight = texDesc.Height; } _spriteList.Clear(); }
private void CopyUAVToSRV(ShaderResourceView srv, UnorderedAccessView uav) { var device = this.DeviceManager.Direct3DDevice; using (var t = srv.ResourceAs<Texture2D>()) { using (var t2 = uav.ResourceAs<Texture2D>()) { // Copy the texture for the resource to the typeless texture device.ImmediateContext.CopyResource(t, t2); } } }
private UnorderedAccessView CopySRVToNewR32_UInt_UAV(ShaderResourceView srv) { UnorderedAccessView uav; var device = this.DeviceManager.Direct3DDevice; using (var t = srv.ResourceAs<Texture2D>()) { // Resize the sourceTexture resource so that it is the correct size var desc = t.Description; desc.BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess; desc.Format = Format.R8G8B8A8_Typeless; using (var t2 = ToDispose(new Texture2D(device, desc))) { uav = ToDispose(new UnorderedAccessView(device, t2, new UnorderedAccessViewDescription { Format = Format.R32_UInt, Dimension = UnorderedAccessViewDimension.Texture2D })); // Copy the texture for the resource to the typeless texture device.ImmediateContext.CopyResource(t, t2); } } return uav; }
private void CopyR32_UInt_UAVToExistingSRV(UnorderedAccessView uav, ShaderResourceView srv) { var device = this.DeviceManager.Direct3DDevice; int width, height; using (var t = uav.ResourceAs<Texture2D>()) { width = t.Description.Width; height = t.Description.Height; if (t.Description.Format != Format.R32_UInt) throw new ArgumentException("The provided UAV does not use the format R32_Uint", "uav"); using (var t2 = srv.ResourceAs<Texture2D>()) { if (t2.Description.Format != Format.R8G8B8A8_Typeless) throw new ArgumentException("Currently only supporting R8G8B8A8_Typeless SRVs", "srv"); this.DeviceManager.Direct3DDevice.ImmediateContext.CopyResource(t, t2); } } }
private void CheckSRVWidthHeight(ShaderResourceView srv, out int width, out int height) { using (var t = srv.ResourceAs<Texture2D>()) { width = t.Description.Width; height = t.Description.Height; } }