Changed ref kind for ArrayPoolStringBuilder type in IShader<TSelf>
This will allow generated code to request an approximated target size from the shared buffer pool, and reduce or eliminate the number of times the target buffer needs to be resized while building the HLSL source
このコミットが含まれているのは:
1 親
5fdee964da
コミット
56b0b758fa
5ファイル変更
+27
-11
検索条件に一致するファイルはありません
@@ -84,7 +84,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
Identifier("BuildHlslString"))
|
||||
.AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("builder")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(IdentifierName("ArrayPoolStringBuilder")),
|
||||
Parameter(Identifier("builder")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(IdentifierName("ArrayPoolStringBuilder")),
|
||||
Parameter(Identifier("threadsX")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsY")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))))
|
||||
@@ -463,6 +463,22 @@ namespace ComputeSharp.SourceGenerators
|
||||
IEnumerable<string> processedMethods,
|
||||
string executeMethod)
|
||||
{
|
||||
// builder = ArrayPoolStringBuilder.Create(1024);
|
||||
yield return
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("builder"),
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ArrayPoolStringBuilder"),
|
||||
IdentifierName("Create")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(1024))))));
|
||||
|
||||
// Header
|
||||
yield return ParseStatement("builder.AppendLine(\"// ================================================\");");
|
||||
yield return ParseStatement("builder.AppendLine(\"// AUTO GENERATED\");");
|
||||
|
||||
@@ -48,12 +48,12 @@ namespace ComputeSharp.__Internals
|
||||
/// <summary>
|
||||
/// Builds the HLSL source code for the current shader instance.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write the HLSL source to.</param>
|
||||
/// <param name="builder">The resulting <see cref="ArrayPoolStringBuilder"/> instance containing the HLSL source.</param>
|
||||
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void BuildHlslString(ref ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ);
|
||||
void BuildHlslString(out ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ);
|
||||
}
|
||||
}
|
||||
@@ -102,11 +102,12 @@ namespace ComputeSharp.Interop
|
||||
private static unsafe void GetNonGenericShaderInfo<T>(in T shader, out ShaderInfo shaderInfo)
|
||||
where T : struct, IShader<T>
|
||||
{
|
||||
ArrayPoolStringBuilder shaderSource = ArrayPoolStringBuilder.Create();
|
||||
|
||||
shader.BuildHlslString(ref shaderSource, 1, 1, 1);
|
||||
shader.BuildHlslString(out ArrayPoolStringBuilder shaderSource, 1, 1, 1);
|
||||
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(shaderSource.WrittenSpan);
|
||||
|
||||
shaderSource.Dispose();
|
||||
|
||||
using ComPtr<IDxcUtils> dxcUtils = default;
|
||||
|
||||
Guid dxcLibraryClsid = FX.CLSID_DxcLibrary;
|
||||
|
||||
@@ -25,13 +25,14 @@ namespace ComputeSharp.__Internals
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ArrayPoolStringBuilder"/> instance ready to use.
|
||||
/// </summary>
|
||||
/// <param name="sizeHint">The size hint for the internal buffer to allocate.</param>
|
||||
/// <returns>A new <see cref="ArrayPoolStringBuilder"/> instance with default values.</returns>
|
||||
[Pure]
|
||||
public static ArrayPoolStringBuilder Create()
|
||||
public static ArrayPoolStringBuilder Create(int sizeHint)
|
||||
{
|
||||
ArrayPoolStringBuilder builder;
|
||||
|
||||
builder.array = ArrayPool<char>.Shared.Rent(1024);
|
||||
builder.array = ArrayPool<char>.Shared.Rent(sizeHint);
|
||||
builder.index = 0;
|
||||
|
||||
return builder;
|
||||
|
||||
@@ -237,9 +237,7 @@ namespace ComputeSharp.Shaders
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, in T shader, out CachedShader shaderData)
|
||||
{
|
||||
ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create();
|
||||
|
||||
shader.BuildHlslString(ref builder, threadsX, threadsY, threadsZ);
|
||||
shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);
|
||||
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(builder.WrittenSpan);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする