LibGL: Only pass bound texture units to rasterizer
Before, `SoftwareRasterizer` was iterating over all 32 possible texture units for each fragment and checking each if they're bound to a texture. After this change, an intrusive list containing only texture units with bound textures is passed to the rasterizer. In GLQuake, this results in a performance improvement of ~30% (from 12 to 16 FPS in the first demo) on my machine.
This commit is contained in:
parent
f201567153
commit
4e3ed16527
Notes:
sideshowbarker
2024-07-17 22:34:08 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/4e3ed165279 Pull-request: https://github.com/SerenityOS/serenity/pull/11236 Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/sunverwerth ✅
5 changed files with 16 additions and 10 deletions
|
@ -328,6 +328,12 @@ void SoftwareGLContext::gl_end()
|
|||
}
|
||||
}
|
||||
|
||||
m_bound_texture_units.clear();
|
||||
for (auto& texture_unit : m_texture_units) {
|
||||
if (texture_unit.is_bound())
|
||||
m_bound_texture_units.append(texture_unit);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < processed_triangles.size(); i++) {
|
||||
GLTriangle& triangle = processed_triangles.at(i);
|
||||
|
||||
|
@ -356,7 +362,7 @@ void SoftwareGLContext::gl_end()
|
|||
swap(triangle.vertices[0], triangle.vertices[1]);
|
||||
}
|
||||
|
||||
m_rasterizer.submit_triangle(triangle, m_texture_units);
|
||||
m_rasterizer.submit_triangle(triangle, m_bound_texture_units);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -234,6 +234,7 @@ private:
|
|||
HashMap<GLuint, RefPtr<Texture>> m_allocated_textures;
|
||||
Array<TextureUnit, 32> m_texture_units;
|
||||
TextureUnit* m_active_texture_unit { &m_texture_units[0] };
|
||||
TextureUnit::BoundList m_bound_texture_units;
|
||||
|
||||
SoftwareRasterizer m_rasterizer;
|
||||
|
||||
|
|
|
@ -494,17 +494,12 @@ SoftwareRasterizer::SoftwareRasterizer(const Gfx::IntSize& min_size)
|
|||
m_options.scissor_box = m_render_target->rect();
|
||||
}
|
||||
|
||||
void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units)
|
||||
void SoftwareRasterizer::submit_triangle(GLTriangle const& triangle, TextureUnit::BoundList const& bound_texture_units)
|
||||
{
|
||||
rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [this, &texture_units](const FloatVector2& uv, const FloatVector4& color, float z) -> FloatVector4 {
|
||||
rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [this, &bound_texture_units](const FloatVector2& uv, const FloatVector4& color, float z) -> FloatVector4 {
|
||||
FloatVector4 fragment = color;
|
||||
|
||||
for (const auto& texture_unit : texture_units) {
|
||||
|
||||
// No texture is bound to this texture unit
|
||||
if (!texture_unit.is_bound())
|
||||
continue;
|
||||
|
||||
for (auto const& texture_unit : bound_texture_units) {
|
||||
// FIXME: implement GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP
|
||||
FloatVector4 texel;
|
||||
switch (texture_unit.currently_bound_target()) {
|
||||
|
|
|
@ -56,7 +56,7 @@ class SoftwareRasterizer final {
|
|||
public:
|
||||
SoftwareRasterizer(const Gfx::IntSize& min_size);
|
||||
|
||||
void submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units);
|
||||
void submit_triangle(GLTriangle const& triangle, TextureUnit::BoundList const& bound_texture_units);
|
||||
void resize(const Gfx::IntSize& min_size);
|
||||
void clear_color(const FloatVector4&);
|
||||
void clear_depth(float);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibGL/Tex/Texture2D.h>
|
||||
|
||||
|
@ -35,6 +36,9 @@ public:
|
|||
bool texture_cube_map_enabled() const { return m_texture_cube_map_enabled; };
|
||||
void set_texture_cube_map_enabled(bool texture_cube_map_enabled) { m_texture_cube_map_enabled = texture_cube_map_enabled; }
|
||||
|
||||
IntrusiveListNode<TextureUnit> m_bound_node;
|
||||
using BoundList = IntrusiveList<&TextureUnit::m_bound_node>;
|
||||
|
||||
private:
|
||||
mutable RefPtr<Texture2D> m_texture_target_2d { nullptr };
|
||||
mutable RefPtr<Texture> m_currently_bound_texture { nullptr };
|
||||
|
|
Loading…
Add table
Reference in a new issue