1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

LibSoftGPU: Make blending simpler and more efficient

Previously, we would precalculate "alpha blend factors" on every
configuration update and then calculate the source and destination
blending factors in one go using all these factors. The idea here was
probably that we would get better performance by avoiding branching.

However, by measuring blending performance in Quake III, it seems that
this simpler version that only calculates the required factors reduces
the CPU time spent in `rasterize_triangle` by 3%.

As a bonus, `GL_SRC_ALPHA_SATURATE` is now also implemented.
This commit is contained in:
Jelle Raaijmakers 2023-02-01 21:18:53 +01:00 committed by Andreas Kling
parent f0f9d8f1e0
commit 69b94e4235
4 changed files with 63 additions and 130 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
* Copyright (c) 2022-2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -29,7 +29,6 @@
#include <LibGfx/Matrix4x4.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/AlphaBlendFactors.h>
#include <LibSoftGPU/Buffer/FrameBuffer.h>
#include <LibSoftGPU/Buffer/Typed2DBuffer.h>
#include <LibSoftGPU/Clipper.h>
@ -102,7 +101,6 @@ private:
void rasterize_point(GPU::Vertex&);
void rasterize_triangle(Triangle&);
void setup_blend_factors();
void shade_fragments(PixelQuad&);
RefPtr<FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>> m_frame_buffer {};
@ -113,7 +111,6 @@ private:
Vector<Triangle> m_processed_triangles;
Vector<GPU::Vertex> m_clipped_vertices;
Array<Sampler, GPU::NUM_TEXTURE_UNITS> m_samplers;
AlphaBlendFactors m_alpha_blend_factors;
Array<GPU::Light, NUM_LIGHTS> m_lights;
Array<GPU::Material, 2u> m_materials;
GPU::RasterPosition m_raster_position;