public GpuSBuffer(Device device, T[] data) { StructCount = data.Length; StructSize = System.Runtime.InteropServices.Marshal.SizeOf <T>();// (sizeof(T)); BufferSize = StructCount * StructSize; //var ds = new DataStream(new DataPointer() Buffer = Buffer.Create <T>(device, BindFlags.ShaderResource, data, BufferSize, ResourceUsage.Default, CpuAccessFlags.None, ResourceOptionFlags.BufferStructured, StructSize); //Buffer = new Buffer(device, BufferSize, ResourceUsage.Default, BindFlags.ShaderResource, CpuAccessFlags.None, ResourceOptionFlags.BufferStructured, StructSize); SRV = DXUtility.CreateShaderResourceView(device, Buffer, SharpDX.DXGI.Format.Unknown, SharpDX.Direct3D.ShaderResourceViewDimension.Buffer, 0, 0, StructCount, 0); }
public GpuBuffer(Device device, int itemSize, int itemCount) { StructSize = System.Runtime.InteropServices.Marshal.SizeOf <T>();// sizeof(T)), StructCount = itemCount * itemSize; ItemTotalSize = itemSize * StructSize; ItemCount = itemCount; Size = StructSize * itemSize * itemCount; Buffer = DXUtility.CreateBuffer(device, Size, ResourceUsage.Default, BindFlags.ShaderResource | BindFlags.UnorderedAccess, 0, ResourceOptionFlags.BufferStructured, StructSize); SRV = DXUtility.CreateShaderResourceView(device, Buffer, Format.Unknown, ShaderResourceViewDimension.Buffer, 0, 0, StructCount, 0); UAV = DXUtility.CreateUnorderedAccessView(device, Buffer, Format.Unknown, UnorderedAccessViewDimension.Buffer, 0, StructCount, 0, 0); }
public GpuCBuffer(Device device, int count) { StructCount = count; StructSize = System.Runtime.InteropServices.Marshal.SizeOf <T>();// (sizeof(T)); BufferSize = StructCount * StructSize; //Buffer = Buffer.Create<T>(device, BindFlags.ShaderResource, null, BufferSize, ResourceUsage.Dynamic, CpuAccessFlags.Write, ResourceOptionFlags.BufferStructured, StructSize); Buffer = new Buffer(device, BufferSize, ResourceUsage.Dynamic, BindFlags.ShaderResource, CpuAccessFlags.Write, ResourceOptionFlags.BufferStructured, StructSize); SRV = DXUtility.CreateShaderResourceView(device, Buffer, SharpDX.DXGI.Format.Unknown, SharpDX.Direct3D.ShaderResourceViewDimension.Buffer, 0, 0, StructCount, 0); Data = new List <T>(count); DataArray = new T[count]; }
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; } }