Exemplo n.º 1
0
 public void Init(
     string name,
     int width,
     int height,
     Format resourceFormat,
     Format srvFormat,
     BindFlags bindFlags,
     int samplesCount,
     int samplesQuality,
     ResourceOptionFlags roFlags,
     ResourceUsage ru,
     int mipmapLevels,
     CpuAccessFlags cpuAccessFlags)
 {
     m_name = name;
     m_size = new Vector2I(width, height);
     m_resourceFormat = resourceFormat;
     m_srvFormat = srvFormat;
     m_bindFlags = bindFlags;
     m_samplesCount = samplesCount;
     m_samplesQuality = samplesQuality;
     m_roFlags = roFlags;
     m_resourceUsage = ru;
     m_mipmapLevels = mipmapLevels;
     m_cpuAccessFlags = cpuAccessFlags;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="sizeInBytes">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="bindFlags">The bind flags.</param>
 /// <param name="cpuAccessFlags">The CPU access flags.</param>
 /// <param name="optionFlags">The option flags.</param>
 public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags)
 {
     SizeInBytes = sizeInBytes;
     Usage = usage;
     BindFlags = bindFlags;
     CpuAccessFlags = cpuAccessFlags;
     OptionFlags = optionFlags;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="sizeInBytes">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="bindFlags">The bind flags.</param>
 /// <param name="cpuAccessFlags">The cpu access flags.</param>
 /// <param name="optionFlags">The option flags.</param>
 /// <param name="structureByteStride">The structure byte stride.</param>
 public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags, int structureByteStride)
 {
     SizeInBytes = sizeInBytes;
     Usage = usage;
     BindFlags = bindFlags;
     CpuAccessFlags = cpuAccessFlags;
     OptionFlags = optionFlags;
     StructureByteStride = structureByteStride;
 }
Exemplo n.º 4
0
        public Buffer CreateEmptyBuffer(int sizeInBytes, BindFlags bindFlags, ResourceUsage usage = ResourceUsage.Default)
        {
            var desc = new BufferDescription()
            {
                BindFlags      = bindFlags,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = usage,
                SizeInBytes    = sizeInBytes, // min is 16
            };

            return(new Buffer(device, desc));
        }
Exemplo n.º 5
0
        internal static VertexBufferId CreateVertexBuffer(int elements, int stride, BindFlags bind, ResourceUsage usage, IntPtr?data = null, string debugName = null)
        {
            bind |= BindFlags.VertexBuffer;

            BufferDescription desc = new BufferDescription();

            desc.BindFlags      = bind;
            desc.SizeInBytes    = stride * elements;
            desc.Usage          = usage;
            desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None;

            return(CreateVertexBuffer(desc, stride, data, debugName));
        }
Exemplo n.º 6
0
        private Texture2DDescription CreateTextureDescription(bool createUav, bool createRtv)
        {
            Debug.Assert(NumLayers > 0);
            Debug.Assert(NumMipmaps > 0);
            Debug.Assert(Size.Min > 0);
            Debug.Assert(Format != Format.Unknown);

            // check resource limits
            if (Size.X > Device.MAX_TEXTURE_2D_DIMENSION || Size.Y > Device.MAX_TEXTURE_2D_DIMENSION)
            {
                throw new Exception($"Texture2D Dimensions may not exceed {Device.MAX_TEXTURE_2D_DIMENSION}x{Device.MAX_TEXTURE_2D_DIMENSION} but were {Size.X}x{Size.Y}");
            }

            if (NumLayers > Device.MAX_TEXTURE_2D_ARRAY_DIMENSION)
            {
                throw new Exception($"Number of layers may not exceed {Device.MAX_TEXTURE_2D_ARRAY_DIMENSION} but was {NumLayers}");
            }

            // render target required for mip map generation
            BindFlags flags = BindFlags.ShaderResource;

            if (createRtv)
            {
                flags |= BindFlags.RenderTarget;
            }
            if (createUav)
            {
                flags |= BindFlags.UnorderedAccess;
            }

            var optionFlags = ResourceOptionFlags.None;

            if (HasCubemap)
            {
                optionFlags |= ResourceOptionFlags.TextureCube;
            }

            return(new Texture2DDescription
            {
                ArraySize = NumLayers,
                BindFlags = flags,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format,
                Height = Size.Height,
                MipLevels = NumMipmaps,
                OptionFlags = optionFlags,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                Width = Size.Width
            });
        }
