/// <summary> /// Initializes a new instance of the <see cref="RenderTargetViewDescription1"/> struct. /// </summary> /// <param name="viewDimension">The <see cref="RenderTargetViewDimension"/></param> /// <param name="format">The <see cref="DXGI.Format"/> to use or <see cref="Format.Unknown"/>.</param> /// <param name="mipSlice">The index of the mipmap level to use mip slice. or first element for <see cref="RenderTargetViewDimension.Buffer"/>.</param> /// <param name="firstArraySlice">The index of the first texture to use in an array of textures or NumElements for <see cref="RenderTargetViewDimension.Buffer"/>, FirstWSlice for <see cref="RenderTargetViewDimension.Texture3D"/>.</param> /// <param name="arraySize">Number of textures in the array or WSize for <see cref="RenderTargetViewDimension.Texture3D"/>. </param> /// <param name="planeSlice"></param> public RenderTargetViewDescription1( RenderTargetViewDimension viewDimension, Format format = Format.Unknown, int mipSlice = 0, int firstArraySlice = 0, int arraySize = -1, int planeSlice = 0) : this() { Format = format; ViewDimension = viewDimension; switch (viewDimension) { case RenderTargetViewDimension.Buffer: Buffer.FirstElement = mipSlice; Buffer.NumElements = firstArraySlice; break; case RenderTargetViewDimension.Texture1D: Texture1D.MipSlice = mipSlice; break; case RenderTargetViewDimension.Texture1DArray: Texture1DArray.MipSlice = mipSlice; Texture1DArray.FirstArraySlice = firstArraySlice; Texture1DArray.ArraySize = arraySize; break; case RenderTargetViewDimension.Texture2D: Texture2D.MipSlice = mipSlice; Texture2D.PlaneSlice = planeSlice; break; case RenderTargetViewDimension.Texture2DArray: Texture2DArray.MipSlice = mipSlice; Texture2DArray.FirstArraySlice = firstArraySlice; Texture2DArray.ArraySize = arraySize; Texture2DArray.PlaneSlice = planeSlice; break; case RenderTargetViewDimension.Texture2DMultisampled: break; case RenderTargetViewDimension.Texture2DMultisampledArray: Texture2DMSArray.FirstArraySlice = firstArraySlice; Texture2DMSArray.ArraySize = arraySize; break; case RenderTargetViewDimension.Texture3D: Texture3D.MipSlice = mipSlice; Texture3D.FirstWSlice = firstArraySlice; Texture3D.WSize = arraySize; break; default: break; } }
/// <summary> /// Initializes a new instance of the <see cref="RenderTargetViewDescription"/> struct. /// </summary> /// <param name="texture"></param> /// <param name="viewDimension"></param> /// <param name="format"></param> /// <param name="mipSlice"></param> /// <param name="firstArraySlice"></param> /// <param name="arraySize"></param> /// <param name="planeSlice"></param> public RenderTargetViewDescription1( ID3D11Texture2D texture, RenderTargetViewDimension viewDimension, Format format = Format.Unknown, int mipSlice = 0, int firstArraySlice = 0, int arraySize = -1, int planeSlice = 0) : this() { ViewDimension = viewDimension; if (format == Format.Unknown || (-1 == arraySize && (RenderTargetViewDimension.Texture2DArray == viewDimension || RenderTargetViewDimension.Texture2DMultisampledArray == viewDimension))) { var textureDesc = texture.Description; if (format == Format.Unknown) { format = textureDesc.Format; } if (-1 == arraySize) { arraySize = textureDesc.ArraySize - firstArraySlice; } } Format = format; switch (viewDimension) { case RenderTargetViewDimension.Texture2D: Texture2D.MipSlice = mipSlice; Texture2D.PlaneSlice = planeSlice; break; case RenderTargetViewDimension.Texture2DArray: Texture2DArray.MipSlice = mipSlice; Texture2DArray.FirstArraySlice = firstArraySlice; Texture2DArray.ArraySize = arraySize; Texture2DArray.PlaneSlice = planeSlice; break; case RenderTargetViewDimension.Texture2DMultisampled: break; case RenderTargetViewDimension.Texture2DMultisampledArray: Texture2DMSArray.FirstArraySlice = firstArraySlice; Texture2DMSArray.ArraySize = arraySize; break; default: break; } }
public void Init(Device device, int w, int h, Format f, int sc, int sq, bool depth, Format df) { VramUsage = 0; Multisampled = (sc > 1); UseDepth = depth; ResourceUsage u = ResourceUsage.Default; BindFlags b = BindFlags.RenderTarget | BindFlags.ShaderResource; RenderTargetViewDimension rtvd = RenderTargetViewDimension.Texture2D; ShaderResourceViewDimension srvd = ShaderResourceViewDimension.Texture2D;// D3D11_SRV_DIMENSION_TEXTURE2D; int fs = DXUtility.ElementSize(f); int wh = w * h; BindFlags db = BindFlags.DepthStencil;// | BindFlags.ShaderResource;// D3D11_BIND_DEPTH_STENCIL; DepthStencilViewDimension dsvd = DepthStencilViewDimension.Texture2D; Format dtexf = GetDepthTexFormat(df); Format dsrvf = GetDepthSrvFormat(df); Texture = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, 1, 0, u, b, 0, 0); RTV = DXUtility.CreateRenderTargetView(device, Texture, f, rtvd, 0, 0, 0); SRV = DXUtility.CreateShaderResourceView(device, Texture, f, srvd, 1, 0, 0, 0); VramUsage += (wh * fs); if (Multisampled) { b = BindFlags.RenderTarget; rtvd = RenderTargetViewDimension.Texture2DMultisampled; dsvd = DepthStencilViewDimension.Texture2DMultisampled; //srvd = ShaderResourceViewDimension.Texture2DMultisampled; TextureMS = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, sc, sq, u, b, 0, 0); MSRTV = DXUtility.CreateRenderTargetView(device, TextureMS, f, rtvd, 0, 0, 0); VramUsage += (wh * fs) * sc; if (depth) { DepthMS = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, sc, sq, u, db, 0, 0); MSDSV = DXUtility.CreateDepthStencilView(device, DepthMS, df, dsvd); //DepthSRV = DXUtility.CreateShaderResourceView(device, DepthMS, dsrvf, srvd, 1, 0, 0, 0); VramUsage += (wh * DXUtility.ElementSize(df)) * sc; } } else { if (depth) { Depth = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, sc, sq, u, db, 0, 0); DSV = DXUtility.CreateDepthStencilView(device, Depth, df, dsvd); //DepthSRV = DXUtility.CreateShaderResourceView(device, Depth, dsrvf, srvd, 1, 0, 0, 0); VramUsage += (wh * DXUtility.ElementSize(df)); } } }
public void Init(Device device, int w, int h, int count, Format f, bool depth, Format df, int multisamplecount) { Count = count; VramUsage = 0; UseDepth = depth; MultisampleCount = multisamplecount; Multisampled = (multisamplecount > 1); ResourceUsage u = ResourceUsage.Default; BindFlags b = BindFlags.RenderTarget | BindFlags.ShaderResource; int fs = DXUtility.ElementSize(f); int wh = w * h; BindFlags db = BindFlags.DepthStencil | BindFlags.ShaderResource; // D3D11_BIND_DEPTH_STENCIL; RenderTargetViewDimension rtvd = RenderTargetViewDimension.Texture2D; ShaderResourceViewDimension srvd = ShaderResourceViewDimension.Texture2D; // D3D11_SRV_DIMENSION_TEXTURE2D; DepthStencilViewDimension dsvd = DepthStencilViewDimension.Texture2D; if (Multisampled) { rtvd = RenderTargetViewDimension.Texture2DMultisampled; srvd = ShaderResourceViewDimension.Texture2DMultisampled; dsvd = DepthStencilViewDimension.Texture2DMultisampled; } Textures = new Texture2D[count]; RTVs = new RenderTargetView[count]; SRVs = new ShaderResourceView[count]; for (int i = 0; i < count; i++) { Textures[i] = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, multisamplecount, 0, u, b, 0, 0); RTVs[i] = DXUtility.CreateRenderTargetView(device, Textures[i], f, rtvd, 0, 0, 0); SRVs[i] = DXUtility.CreateShaderResourceView(device, Textures[i], f, srvd, 1, 0, 0, 0); VramUsage += (wh * fs) * multisamplecount; } if (depth) { Format dtexf = GpuTexture.GetDepthTexFormat(df); Format dsrvf = GpuTexture.GetDepthSrvFormat(df); Depth = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, multisamplecount, 0, u, db, 0, 0); DSV = DXUtility.CreateDepthStencilView(device, Depth, df, dsvd); DepthSRV = DXUtility.CreateShaderResourceView(device, Depth, dsrvf, srvd, 1, 0, 0, 0); VramUsage += (wh * DXUtility.ElementSize(df)) * multisamplecount; } }
public static RenderTargetView CreateRenderTargetView(Device device, Resource renderTarget, Format format, RenderTargetViewDimension viewDimension, int mipSlice, int arraySize, int firstArraySlice) { RenderTargetView rtv; RenderTargetViewDescription rtvd = new RenderTargetViewDescription(); rtvd.Format = format; rtvd.Dimension = viewDimension; switch (viewDimension) { case RenderTargetViewDimension.Buffer: // D3D11_RTV_DIMENSION_BUFFER: rtvd.Buffer.ElementOffset = mipSlice; rtvd.Buffer.ElementWidth = arraySize * ElementSize(format); // arraySize; //assume square buffer... is this the width? rtvd.Buffer.FirstElement = 0 * ElementSize(format); //firstArraySlice; rtvd.Buffer.ElementCount = arraySize; //*arraySize*ElementSize(format); //does this represent the height?? break; case RenderTargetViewDimension.Texture2D: // D3D11_RTV_DIMENSION_TEXTURE2D: rtvd.Texture2D.MipSlice = mipSlice; break; case RenderTargetViewDimension.Texture2DArray: // D3D11_RTV_DIMENSION_TEXTURE2DARRAY: rtvd.Texture2DArray.MipSlice = mipSlice; rtvd.Texture2DArray.ArraySize = arraySize; rtvd.Texture2DArray.FirstArraySlice = firstArraySlice; break; case RenderTargetViewDimension.Texture2DMultisampled: // D3D11_RTV_DIMENSION_TEXTURE2DMS: break; case RenderTargetViewDimension.Texture2DMultisampledArray: // D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY: rtvd.Texture2DMSArray.ArraySize = arraySize; rtvd.Texture2DMSArray.FirstArraySlice = firstArraySlice; break; case RenderTargetViewDimension.Texture3D: // D3D11_RTV_DIMENSION_TEXTURE3D: rtvd.Texture3D.MipSlice = mipSlice; rtvd.Texture3D.DepthSliceCount = arraySize; rtvd.Texture3D.FirstDepthSlice = firstArraySlice; break; } rtv = new RenderTargetView(device, renderTarget, rtvd); return(rtv); }
public void Init(Device device, int w, int h, int count, Format f, bool depth, Format df, int multisamplecount) { Count = count; VramUsage = 0; UseDepth = depth; MultisampleCount = multisamplecount; Multisampled = (multisamplecount > 1); ResourceUsage u = ResourceUsage.Default; BindFlags b = BindFlags.RenderTarget | BindFlags.ShaderResource; int fs = DXUtility.ElementSize(f); int wh = w * h; BindFlags db = BindFlags.DepthStencil | BindFlags.ShaderResource; // D3D11_BIND_DEPTH_STENCIL; RenderTargetViewDimension rtvd = RenderTargetViewDimension.Texture2D; ShaderResourceViewDimension srvd = ShaderResourceViewDimension.Texture2D; // D3D11_SRV_DIMENSION_TEXTURE2D; DepthStencilViewDimension dsvd = DepthStencilViewDimension.Texture2D; if (Multisampled) { rtvd = RenderTargetViewDimension.Texture2DMultisampled; srvd = ShaderResourceViewDimension.Texture2DMultisampled; dsvd = DepthStencilViewDimension.Texture2DMultisampled; } Textures = new Texture2D[count]; RTVs = new RenderTargetView[count]; SRVs = new ShaderResourceView[count]; for (int i = 0; i < count; i++) { Textures[i] = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, multisamplecount, 0, u, b, 0, 0); RTVs[i] = DXUtility.CreateRenderTargetView(device, Textures[i], f, rtvd, 0, 0, 0); SRVs[i] = DXUtility.CreateShaderResourceView(device, Textures[i], f, srvd, 1, 0, 0, 0); VramUsage += (wh * fs) * multisamplecount; } if (depth) { Format dtexf = Format.R32_Typeless; Format dsrvf = Format.R32_Float; switch (df) { case Format.D16_UNorm: dtexf = Format.R16_Typeless; dsrvf = Format.R16_UNorm; break; case Format.D24_UNorm_S8_UInt: dtexf = Format.R24G8_Typeless; dsrvf = Format.R24_UNorm_X8_Typeless; break; case Format.D32_Float: dtexf = Format.R32_Typeless; dsrvf = Format.R32_Float; break; case Format.D32_Float_S8X24_UInt: dtexf = Format.R32G8X24_Typeless; //is this right? who uses this anyway?? dsrvf = Format.R32_Float_X8X24_Typeless; break; } Depth = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, multisamplecount, 0, u, db, 0, 0); DSV = DXUtility.CreateDepthStencilView(device, Depth, df, dsvd); DepthSRV = DXUtility.CreateShaderResourceView(device, Depth, dsrvf, srvd, 1, 0, 0, 0); VramUsage += (wh * DXUtility.ElementSize(df)) * multisamplecount; } }