Commit d2328a52 by Jamie Madill

D3D11: Futher optimize input layout cache.

Using the new vertex format type enum, we can shrink the size of the input layout tables and reduce draw call overhead further. BUG=angleproject:959 Change-Id: Iea595fa64edbbd91f669138dfdeb9d2543b83929 Reviewed-on: https://chromium-review.googlesource.com/277291Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 0342253e
......@@ -647,6 +647,58 @@ const FormatSet &GetAllSizedInternalFormats()
return formatSet;
}
AttributeType GetAttributeType(GLenum enumValue)
{
switch (enumValue)
{
case GL_FLOAT:
return ATTRIBUTE_FLOAT;
case GL_FLOAT_VEC2:
return ATTRIBUTE_VEC2;
case GL_FLOAT_VEC3:
return ATTRIBUTE_VEC3;
case GL_FLOAT_VEC4:
return ATTRIBUTE_VEC4;
case GL_INT:
return ATTRIBUTE_INT;
case GL_INT_VEC2:
return ATTRIBUTE_IVEC2;
case GL_INT_VEC3:
return ATTRIBUTE_IVEC3;
case GL_INT_VEC4:
return ATTRIBUTE_IVEC4;
case GL_UNSIGNED_INT:
return ATTRIBUTE_UINT;
case GL_UNSIGNED_INT_VEC2:
return ATTRIBUTE_UVEC2;
case GL_UNSIGNED_INT_VEC3:
return ATTRIBUTE_UVEC3;
case GL_UNSIGNED_INT_VEC4:
return ATTRIBUTE_UVEC4;
case GL_FLOAT_MAT2:
return ATTRIBUTE_MAT2;
case GL_FLOAT_MAT3:
return ATTRIBUTE_MAT3;
case GL_FLOAT_MAT4:
return ATTRIBUTE_MAT4;
case GL_FLOAT_MAT2x3:
return ATTRIBUTE_MAT2x3;
case GL_FLOAT_MAT2x4:
return ATTRIBUTE_MAT2x4;
case GL_FLOAT_MAT3x2:
return ATTRIBUTE_MAT3x2;
case GL_FLOAT_MAT3x4:
return ATTRIBUTE_MAT3x4;
case GL_FLOAT_MAT4x2:
return ATTRIBUTE_MAT4x2;
case GL_FLOAT_MAT4x3:
return ATTRIBUTE_MAT4x3;
default:
UNREACHABLE();
return ATTRIBUTE_FLOAT;
}
}
VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
{
switch (type)
......
......@@ -76,6 +76,37 @@ GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type);
typedef std::set<GLenum> FormatSet;
const FormatSet &GetAllSizedInternalFormats();
// From the ESSL 3.00.4 spec:
// Vertex shader inputs can only be float, floating-point vectors, matrices, signed and unsigned
// integers and integer vectors. Vertex shader inputs cannot be arrays or structures.
enum AttributeType
{
ATTRIBUTE_FLOAT,
ATTRIBUTE_VEC2,
ATTRIBUTE_VEC3,
ATTRIBUTE_VEC4,
ATTRIBUTE_INT,
ATTRIBUTE_IVEC2,
ATTRIBUTE_IVEC3,
ATTRIBUTE_IVEC4,
ATTRIBUTE_UINT,
ATTRIBUTE_UVEC2,
ATTRIBUTE_UVEC3,
ATTRIBUTE_UVEC4,
ATTRIBUTE_MAT2,
ATTRIBUTE_MAT3,
ATTRIBUTE_MAT4,
ATTRIBUTE_MAT2x3,
ATTRIBUTE_MAT2x4,
ATTRIBUTE_MAT3x2,
ATTRIBUTE_MAT3x4,
ATTRIBUTE_MAT4x2,
ATTRIBUTE_MAT4x3,
};
AttributeType GetAttributeType(GLenum enumValue);
enum VertexFormatType
{
VERTEX_FORMAT_INVALID,
......
......@@ -70,14 +70,8 @@ bool InputLayoutCache::PackedAttributeComparator::operator()(const PackedAttribu
const auto &attribA = a.attributeData[attribIndex];
const auto &attribB = b.attributeData[attribIndex];
if (attribA.glType != attribB.glType)
return attribA.glType < attribB.glType;
if (attribA.semanticIndex != attribB.semanticIndex)
return attribA.semanticIndex < attribB.semanticIndex;
if (attribA.dxgiFormat != attribB.dxgiFormat)
return attribA.dxgiFormat < attribB.dxgiFormat;
if (attribA.divisor != attribB.divisor)
return attribA.divisor < attribB.divisor;
if (attribA.pack != attribB.pack)
return attribA.pack < attribB.pack;
}
// Equal
......@@ -198,13 +192,13 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
firstInstancedElement = ilKey.elementCount;
}
ilKey.elementCount++;
nextAvailableInputSlot = i + 1;
layout.addAttributeData(ilKey.elements[ilKey.elementCount].glslElementType,
sortedSemanticIndices[i],
vertexFormatInfo.nativeFormat,
vertexFormatType,
sortedAttributes[i]->divisor);
ilKey.elementCount++;
nextAvailableInputSlot = i + 1;
}
}
......
......@@ -10,16 +10,17 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
#define LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
#include "libANGLE/Constants.h"
#include "libANGLE/Error.h"
#include "common/angleutils.h"
#include <GLES2/gl2.h>
#include <cstddef>
#include <map>
#include <unordered_map>
#include "common/angleutils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Error.h"
#include "libANGLE/formatutils.h"
namespace gl
{
class Program;
......@@ -80,22 +81,38 @@ class InputLayoutCache : angle::NonCopyable
void addAttributeData(GLenum glType,
UINT semanticIndex,
DXGI_FORMAT dxgiFormat,
gl::VertexFormatType vertexFormatType,
unsigned int divisor)
{
attributeData[numAttributes].glType = glType;
attributeData[numAttributes].semanticIndex = semanticIndex;
attributeData[numAttributes].dxgiFormat = dxgiFormat;
attributeData[numAttributes].divisor = divisor;
gl::AttributeType attribType = gl::GetAttributeType(glType);
uint8_t packedType = static_cast<uint8_t>(attribType);
uint8_t packedSemantic = static_cast<uint8_t>(semanticIndex);
uint8_t packedFormatType = static_cast<uint8_t>(vertexFormatType);
uint8_t packedDivisor = static_cast<uint8_t>(divisor);
ASSERT(static_cast<gl::AttributeType>(packedType) == attribType);
ASSERT(static_cast<UINT>(packedSemantic) == semanticIndex);
ASSERT(static_cast<gl::VertexFormatType>(packedFormatType) == vertexFormatType);
ASSERT(static_cast<unsigned int>(packedDivisor) == divisor);
attributeData[numAttributes].values.attribType = packedType;
attributeData[numAttributes].values.semanticIndex = packedSemantic;
attributeData[numAttributes].values.vertexFormatType = packedFormatType;
attributeData[numAttributes].values.divisor = packedDivisor;
++numAttributes;
}
struct PackedAttribute
union PackedAttribute
{
GLenum glType;
UINT semanticIndex;
DXGI_FORMAT dxgiFormat;
unsigned int divisor;
struct
{
uint8_t attribType;
uint8_t semanticIndex;
uint8_t vertexFormatType;
uint8_t divisor;
} values;
uint32_t pack;
};
enum Flags
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment