diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 9bc7c664..7572930d 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -88,6 +88,7 @@ public sealed partial class HlslBokehBlurProcessor // Initialize the complex kernels and parameters with the current arguments (KernelParameters, KernelsScale) = GetParameters(); Kernels = CreateComplexKernels(); + NormalizeKernels(); // Store them in the cache for future use @@ -161,6 +162,7 @@ public sealed partial class HlslBokehBlurProcessor { // Prepare the kernel components int index = Math.Max(0, Math.Min(ComponentsCount - 1, KernelComponents.Count)); + return (KernelComponents[index], KernelScales[index]); } @@ -171,9 +173,11 @@ public sealed partial class HlslBokehBlurProcessor { var kernels = new Complex64[KernelParameters.Length][]; ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan()); + for (int i = 0; i < KernelParameters.Length; i++) { ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i); + kernels[i] = CreateComplex1DKernel(paramsRef.X, paramsRef.Y); } @@ -189,12 +193,14 @@ public sealed partial class HlslBokehBlurProcessor { var kernel = new Complex64[KernelSize]; ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan()); - int r = Radius, n = -r; + int r = Radius; + int n = -r; for (int i = 0; i < KernelSize; i++, n++) { // Incrementally compute the range values float value = n * KernelsScale * (1f / r); + value *= value; // Fill in the complex kernel values @@ -230,6 +236,7 @@ public sealed partial class HlslBokehBlurProcessor { ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j); ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k); + total += paramsRef.Z * (jRef.Real * kRef.Real - jRef.Imaginary * kRef.Imaginary) + paramsRef.W * (jRef.Real * kRef.Imaginary + jRef.Imaginary * kRef.Real); @@ -239,6 +246,7 @@ public sealed partial class HlslBokehBlurProcessor // Normalize the kernels float scalar = 1f / MathF.Sqrt(total); + for (int i = 0; i < kernelsSpan.Length; i++) { ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i); diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 72cac2fe..c72c0d38 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -75,9 +75,8 @@ internal unsafe static class Win32ApplicationRunner // Set the target window size _ = Windows.AdjustWindowRect((RECT*)&windowRect, Windows.WS_OVERLAPPEDWINDOW, Windows.FALSE); - uint - height = (uint)(windowRect.Bottom - windowRect.Top), - width = (uint)(windowRect.Right - windowRect.Left); + uint height = (uint)(windowRect.Bottom - windowRect.Top); + uint width = (uint)(windowRect.Right - windowRect.Left); // Create the window and store a handle to it hwnd = Windows.CreateWindowExW( @@ -117,9 +116,8 @@ internal unsafe static class Win32ApplicationRunner { (Win32Application application, CancellationToken token) = ((Win32Application, CancellationToken))args!; - Stopwatch - startStopwatch = Stopwatch.StartNew(), - frameStopwatch = Stopwatch.StartNew(); + Stopwatch startStopwatch = Stopwatch.StartNew(); + Stopwatch frameStopwatch = Stopwatch.StartNew(); const long targetFrameTimeInTicksFor60fps = 166666; @@ -251,11 +249,10 @@ internal unsafe static class Win32ApplicationRunner _ = Windows.GetCursorPos(&point); _ = Windows.GetWindowRect(hwnd, &rect); - bool - isAtTop = Math.Abs(point.y - rect.top) < 12, - isAtRight = Math.Abs(point.x - rect.right) < 12, - isAtBottom = Math.Abs(point.y - rect.bottom) < 12, - isAtLeft = Math.Abs(point.x - rect.left) < 12; + bool isAtTop = Math.Abs(point.y - rect.top) < 12; + bool isAtRight = Math.Abs(point.x - rect.right) < 12; + bool isAtBottom = Math.Abs(point.y - rect.bottom) < 12; + bool isAtLeft = Math.Abs(point.x - rect.left) < 12; if (isAtTop) { diff --git a/samples/ComputeSharp.SwapChain/Shaders/ExtrudedTruchetPattern.cs b/samples/ComputeSharp.SwapChain/Shaders/ExtrudedTruchetPattern.cs index 3956f1c9..d6122bb3 100644 --- a/samples/ComputeSharp.SwapChain/Shaders/ExtrudedTruchetPattern.cs +++ b/samples/ComputeSharp.SwapChain/Shaders/ExtrudedTruchetPattern.cs @@ -26,7 +26,8 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -148,12 +149,14 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader // Anyway, I like this one. I'm assuHlsl.Ming it's based on IQ's original. private float CalculateAO(in float3 p, in float3 n) { - float sca = 2.0f, occ = 0.0f; + float sca = 2.0f; + float occ = 0.0f; for (int i = (int)Hlsl.Min(time, 0f); i < 5; i++) { float hr = (i + 1f) * 0.15f / 5.0f; float d = M(p + n * hr); + occ += (hr - d) * sca; sca *= 0.7f; @@ -179,16 +182,17 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader { int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y); float2 u = (coords - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y; - float3 - r = Hlsl.Normalize(new float3(u, 1)), - o = new(0, time / 2.0f, -3), - l = o + new float3(0.25f, 0.25f, 2.0f); + float3 r = Hlsl.Normalize(new float3(u, 1)); + float3 o = new(0, time / 2.0f, -3); + float3 l = o + new float3(0.25f, 0.25f, 2.0f); r.YZ = Hlsl.Mul(Rotate2x2(0.15f), r.YZ); r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(time * 3.14159f / 32.0f) / 8.0f), r.XZ); r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(time * 3.14159f / 32.0f) / 8.0f), r.XY); - float d, t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f, glow = 0; + float d; + float t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f; + float glow = 0; for (int i = 0; i < 96; i++) { @@ -201,7 +205,8 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader } int gObjID = objID; - float3 p = o + r * t, n = Normal(p); + float3 p = o + r * t; + float3 n = Normal(p); float2 uv = p.XY; float sc = 0.5f; float2 iuv = Hlsl.Floor(uv / sc) + 0.5f; diff --git a/samples/ComputeSharp.SwapChain/Shaders/Octagrams.cs b/samples/ComputeSharp.SwapChain/Shaders/Octagrams.cs index eee31181..ac9cb3a5 100644 --- a/samples/ComputeSharp.SwapChain/Shaders/Octagrams.cs +++ b/samples/ComputeSharp.SwapChain/Shaders/Octagrams.cs @@ -15,7 +15,8 @@ internal readonly partial struct Octagrams : IPixelShader private static float2x2 Rotate(float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, s, -s, c); } diff --git a/samples/ComputeSharp.SwapChain/Shaders/ProteanClouds.cs b/samples/ComputeSharp.SwapChain/Shaders/ProteanClouds.cs index 895d27ea..16d4e015 100644 --- a/samples/ComputeSharp.SwapChain/Shaders/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain/Shaders/ProteanClouds.cs @@ -18,7 +18,8 @@ internal readonly partial struct ProteanClouds : IPixelShader private static float2x2 Rotate(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, s, -s, c); } diff --git a/samples/ComputeSharp.SwapChain/Shaders/PyramidPattern.cs b/samples/ComputeSharp.SwapChain/Shaders/PyramidPattern.cs index 51797672..d1925bff 100644 --- a/samples/ComputeSharp.SwapChain/Shaders/PyramidPattern.cs +++ b/samples/ComputeSharp.SwapChain/Shaders/PyramidPattern.cs @@ -17,7 +17,8 @@ internal readonly partial struct PyramidPattern : IPixelShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -141,9 +142,8 @@ internal readonly partial struct PyramidPattern : IPixelShader float2 oP = p; float m = BMap(p); float3 n = new(0, 0, -1); - float - edge = 0.0f, - bumpFactor = 0.25f; + float edge = 0.0f; + float bumpFactor = 0.25f; n = DoBumpMap(p, n, bumpFactor, ref edge); diff --git a/samples/ComputeSharp.SwapChain/Shaders/TriangleGridContouring.cs b/samples/ComputeSharp.SwapChain/Shaders/TriangleGridContouring.cs index 89a50c34..2303cb5e 100644 --- a/samples/ComputeSharp.SwapChain/Shaders/TriangleGridContouring.cs +++ b/samples/ComputeSharp.SwapChain/Shaders/TriangleGridContouring.cs @@ -16,7 +16,8 @@ internal readonly partial struct TriangleGridContouring : IPixelShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -157,12 +158,11 @@ internal readonly partial struct TriangleGridContouring : IPixelShader p -= s - (s.X + s.Y) * 0.211324865f; float i = p.X < p.Y ? 1.0f : 0.0f; - float2 - ioffs = new(1.0f - i, i), - ip0 = 0, - ip1 = ioffs - 0.2113248654f, - ip2 = 0.577350269f, - ctr = (ip0 + ip1 + ip2) / 3.0f; + float2 ioffs = new(1.0f - i, i); + float2 ip0 = 0; + float2 ip1 = ioffs - 0.2113248654f; + float2 ip2 = 0.577350269f; + float2 ctr = (ip0 + ip1 + ip2) / 3.0f; ip0 -= ctr; ip1 -= ctr; @@ -175,15 +175,14 @@ internal readonly partial struct TriangleGridContouring : IPixelShader n3.Y = IsoFunction(s + ioffs); n3.Z = IsoFunction(s + 1.0f); - float - d = 1e5f, - d2 = 1e5f, - d3 = 1e5f, - d4 = 1e5f, - d5 = 1e5f; - + float d = 1e5f; + float d2 = 1e5f; + float d3 = 1e5f; + float d4 = 1e5f; + float d5 = 1e5f; float isovalue = 0; - float2 p0 = default, p1 = default; + float2 p0 = default; + float2 p1 = default; int iTh = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1); d = Hlsl.Min(d, distEdge(p - p0, p - p1)); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs index b4cc7f6f..66b7a382 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs @@ -679,10 +679,9 @@ public sealed partial class IShaderGenerator AppendCharacterAndLF('}'); - int - constantBuffersCount = 1, - readOnlyBuffersCount = 0, - readWriteBuffersCount = 0; + int constantBuffersCount = 1; + int readOnlyBuffersCount = 0; + int readWriteBuffersCount = 0; // Optional implicit texture field if (!isComputeShader) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs index e8751e13..a6288e93 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -67,9 +67,8 @@ public sealed partial class IShaderGenerator var pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader) }); var isComputeShader = pixelShaderSymbol is null; - int - resourceOffset = 0, - rawDataOffset = sizeof(int) * (isComputeShader ? 3 : 2); + int resourceOffset = 0; + int rawDataOffset = sizeof(int) * (isComputeShader ? 3 : 2); // Append the statements for the dispatch ranges: // @@ -232,9 +231,8 @@ public sealed partial class IShaderGenerator !fieldSymbol.IsConst && !fieldSymbol.IsStatic && !fieldSymbol.IsFixedSizeBuffer select fieldSymbol) { - string - fieldName = fieldSymbol.Name, - typeName = fieldSymbol.Type.GetFullMetadataName(); + string fieldName = fieldSymbol.Name; + string typeName = fieldSymbol.Type.GetFullMetadataName(); // Disambiguates the name of target fields against the current input parameters if (fieldName is "loader" or "device" or "x" or "y" or "z") @@ -290,9 +288,8 @@ public sealed partial class IShaderGenerator // each row needs to be at a multiple of 16 bytes (a float4 register). if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns)) { - string - rowTypeName = $"global::ComputeSharp.{elementName}{columns}", - rowLocalName = $"__{string.Join("_", fieldPath)}__row0"; + string rowTypeName = $"global::ComputeSharp.{elementName}{columns}"; + string rowLocalName = $"__{string.Join("_", fieldPath)}__row0"; statements.Add(ParseStatement($"ref {rowTypeName} {rowLocalName} = ref global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in {string.Join(".", fieldPath)}));")); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs index fc8c779e..391416d0 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs @@ -122,11 +122,10 @@ public sealed partial class IShaderGenerator yield return ParseStatement($"global::System.Runtime.CompilerServices.Unsafe.WriteUnaligned(ref global::System.Runtime.CompilerServices.Unsafe.Add(ref r0, 0), {root32BitConstantsCount});"); yield return ParseStatement($"global::System.Runtime.CompilerServices.Unsafe.WriteUnaligned(ref global::System.Runtime.CompilerServices.Unsafe.Add(ref r0, 4), {isSamplerUsed.ToString().ToLowerInvariant()});"); - int - constantBufferOffset = 1, - readOnlyResourceOffset = 0, - readWriteResourceOffset = 0, - resourceOffset = 0; + int constantBufferOffset = 1; + int readOnlyResourceOffset = 0; + int readWriteResourceOffset = 0; + int resourceOffset = 0; // Add the implicit texture descriptor, if needed if (implicitTextureType is not null) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index a86963e6..29b01464 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -56,11 +56,10 @@ public sealed partial class IShaderGenerator : ISourceGenerator private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol) { // Create the required interface methods for the current shader type - MethodDeclarationSyntax - getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol), - loadDispatchDataMethod = CreateLoadDispatchDataMethod(context, structDeclarationSymbol, out var discoveredResources, out int root32BitConstants), - buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed), - loadDispatchMetadataMethod = CreateLoadDispatchMetadataMethod(implicitTextureType, discoveredResources, root32BitConstants, isSamplerUsed); + MethodDeclarationSyntax getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol); + MethodDeclarationSyntax loadDispatchDataMethod = CreateLoadDispatchDataMethod(context, structDeclarationSymbol, out var discoveredResources, out int root32BitConstants); + MethodDeclarationSyntax buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed); + MethodDeclarationSyntax loadDispatchMetadataMethod = CreateLoadDispatchMetadataMethod(implicitTextureType, discoveredResources, root32BitConstants, isSamplerUsed); // Reorder the method declarations to respect the order in the interface definition MethodDeclarationSyntax[] methods = diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs index 796a0f20..904ef8e1 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs @@ -214,9 +214,8 @@ internal static class HlslKnownMembers where Regex.IsMatch(property.Name, "^M[1-4]{2}$") select (Type: type, Property: property)) { - char - row = (char)(item.Property.Name[1] - 1), - column = (char)(item.Property.Name[2] - 1); + char row = (char)(item.Property.Name[1] - 1); + char column = (char)(item.Property.Name[2] - 1); knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"_m{row}{column}"); } @@ -254,18 +253,16 @@ internal static class HlslKnownMembers break; case string name when name.Length == 2: { - string - numerator = $"float2({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])})", - denominator = $"float2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})"; + string numerator = $"float2({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])})"; + string denominator = $"float2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})"; knownMembers.Add(key, $"{numerator} / {denominator}"); break; } case string name when name.Length == 3: { - string - numerator = $"float3({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])}, {typeof(ThreadIds).Name}.{char.ToLower(name[2])})", - denominator = $"float3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})"; + string numerator = $"float3({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])}, {typeof(ThreadIds).Name}.{char.ToLower(name[2])})"; + string denominator = $"float3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})"; knownMembers.Add(key, $"{numerator} / {denominator}"); break; diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 43261dbf..89cd50a3 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -404,9 +404,8 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter if (!this.staticMethods.ContainsKey(method)) { ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Context); - MethodDeclarationSyntax - methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(), - processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia(); + MethodDeclarationSyntax methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(); + MethodDeclarationSyntax processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia(); this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier))); } diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs index 97866a6d..c08dfc4c 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -322,7 +322,8 @@ internal static unsafe class ID3D12DeviceExtensions out ulong totalSizeInBytes) { D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height); - ulong a, b; + ulong a; + ulong b; fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* p = &d3D12PlacedSubresourceFootprint) { @@ -357,7 +358,8 @@ internal static unsafe class ID3D12DeviceExtensions out ulong totalSizeInBytes) { D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth); - ulong a, b; + ulong a; + ulong b; fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* p = &d3D12PlacedSubresourceFootprint) { diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs index ad1378ae..0027ade5 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs @@ -40,9 +40,8 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions ushort depth) { D3D12_RESOURCE_DESC d3D12ResourceDescriptionSource = d3D12ResourceSource->GetDesc(); - D3D12_TEXTURE_COPY_LOCATION - d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, in *d3D12PlacedSubresourceFootprintDestination), - d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0); + D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, in *d3D12PlacedSubresourceFootprintDestination); + D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0); D3D12_BOX d3D12Box; D3D12_BOX* pD3D12Box; @@ -99,9 +98,8 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions uint height, ushort depth) { - D3D12_TEXTURE_COPY_LOCATION - d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0), - d3D12TextureCopyLocationSource = new(d3D12ResourceSource, in *d3D12PlacedSubresourceFootprintSource); + D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0); + D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationSource = new(d3D12ResourceSource, in *d3D12PlacedSubresourceFootprintSource); D3D12_BOX d3D12Box; D3D12_BOX* pD3D12Box; diff --git a/src/ComputeSharp/Graphics/Helpers/MemoryHelper.cs b/src/ComputeSharp/Graphics/Helpers/MemoryHelper.cs index ec92d865..71ba72da 100644 --- a/src/ComputeSharp/Graphics/Helpers/MemoryHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/MemoryHelper.cs @@ -187,9 +187,8 @@ internal static class MemoryHelper { for (int z = 0; z < depth; z++) { - ulong - sourceZOffset = (uint)z * widthInBytes * height, - destinationZOffset = (uint)z * sliceInBytes; + ulong sourceZOffset = (uint)z * widthInBytes * height; + ulong destinationZOffset = (uint)z * sliceInBytes; for (int i = 0; i < height; i++) { @@ -231,9 +230,8 @@ internal static class MemoryHelper { for (int z = 0; z < depth; z++) { - ulong - sourceZOffset = (uint)z * sliceInBytes, - destinationZOffset = (uint)z * widthInBytes * height; + ulong sourceZOffset = (uint)z * sliceInBytes; + ulong destinationZOffset = (uint)z * widthInBytes * height; for (int i = 0; i < height; i++) { diff --git a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs index 24700c22..6b321c7c 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs @@ -220,14 +220,14 @@ internal sealed unsafe class WICHelper // Get the first frame of the loaded image (if more are present, they will be ignored) wicBitmapDecoder->GetFrame(0, wicBitmapFrameDecode.GetAddressOf()).Assert(); - uint width, height; + uint width; + uint height; // Extract the image size info wicBitmapFrameDecode.Get()->GetSize(&width, &height).Assert(); - Guid - wicTargetPixelFormatGuid = WICFormatHelper.GetForType(), - wicActualPixelFormatGuid; + Guid wicTargetPixelFormatGuid = WICFormatHelper.GetForType(); + Guid wicActualPixelFormatGuid; // Get the current and target pixel format info wicBitmapFrameDecode.Get()->GetPixelFormat(&wicActualPixelFormatGuid).Assert(); diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 095ed525..902ed07f 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -55,9 +55,8 @@ public abstract class StructuredBuffer : Buffer } else { - nint - byteOffset = (nint)offset * sizeof(T), - byteLength = length * sizeof(T); + nint byteOffset = (nint)offset * sizeof(T); + nint byteLength = length * sizeof(T); using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength); @@ -115,10 +114,9 @@ public abstract class StructuredBuffer : Buffer } else { - ulong - byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T), - byteOffset = (uint)offset * (uint)sizeof(T), - byteLength = (uint)length * (uint)sizeof(T); + ulong byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T); + ulong byteOffset = (uint)offset * (uint)sizeof(T); + ulong byteLength = (uint)length * (uint)sizeof(T); using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); @@ -153,9 +151,8 @@ public abstract class StructuredBuffer : Buffer } else { - nint - byteOffset = (nint)offset * sizeof(T), - byteLength = length * sizeof(T); + nint byteOffset = (nint)offset * sizeof(T); + nint byteLength = length * sizeof(T); using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength); @@ -211,10 +208,9 @@ public abstract class StructuredBuffer : Buffer } else { - ulong - byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T), - byteOffset = (uint)offset * (uint)sizeof(T), - byteLength = (uint)length * (uint)sizeof(T); + ulong byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T); + ulong byteOffset = (uint)offset * (uint)sizeof(T); + ulong byteLength = (uint)length * (uint)sizeof(T); using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index 2511c959..58bb4df9 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -41,15 +41,13 @@ internal static class ShaderRunner // number of registers and any amount of thread local storage. We use the wave size of the device in // use for 1D dispatches, otherwise a multiple of 32 that is greater than or equal to 64, which still // results in an evenly divisible number of waves per thread group on all existing GPU devices. - bool - xIs1 = x == 1, - yIs1 = y == 1, - zIs1 = z == 1; - int - mask = *(byte*)&xIs1 << 2 | *(byte*)&yIs1 << 1 | *(byte*)&zIs1, - threadsX, - threadsY, - threadsZ; + bool xIs1 = x == 1; + bool yIs1 = y == 1; + bool zIs1 = z == 1; + int mask = *(byte*)&xIs1 << 2 | *(byte*)&yIs1 << 1 | *(byte*)&zIs1; + int threadsX; + int threadsY; + int threadsZ; switch (mask - 1) { @@ -116,10 +114,9 @@ internal static class ShaderRunner Guard.IsBetweenOrEqualTo(threadsZ, 1, 64, nameof(threadsZ)); Guard.IsLessThanOrEqualTo(threadsX * threadsY * threadsZ, 1024, "threadsXYZ"); - int - groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1), - groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1), - groupsZ = Math.DivRem(z, threadsZ, out int modZ) + (modZ == 0 ? 0 : 1); + int groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1); + int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); + int groupsZ = Math.DivRem(z, threadsZ, out int modZ) + (modZ == 0 ? 0 : 1); Guard.IsBetweenOrEqualTo(groupsX, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); Guard.IsBetweenOrEqualTo(groupsY, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); @@ -169,13 +166,12 @@ internal static class ShaderRunner { device.ThrowIfDisposed(); - int - x = texture.Width, - y = texture.Height, - threadsX = 8, - threadsY = 8, - groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1), - groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); + int x = texture.Width; + int y = texture.Height; + int threadsX = 8; + int threadsY = 8; + int groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1); + int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); Guard.IsBetweenOrEqualTo(groupsX, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); Guard.IsBetweenOrEqualTo(groupsY, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs index 4872bf31..2314c120 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs +++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs @@ -37,9 +37,8 @@ internal sealed unsafe partial class ShaderCompiler if (isNuGetRuntimeLibrariesDirectoryPresent) { - string - dxcompilerPath = Path.Combine(AppContext.BaseDirectory, $@"runtimes\{rid}\native\dxcompiler.dll"), - dxilPath = Path.Combine(AppContext.BaseDirectory, $@"runtimes\{rid}\native\dxil.dll"); + string dxcompilerPath = Path.Combine(AppContext.BaseDirectory, $@"runtimes\{rid}\native\dxcompiler.dll"); + string dxilPath = Path.Combine(AppContext.BaseDirectory, $@"runtimes\{rid}\native\dxil.dll"); // Load DXIL first so that DXC doesn't fail to load it, and then DXIL, both from the NuGet path if (NativeLibrary.TryLoad(dxilPath, out _) && diff --git a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs index 1fbf26ba..b78385cf 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs @@ -29,9 +29,8 @@ public partial class ShaderHashCodeTests Shader1 shader1 = new() { A = value, B = buffer }; - int - hash1 = ((IShader)shader1).GetDispatchId(), - hash2 = ((IShader)shader1).GetDispatchId(); + int hash1 = ((IShader)shader1).GetDispatchId(); + int hash2 = ((IShader)shader1).GetDispatchId(); Assert.IsTrue(hash1 == hash2); @@ -63,9 +62,8 @@ public partial class ShaderHashCodeTests Shader2 shader1 = new() { A = 1, B = buffer, F = f }; - int - hash1 = ((IShader)shader1).GetDispatchId(), - hash2 = ((IShader)shader1).GetDispatchId(); + int hash1 = ((IShader)shader1).GetDispatchId(); + int hash2 = ((IShader)shader1).GetDispatchId(); Assert.IsTrue(hash1 == hash2); diff --git a/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs index b283571b..ca2cc0af 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs @@ -95,9 +95,8 @@ public class AutoConstructorGeneratorTests string outputBody = outputCompilation.SyntaxTrees.Skip(index + 1).First().ToString(); - string[] - outputLines = outputBody.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), - expectedLines = expectedBody.Replace("\r", "").Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + string[] outputLines = outputBody.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + string[] expectedLines = expectedBody.Replace("\r", "").Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); Assert.AreEqual(expectedLines.Length, outputLines.Length); diff --git a/tests/ComputeSharp.Tests/ImageProcessingTests.cs b/tests/ComputeSharp.Tests/ImageProcessingTests.cs index 0f1e971f..3399defc 100644 --- a/tests/ComputeSharp.Tests/ImageProcessingTests.cs +++ b/tests/ComputeSharp.Tests/ImageProcessingTests.cs @@ -31,9 +31,8 @@ public class ImageProcessingTests using var cpu = original.Clone(c => c.BokehBlur(40, 2, 3)); using var gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 40, 2))); - string - expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg"), - actualPath = Path.Combine(path, "city_bokeh_gpu.jpg"); + string expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg"); + string actualPath = Path.Combine(path, "city_bokeh_gpu.jpg"); cpu.Save(expectedPath); gpu.Save(actualPath); @@ -56,9 +55,8 @@ public class ImageProcessingTests using var cpu = original.Clone(c => c.GaussianBlur(30f)); using var gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90))); - string - expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg"), - actualPath = Path.Combine(path, "city_gaussian_gpu.jpg"); + string expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg"); + string actualPath = Path.Combine(path, "city_gaussian_gpu.jpg"); cpu.Save(expectedPath); gpu.Save(actualPath); diff --git a/tests/ComputeSharp.Tests/ImagingTests.cs b/tests/ComputeSharp.Tests/ImagingTests.cs index 6b68880e..54b2cef1 100644 --- a/tests/ComputeSharp.Tests/ImagingTests.cs +++ b/tests/ComputeSharp.Tests/ImagingTests.cs @@ -96,10 +96,9 @@ public class ImagingTests [AllDevices] public void SaveRgba32AsJpeg(Device device) { - string - path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"), - expectedPath = Path.Combine(path, "city.jpg"), - actualPath = Path.Combine(path, "city_rgba32_saved.jpg"); + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"); + string expectedPath = Path.Combine(path, "city.jpg"); + string actualPath = Path.Combine(path, "city_rgba32_saved.jpg"); using ReadOnlyTexture2D texture = device.Get().LoadReadOnlyTexture2D(expectedPath); @@ -112,10 +111,9 @@ public class ImagingTests [AllDevices] public void SaveBgra32AsJpeg(Device device) { - string - path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"), - expectedPath = Path.Combine(path, "city.jpg"), - actualPath = Path.Combine(path, "city_bgra32_saved.jpg"); + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"); + string expectedPath = Path.Combine(path, "city.jpg"); + string actualPath = Path.Combine(path, "city_bgra32_saved.jpg"); using ReadOnlyTexture2D texture = device.Get().LoadReadOnlyTexture2D(expectedPath); @@ -128,11 +126,10 @@ public class ImagingTests [AllDevices] public void SaveR8AsJpeg(Device device) { - string - path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"), - sourcePath = Path.Combine(path, "city.jpg"), - expectedPath = Path.Combine(path, "city_r8_reference.jpg"), - actualPath = Path.Combine(path, "city_r8_saved.jpg"); + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"); + string sourcePath = Path.Combine(path, "city.jpg"); + string expectedPath = Path.Combine(path, "city_r8_reference.jpg"); + string actualPath = Path.Combine(path, "city_r8_saved.jpg"); using ReadOnlyTexture2D texture = device.Get().LoadReadOnlyTexture2D(sourcePath); diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs index 577be909..9107274e 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs @@ -31,7 +31,8 @@ internal readonly partial struct ExtrudedTruchetPattern : IComputeShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -153,12 +154,14 @@ internal readonly partial struct ExtrudedTruchetPattern : IComputeShader // Anyway, I like this one. I'm assuHlsl.Ming it's based on IQ's original. private float CalculateAO(in float3 p, in float3 n) { - float sca = 2.0f, occ = 0.0f; + float sca = 2.0f; + float occ = 0.0f; for (int i = (int)Hlsl.Min(time, 0f); i < 5; i++) { float hr = (i + 1f) * 0.15f / 5.0f; float d = M(p + n * hr); + occ += (hr - d) * sca; sca *= 0.7f; @@ -184,16 +187,17 @@ internal readonly partial struct ExtrudedTruchetPattern : IComputeShader { int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y); float2 u = (coords - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y; - float3 - r = Hlsl.Normalize(new float3(u, 1)), - o = new(0, time / 2.0f, -3), - l = o + new float3(0.25f, 0.25f, 2.0f); + float3 r = Hlsl.Normalize(new float3(u, 1)); + float3 o = new(0, time / 2.0f, -3); + float3 l = o + new float3(0.25f, 0.25f, 2.0f); r.YZ = Hlsl.Mul(Rotate2x2(0.15f), r.YZ); r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(time * 3.14159f / 32.0f) / 8.0f), r.XZ); r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(time * 3.14159f / 32.0f) / 8.0f), r.XY); - float d, t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f, glow = 0; + float d; + float t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f; + float glow = 0; for (int i = 0; i < 96; i++) { @@ -206,7 +210,8 @@ internal readonly partial struct ExtrudedTruchetPattern : IComputeShader } int gObjID = objID; - float3 p = o + r * t, n = Normal(p); + float3 p = o + r * t; + float3 n = Normal(p); float2 uv = p.XY; float sc = 0.5f; float2 iuv = Hlsl.Floor(uv / sc) + 0.5f; diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs b/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs index a3da394a..9901a7f0 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs @@ -20,7 +20,8 @@ internal readonly partial struct Octagrams : IComputeShader private static float2x2 Rotate(float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, s, -s, c); } diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs index eddb54ce..079f600c 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs @@ -23,7 +23,8 @@ internal readonly partial struct ProteanClouds : IComputeShader private static float2x2 Rotate(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, s, -s, c); } diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs b/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs index e8308f06..adb0a1be 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs @@ -22,7 +22,8 @@ internal readonly partial struct PyramidPattern : IComputeShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -146,9 +147,8 @@ internal readonly partial struct PyramidPattern : IComputeShader float2 oP = p; float m = BMap(p); float3 n = new(0, 0, -1); - float - edge = 0.0f, - bumpFactor = 0.25f; + float edge = 0.0f; + float bumpFactor = 0.25f; n = DoBumpMap(p, n, bumpFactor, ref edge); diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs b/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs index f85e21ff..66e59609 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs @@ -21,7 +21,8 @@ internal readonly partial struct TriangleGridContouring : IComputeShader // Standard 2D rotation formula. private static float2x2 Rotate2x2(in float a) { - float c = Hlsl.Cos(a), s = Hlsl.Sin(a); + float c = Hlsl.Cos(a); + float s = Hlsl.Sin(a); return new(c, -s, s, c); } @@ -162,12 +163,11 @@ internal readonly partial struct TriangleGridContouring : IComputeShader p -= s - (s.X + s.Y) * 0.211324865f; float i = p.X < p.Y ? 1.0f : 0.0f; - float2 - ioffs = new(1.0f - i, i), - ip0 = 0, - ip1 = ioffs - 0.2113248654f, - ip2 = 0.577350269f, - ctr = (ip0 + ip1 + ip2) / 3.0f; + float2 ioffs = new(1.0f - i, i); + float2 ip0 = 0; + float2 ip1 = ioffs - 0.2113248654f; + float2 ip2 = 0.577350269f; + float2 ctr = (ip0 + ip1 + ip2) / 3.0f; ip0 -= ctr; ip1 -= ctr; @@ -180,15 +180,14 @@ internal readonly partial struct TriangleGridContouring : IComputeShader n3.Y = IsoFunction(s + ioffs); n3.Z = IsoFunction(s + 1.0f); - float - d = 1e5f, - d2 = 1e5f, - d3 = 1e5f, - d4 = 1e5f, - d5 = 1e5f; - + float d = 1e5f; + float d2 = 1e5f; + float d3 = 1e5f; + float d4 = 1e5f; + float d5 = 1e5f; float isovalue = 0; - float2 p0 = default, p1 = default; + float2 p0 = default; + float2 p1 = default; int iTh = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1); d = Hlsl.Min(d, distEdge(p - p0, p - p1)); diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 3171c83d..a89f3ce4 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -135,9 +135,8 @@ public partial class Texture2DTests texture.CopyTo(result, x, y, width, height); - Span2D - expected = new Span2D(array, 64, 64).Slice(y, x, height, width), - data = new(result, height, width); + Span2D expected = new Span2D(array, 64, 64).Slice(y, x, height, width); + Span2D data = new(result, height, width); CollectionAssert.AreEqual(expected.ToArray(), data.ToArray()); } diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index 377fdf2d..2591ce8c 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -150,7 +150,9 @@ public partial class Texture3DTests int[,,] array = new int[3, 64, 64]; foreach (var item in array.AsSpan().Enumerate()) + { item.Value = item.Index; + } using Texture3D texture = device.Get().AllocateTexture3D(textureType, array); @@ -160,9 +162,8 @@ public partial class Texture3DTests for (int k = 0; k < depth; k++) { - Span2D - source = array.AsSpan2D(z + k).Slice(y, x, height, width), - destination = result.AsSpan2D(k); + Span2D source = array.AsSpan2D(z + k).Slice(y, x, height, width); + Span2D destination = result.AsSpan2D(k); CollectionAssert.AreEqual(source.ToArray(), destination.ToArray()); }