Fixed an issue with local functions in external methods
このコミットが含まれているのは:
1 親
8bf828da6d
コミット
36f2512cf6
3ファイル変更
+46
-22
検索条件に一致するファイルはありません
@@ -18,18 +18,6 @@
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
|
||||
// Fast hash for a pair of floats
|
||||
private static float Hash21(Float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new Float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// HLSL's port of the GLSL mod intrinsic
|
||||
private static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Truchet distance field.
|
||||
/// </summary>
|
||||
@@ -38,6 +26,18 @@
|
||||
/// <returns>The distance field for the input value.</returns>
|
||||
private Float2 DistanceField(Float2 p, out Float2 ang)
|
||||
{
|
||||
// Fast hash for a pair of floats
|
||||
static float Hash21(Float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new Float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// HLSL's port of the GLSL mod intrinsic
|
||||
static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
Float2 ip2 = Hlsl.Floor(p / 2.0f);
|
||||
Float2 ip = Hlsl.Floor(p);
|
||||
float rnd = Hash21(ip);
|
||||
|
||||
@@ -251,6 +251,12 @@ namespace ComputeSharp.SourceGenerators
|
||||
// Rewrite the method syntax tree
|
||||
MethodDeclarationSyntax? processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
|
||||
|
||||
// Emit the extracted local functions first
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
methods.Add(localFunction.Value);
|
||||
}
|
||||
|
||||
// If the method is the shader entry point, do additional processing
|
||||
if (isShaderEntryPoint)
|
||||
{
|
||||
@@ -259,12 +265,6 @@ namespace ComputeSharp.SourceGenerators
|
||||
entryPoint = processedMethod.NormalizeWhitespace().ToFullString();
|
||||
}
|
||||
else methods.Add(processedMethod);
|
||||
|
||||
// Emit the extracted local functions
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
methods.Add(localFunction.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return (entryPoint!, methods);
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace ComputeSharp.Tests
|
||||
[TestMethod]
|
||||
public void ReservedKeywords()
|
||||
{
|
||||
ReflectionServices.GetShaderInfo<SoftmaxActivation>(out _);
|
||||
ReflectionServices.GetShaderInfo<ReservedKeywords_Kernel>(out _);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct SoftmaxActivation : IComputeShader
|
||||
public readonly partial struct ReservedKeywords_Kernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> row_major;
|
||||
public readonly float dword;
|
||||
@@ -32,11 +32,11 @@ namespace ComputeSharp.Tests
|
||||
[TestMethod]
|
||||
public void SpecialTypeAsReturnType()
|
||||
{
|
||||
ReflectionServices.GetShaderInfo<FloatReturnType>(out _);
|
||||
ReflectionServices.GetShaderInfo<SpecialTypeAsReturnType_Kernel>(out _);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct FloatReturnType : IComputeShader
|
||||
public readonly partial struct SpecialTypeAsReturnType_Kernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<Float2> buffer;
|
||||
|
||||
@@ -49,5 +49,29 @@ namespace ComputeSharp.Tests
|
||||
buffer[ThreadIds.X] = Foo(ThreadIds.X) + Bar(ThreadIds.X).XY;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LocalFunctionInExternalMethods()
|
||||
{
|
||||
ReflectionServices.GetShaderInfo<LocalFunctionInExternalMethods_Kernel>(out _);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct LocalFunctionInExternalMethods_Kernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<Float2> buffer;
|
||||
|
||||
Float2 Foo(float x)
|
||||
{
|
||||
static Float2 Baz(float y) => y;
|
||||
|
||||
return Baz(x);
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] = Foo(ThreadIds.X);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする