Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /// <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);
         }
     }
 }
Ejemplo n.º 3
0
        protected override void ProcessResource(DX11RenderContext context, IDX11ReadableStructureBuffer inputResource, ref IDX11ReadableStructureBuffer outputResource)
        {
            if (outputResource != null)
            {
                if (currentDescription != outputResource.Buffer.Description)
                {
                    outputResource.Dispose();
                    outputResource = null;
                }
            }

            if (outputResource == null)
            {
                this.currentDescription = inputResource.Buffer.Description;
                BufferDescription desc = this.currentDescription;
                desc.Usage = ResourceUsage.Default;
                desc.BindFlags = BindFlags.ShaderResource;
                desc.CpuAccessFlags = CpuAccessFlags.None;

                outputResource = new DX11CopyDestStructuredBuffer(context.Device, desc);
            }
            context.CurrentDeviceContext.CopyResource(inputResource.Buffer, outputResource.Buffer);
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }