Commit 5a206950 by Jamie Madill Committed by Commit Bot

GL: Move draw functions from Renderer to Context.

This avoids one more function call + register pushing/popping. Slight improvement in the command_buffer_perftests. Bug: angleproject:2877 Change-Id: Ia50a330e62f0bd32266c9f0999810243cbaa41e0 Reviewed-on: https://chromium-review.googlesource.com/c/1293630Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent f38cb6d3
...@@ -170,12 +170,90 @@ angle::Result ContextGL::finish(const gl::Context *context) ...@@ -170,12 +170,90 @@ angle::Result ContextGL::finish(const gl::Context *context)
return mRenderer->finish(); return mRenderer->finish();
} }
ANGLE_INLINE angle::Result ContextGL::setDrawArraysState(const gl::Context *context,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
if (context->getStateCache().hasAnyActiveClientAttrib())
{
const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncClientSideData(context, program->getActiveAttribLocationsMask(), first,
count, instanceCount));
}
if (context->getExtensions().webglCompatibility)
{
const gl::State &glState = context->getGLState();
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
ANGLE_INLINE angle::Result ContextGL::setDrawElementsState(const gl::Context *context,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount,
const void **outIndices)
{
const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncDrawElementsState(context, program->getActiveAttribLocationsMask(), count,
type, indices, instanceCount,
glState.isPrimitiveRestartEnabled(), outIndices));
if (context->getExtensions().webglCompatibility)
{
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
ANGLE_INLINE angle::Result ContextGL::setDrawIndirectState(const gl::Context *context)
{
if (context->getExtensions().webglCompatibility)
{
const gl::State &glState = context->getGLState();
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
angle::Result ContextGL::drawArrays(const gl::Context *context, angle::Result ContextGL::drawArrays(const gl::Context *context,
gl::PrimitiveMode mode, gl::PrimitiveMode mode,
GLint first, GLint first,
GLsizei count) GLsizei count)
{ {
return mRenderer->drawArrays(context, mode, first, count); const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
ANGLE_TRY(setDrawArraysState(context, first, count, instanceCount));
if (!usesMultiview)
{
getFunctions()->drawArrays(ToGLenum(mode), first, count);
}
else
{
getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
}
return angle::Result::Continue();
} }
angle::Result ContextGL::drawArraysInstanced(const gl::Context *context, angle::Result ContextGL::drawArraysInstanced(const gl::Context *context,
...@@ -184,7 +262,16 @@ angle::Result ContextGL::drawArraysInstanced(const gl::Context *context, ...@@ -184,7 +262,16 @@ angle::Result ContextGL::drawArraysInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLsizei instanceCount) GLsizei instanceCount)
{ {
return mRenderer->drawArraysInstanced(context, mode, first, count, instanceCount); GLsizei adjustedInstanceCount = instanceCount;
const gl::Program *program = context->getGLState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount));
getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
return angle::Result::Continue();
} }
angle::Result ContextGL::drawElements(const gl::Context *context, angle::Result ContextGL::drawElements(const gl::Context *context,
...@@ -193,7 +280,22 @@ angle::Result ContextGL::drawElements(const gl::Context *context, ...@@ -193,7 +280,22 @@ angle::Result ContextGL::drawElements(const gl::Context *context,
GLenum type, GLenum type,
const void *indices) const void *indices)
{ {
return mRenderer->drawElements(context, mode, count, type, indices); const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPtr = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPtr));
if (!usesMultiview)
{
getFunctions()->drawElements(ToGLenum(mode), count, type, drawIndexPtr);
}
else
{
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPtr,
instanceCount);
}
return angle::Result::Continue();
} }
angle::Result ContextGL::drawElementsInstanced(const gl::Context *context, angle::Result ContextGL::drawElementsInstanced(const gl::Context *context,
...@@ -203,7 +305,19 @@ angle::Result ContextGL::drawElementsInstanced(const gl::Context *context, ...@@ -203,7 +305,19 @@ angle::Result ContextGL::drawElementsInstanced(const gl::Context *context,
const void *indices, const void *indices,
GLsizei instances) GLsizei instances)
{ {
return mRenderer->drawElementsInstanced(context, mode, count, type, indices, instances); GLsizei adjustedInstanceCount = instances;
const gl::Program *program = context->getGLState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
const void *drawIndexPointer = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, adjustedInstanceCount,
&drawIndexPointer));
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
adjustedInstanceCount);
return angle::Result::Continue();
} }
angle::Result ContextGL::drawRangeElements(const gl::Context *context, angle::Result ContextGL::drawRangeElements(const gl::Context *context,
...@@ -214,14 +328,33 @@ angle::Result ContextGL::drawRangeElements(const gl::Context *context, ...@@ -214,14 +328,33 @@ angle::Result ContextGL::drawRangeElements(const gl::Context *context,
GLenum type, GLenum type,
const void *indices) const void *indices)
{ {
return mRenderer->drawRangeElements(context, mode, start, end, count, type, indices); const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPointer = nullptr;
ANGLE_TRY(
setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPointer));
if (!usesMultiview)
{
getFunctions()->drawRangeElements(ToGLenum(mode), start, end, count, type,
drawIndexPointer);
}
else
{
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
instanceCount);
}
return angle::Result::Continue();
} }
angle::Result ContextGL::drawArraysIndirect(const gl::Context *context, angle::Result ContextGL::drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode, gl::PrimitiveMode mode,
const void *indirect) const void *indirect)
{ {
return mRenderer->drawArraysIndirect(context, mode, indirect); ANGLE_TRY(setDrawIndirectState(context));
getFunctions()->drawArraysIndirect(ToGLenum(mode), indirect);
return angle::Result::Continue();
} }
angle::Result ContextGL::drawElementsIndirect(const gl::Context *context, angle::Result ContextGL::drawElementsIndirect(const gl::Context *context,
...@@ -229,7 +362,9 @@ angle::Result ContextGL::drawElementsIndirect(const gl::Context *context, ...@@ -229,7 +362,9 @@ angle::Result ContextGL::drawElementsIndirect(const gl::Context *context,
GLenum type, GLenum type,
const void *indirect) const void *indirect)
{ {
return mRenderer->drawElementsIndirect(context, mode, type, indirect); ANGLE_TRY(setDrawIndirectState(context));
getFunctions()->drawElementsIndirect(ToGLenum(mode), type, indirect);
return angle::Result::Continue();
} }
void ContextGL::stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask) void ContextGL::stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask)
...@@ -415,11 +550,6 @@ void ContextGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const ...@@ -415,11 +550,6 @@ void ContextGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
return mRenderer->applyNativeWorkarounds(workarounds); return mRenderer->applyNativeWorkarounds(workarounds);
} }
const FunctionsGL *ContextGL::getFunctions() const
{
return mRenderer->getFunctions();
}
StateManagerGL *ContextGL::getStateManager() StateManagerGL *ContextGL::getStateManager()
{ {
return mRenderer->getStateManager(); return mRenderer->getStateManager();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBANGLE_RENDERER_GL_CONTEXTGL_H_ #define LIBANGLE_RENDERER_GL_CONTEXTGL_H_
#include "libANGLE/renderer/ContextImpl.h" #include "libANGLE/renderer/ContextImpl.h"
#include "libANGLE/renderer/gl/RendererGL.h"
namespace sh namespace sh
{ {
...@@ -194,7 +195,8 @@ class ContextGL : public ContextImpl ...@@ -194,7 +195,8 @@ class ContextGL : public ContextImpl
void applyNativeWorkarounds(gl::Workarounds *workarounds) const override; void applyNativeWorkarounds(gl::Workarounds *workarounds) const override;
// Handle helpers // Handle helpers
const FunctionsGL *getFunctions() const; ANGLE_INLINE const FunctionsGL *getFunctions() const { return mRenderer->getFunctions(); }
StateManagerGL *getStateManager(); StateManagerGL *getStateManager();
const WorkaroundsGL &getWorkaroundsGL() const; const WorkaroundsGL &getWorkaroundsGL() const;
BlitGL *getBlitter() const; BlitGL *getBlitter() const;
...@@ -216,6 +218,20 @@ class ContextGL : public ContextImpl ...@@ -216,6 +218,20 @@ class ContextGL : public ContextImpl
unsigned int line); unsigned int line);
private: private:
angle::Result setDrawArraysState(const gl::Context *context,
GLint first,
GLsizei count,
GLsizei instanceCount);
angle::Result setDrawElementsState(const gl::Context *context,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount,
const void **outIndices);
angle::Result setDrawIndirectState(const gl::Context *context);
std::shared_ptr<RendererGL> mRenderer; std::shared_ptr<RendererGL> mRenderer;
}; };
......
...@@ -247,201 +247,6 @@ angle::Result RendererGL::finish() ...@@ -247,201 +247,6 @@ angle::Result RendererGL::finish()
return angle::Result::Continue(); return angle::Result::Continue();
} }
ANGLE_INLINE angle::Result RendererGL::setDrawArraysState(const gl::Context *context,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
if (context->getStateCache().hasAnyActiveClientAttrib())
{
const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncClientSideData(context, program->getActiveAttribLocationsMask(), first,
count, instanceCount));
}
if (context->getExtensions().webglCompatibility)
{
const gl::State &glState = context->getGLState();
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
ANGLE_INLINE angle::Result RendererGL::setDrawElementsState(const gl::Context *context,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount,
const void **outIndices)
{
const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncDrawElementsState(context, program->getActiveAttribLocationsMask(), count,
type, indices, instanceCount,
glState.isPrimitiveRestartEnabled(), outIndices));
if (context->getExtensions().webglCompatibility)
{
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
ANGLE_INLINE angle::Result RendererGL::setDrawIndirectState(const gl::Context *context)
{
if (context->getExtensions().webglCompatibility)
{
const gl::State &glState = context->getGLState();
FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(glState.getDrawFramebuffer());
framebufferGL->maskOutInactiveOutputDrawBuffers(context);
}
return angle::Result::Continue();
}
angle::Result RendererGL::drawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count)
{
const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
ANGLE_TRY(setDrawArraysState(context, first, count, instanceCount));
if (!usesMultiview)
{
mFunctions->drawArrays(ToGLenum(mode), first, count);
}
else
{
mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
}
return angle::Result::Continue();
}
angle::Result RendererGL::drawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
GLsizei adjustedInstanceCount = instanceCount;
const gl::Program *program = context->getGLState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount));
mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
return angle::Result::Continue();
}
angle::Result RendererGL::drawElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
GLenum type,
const void *indices)
{
const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPtr = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPtr));
if (!usesMultiview)
{
mFunctions->drawElements(ToGLenum(mode), count, type, drawIndexPtr);
}
else
{
mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPtr, instanceCount);
}
return angle::Result::Continue();
}
angle::Result RendererGL::drawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instances)
{
GLsizei adjustedInstanceCount = instances;
const gl::Program *program = context->getGLState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
const void *drawIndexPointer = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, adjustedInstanceCount,
&drawIndexPointer));
mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
adjustedInstanceCount);
return angle::Result::Continue();
}
angle::Result RendererGL::drawRangeElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const void *indices)
{
const gl::Program *program = context->getGLState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPointer = nullptr;
ANGLE_TRY(
setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPointer));
if (!usesMultiview)
{
mFunctions->drawRangeElements(ToGLenum(mode), start, end, count, type, drawIndexPointer);
}
else
{
mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
instanceCount);
}
return angle::Result::Continue();
}
angle::Result RendererGL::drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect)
{
ANGLE_TRY(setDrawIndirectState(context));
mFunctions->drawArraysIndirect(ToGLenum(mode), indirect);
return angle::Result::Continue();
}
angle::Result RendererGL::drawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
GLenum type,
const void *indirect)
{
ANGLE_TRY(setDrawIndirectState(context));
mFunctions->drawElementsIndirect(ToGLenum(mode), type, indirect);
return angle::Result::Continue();
}
void RendererGL::stencilFillPath(const gl::ContextState &state, void RendererGL::stencilFillPath(const gl::ContextState &state,
const gl::Path *path, const gl::Path *path,
GLenum fillMode, GLenum fillMode,
......
...@@ -50,42 +50,6 @@ class RendererGL : angle::NonCopyable ...@@ -50,42 +50,6 @@ class RendererGL : angle::NonCopyable
angle::Result flush(); angle::Result flush();
angle::Result finish(); angle::Result finish();
angle::Result drawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count);
angle::Result drawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount);
angle::Result drawElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
GLenum type,
const void *indices);
angle::Result drawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instances);
angle::Result drawRangeElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const void *indices);
angle::Result drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect);
angle::Result drawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
GLenum type,
const void *indirect);
// CHROMIUM_path_rendering implementation // CHROMIUM_path_rendering implementation
void stencilFillPath(const gl::ContextState &state, void stencilFillPath(const gl::ContextState &state,
const gl::Path *path, const gl::Path *path,
...@@ -192,20 +156,6 @@ class RendererGL : angle::NonCopyable ...@@ -192,20 +156,6 @@ class RendererGL : angle::NonCopyable
gl::Extensions *outExtensions, gl::Extensions *outExtensions,
gl::Limitations *outLimitations) const; gl::Limitations *outLimitations) const;
angle::Result setDrawArraysState(const gl::Context *context,
GLint first,
GLsizei count,
GLsizei instanceCount);
angle::Result setDrawElementsState(const gl::Context *context,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount,
const void **outIndices);
angle::Result setDrawIndirectState(const gl::Context *context);
mutable gl::Version mMaxSupportedESVersion; mutable gl::Version mMaxSupportedESVersion;
std::unique_ptr<FunctionsGL> mFunctions; std::unique_ptr<FunctionsGL> mFunctions;
......
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