Exemplo n.º 1
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInput.IsConnected && this.FInEnabled[0])
            {
                this.FInput.Sync();

                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

                if (this.AssignedContext == null)
                {
                    this.FOutput.SliceCount = 0;
                    return;
                }

                IDX11StructuredBuffer b = this.FInput[0][this.AssignedContext];
                if (b != null)
                {
                    if (this.staging != null && this.staging.ElementCount != b.ElementCount)
                    {
                        this.staging.Dispose(); this.staging = null;
                    }
                    if (this.staging != null && currentStride != b.Stride)
                    {
                        this.staging.Dispose(); this.staging = null;
                        currentStride = b.Stride;
                    }

                    if (this.staging == null)
                    {
                        staging = new DX11StagingStructuredBuffer(this.AssignedContext.Device, b.ElementCount, b.Stride);
                    }

                    this.AssignedContext.CurrentDeviceContext.CopyResource(b.Buffer, staging.Buffer);

                    //this.FOutput.SliceCount = b.ElementCount;
                    this.FOutput.SliceCount = 1;

                    DataStream ds = staging.MapForRead(this.AssignedContext.CurrentDeviceContext);
                    try
                    {
                        MemoryComStream outstream = new MemoryComStream();
                        ds.Position = 0;
                        ds.CopyTo(outstream);
                        FOutput[0] = outstream;

                        this.FOutput.Flush(true);
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error inreadback node: " + ex.Message);
                    }
                    finally
                    {
                        staging.UnMap(this.AssignedContext.CurrentDeviceContext);
                    }
                }
                else
                {
                    this.FOutput.SliceCount = 0;
                }
            }
            else
            {
                this.FOutput.SliceCount = 0;
            }
        }
Exemplo n.º 2
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInput.IsConnected && this.FInEnabled[0])
            {
                this.FInput.Sync();

                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

                if (this.AssignedContext == null)
                {
                    this.FOutput.SliceCount = 0;
                    return;
                }

                IDX11StructuredBuffer b = this.FInput[0][this.AssignedContext];
                if (b != null)
                {
                    if (Marshal.SizeOf(typeof(T)) != b.Stride)
                    {
                        this.FOutput.SliceCount = 0;
                        this.FHost.Log(TLogType.Error, "Buffer has an invalid stride");
                        return;
                    }

                    if (this.stagingWrite != null && this.stagingWrite.ElementCount != b.ElementCount)
                    {
                        this.stagingWrite.Dispose(); this.stagingWrite = null;
                        this.stagingRead.Dispose(); this.stagingRead   = null;
                    }

                    if (this.stagingWrite == null)
                    {
                        stagingWrite = new DX11StagingStructuredBuffer(this.AssignedContext.Device, b.ElementCount, b.Stride);
                        stagingRead  = new DX11StagingStructuredBuffer(this.AssignedContext.Device, b.ElementCount, b.Stride);
                    }

                    this.AssignedContext.CurrentDeviceContext.CopyResource(b.Buffer, stagingWrite.Buffer);

                    this.FOutput.SliceCount = b.ElementCount;

                    DataStream ds = stagingRead.MapForRead(this.AssignedContext.CurrentDeviceContext);
                    try
                    {
                        this.WriteData(ds, b.ElementCount);

                        this.FOutput.Flush(true);
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error inreadback node: " + ex.Message);
                    }
                    finally
                    {
                        stagingRead.UnMap(this.AssignedContext.CurrentDeviceContext);
                    }

                    SharpDX.Utilities.Swap(ref stagingWrite, ref stagingRead);
                }
                else
                {
                    this.FOutput.SliceCount = 0;
                }
            }
            else
            {
                this.FOutput.SliceCount = 0;
            }
        }