/// <summary> /// Function to copy the structure count from this view into a buffer. /// </summary> /// <param name="buffer">The buffer that will receive the data.</param> /// <param name="offset">[Optional] The offset, in bytes, within the buffer attached to this view to start reading from.</param> /// <remarks> /// <para> /// When the structure unordered access view is set up with a <see cref="StructuredBufferReadWriteViewType.Append"/>, or <see cref="StructuredBufferReadWriteViewType.Counter"/>, the values updated by these flags are /// not readily accessible from the CPU. To retrieve these values, this method must be called to retrieve the values. These values are copied into the <paramref name="buffer"/> provided to the /// method so that applications can make use of data generated on the GPU. Note that this value will be written out as a 32 bit unsigned integer. /// </para> /// <para> /// If the unordered access view does not specify the appropriate values on the <see cref="ReadWriteViewType"/>, then this method will do nothing. /// </para> /// <para> /// <note type="important"> /// <para> /// For performance reasons, exceptions will only be thrown from this method when Gorgon is compiled as <b>DEBUG</b>. /// </para> /// </note> /// </para> /// </remarks> public void CopyStructureCount(GorgonBufferCommon buffer, int offset = 0) { buffer.ValidateObject(nameof(buffer)); offset.ValidateRange(nameof(offset), 0, Buffer.SizeInBytes - 4); buffer.Graphics.D3DDeviceContext.CopyStructureCount(buffer.Native, offset, Native); }
/// <summary> /// Function to determine if a buffer type is valid or not. /// </summary> /// <param name="buffer">The buffer to validate.</param> private static void IsValidBufferType(GorgonBufferCommon buffer) { switch (buffer) { case null: return; case GorgonConstantBuffer _: // Deny constant buffers entirely. throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_ERR_BUFFER_CONSTANT_NO_SO); case GorgonIndexBuffer indexBuffer when((indexBuffer.Binding & VertexIndexBufferBinding.StreamOut) != VertexIndexBufferBinding.StreamOut): case GorgonVertexBuffer vertexBuffer when((vertexBuffer.Binding & VertexIndexBufferBinding.StreamOut) != VertexIndexBufferBinding.StreamOut): case GorgonBuffer genericBuffer when((genericBuffer.Binding & BufferBinding.StreamOut) == BufferBinding.StreamOut): throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_BUFFER_TYPE_MISSING_SO, buffer.Name)); } }
/// <summary> /// Function to execute a <see cref="GorgonComputeShader"/> using a buffer for argument passing. /// </summary> /// <param name="dispatchCall">The <see cref="GorgonDispatchCall"/> to execute.</param> /// <param name="indirectArgs">The buffer containing the arguments for the compute shader.</param> /// <param name="threadGroupOffset">[Optional] The offset within the buffer, in bytes, to where the arguments are stored.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="dispatchCall"/>, or the <paramref name="indirectArgs"/> parameter is <b>null</b>.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="threadGroupOffset"/> is less than 0.</exception> /// <remarks> /// <para> /// This will take the <see cref="GorgonDispatchCall"/> and execute it using the <paramref name="indirectArgs"/> buffer. This method will also bind any buffers set up to the GPU prior to executing /// the shader. /// </para> /// <para> /// The <paramref name="indirectArgs"/> buffer must contain the thread group count arguments for a <see cref="GorgonDispatchCall.ComputeShader"/>. The <paramref name="threadGroupOffset"/>, will instruct the GPU /// to begin reading these arguments at the specified offset. /// </para> /// <para> /// This method differs from the <see cref="Execute(GorgonDispatchCall,int,int,int)"/> overload in that it uses a buffer to retrieve the arguments to send to the next compute /// shader workload. Like the <see cref="GorgonGraphics.SubmitStreamOut"/> method, this method takes a variable sized output from a previous compute shader workload and allows it to be passed directly /// to the shader without having to stall on the CPU side by retrieving count values. /// </para> /// <para> /// <note type="important"> /// <para> /// For performance reasons, this method will only throw exceptions when Gorgon is compiled as <b>DEBUG</b>. /// </para> /// </note> /// </para> /// </remarks> public void Execute(GorgonDispatchCall dispatchCall, GorgonBufferCommon indirectArgs, int threadGroupOffset = 0) => Graphics.Dispatch(dispatchCall, indirectArgs, threadGroupOffset);