diff --git a/README.md b/README.md index adadbcd6..fe2779a2 100644 --- a/README.md +++ b/README.md @@ -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 buffer = Gpu.Default.AllocateReadWriteBuffer(array); +using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array); ``` The `AllocateReadWriteBuffer` extension takes care of creating a `ReadWriteBuffer` 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("myImage.jpg"); +using var texture = GraphicsDevice.Default.LoadReadWriteTexture2D("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(1280, 720); +using var texture = GraphicsDevice.Default.AllocateReadWriteTexture2D(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` instance and use that to co float[] array = LoadSampleData(); // Allocate the buffer and copy data to it -using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(array); +using ReadWriteBuffer 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 d3D12Device = default; using ComPtr d3D12Resource = default; -using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(128); +using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(128); // Get the underlying ID3D12Device object -InteropServices.GetID3D12Device(Gpu.Default, __uuidof(), (void**)d3D12Device.GetAddressOf()); +InteropServices.GetID3D12Device(GraphicsDevice.Default, __uuidof(), (void**)d3D12Device.GetAddressOf()); // Get the underlying ID3D12Resource object InteropServices.GetID3D12Resource(buffer, __uuidof(), (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 diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs index f58bdece..0dd6f5a4 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs @@ -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!); } /// @@ -149,12 +149,12 @@ public class BlasBenchmark : IDisposable [Benchmark] public void GpuWithTemporaryBuffers() { - using ReadOnlyBuffer x = Gpu.Default.AllocateReadOnlyBuffer(X!); - using ReadOnlyBuffer w = Gpu.Default.AllocateReadOnlyBuffer(W!); - using ReadOnlyBuffer b = Gpu.Default.AllocateReadOnlyBuffer(B!); - using ReadWriteBuffer y = Gpu.Default.AllocateReadWriteBuffer(Y!.Length); + using ReadOnlyBuffer x = GraphicsDevice.Default.AllocateReadOnlyBuffer(X!); + using ReadOnlyBuffer w = GraphicsDevice.Default.AllocateReadOnlyBuffer(W!); + using ReadOnlyBuffer b = GraphicsDevice.Default.AllocateReadOnlyBuffer(B!); + using ReadWriteBuffer y = GraphicsDevice.Default.AllocateReadWriteBuffer(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); } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs index 75c601bd..fa3f8d67 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs @@ -26,7 +26,7 @@ public sealed partial class HlslBokehBlurProcessor : IImageProcessor /// Initializes a new instance of the class. /// public HlslBokehBlurProcessor() - : this(Gpu.Default, DefaultRadius, DefaultComponents) + : this(GraphicsDevice.Default, DefaultRadius, DefaultComponents) { } @@ -36,7 +36,7 @@ public sealed partial class HlslBokehBlurProcessor : IImageProcessor /// The size of the area to sample. /// The number of components to use to approximate the original 2D bokeh blur convolution kernel. public HlslBokehBlurProcessor(int radius, int components) - : this(Gpu.Default, radius, components) + : this(GraphicsDevice.Default, radius, components) { } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs index 545c3e48..0dd0481e 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs @@ -21,7 +21,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor /// Initializes a new instance of the class. /// public HlslGaussianBlurProcessor() - : this(Gpu.Default, DefaultSigma, 9) + : this(GraphicsDevice.Default, DefaultSigma, 9) { } @@ -30,7 +30,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor /// /// The radius value representing the size of the area to sample. public HlslGaussianBlurProcessor(int radius) - : this(Gpu.Default, radius / 3F, radius) + : this(GraphicsDevice.Default, radius / 3F, radius) { } diff --git a/samples/ComputeSharp.Sample.FSharp/Program.fs b/samples/ComputeSharp.Sample.FSharp/Program.fs index 397d0079..8782690a 100644 --- a/samples/ComputeSharp.Sample.FSharp/Program.fs +++ b/samples/ComputeSharp.Sample.FSharp/Program.fs @@ -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" diff --git a/samples/ComputeSharp.Sample.Shared/Program.cs b/samples/ComputeSharp.Sample.Shared/Program.cs index c1dfd234..d52553d1 100644 --- a/samples/ComputeSharp.Sample.Shared/Program.cs +++ b/samples/ComputeSharp.Sample.Shared/Program.cs @@ -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 gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array); + using ReadWriteBuffer 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"); diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/ContouredLayersRunner.cs index 6e91c5e5..a3d18eb4 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/ContouredLayersRunner.cs @@ -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(filename); + this.texture = GraphicsDevice.Default.LoadReadOnlyTexture2D(filename); } - Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture)); + GraphicsDevice.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture)); } } diff --git a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs index df208d46..18077d7f 100644 --- a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs +++ b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs @@ -90,7 +90,7 @@ internal sealed class SwapChainApplication : Win32Application // Get the underlying ID3D12Device in use fixed (ID3D12Device** d3D12Device = this.d3D12Device) { - _ = InteropServices.TryGetID3D12Device(Gpu.Default, Windows.__uuidof(), (void**)d3D12Device); + _ = InteropServices.TryGetID3D12Device(GraphicsDevice.Default, Windows.__uuidof(), (void**)d3D12Device); } // Create the direct command queue to use @@ -217,7 +217,7 @@ internal sealed class SwapChainApplication : 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( + this.texture = GraphicsDevice.Default.AllocateReadWriteTexture2D( (int)d3D12Resource0Description.Width, (int)d3D12Resource0Description.Height); } @@ -233,7 +233,7 @@ internal sealed class SwapChainApplication : Win32Application } // Generate the new frame - Gpu.Default.ForEach(this.texture!, this.shaderFactory(time)); + GraphicsDevice.Default.ForEach(this.texture!, this.shaderFactory(time)); using ComPtr d3D12Resource = default; diff --git a/samples/ComputeSharp.SwapChain/Program.cs b/samples/ComputeSharp.SwapChain/Program.cs index a9240019..d479b5c4 100644 --- a/samples/ComputeSharp.SwapChain/Program.cs +++ b/samples/ComputeSharp.SwapChain/Program.cs @@ -79,6 +79,6 @@ class Program { string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png"); - return Gpu.Default.LoadReadOnlyTexture2D(filename); + return GraphicsDevice.Default.LoadReadOnlyTexture2D(filename); } } diff --git a/src/ComputeSharp.UI/Controls/ComputeShaderPanel.Rendering.cs b/src/ComputeSharp.UI/Controls/ComputeShaderPanel.Rendering.cs index 0e4903ee..855c3223 100644 --- a/src/ComputeSharp.UI/Controls/ComputeShaderPanel.Rendering.cs +++ b/src/ComputeSharp.UI/Controls/ComputeShaderPanel.Rendering.cs @@ -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(), (void**)d3D12Device).Assert(); + InteropServices.TryGetID3D12Device(GraphicsDevice.Default, Win32.__uuidof(), (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( + this.texture = GraphicsDevice.Default.AllocateReadWriteTexture2D( (int)d3D12Resource0Description.Width, (int)d3D12Resource0Description.Height); } diff --git a/src/ComputeSharp.UI/ShaderRunner{T}.cs b/src/ComputeSharp.UI/ShaderRunner{T}.cs index be100516..370089d6 100644 --- a/src/ComputeSharp.UI/ShaderRunner{T}.cs +++ b/src/ComputeSharp.UI/ShaderRunner{T}.cs @@ -40,6 +40,6 @@ public sealed class ShaderRunner : IShaderRunner /// public void Execute(IReadWriteTexture2D texture, TimeSpan time) { - Gpu.Default.ForEach(texture, this.shaderFactory(time)); + GraphicsDevice.Default.ForEach(texture, this.shaderFactory(time)); } } diff --git a/src/ComputeSharp/Gpu.cs b/src/ComputeSharp/Graphics/GraphicsDevice.GetDevice.cs similarity index 93% rename from src/ComputeSharp/Gpu.cs rename to src/ComputeSharp/Graphics/GraphicsDevice.GetDevice.cs index 8efab27a..5dc34820 100644 --- a/src/ComputeSharp/Gpu.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.GetDevice.cs @@ -5,10 +5,8 @@ using ComputeSharp.Graphics.Helpers; namespace ComputeSharp; -/// -/// A that acts as an entry-point for all the library APIs, exposing the available GPU devices. -/// -public static class Gpu +/// +partial class GraphicsDevice { /// /// Gets the default instance for the current machine. diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index dfd55438..2a5dfb71 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -22,7 +22,7 @@ namespace ComputeSharp; /// A that represents an instance that can be used to run compute shaders. /// [DebuggerDisplay("{ToString(),raw}")] -public sealed unsafe class GraphicsDevice : NativeObject +public sealed unsafe partial class GraphicsDevice : NativeObject { /// /// The underlying wrapped by the current instance. diff --git a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs index 0152e806..6b6274fd 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs @@ -23,11 +23,11 @@ public partial class ShaderDataLoaderTests [TestMethod] public unsafe void CapturedResource() { - using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(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 buffer0 = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer buffer1 = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer0 = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer1 = GraphicsDevice.Default.AllocateReadWriteBuffer(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 buffer = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(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 buffer = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(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 buffer = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(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 buffer = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(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 a = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer b = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer c = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer x = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer y = Gpu.Default.AllocateReadWriteBuffer(16); - using ReadWriteBuffer z = Gpu.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer a = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer b = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer c = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer x = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer y = GraphicsDevice.Default.AllocateReadWriteBuffer(16); + using ReadWriteBuffer z = GraphicsDevice.Default.AllocateReadWriteBuffer(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); diff --git a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs index b78385cf..f90251a9 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs @@ -25,7 +25,7 @@ public partial class ShaderHashCodeTests public void ShaderWithNoCapturedDelegates() { float value = 10; - using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(1); Shader1 shader1 = new() { A = value, B = buffer }; @@ -58,7 +58,7 @@ public partial class ShaderHashCodeTests { Func f = static x => x * x; - using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + using ReadWriteBuffer buffer = GraphicsDevice.Default.AllocateReadWriteBuffer(1); Shader2 shader1 = new() { A = 1, B = buffer, F = f }; diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index 7860f8e9..d857dcdf 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -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)) }; diff --git a/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs b/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs index 500b6a80..011d306c 100644 --- a/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs +++ b/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs @@ -5,7 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ComputeSharp.Tests.Extensions; /// -/// A helper class for testing APIs. +/// A helper class for testing APIs. /// 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("Invalid device") }; diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs index 2ed05bdb..fa703600 100644 --- a/tests/ComputeSharp.Tests/InitializationTests.cs +++ b/tests/ComputeSharp.Tests/InitializationTests.cs @@ -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(128); + using var before = GraphicsDevice.Default.AllocateReadOnlyBuffer(128); - Gpu.Default.Dispose(); + GraphicsDevice.Default.Dispose(); - using var after = Gpu.Default.AllocateReadOnlyBuffer(128); + using var after = GraphicsDevice.Default.AllocateReadOnlyBuffer(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 buffer = device.AllocateReadWriteBuffer(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 buffer = device.AllocateReadWriteBuffer(128); diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 728369b9..bae22587 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -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)) }; diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index b360e3c8..07094ef1 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -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)) }; diff --git a/tests/ComputeSharp.Tests/TransferBufferTests.cs b/tests/ComputeSharp.Tests/TransferBufferTests.cs index 1a933637..ee8620ad 100644 --- a/tests/ComputeSharp.Tests/TransferBufferTests.cs +++ b/tests/ComputeSharp.Tests/TransferBufferTests.cs @@ -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)) }; diff --git a/tests/ComputeSharp.Tests/TransferTexture2DTests.cs b/tests/ComputeSharp.Tests/TransferTexture2DTests.cs index 4ab2b901..8650edf0 100644 --- a/tests/ComputeSharp.Tests/TransferTexture2DTests.cs +++ b/tests/ComputeSharp.Tests/TransferTexture2DTests.cs @@ -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)) }; diff --git a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs index 2999795f..ac4b2211 100644 --- a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs +++ b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs @@ -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)) };