/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="format">The format of the view.</param> /// <param name="firstElement">The first element in the buffer.</param> /// <param name="elementCount">The number of elements to view.</param> /// <param name="isRaw">TRUE if the view should be a raw view, FALSE if not.</param> internal GorgonBufferUnorderedAccessView(GorgonResource resource, BufferFormat format, int firstElement, int elementCount, bool isRaw) : base(resource, format) { IsRaw = isRaw; ElementStart = firstElement; ElementCount = elementCount; _buffer = resource as GorgonBuffer; _indexBuffer = resource as GorgonIndexBuffer; _vertexBuffer = resource as GorgonVertexBuffer; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferShaderView"/> class. /// </summary> /// <param name="buffer">The buffer to bind to the view.</param> /// <param name="format">Format of the view.</param> /// <param name="elementStart">The starting element for the view.</param> /// <param name="elementCount">The number of elements in the view.</param> /// <param name="isRaw">TRUE to use a raw view, FALSE to use a normal view.</param> internal GorgonBufferShaderView(GorgonResource buffer, BufferFormat format, int elementStart, int elementCount, bool isRaw) : base(buffer, format) { IsRaw = isRaw; ElementStart = elementStart; ElementCount = elementCount; _buffer = buffer as GorgonBuffer; _structuredBuffer = buffer as GorgonStructuredBuffer; _indexBuffer = buffer as GorgonIndexBuffer; _vertexBuffer = buffer as GorgonVertexBuffer; }
/// <summary> /// Function to execute the current compute shader using an indirect argument buffer. /// </summary> /// <param name="indirectArgsBuffer">The indirect argument buffer to use.</param> /// <param name="alignedOffset">The byte aligned offset into the buffer to start at.</param> /// <remarks>Call dispatch to execute the commands in the compute shader. A compute shader can be run on multiple threads in parallel within a threading group. Use a particular threading group /// within the shader by using a 3D vector (float3). /// <para>The <paramref name="indirectArgsBuffer"/> must be loaded with data that matches the argument list of <see cref="Dispatch(int, int, int)"/>.</para></remarks> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="indirectArgsBuffer"/> was NULL (Nothing in VB.Net).</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="alignedOffset"/> parameter is less than 0 or not less than the number of bytes in the buffer.</exception> /// <exception cref="System.ArgumentException">Thrown when the buffer passed in through <paramref name="indirectArgsBuffer"/> was not created as an indirect argument buffer.</exception> public void Dispatch(GorgonBuffer indirectArgsBuffer, int alignedOffset) { GorgonDebug.AssertNull(indirectArgsBuffer, "indirectArgsBuffer"); GorgonDebug.AssertParamRange(alignedOffset, 0, indirectArgsBuffer.SizeInBytes, "alignedOffset"); #if DEBUG if (!indirectArgsBuffer.Settings.AllowIndirectArguments) { throw new ArgumentException(Properties.Resources.GORGFX_BUFFER_NOT_INDIRECT, "indirectArgsBuffer"); } #endif Graphics.Context.DispatchIndirect(indirectArgsBuffer.D3DBuffer, alignedOffset); }
/// <summary> /// Function to create a generic buffer. /// </summary> /// <param name="name">Name of the buffer.</param> /// <param name="settings">The settings for the buffer.</param> /// <param name="stream">[Optional] Stream used to initialize the buffer.</param> /// <returns>A new generic buffer object.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net). /// <para>-or-</para> /// <para>Thrown when the <paramref name="settings"/> parameter is NULL.</para> /// </exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the <see cref="GorgonLibrary.Graphics.GorgonBufferSettings.IsOutput">IsOutput</see> property is TRUE and has a usage that is not Default. /// <para>-or-</para> /// <para>Thrown when the <see cref="GorgonLibrary.Graphics.GorgonBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is less than 1.</para> /// <para>-or-</para> /// <para>Thrown when the usage is set to immutable and the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net) or has no data.</para> /// </exception> /// <remarks>The generic buffer is intended to be used with the [RW]Buffer<> HLSL type. /// <para>Generic buffers are only available on video devices that are capable of SM4 or better.</para> /// <para>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</para> /// </remarks> public GorgonBuffer CreateBuffer(string name, GorgonBufferSettings settings, GorgonDataStream stream = null) { if (_graphics.IsDeferred) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT); } if (name == null) { throw new ArgumentNullException("name"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (name.Length == 0) { throw new ArgumentException(Resources.GORGFX_PARAMETER_MUST_NOT_BE_EMPTY, "name"); } if ((settings.Usage == BufferUsage.Immutable) && ((stream == null) || (stream.Length == 0))) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA); } if ((settings.Usage == BufferUsage.Dynamic) && (!settings.AllowShaderViews)) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_DYNAMIC_NEEDS_SHADER_VIEW); } // Validate our buffer settings. ValidateGenericBufferSettings(settings); var buffer = new GorgonBuffer(_graphics, name, settings); buffer.Initialize(stream); _graphics.AddTrackedObject(buffer); return(buffer); }