Commit d9669322 by Jamie Madill Committed by Commit Bot

Remove "init" from VaryingPacking.

Instead we can pass the pack mode and size to the collectAndPack method. This cleans up the interface and also allows us to merge two separate code blocks in Program and ProgramPipeline. Bug: angleproject:5496 Change-Id: I390b5d2e8a3b033374ccc5a250597be1f03dec96 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2606531 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent d33ffb22
......@@ -1513,8 +1513,22 @@ bool Program::linkMergedVaryings(const Context *context,
return false;
}
// Map the varyings to the register file
// In WebGL, we use a slightly different handling for packing variables.
gl::PackMode packMode = PackMode::ANGLE_RELAXED;
if (context->getLimitations().noFlexibleVaryingPacking)
{
// D3D9 pack mode is strictly more strict than WebGL, so takes priority.
packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9;
}
else if (context->getExtensions().webglCompatibility)
{
packMode = PackMode::WEBGL_STRICT;
}
if (!varyingPacking->collectAndPackUserVaryings(
infoLog, mergedVaryings, mState.getTransformFeedbackVaryingNames(), isSeparable()))
infoLog, context->getCaps().maxVaryingVectors, packMode, mergedVaryings,
mState.getTransformFeedbackVaryingNames(), isSeparable()))
{
return false;
}
......@@ -1547,7 +1561,6 @@ angle::Result Program::linkImpl(const Context *context)
ASSERT(!mLinkingState);
// Don't make any local variables pointing to anything within the ProgramExecutable, since
// unlink() could make a new ProgramExecutable making any references/pointers invalid.
const auto &data = context->getState();
auto *platform = ANGLEPlatformCurrent();
double startTime = platform->currentTime(platform);
......@@ -1599,7 +1612,6 @@ angle::Result Program::linkImpl(const Context *context)
if (mState.mAttachedShaders[ShaderType::Compute])
{
resources.varyingPacking.init(0, PackMode::ANGLE_RELAXED);
resources.init(&mState.mExecutable->mUniformBlocks, &mState.mExecutable->mUniforms,
&mState.mExecutable->mComputeShaderStorageBlocks, &mState.mBufferVariables,
&mState.mExecutable->mAtomicCounterBuffers);
......@@ -1641,21 +1653,6 @@ angle::Result Program::linkImpl(const Context *context)
}
else
{
// Map the varyings to the register file
// In WebGL, we use a slightly different handling for packing variables.
gl::PackMode packMode = PackMode::ANGLE_RELAXED;
if (data.getLimitations().noFlexibleVaryingPacking)
{
// D3D9 pack mode is strictly more strict than WebGL, so takes priority.
packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9;
}
else if (data.getExtensions().webglCompatibility)
{
packMode = PackMode::WEBGL_STRICT;
}
resources.varyingPacking.init(static_cast<GLuint>(data.getCaps().maxVaryingVectors),
packMode);
resources.init(&mState.mExecutable->mUniformBlocks, &mState.mExecutable->mUniforms,
&mState.mExecutable->mGraphicsShaderStorageBlocks, &mState.mBufferVariables,
&mState.mExecutable->mAtomicCounterBuffers);
......
......@@ -543,20 +543,6 @@ angle::Result ProgramPipeline::link(const Context *context)
{
InfoLog &infoLog = mState.mExecutable->getInfoLog();
infoLog.reset();
const State &state = context->getState();
// Map the varyings to the register file
gl::PackMode packMode = PackMode::ANGLE_RELAXED;
if (state.getLimitations().noFlexibleVaryingPacking)
{
// D3D9 pack mode is strictly more strict than WebGL, so takes priority.
packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9;
}
else if (state.getExtensions().webglCompatibility)
{
// In WebGL, we use a slightly different handling for packing variables.
packMode = PackMode::WEBGL_STRICT;
}
if (!linkVaryings(infoLog))
{
......@@ -570,10 +556,6 @@ angle::Result ProgramPipeline::link(const Context *context)
return angle::Result::Stop;
}
GLuint maxVaryingVectors =
static_cast<GLuint>(context->getState().getCaps().maxVaryingVectors);
varyingPacking.init(maxVaryingVectors, packMode);
mergedVaryings = getMergedVaryings();
for (ShaderType shaderType : getExecutable().getLinkedShaderStages())
{
......@@ -585,10 +567,6 @@ angle::Result ProgramPipeline::link(const Context *context)
}
}
}
else
{
varyingPacking.init(0, gl::PackMode::ANGLE_RELAXED);
}
ANGLE_TRY(getImplementation()->link(context, mergedVaryings, varyingPacking));
......
......@@ -171,12 +171,6 @@ VaryingPacking::VaryingPacking() = default;
VaryingPacking::~VaryingPacking() = default;
void VaryingPacking::init(GLuint maxVaryingVectors, PackMode packMode)
{
mRegisterMap.resize(maxVaryingVectors);
mPackMode = packMode;
}
void VaryingPacking::reset()
{
clearRegisterMap();
......@@ -203,7 +197,8 @@ void VaryingPacking::clearRegisterMap()
// See [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
// Also [OpenGL ES Shading Language 3.00 rev. 4] Section 11 page 119
// Returns false if unsuccessful.
bool VaryingPacking::packVaryingIntoRegisterMap(const PackedVarying &packedVarying)
bool VaryingPacking::packVaryingIntoRegisterMap(PackMode packMode,
const PackedVarying &packedVarying)
{
const sh::ShaderVariable &varying = packedVarying.varying();
......@@ -218,14 +213,14 @@ bool VaryingPacking::packVaryingIntoRegisterMap(const PackedVarying &packedVaryi
// Special pack mode for D3D9. Each varying takes a full register, no sharing.
// TODO(jmadill): Implement more sophisticated component packing in D3D9.
if (mPackMode == PackMode::ANGLE_NON_CONFORMANT_D3D9)
if (packMode == PackMode::ANGLE_NON_CONFORMANT_D3D9)
{
varyingColumns = 4;
}
// "Variables of type mat2 occupies 2 complete rows."
// For non-WebGL contexts, we allow mat2 to occupy only two columns per row.
else if (mPackMode == PackMode::WEBGL_STRICT && varying.type == GL_FLOAT_MAT2)
else if (packMode == PackMode::WEBGL_STRICT && varying.type == GL_FLOAT_MAT2)
{
varyingColumns = 4;
}
......@@ -701,6 +696,8 @@ void VaryingPacking::collectTFVarying(const std::string &tfVarying,
}
bool VaryingPacking::collectAndPackUserVaryings(gl::InfoLog &infoLog,
GLint maxVaryingVectors,
PackMode packMode,
const ProgramMergedVaryings &mergedVaryings,
const std::vector<std::string> &tfVaryings,
const bool isSeparableProgram)
......@@ -738,7 +735,7 @@ bool VaryingPacking::collectAndPackUserVaryings(gl::InfoLog &infoLog,
// Don't count gl_Position. Also don't count gl_PointSize for D3D9.
if (varying->name != "gl_Position" &&
!(varying->name == "gl_PointSize" &&
mPackMode == PackMode::ANGLE_NON_CONFORMANT_D3D9))
packMode == PackMode::ANGLE_NON_CONFORMANT_D3D9))
{
collectVarying(*varying, ref, &uniqueFullNames);
continue;
......@@ -776,18 +773,23 @@ bool VaryingPacking::collectAndPackUserVaryings(gl::InfoLog &infoLog,
std::sort(mPackedVaryings.begin(), mPackedVaryings.end(), ComparePackedVarying);
return packUserVaryings(infoLog, mPackedVaryings);
return packUserVaryings(infoLog, maxVaryingVectors, packMode, mPackedVaryings);
}
// See comment on packVarying.
bool VaryingPacking::packUserVaryings(gl::InfoLog &infoLog,
GLint maxVaryingVectors,
PackMode packMode,
const std::vector<PackedVarying> &packedVaryings)
{
clearRegisterMap();
mRegisterMap.resize(maxVaryingVectors);
// "Variables are packed into the registers one at a time so that they each occupy a contiguous
// subrectangle. No splitting of variables is permitted."
for (const PackedVarying &packedVarying : packedVaryings)
{
if (!packVaryingIntoRegisterMap(packedVarying))
if (!packVaryingIntoRegisterMap(packMode, packedVarying))
{
ShaderType eitherStage = packedVarying.frontVarying.varying
? packedVarying.frontVarying.stage
......@@ -795,7 +797,7 @@ bool VaryingPacking::packUserVaryings(gl::InfoLog &infoLog,
infoLog << "Could not pack varying " << packedVarying.fullName(eitherStage);
// TODO(jmadill): Implement more sophisticated component packing in D3D9.
if (mPackMode == PackMode::ANGLE_NON_CONFORMANT_D3D9)
if (packMode == PackMode::ANGLE_NON_CONFORMANT_D3D9)
{
infoLog << "Note: Additional non-conformant packing restrictions are enforced on "
"D3D9.";
......
......@@ -205,9 +205,9 @@ class VaryingPacking final : angle::NonCopyable
VaryingPacking();
~VaryingPacking();
void init(GLuint maxVaryingVectors, PackMode packMode);
bool collectAndPackUserVaryings(gl::InfoLog &infoLog,
bool collectAndPackUserVaryings(InfoLog &infoLog,
GLint maxVaryingVectors,
PackMode packMode,
const ProgramMergedVaryings &mergedVaryings,
const std::vector<std::string> &tfVaryings,
const bool isSeparableProgram);
......@@ -247,8 +247,11 @@ class VaryingPacking final : angle::NonCopyable
using VaryingUniqueFullNames = ShaderMap<std::set<std::string>>;
// Register map functions.
bool packUserVaryings(gl::InfoLog &infoLog, const std::vector<PackedVarying> &packedVaryings);
bool packVaryingIntoRegisterMap(const PackedVarying &packedVarying);
bool packUserVaryings(InfoLog &infoLog,
GLint maxVaryingVectors,
PackMode packMode,
const std::vector<PackedVarying> &packedVaryings);
bool packVaryingIntoRegisterMap(PackMode packMode, const PackedVarying &packedVarying);
bool isRegisterRangeFree(unsigned int registerRow,
unsigned int registerColumn,
unsigned int varyingRows,
......@@ -282,8 +285,6 @@ class VaryingPacking final : angle::NonCopyable
std::vector<PackedVarying> mPackedVaryings;
ShaderMap<std::vector<std::string>> mInactiveVaryingMappedNames;
ShaderMap<std::vector<std::string>> mActiveOutputBuiltIns;
PackMode mPackMode = PackMode::ANGLE_RELAXED;
};
} // namespace gl
......
......@@ -26,8 +26,9 @@ class VaryingPackingTest : public ::testing::TestWithParam<GLuint>
protected:
VaryingPackingTest() {}
bool testVaryingPacking(const std::vector<sh::ShaderVariable> &shVaryings,
VaryingPacking *varyingPacking)
bool testVaryingPacking(GLint maxVaryings,
PackMode packMode,
const std::vector<sh::ShaderVariable> &shVaryings)
{
ProgramMergedVaryings mergedVaryings;
for (const sh::ShaderVariable &shVarying : shVaryings)
......@@ -43,24 +44,21 @@ class VaryingPackingTest : public ::testing::TestWithParam<GLuint>
InfoLog infoLog;
std::vector<std::string> transformFeedbackVaryings;
return varyingPacking->collectAndPackUserVaryings(infoLog, mergedVaryings,
transformFeedbackVaryings, false);
VaryingPacking varyingPacking;
return varyingPacking.collectAndPackUserVaryings(
infoLog, maxVaryings, packMode, mergedVaryings, transformFeedbackVaryings, false);
}
// Uses the "relaxed" ANGLE packing mode.
bool packVaryings(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
bool packVaryings(GLint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
{
VaryingPacking varyingPacking;
varyingPacking.init(maxVaryings, PackMode::ANGLE_RELAXED);
return testVaryingPacking(shVaryings, &varyingPacking);
return testVaryingPacking(maxVaryings, PackMode::ANGLE_RELAXED, shVaryings);
}
// Uses the stricter WebGL style packing rules.
bool packVaryingsStrict(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
bool packVaryingsStrict(GLint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
{
VaryingPacking varyingPacking;
varyingPacking.init(maxVaryings, PackMode::WEBGL_STRICT);
return testVaryingPacking(shVaryings, &varyingPacking);
return testVaryingPacking(maxVaryings, PackMode::WEBGL_STRICT, shVaryings);
}
const int kMaxVaryings = GetParam();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment