diff --git a/generator/opengl_loader_generator.py b/generator/opengl_loader_generator.py index db253e222d..ba2d47c524 100644 --- a/generator/opengl_loader_generator.py +++ b/generator/opengl_loader_generator.py @@ -240,6 +240,10 @@ class OpenGLLoaderGenerator(Generator): required=True, type=str, help='The Khronos gl.xml to use.') + parser.add_argument('--gl-angle-ext-xml', + required=True, + type=str, + help='The ANGLE gl_angle_ext.xml to use.') parser.add_argument( '--supported-extensions', required=True, @@ -250,14 +254,24 @@ class OpenGLLoaderGenerator(Generator): def get_file_renders(self, args): supported_extensions = [] + supported_angle_extensions = [] with open(args.supported_extensions) as f: supported_extensions_json = json.loads(f.read()) supported_extensions = supported_extensions_json[ 'supported_extensions'] + supported_angle_extensions = supported_extensions_json[ + 'supported_angle_extensions'] params = compute_params( etree.parse(args.gl_xml).getroot(), supported_extensions) + angle_params = compute_params( + etree.parse(args.gl_angle_ext_xml).getroot(), + supported_angle_extensions) + + for key, value in params.items(): + params[key] += angle_params[key] + return [ FileRender( 'opengl/OpenGLFunctionsBase.cpp', @@ -274,6 +288,7 @@ class OpenGLLoaderGenerator(Generator): def get_dependencies(self, args): return [ os.path.abspath(args.gl_xml), + os.path.abspath(args.gl_angle_ext_xml), os.path.abspath(args.supported_extensions) ] diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 4f3027327f..9f8f713e22 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -112,6 +112,8 @@ if (dawn_enable_opengl) { args = [ "--gl-xml", rebase_path("${dawn_root}/third_party/khronos/gl.xml", root_build_dir), + "--gl-angle-ext-xml", + rebase_path("${dawn_angle_dir}/scripts/gl_angle_ext.xml", root_build_dir), "--supported-extensions", rebase_path("opengl/supported_extensions.json", root_build_dir), ] diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index 0ce0af4801..7452b9e858 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -413,6 +413,8 @@ if (DAWN_ENABLE_OPENGL) PRINT_NAME "OpenGL function loader" ARGS "--gl-xml" "${Dawn_SOURCE_DIR}/third_party/khronos/gl.xml" + "--gl-angle-ext-xml" + "${Dawn_SOURCE_DIR}/third_party/angle/scripts/gl_angle_ext.xml" "--supported-extensions" "${Dawn_SOURCE_DIR}/src/dawn/native/opengl/supported_extensions.json" RESULT_VARIABLE "DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES" diff --git a/src/dawn/native/opengl/AdapterGL.cpp b/src/dawn/native/opengl/AdapterGL.cpp index ef41c537c0..b965e42ef1 100644 --- a/src/dawn/native/opengl/AdapterGL.cpp +++ b/src/dawn/native/opengl/AdapterGL.cpp @@ -194,6 +194,11 @@ void Adapter::SetupBackendDeviceToggles(TogglesState* deviceToggles) const { // (gl.IsAtLeastGLES(3, 1) && gl.IsGLExtensionSupported("EXT_base_instance")) || // (gl.IsAtLeastGL(3, 1) && gl.IsGLExtensionSupported("ARB_base_instance")); + if (gl.IsAtLeastGLES(3, 1) && gl.IsGLExtensionSupported("GL_ANGLE_base_vertex_base_instance")) { + supportsBaseVertex = true; + supportsBaseInstance = true; + } + // TODO(crbug.com/dawn/343): Investigate emulation. deviceToggles->Default(Toggle::DisableBaseVertex, !supportsBaseVertex); deviceToggles->Default(Toggle::DisableBaseInstance, !supportsBaseInstance); diff --git a/src/dawn/native/opengl/CommandBufferGL.cpp b/src/dawn/native/opengl/CommandBufferGL.cpp index d8a32e4430..99d219bea0 100644 --- a/src/dawn/native/opengl/CommandBufferGL.cpp +++ b/src/dawn/native/opengl/CommandBufferGL.cpp @@ -1007,7 +1007,11 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) { vertexStateBufferBindingTracker.Apply(gl); bindGroupTracker.Apply(gl); - if (draw->firstInstance > 0) { + if (gl.DrawArraysInstancedBaseInstanceANGLE) { + gl.DrawArraysInstancedBaseInstanceANGLE( + lastPipeline->GetGLPrimitiveTopology(), draw->firstVertex, + draw->vertexCount, draw->instanceCount, draw->firstInstance); + } else if (draw->firstInstance > 0) { gl.DrawArraysInstancedBaseInstance(lastPipeline->GetGLPrimitiveTopology(), draw->firstVertex, draw->vertexCount, draw->instanceCount, draw->firstInstance); @@ -1025,7 +1029,13 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) { vertexStateBufferBindingTracker.Apply(gl); bindGroupTracker.Apply(gl); - if (draw->firstInstance > 0) { + if (gl.DrawElementsInstancedBaseVertexBaseInstanceANGLE) { + gl.DrawElementsInstancedBaseVertexBaseInstanceANGLE( + lastPipeline->GetGLPrimitiveTopology(), draw->indexCount, indexBufferFormat, + reinterpret_cast(draw->firstIndex * indexFormatSize + + indexBufferBaseOffset), + draw->instanceCount, draw->baseVertex, draw->firstInstance); + } else if (draw->firstInstance > 0) { gl.DrawElementsInstancedBaseVertexBaseInstance( lastPipeline->GetGLPrimitiveTopology(), draw->indexCount, indexBufferFormat, reinterpret_cast(draw->firstIndex * indexFormatSize + diff --git a/src/dawn/native/opengl/supported_extensions.json b/src/dawn/native/opengl/supported_extensions.json index 8c110d012b..f0da1f6eb5 100644 --- a/src/dawn/native/opengl/supported_extensions.json +++ b/src/dawn/native/opengl/supported_extensions.json @@ -21,5 +21,9 @@ "GL_OES_EGL_image", "GL_EXT_texture_format_BGRA8888", "GL_APPLE_texture_format_BGRA8888" + ], + + "supported_angle_extensions": [ + "GL_ANGLE_base_vertex_base_instance" ] }