コード例 #1
0
        /// <summary>
        /// Function to create a new <see cref="GorgonStructuredReadWriteView"/> for this buffer.
        /// </summary>
        /// <param name="startElement">[Optional] The first element to start viewing from.</param>
        /// <param name="elementCount">[Optional] The number of elements to view.</param>
        /// <param name="uavType">[Optional] The type of uav to create.</param>
        /// <returns>A <see cref="GorgonStructuredReadWriteView"/> used to bind the buffer to a shader.</returns>
        /// <exception cref="GorgonException">
        /// Thrown when this buffer does not have a <see cref="BufferBinding"/> of <see cref="BufferBinding.ReadWrite"/>.
        /// <para>-or-</para>
        /// <para>Thrown when this buffer has a usage of <see cref="ResourceUsage.Staging"/>.</para>
        /// </exception>
        /// <remarks>
        /// <para>
        /// This will create an unordered access view that makes a buffer accessible to shaders using unordered access to the data. This allows viewing of the buffer data in a
        /// different format, or even a subsection of the buffer from within the shader.
        /// </para>
        /// <para>
        /// The <paramref name="startElement"/> parameter defines the starting data element to allow access to within the shader. If this value falls outside of the range of available elements, then it
        /// will be clipped to the upper and lower bounds of the element range. If this value is left at 0, then first element is viewed.
        /// </para>
        /// <para>
        /// The <paramref name="elementCount"/> parameter defines how many elements to allow access to inside of the view. If this value falls outside of the range of available elements, then it will be
        /// clipped to the upper or lower bounds of the element range. If this value is left at 0, then the entire buffer is viewed.
        /// </para>
        /// <para>
        /// The <paramref name="uavType"/> parameter specifies whether the buffer can be used as an <see cref="StructuredBufferReadWriteViewType.Append"/>/Consume buffer or
        /// <see cref="StructuredBufferReadWriteViewType.Counter"/> by the shader.
        /// </para>
        /// </remarks>
        public GorgonStructuredReadWriteView GetStructuredReadWriteView(int startElement = 0, int elementCount = 0, StructuredBufferReadWriteViewType uavType = StructuredBufferReadWriteViewType.None)
        {
            if ((Usage == ResourceUsage.Staging) ||
                ((Binding & BufferBinding.ReadWrite) != BufferBinding.ReadWrite))
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_UAV_RESOURCE_NOT_VALID, Name));
            }

            // Ensure the size of the data type fits the requested format.
            int totalElementCount = GetTotalStructuredElementCount();

            startElement = startElement.Min(totalElementCount - 1).Max(0);

            if (elementCount <= 0)
            {
                elementCount = totalElementCount - startElement;
            }

            elementCount = elementCount.Min(totalElementCount - startElement).Max(1);

            var key = new BufferShaderViewKey(startElement, elementCount, (int)uavType);
            GorgonStructuredReadWriteView result = GetReadWriteView <GorgonStructuredReadWriteView>(key);

            if (result != null)
            {
                return(result);
            }

            result = new GorgonStructuredReadWriteView(this, uavType, startElement, elementCount, totalElementCount);
            result.CreateNativeView();
            RegisterReadWriteView(key, result);

            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonStructuredReadWriteView"/> class.
 /// </summary>
 /// <param name="buffer">The buffer to assign to the view.</param>
 /// <param name="elementStart">The first element in the buffer to view.</param>
 /// <param name="elementCount">The number of elements in the view.</param>
 /// <param name="totalElementCount">The total number of elements in the buffer.</param>
 /// <param name="uavType">Flags used to indicate the purpose of this view.</param>
 internal GorgonStructuredReadWriteView(GorgonBuffer buffer,
                                        StructuredBufferReadWriteViewType uavType,
                                        int elementStart,
                                        int elementCount,
                                        int totalElementCount)
     : base(buffer, elementStart, elementCount, totalElementCount) => ReadWriteViewType = uavType;