all repos — mgba @ ab1d825e3038bd4aac252504c757a11be2435aff

mGBA Game Boy Advance Emulator

GBA Video: Slightly optimize frame compositing
Vicki Pfau vi@endrift.com
Tue, 14 Jan 2020 23:23:53 -0800
commit

ab1d825e3038bd4aac252504c757a11be2435aff

parent

d4e30b74ff3d34352ca86094bb1a4f97ccf12a8f

1 files changed, 27 insertions(+), 19 deletions(-)

jump to
M src/gba/renderers/gl.csrc/gba/renderers/gl.c

@@ -585,9 +585,6 @@ "uniform isampler2D backdropFlags;\n"

"out vec4 color;\n" "void composite(vec4 pixel, ivec4 flags, inout vec4 topPixel, inout ivec4 topFlags, inout vec4 bottomPixel, inout ivec4 bottomFlags) {\n" - " if (pixel.a == 0.) {\n" - " return;\n" - " }\n" " if (flags.x >= topFlags.x) {\n" " if (flags.x >= bottomFlags.x) {\n" " return;\n"

@@ -607,32 +604,43 @@ " vec4 topPixel = texelFetch(backdrop, ivec2(0, texCoord.y), 0);\n"

" vec4 bottomPixel = topPixel;\n" " ivec4 topFlags = ivec4(texelFetch(backdropFlags, ivec2(0, texCoord.y), 0));\n" " ivec4 bottomFlags = topFlags;\n" - " ivec4 windowFlags = texelFetch(window, ivec2(texCoord * float(scale)), 0);\n" + " ivec2 coord = ivec2(texCoord * float(scale));\n" + " ivec4 windowFlags = texelFetch(window, coord, 0);\n" " int layerWindow = windowFlags.x;\n" " if ((layerWindow & 16) != 0) {\n" - " vec4 pix = texelFetch(layers[4], ivec2(texCoord * float(scale)), 0);\n" - " ivec4 inflags = ivec4(texelFetch(flags[4], ivec2(texCoord * float(scale)), 0));\n" - " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " vec4 pix = texelFetch(layers[4], coord, 0);\n" + " if (pix.a != 0.) {\n" + " ivec4 inflags = ivec4(texelFetch(flags[4], coord, 0));\n" + " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " }\n" " }\n" " if ((layerWindow & 1) != 0) {\n" - " vec4 pix = texelFetch(layers[0], ivec2(texCoord * float(scale)), 0);\n" - " ivec4 inflags = ivec4(texelFetch(flags[0], ivec2(texCoord * float(scale)), 0).xyz, 0);\n" - " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " vec4 pix = texelFetch(layers[0], coord, 0);\n" + " if (pix.a != 0.) {\n" + " ivec4 inflags = ivec4(texelFetch(flags[0], coord, 0).xyz, 0);\n" + " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " }\n" " }\n" " if ((layerWindow & 2) != 0) {\n" - " vec4 pix = texelFetch(layers[1], ivec2(texCoord * float(scale)), 0);\n" - " ivec4 inflags = ivec4(texelFetch(flags[1], ivec2(texCoord * float(scale)), 0).xyz, 0);\n" - " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " vec4 pix = texelFetch(layers[1], coord, 0);\n" + " if (pix.a != 0.) {\n" + " ivec4 inflags = ivec4(texelFetch(flags[1], coord, 0).xyz, 0);\n" + " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " }\n" " }\n" " if ((layerWindow & 4) != 0) {\n" - " vec4 pix = texelFetch(layers[2], ivec2(texCoord * float(scale)), 0);\n" - " ivec4 inflags = ivec4(texelFetch(flags[2], ivec2(texCoord * float(scale)), 0).xyz.xyz, 0);\n" - " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " vec4 pix = texelFetch(layers[2], coord, 0);\n" + " if (pix.a != 0.) {\n" + " ivec4 inflags = ivec4(texelFetch(flags[2], coord, 0).xyz, 0);\n" + " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " }\n" " }\n" " if ((layerWindow & 8) != 0) {\n" - " vec4 pix = texelFetch(layers[3], ivec2(texCoord * float(scale)), 0);\n" - " ivec4 inflags = ivec4(texelFetch(flags[3], ivec2(texCoord * float(scale)), 0).xyz, 0);\n" - " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " vec4 pix = texelFetch(layers[3], coord, 0);\n" + " if (pix.a != 0.) {\n" + " ivec4 inflags = ivec4(texelFetch(flags[3], coord, 0).xyz, 0);\n" + " composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n" + " }\n" " }\n" " if ((layerWindow & 32) == 0) {\n" " topFlags.y &= ~1;\n"