Exemplo n.º 7
0
        public void Init(Device device, int w, int h, Format f, int sc, int sq, bool depth, Format df)
        {
            VramUsage    = 0;
            Multisampled = (sc > 1);
            UseDepth     = depth;
            ResourceUsage               u    = ResourceUsage.Default;
            BindFlags                   b    = BindFlags.RenderTarget | BindFlags.ShaderResource;
            RenderTargetViewDimension   rtvd = RenderTargetViewDimension.Texture2D;
            ShaderResourceViewDimension srvd = ShaderResourceViewDimension.Texture2D;// D3D11_SRV_DIMENSION_TEXTURE2D;
            int       fs = DXUtility.ElementSize(f);
            int       wh = w * h;
            BindFlags db = BindFlags.DepthStencil;// | BindFlags.ShaderResource;// D3D11_BIND_DEPTH_STENCIL;
            DepthStencilViewDimension dsvd = DepthStencilViewDimension.Texture2D;
            Format dtexf = GetDepthTexFormat(df);
            Format dsrvf = GetDepthSrvFormat(df);

            Texture    = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, 1, 0, u, b, 0, 0);
            RTV        = DXUtility.CreateRenderTargetView(device, Texture, f, rtvd, 0, 0, 0);
            SRV        = DXUtility.CreateShaderResourceView(device, Texture, f, srvd, 1, 0, 0, 0);
            VramUsage += (wh * fs);

            if (Multisampled)
            {
                b    = BindFlags.RenderTarget;
                rtvd = RenderTargetViewDimension.Texture2DMultisampled;
                dsvd = DepthStencilViewDimension.Texture2DMultisampled;
                //srvd = ShaderResourceViewDimension.Texture2DMultisampled;

                TextureMS  = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, sc, sq, u, b, 0, 0);
                MSRTV      = DXUtility.CreateRenderTargetView(device, TextureMS, f, rtvd, 0, 0, 0);
                VramUsage += (wh * fs) * sc;

                if (depth)
                {
                    DepthMS = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, sc, sq, u, db, 0, 0);
                    MSDSV   = DXUtility.CreateDepthStencilView(device, DepthMS, df, dsvd);
                    //DepthSRV = DXUtility.CreateShaderResourceView(device, DepthMS, dsrvf, srvd, 1, 0, 0, 0);
                    VramUsage += (wh * DXUtility.ElementSize(df)) * sc;
                }
            }
            else
            {
                if (depth)
                {
                    Depth = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, sc, sq, u, db, 0, 0);
                    DSV   = DXUtility.CreateDepthStencilView(device, Depth, df, dsvd);
                    //DepthSRV = DXUtility.CreateShaderResourceView(device, Depth, dsrvf, srvd, 1, 0, 0, 0);
                    VramUsage += (wh * DXUtility.ElementSize(df));
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="byteWidth">The size in bytes.</param>
 /// <param name="bindFlags">The bind flags.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="cpuAccessFlags">The CPU access flags.</param>
 /// <param name="miscFlags">The option flags.</param>
 /// <param name="structureByteStride">The structure byte stride.</param>
 public BufferDescription(int byteWidth,
                          BindFlags bindFlags,
                          ResourceUsage usage           = ResourceUsage.Default,
                          CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None,
                          ResourceOptionFlags miscFlags = ResourceOptionFlags.None,
                          int structureByteStride       = 0)
 {
     ByteWidth           = byteWidth;
     BindFlags           = bindFlags;
     Usage               = usage;
     CPUAccessFlags      = cpuAccessFlags;
     MiscFlags           = miscFlags;
     StructureByteStride = structureByteStride;
 }
Exemplo n.º 9
0
        protected Buffer(GxContext context, BindFlags binding)
        {
            mContext = context;

            mDescription = new BufferDescription
            {
                BindFlags           = binding,
                CpuAccessFlags      = CpuAccessFlags.None,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = 0,
                StructureByteStride = 0,
                Usage = ResourceUsage.Default
            };
        }
Exemplo n.º 10
0
 public ConstantBufferProxy(int structSize, BindFlags bindFlags = BindFlags.ConstantBuffer,
                            CpuAccessFlags cpuAccessFlags       = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, ResourceUsage usage = ResourceUsage.Default)
     : base(structSize)
 {
     bufferDesc = new BufferDescription()
     {
         SizeInBytes         = structSize,
         BindFlags           = bindFlags,
         CpuAccessFlags      = cpuAccessFlags,
         OptionFlags         = optionFlags,
         Usage               = usage,
         StructureByteStride = 0
     };
 }
Exemplo n.º 11
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Buffer" /> class.
        /// </summary>
        /// <param name = "device">The device with which to associate the buffer.</param>
        /// <param name = "sizeInBytes">The size, in bytes, of the buffer.</param>
        /// <param name = "usage">The usage pattern for the buffer.</param>
        /// <param name = "bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param>
        /// <param name = "accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param>
        /// <param name = "optionFlags">Miscellaneous resource options.</param>
        public Buffer(Device device, int sizeInBytes, ResourceUsage usage, BindFlags bindFlags,
                      CpuAccessFlags accessFlags, ResourceOptionFlags optionFlags)
            : base(IntPtr.Zero)
        {
            var description = new BufferDescription()
            {
                BindFlags      = bindFlags,
                CpuAccessFlags = accessFlags,
                OptionFlags    = optionFlags,
                SizeInBytes    = sizeInBytes,
                Usage          = usage,
            };

            device.CreateBuffer(ref description, null, this);
        }
Exemplo n.º 12
0
 public BufferDescription(
     int sizeInBytes,
     Usage usage,
     BindFlags bindFlags,
     MiscFlags miscFlags,
     ExtraFlags extraFlags,
     int structureByteStide)
 {
     SizeInBytes = sizeInBytes;
     Usage = usage;
     BindFlags = bindFlags;
     MiscFlags = miscFlags;
     ExtraFlags = extraFlags;
     StructureByteStride = structureByteStide;
 }
Exemplo n.º 13
0
        internal static IndexBufferId CreateIndexBuffer(int elements, Format format, BindFlags bind, ResourceUsage usage, IntPtr?data, string debugName)
        {
            bind |= BindFlags.IndexBuffer;

            Debug.Assert(format == Format.R32_UInt || format == Format.R16_UInt);

            BufferDescription desc = new BufferDescription();

            desc.BindFlags      = bind;
            desc.SizeInBytes    = elements * (format == Format.R32_UInt ? 4 : 2);
            desc.Usage          = usage;
            desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None;

            return(CreateIndexBuffer(desc, format, data, debugName));
        }
Exemplo n.º 14
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);

            newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                FirstElement = 0,
                ElementCount = size,
                Format       = Format.Unknown,
                Dimension    = ShaderResourceViewDimension.ExtendedBuffer,
                Flags        = 0,
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            if (allowStaging)
            {
                description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);
                newBuffer.m_StagingBufferObject = new Buffer(device, description);

                description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4);
                newBuffer.m_StagingCountBufferObject = new Buffer(device, description);
            }

            return(newBuffer);
        }
