Exemple #1
0
    /// <summary>
    /// Creates a new <see cref="GraphicsDeviceMismatchException"/> instance from the specified parameters.
    /// </summary>
    /// <param name="resource">The input <see cref="NativeObject"/> that was used.</param>
    /// <param name="sourceDevice">The source <see cref="GraphicsDevice"/> instance tied to <paramref name="resource"/>.</param>
    /// <param name="destinationDevice">The target <see cref="GraphicsDevice"/> instance that was used.</param>
    /// <returns>A new <see cref="GraphicsDeviceMismatchException"/> instance with a formatted error message.</returns>
    /// <remarks>
    /// This method only takes a <see cref="NativeObject"/> instance and the associated <see cref="GraphicsDevice"/> instance as
    /// <see cref="object.GetType"/> will still be available, but without the unnecessary generic type specializations for the method.
    /// </remarks>
    private static GraphicsDeviceMismatchException Create(NativeObject resource, GraphicsDevice sourceDevice, GraphicsDevice destinationDevice)
    {
        StringBuilder builder = new(512);

        builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
        builder.AppendLine($"The target device to run the compute shader is \"{destinationDevice}\".");
        builder.AppendLine($"The buffer of type {resource.GetType()} was allocated on device \"{sourceDevice}\".");
        builder.Append("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
        builder.ToString();

        return(new(builder.ToString()));
    }