// Methods. public bool Initialize(Device device, string fileName) { try { using (var texture = LoadFromFile(device, new SharpDX.WIC.ImagingFactory(), fileName)) { ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, }; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = -1; TextureResource = new ShaderResourceView(device, texture, srvDesc); device.ImmediateContext.GenerateMips(TextureResource); } // TextureResource = ShaderResourceView.FromFile(device, fileName); return(true); } catch { return(false); } }
/// <summary> /// Resizes the buffer to the nearest power of two >= nElements /// and sets Count to nElements /// </summary> /// <param name="nElements"></param> public void Resize( int nElements ) { if( nElements > Capacity || // if we need more than we currently have allocated nElements < Capacity / 2 ) // or if the current one is more than twice as big { Capacity = nElements.RoundUpToNearestPowerOfTwo(); if( Buffer != null ) { View.Dispose(); Buffer.Dispose(); } Buffer = BufferFactory.CreateDynamicDataBuffer( Capacity, ElementSizeBytes ); var srv = new ShaderResourceViewDescription() { ArraySize = 1, Format = SlimDX.DXGI.Format.R32G32B32A32_Float, Dimension = ShaderResourceViewDimension.Buffer, ElementOffset = 0, ElementWidth = ElementSizeBytes }; View = new ShaderResourceView( D3D10Wrapper.Instance.Device, Buffer, srv ); } Count = nElements; }
public ShaderResourceView LoadBitmapShaderResource(System.Drawing.Bitmap btm) { ShaderResourceView res = null; try { var ms = new MemoryStream(); btm.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.Position = 0; var factory = new SharpDX.WIC.ImagingFactory(); var bitmapDecoder = new BitmapDecoder(factory, ms, DecodeOptions.CacheOnDemand); var result = new FormatConverter(factory); result.Initialize(bitmapDecoder.GetFrame(0), PixelFormat.Format32bppPRGBA, BitmapDitherType.None, null, 0.0, BitmapPaletteType.Custom); using (var texture = CreateTexture2DFromBitmap(device, result)) { var srvDesc = new ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, }; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = -1; res = new ShaderResourceView(device, texture, srvDesc); device.ImmediateContext.GenerateMips(res); } // TextureResource = ShaderResourceView.FromFile(device, fileName); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine($"TexturedLoader {ex.Message}"); } return(res); }
private void Update(EvaluationContext context) { var resourceManager = ResourceManager.Instance(); Texture2D texture = Texture.GetValue(context); if (texture != null) { ShaderResourceView.Value?.Dispose(); if ((texture.Description.BindFlags & BindFlags.DepthStencil) > 0) { // it's a depth stencil texture, so we need to set the format explicitly var desc = new ShaderResourceViewDescription() { Format = Format.R32_Float, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1, MostDetailedMip = 0 } }; ShaderResourceView.Value = new ShaderResourceView(resourceManager.Device, texture, desc); } else { ShaderResourceView.Value = new ShaderResourceView(resourceManager.Device, texture); // todo: create via resource manager } } else { Utilities.Dispose(ref ShaderResourceView.Value); } }
private void PrepareShaders() { if (D3DDevice == null || DisplayTexture == null) { return; } //Create new Shader with R8 which contains the Y component of the picture ShaderResourceViewDescription srv = new ShaderResourceViewDescription { Format = Format.R8_UNorm, Dimension = ShaderResourceViewDimension.Texture2D }; srv.Texture2D.MipLevels = 1; //Set Shaders onto the pipeline using (var textureView1 = new ShaderResourceView(D3DDevice, DisplayTexture, srv)) { D3DContext.PixelShader.SetShaderResource(0, textureView1); } //Create new Shader with R8G8 which contains the UV component of the picture srv.Format = Format.R8G8_UNorm; //Set Shaders onto the pipeline using (var textureView2 = new ShaderResourceView(D3DDevice, DisplayTexture, srv)) { D3DContext.PixelShader.SetShaderResource(1, textureView2); } }
public DX11MipSliceRenderTarget(DX11RenderContext context, DX11Texture3D texture, int mipindex,int w, int h,int d) { this.context = context; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture3D, Format = texture.Format, MipSlice = mipindex, DepthSliceCount = d }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription(); srvd.Dimension = ShaderResourceViewDimension.Texture3D; srvd.MipLevels = 1; srvd.MostDetailedMip = mipindex; srvd.Format = texture.Format; this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd); this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd); this.Width = w; this.Height = h; this.Depth = d; }
public DX11SliceRenderTarget(DX11RenderContext context, DX11Texture2D texture, int sliceindex) { this.isowner = false; this.context = context; this.parent = texture; this.desc = texture.Description; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { ArraySize = 1, Dimension = RenderTargetViewDimension.Texture2DArray, Format = texture.Format, MipSlice = 0, FirstArraySlice = sliceindex, }; this.RTV = new RenderTargetView(context.Device, this.parent.Resource, rtd); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = 1, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = texture.Format, FirstArraySlice = sliceindex, MipLevels = texture.Resource.Description.MipLevels, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.parent.Resource, srvd); }
public DX11RawBuffer(Device dev, int size, DX11RawBufferFlags flags= new DX11RawBufferFlags()) { this.Size = size; BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.RawBuffer, SizeInBytes = this.Size, Usage = ResourceUsage.Default, }; this.Buffer = new Buffer(dev, bd); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = ShaderResourceViewExtendedBufferFlags.RawData, ElementCount = size / 4 }; this.SRV = new ShaderResourceView(dev, this.Buffer, srvd); UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = UnorderedAccessViewDimension.Buffer, Flags = UnorderedAccessViewBufferFlags.RawData, ElementCount = size / 4 }; this.UAV = new UnorderedAccessView(dev, this.Buffer, uavd); }
/// <summary> /// Gets a <see cref="ShaderResourceView"/> for a particular <see cref="PixelFormat"/>. /// </summary> /// <param name="viewFormat">The view format.</param> /// <returns>A <see cref="ShaderResourceView"/> for the particular view format.</returns> /// <remarks> /// The buffer must have been declared with <see cref="Graphics.BufferFlags.ShaderResource"/>. /// The ShaderResourceView instance is kept by this buffer and will be disposed when this buffer is disposed. /// </remarks> internal ShaderResourceView GetShaderResourceView(PixelFormat viewFormat) { ShaderResourceView srv = null; if ((nativeDescription.BindFlags & BindFlags.ShaderResource) != 0) { var description = new ShaderResourceViewDescription { Format = (SharpDX.DXGI.Format)viewFormat, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.ExtendedBuffer, BufferEx = { ElementCount = this.ElementCount, FirstElement = 0, Flags = ShaderResourceViewExtendedBufferFlags.None, }, }; if (((ViewFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer)) { description.BufferEx.Flags |= ShaderResourceViewExtendedBufferFlags.Raw; } srv = new ShaderResourceView(this.GraphicsDevice.NativeDevice, NativeResource, description); } return(srv); }
void CreateFontsTexture() { var io = ImGui.GetIO(); byte *pixels; int width, height; io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height); var texDesc = new Texture2DDescription { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = Format.R8G8B8A8_UNorm, SampleDescription = new SampleDescription { Count = 1 }, Usage = Vortice.Direct3D11.Usage.Default, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None }; var subResource = new SubresourceData { DataPointer = (IntPtr)pixels, Pitch = texDesc.Width * 4, SlicePitch = 0 }; var texture = device.CreateTexture2D(texDesc, new[] { subResource }); var resViewDesc = new ShaderResourceViewDescription { Format = Format.R8G8B8A8_UNorm, ViewDimension = ShaderResourceViewDimension.Texture2D, Texture2D = new Texture2DShaderResourceView { MipLevels = texDesc.MipLevels, MostDetailedMip = 0 } }; fontTextureView = device.CreateShaderResourceView(texture, resViewDesc); texture.Release(); io.Fonts.TexID = RegisterTexture(fontTextureView); var samplerDesc = new SamplerDescription { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MipLODBias = 0f, ComparisonFunction = ComparisonFunction.Always, MinLOD = 0f, MaxLOD = 0f }; fontSampler = device.CreateSamplerState(samplerDesc); }
public DX11MipSliceRenderTarget(DX11RenderContext context, DX11Texture3D texture, int mipindex, int w, int h, int d) { this.context = context; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture3D, Format = texture.Format, MipSlice = mipindex, DepthSliceCount = d }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription(); srvd.Dimension = ShaderResourceViewDimension.Texture3D; srvd.MipLevels = 1; srvd.MostDetailedMip = mipindex; srvd.Format = texture.Format; this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd); this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd); this.Width = w; this.Height = h; this.Depth = d; }
internal override ShaderResourceView GetShaderResourceView(ViewType viewType, int arrayOrDepthSlice, int mipIndex) { if ((this.NativeDescription.BindFlags & BindFlags.ShaderResource) == 0) { return(null); } int arrayCount; int mipCount; GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount); // Create the view var srvDescription = new ShaderResourceViewDescription { Format = (Format)this.Description.Format, Dimension = ShaderResourceViewDimension.Texture3D, Texture3D = { MipLevels = mipCount, MostDetailedMip = mipIndex } }; return(new ShaderResourceView(this.GraphicsDevice.NativeDevice, this.Resource, srvDescription)); }
/// <summary> /// 作成済みのテクスチャーからidxより、シェーダーリソースビューを作成する /// </summary> /// <param name="idx">0~7</param> /// <param name="device"></param> /// <param name="desc">シェーダーリソースビューの説明</param> /// <returns></returns> internal int CreateShaderResourceView(int idx, ShaderResourceViewDescription desc) { if (idx > 7) { Debug.Assert(false); throw new ArgumentException(); } if (m_aResourceTx[idx] == null) { Debug.Assert(false); throw new NotCreatedException(); } if (m_aTxResourceView[idx] != null) { Debug.Assert(false); throw new CreatedException(); } m_aTxResourceView[idx] = new ShaderResourceView(App.DXDevice, m_aResourceTx[idx], desc); if (m_aTxResourceView[idx] == null) { HasShaderResource = false; return(-1); } m_aTxResourceView[idx].DebugName = "Shader=>" + m_name; HasShaderResource = true; return(0); }
private void Update(EvaluationContext context) { var resourceManager = ResourceManager.Instance(); var buffer = Buffer.GetValue(context); if (buffer != null) { if ((buffer.Description.OptionFlags & ResourceOptionFlags.BufferStructured) == 0) { Log.Warning($"{nameof(SrvFromStructuredBuffer)} - input buffer is not structured, skipping SRV creation."); return; } ShaderResourceView.Value?.Dispose(); var elementCount = buffer.Description.SizeInBytes / buffer.Description.StructureByteStride; var desc = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.ExtendedBuffer, Format = Format.Unknown, BufferEx = new ShaderResourceViewDescription.ExtendedBufferResource() { FirstElement = 0, ElementCount = elementCount } }; ShaderResourceView.Value = new ShaderResourceView(resourceManager.Device, buffer, desc); // todo: create via resource manager ElementCount.Value = elementCount; } }
public bool Initialise(Bitmap bitmap) { RemoveAndDispose(ref _tex); RemoveAndDispose(ref _texSRV); //Debug.Assert(bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bmData; Width = bitmap.Width; Height = bitmap.Height; bmData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try { var texDesc = new Texture2DDescription(); texDesc.Width = Width; texDesc.Height = Height; texDesc.MipLevels = 1; texDesc.ArraySize = 1; texDesc.Format = Format.B8G8R8A8_UNorm; texDesc.SampleDescription.Count = 1; texDesc.SampleDescription.Quality = 0; texDesc.Usage = ResourceUsage.Immutable; texDesc.BindFlags = BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.OptionFlags = ResourceOptionFlags.None; DataBox data; data.DataPointer = bmData.Scan0; data.RowPitch = bmData.Stride; // _texWidth * 4; data.SlicePitch = 0; _tex = ToDispose(new Texture2D(Device, texDesc, new[] { data })); if (_tex == null) { return(false); } var srvDesc = new ShaderResourceViewDescription(); srvDesc.Format = Format.B8G8R8A8_UNorm; srvDesc.Dimension = ShaderResourceViewDimension.Texture2D; srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MostDetailedMip = 0; _texSRV = ToDispose(new ShaderResourceView(Device, _tex, srvDesc)); if (_texSRV == null) { return(false); } } finally { bitmap.UnlockBits(bmData); } _initialised = true; return(true); }
public DX11RawBuffer(Device dev, int size, DX11RawBufferFlags flags = new DX11RawBufferFlags()) { this.Size = size; BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.RawBuffer, SizeInBytes = this.Size, Usage = ResourceUsage.Default, }; this.Buffer = new Buffer(dev, bd); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = ShaderResourceViewExtendedBufferFlags.RawData, ElementCount = size / 4 }; this.SRV = new ShaderResourceView(dev, this.Buffer, srvd); UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = UnorderedAccessViewDimension.Buffer, Flags = UnorderedAccessViewBufferFlags.RawData, ElementCount = size / 4 }; this.UAV = new UnorderedAccessView(dev, this.Buffer, uavd); }
/// <summary> /// Constructor /// Creates the texture we will render to based on the supplied width and height /// </summary> /// <param name="device">The device we will create the texture with</param> /// <param name="texWidth"></param> /// <param name="texHeight"></param> public RenderTexture(Device device, int texWidth, int texHeight) { Texture2DDescription textureDescription = new Texture2DDescription() { Width = texWidth, Height = texHeight, MipLevels = 1, ArraySize = 1, Format = SlimDX.DXGI.Format.R32G32B32A32_Float, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, }; Texture = new Texture2D(device, textureDescription); RenderTargetViewDescription renderTargetViewDescription = new RenderTargetViewDescription() { Format = textureDescription.Format, Dimension = RenderTargetViewDimension.Texture2D, MipSlice = 0, }; renderTargetView = new RenderTargetView(device, Texture, renderTargetViewDescription); ShaderResourceViewDescription shaderResourceViewDescription = new ShaderResourceViewDescription() { Format = textureDescription.Format, Dimension = ShaderResourceViewDimension.Texture2D, MostDetailedMip = 0, MipLevels = 1 }; shaderResourceView = new ShaderResourceView(device, Texture, shaderResourceViewDescription); }
private void CreateNew(int width, int height, Format format, DataBox[] boxes) { if (mTexture != gDefaultTexture) { mTexture.Dispose(); NativeView.Dispose(); } var desc = mTexture.Description; desc.Width = width; desc.Height = height; desc.Format = format; desc.Usage = ResourceUsage.Default; mTexture = new Texture2D(mContext.Device, desc, boxes); var srvd = new ShaderResourceViewDescription { Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, Format = format, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = boxes.Length, MostDetailedMip = 0 } }; NativeView = new ShaderResourceView(mContext.Device, mTexture, srvd); }
public D3DDepthStencil CreateDepthStencil(int width, int height) { var description = new Texture2DDescription(); description.Width = width; description.Height = height; description.ArraySize = 1; description.BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource; description.CpuAccessFlags = CpuAccessFlags.None; description.MipLevels = 1; description.OptionFlags = ResourceOptionFlags.None; description.SampleDescription.Count = 1; description.Usage = ResourceUsage.Default; description.Format = Format.R32_Typeless; var texture = new Texture2D(device, description); var depthDescription = new DepthStencilViewDescription(); depthDescription.Dimension = DepthStencilViewDimension.Texture2D; depthDescription.Flags = DepthStencilViewFlags.None; depthDescription.Format = Format.D32_Float; depthDescription.Texture2D.MipSlice = 0; var depthStencil = new DepthStencilView(device, texture, depthDescription); var srvDescription = new ShaderResourceViewDescription(); srvDescription.Format = Format.R32_Float; srvDescription.Dimension = ShaderResourceViewDimension.Texture2D; srvDescription.Texture2D.MipLevels = 1; srvDescription.Texture2D.MostDetailedMip = 0; var depthSrv = new ShaderResourceView(device, texture, srvDescription); return(new D3DDepthStencil(texture, depthStencil, depthSrv)); }
public DX11DynamicRawBuffer(Device dev, int size) { this.Size = size; BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.RawBuffer, SizeInBytes = this.Size, Usage = ResourceUsage.Dynamic, }; this.Buffer = new Buffer(dev, bd); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = ShaderResourceViewExtendedBufferFlags.RawData, ElementCount = size / 4 }; this.SRV = new ShaderResourceView(dev, this.Buffer, srvd); }
/// <summary> /// Create a raw buffer based UAV /// </summary> /// <param name="device">The device.</param> /// <param name="bufferDesc">The buffer desc.</param> /// <param name="uavDesc">The uav desc.</param> /// <param name="srvDesc">The SRV desc.</param> public UAVBufferViewProxy(Device device, ref BufferDescription bufferDesc, ref UnorderedAccessViewDescription uavDesc, ref ShaderResourceViewDescription srvDesc) : this(device, ref bufferDesc, ref uavDesc) { srv = new ShaderResourceViewProxy(device, resource); srv.CreateTextureView(); }
public bool Initialise(Device device, string fileName) { try { using (var texture = LoadFromFile(device, new ImagingFactory(), fileName)) { var shaderResourceViewDescription = new ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = ShaderResourceViewDimension.Texture2D }; shaderResourceViewDescription.Texture2D.MostDetailedMip = 0; shaderResourceViewDescription.Texture2D.MipLevels = -1; TextureResource = new ShaderResourceView(device, texture, shaderResourceViewDescription); device.ImmediateContext.GenerateMips(TextureResource); } return(true); } catch (Exception ex) { //Log.WriteToFile(ErrorLevel.Error, "Texture.Initialise", ex, true); return(false); } }
public DX11CubeDepthStencil(DX11RenderContext context, int size, SampleDescription sd, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, MipLevels = 1 }; this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.SliceDSV = new DX11SliceDepthStencil[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize= 6, Dimension = DepthStencilViewDimension.Texture2DArray, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format), MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); for (int i = 0; i < 6; i++) { this.SliceDSV[i] = new DX11SliceDepthStencil(context, this, i, DepthFormatsHelper.GetDepthFormat(format)); } }
public DX11StructuredBufferRegion(DxDevice device, DX11StructuredBuffer parentBuffer, int StartOffset, int ElementCount) { this.Buffer = parentBuffer.Buffer; this.ElementCount = ElementCount; this.Stride = parentBuffer.Stride; UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Format = SharpDX.DXGI.Format.Unknown, Dimension = UnorderedAccessViewDimension.Buffer, Buffer = new UnorderedAccessViewDescription.BufferResource() { ElementCount = this.ElementCount, Flags = parentBuffer.UnorderedView.Description.Buffer.Flags, FirstElement = StartOffset } }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SharpDX.DXGI.Format.Unknown, Dimension = ShaderResourceViewDimension.Buffer, BufferEx = new ShaderResourceViewDescription.ExtendedBufferResource() { ElementCount = this.ElementCount, FirstElement = StartOffset } }; this.ShaderView = new ShaderResourceView(device, parentBuffer.Buffer, srvd); this.UnorderedView = new UnorderedAccessView(device, parentBuffer.Buffer, uavd); }
/// <summary> /// Gets a <see cref="ShaderResourceView"/> for a particular <see cref="PixelFormat"/>. /// </summary> /// <param name="viewFormat">The view format.</param> /// <returns>A <see cref="ShaderResourceView"/> for the particular view format.</returns> /// <remarks> /// The buffer must have been declared with <see cref="Graphics.BufferFlags.ShaderResource"/>. /// The ShaderResourceView instance is kept by this buffer and will be disposed when this buffer is disposed. /// </remarks> internal CpuDescriptorHandle GetShaderResourceView(PixelFormat viewFormat) { var srv = new CpuDescriptorHandle(); if ((ViewFlags & BufferFlags.ShaderResource) != 0) { var description = new ShaderResourceViewDescription { Shader4ComponentMapping = 0x00001688, Format = (SharpDX.DXGI.Format)viewFormat, Dimension = SharpDX.Direct3D12.ShaderResourceViewDimension.Buffer, Buffer = { ElementCount = this.ElementCount, FirstElement = 0, Flags = BufferShaderResourceViewFlags.None, StructureByteStride = StructureByteStride, } }; if (((ViewFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer)) { description.Buffer.Flags |= BufferShaderResourceViewFlags.Raw; } srv = GraphicsDevice.ShaderResourceViewAllocator.Allocate(1); NativeDevice.CreateShaderResourceView(NativeResource, description, srv); } return(srv); }
public bool Initialize(D3DDevice device, string filename) { try { using (Texture2D texture = LoadFromFile(device, new SharpDX.WIC.ImagingFactory(), filename)) { ShaderResourceViewDescription desc = new ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D }; desc.Texture2D.MostDetailedMip = 0; desc.Texture2D.MipLevels = -1; TextureResource = new ShaderResourceView(device, texture, desc); device.ImmediateContext.GenerateMips(TextureResource); return(true); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
private void PlatformSetTexture(int index, Texture texture) { var deviceResource = texture?.DeviceResource; var format = deviceResource?.Description.Format ?? SharpDX.DXGI.Format.BC1_UNorm; var dimension = deviceResource?.Description.Dimension ?? ResourceDimension.Texture2D; var description = new ShaderResourceViewDescription { Shader4ComponentMapping = ComponentMappingUtility.DefaultComponentMapping(), Format = format }; switch (dimension) { case ResourceDimension.Texture2D: description.Dimension = ShaderResourceViewDimension.Texture2D; description.Texture2D.MipLevels = -1; break; default: throw new ArgumentOutOfRangeException(); } GraphicsDevice.Device.CreateShaderResourceView( deviceResource, description, _cbvUavSrvPoolEntry.GetCpuHandle(index)); }
public DX11ImmutableRawBuffer(DX11RenderContext renderContext, DataStream data, int size) { this.renderContext = renderContext; this.Size = size; BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.RawBuffer, SizeInBytes = this.Size, Usage = ResourceUsage.Immutable, }; this.Buffer = new Buffer(this.renderContext.Device, data, bd); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = ShaderResourceViewExtendedBufferFlags.RawData, ElementCount = size / 4 }; this.SRV = new ShaderResourceView(this.renderContext.Device, this.Buffer, srvd); }
public Buffer CreateBufferDynamic(int elements, int elementSize, int slot) { if (elementSize == 1) // DirectX doesn't like non-4-byte element size, we here just padd the element size to 4. { elementSize = 4; elements = (elements + 3) / 4; } if ((elements > (1 << 29)) || (elements < 0)) { throw new System.Exception(string.Format( "GPU Dynamic-buffer size limit overflow! Total number of floats {0:n0} must be smaller than {1:n0} ", elements, 1 << 29)); } Buffer buf = new Buffer(device, new BufferDescription { BindFlags = BindFlags.ShaderResource, OptionFlags = ResourceOptionFlags.BufferStructured, SizeInBytes = elements * elementSize, StructureByteStride = elementSize, Usage = ResourceUsage.Dynamic, CpuAccessFlags = CpuAccessFlags.Write, }); var srvDesc = new ShaderResourceViewDescription(); srvDesc.Format = SharpDX.DXGI.Format.Unknown; srvDesc.Buffer.ElementCount = elements; srvDesc.Buffer.ElementWidth = elements; srvDesc.Dimension = ShaderResourceViewDimension.Buffer; using (var srv = new ShaderResourceView(device, buf, srvDesc)) ctx.ComputeShader.SetShaderResource(slot, srv); return(buf); }
private void BuildDescriptors() { var srvDesc = new ShaderResourceViewDescription { Shader4ComponentMapping = D3DUtil.DefaultShader4ComponentMapping, Format = _format, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MostDetailedMip = 0, MipLevels = 1 } }; var uavDesc = new UnorderedAccessViewDescription { Format = _format, Dimension = UnorderedAccessViewDimension.Texture2D, Texture2D = new UnorderedAccessViewDescription.Texture2DResource { MipSlice = 0 } }; _device.CreateShaderResourceView(_blurMap0, srvDesc, _blur0CpuSrv); _device.CreateUnorderedAccessView(_blurMap0, null, uavDesc, _blur0CpuUav); _device.CreateShaderResourceView(_blurMap1, srvDesc, _blur1CpuSrv); _device.CreateUnorderedAccessView(_blurMap1, null, uavDesc, _blur1CpuUav); }
private void BuildDescriptors() { // Create SRV to resource so we can sample the shadow map in a shader program. var srvDesc = new ShaderResourceViewDescription { Shader4ComponentMapping = D3DUtil.DefaultShader4ComponentMapping, Format = Format.R24_UNorm_X8_Typeless, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MostDetailedMip = 0, MipLevels = 1, ResourceMinLODClamp = 0.0f, PlaneSlice = 0 } }; _device.CreateShaderResourceView(Resource, srvDesc, _cpuSrv); // Create DSV to resource so we can render to the shadow map. var dsvDesc = new DepthStencilViewDescription { Flags = DepthStencilViewFlags.None, Dimension = DepthStencilViewDimension.Texture2D, Format = Format.D24_UNorm_S8_UInt, Texture2D = new DepthStencilViewDescription.Texture2DResource { MipSlice = 0 } }; _device.CreateDepthStencilView(Resource, dsvDesc, _cpuDsv); }
public static ShaderResourceView CreateRandomTexture1DSRV(Device device) { var randomValues = new List <Vector4>(); for (int i = 0; i < 1024; i++) { randomValues.Add(new Vector4(MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f))); } var texDesc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32G32B32A32_Float, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Immutable, Width = 1024 }; var randTex = new Texture1D(device, texDesc, new DataStream(randomValues.ToArray(), false, false)); var viewDesc = new ShaderResourceViewDescription() { Format = texDesc.Format, Dimension = ShaderResourceViewDimension.Texture1D, MipLevels = texDesc.MipLevels, MostDetailedMip = 0 }; var randTexSRV = new ShaderResourceView(device, randTex, viewDesc); ReleaseCom(ref randTex); return(randTexSRV); }
public DX11MipSliceRenderTarget2D(DX11RenderContext context, DX11Texture2D texture, int mipindex, int w, int h) { this.context = context; this.Resource = texture.Resource; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture2D, Format = texture.Format, MipSlice = mipindex }; UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Dimension = UnorderedAccessViewDimension.Texture2D, Format = texture.Format, MipSlice = mipindex, }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription(); srvd.Dimension = ShaderResourceViewDimension.Texture2D; srvd.MipLevels = 1; srvd.MostDetailedMip = mipindex; srvd.Format = texture.Format; this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd); }
public void OnDeviceInitInternal() { { Texture2DDescription desc = new Texture2DDescription(); desc.Width = Size.X; desc.Height = Size.Y; desc.Format = m_resourceFormat; desc.ArraySize = 1; desc.MipLevels = m_mipmapLevels; desc.BindFlags = m_bindFlags; desc.Usage = m_resourceUsage; desc.CpuAccessFlags = m_cpuAccessFlags; desc.SampleDescription.Count = m_samplesCount; desc.SampleDescription.Quality = m_samplesQuality; desc.OptionFlags = m_roFlags; m_resource = new Texture2D(MyRender11.Device, desc); } { ShaderResourceViewDescription desc = new ShaderResourceViewDescription(); desc.Format = m_srvFormat; desc.Dimension = ShaderResourceViewDimension.Texture2D; desc.Texture2D.MipLevels = m_mipmapLevels; desc.Texture2D.MostDetailedMip = 0; m_srv = new ShaderResourceView(MyRender11.Device, m_resource, desc); } m_resource.DebugName = m_name; m_srv.DebugName = m_name; }
private void PlatformSetStructuredBuffer <T>(int index, StaticBuffer <T> buffer) where T : struct { var deviceResource = buffer?.DeviceBuffer; var description = new ShaderResourceViewDescription { Shader4ComponentMapping = ComponentMappingUtility.DefaultComponentMapping(), Format = buffer != null ? SharpDX.DXGI.Format.Unknown : SharpDX.DXGI.Format.R32_UInt, Dimension = ShaderResourceViewDimension.Buffer, Buffer = { FirstElement = 0, ElementCount = (int)(buffer?.ElementCount ?? 0), StructureByteStride = (int)(buffer?.ElementSizeInBytes ?? 0), Flags = BufferShaderResourceViewFlags.None } }; GraphicsDevice.Device.CreateShaderResourceView( deviceResource, description, _cbvUavSrvPoolEntry.GetCpuHandle(index)); }
public DX11RenderTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1,0), Usage = ResourceUsage.Default, }; this.Resource = new Texture2D(context.Device, texBufferDesc); RenderTargetViewDescription rtd = new RenderTargetViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = RenderTargetViewDimension.Texture2DArray, Format = format }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = format, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); this.RTV = new RenderTargetView(context.Device, this.Resource, rtd); this.SRVArray = new ShaderResourceView[elemcnt]; ShaderResourceViewDescription srvad = new ShaderResourceViewDescription() { ArraySize = 1, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = format, MipLevels = 1, MostDetailedMip = 0 }; for (int i = 0; i < elemcnt; i++) { srvad.FirstArraySlice = i; this.SRVArray[i] = new ShaderResourceView(context.Device, this.Resource, srvad); } this.desc = texBufferDesc; }
/// <summary> /// Creates render target /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public DepthStencilCube( GraphicsDevice device, DepthFormat format, int size, int samples, string debugName = "" ) : base(device) { bool msaa = samples > 1; CheckSamplesCount( samples ); SampleCount = samples; Format = format; SampleCount = samples; Width = size; Height = size; Depth = 1; var texDesc = new Texture2DDescription(); texDesc.Width = Width; texDesc.Height = Height; texDesc.ArraySize = 6; texDesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.ConvertToTex( format ); texDesc.MipLevels = 1; texDesc.OptionFlags = ResourceOptionFlags.TextureCube; texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0); texDesc.Usage = ResourceUsage.Default; texCube = new D3D.Texture2D( device.Device, texDesc ); var srvDesc = new ShaderResourceViewDescription(); srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D; srvDesc.Format = Converter.ConvertToSRV( format ); srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = 1; SRV = new ShaderResourceView( device.Device, texCube ); // // Create surfaces : // surfaces = new DepthStencilSurface[ 6 ]; for ( int face=0; face<6; face++) { var rtvDesc = new DepthStencilViewDescription(); rtvDesc.Texture2DArray.MipSlice = 0; rtvDesc.Texture2DArray.FirstArraySlice = face; rtvDesc.Texture2DArray.ArraySize = 1; rtvDesc.Dimension = msaa ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray; rtvDesc.Format = Converter.ConvertToDSV( format ); var dsv = new DepthStencilView( device.Device, texCube, rtvDesc ); int subResId = Resource.CalculateSubResourceIndex( 0, face, 1 ); surfaces[face] = new DepthStencilSurface( dsv, format, Width, Height, SampleCount ); } }
public void LoadFromLoadInfo(IO.Files.Texture.TextureLoadInfo loadInfo) { var texDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = loadInfo.Format, Height = loadInfo.Height, Width = loadInfo.Width, MipLevels = loadInfo.Layers.Count, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default }; if (mTexture != gDefaultTexture) { if (mTexture != null) mTexture.Dispose(); if (NativeView != null) NativeView.Dispose(); } var boxes = new DataBox[texDesc.MipLevels]; var streams = new DataStream[texDesc.MipLevels]; try { for(var i = 0; i < texDesc.MipLevels; ++i) { streams[i] = new DataStream(loadInfo.Layers[i].Length, true, true); streams[i].WriteRange(loadInfo.Layers[i]); streams[i].Position = 0; boxes[i] = new DataBox(streams[i].DataPointer, loadInfo.RowPitchs[i], 0); } mTexture = new Texture2D(mContext.Device, texDesc, boxes); var srvd = new ShaderResourceViewDescription { Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, Format = loadInfo.Format, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = boxes.Length, MostDetailedMip = 0 } }; NativeView = new ShaderResourceView(mContext.Device, mTexture, srvd); } finally { foreach (var stream in streams) { if (stream != null) stream.Dispose(); } } }
/// <summary> /// Creates depth stencil texture, view and shader resource with format D24S8 /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public DepthStencil2D( GraphicsDevice device, DepthFormat format, int width, int height, int samples = 1 ) : base(device) { CheckSamplesCount( samples ); Width = width; Height = height; Depth = 1; Format = format; SampleCount = samples; var bindFlags = BindFlags.DepthStencil; if (device.GraphicsProfile==GraphicsProfile.HiDef) { bindFlags |= BindFlags.ShaderResource; } else if (device.GraphicsProfile==GraphicsProfile.Reach) { if (samples==1) { bindFlags |= BindFlags.ShaderResource; } } var texDesc = new Texture2DDescription(); texDesc.Width = width; texDesc.Height = height; texDesc.ArraySize = 1; texDesc.BindFlags = bindFlags; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.ConvertToTex( format ); texDesc.MipLevels = 1; texDesc.OptionFlags = ResourceOptionFlags.None; texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0); texDesc.Usage = ResourceUsage.Default; var dsvDesc = new DepthStencilViewDescription(); dsvDesc.Dimension = samples > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D; dsvDesc.Format = Converter.ConvertToDSV( format ); dsvDesc.Flags = DepthStencilViewFlags.None; var srvDesc = new ShaderResourceViewDescription(); srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D; srvDesc.Format = Converter.ConvertToSRV( format ); srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = 1; tex2D = new D3D.Texture2D ( device.Device, texDesc ); var dsv = new DepthStencilView ( device.Device, tex2D, dsvDesc ); if (bindFlags.HasFlag( BindFlags.ShaderResource)) { SRV = new ShaderResourceView ( device.Device, tex2D, srvDesc ); } surface = new DepthStencilSurface ( dsv, format, width, height, samples ); }
public ShaderResourceView GetSRVSlice(int slice, int count) { ShaderResourceViewDescription rtd = new ShaderResourceViewDescription() { ArraySize = count, FirstArraySlice = slice, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = this.Format }; return new ShaderResourceView(context.Device, this.Resource, rtd); }
private void CreateShaderResourceView() { var shaderResourceViewDesc = new ShaderResourceViewDescription(); shaderResourceViewDesc.ArraySize = layerCount; shaderResourceViewDesc.Dimension = ShaderResourceViewDimension.Texture2DArray; shaderResourceViewDesc.FirstArraySlice = 0; shaderResourceViewDesc.Format = format; shaderResourceViewDesc.MipLevels = 1; shaderResourceViewDesc.MostDetailedMip = 0; shaderResourceViewAsArray = new ShaderResourceView(device, texture, shaderResourceViewDesc); }
public DX11RenderTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format, bool buildslices = true, int miplevels = 0) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = miplevels == 0 ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None, SampleDescription = new SampleDescription(1,0), Usage = ResourceUsage.Default, MipLevels= miplevels }; this.Resource = new Texture2D(context.Device, texBufferDesc); RenderTargetViewDescription rtd = new RenderTargetViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = RenderTargetViewDimension.Texture2DArray, Format = format }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = format, MipLevels = this.Resource.Description.MipLevels, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); this.RTV = new RenderTargetView(context.Device, this.Resource, rtd); this.desc = texBufferDesc; this.SliceRTV = new DX11SliceRenderTarget[this.ElemCnt]; if (buildslices) { for (int i = 0; i < this.ElemCnt; i++) { this.SliceRTV[i] = new DX11SliceRenderTarget(this.context, this, i); } } }
public DX11DepthStencil(DX11RenderContext context, int w, int h, SampleDescription sd, Format format) { this.context = context; var depthBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = h, Width = w, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default }; this.Resource = new Texture2D(context.Device, depthBufferDesc); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = 1, Format = DepthFormatsHelper.GetSRVFormat(format), Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = DepthFormatsHelper.GetDepthFormat(format), Dimension = sd.Count == 1 ? DepthStencilViewDimension.Texture2D : DepthStencilViewDimension.Texture2DMultisampled, MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); //Read only dsv only supported in dx11 minimum if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.desc = depthBufferDesc; this.isowner = true; }
public DX11DepthTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format) { this.context = context; this.original = format; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1,0), Usage = ResourceUsage.Default, }; this.Resource = new Texture2D(context.Device, texBufferDesc); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format),// Format.D32_Float, Dimension = DepthStencilViewDimension.Texture2DArray, MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); this.desc = texBufferDesc; }
public DX11RawBuffer(DX11RenderContext context, Buffer buffer) { this.Size = buffer.Description.SizeInBytes; this.Buffer = buffer; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SlimDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = ShaderResourceViewExtendedBufferFlags.RawData, ElementCount = this.Size / 4 }; this.SRV = new ShaderResourceView(context.Device, this.Buffer, srvd); }
public DX11CubeRenderTarget(DX11RenderContext context, int size, SampleDescription sd, Format format, bool genMipMaps, int mmLevels) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, }; if (genMipMaps && sd.Count == 1) { texBufferDesc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; texBufferDesc.MipLevels = mmLevels; } else { //Make sure we enforce 1 here, as we dont generate texBufferDesc.MipLevels = 1; } this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.FaceRTVs = new RenderTargetView[6]; this.FaceSRVs = new ShaderResourceView[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = format, MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); this.CreateSliceViews(context.Device, format); }
// Static functions static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false) { GPUBufferObject newBuffer = new GPUBufferObject(); // Variables newBuffer.m_Size = size; BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess; BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes); newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description); ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription { FirstElement = 0, ElementCount = size, Format = Format.Unknown, Dimension = ShaderResourceViewDimension.ExtendedBuffer, Flags = 0, }; newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc); UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription { ArraySize = 0, Dimension = UnorderedAccessViewDimension.Buffer, ElementCount = size, Flags = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None, Format = Format.Unknown, MipSlice = 0 }; newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc); if (allowStaging) { description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes); newBuffer.m_StagingBufferObject = new Buffer(device, description); description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4); newBuffer.m_StagingCountBufferObject = new Buffer(device, description); } return newBuffer; }
public void TestNormalizedViewDesc() { var desc = BodyIndexTextureDescriptors.NormalizedView; var expected = new ShaderResourceViewDescription() { Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, Format = SharpDX.DXGI.Format.R8_UNorm, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }; Assert.AreEqual(desc, expected); }
public ShadowMap(Device device, int width, int height) { _width = width; _height = height; _viewport = new Viewport(0, 0, _width, _height, 0, 1.0f); var texDesc = new Texture2DDescription { Width = _width, Height = _height, MipLevels = 1, ArraySize = 1, Format = Format.R24G8_Typeless, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; var depthMap = new Texture2D(device, texDesc) { DebugName = "shadowmap depthmap" }; var dsvDesc = new DepthStencilViewDescription { Flags = DepthStencilViewFlags.None, Format = Format.D24_UNorm_S8_UInt, Dimension = DepthStencilViewDimension.Texture2D, Texture2D = new DepthStencilViewDescription.Texture2DResource() { MipSlice = 0 } }; _depthMapDSV = new DepthStencilView(device, depthMap, dsvDesc); var srvDesc = new ShaderResourceViewDescription { Format = Format.R24_UNorm_X8_Typeless, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = texDesc.MipLevels, MostDetailedMip = 0 } }; DepthMapSRV = new ShaderResourceView(device, depthMap, srvDesc); Utilities.Dispose(ref depthMap); }
public DX11TextureArray2D(DX11RenderContext context, Texture2D resource) { this.context = context; this.desc = resource.Description; this.Resource = resource; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = this.desc.ArraySize, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = this.desc.Format, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); }
public void OnDeviceInit() { { ShaderResourceViewDescription desc = new ShaderResourceViewDescription(); desc.Format = m_format; desc.Dimension = ShaderResourceViewDimension.Texture2D; desc.Texture2D.MipLevels = 1; desc.Texture2D.MostDetailedMip = 0; m_srv = new ShaderResourceView(MyRender11.Device, m_owner.Resource, desc); m_srv.DebugName = m_owner.Name; } { RenderTargetViewDescription desc = new RenderTargetViewDescription(); desc.Format = m_format; desc.Dimension = RenderTargetViewDimension.Texture2D; desc.Texture2D.MipSlice = 0; m_rtv = new RenderTargetView(MyRender11.Device, m_owner.Resource, desc); m_rtv.DebugName = m_owner.Name; } }
public DX11MipSliceRenderTarget3D(DX11RenderContext context, DX11Texture3D texture, int mipindex, int w, int h, int d) : base(context) { this.Resource = texture.Resource; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture3D, Format = texture.Format, MipSlice = mipindex, DepthSliceCount = d }; UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Dimension = UnorderedAccessViewDimension.Texture3D, Format = texture.Format, MipSlice = mipindex, FirstDepthSlice = 0, DepthSliceCount = d }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription(); srvd.Dimension = ShaderResourceViewDimension.Texture3D; srvd.MipLevels = 1; srvd.MostDetailedMip = mipindex; srvd.Format = texture.Format; srvd.ArraySize = d; srvd.FirstArraySlice = 0; this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd); this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd); this.UAV = new UnorderedAccessView(context.Device, texture.Resource, uavd); this.Width = w; this.Height = h; this.Depth = d; }
public void LoadFromData(SharpDX.DXGI.Format format, int width, int height, int numTextures, int numMips, params DataBox[] datas) { var textureDesc = new Texture2DDescription { ArraySize = numTextures, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = height, Width = width, MipLevels = numMips, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Default }; if (mTexture != null) mTexture.Dispose(); mTexture = new Texture2D(mDevice.Device, textureDesc, datas); var srvd = new ShaderResourceViewDescription { Format = format, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray, Texture2DArray = new ShaderResourceViewDescription.Texture2DArrayResource { ArraySize = numTextures, FirstArraySlice = 0, MipLevels = -1, MostDetailedMip = 0 } }; if (mView != null) mView.Dispose(); mView = new ShaderResourceView(mDevice.Device, mTexture, srvd); }
// Simple DDS loader ported from http://msdn.microsoft.com/en-us/library/windows/apps/jj651550.aspx static void CreateD3DResources( SharpDX.Direct3D11.Device d3dDevice, TextureDimension resDim, int width, int height, int depth, int mipCount, int arraySize, Format format, bool isCubeMap, DataBox[] initData, //_In_reads_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData, out SharpDX.Direct3D11.Resource texture, out SharpDX.Direct3D11.ShaderResourceView textureView //_Out_opt_ ID3D11Resource** texture, //_Out_opt_ ID3D11ShaderResourceView** textureView ) { texture = null; textureView = null; if (d3dDevice == null || initData == null) { return; } switch (resDim) { case TextureDimension.Texture1D:// D3D11_RESOURCE_DIMENSION_TEXTURE1D: { Texture1DDescription desc = new Texture1DDescription(); //D3D11_TEXTURE1D_DESC desc; desc.Width = width; desc.MipLevels = mipCount; desc.ArraySize = arraySize; desc.Format = format; desc.Usage = ResourceUsage.Default; desc.BindFlags = BindFlags.ShaderResource;// D3D11_BIND_SHADER_RESOURCE; desc.CpuAccessFlags = CpuAccessFlags.None; desc.OptionFlags = ResourceOptionFlags.None; Texture1D tex = null; //ID3D11Texture1D* tex = nullptr; tex = new Texture1D(d3dDevice, desc, initData); //hr = d3dDevice->CreateTexture1D(&desc, initData, &tex); if (tex != null) { ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription(); //D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; //memset(&SRVDesc, 0, sizeof(SRVDesc)); SRVDesc.Format = format; if (arraySize > 1) { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray;// D3D_SRV_DIMENSION_TEXTURE1DARRAY; SRVDesc.Texture1DArray.MipLevels = desc.MipLevels; SRVDesc.Texture1DArray.ArraySize = arraySize; } else { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D;// D3D_SRV_DIMENSION_TEXTURE1D; SRVDesc.Texture1D.MipLevels = desc.MipLevels; } textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc); //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView); if (textureView == null) { tex.Dispose(); return; } texture = tex; } } break; case TextureDimension.TextureCube: case TextureDimension.Texture2D:// D3D11_RESOURCE_DIMENSION_TEXTURE2D: { Texture2DDescription desc = new Texture2DDescription(); desc.Width = width; desc.Height = height; desc.MipLevels = mipCount; desc.ArraySize = arraySize; desc.Format = format; desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; desc.Usage = ResourceUsage.Default; desc.BindFlags = BindFlags.ShaderResource; desc.CpuAccessFlags = CpuAccessFlags.None; desc.OptionFlags = (isCubeMap) ? ResourceOptionFlags.TextureCube : ResourceOptionFlags.None; Texture2D tex = null; tex = new Texture2D(d3dDevice, desc, initData); tex.DebugName = "Test"; //hr = d3dDevice->CreateTexture2D(&desc, initData, &tex); if (tex != null) { ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription(); SRVDesc.Format = format; if (isCubeMap) { if (arraySize > 6) { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray; SRVDesc.TextureCubeArray.MipLevels = desc.MipLevels; // Earlier we set arraySize to (NumCubes * 6) SRVDesc.TextureCubeArray.CubeCount = arraySize / 6; } else { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube; SRVDesc.TextureCube.MipLevels = desc.MipLevels; } } else if (arraySize > 1) { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray; SRVDesc.Texture2DArray.MipLevels = desc.MipLevels; SRVDesc.Texture2DArray.ArraySize = arraySize; } else { SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D; SRVDesc.Texture2D.MipLevels = desc.MipLevels; } textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc); //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView); texture = tex; } } break; case TextureDimension.Texture3D: { Texture3DDescription desc = new Texture3DDescription(); desc.Width = width; desc.Height = height; desc.Depth = depth; desc.MipLevels = mipCount; desc.Format = format; desc.Usage = ResourceUsage.Default; desc.BindFlags = BindFlags.ShaderResource; desc.CpuAccessFlags = CpuAccessFlags.None; desc.OptionFlags = ResourceOptionFlags.None; Texture3D tex = null; tex = new Texture3D(d3dDevice, desc, initData); //hr = d3dDevice->CreateTexture3D(&desc, initData, &tex); if (tex != null) { ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription(); SRVDesc.Format = format; SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D; SRVDesc.Texture3D.MipLevels = desc.MipLevels; textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc); texture = tex; } } break; } }
/// <summary> /// Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> for accessing resource data. /// </summary> /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" />.</param> /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param> /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> to be created.</param> /// <msdn-id>ff476519</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateShaderResourceView([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc,[Out, Fast] ID3D11ShaderResourceView** ppSRView)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateShaderResourceView</unmanaged-short> public ShaderResourceView(Device device, Resource resource, ShaderResourceViewDescription description) : base(IntPtr.Zero) { device.CreateShaderResourceView(resource, description, this); }
public void OnDeviceInit(MyDepthStencil owner, ShaderResourceViewDescription desc) { m_owner = owner; m_srv = new ShaderResourceView(MyRender11.Device, m_owner.Resource, desc); m_srv.DebugName = owner.Name; }
public void OnDeviceInit() { Texture2DDescription desc = new Texture2DDescription(); desc.Width = Size.X; desc.Height = Size.Y; desc.Format = m_resourceFormat; desc.ArraySize = 1; desc.MipLevels = 1; desc.BindFlags = BindFlags.ShaderResource | BindFlags.DepthStencil; desc.Usage = ResourceUsage.Default; desc.CpuAccessFlags = 0; desc.SampleDescription.Count = m_samplesCount; desc.SampleDescription.Quality = m_samplesQuality; desc.OptionFlags = 0; m_resource = new Texture2D(MyRender11.Device, desc); m_resource.DebugName = Name; DepthStencilViewDescription dsvDesc = new DepthStencilViewDescription(); dsvDesc.Format = m_dsvFormat; if (m_samplesCount == 1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2D; dsvDesc.Flags = DepthStencilViewFlags.None; dsvDesc.Texture2D.MipSlice = 0; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled; dsvDesc.Flags = DepthStencilViewFlags.None; } m_dsv = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc); if (m_samplesCount == 1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2D; dsvDesc.Flags = DepthStencilViewFlags.ReadOnlyDepth; dsvDesc.Texture2D.MipSlice = 0; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled; dsvDesc.Flags = DepthStencilViewFlags.ReadOnlyDepth; } m_dsv_roDepth = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc); if (m_samplesCount == 1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2D; dsvDesc.Flags = DepthStencilViewFlags.ReadOnlyStencil; dsvDesc.Texture2D.MipSlice = 0; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled; dsvDesc.Flags = DepthStencilViewFlags.ReadOnlyStencil; } m_dsv_roStencil = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc); dsvDesc.Flags = DepthStencilViewFlags.ReadOnlyStencil | DepthStencilViewFlags.ReadOnlyDepth; if (m_samplesCount == 1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2D; dsvDesc.Texture2D.MipSlice = 0; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled; } m_dsv_ro = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc); ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription(); srvDesc.Format = m_srvDepthFormat; if (m_samplesCount == 1) { srvDesc.Dimension = ShaderResourceViewDimension.Texture2D; srvDesc.Texture2D.MipLevels = -1; srvDesc.Texture2D.MostDetailedMip = 0; } else { srvDesc.Dimension = ShaderResourceViewDimension.Texture2DMultisampled; } m_srvDepth.OnDeviceInit(this, srvDesc); srvDesc.Format = m_srvStencilFormat; if (m_samplesCount == 1) { srvDesc.Dimension = ShaderResourceViewDimension.Texture2D; srvDesc.Texture2D.MipLevels = -1; srvDesc.Texture2D.MostDetailedMip = 0; } else { srvDesc.Dimension = ShaderResourceViewDimension.Texture2DMultisampled; } m_srvStencil.OnDeviceInit(this, srvDesc); }