Beispiel #1
0
        public DX11StructuredBufferRegion(DxDevice device, DX11StructuredBuffer parentBuffer, int StartOffset, int ElementCount)
        {
            this.Buffer       = parentBuffer.Buffer;
            this.ElementCount = ElementCount;
            this.Stride       = parentBuffer.Stride;

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Format    = SharpDX.DXGI.Format.Unknown,
                Dimension = UnorderedAccessViewDimension.Buffer,
                Buffer    = new UnorderedAccessViewDescription.BufferResource()
                {
                    ElementCount = this.ElementCount,
                    Flags        = parentBuffer.UnorderedView.Description.Buffer.Flags,
                    FirstElement = StartOffset
                }
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                Format    = SharpDX.DXGI.Format.Unknown,
                Dimension = ShaderResourceViewDimension.Buffer,
                BufferEx  = new ShaderResourceViewDescription.ExtendedBufferResource()
                {
                    ElementCount = this.ElementCount,
                    FirstElement = StartOffset
                }
            };

            this.ShaderView    = new ShaderResourceView(device, parentBuffer.Buffer, srvd);
            this.UnorderedView = new UnorderedAccessView(device, parentBuffer.Buffer, uavd);
        }
Beispiel #2
0
        public BaseIndirectBuffer(DxDevice device, T args)
        {
            this.device = device;

            int size = Marshal.SizeOf(args);

            BufferDescription bd = new BufferDescription();

            bd.Usage = ResourceUsage.Default;
            bd.StructureByteStride = 0;
            bd.SizeInBytes         = size;
            bd.CpuAccessFlags      = CpuAccessFlags.None;
            bd.BindFlags           = BindFlags.None;
            bd.OptionFlags         = ResourceOptionFlags.DrawIndirectArguments;

            DataStream dsb = new DataStream(size, false, true);

            dsb.Position = 0;
            dsb.Write <T>(args);
            dsb.Position = 0;

            this.ArgumentBuffer = new SharpDX.Direct3D11.Buffer(device.Device, dsb, bd);
            dsb.Dispose();

            this.WriteBuffer = DX11StructuredBuffer.CreateWriteable(device, size / 4, 4);
        }
 public void Copy(DeviceContext ctx, DX11StructuredBuffer destination)
 {
     if (this.Size == destination.Size)
     {
         ctx.CopyResource(this.Buffer, destination.Buffer);
     }
     else
     {
         throw new Exception("Invalid Matching sizes");
     }
 }
Beispiel #4
0
 public void Copy(DeviceContext ctx, DX11StructuredBuffer <T> destination)
 {
     if (this.Size == destination.Size)
     {
         ctx.CopyResource(this.Buffer, destination.Buffer);
     }
     else
     {
         throw new Exception("Invalid Matching sizes");
     }
 }
Beispiel #5
0
        public DX11StructuredBuffer CopyToStructuredBuffer(RenderContext context)
        {
            if (this.format != SharpDX.DXGI.Format.R32_UInt)
            {
                throw new Exception("Only Large indices formats supported");
            }
            DX11StructuredBuffer sb = DX11StructuredBuffer.CreateWriteable <uint>(this.device, this.IndicesCount);

            context.Context.CopyResource(this.Buffer, sb.Buffer);
            return(sb);
        }
Beispiel #6
0
        public DX11StructuredBuffer AsStaging()
        {
            BufferDescription bd = this.Buffer.Description;

            bd.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write;
            bd.OptionFlags    = ResourceOptionFlags.None;
            bd.Usage          = ResourceUsage.Staging;
            bd.BindFlags      = BindFlags.None;

            DX11StructuredBuffer result = new DX11StructuredBuffer(this.device, this.ElementCount, this.Stride, bd, null);

            return(result);
        }
Beispiel #7
0
        public static DX11StructuredBuffer CreateImmutable <T>(DxDevice device, T[] initial) where T : struct
        {
            int        stride = Marshal.SizeOf(typeof(T));
            DataStream ds     = new DataStream(stride * initial.Length, true, true);

            ds.WriteRange <T>(initial);
            ds.Position = 0;

            DX11StructuredBuffer sb = CreateImmutable(device, initial.Length, stride, ds);

            ds.Dispose();
            return(sb);
        }