blob: a7e58078ba11ebff6139467c7c85cf7731c88448 [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// RendererGL.cpp: Implements the class methods for RendererGL.
8
9#include "libANGLE/renderer/gl/RendererGL.h"
10
Jamie Madill39fcf262015-06-08 14:39:07 -040011#include <EGL/eglext.h>
12
Geoff Langf9a6f082015-01-22 13:32:49 -050013#include "common/debug.h"
Jamie Madill39fcf262015-06-08 14:39:07 -040014#include "libANGLE/AttributeMap.h"
Martin Radev8f276e22017-05-30 12:05:52 +030015#include "libANGLE/Context.h"
Jamie Madill9082b982016-04-27 15:21:51 -040016#include "libANGLE/ContextState.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "libANGLE/Path.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040018#include "libANGLE/Surface.h"
Geoff Lang53b8aec2015-08-24 10:33:25 -040019#include "libANGLE/renderer/gl/BlitGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050020#include "libANGLE/renderer/gl/BufferGL.h"
Martin Radev5e424fa2017-08-09 16:25:36 +030021#include "libANGLE/renderer/gl/ClearMultiviewGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050022#include "libANGLE/renderer/gl/CompilerGL.h"
Jamie Madill437fa652016-05-03 15:13:24 -040023#include "libANGLE/renderer/gl/ContextGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050024#include "libANGLE/renderer/gl/FenceNVGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050025#include "libANGLE/renderer/gl/FramebufferGL.h"
Geoff Lang56cf9af2015-02-17 10:16:49 -050026#include "libANGLE/renderer/gl/FunctionsGL.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/renderer/gl/PathGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050028#include "libANGLE/renderer/gl/ProgramGL.h"
29#include "libANGLE/renderer/gl/QueryGL.h"
30#include "libANGLE/renderer/gl/RenderbufferGL.h"
Geoff Lang0af0b812015-09-23 13:56:25 -040031#include "libANGLE/renderer/gl/SamplerGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050032#include "libANGLE/renderer/gl/ShaderGL.h"
Geoff Lang94463d52015-02-18 13:09:37 -050033#include "libANGLE/renderer/gl/StateManagerGL.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040034#include "libANGLE/renderer/gl/SurfaceGL.h"
Jamie Madill70b5bb02017-08-28 13:32:37 -040035#include "libANGLE/renderer/gl/SyncGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050036#include "libANGLE/renderer/gl/TextureGL.h"
37#include "libANGLE/renderer/gl/TransformFeedbackGL.h"
38#include "libANGLE/renderer/gl/VertexArrayGL.h"
Geoff Langddc74462015-02-25 11:48:09 -050039#include "libANGLE/renderer/gl/renderergl_utils.h"
Jamie Madill222c5172017-07-19 16:15:42 -040040#include "libANGLE/renderer/renderer_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050041
Sami Väisänend59ca052016-06-21 16:10:00 +030042namespace
43{
44
45std::vector<GLuint> GatherPaths(const std::vector<gl::Path *> &paths)
46{
47 std::vector<GLuint> ret;
48 ret.reserve(paths.size());
49
50 for (const auto *p : paths)
51 {
52 const auto *pathObj = rx::GetImplAs<rx::PathGL>(p);
53 ret.push_back(pathObj->getPathID());
54 }
55 return ret;
56}
57
58} // namespace
59
Jamie Madill231c7f52017-04-26 13:45:37 -040060static void INTERNAL_GL_APIENTRY LogGLDebugMessage(GLenum source,
61 GLenum type,
62 GLuint id,
63 GLenum severity,
64 GLsizei length,
65 const GLchar *message,
66 const void *userParam)
Geoff Langb80360f2015-05-04 15:01:31 -040067{
Geoff Lang3f332582018-06-26 21:00:14 +000068 std::string sourceText;
69 switch (source)
70 {
71 case GL_DEBUG_SOURCE_API:
72 sourceText = "OpenGL";
73 break;
74 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
75 sourceText = "Windows";
76 break;
77 case GL_DEBUG_SOURCE_SHADER_COMPILER:
78 sourceText = "Shader Compiler";
79 break;
80 case GL_DEBUG_SOURCE_THIRD_PARTY:
81 sourceText = "Third Party";
82 break;
83 case GL_DEBUG_SOURCE_APPLICATION:
84 sourceText = "Application";
85 break;
86 case GL_DEBUG_SOURCE_OTHER:
87 sourceText = "Other";
88 break;
89 default:
90 sourceText = "UNKNOWN";
91 break;
92 }
93
94 std::string typeText;
95 switch (type)
96 {
97 case GL_DEBUG_TYPE_ERROR:
98 typeText = "Error";
99 break;
100 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
101 typeText = "Deprecated behavior";
102 break;
103 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
104 typeText = "Undefined behavior";
105 break;
106 case GL_DEBUG_TYPE_PORTABILITY:
107 typeText = "Portability";
108 break;
109 case GL_DEBUG_TYPE_PERFORMANCE:
110 typeText = "Performance";
111 break;
112 case GL_DEBUG_TYPE_OTHER:
113 typeText = "Other";
114 break;
115 case GL_DEBUG_TYPE_MARKER:
116 typeText = "Marker";
117 break;
118 default:
119 typeText = "UNKNOWN";
120 break;
121 }
122
123 std::string severityText;
124 switch (severity)
125 {
126 case GL_DEBUG_SEVERITY_HIGH:
127 severityText = "High";
128 break;
129 case GL_DEBUG_SEVERITY_MEDIUM:
130 severityText = "Medium";
131 break;
132 case GL_DEBUG_SEVERITY_LOW:
133 severityText = "Low";
134 break;
135 case GL_DEBUG_SEVERITY_NOTIFICATION:
136 severityText = "Notification";
137 break;
138 default:
139 severityText = "UNKNOWN";
140 break;
141 }
142
143 if (type == GL_DEBUG_TYPE_ERROR)
144 {
145 ERR() << std::endl
146 << "\tSource: " << sourceText << std::endl
147 << "\tType: " << typeText << std::endl
148 << "\tID: " << gl::Error(id) << std::endl
149 << "\tSeverity: " << severityText << std::endl
150 << "\tMessage: " << message;
151 }
Geoff Lange0234ae2018-06-26 17:06:25 -0400152 else if (type != GL_DEBUG_TYPE_PERFORMANCE)
Geoff Lang3f332582018-06-26 21:00:14 +0000153 {
Geoff Lange0234ae2018-06-26 17:06:25 -0400154 // Don't print performance warnings. They tend to be very spammy in the dEQP test suite and
155 // there is very little we can do about them.
156
Geoff Lang3f332582018-06-26 21:00:14 +0000157 // TODO(ynovikov): filter into WARN and INFO if INFO is ever implemented
158 WARN() << std::endl
159 << "\tSource: " << sourceText << std::endl
160 << "\tType: " << typeText << std::endl
161 << "\tID: " << gl::Error(id) << std::endl
162 << "\tSeverity: " << severityText << std::endl
163 << "\tMessage: " << message;
164 }
Geoff Langb80360f2015-05-04 15:01:31 -0400165}
Geoff Langb80360f2015-05-04 15:01:31 -0400166
Geoff Langf9a6f082015-01-22 13:32:49 -0500167namespace rx
168{
169
Geoff Lang5da66902018-06-05 12:24:06 -0400170RendererGL::RendererGL(std::unique_ptr<FunctionsGL> functions, const egl::AttributeMap &attribMap)
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400171 : mMaxSupportedESVersion(0, 0),
Geoff Lang5da66902018-06-05 12:24:06 -0400172 mFunctions(std::move(functions)),
Jamie Madill39fcf262015-06-08 14:39:07 -0400173 mStateManager(nullptr),
Geoff Lang53b8aec2015-08-24 10:33:25 -0400174 mBlitter(nullptr),
Martin Radev5e424fa2017-08-09 16:25:36 +0300175 mMultiviewClearer(nullptr),
Jamie Madill222c5172017-07-19 16:15:42 -0400176 mUseDebugOutput(false),
Martin Radev318f9aa2017-05-17 17:47:28 +0300177 mCapsInitialized(false),
178 mMultiviewImplementationType(MultiviewImplementationTypeGL::UNSPECIFIED)
Geoff Lang56cf9af2015-02-17 10:16:49 -0500179{
180 ASSERT(mFunctions);
Geoff Lang5da66902018-06-05 12:24:06 -0400181 nativegl_gl::GenerateWorkarounds(mFunctions.get(), &mWorkarounds);
182 mStateManager = new StateManagerGL(mFunctions.get(), getNativeCaps(), getNativeExtensions());
183 mBlitter = new BlitGL(mFunctions.get(), mWorkarounds, mStateManager);
184 mMultiviewClearer = new ClearMultiviewGL(mFunctions.get(), mStateManager);
Geoff Langb80360f2015-05-04 15:01:31 -0400185
Jamie Madill222c5172017-07-19 16:15:42 -0400186 bool hasDebugOutput = mFunctions->isAtLeastGL(gl::Version(4, 3)) ||
187 mFunctions->hasGLExtension("GL_KHR_debug") ||
188 mFunctions->isAtLeastGLES(gl::Version(3, 2)) ||
189 mFunctions->hasGLESExtension("GL_KHR_debug");
190
191 mUseDebugOutput = hasDebugOutput && ShouldUseDebugLayers(attribMap);
192
193 if (mUseDebugOutput)
Geoff Langb80360f2015-05-04 15:01:31 -0400194 {
Corentin Wallez930fefc2016-09-14 15:54:18 -0400195 mFunctions->enable(GL_DEBUG_OUTPUT);
Geoff Langb80360f2015-05-04 15:01:31 -0400196 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
Jamie Madill231c7f52017-04-26 13:45:37 -0400197 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0,
198 nullptr, GL_TRUE);
199 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0,
200 nullptr, GL_TRUE);
201 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0,
202 nullptr, GL_FALSE);
203 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION,
204 0, nullptr, GL_FALSE);
Geoff Lang3f332582018-06-26 21:00:14 +0000205 mFunctions->debugMessageCallback(&LogGLDebugMessage, nullptr);
Geoff Langb80360f2015-05-04 15:01:31 -0400206 }
Jamie Madill39fcf262015-06-08 14:39:07 -0400207
Corentin Wallez83144652016-08-31 17:03:30 -0400208 if (mWorkarounds.initializeCurrentVertexAttributes)
209 {
210 GLint maxVertexAttribs = 0;
211 mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
212
213 for (GLint i = 0; i < maxVertexAttribs; ++i)
214 {
215 mFunctions->vertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 1.0f);
216 }
217 }
Geoff Lang56cf9af2015-02-17 10:16:49 -0500218}
Geoff Langf9a6f082015-01-22 13:32:49 -0500219
220RendererGL::~RendererGL()
Geoff Lang94463d52015-02-18 13:09:37 -0500221{
Geoff Lang53b8aec2015-08-24 10:33:25 -0400222 SafeDelete(mBlitter);
Martin Radev5e424fa2017-08-09 16:25:36 +0300223 SafeDelete(mMultiviewClearer);
Geoff Langbf8a72f2015-11-03 16:34:45 -0500224 SafeDelete(mStateManager);
Geoff Lang94463d52015-02-18 13:09:37 -0500225}
Geoff Langf9a6f082015-01-22 13:32:49 -0500226
Jamie Madille39e8f42018-10-05 08:17:38 -0400227angle::Result RendererGL::flush()
Geoff Langf9a6f082015-01-22 13:32:49 -0500228{
Geoff Lang2c919142015-04-01 14:44:13 -0400229 mFunctions->flush();
Jamie Madille39e8f42018-10-05 08:17:38 -0400230 return angle::Result::Continue();
Geoff Langf9a6f082015-01-22 13:32:49 -0500231}
232
Jamie Madille39e8f42018-10-05 08:17:38 -0400233angle::Result RendererGL::finish()
Geoff Langf9a6f082015-01-22 13:32:49 -0500234{
Jamie Madill222c5172017-07-19 16:15:42 -0400235 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400236 {
237 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
238 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400239
Geoff Lang2c919142015-04-01 14:44:13 -0400240 mFunctions->finish();
Geoff Langf0aa8422015-09-29 15:08:34 -0400241
Jamie Madill222c5172017-07-19 16:15:42 -0400242 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400243 {
244 mFunctions->disable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
245 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400246
Jamie Madille39e8f42018-10-05 08:17:38 -0400247 return angle::Result::Continue();
Geoff Langf9a6f082015-01-22 13:32:49 -0500248}
249
Jamie Madille39e8f42018-10-05 08:17:38 -0400250angle::Result RendererGL::drawArrays(const gl::Context *context,
251 gl::PrimitiveMode mode,
252 GLint first,
253 GLsizei count)
Geoff Langf9a6f082015-01-22 13:32:49 -0500254{
Martin Radev8f276e22017-05-30 12:05:52 +0300255 const gl::Program *program = context->getGLState().getProgram();
256 const bool usesMultiview = program->usesMultiview();
257 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400258
Martin Radev8f276e22017-05-30 12:05:52 +0300259 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, instanceCount));
Jamie Madill6d94f062017-10-21 22:19:40 -0400260 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400261 {
Jamie Madill493f9572018-05-24 19:52:15 -0400262 mFunctions->drawArrays(ToGLenum(mode), first, count);
Jamie Madill6d94f062017-10-21 22:19:40 -0400263 }
264 else
265 {
Jamie Madill493f9572018-05-24 19:52:15 -0400266 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400267 }
Jamie Madille39e8f42018-10-05 08:17:38 -0400268 return angle::Result::Continue();
Geoff Langf9a6f082015-01-22 13:32:49 -0500269}
270
Jamie Madille39e8f42018-10-05 08:17:38 -0400271angle::Result RendererGL::drawArraysInstanced(const gl::Context *context,
272 gl::PrimitiveMode mode,
273 GLint first,
274 GLsizei count,
275 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400276{
Martin Radev8f276e22017-05-30 12:05:52 +0300277 GLsizei adjustedInstanceCount = instanceCount;
278 const gl::Program *program = context->getGLState().getProgram();
279 if (program->usesMultiview())
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400280 {
Martin Radev8f276e22017-05-30 12:05:52 +0300281 adjustedInstanceCount *= program->getNumViews();
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400282 }
283
Martin Radev8f276e22017-05-30 12:05:52 +0300284 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, adjustedInstanceCount));
Jamie Madill493f9572018-05-24 19:52:15 -0400285 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
Jamie Madille39e8f42018-10-05 08:17:38 -0400286 return angle::Result::Continue();
Geoff Langf6db0982015-08-25 13:04:00 -0400287}
288
Jamie Madille39e8f42018-10-05 08:17:38 -0400289angle::Result RendererGL::drawElements(const gl::Context *context,
290 gl::PrimitiveMode mode,
291 GLsizei count,
292 GLenum type,
293 const void *indices)
Geoff Langf9a6f082015-01-22 13:32:49 -0500294{
Martin Radev8f276e22017-05-30 12:05:52 +0300295 const gl::Program *program = context->getGLState().getProgram();
296 const bool usesMultiview = program->usesMultiview();
297 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill493f9572018-05-24 19:52:15 -0400298 const void *drawIndexPtr = nullptr;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400299
Martin Radev8f276e22017-05-30 12:05:52 +0300300 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
301 &drawIndexPtr));
Jamie Madill6d94f062017-10-21 22:19:40 -0400302 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400303 {
Jamie Madill493f9572018-05-24 19:52:15 -0400304 mFunctions->drawElements(ToGLenum(mode), count, type, drawIndexPtr);
Jamie Madill6d94f062017-10-21 22:19:40 -0400305 }
306 else
307 {
Jamie Madill493f9572018-05-24 19:52:15 -0400308 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPtr, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400309 }
Jamie Madille39e8f42018-10-05 08:17:38 -0400310 return angle::Result::Continue();
Geoff Langf9a6f082015-01-22 13:32:49 -0500311}
312
Jamie Madille39e8f42018-10-05 08:17:38 -0400313angle::Result RendererGL::drawElementsInstanced(const gl::Context *context,
314 gl::PrimitiveMode mode,
315 GLsizei count,
316 GLenum type,
317 const void *indices,
318 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -0400319{
Martin Radev8f276e22017-05-30 12:05:52 +0300320 GLsizei adjustedInstanceCount = instances;
321 const gl::Program *program = context->getGLState().getProgram();
322 if (program->usesMultiview())
323 {
324 adjustedInstanceCount *= program->getNumViews();
325 }
Jamie Madill876429b2017-04-20 15:46:24 -0400326 const void *drawIndexPointer = nullptr;
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400327
Martin Radev8f276e22017-05-30 12:05:52 +0300328 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices,
329 adjustedInstanceCount, &drawIndexPointer));
Jamie Madill493f9572018-05-24 19:52:15 -0400330 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
331 adjustedInstanceCount);
Jamie Madille39e8f42018-10-05 08:17:38 -0400332 return angle::Result::Continue();
Geoff Langf6db0982015-08-25 13:04:00 -0400333}
334
Jamie Madille39e8f42018-10-05 08:17:38 -0400335angle::Result RendererGL::drawRangeElements(const gl::Context *context,
336 gl::PrimitiveMode mode,
337 GLuint start,
338 GLuint end,
339 GLsizei count,
340 GLenum type,
341 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -0400342{
Martin Radev8f276e22017-05-30 12:05:52 +0300343 const gl::Program *program = context->getGLState().getProgram();
344 const bool usesMultiview = program->usesMultiview();
345 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill876429b2017-04-20 15:46:24 -0400346 const void *drawIndexPointer = nullptr;
Geoff Lang47502232015-08-25 16:26:10 -0400347
Martin Radev8f276e22017-05-30 12:05:52 +0300348 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
349 &drawIndexPointer));
Jamie Madill6d94f062017-10-21 22:19:40 -0400350 if (!usesMultiview)
Geoff Lang47502232015-08-25 16:26:10 -0400351 {
Jamie Madill493f9572018-05-24 19:52:15 -0400352 mFunctions->drawRangeElements(ToGLenum(mode), start, end, count, type, drawIndexPointer);
Jamie Madill6d94f062017-10-21 22:19:40 -0400353 }
354 else
355 {
Jamie Madill493f9572018-05-24 19:52:15 -0400356 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
357 instanceCount);
Geoff Lang47502232015-08-25 16:26:10 -0400358 }
Jamie Madille39e8f42018-10-05 08:17:38 -0400359 return angle::Result::Continue();
Geoff Langf6db0982015-08-25 13:04:00 -0400360}
361
Jamie Madille39e8f42018-10-05 08:17:38 -0400362angle::Result RendererGL::drawArraysIndirect(const gl::Context *context,
363 gl::PrimitiveMode mode,
364 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800365{
Jiajia Qin47474142017-12-29 13:41:00 +0800366 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400367 mFunctions->drawArraysIndirect(ToGLenum(mode), indirect);
Jamie Madille39e8f42018-10-05 08:17:38 -0400368 return angle::Result::Continue();
Jiajia Qind9671222016-11-29 16:30:31 +0800369}
370
Jamie Madille39e8f42018-10-05 08:17:38 -0400371angle::Result RendererGL::drawElementsIndirect(const gl::Context *context,
372 gl::PrimitiveMode mode,
373 GLenum type,
374 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800375{
Jiajia Qin47474142017-12-29 13:41:00 +0800376 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400377 mFunctions->drawElementsIndirect(ToGLenum(mode), type, indirect);
Jamie Madille39e8f42018-10-05 08:17:38 -0400378 return angle::Result::Continue();
Jiajia Qind9671222016-11-29 16:30:31 +0800379}
380
Sami Väisänene45e53b2016-05-25 10:36:04 +0300381void RendererGL::stencilFillPath(const gl::ContextState &state,
382 const gl::Path *path,
383 GLenum fillMode,
384 GLuint mask)
385{
386 const auto *pathObj = GetImplAs<PathGL>(path);
387
388 mFunctions->stencilFillPathNV(pathObj->getPathID(), fillMode, mask);
389
390 ASSERT(mFunctions->getError() == GL_NO_ERROR);
391}
392
393void RendererGL::stencilStrokePath(const gl::ContextState &state,
394 const gl::Path *path,
395 GLint reference,
396 GLuint mask)
397{
398 const auto *pathObj = GetImplAs<PathGL>(path);
399
400 mFunctions->stencilStrokePathNV(pathObj->getPathID(), reference, mask);
401
402 ASSERT(mFunctions->getError() == GL_NO_ERROR);
403}
404
405void RendererGL::coverFillPath(const gl::ContextState &state,
406 const gl::Path *path,
407 GLenum coverMode)
408{
409
410 const auto *pathObj = GetImplAs<PathGL>(path);
411 mFunctions->coverFillPathNV(pathObj->getPathID(), coverMode);
412
413 ASSERT(mFunctions->getError() == GL_NO_ERROR);
414}
415
416void RendererGL::coverStrokePath(const gl::ContextState &state,
417 const gl::Path *path,
418 GLenum coverMode)
419{
420 const auto *pathObj = GetImplAs<PathGL>(path);
421 mFunctions->coverStrokePathNV(pathObj->getPathID(), coverMode);
422
423 ASSERT(mFunctions->getError() == GL_NO_ERROR);
424}
425
426void RendererGL::stencilThenCoverFillPath(const gl::ContextState &state,
427 const gl::Path *path,
428 GLenum fillMode,
429 GLuint mask,
430 GLenum coverMode)
431{
432
433 const auto *pathObj = GetImplAs<PathGL>(path);
434 mFunctions->stencilThenCoverFillPathNV(pathObj->getPathID(), fillMode, mask, coverMode);
435
436 ASSERT(mFunctions->getError() == GL_NO_ERROR);
437}
438
439void RendererGL::stencilThenCoverStrokePath(const gl::ContextState &state,
440 const gl::Path *path,
441 GLint reference,
442 GLuint mask,
443 GLenum coverMode)
444{
445
446 const auto *pathObj = GetImplAs<PathGL>(path);
447 mFunctions->stencilThenCoverStrokePathNV(pathObj->getPathID(), reference, mask, coverMode);
448
449 ASSERT(mFunctions->getError() == GL_NO_ERROR);
450}
451
Sami Väisänend59ca052016-06-21 16:10:00 +0300452void RendererGL::coverFillPathInstanced(const gl::ContextState &state,
453 const std::vector<gl::Path *> &paths,
454 GLenum coverMode,
455 GLenum transformType,
456 const GLfloat *transformValues)
457{
458 const auto &pathObjs = GatherPaths(paths);
459
460 mFunctions->coverFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
461 &pathObjs[0], 0, coverMode, transformType,
462 transformValues);
463
464 ASSERT(mFunctions->getError() == GL_NO_ERROR);
465}
466void RendererGL::coverStrokePathInstanced(const gl::ContextState &state,
467 const std::vector<gl::Path *> &paths,
468 GLenum coverMode,
469 GLenum transformType,
470 const GLfloat *transformValues)
471{
472 const auto &pathObjs = GatherPaths(paths);
473
474 mFunctions->coverStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
475 &pathObjs[0], 0, coverMode, transformType,
476 transformValues);
477
478 ASSERT(mFunctions->getError() == GL_NO_ERROR);
479}
480void RendererGL::stencilFillPathInstanced(const gl::ContextState &state,
481 const std::vector<gl::Path *> &paths,
482 GLenum fillMode,
483 GLuint mask,
484 GLenum transformType,
485 const GLfloat *transformValues)
486{
487 const auto &pathObjs = GatherPaths(paths);
488
489 mFunctions->stencilFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
490 &pathObjs[0], 0, fillMode, mask, transformType,
491 transformValues);
492
493 ASSERT(mFunctions->getError() == GL_NO_ERROR);
494}
495void RendererGL::stencilStrokePathInstanced(const gl::ContextState &state,
496 const std::vector<gl::Path *> &paths,
497 GLint reference,
498 GLuint mask,
499 GLenum transformType,
500 const GLfloat *transformValues)
501{
502 const auto &pathObjs = GatherPaths(paths);
503
504 mFunctions->stencilStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
505 &pathObjs[0], 0, reference, mask, transformType,
506 transformValues);
507
508 ASSERT(mFunctions->getError() == GL_NO_ERROR);
509}
510
511void RendererGL::stencilThenCoverFillPathInstanced(const gl::ContextState &state,
512 const std::vector<gl::Path *> &paths,
513 GLenum coverMode,
514 GLenum fillMode,
515 GLuint mask,
516 GLenum transformType,
517 const GLfloat *transformValues)
518{
519 const auto &pathObjs = GatherPaths(paths);
520
521 mFunctions->stencilThenCoverFillPathInstancedNV(
522 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, fillMode, mask,
523 coverMode, transformType, transformValues);
524
525 ASSERT(mFunctions->getError() == GL_NO_ERROR);
526}
527void RendererGL::stencilThenCoverStrokePathInstanced(const gl::ContextState &state,
528 const std::vector<gl::Path *> &paths,
529 GLenum coverMode,
530 GLint reference,
531 GLuint mask,
532 GLenum transformType,
533 const GLfloat *transformValues)
534{
535 const auto &pathObjs = GatherPaths(paths);
536
537 mFunctions->stencilThenCoverStrokePathInstancedNV(
538 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, reference, mask,
539 coverMode, transformType, transformValues);
540
541 ASSERT(mFunctions->getError() == GL_NO_ERROR);
542}
543
Corentin Wallezb920e362016-08-03 18:19:41 -0400544GLenum RendererGL::getResetStatus()
545{
546 return mFunctions->getGraphicsResetStatus();
547}
548
Geoff Langf6ade2e2015-09-29 11:21:43 -0400549void RendererGL::insertEventMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700550{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700551}
552
Geoff Langf6ade2e2015-09-29 11:21:43 -0400553void RendererGL::pushGroupMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700554{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700555}
556
557void RendererGL::popGroupMarker()
558{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500559}
560
561void RendererGL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
562{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500563}
564
565void RendererGL::popDebugGroup()
566{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700567}
568
Geoff Langf9a6f082015-01-22 13:32:49 -0500569std::string RendererGL::getVendorString() const
570{
Jamie Madill231c7f52017-04-26 13:45:37 -0400571 return std::string(reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
Geoff Langf9a6f082015-01-22 13:32:49 -0500572}
573
574std::string RendererGL::getRendererDescription() const
575{
Jamie Madill231c7f52017-04-26 13:45:37 -0400576 std::string nativeVendorString(
577 reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
578 std::string nativeRendererString(
579 reinterpret_cast<const char *>(mFunctions->getString(GL_RENDERER)));
Geoff Lange42753b2015-04-08 13:46:33 -0400580
Geoff Lange42753b2015-04-08 13:46:33 -0400581 std::ostringstream rendererString;
582 rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL";
Geoff Lang08dcfed2015-05-25 13:38:42 -0400583 if (mFunctions->standard == STANDARD_GL_ES)
Geoff Lange42753b2015-04-08 13:46:33 -0400584 {
585 rendererString << " ES";
586 }
Geoff Lang08dcfed2015-05-25 13:38:42 -0400587 rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor;
Geoff Lang8b0f0b32015-07-20 15:59:28 -0400588 if (mFunctions->standard == STANDARD_GL_DESKTOP)
589 {
590 // Some drivers (NVIDIA) use a profile mask of 0 when in compatibility profile.
591 if ((mFunctions->profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0 ||
592 (mFunctions->isAtLeastGL(gl::Version(3, 2)) && mFunctions->profile == 0))
593 {
594 rendererString << " compatibility";
595 }
596 else if ((mFunctions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
597 {
598 rendererString << " core";
599 }
600 }
Geoff Lange42753b2015-04-08 13:46:33 -0400601
602 return rendererString.str();
Geoff Langf9a6f082015-01-22 13:32:49 -0500603}
604
Geoff Lang862c0ba2015-05-25 15:31:16 -0400605const gl::Version &RendererGL::getMaxSupportedESVersion() const
606{
607 // Force generation of caps
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400608 getNativeCaps();
Geoff Lang862c0ba2015-05-25 15:31:16 -0400609
610 return mMaxSupportedESVersion;
611}
612
Jamie Madill231c7f52017-04-26 13:45:37 -0400613void RendererGL::generateCaps(gl::Caps *outCaps,
614 gl::TextureCapsMap *outTextureCaps,
Austin Kinross02df7962015-07-01 10:03:42 -0700615 gl::Extensions *outExtensions,
616 gl::Limitations * /* outLimitations */) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500617{
Geoff Lang5da66902018-06-05 12:24:06 -0400618 nativegl_gl::GenerateCaps(mFunctions.get(), mWorkarounds, outCaps, outTextureCaps,
619 outExtensions, &mMaxSupportedESVersion,
620 &mMultiviewImplementationType);
Geoff Langf9a6f082015-01-22 13:32:49 -0500621}
622
Ian Ewell53f59f42016-01-28 17:36:55 -0500623GLint RendererGL::getGPUDisjoint()
624{
625 // TODO(ewell): On GLES backends we should find a way to reliably query disjoint events
626 return 0;
627}
628
629GLint64 RendererGL::getTimestamp()
630{
631 GLint64 result = 0;
632 mFunctions->getInteger64v(GL_TIMESTAMP, &result);
633 return result;
634}
Ian Ewell292f0052016-02-04 10:37:32 -0500635
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400636void RendererGL::ensureCapsInitialized() const
Ian Ewell292f0052016-02-04 10:37:32 -0500637{
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400638 if (!mCapsInitialized)
639 {
640 generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations);
641 mCapsInitialized = true;
642 }
Ian Ewell292f0052016-02-04 10:37:32 -0500643}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400644
645const gl::Caps &RendererGL::getNativeCaps() const
646{
647 ensureCapsInitialized();
648 return mNativeCaps;
Geoff Langf9a6f082015-01-22 13:32:49 -0500649}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400650
651const gl::TextureCapsMap &RendererGL::getNativeTextureCaps() const
652{
653 ensureCapsInitialized();
654 return mNativeTextureCaps;
655}
656
657const gl::Extensions &RendererGL::getNativeExtensions() const
658{
659 ensureCapsInitialized();
660 return mNativeExtensions;
661}
662
663const gl::Limitations &RendererGL::getNativeLimitations() const
664{
665 ensureCapsInitialized();
666 return mNativeLimitations;
667}
668
Martin Radev318f9aa2017-05-17 17:47:28 +0300669MultiviewImplementationTypeGL RendererGL::getMultiviewImplementationType() const
670{
671 ensureCapsInitialized();
672 return mMultiviewImplementationType;
673}
674
Jamie Madill761b02c2017-06-23 16:27:06 -0400675void RendererGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
676{
677 ensureCapsInitialized();
Geoff Lang5da66902018-06-05 12:24:06 -0400678 nativegl_gl::ApplyWorkarounds(mFunctions.get(), workarounds);
Jamie Madill761b02c2017-06-23 16:27:06 -0400679}
680
Jamie Madille39e8f42018-10-05 08:17:38 -0400681angle::Result RendererGL::dispatchCompute(const gl::Context *context,
682 GLuint numGroupsX,
683 GLuint numGroupsY,
684 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800685{
Xinghua Cao2b396592017-03-29 15:36:04 +0800686 mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
Jamie Madille39e8f42018-10-05 08:17:38 -0400687 return angle::Result::Continue();
Xinghua Cao2b396592017-03-29 15:36:04 +0800688}
689
Jamie Madille39e8f42018-10-05 08:17:38 -0400690angle::Result RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
Qin Jiajia62fcf622017-11-30 16:16:12 +0800691{
Qin Jiajia62fcf622017-11-30 16:16:12 +0800692 mFunctions->dispatchComputeIndirect(indirect);
Jamie Madille39e8f42018-10-05 08:17:38 -0400693 return angle::Result::Continue();
Qin Jiajia62fcf622017-11-30 16:16:12 +0800694}
695
Jamie Madille39e8f42018-10-05 08:17:38 -0400696angle::Result RendererGL::memoryBarrier(GLbitfield barriers)
Xinghua Cao89c422a2017-11-29 18:24:20 +0800697{
698 mFunctions->memoryBarrier(barriers);
Jamie Madille39e8f42018-10-05 08:17:38 -0400699 return angle::Result::Continue();
Xinghua Cao89c422a2017-11-29 18:24:20 +0800700}
Jamie Madille39e8f42018-10-05 08:17:38 -0400701angle::Result RendererGL::memoryBarrierByRegion(GLbitfield barriers)
Xinghua Cao89c422a2017-11-29 18:24:20 +0800702{
703 mFunctions->memoryBarrierByRegion(barriers);
Jamie Madille39e8f42018-10-05 08:17:38 -0400704 return angle::Result::Continue();
Xinghua Cao89c422a2017-11-29 18:24:20 +0800705}
706
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400707} // namespace rx