Commit 2ee580f1 by Jamie Madill

D3D11: Futher optimize input layout cache.

*re-land with fix for matrix attributes* 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: I6d8ad78a003c41f40e7e1caa5972838f8ff4fce8 Reviewed-on: https://chromium-review.googlesource.com/284811Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 75da1974
...@@ -195,6 +195,7 @@ class Program : angle::NonCopyable ...@@ -195,6 +195,7 @@ class Program : angle::NonCopyable
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
GLint getActiveAttributeCount(); GLint getActiveAttributeCount();
GLint getActiveAttributeMaxLength(); GLint getActiveAttributeMaxLength();
const sh::Attribute *getLinkedAttributes() const { return mLinkedAttribute; }
GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps); GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps);
GLenum getSamplerTextureType(SamplerType type, unsigned int samplerIndex); GLenum getSamplerTextureType(SamplerType type, unsigned int samplerIndex);
......
...@@ -647,6 +647,58 @@ const FormatSet &GetAllSizedInternalFormats() ...@@ -647,6 +647,58 @@ const FormatSet &GetAllSizedInternalFormats()
return formatSet; 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) VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
{ {
switch (type) switch (type)
......
...@@ -76,6 +76,37 @@ GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type); ...@@ -76,6 +76,37 @@ GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type);
typedef std::set<GLenum> FormatSet; typedef std::set<GLenum> FormatSet;
const FormatSet &GetAllSizedInternalFormats(); 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 enum VertexFormatType
{ {
VERTEX_FORMAT_INVALID, VERTEX_FORMAT_INVALID,
......
...@@ -10,16 +10,17 @@ ...@@ -10,16 +10,17 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ #ifndef LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
#define 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 <GLES2/gl2.h>
#include <cstddef> #include <cstddef>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include "common/angleutils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Error.h"
#include "libANGLE/formatutils.h"
namespace gl namespace gl
{ {
class Program; class Program;
...@@ -48,28 +49,6 @@ class InputLayoutCache : angle::NonCopyable ...@@ -48,28 +49,6 @@ class InputLayoutCache : angle::NonCopyable
void setCacheSize(unsigned int cacheSize) { mCacheSize = cacheSize; } void setCacheSize(unsigned int cacheSize) { mCacheSize = cacheSize; }
private: private:
struct InputLayoutElement
{
D3D11_INPUT_ELEMENT_DESC desc;
GLenum glslElementType;
};
struct InputLayoutKey
{
unsigned int elementCount;
InputLayoutElement elements[gl::MAX_VERTEX_ATTRIBS];
const char *begin() const
{
return reinterpret_cast<const char*>(&elementCount);
}
const char *end() const
{
return reinterpret_cast<const char*>(&elements[elementCount]);
}
};
struct PackedAttributeLayout struct PackedAttributeLayout
{ {
PackedAttributeLayout() PackedAttributeLayout()
...@@ -80,23 +59,10 @@ class InputLayoutCache : angle::NonCopyable ...@@ -80,23 +59,10 @@ class InputLayoutCache : angle::NonCopyable
void addAttributeData(GLenum glType, void addAttributeData(GLenum glType,
UINT semanticIndex, UINT semanticIndex,
DXGI_FORMAT dxgiFormat, gl::VertexFormatType vertexFormatType,
unsigned int divisor) unsigned int divisor);
{
attributeData[numAttributes].glType = glType;
attributeData[numAttributes].semanticIndex = semanticIndex;
attributeData[numAttributes].dxgiFormat = dxgiFormat;
attributeData[numAttributes].divisor = divisor;
++numAttributes;
}
struct PackedAttribute bool operator<(const PackedAttributeLayout &other) const;
{
GLenum glType;
UINT semanticIndex;
DXGI_FORMAT dxgiFormat;
unsigned int divisor;
};
enum Flags enum Flags
{ {
...@@ -107,15 +73,10 @@ class InputLayoutCache : angle::NonCopyable ...@@ -107,15 +73,10 @@ class InputLayoutCache : angle::NonCopyable
size_t numAttributes; size_t numAttributes;
unsigned int flags; unsigned int flags;
PackedAttribute attributeData[gl::MAX_VERTEX_ATTRIBS]; uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS];
};
struct PackedAttributeComparator
{
bool operator()(const PackedAttributeLayout &a, const PackedAttributeLayout &b) const;
}; };
std::map<PackedAttributeLayout, ID3D11InputLayout *, PackedAttributeComparator> mLayoutMap; std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap;
ID3D11InputLayout *mCurrentIL; ID3D11InputLayout *mCurrentIL;
ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS]; ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
......
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