예제 #1
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInput.PluginIO.IsConnected && this.FInEnabled[0])
            {
                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

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

                IDX11RWStructureBuffer 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.staging != null && this.staging.ElementCount != b.ElementCount)
                    {
                        this.staging.Dispose(); this.staging = null;
                    }

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

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

                    this.FOutput.SliceCount = b.ElementCount;
                    DataStream ds = staging.MapForRead(this.AssignedContext.CurrentDeviceContext);

                    this.WriteData(ds, b.ElementCount);

                    this.FOutput.Flush(true);

                    staging.UnMap(this.AssignedContext.CurrentDeviceContext);
                }
                else
                {
                    this.FOutput.SliceCount = 0;
                }
            }
            else
            {
                this.FOutput.SliceCount = 0;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInput.IsConnected && this.FInEnabled[0])
            {
                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

                IDX11ReadableStructureBuffer b = this.FInput[0][this.AssignedContext];

                if (b != null)
                {
                    int elementcount = this.FInElementCount[0];
                    if (elementcount == 0)
                    {
                        elementcount = b.ElementCount;
                    }

                    DX11StagingStructuredBuffer staging = new DX11StagingStructuredBuffer(this.AssignedContext.Device
                                                                                          , elementcount, b.Stride);



                    ResourceRegion region = new ResourceRegion(0, 0, 0, this.FInElementCount[0] * b.Stride, 1, 1);
                    /*this.AssignedContext.CurrentDeviceContext.CopySubresourceRegion(b.Buffer, 0, staging.Buffer, 0, */
                    this.AssignedContext.CurrentDeviceContext.CopySubresourceRegion(b.Buffer, 0, region, staging.Buffer, 0, 0, 0, 0);

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

                    foreach (IIOContainer sp in this.outspreads)
                    {
                        ISpread s = (ISpread)sp.RawIOObject;
                        s.SliceCount = elementcount;
                    }

                    DataStream ds = staging.MapForRead(this.AssignedContext.CurrentDeviceContext);

                    for (int i = 0; i < elementcount; 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;
                }
            }
        }
예제 #4
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;
            }
        }
예제 #5
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;
            }
        }