Exemplo n.º 15
0
        /// <summary>
        ///     指定したサイズの、空の画像を作成する。
        /// </summary>
        public 画像(Size2F サイズ, BindFlags bindFlags = BindFlags.ShaderResource)
        {
            //using var _ = new LogBlock( Log.現在のメソッド名 );

            #region " 条件チェック "
            //----------------
            if (0f >= サイズ.Width || 0f >= サイズ.Height)
            {
                Log.ERROR($"テクスチャサイズが不正です。[{サイズ}]");
                return;
            }
            //----------------
            #endregion

            this._CreateShaderResourceView(Global.D3D11Device1, bindFlags, サイズ);
        }
Exemplo n.º 16
0
 /// <summary>Create and set fields to their defaults</summary>
 public TextureDesc(bool unused)
 {
     baseStruct       = new DeviceObjectAttribs(true);
     Type             = ResourceDimension.Undefined;
     Size             = new CSize(0, 0);
     ArraySizeOrDepth = 1;
     Format           = TextureFormat.Unknown;
     MipLevels        = 1;
     SampleCount      = 1;
     Usage            = Usage.Default;
     BindFlags        = BindFlags.None;
     CPUAccessFlags   = CpuAccessFlags.None;
     MiscFlags        = MiscTextureFlags.None;
     ClearValue       = new OptimizedClearValue(true);
     CommandQueueMask = 1;
 }
Exemplo n.º 17
0
        public static Texture2DDescription GetTextureDescription(BindFlags bindFlags, Format format, int width, int height)
        {
            var textureDesc = new Texture2DDescription();

            textureDesc.BindFlags         = bindFlags;
            textureDesc.Format            = format;
            textureDesc.Width             = width;
            textureDesc.Height            = height;
            textureDesc.MipLevels         = 1;
            textureDesc.SampleDescription = new SampleDescription(1, 0);
            textureDesc.Usage             = ResourceUsage.Default;
            textureDesc.OptionFlags       = ResourceOptionFlags.None;
            textureDesc.CpuAccessFlags    = CpuAccessFlags.None;
            textureDesc.ArraySize         = 1;
            return(textureDesc);
        }
Exemplo n.º 18
0
        /// <summary>
        ///     指定したサイズの、空の画像を作成する。
        /// </summary>
        public 画像(Device1 d3dDevice1, Size2F サイズ, BindFlags bindFlags = BindFlags.ShaderResource)
        {
            //using var _ = new LogBlock( Log.現在のメソッド名 );

            #region " 条件チェック "
            //----------------
            if (0f >= サイズ.Width || 0f >= サイズ.Height)
            {
                Log.ERROR($"テクスチャサイズが不正です。0 より大きい正の値を指定してください。[{サイズ}]");
                return;
            }
            //----------------
            #endregion

            this._空のテクスチャとそのシェーダーリソースビューを作成して返す(d3dDevice1, bindFlags, サイズ);
        }
