Commit 526a6f6b by Jamie Madill Committed by Commit Bot

Cache valid draw modes for draw calls.

This optimizes some of our dynamic switching. It uses packed enum maps. Bug: angleproject:2747 Change-Id: Ibd2f9306d066f2fd9eb64c99a25668b7ba5c009c Reviewed-on: https://chromium-review.googlesource.com/1171505 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent daab0014
...@@ -260,17 +260,17 @@ void LimitCap(CapT *cap, MaxT maximum) ...@@ -260,17 +260,17 @@ void LimitCap(CapT *cap, MaxT maximum)
} }
constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{ constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
/* Points */ 1, 1, /* Points */
/* Lines */ 2, 2, /* Lines */
/* LineLoop */ 2, 2, /* LineLoop */
/* LineStrip */ 2, 2, /* LineStrip */
/* Triangles */ 3, 3, /* Triangles */
/* TriangleStrip */ 3, 3, /* TriangleStrip */
/* TriangleFan */ 3, 3, /* TriangleFan */
/* LinesAdjacency */ 2, 2, /* LinesAdjacency */
/* LineStripAdjacency */ 2, 2, /* LineStripAdjacency */
/* TrianglesAdjacency */ 3, 3, /* TrianglesAdjacency */
/* TriangleStripAdjacency */ 3, 3, /* TriangleStripAdjacency */
}}; }};
// Indices above are code-gen'd so make sure they don't change // Indices above are code-gen'd so make sure they don't change
// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve // if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
...@@ -7893,6 +7893,7 @@ void StateCache::onProgramExecutableChange(Context *context) ...@@ -7893,6 +7893,7 @@ void StateCache::onProgramExecutableChange(Context *context)
updateActiveAttribsMask(context); updateActiveAttribsMask(context);
updateVertexElementLimits(context); updateVertexElementLimits(context);
updateBasicDrawStatesError(); updateBasicDrawStatesError();
updateValidDrawModes(context);
} }
void StateCache::onVertexArrayFormatChange(Context *context) void StateCache::onVertexArrayFormatChange(Context *context)
...@@ -7967,4 +7968,47 @@ void StateCache::onBufferBindingChange(Context *context) ...@@ -7967,4 +7968,47 @@ void StateCache::onBufferBindingChange(Context *context)
{ {
updateBasicDrawStatesError(); updateBasicDrawStatesError();
} }
void StateCache::updateValidDrawModes(Context *context)
{
Program *program = context->getGLState().getProgram();
if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
{
mCachedValidDrawModes = {{
true, /* Points */
true, /* Lines */
true, /* LineLoop */
true, /* LineStrip */
true, /* Triangles */
true, /* TriangleStrip */
true, /* TriangleFan */
false, /* LinesAdjacency */
false, /* LineStripAdjacency */
false, /* TrianglesAdjacency */
false, /* TriangleStripAdjacency */
false, /* InvalidEnum */
}};
}
else
{
ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
mCachedValidDrawModes = {{
gsMode == PrimitiveMode::Points, /* Points */
gsMode == PrimitiveMode::Lines, /* Lines */
gsMode == PrimitiveMode::Lines, /* LineLoop */
gsMode == PrimitiveMode::Lines, /* LineStrip */
gsMode == PrimitiveMode::Triangles, /* Triangles */
gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
gsMode == PrimitiveMode::Triangles, /* TriangleFan */
gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
false, /* InvalidEnum */
}};
}
}
} // namespace gl } // namespace gl
...@@ -137,6 +137,13 @@ class StateCache final : angle::NonCopyable ...@@ -137,6 +137,13 @@ class StateCache final : angle::NonCopyable
return getBasicDrawStatesErrorImpl(context); return getBasicDrawStatesErrorImpl(context);
} }
// Places that can trigger updateValidDrawModes:
// 1. onProgramExecutableChange.
bool isValidDrawMode(PrimitiveMode primitiveMode) const
{
return mCachedValidDrawModes[primitiveMode];
}
// State change notifications. // State change notifications.
void onVertexArrayBindingChange(Context *context); void onVertexArrayBindingChange(Context *context);
void onProgramExecutableChange(Context *context); void onProgramExecutableChange(Context *context);
...@@ -160,6 +167,7 @@ class StateCache final : angle::NonCopyable ...@@ -160,6 +167,7 @@ class StateCache final : angle::NonCopyable
void updateActiveAttribsMask(Context *context); void updateActiveAttribsMask(Context *context);
void updateVertexElementLimits(Context *context); void updateVertexElementLimits(Context *context);
void updateBasicDrawStatesError(); void updateBasicDrawStatesError();
void updateValidDrawModes(Context *context);
intptr_t getBasicDrawStatesErrorImpl(Context *context) const; intptr_t getBasicDrawStatesErrorImpl(Context *context) const;
...@@ -172,6 +180,10 @@ class StateCache final : angle::NonCopyable ...@@ -172,6 +180,10 @@ class StateCache final : angle::NonCopyable
GLint64 mCachedNonInstancedVertexElementLimit; GLint64 mCachedNonInstancedVertexElementLimit;
GLint64 mCachedInstancedVertexElementLimit; GLint64 mCachedInstancedVertexElementLimit;
mutable intptr_t mCachedBasicDrawStatesError; mutable intptr_t mCachedBasicDrawStatesError;
// Reserve an extra slot at the end of the map for invalid enum.
angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
mCachedValidDrawModes;
}; };
class Context final : public egl::LabeledObject, angle::NonCopyable, public angle::ObserverInterface class Context final : public egl::LabeledObject, angle::NonCopyable, public angle::ObserverInterface
......
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