Commit 8a561914 by Jamie Madill Committed by Commit Bot

Pack SamplerState into small struct.

Is much faster for completeness cache checks in syncProgramTextures. Bug: angleproject:2763 Change-Id: Iffdacbb8a4f6640caa5051643c379a7b4c3311b6 Reviewed-on: https://chromium-review.googlesource.com/1171508 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 097d3c0c
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
"packed enum:src/common/packed_egl_enums.json": "packed enum:src/common/packed_egl_enums.json":
"0389a8a565ccee99163bd0cf3ca146d3", "0389a8a565ccee99163bd0cf3ca146d3",
"packed enum:src/common/packed_gl_enums.json": "packed enum:src/common/packed_gl_enums.json":
"d8112f980e13ebaed3a888325563e632", "feddad35f1d497399a5cac85fe2ca352",
"proc table:src/libGLESv2/gen_proc_table.py": "proc table:src/libGLESv2/gen_proc_table.py":
"027bfd5a8a8dffe91f492bf199029cde", "027bfd5a8a8dffe91f492bf199029cde",
"proc table:src/libGLESv2/proc_table_data.json": "proc table:src/libGLESv2/proc_table_data.json":
......
...@@ -264,6 +264,46 @@ GLenum ToGLenum(CullFaceMode from) ...@@ -264,6 +264,46 @@ GLenum ToGLenum(CullFaceMode from)
} }
template <> template <>
FilterMode FromGLenum<FilterMode>(GLenum from)
{
switch (from)
{
case GL_NEAREST:
return FilterMode::Nearest;
case GL_LINEAR:
return FilterMode::Linear;
case GL_NEAREST_MIPMAP_NEAREST:
return FilterMode::NearestMipmapNearest;
case GL_NEAREST_MIPMAP_LINEAR:
return FilterMode::NearestMipmapLinear;
case GL_LINEAR_MIPMAP_LINEAR:
return FilterMode::LinearMipmapLinear;
default:
return FilterMode::InvalidEnum;
}
}
GLenum ToGLenum(FilterMode from)
{
switch (from)
{
case FilterMode::Nearest:
return GL_NEAREST;
case FilterMode::Linear:
return GL_LINEAR;
case FilterMode::NearestMipmapNearest:
return GL_NEAREST_MIPMAP_NEAREST;
case FilterMode::NearestMipmapLinear:
return GL_NEAREST_MIPMAP_LINEAR;
case FilterMode::LinearMipmapLinear:
return GL_LINEAR_MIPMAP_LINEAR;
default:
UNREACHABLE();
return 0;
}
}
template <>
FogMode FromGLenum<FogMode>(GLenum from) FogMode FromGLenum<FogMode>(GLenum from)
{ {
switch (from) switch (from)
...@@ -1219,4 +1259,36 @@ GLenum ToGLenum(VertexArrayType from) ...@@ -1219,4 +1259,36 @@ GLenum ToGLenum(VertexArrayType from)
} }
} }
template <>
WrapMode FromGLenum<WrapMode>(GLenum from)
{
switch (from)
{
case GL_CLAMP_TO_EDGE:
return WrapMode::ClampToEdge;
case GL_MIRRORED_REPEAT:
return WrapMode::MirroredRepeat;
case GL_REPEAT:
return WrapMode::Repeat;
default:
return WrapMode::InvalidEnum;
}
}
GLenum ToGLenum(WrapMode from)
{
switch (from)
{
case WrapMode::ClampToEdge:
return GL_CLAMP_TO_EDGE;
case WrapMode::MirroredRepeat:
return GL_MIRRORED_REPEAT;
case WrapMode::Repeat:
return GL_REPEAT;
default:
UNREACHABLE();
return 0;
}
}
} // namespace gl } // namespace gl
...@@ -116,6 +116,22 @@ template <> ...@@ -116,6 +116,22 @@ template <>
CullFaceMode FromGLenum<CullFaceMode>(GLenum from); CullFaceMode FromGLenum<CullFaceMode>(GLenum from);
GLenum ToGLenum(CullFaceMode from); GLenum ToGLenum(CullFaceMode from);
enum class FilterMode : uint8_t
{
Nearest = 0,
Linear = 1,
NearestMipmapNearest = 2,
NearestMipmapLinear = 3,
LinearMipmapLinear = 4,
InvalidEnum = 5,
EnumCount = 5,
};
template <>
FilterMode FromGLenum<FilterMode>(GLenum from);
GLenum ToGLenum(FilterMode from);
enum class FogMode : uint8_t enum class FogMode : uint8_t
{ {
Exp = 0, Exp = 0,
...@@ -475,6 +491,20 @@ template <> ...@@ -475,6 +491,20 @@ template <>
VertexArrayType FromGLenum<VertexArrayType>(GLenum from); VertexArrayType FromGLenum<VertexArrayType>(GLenum from);
GLenum ToGLenum(VertexArrayType from); GLenum ToGLenum(VertexArrayType from);
enum class WrapMode : uint8_t
{
ClampToEdge = 0,
MirroredRepeat = 1,
Repeat = 2,
InvalidEnum = 3,
EnumCount = 3,
};
template <>
WrapMode FromGLenum<WrapMode>(GLenum from);
GLenum ToGLenum(WrapMode from);
} // namespace gl } // namespace gl
#endif // COMMON_PACKEDGLENUMS_AUTOGEN_H_ #endif // COMMON_PACKEDGLENUMS_AUTOGEN_H_
...@@ -249,5 +249,19 @@ ...@@ -249,5 +249,19 @@
"PointSizeMax" : "GL_POINT_SIZE_MAX", "PointSizeMax" : "GL_POINT_SIZE_MAX",
"PointFadeThresholdSize" : "GL_POINT_FADE_THRESHOLD_SIZE", "PointFadeThresholdSize" : "GL_POINT_FADE_THRESHOLD_SIZE",
"PointDistanceAttenuation" : "GL_POINT_DISTANCE_ATTENUATION" "PointDistanceAttenuation" : "GL_POINT_DISTANCE_ATTENUATION"
},
"FilterMode":
{
"Nearest": "GL_NEAREST",
"Linear": "GL_LINEAR",
"NearestMipmapNearest": "GL_NEAREST_MIPMAP_NEAREST",
"NearestMipmapLinear": "GL_NEAREST_MIPMAP_LINEAR",
"LinearMipmapLinear": "GL_LINEAR_MIPMAP_LINEAR"
},
"WrapMode":
{
"ClampToEdge": "GL_CLAMP_TO_EDGE",
"MirroredRepeat": "GL_MIRRORED_REPEAT",
"Repeat": "GL_REPEAT"
} }
} }
...@@ -628,11 +628,6 @@ const std::string &Texture::getLabel() const ...@@ -628,11 +628,6 @@ const std::string &Texture::getLabel() const
return mLabel; return mLabel;
} }
TextureType Texture::getType() const
{
return mState.mType;
}
void Texture::setSwizzleRed(GLenum swizzleRed) void Texture::setSwizzleRed(GLenum swizzleRed)
{ {
mState.mSwizzleState.swizzleRed = swizzleRed; mState.mSwizzleState.swizzleRed = swizzleRed;
...@@ -1537,7 +1532,7 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS ...@@ -1537,7 +1532,7 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS
const auto &contextState = context->getContextState(); const auto &contextState = context->getContextState();
if (contextState.getContextID() != mCompletenessCache.context || if (contextState.getContextID() != mCompletenessCache.context ||
mCompletenessCache.samplerState != samplerState) !mCompletenessCache.samplerState.sameCompleteness(samplerState))
{ {
mCompletenessCache.context = context->getContextState().getContextID(); mCompletenessCache.context = context->getContextState().getContextID();
mCompletenessCache.samplerState = samplerState; mCompletenessCache.samplerState = samplerState;
......
...@@ -198,7 +198,7 @@ class Texture final : public RefCountObject, public egl::ImageSibling, public La ...@@ -198,7 +198,7 @@ class Texture final : public RefCountObject, public egl::ImageSibling, public La
void setLabel(const std::string &label) override; void setLabel(const std::string &label) override;
const std::string &getLabel() const override; const std::string &getLabel() const override;
TextureType getType() const; TextureType getType() const { return mState.mType; }
void setSwizzleRed(GLenum swizzleRed); void setSwizzleRed(GLenum swizzleRed);
GLenum getSwizzleRed() const; GLenum getSwizzleRed() const;
......
...@@ -110,17 +110,17 @@ SamplerState::SamplerState() ...@@ -110,17 +110,17 @@ SamplerState::SamplerState()
{ {
memset(this, 0, sizeof(SamplerState)); memset(this, 0, sizeof(SamplerState));
mMinFilter = GL_NEAREST_MIPMAP_LINEAR; setMinFilter(GL_NEAREST_MIPMAP_LINEAR);
mMagFilter = GL_LINEAR; setMagFilter(GL_LINEAR);
mWrapS = GL_REPEAT; setWrapS(GL_REPEAT);
mWrapT = GL_REPEAT; setWrapT(GL_REPEAT);
mWrapR = GL_REPEAT; setWrapR(GL_REPEAT);
mMaxAnisotropy = 1.0f; setMaxAnisotropy(1.0f);
mMinLod = -1000.0f; setMinLod(-1000.0f);
mMaxLod = 1000.0f; setMaxLod(1000.0f);
mCompareMode = GL_NONE; setCompareMode(GL_NONE);
mCompareFunc = GL_LEQUAL; setCompareFunc(GL_LEQUAL);
mSRGBDecode = GL_DECODE_EXT; setSRGBDecode(GL_DECODE_EXT);
} }
SamplerState::SamplerState(const SamplerState &other) = default; SamplerState::SamplerState(const SamplerState &other) = default;
...@@ -144,22 +144,26 @@ SamplerState SamplerState::CreateDefaultForTarget(TextureType type) ...@@ -144,22 +144,26 @@ SamplerState SamplerState::CreateDefaultForTarget(TextureType type)
void SamplerState::setMinFilter(GLenum minFilter) void SamplerState::setMinFilter(GLenum minFilter)
{ {
mMinFilter = minFilter; mMinFilter = minFilter;
mCompleteness.typed.minFilter = static_cast<uint8_t>(FromGLenum<FilterMode>(minFilter));
} }
void SamplerState::setMagFilter(GLenum magFilter) void SamplerState::setMagFilter(GLenum magFilter)
{ {
mMagFilter = magFilter; mMagFilter = magFilter;
mCompleteness.typed.magFilter = static_cast<uint8_t>(FromGLenum<FilterMode>(magFilter));
} }
void SamplerState::setWrapS(GLenum wrapS) void SamplerState::setWrapS(GLenum wrapS)
{ {
mWrapS = wrapS; mWrapS = wrapS;
mCompleteness.typed.wrapS = static_cast<uint8_t>(FromGLenum<WrapMode>(wrapS));
} }
void SamplerState::setWrapT(GLenum wrapT) void SamplerState::setWrapT(GLenum wrapT)
{ {
mWrapT = wrapT; mWrapT = wrapT;
updateWrapTCompareMode();
} }
void SamplerState::setWrapR(GLenum wrapR) void SamplerState::setWrapR(GLenum wrapR)
...@@ -185,6 +189,7 @@ void SamplerState::setMaxLod(GLfloat maxLod) ...@@ -185,6 +189,7 @@ void SamplerState::setMaxLod(GLfloat maxLod)
void SamplerState::setCompareMode(GLenum compareMode) void SamplerState::setCompareMode(GLenum compareMode)
{ {
mCompareMode = compareMode; mCompareMode = compareMode;
updateWrapTCompareMode();
} }
void SamplerState::setCompareFunc(GLenum compareFunc) void SamplerState::setCompareFunc(GLenum compareFunc)
...@@ -197,6 +202,13 @@ void SamplerState::setSRGBDecode(GLenum sRGBDecode) ...@@ -197,6 +202,13 @@ void SamplerState::setSRGBDecode(GLenum sRGBDecode)
mSRGBDecode = sRGBDecode; mSRGBDecode = sRGBDecode;
} }
void SamplerState::updateWrapTCompareMode()
{
uint8_t wrap = static_cast<uint8_t>(FromGLenum<WrapMode>(mWrapT));
uint8_t compare = static_cast<uint8_t>(mCompareMode == GL_NONE ? 0x10 : 0x00);
mCompleteness.typed.wrapTCompareMode = wrap | compare;
}
ImageUnit::ImageUnit() ImageUnit::ImageUnit()
: texture(), level(0), layered(false), layer(0), access(GL_READ_ONLY), format(GL_R32UI) : texture(), level(0), layered(false), layer(0), access(GL_READ_ONLY), format(GL_R32UI)
{ {
......
...@@ -195,6 +195,29 @@ struct DepthStencilState final ...@@ -195,6 +195,29 @@ struct DepthStencilState final
bool operator==(const DepthStencilState &a, const DepthStencilState &b); bool operator==(const DepthStencilState &a, const DepthStencilState &b);
bool operator!=(const DepthStencilState &a, const DepthStencilState &b); bool operator!=(const DepthStencilState &a, const DepthStencilState &b);
// Packs a sampler state for completeness checks:
// * minFilter: 5 values (3 bits)
// * magFilter: 2 values (1 bit)
// * wrapS: 3 values (2 bits)
// * wrapT: 3 values (2 bits)
// * compareMode: 1 bit (for == GL_NONE).
// This makes a total of 9 bits. We can pack this easily into 32 bits:
// * minFilter: 8 bits
// * magFilter: 8 bits
// * wrapS: 8 bits
// * wrapT: 4 bits
// * compareMode: 4 bits
struct PackedSamplerCompleteness
{
uint8_t minFilter;
uint8_t magFilter;
uint8_t wrapS;
uint8_t wrapTCompareMode;
};
static_assert(sizeof(PackedSamplerCompleteness) == sizeof(uint32_t), "Unexpected size");
// State from Table 6.10 (state per sampler object) // State from Table 6.10 (state per sampler object)
class SamplerState final class SamplerState final
{ {
...@@ -249,7 +272,14 @@ class SamplerState final ...@@ -249,7 +272,14 @@ class SamplerState final
void setSRGBDecode(GLenum sRGBDecode); void setSRGBDecode(GLenum sRGBDecode);
bool sameCompleteness(const SamplerState &samplerState) const
{
return mCompleteness.packed == samplerState.mCompleteness.packed;
}
private: private:
void updateWrapTCompareMode();
GLenum mMinFilter; GLenum mMinFilter;
GLenum mMagFilter; GLenum mMagFilter;
...@@ -267,6 +297,13 @@ class SamplerState final ...@@ -267,6 +297,13 @@ class SamplerState final
GLenum mCompareFunc; GLenum mCompareFunc;
GLenum mSRGBDecode; GLenum mSRGBDecode;
union Completeness {
uint32_t packed;
PackedSamplerCompleteness typed;
};
Completeness mCompleteness;
}; };
bool operator==(const SamplerState &a, const SamplerState &b); bool operator==(const SamplerState &a, const SamplerState &b);
......
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