Exemplo n.º 19
0
        public UploadBuffer(int byteSize, BindFlags binding = BindFlags.ConstantBuffer)
        {
            ByteSize = Utility.Utility.AlignTo(byteSize, 16);

            var bufferDesc = new BufferDescription
            {
                BindFlags           = binding,
                CpuAccessFlags      = CpuAccessFlags.None,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = ByteSize,
                StructureByteStride = 0,
                Usage = ResourceUsage.Default
            };

            Handle = new Buffer(Device.Get().Handle, bufferDesc);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Texture2DDescription1"/> struct.
        /// </summary>
        /// <param name="format">Texture format.</param>
        /// <param name="width">Texture width (in texels).</param>
        /// <param name="height">Texture height (in texels).</param>
        /// <param name="arraySize">Number of textures in the array.</param>
        /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
        /// <param name="bindFlags">The <see cref="Vortice.Direct3D11.BindFlags"/> for binding to pipeline stages.</param>
        /// <param name="usage">Value that identifies how the texture is to be read from and written to.</param>
        /// <param name="cpuAccessFlags">The <see cref="Direct3D11.CpuAccessFlags"/> to specify the types of CPU access allowed.</param>
        /// <param name="sampleCount">Specifies multisampling parameters for the texture.</param>
        /// <param name="sampleQuality">Specifies multisampling parameters for the texture.</param>
        /// <param name="optionFlags">The <see cref="ResourceOptionFlags"/> that identify other, less common resource options. </param>
        /// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param>
        public Texture2DDescription1(
            Format format,
            int width,
            int height,
            int arraySize                   = 1,
            int mipLevels                   = 0,
            BindFlags bindFlags             = BindFlags.ShaderResource,
            ResourceUsage usage             = ResourceUsage.Default,
            CpuAccessFlags cpuAccessFlags   = CpuAccessFlags.None,
            int sampleCount                 = 1,
            int sampleQuality               = 0,
            ResourceOptionFlags optionFlags = ResourceOptionFlags.None,
            TextureLayout textureLayout     = TextureLayout.Undefined)
        {
            if (format == Format.Unknown)
            {
                throw new ArgumentException($"format need to be valid", nameof(format));
            }

            if (width < 1 || width > ID3D11Resource.MaximumTexture2DSize)
            {
                throw new ArgumentException($"Width need to be in range 1-{ID3D11Resource.MaximumTexture2DSize}", nameof(width));
            }

            if (height < 1 || height > ID3D11Resource.MaximumTexture2DSize)
            {
                throw new ArgumentException($"Height need to be in range 1-{ID3D11Resource.MaximumTexture2DSize}", nameof(height));
            }

            if (arraySize < 1 || arraySize > ID3D11Resource.MaximumTexture2DArraySize)
            {
                throw new ArgumentException($"Array size need to be in range 1-{ID3D11Resource.MaximumTexture2DArraySize}", nameof(arraySize));
            }

            Width             = width;
            Height            = height;
            MipLevels         = mipLevels;
            ArraySize         = arraySize;
            Format            = format;
            SampleDescription = new SampleDescription(sampleCount, sampleQuality);
            Usage             = usage;
            BindFlags         = bindFlags;
            CpuAccessFlags    = cpuAccessFlags;
            OptionFlags       = optionFlags;
            TextureLayout     = textureLayout;
        }
Exemplo n.º 21
0
        public D3DTexture2D(
            Device device,
            BindFlags bindFlags,
            ResourceUsage usage,
            CpuAccessFlags cpuAccessFlags,
            SharpDX.DXGI.Format format,
            int mipLevels,
            int width,
            int height,
            int stride)
        {
            _device   = device;
            MipLevels = mipLevels;
            Texture2DDescription desc = CreateDescription(mipLevels, width, height, bindFlags, usage, cpuAccessFlags, format);

            DeviceTexture = new Texture2D(device, desc);
        }
Exemplo n.º 22
0
        // Static functions
        static public TextureObject CreateTexture3DFromFile(Device device, int width, int height, int depth, Format format, string fileName)
        {
            TextureObject newTexture = new TextureObject();

            // Variables
            newTexture.m_Width     = width;
            newTexture.m_Height    = height;
            newTexture.m_Depth     = depth;
            newTexture.m_TexFormat = format;
            newTexture.m_Mips      = 1;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess;

            ImageLoadInformation imageLoadInfo = new ImageLoadInformation()
            {
                BindFlags      = bindFlags,
                CpuAccessFlags = CpuAccessFlags.None,
                Format         = format,
                Height         = height,
                Width          = width,
                Depth          = depth,
                MipLevels      = 1,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Default
            };

            newTexture.m_TextureObject3D = Texture3D.FromFile(device, fileName, imageLoadInfo);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize       = 0,
                Format          = format,
                Dimension       = ShaderResourceViewDimension.Texture3D,
                Flags           = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels       = 1,
            };

            newTexture.m_ShaderResourceView = new ShaderResourceView(device, newTexture.m_TextureObject3D, srvViewDesc);

            newTexture.m_RenderTargetView    = new RenderTargetView(device, newTexture.m_TextureObject3D);
            newTexture.m_UnorderedAccessView = new UnorderedAccessView(device, newTexture.m_TextureObject3D);

            return(newTexture);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="sizeInBytes">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="bindFlags">The bind flags.</param>
 /// <param name="optionFlags">The option flags.</param>
 /// <param name="structureByteStride">The structure byte stride.</param>
 public BufferDescription(int sizeInBytes, BindFlags bindFlags, Usage usage = Usage.Default, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0)
 {
     SizeInBytes    = sizeInBytes;
     Usage          = usage;
     BindFlags      = bindFlags;
     CpuAccessFlags = CpuAccessFlags.None;
     if (usage == Usage.Dynamic)
     {
         CpuAccessFlags = CpuAccessFlags.Write;
     }
     else if (usage == Usage.Staging)
     {
         CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write;
     }
     OptionFlags         = optionFlags;
     StructureByteStride = structureByteStride;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Creates a new instance of the <see cref="ID3D11Buffer"/> class.
        /// </summary>
        /// <typeparam name="T">Type of the data to upload</typeparam>
        /// <param name="bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param>
        /// <param name="data">Initial data used to initialize the buffer.</param>
        /// <param name="sizeInBytes">The size, in bytes, of the buffer. If 0 is specified, sizeof(T) * data.Length is used.</param>
        /// <param name="usage">The usage pattern for the buffer.</param>
        /// <param name="accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param>
        /// <param name="optionFlags">Miscellaneous resource options.</param>
        /// <param name="structureByteStride">The size (in bytes) of the structure element for structured buffers.</param>
        /// <returns>An initialized buffer</returns>
        /// <msdn-id>ff476501</msdn-id>
        /// <unmanaged>HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer)</unmanaged>
        /// <unmanaged-short>ID3D11Device::CreateBuffer</unmanaged-short>
        public unsafe ID3D11Buffer CreateBuffer <T>(BindFlags bindFlags, T[] data,
                                                    int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : unmanaged
        {
            var description = new BufferDescription()
            {
                BindFlags           = bindFlags,
                CpuAccessFlags      = accessFlags,
                OptionFlags         = optionFlags,
                SizeInBytes         = sizeInBytes == 0 ? sizeof(T) * data.Length : sizeInBytes,
                Usage               = usage,
                StructureByteStride = structureByteStride
            };

            fixed(void *dataPtr = &data[0])
            {
                return(CreateBuffer(description, new SubresourceData((IntPtr)dataPtr)));
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="structSize"></param>
 /// <param name="bindFlags"></param>
 /// <param name="cpuAccessFlags"></param>
 /// <param name="optionFlags"></param>
 /// <param name="usage"></param>
 /// <param name="strideSize"></param>
 public ConstantBufferProxy(int structSize, BindFlags bindFlags = BindFlags.ConstantBuffer,
                            CpuAccessFlags cpuAccessFlags       = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, ResourceUsage usage = ResourceUsage.Default, int strideSize = 0)
     : base(structSize, bindFlags)
 {
     if (structSize % 16 != 0)
     {
         throw new ArgumentException("Constant buffer struct size must be multiple of 16 bytes");
     }
     bufferDesc = new BufferDescription()
     {
         SizeInBytes         = structSize,
         BindFlags           = bindFlags,
         CpuAccessFlags      = cpuAccessFlags,
         OptionFlags         = optionFlags,
         Usage               = usage,
         StructureByteStride = strideSize
     };
 }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a <see cref="BufferDescription"/>.
        /// </summary>
        /// <param name="sizeInBytes">The size in bytes.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="isReadWrite">if set to <c>true</c> [is read write].</param>
        /// <param name="structureByteStride">The structure byte stride.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="optionFlags">The option flags.</param>
        /// <returns>An instance of <see cref="BufferDescription"/></returns>
        protected static BufferDescription NewDescription(int sizeInBytes, BindFlags flags, bool isReadWrite = false, int structureByteStride = 0, ResourceUsage usage = ResourceUsage.Default, ResourceOptionFlags optionFlags = ResourceOptionFlags.None)
        {
            var desc = new BufferDescription()
            {
                SizeInBytes         = sizeInBytes,
                StructureByteStride = structureByteStride,
                CpuAccessFlags      = GetCputAccessFlagsFromUsage(usage),
                BindFlags           = flags,
                OptionFlags         = optionFlags,
                Usage = usage,
            };

            if (isReadWrite)
            {
                desc.BindFlags |= BindFlags.UnorderedAccess;
            }
            return(desc);
        }
Exemplo n.º 27
0
        public void Init(Device device, int w, int h, int count, Format f, bool depth, Format df, int multisamplecount)
        {
            Count            = count;
            VramUsage        = 0;
            UseDepth         = depth;
            MultisampleCount = multisamplecount;
            Multisampled     = (multisamplecount > 1);
            ResourceUsage               u    = ResourceUsage.Default;
            BindFlags                   b    = BindFlags.RenderTarget | BindFlags.ShaderResource;
            int                         fs   = DXUtility.ElementSize(f);
            int                         wh   = w * h;
            BindFlags                   db   = BindFlags.DepthStencil | BindFlags.ShaderResource; // D3D11_BIND_DEPTH_STENCIL;
            RenderTargetViewDimension   rtvd = RenderTargetViewDimension.Texture2D;
            ShaderResourceViewDimension srvd = ShaderResourceViewDimension.Texture2D;             // D3D11_SRV_DIMENSION_TEXTURE2D;
            DepthStencilViewDimension   dsvd = DepthStencilViewDimension.Texture2D;

            if (Multisampled)
            {
                rtvd = RenderTargetViewDimension.Texture2DMultisampled;
                srvd = ShaderResourceViewDimension.Texture2DMultisampled;
                dsvd = DepthStencilViewDimension.Texture2DMultisampled;
            }

            Textures = new Texture2D[count];
            RTVs     = new RenderTargetView[count];
            SRVs     = new ShaderResourceView[count];

            for (int i = 0; i < count; i++)
            {
                Textures[i] = DXUtility.CreateTexture2D(device, w, h, 1, 1, f, multisamplecount, 0, u, b, 0, 0);
                RTVs[i]     = DXUtility.CreateRenderTargetView(device, Textures[i], f, rtvd, 0, 0, 0);
                SRVs[i]     = DXUtility.CreateShaderResourceView(device, Textures[i], f, srvd, 1, 0, 0, 0);
                VramUsage  += (wh * fs) * multisamplecount;
            }
            if (depth)
            {
                Format dtexf = GpuTexture.GetDepthTexFormat(df);
                Format dsrvf = GpuTexture.GetDepthSrvFormat(df);
                Depth      = DXUtility.CreateTexture2D(device, w, h, 1, 1, dtexf, multisamplecount, 0, u, db, 0, 0);
                DSV        = DXUtility.CreateDepthStencilView(device, Depth, df, dsvd);
                DepthSRV   = DXUtility.CreateShaderResourceView(device, Depth, dsrvf, srvd, 1, 0, 0, 0);
                VramUsage += (wh * DXUtility.ElementSize(df)) * multisamplecount;
            }
        }
Exemplo n.º 28
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Texture3DDescription1"/> struct.
    /// </summary>
    /// <param name="format">Texture format.</param>
    /// <param name="width">Texture width (in texels).</param>
    /// <param name="height">Texture height (in texels).</param>
    /// <param name="depth">Texture depth (in texels).</param>
    /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
    /// <param name="bindFlags">The <see cref="Vortice.Direct3D11.BindFlags"/> for binding to pipeline stages.</param>
    /// <param name="usage">Value that identifies how the texture is to be read from and written to.</param>
    /// <param name="cpuAccessFlags">The <see cref="Direct3D11.CpuAccessFlags"/> to specify the types of CPU access allowed.</param>
    /// <param name="miscFlags">The <see cref="ResourceOptionFlags"/> that identify other, less common resource options. </param>
    /// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param>
    public Texture3DDescription1(
        Format format,
        int width,
        int height,
        int depth,
        int mipLevels                 = 0,
        BindFlags bindFlags           = BindFlags.ShaderResource,
        ResourceUsage usage           = ResourceUsage.Default,
        CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None,
        ResourceOptionFlags miscFlags = ResourceOptionFlags.None,
        TextureLayout textureLayout   = TextureLayout.Undefined)
    {
        if (format == Format.Unknown)
        {
            throw new ArgumentException($"format need to be valid", nameof(format));
        }

        if (width < 1 || width > ID3D11Resource.MaximumTexture3DSize)
        {
            throw new ArgumentException($"Width need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(width));
        }

        if (height < 1 || height > ID3D11Resource.MaximumTexture3DSize)
        {
            throw new ArgumentException($"Height need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(height));
        }

        if (depth < 1 || depth > ID3D11Resource.MaximumTexture3DSize)
        {
            throw new ArgumentException($"Depth need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(depth));
        }

        Width          = width;
        Height         = height;
        Depth          = depth;
        MipLevels      = mipLevels;
        Format         = format;
        Usage          = usage;
        BindFlags      = bindFlags;
        CPUAccessFlags = cpuAccessFlags;
        MiscFlags      = miscFlags;
        TextureLayout  = textureLayout;
    }
Exemplo n.º 29
0
        DynamicBuffer moarDrawCalls()
        {
            if (null != m_moarDrawCalls)
            {
                return(m_moarDrawCalls);
            }

            // Pi4 doesn't support buffer reads from vertex shaders: https://www.raspberrypi.org/forums/viewtopic.php?f=68&t=271863&p=1648066#p1648066
            // It does supports texelFetch, but that one doesn't have the precision: https://www.raspberrypi.org/forums/viewtopic.php?f=68&t=266652 and we need all these juicy 32 bits for transformation matrices.
            // For this reason, on Linux that buffer is uniform.
            // Not required on Windows, D3D can keep gigabytes in these buffers and read them everywhere.

            BindFlags bindFlags = RuntimeEnvironment.runningWindows ? BindFlags.ShaderResource : BindFlags.UniformBuffer;
            // Set up initial capacity for 170 draw calls. Will grow larger as needed, it's dynamic.
            int initialCapacity = 512 * 16;

            m_moarDrawCalls = new DynamicBuffer(context, bindFlags, initialCapacity);
            return(m_moarDrawCalls);
        }
Exemplo n.º 30
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * 4, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, 4);

            newBuffer.m_BufferObject = new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize       = 0,
                ElementCount    = size,
                ElementWidth    = size,
                Format          = Format.Unknown,
                Dimension       = ShaderResourceViewDimension.Buffer,
                Flags           = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels       = 0
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            return(newBuffer);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates a new instance of the <see cref="T:SharpDX.Direct3D10.Buffer"/> class.
        /// </summary>
        /// <typeparam name="T">Type of the data to upload</typeparam>
        /// <param name="device">The device with which to associate the buffer.</param>
        /// <param name="bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param>
        /// <param name="data">Initial data used to initialize the buffer.</param>
        /// <param name="sizeInBytes">The size, in bytes, of the buffer. If 0 is specified, sizeof(T) is used.</param>
        /// <param name="usage">The usage pattern for the buffer.</param>
        /// <param name="accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param>
        /// <param name="optionFlags">Miscellaneous resource options.</param>
        /// <param name="structureByteStride">The size (in bytes) of the structure element for structured buffers.</param>
        /// <returns>An initialized buffer</returns>
        public static Buffer Create <T>(Device device, BindFlags bindFlags, T[] data, int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : struct
        {
            var buffer = new Buffer(IntPtr.Zero);

            var description = new BufferDescription()
            {
                BindFlags      = bindFlags,
                CpuAccessFlags = accessFlags,
                OptionFlags    = optionFlags,
                SizeInBytes    = sizeInBytes == 0 ? Utilities.SizeOf <T>() * data.Length : sizeInBytes,
                Usage          = usage,
            };

            unsafe
            {
                device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(data)), buffer);
            }
            return(buffer);
        }
Exemplo n.º 32
0
        public DX11RenderMip2D(DX11RenderContext context, int w, int h, Format format, bool allowUAV = false)
        {
            this.context = context;
            int levels = this.CountMipLevels(w, h);

            BindFlags flags = BindFlags.RenderTarget | BindFlags.ShaderResource;

            if (allowUAV)
            {
                flags |= BindFlags.UnorderedAccess;
            }

            var texBufferDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = flags,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = format,
                Height            = h,
                Width             = w,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                MipLevels         = levels,
            };


            this.Resource = new Texture2D(context.Device, texBufferDesc);
            this.desc     = this.Resource.Description;

            this.SRV = new ShaderResourceView(context.Device, this.Resource);

            this.Slices = new DX11MipSliceRenderTarget2D[levels];

            int sw = w;
            int sh = h;

            for (int i = 0; i < levels; i++)
            {
                this.Slices[i] = new DX11MipSliceRenderTarget2D(this.context, this, i, w, h);
                w /= 2; h /= 2;
            }
        }
Exemplo n.º 33
0
        public void Init(
            string name,
            int width,
            int height,
            Format resourceFormat,
            Format srvFormat,
            Format dsvFormat,
            BindFlags bindFlags,
            int samplesCount,
            int samplesQuality,
            ResourceOptionFlags roFlags,
            ResourceUsage ru,
            int mipmapLevels,
            CpuAccessFlags cpuAccessFlags)
        {
            base.Init(name, width, height, resourceFormat, srvFormat, bindFlags, samplesCount, samplesQuality,
                      roFlags, ru, mipmapLevels, cpuAccessFlags);

            m_dsvFormat = dsvFormat;
        }
Exemplo n.º 34
0
        internal MyCustomTexture(int width, int height, BindFlags bindflags,
                                 Format format)
        {
            m_resolution = new Vector2I(width, height);

            Texture2DDescription desc = new Texture2DDescription();

            desc.Width                     = width;
            desc.Height                    = height;
            desc.Format                    = format;
            desc.ArraySize                 = 1;
            desc.MipLevels                 = 1;
            desc.BindFlags                 = bindflags;
            desc.Usage                     = ResourceUsage.Default;
            desc.CpuAccessFlags            = 0;
            desc.SampleDescription.Count   = 1;
            desc.SampleDescription.Quality = 0;
            desc.OptionFlags               = 0;
            m_resource                     = new Texture2D(MyRender11.Device, desc);
        }
Exemplo n.º 35
0
 public Texture1DDescription(
     int width,
     int mipLevels,
     int arraySize,
     int formatID,
     Usage usage,
     BindFlags bindFlags,
     MiscFlags miscFlags,
     ExtraFlags extraFlags)
 {
     Width = width;
     MipLevels = mipLevels;
     ArraySize = arraySize;
     FormatID = formatID;
     Usage = usage;
     BindFlags = bindFlags;
     MiscFlags = miscFlags;
     ExtraFlags = extraFlags;
 }
Exemplo n.º 36
0
        void CreateViews(string name, BindFlags flags, SlimDX.Direct3D11.Resource resource)
        {
            if (flags.HasFlag(BindFlags.RenderTarget))
            {
                var view = new RenderTargetView(m_D3dDevice, resource);
                m_RTVList.Add(name, view);
            }

            if (flags.HasFlag(BindFlags.DepthStencil))
            {
                var view = new DepthStencilView(m_D3dDevice, resource);
                m_DSVList.Add(name, view);
            }

            if (flags.HasFlag(BindFlags.ShaderResource))
            {
                var view = new ShaderResourceView(m_D3dDevice, resource);
                m_SRVList.Add(name, view);
            }

            if (flags.HasFlag(BindFlags.UnorderedAccess))
            {
                var view = new UnorderedAccessView(m_D3dDevice, resource);
                m_UAVList.Add(name, view);
            }
        }
Exemplo n.º 37
0
		public BufferDescription(BindFlags bindFlags)
		{
			SizeInBytes = 0;
			BindFlags = bindFlags;
		}
Exemplo n.º 38
0
        // HACK: figure out a good way...maybe the D3D way really is the right way
        private static Texture2D CreateTexture( int width, int height, int arraySize, int mipLevels,
            Format format, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
        {
            var wrapper = D3D10Wrapper.Instance;
            var desc = new Texture2DDescription
            {
                Width = width,
                Height = height,
                MipLevels = mipLevels,
                ArraySize = arraySize,
                Format = format,
                SampleDescription = new SampleDescription( 1, 0 ),
                Usage = usage,
                BindFlags = bindFlags,
                CpuAccessFlags = cpuAccessFlags,
                OptionFlags = ResourceOptionFlags.None
            };

            if( mipLevels != 1 )
            {
                desc.OptionFlags = ResourceOptionFlags.GenerateMipMaps;
            }

            return new Texture2D( wrapper.Device, desc );
        }
Exemplo n.º 39
0
 public static Texture2D CreateUnsignedByte4MipMapped( int width, int height, int mipLevels,
     ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
 {
     return CreateTexture( width, height, 1, mipLevels, Format.R8G8B8A8_UNorm, usage, bindFlags, cpuAccessFlags );
 }
Exemplo n.º 40
0
        internal static VertexBufferId CreateVertexBuffer(int elements, int stride, BindFlags bind, ResourceUsage usage, IntPtr? data = null, string debugName = null)
        {
            bind |= BindFlags.VertexBuffer;

            BufferDescription desc = new BufferDescription();
            desc.BindFlags = bind;
            desc.SizeInBytes = stride * elements;
            desc.Usage = usage;
            desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None;

            return CreateVertexBuffer(desc, stride, data, debugName);
        }
Exemplo n.º 41
0
        internal MyCustomTexture(int width, int height, BindFlags bindflags,
            Format format)
        {
            m_resolution = new Vector2I(width, height);

            Texture2DDescription desc = new Texture2DDescription();
            desc.Width = width;
            desc.Height = height;
            desc.Format = format;
            desc.ArraySize = 1;
            desc.MipLevels = 1;
            desc.BindFlags = bindflags;
            desc.Usage = ResourceUsage.Default;
            desc.CpuAccessFlags = 0;
            desc.SampleDescription.Count = 1;
            desc.SampleDescription.Quality = 0;
            desc.OptionFlags = 0;
            m_resource = new Texture2D(MyRender11.Device, desc);   
        }
Exemplo n.º 42
0
 public static Texture2D CreateDepth( int width, int height,
     ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
 {
     return CreateTexture( width, height, 1, 1, Format.D24_UNorm_S8_UInt, usage, bindFlags, cpuAccessFlags );
 }
Exemplo n.º 43
0
 public Texture2DDescription(
     int width,
     int height,
     int mipLevels,
     int arraySize,
     int formatID,
     Sampling sampling,
     Usage usage,
     BindFlags bindFlags,
     MiscFlags miscFlags,
     ExtraFlags extraFlags)
 {
     Width = width;
     Height = height;
     MipLevels = mipLevels;
     ArraySize = arraySize;
     FormatID = formatID;
     Sampling = sampling;
     Usage = usage;
     BindFlags = bindFlags;
     MiscFlags = miscFlags;
     ExtraFlags = extraFlags;
 }
Exemplo n.º 44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="sizeInBytes">The size in bytes.</param>
 /// <param name="bindFlags">The bind flags.</param>
 /// <param name="usage">The usage.</param>
 public BufferDescription(int sizeInBytes, BindFlags bindFlags, ResourceUsage usage) : this()
 {
     SizeInBytes = sizeInBytes;
     BindFlags = bindFlags;
     Usage = usage;
 }
Exemplo n.º 45
0
 public Texture3DDescription(
     int width,
     int height,
     int depth,
     int mipLevels,
     int formatIndex,
     Usage usage,
     BindFlags bindFlags,
     MiscFlags miscFlags,
     ExtraFlags extraFlags)
 {
     Width = width;
     Height = height;
     Depth = depth;
     MipLevels = mipLevels;
     FormatID = formatIndex;
     Usage = usage;
     BindFlags = bindFlags;
     MiscFlags = miscFlags;
     ExtraFlags = extraFlags;
 }
Exemplo n.º 46
0
 public static Texture2D CreateFloat4( int width, int height,
     ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
 {
     return CreateTexture( width, height, 1, 1, Format.R32G32B32A32_Float, usage, bindFlags, cpuAccessFlags );
 }
Exemplo n.º 47
0
        public void Init(
            string name,
            int width,
            int height,
            Format resourceFormat,
            Format srvFormat,
            Format dsvFormat,
            BindFlags bindFlags,
            int samplesCount,
            int samplesQuality,
            ResourceOptionFlags roFlags,
            ResourceUsage ru,
            int mipmapLevels,
            CpuAccessFlags cpuAccessFlags)
        {
            base.Init(name, width, height, resourceFormat, srvFormat, bindFlags, samplesCount, samplesQuality,
                roFlags, ru, mipmapLevels, cpuAccessFlags);

            m_dsvFormat = dsvFormat;
        }
Exemplo n.º 48
0
 public static Texture2D CreateUnsignedByte4Array( int width, int height, int arraySize,
     ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
 {
     return CreateTexture( width, height, arraySize, 1, Format.R8G8B8A8_UNorm, usage, bindFlags, cpuAccessFlags );
 }
Exemplo n.º 49
0
 public static Texture2D CreateDepth( Vector2i size,
     ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags )
 {
     return CreateDepth( size.x, size.y, usage, bindFlags, cpuAccessFlags );
 }
Exemplo n.º 50
0
        internal static IndexBufferId CreateIndexBuffer(int elements, Format format, BindFlags bind, ResourceUsage usage, IntPtr? data = null, string debugName = null)
        {
            bind |= BindFlags.IndexBuffer;

            Debug.Assert(format == Format.R32_UInt || format == Format.R16_UInt);

            BufferDescription desc = new BufferDescription();
            desc.BindFlags = bind;
            desc.SizeInBytes = elements * (format == Format.R32_UInt ? 4 : 2);
            desc.Usage = usage;
            desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None;

            return CreateIndexBuffer(desc, format, data, debugName);
        }
Exemplo n.º 51
0
        public SharpDXBuffer(DxDevice nativeDevice, int sizeInBytes, BindFlags flags)
            : base(nativeDevice, sizeInBytes, ResourceUsage.Dynamic, flags, CpuAccessFlags.Write,
				ResourceOptionFlags.None, 0)
        {
        }