Add explicit discards to all value returning expressions

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-15 09:10:18 -07:00
1 親 38adbe6087
コミット 9343ac7f7b
47ファイル変更
+144 -144

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

@@ -530,13 +530,13 @@ partial class ID2D1ShaderGenerator
void AppendLF()
{
hlslBuilder.Append('\n');
_ = hlslBuilder.Append('\n');
}
void AppendLineAndLF(string text)
{
hlslBuilder.Append(text);
hlslBuilder.Append('\n');
_ = hlslBuilder.Append(text);
_ = hlslBuilder.Append('\n');
}
// Header
+6 -6
ファイルの表示
@@ -26,12 +26,12 @@ public sealed class FxcCompilationException : Exception
{
StringBuilder builder = new(512);
builder.AppendLine("The FXC compiler encountered one or more errors while trying to compile the shader:");
builder.AppendLine();
builder.AppendLine(error.Trim());
builder.AppendLine();
builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
_ = builder.AppendLine("The FXC compiler encountered one or more errors while trying to compile the shader:");
_ = builder.AppendLine();
_ = builder.AppendLine(error.Trim());
_ = builder.AppendLine();
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
return builder.ToString();
}
+1 -1
ファイルの表示
@@ -342,7 +342,7 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
{
if (this.d2D1ResourceManagerImpl is not null)
{
this.d2D1ResourceManagerImpl->Release();
_ = this.d2D1ResourceManagerImpl->Release();
}
}
+2 -2
ファイルの表示
@@ -178,7 +178,7 @@ unsafe partial struct PixelShaderEffect
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = this.resourceTextureManagerBuffer[resourceTextureIndex];
resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data);
_ = resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data);
if (actualSize is not null)
{
@@ -261,7 +261,7 @@ unsafe partial struct PixelShaderEffect
// If there's already an existing manager at this index, release it
if (currentResourceTextureManager is not null)
{
((IUnknown*)currentResourceTextureManager)->Release();
_ = ((IUnknown*)currentResourceTextureManager)->Release();
}
// Store the resource texture manager into the buffer
@@ -165,7 +165,7 @@ partial struct D2D1ResourceTextureManagerImpl
// If the texture has already been created, just return it
if (@this->d2D1ResourceTexture is not null)
{
@this->d2D1ResourceTexture->AddRef();
_ = @this->d2D1ResourceTexture->AddRef();
*resourceTexture = @this->d2D1ResourceTexture;
@@ -194,10 +194,10 @@ partial struct D2D1ResourceTextureManagerImpl
if (result == S.S_OK)
{
// Store the resource texture for later
d2D1ResourceTexture.CopyTo(&@this->d2D1ResourceTexture);
_ = d2D1ResourceTexture.CopyTo(&@this->d2D1ResourceTexture);
// Also return it to callers
d2D1ResourceTexture.CopyTo(resourceTexture);
_ = d2D1ResourceTexture.CopyTo(resourceTexture);
// Free the staging buffers
NativeMemory.Free(@this->resourceTextureProperties.extents);
+1 -1
ファイルの表示
@@ -31,7 +31,7 @@ internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDa
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
_ = this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
bufferCount: (uint)data.Length);
}
+6 -6
ファイルの表示
@@ -26,12 +26,12 @@ public sealed class DxcCompilationException : Exception
{
StringBuilder builder = new(512);
builder.AppendLine("The DXC compiler encountered one or more errors while trying to compile the shader:");
builder.AppendLine();
builder.AppendLine(error.Trim());
builder.AppendLine();
builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
_ = builder.AppendLine("The DXC compiler encountered one or more errors while trying to compile the shader:");
_ = builder.AppendLine();
_ = builder.AppendLine(error.Trim());
_ = builder.AppendLine();
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
return builder.ToString();
}
+2 -2
ファイルの表示
@@ -46,7 +46,7 @@ internal static partial class HlslKnownKeywords
// HLSL primitive names
foreach (var type in HlslKnownTypes.KnownVectorTypes.Concat(HlslKnownTypes.KnownMatrixTypes))
{
knownKeywords.Add(type.Name.ToLowerInvariant());
_ = knownKeywords.Add(type.Name.ToLowerInvariant());
}
// HLSL intrinsics method names
@@ -54,7 +54,7 @@ internal static partial class HlslKnownKeywords
{
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
knownKeywords.Add(name);
_ = knownKeywords.Add(name);
}
// Let other types inject additional keywords
+2 -2
ファイルの表示
@@ -222,7 +222,7 @@ internal static partial class HlslKnownTypes
// Explicitly prevent bool from being a field in a custom struct
if (type.SpecialType == SpecialType.System_Boolean)
{
invalidTypes.Add(type);
_ = invalidTypes.Add(type);
return;
}
@@ -236,7 +236,7 @@ internal static partial class HlslKnownTypes
type.IsRefLikeType ||
type.GetFullyQualifiedName().StartsWith("System."))
{
invalidTypes.Add(type);
_ = invalidTypes.Add(type);
return;
}
@@ -96,12 +96,12 @@ partial class IShaderGenerator
void AppendLF()
{
textBuilder.Append('\n');
_ = textBuilder.Append('\n');
}
void AppendLine(string text)
{
textBuilder.Append(text);
_ = textBuilder.Append(text);
}
void AppendParsedStatement(string text)
@@ -117,7 +117,7 @@ partial class IShaderGenerator
{
string hlslSource = textBuilder.ToString();
textBuilder.Append(hlslSource);
_ = textBuilder.Append(hlslSource);
sizeHint += textBuilder.Length;
@@ -133,7 +133,7 @@ partial class IShaderGenerator
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Append")))
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
textBuilder.Clear();
_ = textBuilder.Clear();
}
}
+7 -7
ファイルの表示
@@ -570,31 +570,31 @@ partial class IShaderGenerator
void AppendLF()
{
hlslBuilder.Append('\n');
_ = hlslBuilder.Append('\n');
}
void AppendLine(string text)
{
hlslBuilder.Append(text);
_ = hlslBuilder.Append(text);
}
void AppendLineAndLF(string text)
{
hlslBuilder.Append(text);
hlslBuilder.Append('\n');
_ = hlslBuilder.Append(text);
_ = hlslBuilder.Append('\n');
}
void AppendCharacterAndLF(char c)
{
hlslBuilder.Append(c);
hlslBuilder.Append('\n');
_ = hlslBuilder.Append(c);
_ = hlslBuilder.Append('\n');
}
string FlushText()
{
string text = hlslBuilder.ToString();
hlslBuilder.Clear();
_ = hlslBuilder.Clear();
return text;
}
+1 -1
ファイルの表示
@@ -224,7 +224,7 @@ partial class IShaderGenerator
string sourceFilename = $"ComputeSharp.SourceGenerators.ComputeSharp.Libraries.{rid}.{name}.dll";
string targetFilename = Path.Combine(folder, rid, $"{name}.dll");
Directory.CreateDirectory(Path.GetDirectoryName(targetFilename));
_ = Directory.CreateDirectory(Path.GetDirectoryName(targetFilename));
using Stream sourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(sourceFilename);
+1 -1
ファイルの表示
@@ -50,7 +50,7 @@ internal static class SemaphoreSlimExtensions
/// <inheritdoc/>
public void Dispose()
{
this.semaphore.Release();
_ = this.semaphore.Release();
}
}
}
+1 -1
ファイルの表示
@@ -210,7 +210,7 @@ partial class SwapChainManager<TOwner>
}
finally
{
this.renderSemaphore.Release();
_ = this.renderSemaphore.Release();
}
}
+1 -1
ファイルの表示
@@ -531,7 +531,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
@this.swapChainPanelNative.Get()->SetSwapChain(null).Assert();
@this.swapChainPanelNative.Dispose();
ThreadPool.UnsafeQueueUserWorkItem(static state =>
_ = ThreadPool.UnsafeQueueUserWorkItem(static state =>
{
SwapChainManager<TOwner> @this = (SwapChainManager<TOwner>)state!;
+4 -4
ファイルの表示
@@ -90,8 +90,8 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable
{
foreach (D3D12CommandListBundle d3D12CommandListBundle in this.d3D12CommandListBundleQueue)
{
d3D12CommandListBundle.D3D12CommandList->Release();
d3D12CommandListBundle.D3D12CommandAllocator->Release();
_ = d3D12CommandListBundle.D3D12CommandList->Release();
_ = d3D12CommandListBundle.D3D12CommandAllocator->Release();
}
this.d3D12CommandListBundleQueue.Clear();
@@ -114,8 +114,8 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable
fixed (ID3D12GraphicsCommandList** d3D12CommandListPtr = &d3D12CommandList)
fixed (ID3D12CommandAllocator** d3D12CommandAllocatorPtr = &d3D12CommandAllocator)
{
d3D12CommandListComPtr.CopyTo(d3D12CommandListPtr);
d3D12CommandAllocatorComPtr.CopyTo(d3D12CommandAllocatorPtr);
_ = d3D12CommandListComPtr.CopyTo(d3D12CommandListPtr);
_ = d3D12CommandAllocatorComPtr.CopyTo(d3D12CommandAllocatorPtr);
}
}
+5 -5
ファイルの表示
@@ -34,11 +34,11 @@ public sealed class GraphicsDeviceMismatchException : InvalidOperationException
{
StringBuilder builder = new(512);
builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
builder.AppendLine($"The target device to run the compute shader is \"{destinationDevice}\".");
builder.AppendLine($"The buffer of type {resource.GetType()} was allocated on device \"{sourceDevice}\".");
builder.Append("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
builder.ToString();
_ = builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
_ = builder.AppendLine($"The target device to run the compute shader is \"{destinationDevice}\".");
_ = builder.AppendLine($"The buffer of type {resource.GetType()} was allocated on device \"{sourceDevice}\".");
_ = builder.Append("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
_ = builder.ToString();
return new(builder.ToString());
}
+4 -4
ファイルの表示
@@ -26,10 +26,10 @@ public sealed class UnsupportedDoubleOperationException : NotSupportedException
{
StringBuilder builder = new(256);
builder.AppendLine($"The device in use does not support creating resources of type {type}, as it does not support using double precision floating point numbers.");
builder.AppendLine("As a possible workaround, consider replacing usage of the double type with single precision floating point numbers.");
builder.AppendLine("Note that double precision operations are only partially supported on GPU devices, and are far slower than single precision ones.");
builder.ToString();
_ = builder.AppendLine($"The device in use does not support creating resources of type {type}, as it does not support using double precision floating point numbers.");
_ = builder.AppendLine("As a possible workaround, consider replacing usage of the double type with single precision floating point numbers.");
_ = builder.AppendLine("Note that double precision operations are only partially supported on GPU devices, and are far slower than single precision ones.");
_ = builder.ToString();
return new(builder.ToString());
}
+4 -4
ファイルの表示
@@ -28,10 +28,10 @@ public sealed class UnsupportedTextureTypeException : NotSupportedException
{
StringBuilder builder = new(256);
builder.AppendLine($"The device in use does not support creating {rank}D textures of type {type}.");
builder.Append($"Make sure to check the support at runtime by using {nameof(GraphicsDevice)}.");
_ = builder.AppendLine($"The device in use does not support creating {rank}D textures of type {type}.");
_ = builder.Append($"Make sure to check the support at runtime by using {nameof(GraphicsDevice)}.");
builder.AppendLine(rank switch
_ = builder.AppendLine(rank switch
{
1 => $"{nameof(GraphicsDevice.IsReadOnlyTexture1DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture1DSupportedForType)}<T>().",
2 => $"{nameof(GraphicsDevice.IsReadOnlyTexture2DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture2DSupportedForType)}<T>().",
@@ -39,7 +39,7 @@ public sealed class UnsupportedTextureTypeException : NotSupportedException
_ => ThrowHelper.ThrowArgumentException<string>("Invalid texture rank.")
});
builder.Append("As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
_ = builder.Append("As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
return new(builder.ToString());
}
+1 -1
ファイルの表示
@@ -99,7 +99,7 @@ unsafe partial class GraphicsDevice
device.DeviceLost?.Invoke(device, new DeviceLostEventArgs(reason));
}
ThreadPool.QueueUserWorkItem(static state => RaiseDeviceLostEvent((GraphicsDevice)state!), this);
_ = ThreadPool.QueueUserWorkItem(static state => RaiseDeviceLostEvent((GraphicsDevice)state!), this);
}
/// <summary>
+1 -1
ファイルの表示
@@ -433,7 +433,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
this.copyCommandListPool.Rent(this.d3D12Device.Get(), null, out d3D12CommandList, out d3D12CommandAllocator);
break;
default:
ThrowHelper.ThrowArgumentException<ComPtr<ID3D12CommandAllocator>>();
_ = ThrowHelper.ThrowArgumentException<ComPtr<ID3D12CommandAllocator>>();
d3D12CommandList = null;
d3D12CommandAllocator = null;
break;
+2 -2
ファイルの表示
@@ -100,11 +100,11 @@ partial class DeviceHelper
defaultDevice = null;
}
DevicesCache.Remove(device.Luid);
_ = DevicesCache.Remove(device.Luid);
if (Configuration.IsDebugOutputEnabled)
{
D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
_ = D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
queue.Dispose();
}
+15 -15
ファイルの表示
@@ -47,19 +47,19 @@ partial class DeviceHelper
{
nuint length;
queue->GetMessage(i, null, &length);
_ = queue->GetMessage(i, null, &length);
D3D12_MESSAGE* message = (D3D12_MESSAGE*)NativeMemory.Alloc(length);
try
{
queue->GetMessage(i, message, &length);
_ = queue->GetMessage(i, message, &length);
builder.Clear();
builder.AppendLine($"[D3D12 message #{i} for \"{device}\" (HW: {device.IsHardwareAccelerated}, UMA: {device.IsCacheCoherentUMA})]");
builder.AppendLine($"[Category]: {Enum.GetName(message->Category)}");
builder.AppendLine($"[Severity]: {Enum.GetName(message->Severity)}");
builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
_ = builder.Clear();
_ = builder.AppendLine($"[D3D12 message #{i} for \"{device}\" (HW: {device.IsHardwareAccelerated}, UMA: {device.IsCacheCoherentUMA})]");
_ = builder.AppendLine($"[Category]: {Enum.GetName(message->Category)}");
_ = builder.AppendLine($"[Severity]: {Enum.GetName(message->Severity)}");
_ = builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
bool isDeviceRemovedMessage = message->ID is D3D12_MESSAGE_ID_DEVICE_REMOVAL_PROCESS_AT_FAULT or D3D12_MESSAGE_ID_DEVICE_REMOVAL_PROCESS_POSSIBLY_AT_FAULT or D3D12_MESSAGE_ID_DEVICE_REMOVAL_PROCESS_NOT_AT_FAULT;
@@ -81,14 +81,14 @@ partial class DeviceHelper
_ => ThrowHelper.ThrowArgumentOutOfRangeException<string>("Invalid GetDeviceRemovedReason HRESULT.")
};
builder.AppendLine($"[Reason]: {deviceRemovalReason}");
_ = builder.AppendLine($"[Reason]: {deviceRemovalReason}");
}
}
// If DRED is enabled, also output the available auto breadcrumbs
if (isDeviceRemovedMessage && Configuration.IsDeviceRemovedExtendedDataEnabled)
{
builder.AppendLine($"[Description]: \"{new string(message->pDescription)}\"");
_ = builder.AppendLine($"[Description]: \"{new string(message->pDescription)}\"");
using ComPtr<ID3D12DeviceRemovedExtendedData1> d3D12DeviceRemovedExtendedData = default;
@@ -112,7 +112,7 @@ partial class DeviceHelper
ThrowHelper.ThrowWin32Exception(hresult);
}
builder.AppendLine("[DRED breadcrumbs START] ===============================");
_ = builder.AppendLine("[DRED breadcrumbs START] ===============================");
int breadcrumbNodeIndex = 0;
@@ -126,7 +126,7 @@ partial class DeviceHelper
// For each auto breadcrumb node, not all recorded breadcrumb have actually been executed. To reduce the verbosity of the
// output and only show the most relevant info, indicate how many breadcrumbs were recorded and how many were actually
// executed, but then only display the executed ones in the code below. This makes it easier to debug hangs for users.
builder.AppendLine($"[NODE #{breadcrumbNodeIndex}]: {d3D12AutoBreadcrumbNode->BreadcrumbCount} total breadcrumb(s), {numberOfExecutedOps} executed breadcrumb(s)");
_ = builder.AppendLine($"[NODE #{breadcrumbNodeIndex}]: {d3D12AutoBreadcrumbNode->BreadcrumbCount} total breadcrumb(s), {numberOfExecutedOps} executed breadcrumb(s)");
uint contextIndex = 0;
@@ -145,20 +145,20 @@ partial class DeviceHelper
{
string context = new((char*)d3D12AutoBreadcrumbNode->pBreadcrumbContexts[contextIndex++].pContextString);
builder.AppendLine($">> [OP #{commandIndex}]: {d3D12AutoBreadcrumbNode->pCommandHistory[commandIndex]}, \"{context}\"");
_ = builder.AppendLine($">> [OP #{commandIndex}]: {d3D12AutoBreadcrumbNode->pCommandHistory[commandIndex]}, \"{context}\"");
}
else
{
builder.AppendLine($">> [OP #{commandIndex}]: {d3D12AutoBreadcrumbNode->pCommandHistory[commandIndex]}");
_ = builder.AppendLine($">> [OP #{commandIndex}]: {d3D12AutoBreadcrumbNode->pCommandHistory[commandIndex]}");
}
}
}
builder.AppendLine("================================= [DRED breadcrumbs END]");
_ = builder.AppendLine("================================= [DRED breadcrumbs END]");
}
else
{
builder.Append($"[Description]: \"{new string(message->pDescription)}\"");
_ = builder.Append($"[Description]: \"{new string(message->pDescription)}\"");
}
if (message->Severity is D3D12_MESSAGE_SEVERITY_ERROR or D3D12_MESSAGE_SEVERITY_CORRUPTION or D3D12_MESSAGE_SEVERITY_WARNING)
+1 -1
ファイルの表示
@@ -206,7 +206,7 @@ partial class DeviceHelper
[UnmanagedCallersOnly]
private static uint Release(IDXGIFactory4As6Backcompat* @this)
{
@this->dxgiFactory4->Release();
_ = @this->dxgiFactory4->Release();
NativeMemory.Free(@this);
+4 -4
ファイルの表示
@@ -115,8 +115,8 @@ internal static partial class DeviceHelper
if (Windows.SUCCEEDED(createDeviceResult) &&
d3D12DeviceCandidate.Get()->IsShaderModelSupported(D3D_SHADER_MODEL_6_0))
{
d3D12DeviceCandidate.CopyTo(d3D12Device);
dxgiAdapter1.CopyTo(dxgiAdapter);
_ = d3D12DeviceCandidate.CopyTo(d3D12Device);
_ = dxgiAdapter1.CopyTo(dxgiAdapter);
return true;
}
@@ -159,8 +159,8 @@ internal static partial class DeviceHelper
// There is no need to check for SM6.0, as it's guaranteed to be supported by Windows
if (Windows.SUCCEEDED(createDeviceResult))
{
d3D12DeviceCandidate.CopyTo(d3D12Device);
dxgiAdapter1.CopyTo(dxgiAdapter);
_ = d3D12DeviceCandidate.CopyTo(d3D12Device);
_ = dxgiAdapter1.CopyTo(dxgiAdapter);
return true;
}
+5 -5
ファイルの表示
@@ -372,7 +372,7 @@ internal sealed unsafe class WICHelper
fixed (char* p = filename)
{
wicStream.Get()->InitializeFromFilename(
_ = wicStream.Get()->InitializeFromFilename(
(ushort*)p,
Windows.GENERIC_WRITE);
}
@@ -409,7 +409,7 @@ internal sealed unsafe class WICHelper
// Create and initialize a stream
this.wicImagingFactory2.Get()->CreateStream(wicStream.GetAddressOf()).Assert();
wicStream.Get()->InitializeFromStream(stream);
_ = wicStream.Get()->InitializeFromStream(stream);
// Initialize the encoder
wicBitmapEncoder.Get()->Initialize(
@@ -443,7 +443,7 @@ internal sealed unsafe class WICHelper
// Create and initialize a stream
this.wicImagingFactory2.Get()->CreateStream(wicStream.GetAddressOf()).Assert();
wicStream.Get()->InitializeFromBufferWriter(writer);
_ = wicStream.Get()->InitializeFromBufferWriter(writer);
// Initialize the encoder
wicBitmapEncoder.Get()->Initialize(
@@ -524,7 +524,7 @@ internal sealed unsafe class WICHelper
pbPixels: (byte*)data).Assert();
}
wicBitmapFrameEncode.Get()->Commit();
wicBitmapEncoder->Commit();
_ = wicBitmapFrameEncode.Get()->Commit();
_ = wicBitmapEncoder->Commit();
}
}