Make GSE and TFE work with SetBindingPair

This commit is contained in:
Gabriel A 2023-10-29 16:21:20 -03:00
parent 0d79a84bcf
commit 53440e2e21
5 changed files with 44 additions and 26 deletions

View file

@ -88,7 +88,7 @@ namespace Ryujinx.Graphics.Shader.Translation
if (VertexAsCompute) if (VertexAsCompute)
{ {
int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferSetBinding;
int countFieldIndex = TranslatorContext.Stage == ShaderStage.Vertex int countFieldIndex = TranslatorContext.Stage == ShaderStage.Vertex
? (int)VertexInfoBufferField.VertexCounts ? (int)VertexInfoBufferField.VertexCounts
: (int)VertexInfoBufferField.GeometryCounts; : (int)VertexInfoBufferField.GeometryCounts;
@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.Shader.Translation
this.TextureSample( this.TextureSample(
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFlags.IntCoords, TextureFlags.IntCoords,
ResourceManager.Reservations.IndexBufferTextureBinding, ResourceManager.Reservations.IndexBufferTextureSetBinding,
1, 1,
new[] { vertexIndexVr }, new[] { vertexIndexVr },
new[] { this.IAdd(ibBaseOffset, outputVertexOffset) }); new[] { this.IAdd(ibBaseOffset, outputVertexOffset) });
@ -144,7 +144,7 @@ namespace Ryujinx.Graphics.Shader.Translation
this.TextureSample( this.TextureSample(
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFlags.IntCoords, TextureFlags.IntCoords,
ResourceManager.Reservations.TopologyRemapBufferTextureBinding, ResourceManager.Reservations.TopologyRemapBufferTextureSetBinding,
1, 1,
new[] { vertexIndex }, new[] { vertexIndex },
new[] { this.IAdd(baseVertex, Const(index)) }); new[] { this.IAdd(baseVertex, Const(index)) });
@ -283,7 +283,7 @@ namespace Ryujinx.Graphics.Shader.Translation
Operand offset = this.IAdd(baseOffset, Const(j)); Operand offset = this.IAdd(baseOffset, Const(j));
Operand value = Instructions.AttributeMap.GenerateAttributeLoad(this, null, location * 4, isOutput: true, isPerPatch: false); Operand value = Instructions.AttributeMap.GenerateAttributeLoad(this, null, location * 4, isOutput: true, isPerPatch: false);
int binding = ResourceManager.Reservations.GetTfeBufferStorageBufferBinding(tfbIndex); int binding = ResourceManager.Reservations.GetTfeBufferStorageBufferSetBinding(tfbIndex);
this.Store(StorageKind.StorageBuffer, binding, Const(0), offset, value); this.Store(StorageKind.StorageBuffer, binding, Const(0), offset, value);
} }
@ -528,8 +528,8 @@ namespace Ryujinx.Graphics.Shader.Translation
{ {
if (TranslatorContext.Stage == ShaderStage.Vertex) if (TranslatorContext.Stage == ShaderStage.Vertex)
{ {
int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferSetBinding;
int vertexOutputSbBinding = ResourceManager.Reservations.VertexOutputStorageBufferBinding; int vertexOutputSbBinding = ResourceManager.Reservations.VertexOutputStorageBufferSetBinding;
int stride = ResourceManager.Reservations.OutputSizePerInvocation; int stride = ResourceManager.Reservations.OutputSizePerInvocation;
Operand vertexCount = this.Load(StorageKind.ConstantBuffer, vertexInfoCbBinding, Const((int)VertexInfoBufferField.VertexCounts), Const(0)); Operand vertexCount = this.Load(StorageKind.ConstantBuffer, vertexInfoCbBinding, Const((int)VertexInfoBufferField.VertexCounts), Const(0));
@ -563,7 +563,7 @@ namespace Ryujinx.Graphics.Shader.Translation
this.BranchIfTrue(lblExit, this.ICompareGreaterOrEqualUnsigned(writtenIndices, Const(maxIndicesPerPrimitiveInvocation))); this.BranchIfTrue(lblExit, this.ICompareGreaterOrEqualUnsigned(writtenIndices, Const(maxIndicesPerPrimitiveInvocation)));
int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = ResourceManager.Reservations.VertexInfoConstantBufferSetBinding;
Operand primitiveIndex = this.Load(StorageKind.Input, IoVariable.GlobalId, Const(0)); Operand primitiveIndex = this.Load(StorageKind.Input, IoVariable.GlobalId, Const(0));
Operand instanceIndex = this.Load(StorageKind.Input, IoVariable.GlobalId, Const(1)); Operand instanceIndex = this.Load(StorageKind.Input, IoVariable.GlobalId, Const(1));
@ -574,7 +574,7 @@ namespace Ryujinx.Graphics.Shader.Translation
ibOffset = this.IAdd(ibOffset, this.IMultiply(invocationId, Const(maxIndicesPerPrimitiveInvocation))); ibOffset = this.IAdd(ibOffset, this.IMultiply(invocationId, Const(maxIndicesPerPrimitiveInvocation)));
ibOffset = this.IAdd(ibOffset, writtenIndices); ibOffset = this.IAdd(ibOffset, writtenIndices);
this.Store(StorageKind.StorageBuffer, ResourceManager.Reservations.GeometryIndexOutputStorageBufferBinding, Const(0), ibOffset, Const(-1)); this.Store(StorageKind.StorageBuffer, ResourceManager.Reservations.GeometryIndexOutputStorageBufferSetBinding, Const(0), ibOffset, Const(-1));
this.Store(StorageKind.LocalMemory, ResourceManager.LocalGeometryOutputIndexCountMemoryId, this.IAdd(writtenIndices, Const(1))); this.Store(StorageKind.LocalMemory, ResourceManager.LocalGeometryOutputIndexCountMemoryId, this.IAdd(writtenIndices, Const(1)));
this.Branch(lblLoopHead); this.Branch(lblLoopHead);

View file

@ -18,6 +18,13 @@ namespace Ryujinx.Graphics.Shader.Translation
public int IndexBufferTextureBinding { get; } public int IndexBufferTextureBinding { get; }
public int TopologyRemapBufferTextureBinding { get; } public int TopologyRemapBufferTextureBinding { get; }
public int VertexInfoConstantBufferSetBinding => SetBindingPair.Pack(Constants.VkConstantBufferSetIndex, VertexInfoConstantBufferBinding);
public int VertexOutputStorageBufferSetBinding => SetBindingPair.Pack(Constants.VkStorageBufferSetIndex, VertexOutputStorageBufferBinding);
public int GeometryVertexOutputStorageBufferSetBinding => SetBindingPair.Pack(Constants.VkStorageBufferSetIndex, GeometryVertexOutputStorageBufferBinding);
public int GeometryIndexOutputStorageBufferSetBinding => SetBindingPair.Pack(Constants.VkStorageBufferSetIndex, GeometryIndexOutputStorageBufferBinding);
public int IndexBufferTextureSetBinding => SetBindingPair.Pack(Constants.VkTextureSetIndex, IndexBufferTextureBinding);
public int TopologyRemapBufferTextureSetBinding => SetBindingPair.Pack(Constants.VkTextureSetIndex, TopologyRemapBufferTextureBinding);
public int ReservedConstantBuffers { get; } public int ReservedConstantBuffers { get; }
public int ReservedStorageBuffers { get; } public int ReservedStorageBuffers { get; }
public int ReservedTextures { get; } public int ReservedTextures { get; }
@ -149,7 +156,8 @@ namespace Ryujinx.Graphics.Shader.Translation
return variable switch return variable switch
{ {
IoVariable.ClipDistance or IoVariable.ClipDistance or
IoVariable.Position => true, IoVariable.Position or
IoVariable.ViewportMask => true,
_ => false, _ => false,
}; };
} }
@ -159,11 +167,21 @@ namespace Ryujinx.Graphics.Shader.Translation
return _tfeBufferSbBaseBinding + bufferIndex; return _tfeBufferSbBaseBinding + bufferIndex;
} }
public int GetTfeBufferStorageBufferSetBinding(int bufferIndex)
{
return SetBindingPair.Pack(Constants.VkStorageBufferSetIndex, _tfeBufferSbBaseBinding + bufferIndex);
}
public int GetVertexBufferTextureBinding(int vaLocation) public int GetVertexBufferTextureBinding(int vaLocation)
{ {
return _vertexBufferTextureBaseBinding + vaLocation; return _vertexBufferTextureBaseBinding + vaLocation;
} }
public int GetVertexBufferTextureSetBinding(int vaLocation)
{
return SetBindingPair.Pack(Constants.VkTextureSetIndex, _vertexBufferTextureBaseBinding + vaLocation);
}
internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset) internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset)
{ {
return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset); return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset);

