Commit 901aa3fa by Geoff Lang Committed by Commit Bot

GL: Refactor BlitGL program types into tuples of enums.

Previously we expanded out all the program variations into individual enums but as we add more variations this becomes hard to maintain. Generate the BlitGL program based on the individual parameter instead. BUG=990368 Change-Id: I94fd5132baa5b6828aec7823ca5d9f0ffe94379f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1834581Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 1d02157e
...@@ -307,7 +307,7 @@ angle::Result BlitGL::copySubImageToLUMAWorkaroundTexture(const gl::Context *con ...@@ -307,7 +307,7 @@ angle::Result BlitGL::copySubImageToLUMAWorkaroundTexture(const gl::Context *con
ANGLE_TRY(initializeResources(context)); ANGLE_TRY(initializeResources(context));
BlitProgram *blitProgram = nullptr; BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, BlitProgramType::FLOAT_TO_FLOAT, &blitProgram)); ANGLE_TRY(getBlitProgram(context, gl::TextureType::_2D, GL_FLOAT, GL_FLOAT, &blitProgram));
// Blit the framebuffer to the first scratch texture // Blit the framebuffer to the first scratch texture
const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source); const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source);
...@@ -408,7 +408,7 @@ angle::Result BlitGL::blitColorBufferWithShader(const gl::Context *context, ...@@ -408,7 +408,7 @@ angle::Result BlitGL::blitColorBufferWithShader(const gl::Context *context,
ANGLE_TRY(initializeResources(context)); ANGLE_TRY(initializeResources(context));
BlitProgram *blitProgram = nullptr; BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, BlitProgramType::FLOAT_TO_FLOAT, &blitProgram)); ANGLE_TRY(getBlitProgram(context, gl::TextureType::_2D, GL_FLOAT, GL_FLOAT, &blitProgram));
// We'll keep things simple by removing reversed coordinates from the rectangles. In the end // We'll keep things simple by removing reversed coordinates from the rectangles. In the end
// we'll apply the reversal to the source texture coordinates if needed. The destination // we'll apply the reversal to the source texture coordinates if needed. The destination
...@@ -550,10 +550,9 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context, ...@@ -550,10 +550,9 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
BlitProgramType blitProgramType =
getBlitProgramType(source->getType(), sourceComponentType, destComponentType);
BlitProgram *blitProgram = nullptr; BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, blitProgramType, &blitProgram)); ANGLE_TRY(getBlitProgram(context, source->getType(), sourceComponentType, destComponentType,
&blitProgram));
// Setup the source texture // Setup the source texture
if (needsLumaWorkaround) if (needsLumaWorkaround)
...@@ -1068,40 +1067,15 @@ angle::Result BlitGL::setScratchTextureParameter(const gl::Context *context, ...@@ -1068,40 +1067,15 @@ angle::Result BlitGL::setScratchTextureParameter(const gl::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
BlitGL::BlitProgramType BlitGL::getBlitProgramType(gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType)
{
if (sourceComponentType == GL_UNSIGNED_INT)
{
ASSERT(destComponentType == GL_UNSIGNED_INT);
return BlitProgramType::UINT_TO_UINT;
}
else
{
// Source is a float type
ASSERT(sourceComponentType != GL_INT);
if (destComponentType == GL_UNSIGNED_INT)
{
return sourceTextureType == gl::TextureType::External
? BlitProgramType::FLOAT_TO_UINT_EXTERNAL
: BlitProgramType::FLOAT_TO_UINT;
}
else
{
// Dest is a float type
return sourceTextureType == gl::TextureType::External
? BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL
: BlitProgramType::FLOAT_TO_FLOAT;
}
}
}
angle::Result BlitGL::getBlitProgram(const gl::Context *context, angle::Result BlitGL::getBlitProgram(const gl::Context *context,
BlitProgramType type, gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType,
BlitProgram **program) BlitProgram **program)
{ {
BlitProgram &result = mBlitPrograms[type];
BlitProgramType programType(sourceTextureType, sourceComponentType, destComponentType);
BlitProgram &result = mBlitPrograms[programType];
if (result.program == 0) if (result.program == 0)
{ {
result.program = ANGLE_GL_TRY(context, mFunctions->createProgram()); result.program = ANGLE_GL_TRY(context, mFunctions->createProgram());
...@@ -1114,9 +1088,11 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1114,9 +1088,11 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
std::string fsInputVariableQualifier; std::string fsInputVariableQualifier;
std::string fsOutputVariableQualifier; std::string fsOutputVariableQualifier;
std::string sampleFunction; std::string sampleFunction;
if (type == BlitProgramType::FLOAT_TO_FLOAT || if (sourceComponentType != GL_UNSIGNED_INT && destComponentType != GL_UNSIGNED_INT &&
type == BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL) (sourceTextureType == gl::TextureType::_2D ||
sourceTextureType == gl::TextureType::External))
{ {
// Simple case, float-to-float with 2D or external textures. Only needs ESSL/GLSL 100
version = "100"; version = "100";
vsInputVariableQualifier = "attribute"; vsInputVariableQualifier = "attribute";
vsOutputVariableQualifier = "varying"; vsOutputVariableQualifier = "varying";
...@@ -1173,30 +1149,51 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1173,30 +1149,51 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
{ {
// Sampling texture uniform changes depending on source texture type. // Sampling texture uniform changes depending on source texture type.
std::string samplerType; std::string samplerType;
std::string samplerResultType; switch (sourceTextureType)
std::string extensionRequirements;
switch (type)
{ {
case BlitProgramType::FLOAT_TO_FLOAT: case gl::TextureType::_2D:
case BlitProgramType::FLOAT_TO_UINT: switch (sourceComponentType)
samplerType = "sampler2D"; {
samplerResultType = "vec4"; case GL_UNSIGNED_INT:
samplerType = "usampler2D";
break;
default: // Float type
samplerType = "sampler2D";
break;
}
break; break;
case BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL: case gl::TextureType::External:
case BlitProgramType::FLOAT_TO_UINT_EXTERNAL: ASSERT(sourceComponentType != GL_UNSIGNED_INT);
samplerType = "samplerExternalOES"; samplerType = "samplerExternalOES";
samplerResultType = "vec4"; break;
extensionRequirements = "#extension GL_OES_EGL_image_external : require";
default:
UNREACHABLE();
break; break;
}
case BlitProgramType::UINT_TO_UINT: std::string samplerResultType;
samplerType = "usampler2D"; switch (sourceComponentType)
{
case GL_UNSIGNED_INT:
samplerResultType = "uvec4"; samplerResultType = "uvec4";
break; break;
default: // Float type
samplerResultType = "vec4";
break;
}
std::string extensionRequirements;
switch (sourceTextureType)
{
case gl::TextureType::External:
extensionRequirements = "#extension GL_OES_EGL_image_external : require";
break;
default: default:
UNREACHABLE();
break; break;
} }
...@@ -1204,26 +1201,19 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1204,26 +1201,19 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
std::string outputType; std::string outputType;
std::string outputVariableName; std::string outputVariableName;
std::string outputMultiplier; std::string outputMultiplier;
switch (type) switch (destComponentType)
{ {
case BlitProgramType::FLOAT_TO_FLOAT: case GL_UNSIGNED_INT:
case BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL:
ASSERT(version == "100");
outputType = "";
outputVariableName = "gl_FragColor";
outputMultiplier = "1.0";
break;
case BlitProgramType::FLOAT_TO_UINT:
case BlitProgramType::FLOAT_TO_UINT_EXTERNAL:
case BlitProgramType::UINT_TO_UINT:
outputType = "uvec4"; outputType = "uvec4";
outputVariableName = "outputUint"; outputVariableName = "outputUint";
outputMultiplier = "255.0"; outputMultiplier = "255.0";
break; break;
default: default: // float type
UNREACHABLE(); ASSERT(version == "100");
outputType = "";
outputVariableName = "gl_FragColor";
outputMultiplier = "1.0";
break; break;
} }
......
...@@ -157,22 +157,14 @@ class BlitGL : angle::NonCopyable ...@@ -157,22 +157,14 @@ class BlitGL : angle::NonCopyable
GLint unMultiplyAlphaLocation = -1; GLint unMultiplyAlphaLocation = -1;
}; };
enum class BlitProgramType
{
FLOAT_TO_FLOAT,
FLOAT_TO_FLOAT_EXTERNAL,
FLOAT_TO_UINT,
FLOAT_TO_UINT_EXTERNAL,
UINT_TO_UINT,
};
static BlitProgramType getBlitProgramType(gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType);
angle::Result getBlitProgram(const gl::Context *context, angle::Result getBlitProgram(const gl::Context *context,
BlitProgramType type, gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType,
BlitProgram **program); BlitProgram **program);
// SourceType, SourceComponentType, DestComponentType
using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
std::map<BlitProgramType, BlitProgram> mBlitPrograms; std::map<BlitProgramType, BlitProgram> mBlitPrograms;
GLuint mScratchTextures[2]; GLuint mScratchTextures[2];
......
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