Merge pull request #175 from Sergio0694/refactor/gpu-rename

Rename Gpu class to GraphicsDevice
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-12-08 00:40:18 +01:00
コミット 25b8ed1ac8
23ファイル変更
+88 -90

検索条件に一致するファイルはありません

+13 -13
ファイルの表示
@@ -42,7 +42,7 @@ More details available [here](https://www.nuget.org/packages/ComputeSharp/).
# Quick start
**ComputeSharp** exposes a `Gpu` class that acts as entry point for all public APIs. The available `Gpu.Default` property that lets you access the main GPU device on the current machine, which can be used to allocate buffers and perform operations. If your machine doesn't have a supported GPU (or if it doesn't have a GPU at all), **ComputeSharp** will automatically create a [WARP device](https://docs.microsoft.com/windows/win32/direct3darticles/directx-warp) instead, which will still let you use the library normally, with shaders running on the CPU instead through an emulation layer. This means that you don't need to manually write a fallback path in case no GPU is available - **ComputeSharp** will automatically handle this for you.
**ComputeSharp** exposes a `GraphicsDevice` class that acts as entry point for all public APIs. The available `GraphicsDevice.Default` property that lets you access the main GPU device on the current machine, which can be used to allocate buffers and perform operations. If your machine doesn't have a supported GPU (or if it doesn't have a GPU at all), **ComputeSharp** will automatically create a [WARP device](https://docs.microsoft.com/windows/win32/direct3darticles/directx-warp) instead, which will still let you use the library normally, with shaders running on the CPU instead through an emulation layer. This means that you don't need to manually write a fallback path in case no GPU is available - **ComputeSharp** will automatically handle this for you.
Let's suppose we want to run a simple compute shader that multiplies all items in a target buffer by two. The first step is to create the GPU buffer and copy our data to it:
@@ -53,7 +53,7 @@ int[] array = Enumerable.Range(1, 100).ToArray();
// Allocate a GPU buffer and copy the data to it.
// We want the shader to modify the items in-place, so we
// can allocate a single read-write buffer to work on.
using ReadWriteBuffer<int> buffer = Gpu.Default.AllocateReadWriteBuffer(array);
using ReadWriteBuffer<int> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
```
The `AllocateReadWriteBuffer` extension takes care of creating a `ReadWriteBuffer<T>` instance with the same size as the input array and copying its contents to the allocated GPU buffer. There are a number of overloads available as well, to create buffers of different types and with custom length.
@@ -79,7 +79,7 @@ We can now finally run the GPU shader and copy the data back to our array:
```csharp
// Launch the shader
Gpu.Default.For(buffer.Length, new MultiplyByTwo(buffer));
GraphicsDevice.Default.For(buffer.Length, new MultiplyByTwo(buffer));
// Get the data back
buffer.CopyTo(array);
@@ -216,10 +216,10 @@ As mentioned in the [GPU resource types](#gpu-resource-types) paragraph, there a
```csharp
// Load a texture from a specified image, and decode it in the BGRA32 format
using var texture = Gpu.Default.LoadReadWriteTexture2D<Bgra32, float4>("myImage.jpg");
using var texture = GraphicsDevice.Default.LoadReadWriteTexture2D<Bgra32, float4>("myImage.jpg");
// Run our shader on the texture we just loaded
Gpu.Default.For(texture.Width, texture.Height, new GrayscaleEffect(texture));
GraphicsDevice.Default.For(texture.Width, texture.Height, new GrayscaleEffect(texture));
// Save the processed image by overwriting the original image
texture.Save("myImage.jpg");
@@ -253,10 +253,10 @@ You can also use a similar technique to create a blank texture, render a single
```csharp
// Create a blank 1280x720 surface for us to render to
using var texture = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, float4>(1280, 720);
using var texture = GraphicsDevice.Default.AllocateReadWriteTexture2D<Bgra32, float4>(1280, 720);
// Using an existing shader from our samples, we can render a specific time frame
Gpu.Default.ForEach(texture, new FourColorGradient(0));
GraphicsDevice.Default.ForEach(texture, new FourColorGradient(0));
// Save the result to a file on disk
texture.Save("output.png");
@@ -291,10 +291,10 @@ Then we can simply create a new `Func<float, float>` instance and use that to co
float[] array = LoadSampleData();
// Allocate the buffer and copy data to it
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer(array);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
// Run the shader
Gpu.Default.For(width, height, new ApplyFunction(buffer, Square));
GraphicsDevice.Default.For(width, height, new ApplyFunction(buffer, Square));
// Copy the processed data back as usual
buffer.CopyTo(array);
@@ -323,10 +323,10 @@ There are cases where it might be needed to manually interop with other DirectX
using ComPtr<ID3D12Device> d3D12Device = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(128);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(128);
// Get the underlying ID3D12Device object
InteropServices.GetID3D12Device(Gpu.Default, __uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());
InteropServices.GetID3D12Device(GraphicsDevice.Default, __uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());
// Get the underlying ID3D12Resource object
InteropServices.GetID3D12Resource(buffer, __uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
@@ -363,12 +363,12 @@ Assuming we had the `MultiplyByTwo` shader defined in the [Quick start](#quick-s
let array = [| for i in 1 .. 100 -> (float32)i |]
// Create the graphics buffer
use buffer = Gpu.Default.AllocateReadWriteBuffer(array)
use buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array)
let shader = new MultiplyByTwo(buffer)
// Run the shader (passed by reference)
Gpu.Default.For(100, &shader)
GraphicsDevice.Default.For(100, &shader)
// Get the data back
buffer.CopyTo array
+10 -10
ファイルの表示
@@ -100,10 +100,10 @@ public class BlasBenchmark : IDisposable
B = CreateRandomArray(P);
Y = CreateRandomArray(C * N * P);
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
BufferX = GraphicsDevice.Default.AllocateReadOnlyBuffer(X);
BufferW = GraphicsDevice.Default.AllocateReadOnlyBuffer(W);
BufferB = GraphicsDevice.Default.AllocateReadOnlyBuffer(B);
BufferY = GraphicsDevice.Default.AllocateReadWriteBuffer(Y);
Cpu();
GpuWithNoTemporaryBuffers();
@@ -140,7 +140,7 @@ public class BlasBenchmark : IDisposable
[Benchmark]
public void GpuWithNoTemporaryBuffers()
{
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
BlasHelpers.FullyConnectedForwardGpu(GraphicsDevice.Default, C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
}
/// <summary>
@@ -149,12 +149,12 @@ public class BlasBenchmark : IDisposable
[Benchmark]
public void GpuWithTemporaryBuffers()
{
using ReadOnlyBuffer<float> x = Gpu.Default.AllocateReadOnlyBuffer(X!);
using ReadOnlyBuffer<float> w = Gpu.Default.AllocateReadOnlyBuffer(W!);
using ReadOnlyBuffer<float> b = Gpu.Default.AllocateReadOnlyBuffer(B!);
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(Y!.Length);
using ReadOnlyBuffer<float> x = GraphicsDevice.Default.AllocateReadOnlyBuffer(X!);
using ReadOnlyBuffer<float> w = GraphicsDevice.Default.AllocateReadOnlyBuffer(W!);
using ReadOnlyBuffer<float> b = GraphicsDevice.Default.AllocateReadOnlyBuffer(B!);
using ReadWriteBuffer<float> y = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(Y!.Length);
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);
BlasHelpers.FullyConnectedForwardGpu(GraphicsDevice.Default, C, N, M, P, x, w, b, y);
y.CopyTo(Y);
}
+2 -2
ファイルの表示
@@ -26,7 +26,7 @@ public sealed partial class HlslBokehBlurProcessor : IImageProcessor
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
public HlslBokehBlurProcessor()
: this(Gpu.Default, DefaultRadius, DefaultComponents)
: this(GraphicsDevice.Default, DefaultRadius, DefaultComponents)
{
}
@@ -36,7 +36,7 @@ public sealed partial class HlslBokehBlurProcessor : IImageProcessor
/// <param name="radius">The size of the area to sample.</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
public HlslBokehBlurProcessor(int radius, int components)
: this(Gpu.Default, radius, components)
: this(GraphicsDevice.Default, radius, components)
{
}
+2 -2
ファイルの表示
@@ -21,7 +21,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
public HlslGaussianBlurProcessor()
: this(Gpu.Default, DefaultSigma, 9)
: this(GraphicsDevice.Default, DefaultSigma, 9)
{
}
@@ -30,7 +30,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
/// </summary>
/// <param name="radius">The radius value representing the size of the area to sample.</param>
public HlslGaussianBlurProcessor(int radius)
: this(Gpu.Default, radius / 3F, radius)
: this(GraphicsDevice.Default, radius / 3F, radius)
{
}
+2 -2
ファイルの表示
@@ -32,12 +32,12 @@ let main _ =
let array = [| for i in 1 .. 100 -> (float32)i |]
// Create the graphics buffer
use buffer = Gpu.Default.AllocateReadWriteBuffer(array)
use buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array)
let shader = new MultiplyByTwo(buffer)
// Run the shader (passed by reference)
Gpu.Default.For(100, &shader)
GraphicsDevice.Default.For(100, &shader)
// Print the initial matrix
printMatrix array 10 10 "BEFORE"
+2 -2
ファイルの表示
@@ -11,10 +11,10 @@ partial class Program
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
// Create the graphics buffer
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
using ReadWriteBuffer<float> gpuBuffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
// Run the shader
Gpu.Default.For(100, new MainKernel(gpuBuffer));
GraphicsDevice.Default.For(100, new MainKernel(gpuBuffer));
// Print the initial matrix
PrintMatrix(array, 10, 10, "BEFORE");
+2 -2
ファイルの表示
@@ -29,9 +29,9 @@ public sealed class ContouredLayersRunner : IShaderRunner
{
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
this.texture = GraphicsDevice.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
}
Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
GraphicsDevice.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
}
}
+3 -3
ファイルの表示
@@ -90,7 +90,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
// Get the underlying ID3D12Device in use
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
{
_ = InteropServices.TryGetID3D12Device(Gpu.Default, Windows.__uuidof<ID3D12Device>(), (void**)d3D12Device);
_ = InteropServices.TryGetID3D12Device(GraphicsDevice.Default, Windows.__uuidof<ID3D12Device>(), (void**)d3D12Device);
}
// Create the direct command queue to use
@@ -217,7 +217,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
// Create the 2D texture to use to generate frames to display
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, float4>(
this.texture = GraphicsDevice.Default.AllocateReadWriteTexture2D<Rgba32, float4>(
(int)d3D12Resource0Description.Width,
(int)d3D12Resource0Description.Height);
}
@@ -233,7 +233,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
}
// Generate the new frame
Gpu.Default.ForEach(this.texture!, this.shaderFactory(time));
GraphicsDevice.Default.ForEach(this.texture!, this.shaderFactory(time));
using ComPtr<ID3D12Resource> d3D12Resource = default;
+1 -1
ファイルの表示
@@ -79,6 +79,6 @@ class Program
{
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png");
return Gpu.Default.LoadReadOnlyTexture2D<Rgba32, float4>(filename);
return GraphicsDevice.Default.LoadReadOnlyTexture2D<Rgba32, float4>(filename);
}
}
+2 -2
ファイルの表示
@@ -171,7 +171,7 @@ public sealed partial class ComputeShaderPanel
// Get the underlying ID3D12Device in use
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
{
InteropServices.TryGetID3D12Device(Gpu.Default, Win32.__uuidof<ID3D12Device>(), (void**)d3D12Device).Assert();
InteropServices.TryGetID3D12Device(GraphicsDevice.Default, Win32.__uuidof<ID3D12Device>(), (void**)d3D12Device).Assert();
}
// Create the direct command queue to use
@@ -342,7 +342,7 @@ public sealed partial class ComputeShaderPanel
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
// Create the 2D texture to use to generate frames to display
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(
this.texture = GraphicsDevice.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(
(int)d3D12Resource0Description.Width,
(int)d3D12Resource0Description.Height);
}
+1 -1
ファイルの表示
@@ -40,6 +40,6 @@ public sealed class ShaderRunner<T> : IShaderRunner
/// <inheritdoc/>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time)
{
Gpu.Default.ForEach(texture, this.shaderFactory(time));
GraphicsDevice.Default.ForEach(texture, this.shaderFactory(time));
}
}
+2 -4
ファイルの表示
@@ -5,10 +5,8 @@ using ComputeSharp.Graphics.Helpers;
namespace ComputeSharp;
/// <summary>
/// A <see langword="class"/> that acts as an entry-point for all the library APIs, exposing the available GPU devices.
/// </summary>
public static class Gpu
/// <inheritdoc/>
partial class GraphicsDevice
{
/// <summary>
/// Gets the default <see cref="GraphicsDevice"/> instance for the current machine.
+1 -1
ファイルの表示
@@ -22,7 +22,7 @@ namespace ComputeSharp;
/// A <see langword="class"/> that represents an <see cref="ID3D12Device"/> instance that can be used to run compute shaders.
/// </summary>
[DebuggerDisplay("{ToString(),raw}")]
public sealed unsafe class GraphicsDevice : NativeObject
public sealed unsafe partial class GraphicsDevice : NativeObject
{
/// <summary>
/// The underlying <see cref="ID3D12Device"/> wrapped by the current instance.
+20 -20
ファイルの表示
@@ -23,11 +23,11 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void CapturedResource()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
((IShader)new CapturedResourceShader(buffer)).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)new CapturedResourceShader(buffer)).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(3, dataLoader.Values.Length);
Assert.AreEqual(1, dataLoader.Resources.Length);
@@ -55,12 +55,12 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void LoadMultipleResourcesAndPrimitives()
{
using ReadWriteBuffer<float> buffer0 = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer1 = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer0 = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer1 = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
((IShader)new MultipleResourcesAndPrimitivesShader(buffer0, buffer1, 1, 22, 77)).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)new MultipleResourcesAndPrimitivesShader(buffer0, buffer1, 1, 22, 77)).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(6, dataLoader.Values.Length);
Assert.AreEqual(2, dataLoader.Resources.Length);
@@ -94,12 +94,12 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void LoadScalarAndVectorTypes()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
ScalarAndVectorTypesShader shader = new(buffer, new(55, 44, 888), 22, 77, new(3.14, 6.28), 42, 9999);
((IShader)shader).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(18, dataLoader.Values.Length);
Assert.AreEqual(1, dataLoader.Resources.Length);
@@ -147,7 +147,7 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void LoadScalarVectorAndMatrixTypes()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
ScalarVectorAndMatrixTypesShader shader = new(
@@ -161,7 +161,7 @@ public partial class ShaderDataLoaderTests
i2x2: new(11, 22, 33, 44),
d: 9999);
((IShader)shader).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(31, dataLoader.Values.Length);
Assert.AreEqual(1, dataLoader.Resources.Length);
@@ -226,7 +226,7 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void LoadFlatCustomTypeShader()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
FlatCustomTypeShader shader = new(
@@ -241,7 +241,7 @@ public partial class ShaderDataLoaderTests
i2x2: new(11, 22, 33, 44),
d: 9999));
((IShader)shader).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(31, dataLoader.Values.Length);
Assert.AreEqual(1, dataLoader.Resources.Length);
@@ -318,7 +318,7 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void LoadNestedCustomTypes()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
NestedCustomTypesShader shader = new(
@@ -345,7 +345,7 @@ public partial class ShaderDataLoaderTests
a: 888888,
b: new(333.3f, 444.4f))));
((IShader)shader).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(47, dataLoader.Values.Length);
Assert.AreEqual(1, dataLoader.Resources.Length);
@@ -417,16 +417,16 @@ public partial class ShaderDataLoaderTests
[TestMethod]
public unsafe void AmbiguousNames()
{
using ReadWriteBuffer<float> a = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> b = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> c = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> x = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> z = Gpu.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> a = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> b = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> c = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> x = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> y = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
using ReadWriteBuffer<float> z = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(16);
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
((IShader)new AmbiguousNamesShader(a, b, c, x, y, z, 7777, 8888, 9999)).LoadDispatchData(ref dataLoader, Gpu.Default, 111, 222, 333);
((IShader)new AmbiguousNamesShader(a, b, c, x, y, z, 7777, 8888, 9999)).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);
Assert.AreEqual(6, dataLoader.Values.Length);
Assert.AreEqual(6, dataLoader.Resources.Length);
+2 -2
ファイルの表示
@@ -25,7 +25,7 @@ public partial class ShaderHashCodeTests
public void ShaderWithNoCapturedDelegates()
{
float value = 10;
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(1);
Shader1 shader1 = new() { A = value, B = buffer };
@@ -58,7 +58,7 @@ public partial class ShaderHashCodeTests
{
Func<float, float> f = static x => x * x;
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1);
using ReadWriteBuffer<float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer<float>(1);
Shader2 shader1 = new() { A = 1, B = buffer, F = f };
+2 -2
ファイルの表示
@@ -132,8 +132,8 @@ public partial class BufferTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};
+3 -3
ファイルの表示
@@ -5,7 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests.Extensions;
/// <summary>
/// A helper class for testing <see cref="Gpu"/> APIs.
/// A helper class for testing <see cref="GraphicsDevice"/> APIs.
/// </summary>
public static class DeviceExtensions
{
@@ -19,8 +19,8 @@ public static class DeviceExtensions
{
GraphicsDevice? device = type switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => ThrowHelper.ThrowArgumentException<GraphicsDevice>("Invalid device")
};
+8 -8
ファイルの表示
@@ -13,7 +13,7 @@ public partial class InitializationTests
[TestMethod]
public void IsSupported()
{
Assert.IsTrue(Gpu.Default is not null);
Assert.IsTrue(GraphicsDevice.Default is not null);
}
[CombinatorialTestMethod]
@@ -31,11 +31,11 @@ public partial class InitializationTests
[TestMethod]
public void DisposeDefault()
{
using var before = Gpu.Default.AllocateReadOnlyBuffer<float>(128);
using var before = GraphicsDevice.Default.AllocateReadOnlyBuffer<float>(128);
Gpu.Default.Dispose();
GraphicsDevice.Default.Dispose();
using var after = Gpu.Default.AllocateReadOnlyBuffer<float>(128);
using var after = GraphicsDevice.Default.AllocateReadOnlyBuffer<float>(128);
}
[TestMethod]
@@ -43,9 +43,9 @@ public partial class InitializationTests
{
int i = 0;
foreach (GraphicsDevice device in Gpu.EnumerateDevices())
foreach (GraphicsDevice device in GraphicsDevice.EnumerateDevices())
{
if (i++ == 0) Assert.AreSame(Gpu.Default, device);
if (i++ == 0) Assert.AreSame(GraphicsDevice.Default, device);
using ReadWriteBuffer<int> buffer = device.AllocateReadWriteBuffer<int>(128);
@@ -62,9 +62,9 @@ public partial class InitializationTests
{
int i = 0;
foreach (GraphicsDevice device in Gpu.QueryDevices(info => info.DedicatedMemorySize >= 1024))
foreach (GraphicsDevice device in GraphicsDevice.QueryDevices(info => info.DedicatedMemorySize >= 1024))
{
if (i++ == 0) Assert.AreSame(Gpu.Default, device);
if (i++ == 0) Assert.AreSame(GraphicsDevice.Default, device);
using ReadWriteBuffer<int> buffer = device.AllocateReadWriteBuffer<int>(128);
+2 -2
ファイルの表示
@@ -94,8 +94,8 @@ public partial class Texture2DTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};
+2 -2
ファイルの表示
@@ -113,8 +113,8 @@ public partial class Texture3DTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};
+2 -2
ファイルの表示
@@ -74,8 +74,8 @@ public partial class TransferBufferTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};
+2 -2
ファイルの表示
@@ -78,8 +78,8 @@ public partial class TransferTexture2DTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};
+2 -2
ファイルの表示
@@ -85,8 +85,8 @@ public partial class TransferTexture3DTests
{
GraphicsDevice? gpu = device switch
{
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
_ => throw new ArgumentException(nameof(device))
};