コード例 #1
0
ファイル: GorgonBaseBuffer.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonBaseBuffer"/> class.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="name">The name.</param>
        /// <param name="settings">The settings.</param>
        protected GorgonBaseBuffer(GorgonGraphics graphics, string name, IBufferSettings settings)
            : base(graphics, name)
        {
            _viewCache = new GorgonViewCache(this);

            Settings = settings;

            D3DUsage = (D3D.ResourceUsage)settings.Usage;

            // Determine access rights.
            switch (settings.Usage)
            {
            case BufferUsage.Dynamic:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.Write;
                break;

            case BufferUsage.Immutable:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.None;
                break;

            case BufferUsage.Staging:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.Write | D3D.CpuAccessFlags.Read;
                break;

            default:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.None;
                break;
            }
        }
コード例 #2
0
ファイル: GorgonBuffers.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to perform validation upon the settings for a generic buffer.
        /// </summary>
        internal static void ValidateGenericBufferSettings(IBufferSettings settings)
        {
            if (settings == null)
            {
                return;
            }

            // Ensure that we can actually put something into our buffer.
            if (settings.SizeInBytes <= 4)
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_BUFFER_SIZE_TOO_SMALL, 4));
            }

            // Only allow raw views if we've provided a shader view and/or an unordered access view.
            if ((settings.AllowRawViews) &&
                (!settings.AllowShaderViews) &&
                (!settings.AllowUnorderedAccessViews))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_RAW_ACCESS_REQUIRES_VIEW_ACCESS);
            }

            if ((settings.IsOutput) && (settings.AllowUnorderedAccessViews))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_OUTPUT_NO_UNORDERED);
            }

            // Do not allow staging usage with any of these.
            if ((settings.Usage == BufferUsage.Staging) &&
                ((settings.AllowIndirectArguments) ||
                 (settings.AllowShaderViews) ||
                 (settings.AllowRawViews) ||
                 (settings.AllowUnorderedAccessViews) ||
                 (settings.IsOutput)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_NO_STAGING_INVALID_FLAGS);
            }

            // Do not allow dynamic usage with any of these.
            if ((settings.Usage == BufferUsage.Dynamic) &&
                ((settings.AllowIndirectArguments) ||
                 (settings.AllowUnorderedAccessViews) ||
                 (settings.IsOutput)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_NO_DYNAMIC_INVALID_FLAGS);
            }

            if ((settings.DefaultShaderViewFormat != BufferFormat.Unknown) && (!settings.AllowShaderViews))
            {
                throw new GorgonException(GorgonResult.CannotBind, Resources.GORGFX_BUFFER_NO_SHADER_VIEWS);
            }
        }
コード例 #3
0
ファイル: GorgonBuffers.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to perform validation upon the settings for a structured buffer.
        /// </summary>
        /// <param name="settings">Settings to test.</param>
        private static void ValidateStructuredBufferSettings(IBufferSettings settings)
        {
            if (settings.StructureSize <= 0)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_STRUCTURE_SIZE_INVALID);
            }

            // Round up to the next multiple of 4.
            while ((settings.StructureSize % 4) != 0)
            {
                settings.StructureSize++;
            }

            ValidateGenericBufferSettings(settings);
        }
コード例 #4
0
ファイル: GorgonBuffers.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to perform validation upon the settings for a constant buffer.
        /// </summary>
        private static void ValidateConstantBufferSettings(IBufferSettings settings)
        {
            // Ensure that we can actually put something into our buffer.
            if (settings.SizeInBytes < 16)
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_BUFFER_SIZE_TOO_SMALL, 16));
            }

            // Allow only a multiple of 16.
            while ((settings.SizeInBytes % 16) != 0)
            {
                settings.SizeInBytes++;
            }

            ValidateGenericBufferSettings(settings);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonConstantBuffer"/> class.
 /// </summary>
 /// <param name="graphics">Graphics interface that owns this buffer.</param>
 /// <param name="name">Name of the constant buffer.</param>
 /// <param name="settings">Settings for the buffer.</param>
 internal GorgonConstantBuffer(GorgonGraphics graphics, string name, IBufferSettings settings)
     : base(graphics, name, settings)
 {
 }