Removed multiline variable declarations
このコミットが含まれているのは:
1 親
6fa7464f84
コミット
ee0d3a7b68
31ファイル変更
+182
-194
検索条件に一致するファイルはありません
@@ -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)
|
||||
|
||||
@@ -67,9 +67,8 @@ public sealed partial class IShaderGenerator
|
||||
|
||||
var pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) });
|
||||
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<global::{typeName}, {rowTypeName}>(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in {string.Join(".", fieldPath)}));"));
|
||||
|
||||
|
||||
+4
-5
@@ -122,11 +122,10 @@ public sealed partial class IShaderGenerator
|
||||
yield return ParseStatement($"global::System.Runtime.CompilerServices.Unsafe.WriteUnaligned<int>(ref global::System.Runtime.CompilerServices.Unsafe.Add(ref r0, 0), {root32BitConstantsCount});");
|
||||
yield return ParseStatement($"global::System.Runtime.CompilerServices.Unsafe.WriteUnaligned<bool>(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)
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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<T>(),
|
||||
wicActualPixelFormatGuid;
|
||||
Guid wicTargetPixelFormatGuid = WICFormatHelper.GetForType<T>();
|
||||
Guid wicActualPixelFormatGuid;
|
||||
|
||||
// Get the current and target pixel format info
|
||||
wicBitmapFrameDecode.Get()->GetPixelFormat(&wicActualPixelFormatGuid).Assert();
|
||||
|
||||
@@ -55,9 +55,8 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteLength = length * sizeof(T);
|
||||
nint byteOffset = (nint)offset * sizeof(T);
|
||||
nint byteLength = length * sizeof(T);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
|
||||
|
||||
@@ -115,10 +114,9 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
}
|
||||
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<T> : Buffer<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteLength = length * sizeof(T);
|
||||
nint byteOffset = (nint)offset * sizeof(T);
|
||||
nint byteLength = length * sizeof(T);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
|
||||
|
||||
@@ -211,10 +208,9 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
@@ -41,15 +41,13 @@ internal static class ShaderRunner<T>
|
||||
// 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<T>
|
||||
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<T>
|
||||
{
|
||||
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));
|
||||
|
||||
@@ -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 _) &&
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする