public void Update(DX11RenderContext context) { if (FInvalidate || !FOutput[0].Contains(context) || FElCount.IsChanged || FImmut.IsChanged) { if (FOutput[0].Contains(context)) { if (FOutput[0][context].ElementCount != elcount) { FOutput[0].Dispose(context); } } else { if (FImmut[0]) { FInData.Position = 0; FInData.Read(immutbuf, 0, (int)FInData.Length); var ds = new DataStream(immutbuf, true, true); ds.Position = 0; FOutput[0][context] = new DX11ImmutableStructuredBuffer(context.Device, elcount, elstrides, ds); } else { FOutput[0][context] = new DX11DynamicStructuredBuffer(context.Device, elcount, elstrides); } FValid[0] = true; } var b = FOutput[0][context]; try { if (FImmut[0]) { if (FOutput[0][context] != null) { FOutput[0][context].Dispose(); } FInData.Position = 0; FInData.Read(immutbuf, 0, (int)FInData.Length); var ds = new DataStream(immutbuf, true, true); ds.Position = 0; FOutput[0][context] = new DX11ImmutableStructuredBuffer(context.Device, elcount, elstrides, ds); } else { var db = context.CurrentDeviceContext.MapSubresource(b.Buffer, MapMode.WriteDiscard, MapFlags.None); db.Data.Position = 0; FInData.Position = 0; FInData.CopyTo(db.Data); db.Data.Position = 0; context.CurrentDeviceContext.UnmapSubresource(b.Buffer, 0); } } catch { FValid[0] = false; } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate) { Device device = context.Device; if (this.FOutput[0].Contains(context)) { if (this.FOutput[0][context].ElementCount != FInCount[0]) { if (this.FInCount[0] > 0) { this.FOutput[0].Dispose(context); this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, FInCount[0]); } } } else { if (this.FInCount[0] > 0) { this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, FInCount[0]); } } if (this.FInCount[0] > 0) { DX11DynamicStructuredBuffer <T> b = this.FOutput[0][context]; b.WriteData(this.m_data); } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.spreadmax == 0) { return; } if (this.FInvalidate || !this.FOutput[0].Contains(context)) { int count = this.ffixed ? this.FCount.IOObject[0] : this.FInData.SliceCount; if (this.FOutput[0].Contains(context)) { if (this.FOutput[0][context].ElementCount != count) { this.FOutput[0].Dispose(context); } } if (!this.FOutput[0].Contains(context)) { if (count > 0) { this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, count); this.FValid[0] = true; } else { this.FValid[0] = false; return; } } DX11DynamicStructuredBuffer <T> b = this.FOutput[0][context]; if (this.tempbuffer.Length != count) { Array.Resize <T>(ref this.tempbuffer, count); } //If fixed or if size is the same, we can do a direct copy bool needconvert = ((this.ffixed && count != this.FInData.SliceCount)) || this.NeedConvert; try { if (needconvert) { this.WriteArray(count); b.WriteData(this.tempbuffer); } else { b.WriteData(this.FInData.Stream.Buffer, 0, this.FInData.SliceCount); } } catch (Exception ex) { } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (FInvalidate) { Device device = context.Device; int len = node_data != null ? node_data.Length : 0; if (FNodeBuffer[0].Contains(context)) { if (FNodeBuffer[0][context].ElementCount != len) { if (len > 0) { FNodeBuffer[0].Dispose(context); FNodeBuffer[0][context] = new DX11DynamicStructuredBuffer <LBVH.Node>(context, len); } } } else { if (len > 0) { FNodeBuffer[0][context] = new DX11DynamicStructuredBuffer <LBVH.Node>(context, len); } } if (len > 0) { FNodeBuffer[0][context].WriteData(node_data); } len *= 2; if (FTransformBuffer[0].Contains(context)) { if (FTransformBuffer[0][context].ElementCount != len) { if (len > 0) { FTransformBuffer[0].Dispose(context); FTransformBuffer[0][context] = new DX11DynamicStructuredBuffer <Matrix>(context, len); } } } else { if (len > 0) { FTransformBuffer[0][context] = new DX11DynamicStructuredBuffer <Matrix>(context, len); } } if (len > 0) { FTransformBuffer[0][context].WriteData(transform_data); } } }
private void BindBuffers(DX11RenderContext context) { if (this.worldbuffer != null) { if (this.worldbuffer.ElementCount != this.FInWorld.SliceCount) { this.worldbuffer.Dispose(); this.worldbuffer = null; } } if (this.colorbuffer != null) { if (this.colorbuffer.ElementCount != this.FInColor.SliceCount) { this.colorbuffer.Dispose(); this.colorbuffer = null; } } if (this.FInTexture.PluginIO.IsConnected) { if (this.uvbuffer != null) { if (this.uvbuffer.ElementCount != this.FInTexTransform.SliceCount) { this.uvbuffer.Dispose(); this.uvbuffer = null; } } if (this.uvbuffer == null) { this.uvbuffer = new DX11DynamicStructuredBuffer <Matrix>(context, this.FInTexTransform.SliceCount); } quadshader.SetBySemantic("TEXTUREMATRIXCOUNT", this.uvbuffer.ElementCount); quadshader.SetBySemantic("TEXTUREMATRIXBUFFER", this.uvbuffer.SRV); this.uvbuffer.WriteData(this.FInTexTransform.Stream.Buffer, 0, this.FInTexTransform.SliceCount); } if (this.worldbuffer == null) { this.worldbuffer = new DX11DynamicStructuredBuffer <Matrix>(context, this.FInWorld.SliceCount); } if (this.colorbuffer == null) { this.colorbuffer = new DX11DynamicStructuredBuffer <Color4>(context, this.FInColor.SliceCount); } this.worldbuffer.WriteData(this.FInWorld.Stream.Buffer, 0, this.FInWorld.SliceCount); this.colorbuffer.WriteData(this.FInColor.Stream.Buffer, 0, this.FInColor.SliceCount); quadshader.SetBySemantic("WORLDBUFFER", this.worldbuffer.SRV); quadshader.SetBySemantic("COLORBUFFER", this.colorbuffer.SRV); quadshader.SetBySemantic("WORLDCOUNT", this.worldbuffer.ElementCount); quadshader.SetBySemantic("COLORCOUNT", this.colorbuffer.ElementCount); }
public void Update(DX11RenderContext context) { if (shaderSample == null) { shaderSample = new DX11ShaderInstance(context, effectSample); shaderLoad = new DX11ShaderInstance(context, effectLoad); } DX11ShaderInstance instance = this.pixelCoords[0] ? shaderLoad : shaderSample; if (this.mipLevel.SliceCount > 1) { instance.SelectTechnique("ConstantLevel"); } else { instance.SelectTechnique("DynamicLevel"); } int totalCount; if (this.mipLevel.SliceCount > 1) { totalCount = SpreadUtils.SpreadMax(this.coordinates, this.mipLevel); instance.SetByName("UvCount", this.coordinates.SliceCount); instance.SetByName("LevelCount", this.mipLevel.SliceCount); } else { totalCount = this.coordinates.SliceCount; instance.SetByName("MipLevel", this.mipLevel[0]); } this.coordinateBuffer = this.coordinateBuffer.GetOrResize(context.Device, this.coordinates.SliceCount, 8); this.levelBuffer = this.levelBuffer.GetOrResize(context.Device, this.mipLevel.SliceCount, 4); this.writeBuffer = this.writeBuffer.GetOrResize(context.Device, totalCount, 16); this.readbackBuffer = this.readbackBuffer.GetOrResize(context.Device, totalCount, 16); instance.SetByName("TotalCount", totalCount); instance.SetByName("uvBuffer", coordinateBuffer.SRV); if (this.mipLevel.SliceCount > 1) { instance.SetByName("uvLevelBuffer", levelBuffer.SRV); } instance.SetByName("inputTexture", this.textureInput[0][context].SRV); instance.SetByName("OutputBuffer", writeBuffer.UAV); instance.ApplyPass(0); context.CurrentDeviceContext.CopyResource(this.writeBuffer.Buffer, this.readbackBuffer.Buffer); }
private void WriteToBuffer <T>(DX11Resource <IDX11ReadableStructureBuffer> bufferResource, DX11RenderContext context, T[] bufferToCopy, int elementCount) where T : struct { if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { DX11DynamicStructuredBuffer <T> b = (DX11DynamicStructuredBuffer <T>)bufferResource[context]; b.WriteData(bufferToCopy, 0, elementCount); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { DX11CopyDestStructuredBuffer <T> b = (DX11CopyDestStructuredBuffer <T>)bufferResource[context]; b.WriteData(bufferToCopy, 0, elementCount); } }
/// <summary> /// Creates a buffer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bufferResource">The buffer resource</param> /// <param name="context">The DX11 context.</param> /// <param name="count">The required count. Gets blown up to the next power of 2.</param> /// <param name="bufferToCopy">The buffer to copy in case of immutable buffer type</param> private void CreateBuffer <T>(DX11Resource <IDX11ReadableStructureBuffer> bufferResource, DX11RenderContext context, int count, T[] bufferToCopy) where T : struct { if (!bufferResource.Contains(context)) { count = NextUpperPow2(count); if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { bufferResource[context] = new DX11DynamicStructuredBuffer <T>(context, count); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { bufferResource[context] = new DX11CopyDestStructuredBuffer <T>(context, count); } else { bufferResource[context] = new DX11ImmutableStructuredBuffer <T>(context.Device, bufferToCopy, count); } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.ibo == null) { uint[] faceIndices = faceModel.TriangleIndices.ToArray(); fixed(uint *uPtr = &faceIndices[0]) { DataStream ds = new DataStream(new IntPtr(uPtr), faceIndices.Length * 4, true, true); this.ibo = new DX11IndexBuffer(context, ds, false, false); } this.FOutGeom[0][context] = new DX11IndexOnlyGeometry(context); this.FOutGeom[0][context].IndexBuffer = this.ibo; } if (this.faceVertexBuffer == null) { this.faceVertexBuffer = new DX11DynamicStructuredBuffer <Vector3>(context, (int)FaceModel.VertexCount); this.FOutFaceVertices[0][context] = this.faceVertexBuffer; this.faceUVBuffer = new DX11DynamicStructuredBuffer <Vector2>(context, (int)FaceModel.VertexCount); this.FOutFaceUV[0][context] = this.faceUVBuffer; } if (this.FInvalidate) { fixed(CameraSpacePoint *cPtr = &this.cameraPoints[0]) { this.faceVertexBuffer.WriteData(new IntPtr(cPtr)); } fixed(ColorSpacePoint *cPtr = &this.colorPoints[0]) { this.faceUVBuffer.WriteData(new IntPtr(cPtr)); } this.FInvalidate = false; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutput[0].Contains(context)) { int count = this.ffixed ? this.FCount.IOObject[0] : this.FInData.SliceCount; if (this.FOutput[0].Contains(context)) { if (this.FOutput[0][context].ElementCount != count) { this.FOutput[0].Dispose(context); } } if (!this.FOutput[0].Contains(context)) { if (count > 0) { this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, count); this.FValid[0] = true; } else { this.FValid[0] = false; return; } } DX11DynamicStructuredBuffer <T> b = this.FOutput[0][context]; if (this.tempbuffer.Length != count) { Array.Resize <T>(ref this.tempbuffer, count); } this.WriteArray(count); b.WriteData(this.tempbuffer); } }
public void Update(DX11RenderContext context) { if (this.spreadmax == 0) { return; } if (this.FInvalidate || !this.FOutput[0].Contains(context)) { int count = this.ffixed ? this.FCount.IOObject[0] : this.FInData.SliceCount; if (this.FOutput[0].Contains(context)) { if (this.FOutput[0][context].ElementCount != count || this.bufferType != this.FBufferType[0] || this.FOutput[0][context] is DX11ImmutableStructuredBuffer <T> ) { this.FOutput[0].Dispose(context); } } if (this.tempbuffer.Length != count) { Array.Resize <T>(ref this.tempbuffer, count); } //If fixed or if size is the same, we can do a direct copy bool needconvert = ((this.ffixed && count != this.FInData.SliceCount)) || this.NeedConvert; T[] bufferToCopy = this.FInData.Stream.Buffer; int bufferElementCount = this.FInData.SliceCount; if (needconvert) { this.WriteArray(count); bufferToCopy = this.tempbuffer; bufferElementCount = this.tempbuffer.Length; } if (!this.FOutput[0].Contains(context)) { if (count > 0) { if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, count); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { this.FOutput[0][context] = new DX11CopyDestStructuredBuffer <T>(context, count); } else { this.FOutput[0][context] = new DX11ImmutableStructuredBuffer <T>(context.Device, bufferToCopy, bufferToCopy.Length); } this.FValid[0] = true; this.bufferType = this.FBufferType[0]; } else { this.FValid[0] = false; return; } } bool needContextCopy = this.FBufferType[0] != DX11BufferUploadType.Immutable; if (needContextCopy) { try { if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { DX11DynamicStructuredBuffer <T> b = (DX11DynamicStructuredBuffer <T>) this.FOutput[0][context]; b.WriteData(bufferToCopy, 0, b.ElementCount); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { DX11CopyDestStructuredBuffer <T> b = (DX11CopyDestStructuredBuffer <T>) this.FOutput[0][context]; b.WriteData(bufferToCopy, 0, b.ElementCount); } } catch (Exception ex) { this.iofactory.PluginHost.Log(TLogType.Error, ex.Message); } } } }
public void Update(DX11RenderContext context) { if (!this.FTextureOutput[0].Contains(context)) { this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); this.FPCOut[0][context] = new DX11DynamicStructuredBuffer <float>(context, 640 * 480 * 6); } if (this.FInvalidate) { fixed(int *f = &this.pic[0]) { IntPtr ptr = new IntPtr(f); this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4); } /*fixed (float* f = &this.piccloud[0]) * {* * IntPtr ptr = new IntPtr(f);*/ DX11DynamicStructuredBuffer <float> db = (DX11DynamicStructuredBuffer <float>) this.FPCOut[0][context]; db.WriteData(this.piccloud); //} this.FInvalidate = false; } if (this.FInVoxels[0]) { if (this.FOutVoxels[0].Contains(context)) { this.FOutVoxels[0].Dispose(context); } short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; this.volume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data); DX11DynamicStructuredBuffer <int> b = new DX11DynamicStructuredBuffer <int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ); int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++) { idata[i] = data[i]; } b.WriteData(idata); this.FOutVoxels[0][context] = b; } if (this.FInExport[0]) { if (this.FGeomOut[0].Contains(context)) { this.FGeomOut[0].Dispose(context); } if (this.volume != null) { Mesh m = this.volume.CalculateMesh(this.FInGeomVoxelStep[0]); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); ReadOnlyCollection <int> inds = m.GetTriangleIndexes(); DataStream ds = new DataStream(inds.Count * 4, true, true); ds.WriteRange <int>(inds.ToArray()); ds.Position = 0; DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true); ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> pos = m.GetVertices(); ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> norm = m.GetNormals(); //ReadOnlyCollection<int> col = m.GetColors(); DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count, true, true); SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue); SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < pos.Count; i++) { Microsoft.Kinect.Fusion.Vector3 p = pos[i]; Microsoft.Kinect.Fusion.Vector3 n = norm[i]; dsv.Write <Microsoft.Kinect.Fusion.Vector3>(p); dsv.Write <Microsoft.Kinect.Fusion.Vector3>(n); //dsv.Write<int>(col[i]); if (p.X < bmin.X) { bmin.X = p.X; } if (p.Y < bmin.Y) { bmin.Y = p.Y; } if (p.Z < bmin.Z) { bmin.Z = p.Z; } if (p.X > bmax.X) { bmax.X = p.X; } if (p.Y > bmax.Y) { bmax.Y = p.Y; } if (p.Z > bmax.Z) { bmax.Z = p.Z; } } geom.IndexBuffer = ibo; geom.HasBoundingBox = true; geom.InputLayout = Pos3Norm3Vertex.Layout; // FusionColoredVertex.Layout; geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList; geom.VertexSize = Pos3Norm3Vertex.VertexSize; // FusionColoredVertex.VertexSize; geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, dsv, false, true); geom.VerticesCount = pos.Count; geom.BoundingBox = new BoundingBox(bmin, bmax); this.FGeomOut[0][context] = geom; m.Dispose(); } } }
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; } }