Skip to content

Commit 8b80e85

Browse files
timvpGoogleCommit Bot
authored and
Commit Bot
committed
Remove debug info from SPIR-V
When dcheck_always_on=false, the SPIR-V transformer will strip all debug information to reduce the SPIR-V binary size. Running T-Rex shows about 27% reduction in the SPIR-V binary size. Bug: angleproject:4680 Test: CQ Change-Id: Id9d0189cdc9c12fa5a1741cf62ef549a533cdf93 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2267358 Commit-Queue: Tim Van Patten <[email protected]> Reviewed-by: Jamie Madill <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]>
1 parent b291ad0 commit 8b80e85

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

src/libANGLE/renderer/glslang_wrapper_utils.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ class SpirvTransformer final : angle::NonCopyable
907907
public:
908908
SpirvTransformer(const std::vector<uint32_t> &spirvBlobIn,
909909
bool removeEarlyFragmentTestsOptimization,
910+
bool removeDebugInfo,
910911
const ShaderInterfaceVariableInfoMap &variableInfoMap,
911912
gl::ShaderType shaderType,
912913
SpirvBlob *spirvBlobOut)
@@ -919,6 +920,7 @@ class SpirvTransformer final : angle::NonCopyable
919920
gl::ShaderBitSet allStages;
920921
allStages.set();
921922
mRemoveEarlyFragmentTestsOptimization = removeEarlyFragmentTestsOptimization;
923+
mRemoveDebugInfo = removeDebugInfo;
922924
mBuiltinVariableInfo.activeStages = allStages;
923925
}
924926

@@ -969,6 +971,7 @@ class SpirvTransformer final : angle::NonCopyable
969971
bool mHasTransformFeedbackOutput;
970972

971973
bool mRemoveEarlyFragmentTestsOptimization;
974+
bool mRemoveDebugInfo;
972975

973976
// Input shader variable info map:
974977
const ShaderInterfaceVariableInfoMap &mVariableInfoMap;
@@ -1154,6 +1157,21 @@ void SpirvTransformer::transformInstruction()
11541157
// Look at global declaration opcodes.
11551158
switch (opCode)
11561159
{
1160+
case spv::OpSourceContinued:
1161+
case spv::OpSource:
1162+
case spv::OpSourceExtension:
1163+
case spv::OpName:
1164+
case spv::OpMemberName:
1165+
case spv::OpString:
1166+
case spv::OpLine:
1167+
case spv::OpNoLine:
1168+
case spv::OpModuleProcessed:
1169+
if (mRemoveDebugInfo)
1170+
{
1171+
// Strip debug info to reduce binary size.
1172+
transformed = true;
1173+
}
1174+
break;
11571175
case spv::OpCapability:
11581176
transformed = transformCapability(instruction, wordCount);
11591177
break;
@@ -1866,6 +1884,7 @@ void GlslangGetShaderSource(GlslangSourceOptions &options,
18661884
angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
18671885
const gl::ShaderType shaderType,
18681886
bool removeEarlyFragmentTestsOptimization,
1887+
bool removeDebugInfo,
18691888
const ShaderInterfaceVariableInfoMap &variableInfoMap,
18701889
const SpirvBlob &initialSpirvBlob,
18711890
SpirvBlob *spirvBlobOut)
@@ -1877,7 +1896,7 @@ angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
18771896

18781897
// Transform the SPIR-V code by assigning location/set/binding values.
18791898
SpirvTransformer transformer(initialSpirvBlob, removeEarlyFragmentTestsOptimization,
1880-
variableInfoMap, shaderType, spirvBlobOut);
1899+
removeDebugInfo, variableInfoMap, shaderType, spirvBlobOut);
18811900
ANGLE_GLSLANG_CHECK(callback, transformer.transform(), GlslangError::InvalidSpirv);
18821901

18831902
ASSERT(ValidateSpirv(*spirvBlobOut));

src/libANGLE/renderer/glslang_wrapper_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void GlslangGetShaderSource(GlslangSourceOptions &options,
118118
angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
119119
const gl::ShaderType shaderType,
120120
bool removeEarlyFragmentTestsOptimization,
121+
bool removeDebugInfo,
121122
const ShaderInterfaceVariableInfoMap &variableInfoMap,
122123
const SpirvBlob &initialSpirvBlob,
123124
SpirvBlob *spirvBlobOut);

src/libANGLE/renderer/metal/mtl_glslang_utils.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState,
256256
// do not have ability to add back in at initProgram time.
257257
angle::Result status = GlslangTransformSpirvCode(
258258
[context](GlslangError error) { return HandleError(context, error); }, shaderType,
259-
false, variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
259+
false, false, variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
260260
&(*shaderCodeOut)[shaderType]);
261261
if (status != angle::Result::Continue)
262262
{

src/libANGLE/renderer/vulkan/GlslangWrapperVk.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ angle::Result GlslangWrapperVk::TransformSpirV(
9191
const SpirvBlob &initialSpirvBlob,
9292
SpirvBlob *shaderCodeOut)
9393
{
94+
const bool removeDebugInfo = !context->getRenderer()->getEnableValidationLayers();
95+
9496
return GlslangTransformSpirvCode(
9597
[context](GlslangError error) { return ErrorHandler(context, error); }, shaderType,
96-
removeEarlyFragmentTestsOptimization, variableInfoMap, initialSpirvBlob, shaderCodeOut);
98+
removeEarlyFragmentTestsOptimization, removeDebugInfo, variableInfoMap, initialSpirvBlob,
99+
shaderCodeOut);
97100
}
98101
} // namespace rx

src/libANGLE/renderer/vulkan/RendererVk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ class RendererVk : angle::NonCopyable
258258

259259
vk::BufferHelper &getNullBuffer() { return mTheNullBuffer; }
260260

261+
bool getEnableValidationLayers() const { return mEnableValidationLayers; }
262+
261263
private:
262264
angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex);
263265
void ensureCapsInitialized() const;

0 commit comments

Comments
 (0)