Skip to content

Commit

Permalink
Remove debug info from SPIR-V
Browse files Browse the repository at this point in the history
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 <timvp@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
  • Loading branch information
timvpGoogle authored and Commit Bot committed Jul 7, 2020
1 parent b291ad0 commit 8b80e85
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/libANGLE/renderer/glslang_wrapper_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ class SpirvTransformer final : angle::NonCopyable
public:
SpirvTransformer(const std::vector<uint32_t> &spirvBlobIn,
bool removeEarlyFragmentTestsOptimization,
bool removeDebugInfo,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderType shaderType,
SpirvBlob *spirvBlobOut)
Expand All @@ -919,6 +920,7 @@ class SpirvTransformer final : angle::NonCopyable
gl::ShaderBitSet allStages;
allStages.set();
mRemoveEarlyFragmentTestsOptimization = removeEarlyFragmentTestsOptimization;
mRemoveDebugInfo = removeDebugInfo;
mBuiltinVariableInfo.activeStages = allStages;
}

Expand Down Expand Up @@ -969,6 +971,7 @@ class SpirvTransformer final : angle::NonCopyable
bool mHasTransformFeedbackOutput;

bool mRemoveEarlyFragmentTestsOptimization;
bool mRemoveDebugInfo;

// Input shader variable info map:
const ShaderInterfaceVariableInfoMap &mVariableInfoMap;
Expand Down Expand Up @@ -1154,6 +1157,21 @@ void SpirvTransformer::transformInstruction()
// Look at global declaration opcodes.
switch (opCode)
{
case spv::OpSourceContinued:
case spv::OpSource:
case spv::OpSourceExtension:
case spv::OpName:
case spv::OpMemberName:
case spv::OpString:
case spv::OpLine:
case spv::OpNoLine:
case spv::OpModuleProcessed:
if (mRemoveDebugInfo)
{
// Strip debug info to reduce binary size.
transformed = true;
}
break;
case spv::OpCapability:
transformed = transformCapability(instruction, wordCount);
break;
Expand Down Expand Up @@ -1866,6 +1884,7 @@ void GlslangGetShaderSource(GlslangSourceOptions &options,
angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
const gl::ShaderType shaderType,
bool removeEarlyFragmentTestsOptimization,
bool removeDebugInfo,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const SpirvBlob &initialSpirvBlob,
SpirvBlob *spirvBlobOut)
Expand All @@ -1877,7 +1896,7 @@ angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,

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

ASSERT(ValidateSpirv(*spirvBlobOut));
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/glslang_wrapper_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void GlslangGetShaderSource(GlslangSourceOptions &options,
angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
const gl::ShaderType shaderType,
bool removeEarlyFragmentTestsOptimization,
bool removeDebugInfo,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const SpirvBlob &initialSpirvBlob,
SpirvBlob *spirvBlobOut);
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/metal/mtl_glslang_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState,
// do not have ability to add back in at initProgram time.
angle::Result status = GlslangTransformSpirvCode(
[context](GlslangError error) { return HandleError(context, error); }, shaderType,
false, variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
false, false, variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
&(*shaderCodeOut)[shaderType]);
if (status != angle::Result::Continue)
{
Expand Down
5 changes: 4 additions & 1 deletion src/libANGLE/renderer/vulkan/GlslangWrapperVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ angle::Result GlslangWrapperVk::TransformSpirV(
const SpirvBlob &initialSpirvBlob,
SpirvBlob *shaderCodeOut)
{
const bool removeDebugInfo = !context->getRenderer()->getEnableValidationLayers();

return GlslangTransformSpirvCode(
[context](GlslangError error) { return ErrorHandler(context, error); }, shaderType,
removeEarlyFragmentTestsOptimization, variableInfoMap, initialSpirvBlob, shaderCodeOut);
removeEarlyFragmentTestsOptimization, removeDebugInfo, variableInfoMap, initialSpirvBlob,
shaderCodeOut);
}
} // namespace rx
2 changes: 2 additions & 0 deletions src/libANGLE/renderer/vulkan/RendererVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class RendererVk : angle::NonCopyable

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

bool getEnableValidationLayers() const { return mEnableValidationLayers; }

private:
angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex);
void ensureCapsInitialized() const;
Expand Down

0 comments on commit 8b80e85

Please sign in to comment.