public ConstantBuffer(DxDevice device, int size) { this.device = device; size = ((size + 15) / 16) * 16; BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = Math.Max(size, 16), Usage = ResourceUsage.Dynamic }; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, bd); }
public static DX11Texture2D LoadFromMemory(DxDevice device, IntPtr dataPointer, int dataLength) { IntPtr resource; NativeMethods.LoadTextureFromMemory(device.Device.NativePointer, dataPointer, dataLength, out resource); if (resource != IntPtr.Zero) { Texture2D texture = Texture2D.FromPointer <Texture2D>(resource); ShaderResourceView srv = new ShaderResourceView(device, texture); return(DX11Texture2D.FromReference(device, texture, srv)); } else { throw new Exception("Failed to load texture"); } }
public DxMipSliceRenderTarget(DxDevice device, IDxTexture3D texture, int mipindex, int w, int h, int d) { this.device = device; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture3D, Format = texture.Format, Texture3D = new RenderTargetViewDescription.Texture3DResource() { MipSlice = mipindex } }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.Texture3D, Format = texture.Format, Texture3D = new ShaderResourceViewDescription.Texture3DResource() { MipLevels = 1, MostDetailedMip = mipindex } }; UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Dimension = UnorderedAccessViewDimension.Texture3D, Format = texture.Format, Texture3D = new UnorderedAccessViewDescription.Texture3DResource() { FirstWSlice = 0, MipSlice = mipindex, WSize = d } }; this.RenderView = new RenderTargetView(device.Device, texture.Texture, rtd); this.ShaderView = new ShaderResourceView(device.Device, texture.Texture, srvd); this.UnorderedView = new UnorderedAccessView(device.Device, texture.Texture, uavd); this.Width = w; this.Height = h; this.Depth = d; }
public TimeStampQuery(DxDevice device) { this.device = device; QueryDescription qd = new QueryDescription(); qd.Type = QueryType.Timestamp; qd.Flags = QueryFlags.None; this.tstart = new Query(device.Device, qd); this.tend = new Query(device.Device, qd); QueryDescription qdd = new QueryDescription(); qdd.Type = QueryType.TimestampDisjoint; qdd.Flags = QueryFlags.None; this.tsdis = new Query(device.Device, qdd); }
public static DX11Texture2D LoadFromFile(DxDevice device, string path, bool mips = true) { IntPtr resource; int levels = mips ? 0 : 1; NativeMethods.LoadTextureFromFile(device.Device.NativePointer, path, out resource, levels); if (resource != IntPtr.Zero) { Texture2D texture = Texture2D.FromPointer <Texture2D>(resource); ShaderResourceView srv = new ShaderResourceView(device, texture); return(DX11Texture2D.FromReference(device, texture, srv)); } else { throw new Exception("Failed to load texture"); } }
public static DX11RenderTarget2D CreateTiled(DxDevice device, int w, int h, Format format, int mipLevels = 1) { var texBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.Tiled, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, MipLevels = mipLevels }; return(new DX11RenderTarget2D(device, texBufferDesc)); }
public DX11TextureCube(DxDevice device, Texture2D texture) { this.Texture = texture; this.description = this.Texture.Description; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = this.Texture.Description.Format, TextureCube = new ShaderResourceViewDescription.TextureCubeResource() { MipLevels = this.Texture.Description.MipLevels, MostDetailedMip = 0 } }; this.ShaderView = new ShaderResourceView(device, this.Texture, srvd); }
protected DX11VertexBuffer(DxDevice device, int verticescount, int vertexsize, BufferDescription desc, DataStream initial = null) { this.device = device; this.VertexSize = vertexsize; this.VerticesCount = verticescount; if (initial != null) { initial.Position = 0; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, initial, desc); } else { this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, desc); } this.desc = this.Buffer.Description; }
public DX11RenderTarget2D(DxDevice device, int w, int h, SampleDescription sd, Format format, bool genMipMaps, int mmLevels, bool allowUAV) { this.device = device; var texBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default, }; if (sd.Count == 1 && allowUAV) { texBufferDesc.BindFlags |= BindFlags.UnorderedAccess; } 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.Texture = new Texture2D(device.Device, texBufferDesc); this.resourceDesc = this.Texture.Description; this.RenderView = new RenderTargetView(device.Device, this.Texture); this.ShaderView = new ShaderResourceView(device.Device, this.Texture); if (sd.Count == 1 && allowUAV) { this.UnorderedView = new UnorderedAccessView(device.Device, this.Texture); } }
public static DX11VertexBuffer CreateImmutable(DxDevice device, int verticesCount, int vertexSize, DataStream initial, bool allowRawView = false) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = vertexSize * verticesCount, Usage = ResourceUsage.Immutable }; if (allowRawView) { bd.BindFlags |= BindFlags.ShaderResource; bd.OptionFlags = ResourceOptionFlags.BufferAllowRawViews; } return(new DX11VertexBuffer(device, verticesCount, vertexSize, bd, initial)); }
public DX11SliceRenderTarget(DxDevice device, IDxTexture2D texture, int sliceindex) { this.device = device; this.parent = texture; RenderTargetViewDescription rtd = new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture2DArray, Format = texture.Format, Texture2DArray = new RenderTargetViewDescription.Texture2DArrayResource() { ArraySize = 1, MipSlice = 0, FirstArraySlice = sliceindex } }; this.RenderView = new RenderTargetView(device.Device, this.parent.Texture, rtd); }
public DX11SliceDepthStencil(DxDevice device, IDxTexture2D texture, int sliceindex, eDepthFormat depthformat) { this.device = device; this.parent = texture; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = DepthStencilViewDimension.Texture2DArray, Texture2DArray = new DepthStencilViewDescription.Texture2DArrayResource() { ArraySize = 1, FirstArraySlice = sliceindex, MipSlice = 0 } }; this.DepthView = new DepthStencilView(device, this.parent.Texture, dsvd); }
protected DX11RawBuffer(DxDevice device, BufferDescription desc, IntPtr ptr, bool createUAV) { this.device = device; this.Size = desc.SizeInBytes; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, ptr, desc); this.Description = this.Buffer.Description; if (desc.BindFlags.HasFlag(BindFlags.ShaderResource)) { ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = SharpDX.DXGI.Format.R32_Typeless, Dimension = ShaderResourceViewDimension.ExtendedBuffer, BufferEx = new ShaderResourceViewDescription.ExtendedBufferResource() { ElementCount = desc.SizeInBytes / 4, FirstElement = 0, Flags = ShaderResourceViewExtendedBufferFlags.Raw } }; this.ShaderView = new ShaderResourceView(device.Device, this.Buffer, srvd); } if (createUAV) { UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Format = SharpDX.DXGI.Format.R32_Typeless, Dimension = UnorderedAccessViewDimension.Buffer, Buffer = new UnorderedAccessViewDescription.BufferResource() { ElementCount = this.Size / 4, FirstElement = 0, Flags = UnorderedAccessViewBufferFlags.Raw } }; this.UnorderedView = new UnorderedAccessView(device.Device, this.Buffer, uavd); } }
public DX11TextureArray2D(DxDevice device, Texture2D texture) { this.Texture = texture; this.description = this.Texture.Description; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.Texture2DArray, Format = this.Texture.Description.Format, Texture2DArray = new ShaderResourceViewDescription.Texture2DArrayResource() { ArraySize = this.Texture.Description.ArraySize, FirstArraySlice = 0, MipLevels = this.Texture.Description.MipLevels, MostDetailedMip = 0 } }; this.ShaderView = new ShaderResourceView(device, this.Texture, srvd); }
public static DX11IndexBuffer CreateImmutable(DxDevice device, short[] initial) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = initial.Length * 2, Usage = ResourceUsage.Immutable }; DX11IndexBuffer result; fixed(short *ptr = &initial[0]) { result = new DX11IndexBuffer(device, initial.Length, bd, new IntPtr(ptr), false); } return(result); }
public static DX11RawBuffer CreateWriteable(DxDevice device, int size, RawBufferBindings binding) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.BufferAllowRawViews, SizeInBytes = size, Usage = ResourceUsage.Default, StructureByteStride = 4 }; bd.BindFlags |= binding.WriteMode == eRawBufferWriteMode.Uav ? BindFlags.UnorderedAccess : 0; bd.BindFlags |= binding.AllowIndexBuffer ? BindFlags.IndexBuffer : 0; bd.BindFlags |= binding.AllowVertexBuffer ? BindFlags.VertexBuffer : 0; bd.BindFlags |= binding.WriteMode == eRawBufferWriteMode.StreamOut ? BindFlags.StreamOutput : 0; return(new DX11RawBuffer(device, bd, IntPtr.Zero, binding.WriteMode == eRawBufferWriteMode.Uav)); }
public static DX11DepthStencil FromView(DxDevice device, DepthStencilView view) { var tex = view.Resource.QueryInterface <Texture2D>(); DX11DepthStencil ds = new DX11DepthStencil(); ds.device = device; ds.DepthFormat = eDepthFormat.d24s8; ds.DepthView = view; ds.resourceDesc = tex.Description; ds.Texture = tex; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = ds.DepthFormat.GetSRVFormat(), Dimension = ShaderResourceViewDimension.Texture2D, }; ds.ShaderView = new ShaderResourceView(device, tex, srvd); return(ds); }
protected DX11StructuredBuffer(DxDevice device, int elementcount, int stride, BufferDescription desc, DataStream initial = null) { this.device = device; this.ElementCount = elementcount; this.Stride = stride; this.BufferMode = eDxBufferMode.Default; if (initial != null) { this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, initial, desc); } else { this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, desc); } if (desc.Usage != ResourceUsage.Staging) { this.ShaderView = new ShaderResourceView(device.Device, this.Buffer); } }
public static DX11SwapChain FlipSequential(DxDevice device, IntPtr handle, Format format, Rational refreshRate) { DX11SwapChain swapShain = new DX11SwapChain(); swapShain.device = device; SwapChainDescription sd = new SwapChainDescription() { BufferCount = 2, ModeDescription = new ModeDescription(0, 0, refreshRate, format), IsWindowed = true, OutputHandle = handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.FlipSequential, Usage = Usage.RenderTargetOutput, Flags = SwapChainFlags.None }; swapShain.swapchain = new SwapChain(device.Factory, device.Device, sd); swapShain.Initialize(); return(swapShain); }
public DX11RenderTexture3D(DxDevice device, int w, int h, int d, Format format) { this.device = device; Texture3DDescription desc = new Texture3DDescription() { BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, Depth = d, Format = format, Height = h, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, Width = w }; this.Texture = new Texture3D(device.Device, desc); this.resourceDesc = this.Texture.Description; this.ShaderView = new ShaderResourceView(device.Device, this.Texture); this.UnorderedView = new UnorderedAccessView(device.Device, this.Texture); this.RenderView = new RenderTargetView(device.Device, this.Texture); }
protected DX11StructuredBuffer(DxDevice device, int elementcount, int stride, BufferDescription desc, eDxBufferMode buffermode = eDxBufferMode.Default) { this.device = device; this.ElementCount = elementcount; this.Stride = stride; this.Buffer = new SharpDX.Direct3D11.Buffer(device.Device, desc); this.ShaderView = new ShaderResourceView(device.Device, this.Buffer); this.BufferMode = buffermode; UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription() { Format = SharpDX.DXGI.Format.Unknown, Dimension = UnorderedAccessViewDimension.Buffer, Buffer = new UnorderedAccessViewDescription.BufferResource() { ElementCount = this.ElementCount, Flags = (UnorderedAccessViewBufferFlags)buffermode } }; this.UnorderedView = new UnorderedAccessView(device.Device, this.Buffer, uavd); }
public static DX11Texture2D CreateDynamic(DxDevice device, int width, int height, Format format) { var desc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = format, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Dynamic, Width = width, Height = height, SampleDescription = new SampleDescription(1, 0) }; DX11Texture2D texture = new DX11Texture2D(); texture.Texture = new Texture2D(device.Device, desc); texture.description = texture.Texture.Description; texture.ShaderView = new ShaderResourceView(device.Device, texture.Texture); return(texture); }
public static DX11Texture1D LoadTexture1D(DxDevice device, string path) { IntPtr resource; long retcode = NativeMethods.LoadTextureFromFile(device.Device.NativePointer, path, out resource, 1); if (retcode >= 0) { Resource r = Resource.FromPointer <Resource>(resource); if (r.Dimension != ResourceDimension.Texture1D) { r.Dispose(); throw new Exception("Texture is not a 1D Texture"); } Texture1D texture = Texture1D.FromPointer <Texture1D>(resource); ShaderResourceView srv = new ShaderResourceView(device, texture); return(DX11Texture1D.FromReference(device, texture, srv)); } else { throw new Exception("Failed to load texture"); } }
public static DX11SwapChain FromComposition(DxDevice dxDevice, int w, int h) { DX11SwapChain swapShain = new DX11SwapChain(); swapShain.device = dxDevice; var desc = new SharpDX.DXGI.SwapChainDescription1() { Width = w, Height = h, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput | Usage.ShaderInput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.None, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, AlphaMode = AlphaMode.Premultiplied }; swapShain.swapchain = new SwapChain1(dxDevice.Factory, dxDevice.Device, ref desc); swapShain.Initialize(); return(swapShain); }
public static DX11VertexBuffer CreateWriteable(DxDevice device, int verticesCount, int vertexSize, eVertexBufferWriteMode mode = eVertexBufferWriteMode.None) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = vertexSize * verticesCount, Usage = ResourceUsage.Default }; bd.BindFlags |= BindFlags.ShaderResource; bd.OptionFlags = ResourceOptionFlags.BufferAllowRawViews; if (mode == eVertexBufferWriteMode.StreamOut) { bd.BindFlags |= BindFlags.StreamOutput; } else if (mode == eVertexBufferWriteMode.Raw) { bd.BindFlags |= BindFlags.UnorderedAccess; } return(new DX11VertexBuffer(device, verticesCount, vertexSize, bd, null)); }
public static DX11StructuredBuffer CreateCounter <T>(DxDevice device, int elementcount) where T : struct { return(CreateWriteable(device, elementcount, Marshal.SizeOf(typeof(T)), eDxBufferMode.Counter)); }
public static DX11StructuredBuffer CreateStaging <T>(DxDevice device, int elemenCount) where T : struct { return(CreateStaging(device, elemenCount, Marshal.SizeOf(typeof(T)))); }
public static DX11StructuredBuffer CreateTiled <T>(DxDevice device, int elementCount, eDxBufferMode buffermode = eDxBufferMode.Default) where T : struct { int stride = Marshal.SizeOf(typeof(T)); return(CreateTiled(device, elementCount, stride, buffermode)); }
public DX11DepthTextureArray(DxDevice device, int w, int h, int elemcnt, eDepthFormat depthformat, bool buildslices = true) { this.device = device; this.DepthFormat = depthformat; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = depthformat.GetTypeLessFormat(), Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, }; this.Texture = new Texture2D(device, texBufferDesc); this.resourceDesc = this.Texture.Description; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = depthformat.GetSRVFormat(), Dimension = ShaderResourceViewDimension.Texture2DArray, Texture2DArray = new ShaderResourceViewDescription.Texture2DArrayResource() { ArraySize = elemcnt, FirstArraySlice = 0, MipLevels = 1, MostDetailedMip = 0 } }; this.ShaderView = new ShaderResourceView(device.Device, this.Texture, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = DepthStencilViewDimension.Texture2DArray, Texture2DArray = new DepthStencilViewDescription.Texture2DArrayResource() { ArraySize = elemcnt, FirstArraySlice = 0, MipSlice = 0 } }; this.DepthView = new DepthStencilView(device, this.Texture, dsvd); dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (depthformat.HasStencil()) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyView = new DepthStencilView(device.Device, this.Texture, dsvd); this.SliceDepthView = new DX11SliceDepthStencil[this.ElementCount]; if (buildslices) { for (int i = 0; i < this.ElementCount; i++) { this.SliceDepthView[i] = new DX11SliceDepthStencil(this.device, this, i, depthformat); } } }
public IndexedIndirectBuffer(DxDevice device) : this(device, new DrawIndexedInstancedArgs(1, 1, 0, 0, 0)) { }