Hash :
7b0bb0f6
Author :
Date :
2023-09-01T13:52:28
Properly "install" program executables
According to GL:
- The program has an executable
- The executable is overwritten during link.
- After a failed link, queries of the executable may return
half-linked information
- On glUseProgram, the executable is installed in the context
- On glUseProgramStages, the executable is installed in the program
pipeline
- After a successful link, the executable is updated wherever the
previous executable of the program was installed.
This change implements exactly the above:
- The program's and the program pipeline's executables are now
shared_ptr. References to an executable in the context and PPO are
also through a shared_ptr. Installing an executable thus translates
to sharing the executable.
- The context and PPOs are made to not reference the program directly,
but work solely through the executable. As a result, the program is
free to create a new executable for link.
With this change, the link job will be free to modify the executable as
necessary because that will not be accessed until the link is done.
Note that previous changes made the backend executable accessed through
the frontend one, and moved all link results to the frontend and backend
executables as appropriate.
Bug: angleproject:6358
Bug: angleproject:8297
Change-Id: Ie636b23ff7420ad284d18b525ec4f5fb559dd9d1
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4823089
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: 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 122 123 124 125 126
//
// 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)
{
getExecutable()->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();
ProgramExecutableVk *executableVk = vk::GetImpl(&glExecutable);
SpvSourceOptions options = SpvCreateSourceOptions(contextVk->getFeatures());
SpvProgramInterfaceInfo spvProgramInterfaceInfo = {};
reset(contextVk);
executableVk->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::SharedProgramExecutable &glShaderExecutable =
mState.getShaderProgramExecutable(shaderType);
if (glShaderExecutable && gl::ShaderTypeSupportsTransformFeedback(shaderType))
{
const bool isTransformFeedbackStage =
shaderType == linkedTransformFeedbackStage &&
!glShaderExecutable->getLinkedTransformFeedbackVaryings().empty();
SpvAssignTransformFeedbackLocations(
shaderType, *glShaderExecutable.get(), isTransformFeedbackStage,
&spvProgramInterfaceInfo, &executableVk->mVariableInfoMap);
}
}
}
executableVk->mOriginalShaderInfo.clear();
SpvAssignLocations(options, glExecutable, varyingPacking, linkedTransformFeedbackStage,
&spvProgramInterfaceInfo, &executableVk->mVariableInfoMap);
for (const gl::ShaderType shaderType : glExecutable.getLinkedShaderStages())
{
const gl::SharedProgramExecutable &glShaderExecutable =
mState.getShaderProgramExecutable(shaderType);
ProgramExecutableVk *programExecutableVk = vk::GetImpl(glShaderExecutable.get());
executableVk->mDefaultUniformBlocks[shaderType] =
programExecutableVk->getSharedDefaultUniformBlock(shaderType);
executableVk->mOriginalShaderInfo.initShaderFromProgram(
shaderType, programExecutableVk->mOriginalShaderInfo);
}
executableVk->setAllDefaultUniformsDirty();
if (contextVk->getFeatures().varyingsRequireMatchingPrecisionInSpirv.enabled &&
contextVk->getFeatures().enablePrecisionQualifiers.enabled)
{
executableVk->resolvePrecisionMismatch(mergedVaryings);
}
executableVk->resetLayout(contextVk);
ANGLE_TRY(executableVk->createPipelineLayout(contextVk, &contextVk->getPipelineLayoutCache(),
&contextVk->getDescriptorSetLayoutCache(),
nullptr));
ANGLE_TRY(executableVk->initializeDescriptorPools(contextVk,
&contextVk->getDescriptorSetLayoutCache(),
&contextVk->getMetaDescriptorPools()));
vk::RenderPass temporaryCompatibleRenderPass;
angle::Result result = executableVk->warmUpPipelineCache(
contextVk, contextVk->pipelineRobustness(), contextVk->pipelineProtectedAccess(),
&temporaryCompatibleRenderPass);
temporaryCompatibleRenderPass.destroy(contextVk->getDevice());
return result;
} // 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.
getExecutable()->mDirtyBits |= dirtyBits;
return angle::Result::Continue;
}
void ProgramPipelineVk::onProgramUniformUpdate(gl::ShaderType shaderType)
{
getExecutable()->mDefaultUniformBlocksDirty.set(shaderType);
}
} // namespace rx