Use blocks for all if statements

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-15 09:10:18 -07:00
1 親 7a7f6be038
コミット d910922ef5
28ファイル変更
+239 -59

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

+4 -1
ファイルの表示
@@ -131,7 +131,10 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
float hatch = Hlsl.Clamp((Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f) + 0.5f, 0.0f, 1.0f);
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
if (hRnd > 0.66f) hatch = hRnd;
if (hRnd > 0.66f)
{
hatch = hRnd;
}
hatch = (hatch * 0.75f) + 0.5f;
+37 -9
ファイルの表示
@@ -48,7 +48,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
{
return Hlsl.Length(p);
}
else p = Hlsl.Abs(p);
else
{
p = Hlsl.Abs(p);
}
switch (SHAPE)
{
@@ -77,7 +80,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new float2(1, 113))) * 45758.5453f);
if (rnd < 0.5f) p.Y = -p.Y;
if (rnd < 0.5f)
{
p.Y = -p.Y;
}
float d = Hlsl.Min(Distance(p - (0.5f * sc)), Distance(p + (0.5f * sc))) - (0.5f * sc);
@@ -86,8 +92,15 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
d += (0.5f - (0.5f / Hlsl.Sqrt(2.0f))) * sc;
}
if (rnd < 0.5f) d = -d;
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f) d = -d;
if (rnd < 0.5f)
{
d = -d;
}
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
{
d = -d;
}
return d - 0.03f;
}
@@ -141,7 +154,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
shade = Hlsl.Min(shade, k * d / t);
t += Hlsl.Clamp(d, 0.01f, 0.25f);
if (d < 0.0f || t > end) break;
if (d < 0.0f || t > end)
{
break;
}
}
return Hlsl.Max(shade, 0.0f);
@@ -163,7 +179,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
occ += (hr - d) * sca;
sca *= 0.7f;
if (sca > 1e5f) break;
if (sca > 1e5f)
{
break;
}
}
return Hlsl.Clamp(1.0f - occ, 0.0f, 1.0f);
@@ -201,7 +220,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
{
d = M(o + (r * t));
if (Hlsl.Abs(d) < 0.001f) break;
if (Hlsl.Abs(d) < 0.001f)
{
break;
}
t += d * 0.7f;
glow += 0.2f / (1.0f + (Hlsl.Abs(d) * 5.0f));
@@ -244,7 +266,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
oCol = Hlsl.Lerp(col2, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat2)) * 0.35f);
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f) oCol *= 0.8f;
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f)
{
oCol *= 0.8f;
}
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, d - 0.015f)) * 0.8f);
}
@@ -254,7 +279,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float4 fCol = Hlsl.Lerp(col1, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat)) * 0.35f);
fCol = Hlsl.Lerp(fCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f) fCol *= 0.8f;
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f)
{
fCol *= 0.8f;
}
oCol = Hlsl.Lerp(oCol, fCol, 1 - Hlsl.SmoothStep(0, 0.01f, d + 0.08f));
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, Hlsl.Length(uv2) - 0.08f)) * 0.8f);
+4 -1
ファイルの表示
@@ -134,7 +134,10 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
distance = DE(pos) * FudgeFactor;
totalDistance += distance;
if (distance < MinimumDistance) break;
if (distance < MinimumDistance)
{
break;
}
steps = i;
}
+4 -1
ファイルの表示
@@ -76,7 +76,10 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
for (int i = 0; i < 130; i++)
{
if (rez.A > 0.99f) break;
if (rez.A > 0.99f)
{
break;
}
float3 pos = ro + (t * rd);
float2 mpv = Map(pos, prm1, bsMo);
+20 -5
ファイルの表示
@@ -88,11 +88,23 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
float2 offs = new float2(Hlsl.Cos(ang), Hlsl.Sin(ang)) * 0.35f;
if (p.X < offs.X) p.X = 1.0f - ((p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f));
else p.X = (p.X - offs.X) / (0.5f - offs.X);
if (p.X < offs.X)
{
p.X = 1.0f - ((p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f));
}
else
{
p.X = (p.X - offs.X) / (0.5f - offs.X);
}
if (p.Y < offs.Y) p.Y = 1.0f - ((p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f));
else p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
if (p.Y < offs.Y)
{
p.Y = 1.0f - ((p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f));
}
else
{
p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
}
return 1.0f - Hlsl.Max(p.X, p.Y);
}
@@ -128,7 +140,10 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
float hatch = Hlsl.Clamp((Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f) + 0.5f, 0.0f, 1.0f);
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
if (hRnd > 0.66f) hatch = hRnd;
if (hRnd > 0.66f)
{
hatch = hRnd;
}
return hatch;
}
+40 -9
ファイルの表示
@@ -104,9 +104,20 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
int iTh = 0;
if (n3.X > isovalue) iTh += 4;
if (n3.Y > isovalue) iTh += 2;
if (n3.Z > isovalue) iTh += 1;
if (n3.X > isovalue)
{
iTh += 4;
}
if (n3.Y > isovalue)
{
iTh += 2;
}
if (n3.Z > isovalue)
{
iTh += 1;
}
if (iTh == 1 || iTh == 6)
{
@@ -207,8 +218,15 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
d2 = Hlsl.Min(d2, DistEdge(p - p0, p - p1));
if (iTh2 == 7) d2 = 0.0f;
if (iTh == 7) d2 = 1e5f;
if (iTh2 == 7)
{
d2 = 0.0f;
}
if (iTh == 7)
{
d2 = 1e5f;
}
d2 = Hlsl.Max(d2, -d);
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
@@ -224,15 +242,28 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
float3 col = new(1, 0.85f, 0.6f);
float sf = 0.004f;
if (d > 0.0f && d2 > 0.0f) col = new float3(1, 1.8f, 3) * 0.45f;
if (d > 0.0f) col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f)));
if (d > 0.0f && d2 > 0.0f)
{
col = new float3(1, 1.8f, 3) * 0.45f;
}
if (d > 0.0f)
{
col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f)));
}
col = Hlsl.Lerp(col, new float3(1.1f, 0.85f, 0.6f), (1.0f - Hlsl.SmoothStep(0.0f, sf, d2)));
col = Hlsl.Lerp(col, new float3(1.5f, 0.9f, 0.6f) * 0.6f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d - 0.012f)));
col = Hlsl.Lerp(col, new float3(1, 0.8f, 0.6f) * new float3(0.7f, 1.0f, 0.75f) * 0.95f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d)));
if (d2 > 0.0f) col *= ((Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f) + 1.25f) / 2.0f;
else col *= Hlsl.Max(2.0f - ((Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f), 0.0f);
if (d2 > 0.0f)
{
col *= ((Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f) + 1.25f) / 2.0f;
}
else
{
col *= Hlsl.Max(2.0f - ((Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f), 0.0f);
}
float pat = Hlsl.Abs(Hlsl.Frac((tri * 12.5f) + 0.4f) - 0.5f) * 2.0f;
+40 -8
ファイルの表示
@@ -259,29 +259,61 @@ internal static unsafe class Win32ApplicationRunner
if (isAtTop)
{
if (isAtRight) return Windows.HTTOPRIGHT;
if (isAtLeft) return Windows.HTTOPLEFT;
if (isAtRight)
{
return Windows.HTTOPRIGHT;
}
if (isAtLeft)
{
return Windows.HTTOPLEFT;
}
return Windows.HTTOP;
}
if (isAtRight)
{
if (isAtTop) return Windows.HTTOPRIGHT;
if (isAtBottom) return Windows.HTBOTTOMRIGHT;
if (isAtTop)
{
return Windows.HTTOPRIGHT;
}
if (isAtBottom)
{
return Windows.HTBOTTOMRIGHT;
}
return Windows.HTRIGHT;
}
if (isAtBottom)
{
if (isAtRight) return Windows.HTBOTTOMRIGHT;
if (isAtLeft) return Windows.HTBOTTOMLEFT;
if (isAtRight)
{
return Windows.HTBOTTOMRIGHT;
}
if (isAtLeft)
{
return Windows.HTBOTTOMLEFT;
}
return Windows.HTBOTTOM;
}
if (isAtLeft)
{
if (isAtTop) return Windows.HTTOPLEFT;
if (isAtBottom) return Windows.HTBOTTOMLEFT;
if (isAtTop)
{
return Windows.HTTOPLEFT;
}
if (isAtBottom)
{
return Windows.HTBOTTOMLEFT;
}
return Windows.HTLEFT;
}
@@ -400,7 +400,10 @@ partial class ID2D1ShaderGenerator
// Declare the fields of the current type
foreach (IFieldSymbol field in type.GetMembers().OfType<IFieldSymbol>())
{
if (field.IsStatic) continue;
if (field.IsStatic)
{
continue;
}
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
+4 -1
ファイルの表示
@@ -22,7 +22,10 @@ unsafe partial class ShaderCompiler
// This happens when doing eg. "dotnet bin\Debug\net5.0\MyApp.dll", which would crash at runtime.
Windows.ResolveLibrary += static (libraryName, assembly, searchPath) =>
{
if (libraryName is not "dxcompiler") return IntPtr.Zero;
if (libraryName is not "dxcompiler")
{
return IntPtr.Zero;
}
string rid = RuntimeInformation.ProcessArchitecture switch
{
+20 -5
ファイルの表示
@@ -227,7 +227,10 @@ internal static partial class HlslKnownTypes
return;
}
if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName())) return;
if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName()))
{
return;
}
// Check if the type is unsupported
if (!type.IsUnmanagedType ||
@@ -241,11 +244,17 @@ internal static partial class HlslKnownTypes
return;
}
if (!customTypes.Add(type)) return;
if (!customTypes.Add(type))
{
return;
}
foreach (IFieldSymbol field in type.GetMembers().OfType<IFieldSymbol>())
{
if (field.IsStatic) continue;
if (field.IsStatic)
{
continue;
}
ExploreTypes((INamedTypeSymbol)field.Type, customTypes, invalidTypes);
}
@@ -298,7 +307,10 @@ internal static partial class HlslKnownTypes
// Only add other custom types as dependencies, and ignore HLSL types
foreach (IFieldSymbol field in type.GetMembers().OfType<IFieldSymbol>())
{
if (field.IsStatic) continue;
if (field.IsStatic)
{
continue;
}
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
@@ -327,7 +339,10 @@ internal static partial class HlslKnownTypes
yield return entry.Type;
}
else queue.Enqueue(entry);
else
{
queue.Enqueue(entry);
}
}
}
}
+4 -1
ファイルの表示
@@ -466,7 +466,10 @@ partial class IShaderGenerator
// Declare the fields of the current type
foreach (IFieldSymbol field in type.GetMembers().OfType<IFieldSymbol>())
{
if (field.IsStatic) continue;
if (field.IsStatic)
{
continue;
}
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
+4 -1
ファイルの表示
@@ -136,7 +136,10 @@ partial class HlslKnownTypes
{
// Delegate types just return an empty string, as they're not actually
// used in the generated shaders, but just mapped to a function at runtime.
if (typeSymbol.TypeKind == TypeKind.Delegate) return "";
if (typeSymbol.TypeKind == TypeKind.Delegate)
{
return "";
}
string typeName = typeSymbol.GetFullMetadataName();
+12 -3
ファイルの表示
@@ -55,9 +55,18 @@ partial class ShaderSourceRewriter
{
string typeName = operation.Member.ContainingType.GetFullMetadataName();
if (mappedName == $"__{nameof(GroupIds)}__get_Index") IsGroupIdsIndexUsed = true;
else if (typeName == typeof(GroupIds).FullName) IsGroupIdsUsed = true;
else if (typeName == typeof(GridIds).FullName) IsGridIdsUsed = true;
if (mappedName == $"__{nameof(GroupIds)}__get_Index")
{
IsGroupIdsIndexUsed = true;
}
else if (typeName == typeof(GroupIds).FullName)
{
IsGroupIdsUsed = true;
}
else if (typeName == typeof(GridIds).FullName)
{
IsGridIdsUsed = true;
}
// Check that the dispatch info types are only used from the main shader body
if (!this.isEntryPoint || this.localFunctionDepth > 0)
+2
ファイルの表示
@@ -240,6 +240,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
// Extract the ISwapChainPanelNative reference from the current panel, then query the
// IDXGISwapChain reference just created and set that as the swap chain panel to use.
fixed (ISwapChainPanelNative** swapChainPanelNative = this.swapChainPanelNative)
{
using (ComPtr<IUnknown> swapChainPanel = default)
{
#if WINDOWS_UWP
@@ -254,6 +255,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
(void**)swapChainPanelNative).Assert();
#endif
}
}
// Get the underlying ID3D12Device in use
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
+4 -1
ファイルの表示
@@ -111,7 +111,10 @@ partial class DeviceHelper
}
}
if (this.isCompleted) return false;
if (this.isCompleted)
{
return false;
}
while (true)
{
+8 -2
ファイルの表示
@@ -25,9 +25,15 @@ internal static class TypeInfo<T>
[RequiresUnreferencedCode("This method reads type info of all fields of the input type (recursively).")]
private static bool ChecksIsDoubleOrContainsDoubles(Type type)
{
if (type == typeof(double)) return true;
if (type == typeof(double))
{
return true;
}
if (type.IsPrimitive) return false;
if (type.IsPrimitive)
{
return false;
}
foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
+4 -1
ファイルの表示
@@ -139,7 +139,10 @@ public abstract class StructuredBuffer<T> : Buffer<T>
copyCommandList.ExecuteAndWaitForCompletion();
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, count);
else
{
CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, count);
}
}
/// <summary>
+2
ファイルの表示
@@ -389,6 +389,7 @@ public abstract unsafe class Texture1D<T> : NativeObject, IGraphicsResource, Gra
#endif
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
fixed (void* sourcePointer = &source)
{
Buffer.MemoryCopy(
@@ -397,6 +398,7 @@ public abstract unsafe class Texture1D<T> : NativeObject, IGraphicsResource, Gra
destinationSizeInBytes: rowSizeInBytes,
sourceBytesToCopy: rowSizeInBytes);
}
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
+2
ファイルの表示
@@ -430,6 +430,7 @@ public abstract unsafe class Texture2D<T> : NativeObject, IGraphicsResource, Gra
#endif
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
@@ -439,6 +440,7 @@ public abstract unsafe class Texture2D<T> : NativeObject, IGraphicsResource, Gra
rowSizeInBytes,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch);
}
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
+2
ファイルの表示
@@ -472,6 +472,7 @@ public abstract unsafe class Texture3D<T> : NativeObject, IGraphicsResource, Gra
#endif
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
@@ -483,6 +484,7 @@ public abstract unsafe class Texture3D<T> : NativeObject, IGraphicsResource, Gra
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch * (uint)height);
}
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
+4 -1
ファイルの表示
@@ -115,7 +115,10 @@ public sealed class ConstantBuffer<T> : Buffer<T>
destinationElementPitchInBytes: (uint)GetPaddedSize(),
count: (uint)length);
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
else
{
CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
}
}
/// <inheritdoc/>
+8 -2
ファイルの表示
@@ -35,7 +35,10 @@ public partial class InitializationTests
foreach (GraphicsDevice device in GraphicsDevice.EnumerateDevices())
{
if (i++ == 0) Assert.AreSame(GraphicsDevice.GetDefault(), device);
if (i++ == 0)
{
Assert.AreSame(GraphicsDevice.GetDefault(), device);
}
using ReadWriteBuffer<int> buffer = device.AllocateReadWriteBuffer<int>(128);
@@ -54,7 +57,10 @@ public partial class InitializationTests
foreach (GraphicsDevice device in GraphicsDevice.QueryDevices(info => info.DedicatedMemorySize >= 1024))
{
if (i++ == 0) Assert.AreSame(GraphicsDevice.GetDefault(), device);
if (i++ == 0)
{
Assert.AreSame(GraphicsDevice.GetDefault(), device);
}
using ReadWriteBuffer<int> buffer = device.AllocateReadWriteBuffer<int>(128);
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable IDE0048
#pragma warning disable IDE0048, IDE0011
namespace ComputeSharp.SwapChain.Shaders.Compute;