aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Lavrov <romanl@google.com>2024-04-16 17:31:11 -0400
committerAngle LUCI CQ <angle-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-18 16:45:29 +0000
commit4109a90ee3bb9fc36d1ccdff88c381b60942bc13 (patch)
tree778cf780a6b4a66c2688c0afe138f3d1ef29f120
parent00fa9af9e681eb7f064a7724a9e1c8b977e25095 (diff)
downloadangle-4109a90ee3bb9fc36d1ccdff88c381b60942bc13.tar.gz
LinkedUniform: avoid frequent GLenum -> index conversion
Certain functions such as getElementComponents() are frequently called in driver_overhead benchmark, causing repeated GLenum -> index conversion of the uniform type which shows up in profiling (driver_overhead_2 trace) Change LinkedUniform.pod.type to LinkedUniform.pod.typeIndex storing the UniformTypeInfo index with conversion helpers. Bug: b/335295728 Change-Id: Iae5cd58f4e2703589d23b8e52991fc4b97c5fb08 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5458741 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Roman Lavrov <romanl@google.com> Reviewed-by: Charlie Lao <cclao@google.com>
-rw-r--r--scripts/code_generation_hashes/uniform_type.json4
-rw-r--r--src/common/gen_uniform_type_table.py18
-rw-r--r--src/common/uniform_type_info_autogen.cpp17
-rw-r--r--src/common/utilities.h6
-rw-r--r--src/libANGLE/Uniform.cpp4
-rw-r--r--src/libANGLE/Uniform.h19
-rw-r--r--src/libANGLE/renderer/metal/ProgramExecutableMtl.mm12
-rw-r--r--src/libANGLE/renderer/vulkan/ProgramExecutableVk.cpp8
8 files changed, 60 insertions, 28 deletions
diff --git a/scripts/code_generation_hashes/uniform_type.json b/scripts/code_generation_hashes/uniform_type.json
index 31d566e949..20d6f9cd85 100644
--- a/scripts/code_generation_hashes/uniform_type.json
+++ b/scripts/code_generation_hashes/uniform_type.json
@@ -1,6 +1,6 @@
{
"src/common/gen_uniform_type_table.py":
- "8837f9f3fb0bc37adf015f3a2e446d11",
+ "d9ee274d8fcded1c67802b34fb11a67d",
"src/common/uniform_type_info_autogen.cpp":
- "85b351f2d5525d1af422a880e361a2bd"
+ "d5cfeac395a1f71dc8e186db38228469"
}
diff --git a/src/common/gen_uniform_type_table.py b/src/common/gen_uniform_type_table.py
index a975efb532..ae3d4d5a80 100644
--- a/src/common/gen_uniform_type_table.py
+++ b/src/common/gen_uniform_type_table.py
@@ -81,7 +81,7 @@ constexpr std::array<UniformTypeInfo, {total_count}> kInfoTable =
{uniform_type_info_data}
}}}};
-size_t GetTypeInfoIndex(GLenum uniformType)
+uint16_t GetIndex(GLenum uniformType)
{{
switch (uniformType)
{{
@@ -93,17 +93,27 @@ size_t GetTypeInfoIndex(GLenum uniformType)
}}
}} // anonymous namespace
+UniformTypeIndex GetUniformTypeIndex(GLenum uniformType)
+{{
+ return UniformTypeIndex{{GetIndex(uniformType)}};
+}}
+
const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType)
{{
- ASSERT(kInfoTable[GetTypeInfoIndex(uniformType)].type == uniformType);
- return kInfoTable[GetTypeInfoIndex(uniformType)];
+ ASSERT(kInfoTable[GetIndex(uniformType)].type == uniformType);
+ return kInfoTable[GetIndex(uniformType)];
+}}
+
+const UniformTypeInfo &GetUniformTypeInfoFromIndex(UniformTypeIndex index)
+{{
+ ASSERT(index.value >= 0 && index.value < {total_count});
+ return kInfoTable[index.value];
}}
}} // namespace gl
"""
type_info_data_template = """{{{type}, {component_type}, {texture_type}, {transposed_type}, {bool_type}, {sampler_format}, {rows}, {columns}, {components}, {component_size}, {internal_size}, {external_size}, {is_sampler}, {is_matrix}, {is_image} }}"""
-type_index_case_template = """case {enum_value}: return {index_value};"""
def cpp_bool(value):
diff --git a/src/common/uniform_type_info_autogen.cpp b/src/common/uniform_type_info_autogen.cpp
index 70249981a8..e129f21c24 100644
--- a/src/common/uniform_type_info_autogen.cpp
+++ b/src/common/uniform_type_info_autogen.cpp
@@ -204,7 +204,7 @@ constexpr std::array<UniformTypeInfo, 77> kInfoTable = {
{GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT, GL_INT, GL_NONE, GL_NONE, GL_NONE, SamplerFormat::Float, 1, 1,
1, sizeof(GLint), sizeof(GLint) * 4, sizeof(GLint) * 1, true, false, false}}};
-size_t GetTypeInfoIndex(GLenum uniformType)
+uint16_t GetIndex(GLenum uniformType)
{
switch (uniformType)
{
@@ -369,10 +369,21 @@ size_t GetTypeInfoIndex(GLenum uniformType)
}
} // anonymous namespace
+UniformTypeIndex GetUniformTypeIndex(GLenum uniformType)
+{
+ return UniformTypeIndex{GetIndex(uniformType)};
+}
+
const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType)
{
- ASSERT(kInfoTable[GetTypeInfoIndex(uniformType)].type == uniformType);
- return kInfoTable[GetTypeInfoIndex(uniformType)];
+ ASSERT(kInfoTable[GetIndex(uniformType)].type == uniformType);
+ return kInfoTable[GetIndex(uniformType)];
+}
+
+const UniformTypeInfo &GetUniformTypeInfoFromIndex(UniformTypeIndex index)
+{
+ ASSERT(index.value >= 0 && index.value < 77);
+ return kInfoTable[index.value];
}
} // namespace gl
diff --git a/src/common/utilities.h b/src/common/utilities.h
index 87b1ed4337..9c9b83b633 100644
--- a/src/common/utilities.h
+++ b/src/common/utilities.h
@@ -205,7 +205,13 @@ inline constexpr UniformTypeInfo::UniformTypeInfo(GLenum type,
isImageType(isImageType)
{}
+struct UniformTypeIndex
+{
+ uint16_t value;
+};
const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType);
+UniformTypeIndex GetUniformTypeIndex(GLenum uniformType);
+const UniformTypeInfo &GetUniformTypeInfoFromIndex(UniformTypeIndex index);
const char *GetGenericErrorMessage(GLenum error);
diff --git a/src/libANGLE/Uniform.cpp b/src/libANGLE/Uniform.cpp
index a15ed67a56..5d941cc508 100644
--- a/src/libANGLE/Uniform.cpp
+++ b/src/libANGLE/Uniform.cpp
@@ -26,7 +26,7 @@ LinkedUniform::LinkedUniform(GLenum typeIn,
ASSERT(arraySizesIn.size() <= 1);
memset(this, 0, sizeof(*this));
- SetBitField(pod.type, typeIn);
+ pod.typeIndex = GetUniformTypeIndex(typeIn);
SetBitField(pod.precision, precisionIn);
pod.location = locationIn;
SetBitField(pod.binding, bindingIn);
@@ -54,7 +54,7 @@ LinkedUniform::LinkedUniform(const UsedUniform &usedUniform)
// Note: Ensure every data member is initialized.
pod.flagBitsAsUByte = 0;
- SetBitField(pod.type, usedUniform.type);
+ pod.typeIndex = GetUniformTypeIndex(usedUniform.type);
SetBitField(pod.precision, usedUniform.precision);
SetBitField(pod.imageUnitFormat, usedUniform.imageUnitFormat);
pod.location = usedUniform.location;
diff --git a/src/libANGLE/Uniform.h b/src/libANGLE/Uniform.h
index e10deebca1..2759ed5cd2 100644
--- a/src/libANGLE/Uniform.h
+++ b/src/libANGLE/Uniform.h
@@ -90,12 +90,17 @@ struct LinkedUniform
const sh::BlockMemberInfo &blockInfoIn);
LinkedUniform(const UsedUniform &usedUniform);
- bool isSampler() const { return GetUniformTypeInfo(pod.type).isSampler; }
- bool isImage() const { return GetUniformTypeInfo(pod.type).isImageType; }
- bool isAtomicCounter() const { return IsAtomicCounterType(pod.type); }
+ const UniformTypeInfo &getUniformTypeInfo() const
+ {
+ return GetUniformTypeInfoFromIndex(pod.typeIndex);
+ }
+
+ bool isSampler() const { return getUniformTypeInfo().isSampler; }
+ bool isImage() const { return getUniformTypeInfo().isImageType; }
+ bool isAtomicCounter() const { return IsAtomicCounterType(getType()); }
bool isInDefaultBlock() const { return pod.bufferIndex == -1; }
- size_t getElementSize() const { return GetUniformTypeInfo(pod.type).externalSize; }
- GLint getElementComponents() const { return GetUniformTypeInfo(pod.type).componentCount; }
+ size_t getElementSize() const { return getUniformTypeInfo().externalSize; }
+ GLint getElementComponents() const { return getUniformTypeInfo().componentCount; }
bool isTexelFetchStaticUse() const { return pod.flagBits.texelFetchStaticUse; }
bool isFragmentInOut() const { return pod.flagBits.isFragmentInOut; }
@@ -107,7 +112,7 @@ struct LinkedUniform
return pod.arraySize;
}
- GLenum getType() const { return pod.type; }
+ GLenum getType() const { return getUniformTypeInfo().type; }
uint16_t getOuterArrayOffset() const { return pod.outerArrayOffset; }
uint16_t getOuterArraySizeProduct() const { return pod.outerArraySizeProduct; }
int16_t getBinding() const { return pod.binding; }
@@ -120,7 +125,7 @@ struct LinkedUniform
struct PODStruct
{
- uint16_t type;
+ UniformTypeIndex typeIndex;
uint16_t precision;
int32_t location;
diff --git a/src/libANGLE/renderer/metal/ProgramExecutableMtl.mm b/src/libANGLE/renderer/metal/ProgramExecutableMtl.mm
index 6720310023..76281b1fea 100644
--- a/src/libANGLE/renderer/metal/ProgramExecutableMtl.mm
+++ b/src/libANGLE/renderer/metal/ProgramExecutableMtl.mm
@@ -1531,7 +1531,7 @@ void ProgramExecutableMtl::setUniformImpl(GLint location,
return;
}
- if (linkedUniform.pod.type == entryPointType)
+ if (linkedUniform.getType() == entryPointType)
{
for (gl::ShaderType shaderType : gl::kAllGLES2ShaderTypes)
{
@@ -1546,7 +1546,7 @@ void ProgramExecutableMtl::setUniformImpl(GLint location,
const GLint componentCount = (GLint)linkedUniform.getElementComponents();
const GLint baseComponentSize = (GLint)mtl::GetMetalSizeForGLType(
- gl::VariableComponentType(linkedUniform.pod.type));
+ gl::VariableComponentType(linkedUniform.getType()));
UpdateDefaultUniformBlockWithElementSize(count, locationInfo.arrayIndex, componentCount,
v, baseComponentSize, layoutInfo,
&uniformBlock.uniformData);
@@ -1568,7 +1568,7 @@ void ProgramExecutableMtl::setUniformImpl(GLint location,
const GLint componentCount = linkedUniform.getElementComponents();
- ASSERT(linkedUniform.pod.type == gl::VariableBoolVectorType(entryPointType));
+ ASSERT(linkedUniform.getType() == gl::VariableBoolVectorType(entryPointType));
GLint initialArrayOffset =
locationInfo.arrayIndex * layoutInfo.arrayStride + layoutInfo.offset;
@@ -1604,11 +1604,11 @@ void ProgramExecutableMtl::getUniformImpl(GLint location, T *v, GLenum entryPoin
const DefaultUniformBlockMtl &uniformBlock = mDefaultUniformBlocks[shaderType];
const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location];
- ASSERT(gl::GetUniformTypeInfo(linkedUniform.pod.type).componentType == entryPointType ||
- gl::GetUniformTypeInfo(linkedUniform.pod.type).componentType ==
+ ASSERT(linkedUniform.getUniformTypeInfo().componentType == entryPointType ||
+ linkedUniform.getUniformTypeInfo().componentType ==
gl::VariableBoolVectorType(entryPointType));
const GLint baseComponentSize =
- (GLint)mtl::GetMetalSizeForGLType(gl::VariableComponentType(linkedUniform.pod.type));
+ (GLint)mtl::GetMetalSizeForGLType(gl::VariableComponentType(linkedUniform.getType()));
if (gl::IsMatrixType(linkedUniform.getType()))
{
diff --git a/src/libANGLE/renderer/vulkan/ProgramExecutableVk.cpp b/src/libANGLE/renderer/vulkan/ProgramExecutableVk.cpp
index b27103426a..b2d75cc1de 100644
--- a/src/libANGLE/renderer/vulkan/ProgramExecutableVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ProgramExecutableVk.cpp
@@ -2148,7 +2148,7 @@ void ProgramExecutableVk::setUniformImpl(GLint location,
ASSERT(!linkedUniform.isSampler());
- if (linkedUniform.pod.type == entryPointType)
+ if (linkedUniform.getType() == entryPointType)
{
for (const gl::ShaderType shaderType : mExecutable->getLinkedShaderStages())
{
@@ -2182,7 +2182,7 @@ void ProgramExecutableVk::setUniformImpl(GLint location,
const GLint componentCount = linkedUniform.getElementComponents();
- ASSERT(linkedUniform.pod.type == gl::VariableBoolVectorType(entryPointType));
+ ASSERT(linkedUniform.getType() == gl::VariableBoolVectorType(entryPointType));
GLint initialArrayOffset =
locationInfo.arrayIndex * layoutInfo.arrayStride + layoutInfo.offset;
@@ -2218,8 +2218,8 @@ void ProgramExecutableVk::getUniformImpl(GLint location, T *v, GLenum entryPoint
const DefaultUniformBlockVk &uniformBlock = *mDefaultUniformBlocks[shaderType];
const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location];
- ASSERT(gl::GetUniformTypeInfo(linkedUniform.pod.type).componentType == entryPointType ||
- gl::GetUniformTypeInfo(linkedUniform.pod.type).componentType ==
+ ASSERT(linkedUniform.getUniformTypeInfo().componentType == entryPointType ||
+ linkedUniform.getUniformTypeInfo().componentType ==
gl::VariableBoolVectorType(entryPointType));
if (gl::IsMatrixType(linkedUniform.getType()))