/// <summary> /// Constructor /// </summary> /// <param name="context">Render context</param> /// <param name="vertexSize">Vertex size</param> /// <param name="vertexCount">Vertex Count</param> /// <param name="inputElements">Input elements</param> public StreamOutputBufferWithRawSupport(DX11RenderContext context, int vertexSize, int vertexCount, OutputDrawMode outputDrawMode, bool allowIndexBuffer, InputElement[] inputElements) { this.innerBuffer = BufferHelper.CreateStreamOutBuffer(context, vertexSize, vertexCount, true, allowIndexBuffer); //Copy a new Vertex buffer with stream out this.vertexGeometry = new DX11VertexGeometry(context); vertexGeometry.HasBoundingBox = false; vertexGeometry.InputLayout = inputElements; vertexGeometry.Topology = PrimitiveTopology.TriangleList; vertexGeometry.VertexBuffer = innerBuffer; vertexGeometry.VertexSize = vertexSize; vertexGeometry.VerticesCount = vertexCount; if (outputDrawMode == OutputDrawMode.Auto) { vertexGeometry.AssignDrawer(new DX11VertexAutoDrawer()); } if (context.ComputeShaderSupport) { this.rawBuffer = new DX11RawBuffer(context, innerBuffer); } if (allowIndexBuffer) { this.indexBuffer = DX11IndexBuffer.FromReference(context, this.innerBuffer, vertexCount); } }
private void CheckBufferSupport() { try { DX11RawBuffer raw = new DX11RawBuffer(this.Device, 16); raw.Dispose(); this.computesupport = true; } catch { this.computesupport = false; } }
/// <summary> /// Disposes resources (buffer and view) /// </summary> public void Dispose() { if (this.rawBuffer != null) { this.rawBuffer.SRV.Dispose(); this.rawBuffer = null; } if (this.innerBuffer != null) { this.innerBuffer.Dispose(); this.innerBuffer = null; } }
public void Update(DX11RenderContext context) { if (this.updateddevices.Contains(context)) { return; } if (reset || !this.FOutBuffers[0].Contains(context)) { this.DisposeBuffers(context); DX11RawBuffer rb = new DX11RawBuffer(context.Device, this.size, this.flags); this.FOutBuffers[0][context] = rb; } this.updateddevices.Add(context); }
public void CreateRawWriteableVIS() { RawBufferBindings binding = new RawBufferBindings() { AllowIndexBuffer = true, WriteMode = eRawBufferWriteMode.StreamOut, AllowVertexBuffer = true }; DX11RawBuffer buffer = DX11RawBuffer.CreateWriteable(this.Device, 64, binding); Assert.IsNotNull(buffer.Buffer, "Buffer is null"); Assert.IsNotNull(buffer.ShaderView, "Shader View is null"); Assert.IsNull(buffer.UnorderedView, "UAV is not null"); buffer.Dispose(); }
public void Update(DX11RenderContext context) { Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; if (!this.FOutBuffer[0].Contains(context)) { DX11RawBuffer rb = new DX11RawBuffer(device, 16); this.FOutBuffer[0][context] = rb; } if (this.FInBuffer.IsConnected) { UnorderedAccessView uav = this.FInBuffer[0][context].UAV; ctx.CopyStructureCount(uav, this.FOutBuffer[0][context].Buffer, 0); } }
public RenderDevice(DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport, int adapterindex = 0) : base(flags, adapterindex) { //Since flag doesn't report buffer support on win7, we just try to create a small buffer try { DX11RawBuffer b = DX11RawBuffer.CreateWriteable(this, 16, new RawBufferBindings() { WriteMode = eRawBufferWriteMode.Uav }); b.Dispose(); this.HasBufferSupport = true; } catch { this.HasBufferSupport = false; } }
public void CreateRawImmutable() { RawBufferBindings binding = new RawBufferBindings() { AllowIndexBuffer = false, WriteMode = eRawBufferWriteMode.None, AllowVertexBuffer = false }; DataStream ds = new DataStream(64, true, true); DX11RawBuffer buffer = DX11RawBuffer.CreateImmutable(this.Device, ds, binding); Assert.IsNotNull(buffer.Buffer, "Buffer is null"); Assert.IsNotNull(buffer.ShaderView, "Shader View is null"); Assert.IsNull(buffer.UnorderedView, "UAV is not null"); buffer.Dispose(); }
public void RawStagingCopy() { RawBufferBindings binding = new RawBufferBindings() { AllowIndexBuffer = false, WriteMode = eRawBufferWriteMode.None, AllowVertexBuffer = true }; DataStream ds = new DataStream(16 * sizeof(uint), true, true); for (uint i = 0; i < 16; i++) { ds.Write <uint>(i); } ds.Position = 0; DX11RawBuffer buffer = DX11RawBuffer.CreateImmutable(this.Device, ds, binding); ds.Dispose(); Assert.IsNotNull(buffer.Buffer, "Immutable Buffer is null"); Assert.IsNotNull(buffer.ShaderView, "Immutable Shader View is null"); Assert.IsNull(buffer.UnorderedView, "Immutable UAV is not null"); DX11RawBuffer staging = DX11RawBuffer.CreateStaging(buffer); Assert.IsNotNull(staging.Buffer, "Staging Buffer is null"); Assert.IsNull(staging.ShaderView, "Staging Shader View is not null"); Assert.IsNull(staging.UnorderedView, "Immutable UAV is not null"); this.RenderContext.Context.CopyResource(buffer, staging); ds = staging.MapForRead(this.RenderContext); for (uint i = 0; i < 16; i++) { uint d = ds.Read <uint>(); Assert.AreEqual(i, d, "Invalid Data"); } staging.Dispose(); buffer.Dispose(); }
public void Update(DX11RenderContext context) { if (this.FOutGeom.SliceCount == 0) { return; } if (this.generateShader == null) { this.generateShader = ShaderUtils.GetShader(context, "GenerateDispatch1D"); this.dispatchBuffer = new DispatchIndirectBuffer(context); this.countBuffer = new DX11RawBuffer(context.Device, 16); } if (!this.FOutGeom[0].Contains(context)) { this.indirectDispatch = new DX11NullIndirectDispatcher(); this.indirectDispatch.IndirectArgs = this.dispatchBuffer; DX11NullGeometry nullgeom = new DX11NullGeometry(context); nullgeom.AssignDrawer(this.indirectDispatch); this.FOutGeom[0][context] = nullgeom; this.FOutCounter[0][context] = this.dispatchBuffer.RWBuffer; } var countuav = this.FInArgBuffer[0][context]; context.CurrentDeviceContext.CopyStructureCount(countuav.UAV, this.countBuffer.Buffer, 0); this.generateShader.SetBySemantic("WARPSIZE", this.FInWarpX[0]); this.generateShader.SetBySemantic("COUNTERBUFFER", this.countBuffer.SRV); this.generateShader.SetBySemantic("RWDISPATCHBUFFER", this.dispatchBuffer.UAV); this.generateShader.ApplyPass(0); context.CurrentDeviceContext.Dispatch(1, 1, 1); this.generateShader.CleanUp(); this.dispatchBuffer.UpdateBuffer(); }
public void AssignGeometry(IDxGeometry geometry) { this.outputvertexcount = this.GetVertexCount(geometry); int buffersize = this.outputvertexcount * this.outputvertexsize; if (rawbuffer != null) { if (buffersize != this.rawbuffer.Size) { rawbuffer.Dispose(); rawbuffer = null; } } if (rawbuffer == null) { rawbuffer = DX11RawBuffer.CreateWriteable(this.Device, buffersize, new RawBufferBindings() { AllowVertexBuffer = true, WriteMode = eRawBufferWriteMode.StreamOut }); } this.binding = new StreamOutputBufferBinding[] { new StreamOutputBufferBinding(this.rawbuffer.Buffer, 0) }; this.outputgeometry = this.PrepareGeometry(geometry); }
public void Update(DX11RenderContext context) { if (this.updateddevices.Contains(context)) { return; } foreach (IDX11RenderSemantic semres in rsemantics) { semres.Dispose(); } if (reset) { rsemantics.Clear(); this.DisposeBuffers(context); for (int i = 0; i < FOutBuffers.SliceCount; i++) { if (reset || !this.FOutBuffers[i].Contains(context)) { DX11RawBuffer rb = new DX11RawBuffer(context.Device, this.sizes[i], this.flags[i]); this.FOutBuffers[i][context] = rb; RWBufferRenderSemantic uavbs = new RWBufferRenderSemantic(FSemantic[i] + FUAVPostfix[i], false); uavbs.Data = this.FOutBuffers[i][context]; rsemantics.Add(uavbs); BufferRenderSemantic srvbs = new BufferRenderSemantic(FSemantic[i] + FSRVPostfix[i], false); srvbs.Data = this.FOutBuffers[i][context]; rsemantics.Add(srvbs); } } } this.updateddevices.Add(context); }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || this.FEmpty) { for (int i = 0; i < this.scenes.Count; i++) { if (scenes[i] != null) { AssimpScene scene = scenes[i]; for (int j = 0; j < scene.MeshCount; j++) { AssimpMesh assimpmesh = scene.Meshes[j]; List <int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; DX11IndexOnlyGeometry geom = new DX11IndexOnlyGeometry(context); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = assimpmesh.GetInputElements().ToArray(); geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = true; geom.BoundingBox = assimpmesh.BoundingBox; DX11DynamicStructuredBuffer <Vector3> p = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.PositionPointer, assimpmesh.VerticesCount); DX11DynamicStructuredBuffer <Vector3> n = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.NormalsPointer, assimpmesh.VerticesCount); if (assimpmesh.UvChannelCount > 0) { DX11DynamicStructuredBuffer <Vector3> u = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount); this.FOutUvs[i][j][context] = u; } DX11RawBuffer rb = new DX11RawBuffer(context, geom.IndexBuffer.Buffer); this.FOutPosition[i][j][context] = p; this.FOutNormals[i][j][context] = n; this.FOutGeom[i][j][context] = geom; this.FOutIndices[i][j][context] = rb; } } } } this.FInvalidate = false; this.FEmpty = false; } }
public void Evaluate(int SpreadMax) { if (this.FInput.IsConnected) { if (this.RenderRequest != null) { this.RenderRequest(this, this.FHost); } DX11RawBuffer b = this.FInput[0][this.AssignedContext]; if (b != null) { DX11StagingRawBuffer staging = new DX11StagingRawBuffer(this.AssignedContext.Device, b.Size); this.AssignedContext.CurrentDeviceContext.CopyResource(b.Buffer, staging.Buffer); int elem = b.Size / this.FInStride[0]; foreach (IIOContainer sp in this.outspreads) { ISpread s = (ISpread)sp.RawIOObject; s.SliceCount = elem; } DataStream ds = staging.MapForRead(this.AssignedContext.CurrentDeviceContext); for (int i = 0; i < elem; i++) { int cnt = 0; foreach (string lay in layout) { switch (lay) { case "float": ISpread <float> spr = (ISpread <float>) this.outspreads[cnt].RawIOObject; spr[i] = ds.Read <float>(); break; case "float2": ISpread <Vector2> spr2 = (ISpread <Vector2>) this.outspreads[cnt].RawIOObject; spr2[i] = ds.Read <Vector2>(); break; case "float3": ISpread <Vector3> spr3 = (ISpread <Vector3>) this.outspreads[cnt].RawIOObject; spr3[i] = ds.Read <Vector3>(); break; case "float4": ISpread <Vector4> spr4 = (ISpread <Vector4>) this.outspreads[cnt].RawIOObject; spr4[i] = ds.Read <Vector4>(); break; case "float4x4": ISpread <Matrix> sprm = (ISpread <Matrix>) this.outspreads[cnt].RawIOObject; sprm[i] = ds.Read <Matrix>(); break; case "int": ISpread <int> spri = (ISpread <int>) this.outspreads[cnt].RawIOObject; spri[i] = ds.Read <int>(); break; case "uint": ISpread <uint> sprui = (ISpread <uint>) this.outspreads[cnt].RawIOObject; sprui[i] = ds.Read <uint>(); break; case "uint2": ISpread <Vector2> sprui2 = (ISpread <Vector2>) this.outspreads[cnt].RawIOObject; uint ui1 = ds.Read <uint>(); uint ui2 = ds.Read <uint>(); sprui2[i] = new Vector2(ui1, ui2); break; case "uint3": ISpread <Vector3> sprui3 = (ISpread <Vector3>) this.outspreads[cnt].RawIOObject; uint ui31 = ds.Read <uint>(); uint ui32 = ds.Read <uint>(); uint ui33 = ds.Read <uint>(); sprui3[i] = new Vector3(ui31, ui32, ui33); break; } cnt++; } } staging.UnMap(this.AssignedContext.CurrentDeviceContext); staging.Dispose(); } else { foreach (IIOContainer sp in this.outspreads) { ISpread s = (ISpread)sp.RawIOObject; s.SliceCount = 0; } } } else { foreach (IIOContainer sp in this.outspreads) { ISpread s = (ISpread)sp.RawIOObject; s.SliceCount = 0; } } }