Commit d6fef528 by Olli Etuaho Committed by Commit Bot

Shorten mangled names of types

This will reduce binary size by a few kilobytes once we store mangled names of functions as constexpr strings. This still keeps mangled names human readable. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ia63980bd511c701a93e2c5e247d24578c7d7f332 Reviewed-on: https://chromium-review.googlesource.com/943101 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 98e6a5f7
......@@ -143,7 +143,7 @@ constexpr const char *GetBasicMangledName(TBasicType t)
case EbtBool:
return "b";
case EbtYuvCscStandardEXT:
return "ycs";
return "y";
case EbtSampler2D:
return "s2";
case EbtSampler3D:
......@@ -151,15 +151,15 @@ constexpr const char *GetBasicMangledName(TBasicType t)
case EbtSamplerCube:
return "sC";
case EbtSampler2DArray:
return "s2a";
return "sA";
case EbtSamplerExternalOES:
return "sext";
return "sX";
case EbtSamplerExternal2DY2YEXT:
return "sext2y2y";
return "sY";
case EbtSampler2DRect:
return "s2r";
return "sR";
case EbtSampler2DMS:
return "s2ms";
return "sM";
case EbtISampler2D:
return "is2";
case EbtISampler3D:
......@@ -167,9 +167,9 @@ constexpr const char *GetBasicMangledName(TBasicType t)
case EbtISamplerCube:
return "isC";
case EbtISampler2DArray:
return "is2a";
return "isA";
case EbtISampler2DMS:
return "is2ms";
return "isM";
case EbtUSampler2D:
return "us2";
case EbtUSampler3D:
......@@ -177,41 +177,41 @@ constexpr const char *GetBasicMangledName(TBasicType t)
case EbtUSamplerCube:
return "usC";
case EbtUSampler2DArray:
return "us2a";
return "usA";
case EbtUSampler2DMS:
return "us2ms";
return "usM";
case EbtSampler2DShadow:
return "s2s";
case EbtSamplerCubeShadow:
return "sCs";
case EbtSampler2DArrayShadow:
return "s2as";
return "sAs";
case EbtImage2D:
return "im2";
return "I2";
case EbtIImage2D:
return "iim2";
return "iI2";
case EbtUImage2D:
return "uim2";
return "uI2";
case EbtImage3D:
return "im3";
return "I3";
case EbtIImage3D:
return "iim3";
return "iI3";
case EbtUImage3D:
return "uim3";
return "uI3";
case EbtImage2DArray:
return "im2a";
return "IA";
case EbtIImage2DArray:
return "iim2a";
return "iIA";
case EbtUImage2DArray:
return "uim2a";
return "uIA";
case EbtImageCube:
return "imc";
return "Ic";
case EbtIImageCube:
return "iimc";
return "iIc";
case EbtUImageCube:
return "uimc";
return "uIc";
case EbtAtomicCounter:
return "ac";
return "a";
case EbtStruct:
case EbtInterfaceBlock:
return nullptr;
......
......@@ -27,7 +27,7 @@ namespace Helpers
// Size of the maximum possible constexpr-generated mangled name.
// If this value is too small, the compiler will produce errors.
static constexpr size_t kStaticMangledNameMaxLength = 10;
static constexpr size_t kStaticMangledNameMaxLength = 5;
// Type which holds the mangled names for constexpr-generated TTypes.
// This simple struct is needed so that a char array can be returned by value.
......@@ -50,15 +50,13 @@ constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType,
size_t at = 0;
bool isMatrix = primarySize > 1 && secondarySize > 1;
bool isVector = primarySize > 1 && secondarySize == 1;
if (isMatrix)
if (primarySize > 1)
{
name.name[at++] = 'm';
name.name[at++] = '0' + primarySize;
}
else if (isVector)
if (isMatrix)
{
name.name[at++] = 'v';
name.name[at++] = '0' + secondarySize;
}
{
......@@ -69,13 +67,6 @@ constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType,
}
}
name.name[at++] = '0' + primarySize;
if (isMatrix)
{
name.name[at++] = 'x';
name.name[at++] = '0' + secondarySize;
}
name.name[at++] = ';';
name.name[at] = '\0';
......
......@@ -480,10 +480,16 @@ bool TType::canReplaceWithConstantUnion() const
const char *TType::buildMangledName() const
{
TString mangledName;
if (isMatrix())
mangledName += 'm';
else if (isVector())
mangledName += 'v';
{
mangledName += static_cast<char>('0' + getCols());
mangledName += static_cast<char>('0' + getRows());
}
else if (getNominalSize() > 1)
{
mangledName += static_cast<char>('0' + getNominalSize());
}
const char *basicMangledName = GetBasicMangledName(type);
if (basicMangledName != nullptr)
......@@ -514,17 +520,6 @@ const char *TType::buildMangledName() const
}
}
if (isMatrix())
{
mangledName += static_cast<char>('0' + getCols());
mangledName += static_cast<char>('x');
mangledName += static_cast<char>('0' + getRows());
}
else
{
mangledName += static_cast<char>('0' + getNominalSize());
}
if (mArraySizes)
{
for (unsigned int arraySize : *mArraySizes)
......
......@@ -93,6 +93,7 @@
'<(angle_path)/src/tests/compiler_tests/ShaderValidation_test.cpp',
'<(angle_path)/src/tests/compiler_tests/ShaderVariable_test.cpp',
'<(angle_path)/src/tests/compiler_tests/ShCompile_test.cpp',
'<(angle_path)/src/tests/compiler_tests/Type_test.cpp',
'<(angle_path)/src/tests/compiler_tests/TypeTracking_test.cpp',
'<(angle_path)/src/tests/compiler_tests/UnfoldShortCircuitAST_test.cpp',
'<(angle_path)/src/tests/compiler_tests/VariablePacker_test.cpp',
......
......@@ -188,10 +188,10 @@ TEST_F(ShaderImageTest, ImageLoad)
}
// imageLoad call with image2D passed
CheckImageLoadCall(mASTRoot, "imageLoad(im21;vi2;", EbtImage2D, 2);
CheckImageLoadCall(mASTRoot, "imageLoad(I2;2i;", EbtImage2D, 2);
// imageLoad call with image3D passed
CheckImageLoadCall(mASTRoot, "imageLoad(iim31;vi3;", EbtIImage3D, 3);
CheckImageLoadCall(mASTRoot, "imageLoad(iI3;3i;", EbtIImage3D, 3);
}
// Check that imageStore calls get correctly parsed.
......@@ -212,10 +212,10 @@ TEST_F(ShaderImageTest, ImageStore)
}
// imageStore call with image2D
CheckImageStoreCall(mASTRoot, "imageStore(im21;vi2;vf4;", EbtImage2D, 2, EbtFloat, 4);
CheckImageStoreCall(mASTRoot, "imageStore(I2;2i;4f;", EbtImage2D, 2, EbtFloat, 4);
// imageStore call with image2DArray
CheckImageStoreCall(mASTRoot, "imageStore(uim2a1;vi3;vu4;", EbtUImage2DArray, 3, EbtUInt, 4);
CheckImageStoreCall(mASTRoot, "imageStore(uIA;3i;4u;", EbtUImage2DArray, 3, EbtUInt, 4);
}
// Check that memory qualifiers are correctly parsed.
......
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Type_test.cpp:
// Tests for StaticType, TType and BasicType.
//
#include "angle_gl.h"
#include "compiler/translator/PoolAlloc.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/Types.h"
#include "gtest/gtest.h"
namespace sh
{
// Verify that mangled name matches between a vector/matrix TType and a corresponding StaticType.
TEST(Type, VectorAndMatrixMangledNameConsistent)
{
TPoolAllocator allocator;
allocator.push();
SetGlobalPoolAllocator(&allocator);
const TType *staticTypeScalar = StaticType::Get<EbtFloat, EbpMedium, EvqGlobal, 1, 1>();
const TType *staticTypeVec2 = StaticType::Get<EbtFloat, EbpMedium, EvqGlobal, 2, 1>();
const TType *staticTypeMat2x4 = StaticType::Get<EbtFloat, EbpMedium, EvqGlobal, 2, 4>();
TType *typeScalar = new TType(EbtFloat, EbpMedium, EvqGlobal, 1, 1);
TType *typeVec2 = new TType(EbtFloat, EbpMedium, EvqGlobal, 2, 1);
TType *typeMat2x4 = new TType(EbtFloat, EbpMedium, EvqGlobal, 2, 4);
EXPECT_EQ(std::string(staticTypeScalar->getMangledName()),
std::string(typeScalar->getMangledName()));
EXPECT_EQ(std::string(staticTypeVec2->getMangledName()),
std::string(typeVec2->getMangledName()));
EXPECT_EQ(std::string(staticTypeMat2x4->getMangledName()),
std::string(typeMat2x4->getMangledName()));
SetGlobalPoolAllocator(nullptr);
allocator.pop();
}
// Verify that basic type mangled names are unique.
TEST(Type, BaseTypeMangledNamesUnique)
{
std::set<std::string> uniqueNames;
for (int i = static_cast<int>(EbtVoid); i < static_cast<int>(EbtLast); ++i)
{
if (i == static_cast<int>(EbtStruct) || i == static_cast<int>(EbtInterfaceBlock))
{
continue;
}
const std::string &mangledName = GetBasicMangledName(static_cast<TBasicType>(i));
if (mangledName != "")
{
ASSERT_TRUE(uniqueNames.insert(mangledName).second);
}
}
}
} // namespace sh
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