From 1b96657db7d8b61cec20ea79592976016e9adfca Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 24 Nov 2023 12:56:52 +0100 Subject: [PATCH] Add README files for all NuGet packages --- src/ComputeSharp.Core/README.md | 9 ++++ src/ComputeSharp.D2D1.WinUI/README.md | 9 ++++ src/ComputeSharp.D2D1/README.md | 39 ++++++++++++++ .../README.md | 19 +++++++ src/ComputeSharp.Dxc/README.md | 24 +++++++++ src/ComputeSharp.Pix/README.md | 9 ++++ src/ComputeSharp.WinUI/README.md | 9 ++++ src/ComputeSharp/README.md | 52 +++++++++++++++++++ src/Directory.Build.props | 7 +++ 9 files changed, 177 insertions(+) create mode 100644 src/ComputeSharp.Core/README.md create mode 100644 src/ComputeSharp.D2D1.WinUI/README.md create mode 100644 src/ComputeSharp.D2D1/README.md create mode 100644 src/ComputeSharp.D3D12MemoryAllocator/README.md create mode 100644 src/ComputeSharp.Dxc/README.md create mode 100644 src/ComputeSharp.Pix/README.md create mode 100644 src/ComputeSharp.WinUI/README.md create mode 100644 src/ComputeSharp/README.md diff --git a/src/ComputeSharp.Core/README.md b/src/ComputeSharp.Core/README.md new file mode 100644 index 00000000..9c5f786d --- /dev/null +++ b/src/ComputeSharp.Core/README.md @@ -0,0 +1,9 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.Core** package containing basic primitives to support all dependent **ComputeSharp** packages, as well as some shared internal infrastructure. This package is a transitive dependency of all other **ComputeSharp** packages, and is not supposed to be referenced directly by developers. Refer to the documentation of the other packages to learn more about all the functionality that is available when using them. + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.WinUI/README.md b/src/ComputeSharp.D2D1.WinUI/README.md new file mode 100644 index 00000000..cc8eabac --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/README.md @@ -0,0 +1,9 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.D2D1.WinUI** is a WinUI 3 library with APIs to leverage D2D1 functionality with D2D1 pixel shaders powered by **ComputeSharp.D2D1**. You can refer to the [Win2D docs on custom effects](https://learn.microsoft.com/en-us/windows/apps/develop/win2d/custom-effects) to learn more about how to implement custom effects using the APIs provided by this package. + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/README.md b/src/ComputeSharp.D2D1/README.md new file mode 100644 index 00000000..56c7c9a7 --- /dev/null +++ b/src/ComputeSharp.D2D1/README.md @@ -0,0 +1,39 @@ +![](https://user-images.githubusercontent.com/10199417/ + +# Overview 📖 + +**ComputeSharp.D2D1** is a library to write D2D1 pixel shaders entirely with C# code, and to easily register and create `ID2D1Effect`-s from them. This shares the same base APIs (primitives, intrinsics, etc.) as **ComputeSharp**, but then adds D2D1 specific support, instead of using DX12 compute shaders like the main package. This means it offers the ability to implement D2D1 pixel shaders, and to then either load them manually, or to register a D2D1 effect using them, optionally with a custom draw transform as well. + +# Quick start 🚀 + +Here's a simple D2D1 pixel shader written using **ComputeSharp.D2D1**: + +```csharp +[D2DInputCount(1)] +[D2DInputSimple(0)] +[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] +[D2DGeneratedPixelShaderDescriptor] +public readonly partial struct DifferenceEffect(float amount) : ID2D1PixelShader +{ + /// + public float4 Execute() + { + float4 color = D2D.GetInput(0); + float3 rgb = Hlsl.Saturate(this.amount - color.RGB); + + return new(rgb, 1); + } +} +``` + +This can then be used directly to get the shader bytecode and the buffer, like so: + +```csharp +ReadOnlyMemory bytecode = D2D1PixelShader.LoadBytecode(); +ReadOnlyMemory buffer = D2D1PixelShader.GetConstantBuffer(new DifferenceEffect(1)); +``` + +There are also several other APIs to easily register a pixel shader effect from a shader written using **ComputeSharp.D2D1**, and to then create an `ID2D1Effect` instance from it (from the `D2D1PixelShaderEffect` type), as well as for reflecting into a shader and extract information about it, such as its HLSL source code (from the `D2D1ReflectionServices` type). + +# There's more! +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.D3D12MemoryAllocator/README.md b/src/ComputeSharp.D3D12MemoryAllocator/README.md new file mode 100644 index 00000000..84702e9b --- /dev/null +++ b/src/ComputeSharp.D3D12MemoryAllocator/README.md @@ -0,0 +1,19 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.D3D12MemoryAllocator** is an extension library for **ComputeSharp** to enable using [D3D12MA](https://gpuopen.com/d3d12-memory-allocator/) as the memory allocator for graphics resources. + +# Quick start 🚀 + +You can configure the D3D12MA allocator by using the `AllocationServices` type at startup: + +```csharp +AllocationServices.ConfigureAllocatorFactory(new D3D12MemoryAllocatorFactory()); +``` + +This will make **ComputeSharp** leverage D3D12MA for all subsequent resource allocations. + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.Dxc/README.md b/src/ComputeSharp.Dxc/README.md new file mode 100644 index 00000000..f0f5da7b --- /dev/null +++ b/src/ComputeSharp.Dxc/README.md @@ -0,0 +1,24 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.Dxc** is an extension library for **ComputeSharp** bundling the DXC compiler and enabling shader reflection. + +For users that are familiar with the HLSL language and might want to access more info on a given shader generated by ComputeSharp, such as the compiled HLSL code or the statistics exposed by the DirectX 12 reflection APIs, the library includes a ReflectionServices class that allows to easily gather all these details on a given shader type. + +# Quick start 🚀 + +Assuming we have a `MyShader` type defined, here's how you can use **ComputeSharp.Dxc** to inspect it: + +```csharp +ShaderInfo shaderInfo = ReflectionServices.GetShaderInfo(); + +// Access info here, for instance... +string hlslSource = shaderInfo.HlslSource; +uint numberOfResources = shaderInfo.BoundResourceCount; +uint instructionCount = shaderInfo.InstructionCount; +``` + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.Pix/README.md b/src/ComputeSharp.Pix/README.md new file mode 100644 index 00000000..d39d0d7d --- /dev/null +++ b/src/ComputeSharp.Pix/README.md @@ -0,0 +1,9 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.Pix** is an extension library for **ComputeSharp** to enable [PIX](https://devblogs.microsoft.com/pix/introduction/]) support to produce debugging information. + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp.WinUI/README.md b/src/ComputeSharp.WinUI/README.md new file mode 100644 index 00000000..fefb02b3 --- /dev/null +++ b/src/ComputeSharp.WinUI/README.md @@ -0,0 +1,9 @@ +![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) + +# Overview 📖 + +**ComputeSharp.WinUI** is a WinUI 3 library with controls to render DX12 shaders powered by **ComputeSharp**. + +# There's more! + +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/ComputeSharp/README.md b/src/ComputeSharp/README.md new file mode 100644 index 00000000..c45131b9 --- /dev/null +++ b/src/ComputeSharp/README.md @@ -0,0 +1,52 @@ +![](https://user-images.githubusercontent.com/10199417/ + +# Overview 📖 + +**ComputeSharp** is a library to write DX12 compute shaders entirely with C# code. The available APIs let you access GPU devices, allocate GPU buffers and textures, move data between them and the RAM, write compute shaders entirely in C# and have them run on the GPU. The goal of this project is to make GPU computing easy to use for all .NET developers! + +# Quick start 🚀 + +**ComputeSharp** exposes a `GraphicsDevice` class that acts as entry point for all public APIs. The available `GraphicsDevice.GetDefault()` method 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: + +```csharp +// Get some sample data +int[] array = [.. Enumerable.Range(1, 100)]; + +// 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 = GraphicsDevice.GetDefault().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. + +Next, we need to define the GPU shader to run. To do this, we'll need to define a `partial struct` type implementing the `IComputeShader` interface (note that the `partial` modifier is necessary for **ComputeSharp** to generate additional code to run the shader). This type will contain the code we want to run on the GPU, as well as fields representing the values we want to capture and pass to the GPU (such as GPU resources, or arbitrary values we need). Next, we need to add the `[ThreadGroupSize]` attribute to configure the dispatching configuration for the shader. This shader only operates on a 1D buffer, so we can use `DefaultThreadGroupSizes.X` for this. Lastly, we also need to add the `[GeneratedComputeShaderDescriptor]` attribute, to let the source generator bundled with **ComputeSharp** do its magic. In this case, we only need to capture the buffer to work on, so the shader type will look like this: + +```C# +[ThreadGroupSize(DefaultThreadGroupSizes.X)] +[GeneratedComputeShaderDescriptor] +public readonly partial struct MultiplyByTwo(ReadWriteBuffer buffer) : IComputeShader +{ + public void Execute() + { + buffer[ThreadIds.X] *= 2; + } +} +``` + +In this example, we're using a primary constructor (but you can also explicitly declare fields and set them via a constructor). The shader body is also using a special `ThreadIds` class, which is one of the available special classes to access dispatch parameters from within a shader body. In this case, `ThreadIds` lets us access the current invocation index for the shader, just like if we were accessing the classic `i` variable from within a `for` loop. + +We can now finally run the GPU shader and copy the data back to our array: + +```csharp +// Launch the shader +GraphicsDevice.GetDefault().For(buffer.Length, new MultiplyByTwo(buffer)); + +// Get the data back +buffer.CopyTo(array); +``` + +# There's more! +For a complete list of all features available in **ComputeSharp**, check the documentation in the [GitHub repo](https://github.com/Sergio0694/ComputeSharp). \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 435885da..b6ffa987 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -51,6 +51,10 @@ false true + + false + true + false true @@ -66,6 +70,9 @@ + + +