Removed implicit __z field from pixel shaders
このコミットが含まれているのは:
1 親
31c7058118
コミット
3aeb843023
7ファイル変更
+46
-13
検索条件に一致するファイルはありません
@@ -154,9 +154,11 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
List<StatementSyntax> statements = new();
|
||||
|
||||
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) * 3;
|
||||
rawDataOffset = sizeof(int) * (isComputeShader ? 3 : 2);
|
||||
|
||||
AppendFields(structDeclarationSymbol, Array.Empty<string>(), ref resourceOffset, ref rawDataOffset, statements);
|
||||
|
||||
|
||||
@@ -172,6 +172,21 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
|
||||
return updatedNode.WithBody(Block(IfStatement(rangeCheckExpression, updatedNode.Body!)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
{
|
||||
IdentifierNameSyntax updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
|
||||
// Since pixel shaders are only ever executed on 2D textures, the special __z field can
|
||||
// be removed and replaced with just numeric literal expressions, where the value is 1.
|
||||
if (updatedNode.Identifier.Text == "__z")
|
||||
{
|
||||
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,11 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
builder.AppendLine('{');
|
||||
builder.AppendLine(" uint __x;");
|
||||
builder.AppendLine(" uint __y;");
|
||||
builder.AppendLine(" uint __z;");
|
||||
|
||||
if (info.IsComputeShader)
|
||||
{
|
||||
builder.AppendLine(" uint __z;");
|
||||
}
|
||||
|
||||
foreach (var local in info.FieldsInfo)
|
||||
{
|
||||
|
||||
@@ -193,20 +193,16 @@ namespace ComputeSharp.Shaders
|
||||
int
|
||||
x = texture.Width,
|
||||
y = texture.Height,
|
||||
z = 1,
|
||||
threadsX = 8,
|
||||
threadsY = 8,
|
||||
threadsZ = 1,
|
||||
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);
|
||||
groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1);
|
||||
|
||||
Guard.IsBetweenOrEqualTo(groupsX, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
|
||||
Guard.IsBetweenOrEqualTo(groupsY, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
|
||||
Guard.IsBetweenOrEqualTo(groupsZ, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
|
||||
|
||||
// Create the shader key
|
||||
ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(in shader), threadsX, threadsY, threadsZ);
|
||||
ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(in shader), threadsX, threadsY, 1);
|
||||
CachedShader<T> shaderData;
|
||||
PipelineData? pipelineData;
|
||||
|
||||
@@ -215,7 +211,7 @@ namespace ComputeSharp.Shaders
|
||||
// Get or preload the shader
|
||||
if (!ShadersCache.TryGetValue(key, out shaderData))
|
||||
{
|
||||
LoadShader(threadsX, threadsY, threadsZ, in shader, out shaderData);
|
||||
LoadShader(threadsX, threadsY, 1, in shader, out shaderData);
|
||||
|
||||
// Cache for later use
|
||||
ShadersCache.Add(key, shaderData);
|
||||
@@ -235,7 +231,7 @@ namespace ComputeSharp.Shaders
|
||||
commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineData.D3D12PipelineState);
|
||||
|
||||
// Extract the dispatch data for the shader invocation
|
||||
using DispatchData dispatchData = shaderData.Loader.GetDispatchData(device, in shader, x, y, z);
|
||||
using DispatchData dispatchData = shaderData.Loader.GetDispatchData(device, in shader, x, y, 1);
|
||||
|
||||
// Initialize the loop targets and the captured values
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRoot32BitConstants(dispatchData.Variables);
|
||||
@@ -254,7 +250,7 @@ namespace ComputeSharp.Shaders
|
||||
}
|
||||
|
||||
// Dispatch and wait for completion
|
||||
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ);
|
||||
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, 1);
|
||||
commandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
string EntryPoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the current shader is a compute shader (and not a pixel shader).
|
||||
/// </summary>
|
||||
bool IsComputeShader { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of <see cref="Renderer.Models.HlslResourceInfo"/> items for the shader fields.
|
||||
/// </summary>
|
||||
|
||||
@@ -62,10 +62,14 @@ namespace ComputeSharp.Shaders.Translation
|
||||
ref ulong r0 = ref MemoryMarshal.GetArrayDataReference(resources);
|
||||
ref byte r1 = ref MemoryMarshal.GetArrayDataReference(variables);
|
||||
|
||||
// Set the x, y and z counters
|
||||
// Set the x, y and (optionally) z counters
|
||||
Unsafe.As<byte, int>(ref r1) = x;
|
||||
Unsafe.Add(ref Unsafe.As<byte, int>(ref r1), 1) = y;
|
||||
Unsafe.Add(ref Unsafe.As<byte, int>(ref r1), 2) = z;
|
||||
|
||||
if (IsComputeShader)
|
||||
{
|
||||
Unsafe.Add(ref Unsafe.As<byte, int>(ref r1), 2) = z;
|
||||
}
|
||||
|
||||
// Invoke the dynamic method to extract the captured data
|
||||
int totalVariablesByteSize = this.dispatchDataLoader!(device, in shader, ref r0, ref r1);
|
||||
|
||||
@@ -98,6 +98,9 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// <inheritdoc/>
|
||||
public string EntryPoint { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsComputeShader { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<HlslResourceInfo> HlslResourceInfo => this.hlslResourceInfo;
|
||||
|
||||
@@ -193,6 +196,10 @@ namespace ComputeSharp.Shaders.Translation
|
||||
}
|
||||
}
|
||||
|
||||
// Set the current shader type
|
||||
IsComputeShader = d3D12DescriptorRanges1.Count == 0;
|
||||
|
||||
// Ensure the shader has a valid number of captured resources
|
||||
if (shaderFields.Count == 0 && d3D12DescriptorRanges1.Count == 0)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする