From 39995548e4bd6f95994c2a728ee00ccc5bff9adb Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Thu, 23 Dec 2021 02:38:20 +0100 Subject: [PATCH] LibGL+LibSoftGPU: Add method to query device info This adds a method `info()` to SoftGPU that returns the name of the hardware vendor and device name, as well as the number of texture untis. LibGL uses the returned texture unit count to initialize its internal texture unit array. --- .../Libraries/LibGL/SoftwareGLContext.cpp | 7 +++++-- Userland/Libraries/LibGL/SoftwareGLContext.h | 5 +++-- Userland/Libraries/LibSoftGPU/Device.cpp | 11 +++++++++-- Userland/Libraries/LibSoftGPU/Device.h | 5 ++++- Userland/Libraries/LibSoftGPU/DeviceInfo.h | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 Userland/Libraries/LibSoftGPU/DeviceInfo.h diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index a894283819..72da04c7cb 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -58,7 +58,10 @@ static constexpr size_t TEXTURE_MATRIX_STACK_LIMIT = 8; SoftwareGLContext::SoftwareGLContext(Gfx::Bitmap& frontbuffer) : m_frontbuffer(frontbuffer) , m_rasterizer(frontbuffer.size()) + , m_device_info(m_rasterizer.info()) { + m_texture_units.resize(m_device_info.num_texture_units); + m_active_texture_unit = &m_texture_units[0]; } Optional SoftwareGLContext::get_context_parameter(GLenum name) @@ -333,9 +336,9 @@ GLubyte* SoftwareGLContext::gl_get_string(GLenum name) switch (name) { case GL_VENDOR: - return reinterpret_cast(const_cast("The SerenityOS Developers")); + return reinterpret_cast(const_cast(m_device_info.vendor_name.characters())); case GL_RENDERER: - return reinterpret_cast(const_cast("SerenityOS OpenGL")); + return reinterpret_cast(const_cast(m_device_info.device_name.characters())); case GL_VERSION: return reinterpret_cast(const_cast("1.5")); case GL_EXTENSIONS: diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index cde187e80d..042a491652 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -233,10 +233,11 @@ private: // Texture objects TextureNameAllocator m_name_allocator; HashMap> m_allocated_textures; - Array m_texture_units; - TextureUnit* m_active_texture_unit { &m_texture_units[0] }; + Vector m_texture_units; + TextureUnit* m_active_texture_unit; SoftGPU::Device m_rasterizer; + SoftGPU::DeviceInfo const m_device_info; bool m_sampler_config_is_dirty { true }; struct Listing { diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index cd4ee99c01..b77789f90b 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -498,6 +498,15 @@ Device::Device(const Gfx::IntSize& min_size) m_options.scissor_box = m_render_target->rect(); } +DeviceInfo Device::info() const +{ + return { + .vendor_name = "SerenityOS", + .device_name = "SoftGPU", + .num_texture_units = num_samplers + }; +} + void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, Vector const& enabled_texture_units) { // At this point, the user has effectively specified that they are done with defining the geometry @@ -810,8 +819,6 @@ NonnullRefPtr Device::create_image(ImageFormat format, unsigned width, un void Device::set_sampler_config(unsigned sampler, SamplerConfig const& config) { - VERIFY(sampler < num_samplers); - m_samplers[sampler].set_config(config); } diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 498cea1aee..67c6b83569 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,8 @@ class Device final { public: Device(const Gfx::IntSize& min_size); + DeviceInfo info() const; + void draw_primitives(PrimitiveType, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, Vector const& enabled_texture_units); void resize(const Gfx::IntSize& min_size); void clear_color(const FloatVector4&); @@ -89,7 +92,7 @@ private: Vector m_triangle_list; Vector m_processed_triangles; Vector m_clipped_vertices; - Sampler m_samplers[num_samplers]; + Array m_samplers; }; } diff --git a/Userland/Libraries/LibSoftGPU/DeviceInfo.h b/Userland/Libraries/LibSoftGPU/DeviceInfo.h new file mode 100644 index 0000000000..75e3051df2 --- /dev/null +++ b/Userland/Libraries/LibSoftGPU/DeviceInfo.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021, Stephan Unverwerth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace SoftGPU { + +struct DeviceInfo final { + String vendor_name; + String device_name; + unsigned num_texture_units; +}; + +}