summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-10-16 16:31:15 -0600
committerLinus Groh <mail@linusgroh.de>2022-10-19 22:07:05 +0200
commitabc0c44f0b22afc15bdf02648cc4c477f0359305 (patch)
tree85eee5c250091240f89335df5a84c40abb2bca20 /Userland/Libraries
parent04ae4b89a383ebabffbe6fb152175be5744b96e1 (diff)
downloadserenity-abc0c44f0b22afc15bdf02648cc4c477f0359305.zip
LibGL+LibGPU+LibSoftGPU: Report maximum texture size
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGL/ContextParameter.cpp2
-rw-r--r--Userland/Libraries/LibGL/Tex/Texture2D.h4
-rw-r--r--Userland/Libraries/LibGL/Texture.cpp35
-rw-r--r--Userland/Libraries/LibGPU/DeviceInfo.h1
-rw-r--r--Userland/Libraries/LibSoftGPU/Config.h1
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp1
6 files changed, 27 insertions, 17 deletions
diff --git a/Userland/Libraries/LibGL/ContextParameter.cpp b/Userland/Libraries/LibGL/ContextParameter.cpp
index 1f4efe4b99..494c72723c 100644
--- a/Userland/Libraries/LibGL/ContextParameter.cpp
+++ b/Userland/Libraries/LibGL/ContextParameter.cpp
@@ -79,7 +79,7 @@ Optional<ContextParameter> GLContext::get_context_parameter(GLenum name)
case GL_MAX_TEXTURE_LOD_BIAS:
return ContextParameter { .type = GL_DOUBLE, .value = { .double_value = static_cast<GLdouble>(m_device_info.max_texture_lod_bias) } };
case GL_MAX_TEXTURE_SIZE:
- return ContextParameter { .type = GL_INT, .value = { .integer_value = 4096 } };
+ return ContextParameter { .type = GL_INT, .value = { .integer_value = static_cast<GLint>(m_device_info.max_texture_size) } };
case GL_MAX_TEXTURE_STACK_DEPTH:
return ContextParameter { .type = GL_INT, .value = { .integer_value = TEXTURE_MATRIX_STACK_LIMIT } };
case GL_MAX_TEXTURE_UNITS:
diff --git a/Userland/Libraries/LibGL/Tex/Texture2D.h b/Userland/Libraries/LibGL/Tex/Texture2D.h
index 41f4a90088..19f8e5fae9 100644
--- a/Userland/Libraries/LibGL/Tex/Texture2D.h
+++ b/Userland/Libraries/LibGL/Tex/Texture2D.h
@@ -19,10 +19,6 @@ namespace GL {
class Texture2D final : public Texture {
public:
- // FIXME: These shouldn't really belong here, they're context specific.
- static constexpr u16 MAX_TEXTURE_SIZE = 2048;
- static constexpr u8 LOG2_MAX_TEXTURE_SIZE = AK::log2(MAX_TEXTURE_SIZE);
-
virtual bool is_texture_2d() const override { return true; }
void download_texture_data(GLuint lod, GPU::ImageDataLayout output_layout, GLvoid* pixels);
diff --git a/Userland/Libraries/LibGL/Texture.cpp b/Userland/Libraries/LibGL/Texture.cpp
index fd880e072a..4a20ca6a7e 100644
--- a/Userland/Libraries/LibGL/Texture.cpp
+++ b/Userland/Libraries/LibGL/Texture.cpp
@@ -13,6 +13,17 @@
namespace GL {
+// Helper functions to handle type casting.
+static u16 max_texture_size(GPU::DeviceInfo const& device_info)
+{
+ return static_cast<u16>(device_info.max_texture_size);
+}
+
+static u8 log2_max_texture_size(GPU::DeviceInfo const& device_info)
+{
+ return static_cast<u8>(AK::log2(device_info.max_texture_size));
+}
+
void GLContext::gl_active_texture(GLenum texture)
{
RETURN_WITH_ERROR_IF(texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + m_device_info.num_texture_units, GL_INVALID_ENUM);
@@ -91,8 +102,8 @@ void GLContext::gl_copy_tex_image_2d(GLenum target, GLint level, GLenum internal
auto pixel_type_or_error = get_validated_pixel_type(target, internalformat, GL_NONE, GL_NONE);
RETURN_WITH_ERROR_IF(pixel_type_or_error.is_error(), pixel_type_or_error.release_error().code());
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
- RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + max_texture_size(m_device_info)) || height > (2 + max_texture_size(m_device_info)), GL_INVALID_VALUE);
if (!m_device_info.supports_npot_textures)
RETURN_WITH_ERROR_IF(!is_power_of_two(width) || !is_power_of_two(height), GL_INVALID_VALUE);
RETURN_WITH_ERROR_IF(border != 0, GL_INVALID_VALUE);
@@ -102,7 +113,7 @@ void GLContext::gl_copy_tex_image_2d(GLenum target, GLint level, GLenum internal
auto internal_pixel_format = pixel_format_for_internal_format(internalformat);
if (level == 0) {
- texture_2d->set_device_image(m_rasterizer->create_image(internal_pixel_format, width, height, 1, Texture2D::LOG2_MAX_TEXTURE_SIZE));
+ texture_2d->set_device_image(m_rasterizer->create_image(internal_pixel_format, width, height, 1, log2_max_texture_size(m_device_info)));
m_sampler_config_is_dirty = true;
}
@@ -131,8 +142,8 @@ void GLContext::gl_copy_tex_sub_image_2d(GLenum target, GLint level, GLint xoffs
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_copy_tex_sub_image_2d, target, level, xoffset, yoffset, x, y, width, height);
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
- RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + max_texture_size(m_device_info)) || height > (2 + max_texture_size(m_device_info)), GL_INVALID_VALUE);
auto texture_2d = m_active_texture_unit->texture_2d_target_texture();
VERIFY(!texture_2d.is_null());
@@ -211,7 +222,7 @@ void GLContext::gl_gen_textures(GLsizei n, GLuint* textures)
void GLContext::gl_get_tex_image(GLenum target, GLint level, GLenum format, GLenum type, void* pixels)
{
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
RETURN_WITH_ERROR_IF(format == GL_NONE || type == GL_NONE, GL_INVALID_ENUM);
auto pixel_type_or_error = get_validated_pixel_type(target, GL_NONE, format, type);
RETURN_WITH_ERROR_IF(pixel_type_or_error.is_error(), pixel_type_or_error.release_error().code());
@@ -247,7 +258,7 @@ void GLContext::gl_get_tex_parameter_integerv(GLenum target, GLint level, GLenum
RETURN_WITH_ERROR_IF(target != GL_TEXTURE_2D, GL_INVALID_ENUM);
// FIXME: support other parameter names
RETURN_WITH_ERROR_IF(pname < GL_TEXTURE_WIDTH || pname > GL_TEXTURE_HEIGHT, GL_INVALID_ENUM);
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
// FIXME: GL_INVALID_VALUE is generated if target is GL_TEXTURE_BUFFER and level is not zero
// FIXME: GL_INVALID_OPERATION is generated if GL_TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed internal format or on proxy targets
@@ -538,8 +549,8 @@ void GLContext::gl_tex_image_2d(GLenum target, GLint level, GLint internal_forma
auto pixel_type_or_error = get_validated_pixel_type(target, internal_format, format, type);
RETURN_WITH_ERROR_IF(pixel_type_or_error.is_error(), pixel_type_or_error.release_error().code());
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
- RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + max_texture_size(m_device_info)) || height > (2 + max_texture_size(m_device_info)), GL_INVALID_VALUE);
if (!m_device_info.supports_npot_textures)
RETURN_WITH_ERROR_IF(!is_power_of_two(width) || !is_power_of_two(height), GL_INVALID_VALUE);
RETURN_WITH_ERROR_IF(border != 0, GL_INVALID_VALUE);
@@ -555,7 +566,7 @@ void GLContext::gl_tex_image_2d(GLenum target, GLint level, GLint internal_forma
// To be spec compliant we should create the device image once the texture has become complete and is used for rendering the first time.
// All images that were attached before the device image was created need to be stored somewhere to be used to initialize the device image once complete.
auto internal_pixel_format = pixel_format_for_internal_format(internal_format);
- texture_2d->set_device_image(m_rasterizer->create_image(internal_pixel_format, width, height, 1, Texture2D::LOG2_MAX_TEXTURE_SIZE));
+ texture_2d->set_device_image(m_rasterizer->create_image(internal_pixel_format, width, height, 1, log2_max_texture_size(m_device_info)));
m_sampler_config_is_dirty = true;
}
@@ -688,8 +699,8 @@ void GLContext::gl_tex_sub_image_2d(GLenum target, GLint level, GLint xoffset, G
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
// We only support symbolic constants for now
- RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
- RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(level < 0 || level > log2_max_texture_size(m_device_info), GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + max_texture_size(m_device_info)) || height > (2 + max_texture_size(m_device_info)), GL_INVALID_VALUE);
// A 2D texture array must have been defined by a previous glTexImage2D operation
auto texture_2d = m_active_texture_unit->texture_2d_target_texture();
diff --git a/Userland/Libraries/LibGPU/DeviceInfo.h b/Userland/Libraries/LibGPU/DeviceInfo.h
index 36bb2a552b..d9c12ca334 100644
--- a/Userland/Libraries/LibGPU/DeviceInfo.h
+++ b/Userland/Libraries/LibGPU/DeviceInfo.h
@@ -16,6 +16,7 @@ struct DeviceInfo final {
unsigned num_texture_units;
unsigned num_lights;
unsigned max_clip_planes;
+ unsigned max_texture_size;
float max_texture_lod_bias;
u8 stencil_bits;
bool supports_npot_textures;
diff --git a/Userland/Libraries/LibSoftGPU/Config.h b/Userland/Libraries/LibSoftGPU/Config.h
index 93aaac9077..a87f6e299c 100644
--- a/Userland/Libraries/LibSoftGPU/Config.h
+++ b/Userland/Libraries/LibSoftGPU/Config.h
@@ -20,6 +20,7 @@ static constexpr bool ENABLE_STATISTICS_OVERLAY = false;
static constexpr int MILLISECONDS_PER_STATISTICS_PERIOD = 500;
static constexpr int NUM_LIGHTS = 8;
static constexpr int MAX_CLIP_PLANES = 6;
+static constexpr int MAX_TEXTURE_SIZE = 2048;
static constexpr float MAX_TEXTURE_LOD_BIAS = 2.f;
static constexpr int SUBPIXEL_BITS = 4;
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 4c3669bc0a..2001e9b704 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -801,6 +801,7 @@ GPU::DeviceInfo Device::info() const
.num_texture_units = GPU::NUM_TEXTURE_UNITS,
.num_lights = NUM_LIGHTS,
.max_clip_planes = MAX_CLIP_PLANES,
+ .max_texture_size = MAX_TEXTURE_SIZE,
.max_texture_lod_bias = MAX_TEXTURE_LOD_BIAS,
.stencil_bits = sizeof(GPU::StencilType) * 8,
.supports_npot_textures = true,