libEGL.so serves the guest's native code and Java's EGL10 alike (snx.android.opengl.Egl10, the JSR 239 EGL
that GLSurfaceView uses): both reach the same objects in hle_egl.c, so a context and a surface that Java makes
current are current for the native GLES calls of the same thread, as on Android.
EGL_OPENGL_ES_BIT, EGL_OPENGL_ES2_BIT,
EGL_OPENGL_ES3_BIT_KHR): RGBA 8888, RGB 888 and RGB 565, each with no depth buffer, a 16-bit one and a 24-bit one
with 8 bits of stencil, for window surfaces and pbuffers, matched and sorted as eglChooseConfig does.hle_gles.c). One of version 2 or 3 is GLES 3.1's (gles2*.c), as a
phone's version 2 context is. Version 3.2 is refused with EGL_BAD_MATCH, so an engine asks for 3.1 next.
glGetString names the version that is there (OpenGL ES 3.1, OpenGL ES GLSL ES 3.10), and the Mali GPU of
hle_gpu_name as the renderer.EGL_KHR_no_config_context) of any version can be made current without a surface,
and glGetString answers with the GPU that Vulkan reports. Engines name the GPU from such a throwaway context
before they choose an API, and choose Vulkan on the GPUs of their own lists. A GLES 2 context without a surface
makes a 1x1 pbuffer of its own only when a call first records commands, so a throwaway context makes no Vulkan
device.Both GLES libraries export most of their names twice (glDrawArrays, glClear): hle.c makes one export of each
such name, which calls the current context's.
gles_vk.c is the Vulkan app that both share. It makes the instance, surface, device, queue and swapchain, and
presents, through the pass-through's commands (hle_vulkan_host.h), so its presents get the renderer's layer and
--shot's copies as a guest's own Vulkan presents do. The device is Vulkan 1.3 where the host has it, with dynamic
rendering, and VK_EXT_depth_clip_control and VK_EXT_index_type_uint8 where the device has them. A frame is one
command buffer of a slot, recorded as the calls come, and two slots are in flight. Each submission has a serial: an
object that a frame may still use goes when its serial completed. A call that must see the GPU's results
(glReadPixels, glFinish, glClientWaitSync) submits what the frame recorded so far and waits for it, and the frame
goes on in the same command buffer. Between passes an acquired image is in PRESENT_SRC_KHR, so GLES 1.1's render
passes and GLES 2's dynamic rendering can share a frame.
GLES 1.1 (hle_gles.c) is the fixed function. A draw goes into a render pass on the swapchain image, or on a
pbuffer's image, which rests in COLOR_ATTACHMENT_OPTIMAL between passes as GLES 2 keeps it. A texture
upload ends the pass, copies from a staging buffer and starts the pass again (loading what it drew), so each draw
reads the texture as it was at its call. The client arrays of a draw are converted into one vertex format (position,
texture coordinate and color as floats) in a buffer of the frame, as triangle, line or point lists. GL's window
origin is the bottom left: the viewport has a negative height, so GL's viewport, scissor and glDrawTexOES
coordinates are used as they are. A texture of 3-byte texels on a device that cannot sample that format is an RGBA8
image, which a compute shader (gles_rgb.comp) writes from the packed rows. It does 2D textures (the base level) in
GLES 1.1's formats, the texture environment of unit 0, the matrix stacks, glDrawArrays, glDrawElements,
glDrawTexOES, blending, the scissor, glClear and glReadPixels of RGBA bytes (the frame's image copied into its
staging buffer, the frame submitted and waited for). It does not do yet: depth and stencil tests, lighting, fog, the
alpha test, mipmaps and the second texture unit.
GLES 2, 3.0 and 3.1 (gles2.c, gles2_object.c, gles2_program.c, gles2_draw.c) are done as Mesa's zink does them:
src/common/gpu/gl/gl_program.c, which the console's GL games
use too): flat records and a byte arena a save state holds, while each program's Vulkan objects (its modules and
layouts) are the bridge's, made from the link at its first draw. They compile with glslc (docs/layers/gpu/glslc.md).
glCompileShader compiles for the errors and the info log.
glLinkProgram compiles each stage again with a binding map: binding 0 of the program's set is the vertex
shader's default uniform block, 1 the fragment shader's, then each sampler, image and block of one name at one
binding for both stages. The link writes the vertex outputs' locations into the fragment shader's inputs of the
same names, as OpenGL ES links the stages by name. The loose uniforms are the members of each stage's default
block: the link reads their offsets, strides and types from the module, and flattens structs and arrays into GL's
names and locations. glUniform* writes into each stage's copy, which a draw puts into the frame's arena when it
changed. The vertex inputs take glBindAttribLocation's locations, else glslc's.src/common/gpu/gl/gl_object.c): a buffer's bytes
sit in chunks of host memory the layer places them in, and glMapBufferRange gives the guest those bytes. A draw reads
their Vulkan copy, written in place when no submission in flight reads it, else copied into the frame's arena.
A buffer that the GPU writes (glReadPixels into a pack buffer) moves to host-cached memory, and is read back.glTexStorage*, ETC2 and EAC and ASTC where the device has them, glGenerateMipmap by blits, the texture swizzle
and the base and max levels. A texture rests in SHADER_READ_ONLY_OPTIMAL, so a draw samples it without a barrier,
and an upload copies from the frame's staging buffer and returns the image to its rest. The unpack row length,
skip and alignment are applied by copying whole rows. A 3-component format that the device does not have
(GL_RGB8, GL_RGB16F, GL_RGB32F and their integer forms) is the 4-component one, which gles_expand.comp
writes on the GPU: the CPU does not convert texels. Samplers are kept by their state, sampler objects included. A
sampler whose texture is missing or incomplete reads a black texture.VK_EXT_depth_clip_control's. The fragment shaders read gl_FragCoord
and gl_PointCoord through glslc's flip_y, with the flip of the target in a push constant, so both are GL's in
the window and in a framebuffer object. Renderbuffers are images in their
attachment layout, multisampled when asked. glBlitFramebuffer and glCopyTexSubImage2D are blits, and resolves
from a multisampled image. glReadPixels blits the rectangle into an RGBA8 or BGRA8 image upright, copies it into
host-cached memory, and then copies the rows into the guest's memory.glDrawArrays, glDrawElements, glDrawRangeElements and their instanced forms, with vertex buffers
or client arrays (the range a draw reads copied into the frame's arena), divisors of 0 and 1, the generic attributes'
current values, and indices of 8, 16 and 32 bits. A line loop is a line strip with an index back to its start.
Vertex arrays, occlusion queries (GL_ANY_SAMPLES_PASSED), fence syncs and uniform buffers are there.glDispatchCompute and its
indirect form), shader storage buffers, image units (glBindImageTexture: the texture then rests in GENERAL),
glMemoryBarrier, indirect draws, the vertex attribute bindings (glBindVertexBuffer, glVertexAttribFormat),
multisample textures, glGetTexLevelParameter*, the sample mask, the depth and stencil texture mode, and the
program interface queries, and separate shader objects: a program pipeline draws through a hidden program that
links its stages' shaders together, with the stages' uniforms copied into it at each draw. A dispatch has a
barrier of every write on each side. GLES 3.1's atomic counters are not there (glslc has no atomic_uint), and
their limits are 0.glCopyImageSubData, the robustness
calls (glGetGraphicsResetStatus, glReadnPixels, glGetnUniform*), and the debug calls, which do nothing. A
context does not name itself 3.2: glslc has no geometry or tessellation stage.What GLES 2 and 3 do not do yet: transform feedback, GLES 3.1's atomic counters and its buffer variables in the
interface queries, glFramebufferParameteri, GLES 3.2's geometry and tessellation, its indexed blending and color masks, texture buffers, sample shading and
border colors, a divisor past 1, glClear of an integer color buffer with a partial color mask (it clears every
channel), client depth and stencil texels for a 24-bit depth texture, ETC2 and ASTC on a device that has neither
(the decode on the GPU), glReadPixels of a format other than RGBA or BGRA bytes, program binaries, and a pbuffer bound as a texture.
glClear with a partial color mask, or a stencil write mask of part of the bits, draws what Vulkan's clears cannot
(they write every channel and bit): a triangle over the target with the clear color and the masks in its pipeline
(gles2_clear.vert, gles2_clear.frag), no test and no blend, in the scissor's rectangle.
libz.so is the build's own zlib (hle_zlib.c): z_stream has the guest's layout on an LP64 host, and a stream's
allocator, when the guest gives one, is called through the bridge. Windows' uLong is 32 bits, so Windows has no
zlib for the guest yet.
libicuuc.so and libicui18n.so are the host's own ICU (hle_icu.c), loaded when the guest opens them. They are
not NDK libraries: an app reaches them by dlopen and dlsym, as .NET's System.Globalization.Native does, which
looks for u_strlen with each version's suffix (u_strlen_76) and then takes every function by that suffix. The
guest gets the host's version, and where the host's ICU was built without the suffixes (FreeBSD's) each name is
looked up without it. ICU's C API takes and returns integers, pointers and UDate doubles, which pass in registers
as they are; a UBool argument is extended and a UBool result cut to its byte. Windows passes arguments by
position, which would need each function's signature, so there the guest finds no ICU (and .NET stops).
Made from docs/platforms/android-apps/native.md at 69237645142c. GPL-3.0-or-later.