Hash :
e21ecd1b
Author :
Date :
2023-05-26T14:06:46
Vulkan: Add dirty bit processing for uniform buffer change When app calls glBufferData for the uniform buffer, we may end up reallocate the storage. This will set DIRTY_BIT_UNIFORM_BUFFER_BINDINGS on the context, but the exact uniform block index gets lost along the way. This CL sets mDirtyBits on the program for the corresponding block index and then changed vulkan backend to utilize the program's mDirtyBits and only update the buffer if it is dirty, instead of always update all uniform buffers even if only one of the buffer is dirty. In order to make this work, this CL also adds the reverse tracking from buffer binding to uniform blocks. Previously we already have the tracking of which buffer binding index is used for which buffer block index. This CL adds mUniformBlockBindingMasks which is an array of BitSets. Each array element tracks all the uniform block index that is using this buffer binding index (you can have the same buffer bound to multiple uniform block index). Then when a buffer binding index is dirty, that BitSet gets added into program's uniform block dirty bits. This CL and previous CL improves GfxBench gl_driver2_off score 1.8% (from average 6797 to average 6919) on pixel 7 pro. Bug: b/282194402 Change-Id: Ic5002643a5297907276fc9b20ca7d21af9bdc4fe Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4553136 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Roman Lavrov <romanl@google.com> Commit-Queue: Charlie Lao <cclao@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
//
// Copyright 2017 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.
//
// ProgramPipelineVk.cpp:
// Implements the class methods for ProgramPipelineVk.
//
#include "libANGLE/renderer/vulkan/ProgramPipelineVk.h"
namespace rx
{
ProgramPipelineVk::ProgramPipelineVk(const gl::ProgramPipelineState &state)
: ProgramPipelineImpl(state)
{}
ProgramPipelineVk::~ProgramPipelineVk() {}
void ProgramPipelineVk::destroy(const gl::Context *context)
{
ContextVk *contextVk = vk::GetImpl(context);
reset(contextVk);
}
void ProgramPipelineVk::reset(ContextVk *contextVk)
{
mExecutable.reset(contextVk);
}
angle::Result ProgramPipelineVk::link(const gl::Context *glContext,
const gl::ProgramMergedVaryings &mergedVaryings,
const gl::ProgramVaryingPacking &varyingPacking)
{
ContextVk *contextVk = vk::GetImpl(glContext);
const gl::ProgramExecutable &glExecutable = mState.getExecutable();
SpvSourceOptions options = SpvCreateSourceOptions(contextVk->getFeatures());
SpvProgramInterfaceInfo spvProgramInterfaceInfo;
spvProgramInterfaceInfo = {};
reset(contextVk);
mExecutable.clearVariableInfoMap();
// Now that the program pipeline has all of the programs attached, the various descriptor
// set/binding locations need to be re-assigned to their correct values.
const gl::ShaderType linkedTransformFeedbackStage =
glExecutable.getLinkedTransformFeedbackStage();
// This should be done before assigning varying locations. Otherwise, we can encounter shader
// interface mismatching problems when the transform feedback stage is not the vertex stage.
if (options.supportsTransformFeedbackExtension)
{
for (const gl::ShaderType shaderType : glExecutable.getLinkedShaderStages())
{
const gl::Program *glProgram = mState.getShaderProgram(shaderType);
if (glProgram && gl::ShaderTypeSupportsTransformFeedback(shaderType))
{
const bool isTransformFeedbackStage =
shaderType == linkedTransformFeedbackStage &&
!glProgram->getState().getLinkedTransformFeedbackVaryings().empty();
SpvAssignTransformFeedbackLocations(
shaderType, glProgram->getExecutable(), isTransformFeedbackStage,
&spvProgramInterfaceInfo, &mExecutable.mVariableInfoMap);
}
}
}
mExecutable.mOriginalShaderInfo.clear();
gl::ShaderType frontShaderType = gl::ShaderType::InvalidEnum;
UniformBindingIndexMap uniformBindingIndexMap;
for (const gl::ShaderType shaderType : glExecutable.getLinkedShaderStages())
{
const bool isTransformFeedbackStage =
shaderType == linkedTransformFeedbackStage &&
!glExecutable.getLinkedTransformFeedbackVaryings().empty();
SpvAssignLocations(options, glExecutable, varyingPacking, shaderType, frontShaderType,
isTransformFeedbackStage, &spvProgramInterfaceInfo,
&uniformBindingIndexMap, &mExecutable.mVariableInfoMap);
frontShaderType = shaderType;
const gl::Program *program = mState.getShaderProgram(shaderType);
ProgramVk *programVk = vk::GetImpl(program);
ProgramExecutableVk &programExecutableVk = programVk->getExecutable();
mExecutable.mDefaultUniformBlocks[shaderType] =
programExecutableVk.getSharedDefaultUniformBlock(shaderType);
mExecutable.mOriginalShaderInfo.initShaderFromProgram(
shaderType, programExecutableVk.mOriginalShaderInfo);
}
mExecutable.setAllDefaultUniformsDirty(glExecutable);
if (contextVk->getFeatures().varyingsRequireMatchingPrecisionInSpirv.enabled &&
contextVk->getFeatures().enablePrecisionQualifiers.enabled)
{
mExecutable.resolvePrecisionMismatch(mergedVaryings);
}
ANGLE_TRY(mExecutable.createPipelineLayout(contextVk, mState.getExecutable(), nullptr));
return mExecutable.warmUpPipelineCache(contextVk, mState.getExecutable());
} // namespace rx
angle::Result ProgramPipelineVk::syncState(const gl::Context *context,
const gl::Program::DirtyBits &dirtyBits)
{
ASSERT(dirtyBits.any());
// Push dirty bits to executable so that they can be used later.
mExecutable.mDirtyBits |= dirtyBits;
return angle::Result::Continue;
}
void ProgramPipelineVk::onProgramUniformUpdate(gl::ShaderType shaderType)
{
mExecutable.mDefaultUniformBlocksDirty.set(shaderType);
}
} // namespace rx