예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
                    }
                }
            }
        }