Implement scaled vertex format emulation (#5564)

* Implement scaled vertex format emulation

* Auto-format (whitespace)

* Delete ToVec4Type
This commit is contained in:
gdkchan 2023-08-16 08:30:33 -03:00 committed by GitHub
parent 492a046335
commit effd546331
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 164 additions and 8 deletions

View file

@ -218,17 +218,34 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
bool changed = false;
ref Array32<AttributeType> attributeTypes = ref _graphics.AttributeTypes;
bool supportsScaledFormats = _context.Capabilities.SupportsScaledVertexFormats;
for (int location = 0; location < state.Length; location++)
{
VertexAttribType type = state[location].UnpackType();
AttributeType value = type switch
AttributeType value;
if (supportsScaledFormats)
{
VertexAttribType.Sint => AttributeType.Sint,
VertexAttribType.Uint => AttributeType.Uint,
_ => AttributeType.Float,
};
value = type switch
{
VertexAttribType.Sint => AttributeType.Sint,
VertexAttribType.Uint => AttributeType.Uint,
_ => AttributeType.Float,
};
}
else
{
value = type switch
{
VertexAttribType.Sint => AttributeType.Sint,
VertexAttribType.Uint => AttributeType.Uint,
VertexAttribType.Uscaled => AttributeType.Uscaled,
VertexAttribType.Sscaled => AttributeType.Sscaled,
_ => AttributeType.Float,
};
}
if (attributeTypes[location] != value)
{

View file

@ -932,6 +932,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateVertexAttribState()
{
bool supportsScaledFormats = _context.Capabilities.SupportsScaledVertexFormats;
uint vbEnableMask = _vbEnableMask;
Span<VertexAttribDescriptor> vertexAttribs = stackalloc VertexAttribDescriptor[Constants.TotalVertexAttribs];
@ -949,7 +950,19 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
continue;
}
if (!FormatTable.TryGetAttribFormat(vertexAttrib.UnpackFormat(), out Format format))
uint packedFormat = vertexAttrib.UnpackFormat();
if (!supportsScaledFormats)
{
packedFormat = vertexAttrib.UnpackType() switch
{
VertexAttribType.Uscaled => ((uint)VertexAttribType.Uint << 27) | (packedFormat & (0x3f << 21)),
VertexAttribType.Sscaled => ((uint)VertexAttribType.Sint << 27) | (packedFormat & (0x3f << 21)),
_ => packedFormat,
};
}
if (!FormatTable.TryGetAttribFormat(packedFormat, out Format format))
{
Logger.Debug?.Print(LogClass.Gpu, $"Invalid attribute format 0x{vertexAttrib.UnpackFormat():X}.");