View file

@ -49,7 +49,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
Instruction.Load, Instruction.Load,
StorageKind.StorageBuffer, StorageKind.StorageBuffer,
operation.Dest, operation.Dest,
new[] { Const(context.ResourceManager.Reservations.VertexOutputStorageBufferBinding), Const(0), vertexElemOffset })); new[] { Const(context.ResourceManager.Reservations.VertexOutputStorageBufferSetBinding), Const(0), vertexElemOffset }));
} }
else else
{ {
@ -123,8 +123,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static LinkedListNode<INode> GenerateEmitVertex(ShaderDefinitions definitions, ResourceManager resourceManager, LinkedListNode<INode> node) private static LinkedListNode<INode> GenerateEmitVertex(ShaderDefinitions definitions, ResourceManager resourceManager, LinkedListNode<INode> node)
{ {
int vbOutputBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding; int vbOutputBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferSetBinding;
int ibOutputBinding = resourceManager.Reservations.GeometryIndexOutputStorageBufferBinding; int ibOutputBinding = resourceManager.Reservations.GeometryIndexOutputStorageBufferSetBinding;
int stride = resourceManager.Reservations.OutputSizePerInvocation; int stride = resourceManager.Reservations.OutputSizePerInvocation;
Operand outputPrimVertex = IncrementLocalMemory(node, resourceManager.LocalGeometryOutputVertexCountMemoryId); Operand outputPrimVertex = IncrementLocalMemory(node, resourceManager.LocalGeometryOutputVertexCountMemoryId);
@ -189,7 +189,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static LinkedListNode<INode> GenerateEndPrimitive(ShaderDefinitions definitions, ResourceManager resourceManager, LinkedListNode<INode> node) private static LinkedListNode<INode> GenerateEndPrimitive(ShaderDefinitions definitions, ResourceManager resourceManager, LinkedListNode<INode> node)
{ {
int ibOutputBinding = resourceManager.Reservations.GeometryIndexOutputStorageBufferBinding; int ibOutputBinding = resourceManager.Reservations.GeometryIndexOutputStorageBufferSetBinding;
Operand outputPrimIndex = IncrementLocalMemory(node, resourceManager.LocalGeometryOutputIndexCountMemoryId); Operand outputPrimIndex = IncrementLocalMemory(node, resourceManager.LocalGeometryOutputIndexCountMemoryId);
Operand baseIndexOffset = GenerateBaseOffset( Operand baseIndexOffset = GenerateBaseOffset(
@ -250,7 +250,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
int elementOffset, int elementOffset,
Operand primVertex) Operand primVertex)
{ {
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
Operand vertexCount = Local(); Operand vertexCount = Local();
node.List.AddBefore(node, new Operation( node.List.AddBefore(node, new Operation(
@ -303,7 +303,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static LinkedListNode<INode> GeneratePrimitiveId(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest) private static LinkedListNode<INode> GeneratePrimitiveId(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest)
{ {
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
Operand vertexCount = Local(); Operand vertexCount = Local();
node.List.AddBefore(node, new Operation( node.List.AddBefore(node, new Operation(

View file

@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFormat.Unknown, TextureFormat.Unknown,
TextureFlags.IntCoords, TextureFlags.IntCoords,
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location), context.ResourceManager.Reservations.GetVertexBufferTextureSetBinding(location),
1 << component, 1 << component,
new[] { temp }, new[] { temp },
new[] { vertexElemOffset })); new[] { vertexElemOffset }));
@ -83,7 +83,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFormat.Unknown, TextureFormat.Unknown,
TextureFlags.IntCoords, TextureFlags.IntCoords,
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location), context.ResourceManager.Reservations.GetVertexBufferTextureSetBinding(location),
1, 1,
new[] { temp }, new[] { temp },
new[] { vertexElemOffset })); new[] { vertexElemOffset }));
@ -151,7 +151,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static Operand GenerateVertexOffset(ResourceManager resourceManager, LinkedListNode<INode> node, int location, int component) private static Operand GenerateVertexOffset(ResourceManager resourceManager, LinkedListNode<INode> node, int location, int component)
{ {
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
Operand vertexIdVr = Local(); Operand vertexIdVr = Local();
GenerateVertexIdVertexRateLoad(resourceManager, node, vertexIdVr); GenerateVertexIdVertexRateLoad(resourceManager, node, vertexIdVr);
@ -244,7 +244,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
Operand src) Operand src)
{ {
Operand componentExists = Local(); Operand componentExists = Local();
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
node = node.List.AddAfter(node, new Operation( node = node.List.AddAfter(node, new Operation(
Instruction.Load, Instruction.Load,
StorageKind.ConstantBuffer, StorageKind.ConstantBuffer,
@ -259,7 +259,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static LinkedListNode<INode> GenerateBaseVertexLoad(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest) private static LinkedListNode<INode> GenerateBaseVertexLoad(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest)
{ {
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
return node.List.AddBefore(node, new Operation( return node.List.AddBefore(node, new Operation(
Instruction.Load, Instruction.Load,
@ -270,7 +270,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
private static LinkedListNode<INode> GenerateBaseInstanceLoad(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest) private static LinkedListNode<INode> GenerateBaseInstanceLoad(ResourceManager resourceManager, LinkedListNode<INode> node, Operand dest)
{ {
int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferBinding; int vertexInfoCbBinding = resourceManager.Reservations.VertexInfoConstantBufferSetBinding;
return node.List.AddBefore(node, new Operation( return node.List.AddBefore(node, new Operation(
Instruction.Load, Instruction.Load,

View file

@ -505,11 +505,9 @@ namespace Ryujinx.Graphics.Shader.Translation
var reservations = GetResourceReservations(); var reservations = GetResourceReservations();
int vertexInfoCbBinding = reservations.VertexInfoConstantBufferBinding;
if (Stage == ShaderStage.Vertex) if (Stage == ShaderStage.Vertex)
{ {
BufferDefinition vertexInfoBuffer = new(BufferLayout.Std140, 0, vertexInfoCbBinding, "vb_info", VertexInfoBuffer.GetStructureType()); BufferDefinition vertexInfoBuffer = new(BufferLayout.Std140, 0, reservations.VertexInfoConstantBufferBinding, "vb_info", VertexInfoBuffer.GetStructureType());
resourceManager.Properties.AddOrUpdateConstantBuffer(vertexInfoBuffer); resourceManager.Properties.AddOrUpdateConstantBuffer(vertexInfoBuffer);
} }
@ -518,10 +516,12 @@ namespace Ryujinx.Graphics.Shader.Translation
new StructureField(AggregateType.Array | AggregateType.FP32, "data", 0) new StructureField(AggregateType.Array | AggregateType.FP32, "data", 0)
}); });
int vertexDataSbBinding = reservations.VertexOutputStorageBufferBinding; BufferDefinition vertexOutputBuffer = new(BufferLayout.Std430, 1, reservations.VertexOutputStorageBufferBinding, "vb_input", vertexInputStruct);
BufferDefinition vertexOutputBuffer = new(BufferLayout.Std430, 1, vertexDataSbBinding, "vb_input", vertexInputStruct);
resourceManager.Properties.AddOrUpdateStorageBuffer(vertexOutputBuffer); resourceManager.Properties.AddOrUpdateStorageBuffer(vertexOutputBuffer);
int vertexInfoCbBinding = reservations.VertexInfoConstantBufferSetBinding;
int vertexDataSbBinding = reservations.VertexOutputStorageBufferSetBinding;
var context = new EmitterContext(); var context = new EmitterContext();
Operand vertexIndex = Options.TargetApi == TargetApi.OpenGL Operand vertexIndex = Options.TargetApi == TargetApi.OpenGL