Hash :
eb0d5997
Author :
Date :
2023-09-15T16:41:13
Move set/get uniform machinery to ProgramExecutable This is done because some uniforms are internally added by the compiler (draw ID, base vertex, and base instance) and are automatically set **on the installed executable**. This change fixes scenarios where a draw is done after a program has failed a relink, and therefore is unable to correctly set the uniforms (as it does not have access to the executable that is installed). It also fixes draws that use those uniforms in a PPO. Bug: angleproject:8297 Change-Id: Id74b4984b88aa09b5b81be1c91412d6c91711136 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4864693 Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Yuxin Hu <yuxinhu@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
//
// 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.
//
// ProgramPipeline.h: Defines the gl::ProgramPipeline class.
// Implements GL program pipeline objects and related functionality.
// [OpenGL ES 3.1] section 7.4 page 105.
#ifndef LIBANGLE_PROGRAMPIPELINE_H_
#define LIBANGLE_PROGRAMPIPELINE_H_
#include <memory>
#include "common/angleutils.h"
#include "libANGLE/Debug.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramExecutable.h"
#include "libANGLE/RefCountObject.h"
namespace rx
{
class GLImplFactory;
class ProgramPipelineImpl;
} // namespace rx
namespace gl
{
class Context;
class ProgramPipeline;
class ProgramPipelineState final : angle::NonCopyable
{
public:
ProgramPipelineState(rx::GLImplFactory *factory);
~ProgramPipelineState();
const std::string &getLabel() const;
ProgramExecutable &getExecutable() const
{
ASSERT(mExecutable);
return *mExecutable;
}
const SharedProgramExecutable &getSharedExecutable() const
{
ASSERT(mExecutable);
return mExecutable;
}
void activeShaderProgram(Program *shaderProgram);
void useProgramStages(const Context *context,
const gl::ShaderBitSet &shaderTypes,
Program *shaderProgram,
std::vector<angle::ObserverBinding> *programObserverBindings,
std::vector<angle::ObserverBinding> *programExecutableObserverBindings);
Program *getActiveShaderProgram() { return mActiveShaderProgram; }
GLboolean isValid() const { return mValid; }
const Program *getShaderProgram(ShaderType shaderType) const { return mPrograms[shaderType]; }
const SharedProgramExecutable &getShaderProgramExecutable(ShaderType shaderType) const
{
return mProgramExecutables[shaderType];
}
bool usesShaderProgram(ShaderProgramID program) const;
void updateExecutableTextures();
void updateExecutableSpecConstUsageBits();
private:
void useProgramStage(const Context *context,
ShaderType shaderType,
Program *shaderProgram,
angle::ObserverBinding *programObserverBinding,
angle::ObserverBinding *programExecutableObserverBinding);
void destroyDiscardedExecutables(const Context *context);
friend class ProgramPipeline;
std::string mLabel;
// The active shader program
Program *mActiveShaderProgram;
// The shader programs for each stage.
ShaderMap<Program *> mPrograms;
// Installed executables from the programs. Note that these may be different from the programs'
// current executables, because they may have been unsuccessfully relinked.
ShaderMap<SharedProgramExecutable> mProgramExecutables;
// A list of executables to be garbage collected. This is populated as the pipeline is
// notified about program relinks, but cannot immediately destroy the old executables due to
// lack of access to context.
//
// TODO: add a test where program is bound to PPO. Then Program is linked successfully, then
// again linked unsuccessfully. Using the PPO should use the executable from the successful
// link.
//
// TODO: add a test where program is bound to PPO. Then Program is linked successfully 2x, then
// again linked unsuccessfully. Using the PPO should use the executable from the second
// successful link. This is to make sure we can support discarding an existing
std::vector<SharedProgramExecutable> mProgramExecutablesToDiscard;
GLboolean mValid;
InfoLog mInfoLog;
SharedProgramExecutable mExecutable;
bool mIsLinked;
};
class ProgramPipeline final : public RefCountObject<ProgramPipelineID>,
public LabeledObject,
public angle::ObserverInterface,
public angle::Subject
{
public:
ProgramPipeline(rx::GLImplFactory *factory, ProgramPipelineID handle);
~ProgramPipeline() override;
void onDestroy(const Context *context) override;
angle::Result setLabel(const Context *context, const std::string &label) override;
const std::string &getLabel() const override;
const ProgramPipelineState &getState() const { return mState; }
ProgramPipelineState &getState() { return mState; }
ProgramExecutable &getExecutable() const { return mState.getExecutable(); }
const SharedProgramExecutable &getSharedExecutable() const
{
return mState.getSharedExecutable();
}
rx::ProgramPipelineImpl *getImplementation() const;
Program *getActiveShaderProgram() { return mState.getActiveShaderProgram(); }
void activeShaderProgram(Program *shaderProgram);
Program *getLinkedActiveShaderProgram(const Context *context)
{
Program *program = mState.getActiveShaderProgram();
if (program)
{
program->resolveLink(context);
}
return program;
}
angle::Result useProgramStages(const Context *context,
GLbitfield stages,
Program *shaderProgram);
const Program *getShaderProgram(ShaderType shaderType) const
{
return mState.getShaderProgram(shaderType);
}
const SharedProgramExecutable &getShaderProgramExecutable(ShaderType shaderType) const
{
return mState.getShaderProgramExecutable(shaderType);
}
void resetIsLinked() { mState.mIsLinked = false; }
angle::Result link(const gl::Context *context);
InfoLog &getInfoLog() { return mState.mInfoLog; }
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
angle::Result syncState(const Context *context);
// Ensure program pipeline is linked. Inlined to make sure its overhead is as low as possible.
void resolveLink(const Context *context)
{
if (mState.mIsLinked)
{
// Already linked, nothing to do.
return;
}
resolveAttachedPrograms(context);
angle::Result linkResult = link(context);
if (linkResult != angle::Result::Continue)
{
// If the link failed then log a warning, swallow the error and move on.
WARN() << "ProgramPipeline link failed" << std::endl;
}
return;
}
void resolveAttachedPrograms(const Context *context);
void validate(const gl::Context *context);
GLboolean isValid() const { return mState.isValid(); }
bool isLinked() const { return mState.mIsLinked; }
void onUniformBufferStateChange(size_t uniformBufferIndex);
// ObserverInterface implementation.
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
private:
bool linkVaryings();
void updateLinkedShaderStages();
void updateExecutableAttributes();
void updateTransformFeedbackMembers();
void updateShaderStorageBlocks();
void updateImageBindings();
void updateExecutableGeometryProperties();
void updateExecutableTessellationProperties();
void updateFragmentInoutRangeAndEnablesPerSampleShading();
void updateLinkedVaryings();
void updateExecutable();
std::unique_ptr<rx::ProgramPipelineImpl> mProgramPipelineImpl;
ProgramPipelineState mState;
std::vector<angle::ObserverBinding> mProgramObserverBindings;
std::vector<angle::ObserverBinding> mProgramExecutableObserverBindings;
angle::ObserverBinding mExecutableObserverBinding;
};
} // namespace gl
#endif // LIBANGLE_PROGRAMPIPELINE_H_