Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad0d005
Experiment[glformats]: different format handling for no-data textures
artdeell May 21, 2025
0a05676
Feat[glformats]: refactor workarounds, add color renderability workar…
artdeell May 21, 2025
c1a2a5d
Fix[main]: re-enable swizzle
artdeell May 22, 2025
a0891c0
Fix[glsloptimizer]: explicitly enable GL_NV_shader_noperspective_inte…
artdeell May 22, 2025
00f62a2
Feat[main]: add improved wrappings for glTexBuffer(Range)
artdeell May 22, 2025
e6bff74
Fix[ir_print]: replace f2i/f2u/u2f/i2f binops with proper functions
artdeell May 22, 2025
54fe070
Update ir_print_glsl_visitor.cpp
artdeell May 22, 2025
6fe876e
Feat[shader_wrapper]: implement fragout pos insertion
artdeell May 22, 2025
39b9b70
Fix[glformats]: always use 32-bit depth to avoid far Z-fighting issues
artdeell Jul 8, 2025
abc87f6
Fix[ir_print]: move processed_uniform_blocks into global_print_tracker
artdeell Jul 8, 2025
6438531
Feat[ir_print]: impllement in/out qualifier printing for geometry and…
artdeell Jul 8, 2025
5eac88a
Feat[ir_print]: add NaN checks (can be enabled with env var)
artdeell Jul 8, 2025
d2087c2
Fix[ir_print]: print high precision when sampler2DShadow is used
artdeell Jul 9, 2025
c41d0b6
Test[texsubimage]: Replace with framebuffer blit
artdeell Jul 9, 2025
09d8e56
Feat[randerer]: add toggles for debug messages and hiding buffer storage
artdeell Jul 12, 2025
539fc08
Feat[main]: add flag to force coherence
artdeell Jul 12, 2025
58cdf69
Feat[renderer]: shrink binary size, make LTW_NEVER_FLUSH_BUFFERS default
artdeell Jul 13, 2025
5e6cc9f
Feat[buffer_storage]: force dynamic storage buffers to be coherent by…
artdeell Jul 14, 2025
30876b2
Feat[ir_print_glsl_visitor]: better _ltw_removenan implementation
artdeell Jul 15, 2025
b1bf616
Chore[renderer]: Update copyright and vendor string
artdeell Jul 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ltw/src/main/tinywrapper/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ LOCAL_CFLAGS += -DHAVE_OPENGL
LOCAL_CFLAGS += -DHAVE_OPENGL_ES_1
LOCAL_CFLAGS += -DHAVE_OPENGL_ES_2
LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_LDFLAGS := -ffunction-sections -fdata-sections
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
Expand All @@ -402,9 +403,13 @@ LOCAL_SRC_FILES := \
vertexattrib.c \
swizzle.c \
license_notice.c \
env.c \
vgpu_shaderconv/shaderconv.c \
unordered_map/unordered_map.c \
unordered_map/int_hash.c
LOCAL_STATIC_LIBRARIES := glsl_optimizer
LOCAL_LDFLAGS := -ffunction-sections -fdata-sections -Wl,--version-script=$(LOCAL_PATH)/version.script
# Comment for debugging
LOCAL_LDFLAGS += -flto -Wl,--gc-sections
LOCAL_LDLIBS := -llog -lEGL
include $(BUILD_SHARED_LIBRARY)
2 changes: 1 addition & 1 deletion ltw/src/main/tinywrapper/basevertex.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/
#include <GLES3/gl31.h>
Expand Down
2 changes: 1 addition & 1 deletion ltw/src/main/tinywrapper/basevertex.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand Down
11 changes: 9 additions & 2 deletions ltw/src/main/tinywrapper/egl.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/
#include "egl.h"
#include "unordered_map/int_hash.h"
#include "string_utils.h"
#include "env.h"
#include <string.h>

thread_local context_t *current_context;
Expand Down Expand Up @@ -110,7 +111,12 @@ void build_extension_string(context_t* context) {
int length;
init_extra_extensions(context, &length);
if(context->buffer_storage) {
add_extra_extension(context, &length, "GL_ARB_buffer_storage");
if(!env_istrue("LTW_HIDE_BUFFER_STORAGE"))
add_extra_extension(context, &length, "GL_ARB_buffer_storage");
else printf("LTW: The buffer storage extension is hidden.\n");
}
if(context->buffer_texture_ext || context->es32) {
add_extra_extension(context, &length, "ARB_texture_buffer_object");
}
// More extensions are possible, but will need way more wraps and tracking.
fin_extra_extensions(context, length);
Expand Down Expand Up @@ -139,6 +145,7 @@ static void find_esversion(context_t* context) {

const char* extensions = (const char*) es3_functions.glGetString(GL_EXTENSIONS);
if(strstr(extensions, "GL_EXT_buffer_storage")) context->buffer_storage = true;
if(strstr(extensions, "GL_EXT_texture_buffer")) context->buffer_texture_ext = true;

build_extension_string(context);

Expand Down
5 changes: 3 additions & 2 deletions ltw/src/main/tinywrapper/egl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand Down Expand Up @@ -60,7 +60,8 @@ typedef struct {
typedef struct {
EGLContext phys_context;
bool context_rdy;
bool es31, es32, buffer_storage;
bool es31, es32, buffer_storage, buffer_texture_ext;
bool force_depth32_fallback;
GLint shader_version;
basevertex_renderer_t basevertex;
GLuint multidraw_element_buffer;
Expand Down
17 changes: 17 additions & 0 deletions ltw/src/main/tinywrapper/env.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Created by maks on 12.07.2025.
//
#include "env.h"
#include <stdlib.h>
#include "libraryinternal.h"

INTERNAL bool env_istrue_d(const char* name, bool _default) {
const char* env = getenv(name);
if(env == NULL) return _default;
return *env == '1';
}

INTERNAL bool env_istrue(const char* name) {
const char* env = getenv(name);
return env != NULL && *env == '1';
}
13 changes: 13 additions & 0 deletions ltw/src/main/tinywrapper/env.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by maks on 12.07.2025.
//

#ifndef GL4ES_WRAPPER_ENV_H
#define GL4ES_WRAPPER_ENV_H

#include <stdbool.h>

bool env_istrue(const char* name);
bool env_istrue_d(const char* name, bool _default);

#endif //GL4ES_WRAPPER_ENV_H
8 changes: 6 additions & 2 deletions ltw/src/main/tinywrapper/es3_extended.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand All @@ -11,4 +11,8 @@ GLESFUNC(glMultiDrawElementsEXT,PFNGLMULTIDRAWELEMENTSEXTPROC)
GLESFUNC(glGetTexLevelParameteriv,PFNGLGETTEXLEVELPARAMETERIVPROC)
GLESFUNC(glGetTexLevelParameterfv,PFNGLGETTEXLEVELPARAMETERFVPROC)
GLESFUNC(glDrawElementsBaseVertex, PFNGLDRAWELEMENTSBASEVERTEXPROC)
GLESFUNC(glBufferStorageEXT, PFNGLBUFFERSTORAGEEXTPROC)
GLESFUNC(glBufferStorageEXT, PFNGLBUFFERSTORAGEEXTPROC)
GLESFUNC(glTexBuffer, PFNGLTEXBUFFERPROC);
GLESFUNC(glTexBufferRange, PFNGLTEXBUFFERRANGEPROC);
GLESFUNC(glTexBufferEXT, PFNGLTEXBUFFEREXTPROC)
GLESFUNC(glTexBufferRangeEXT, PFNGLTEXBUFFERRANGEEXTPROC)
2 changes: 1 addition & 1 deletion ltw/src/main/tinywrapper/es3_functions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand Down
14 changes: 12 additions & 2 deletions ltw/src/main/tinywrapper/es3_overrides.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/
void glClearDepth(double depth);
Expand Down Expand Up @@ -40,6 +40,11 @@ GLESOVERRIDE(glGetTexLevelParameteriv)
GLESOVERRIDE(glGetTexLevelParameterfv)
GLESOVERRIDE(glCreateShader)
GLESOVERRIDE(glDeleteShader)
GLESOVERRIDE(glCreateProgram)
GLESOVERRIDE(glDeleteProgram)
GLESOVERRIDE(glLinkProgram)
GLESOVERRIDE(glAttachShader)
GLESOVERRIDE(glGetShaderiv)
GLESOVERRIDE(glShaderSource)
GLESOVERRIDE(glTexImage2D)
GLESOVERRIDE(glDebugMessageControl)
Expand All @@ -61,6 +66,7 @@ GLESOVERRIDE(glFramebufferTextureLayer)
GLESOVERRIDE(glFramebufferRenderbuffer)
GLESOVERRIDE(glGetFramebufferAttachmentParameteriv)
GLESOVERRIDE(glDrawBuffers)
GLESOVERRIDE(glDrawBuffer)
GLESOVERRIDE(glClearBufferiv)
GLESOVERRIDE(glClearBufferuiv)
GLESOVERRIDE(glClearBufferfv)
Expand Down Expand Up @@ -121,4 +127,8 @@ GLESOVERRIDE(glTexParameteriv)
GLESOVERRIDE(glTexParameterIiv)
GLESOVERRIDE(glTexParameterIuiv)
GLESOVERRIDE(glRenderbufferStorage)
GLESOVERRIDE(glGetError)
GLESOVERRIDE(glGetError)
GLESOVERRIDE(glTexBuffer)
GLESOVERRIDE(glTexBufferRange)
GLESOVERRIDE(glMapBufferRange)
GLESOVERRIDE(glFlushMappedBufferRange)
2 changes: 1 addition & 1 deletion ltw/src/main/tinywrapper/framebuffer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand Down
79 changes: 64 additions & 15 deletions ltw/src/main/tinywrapper/glformats.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

#include <stdbool.h>
#include "egl.h"
#include "glformats.h"
#include "libraryinternal.h"
#include "GL/gl.h"
Expand Down Expand Up @@ -71,12 +72,58 @@ static GLint pick_rg_internalformat(GLenum* type, bool* convert) {
}
}

void pick_color_renderable_format(GLint* internalformat, GLenum* type, GLenum* format) {

}
void pick_format(GLint *internalformat, GLenum* type, GLenum* format) {
// Workarounds!
switch (*internalformat) {
// Two legacy GL formats. From testing, OptiFine wants these to be floats.
case GL_RGBA12:
case GL_RGBA16:
*internalformat = GL_RGBA16F;
break;
// Always use 32-bit float depth for GL_DEPTH_COMPONENT, because the 16-bit depth buffer
// causes z-fighting in the distance
case GL_DEPTH_COMPONENT:
*internalformat = GL_DEPTH_COMPONENT32F;
break;
// This appears to be one of the legacy formats from the FPE days, and is not even
// listed in the format tables in 3.3 core. Still, MC uses it for the depth buffers.
case GL_DEPTH_COMPONENT32:
*internalformat = GL_DEPTH_COMPONENT32F;
break;
// Unsized depth-stencil. Not sure what uses it but we'll fall back to 24-bit + 8-bit stencil
case GL_DEPTH_STENCIL:
*internalformat = GL_DEPTH24_STENCIL8;
break;
// Color-renderability workarounds. Yes, those probably decrease performance but they sure do improve compatibility with shaderpacks!
// Ideally these should only be used on framebuffers, but whatever.
// In GL, the SNORM formats are color-renderable and support signed normalized values from -1 to 1.
// Sadly, the only alternative format with the same capabilities that *is* color-renderable in ES is 16-bit float.
// So, switch to that.
case GL_R8_SNORM:
*internalformat = GL_R16F;
case GL_RG8_SNORM:
*internalformat = GL_RG16F;
case GL_RGBA8_SNORM:
*internalformat = GL_RGBA16F;
break;
// Fun fact: the only color renderable formats in GLES that have 3 components are
// GL_R11F_G11F_B10F and GL_RGB8. And only GL_R11F_G11F_B10F supports signed values.
case GL_RGB8I:
case GL_RGB16I:
case GL_RGB32I:
case GL_RGB8_SNORM:
case GL_RGB12:
case GL_RGB16:
case GL_RGB16F:
case GL_RGB32F:
*internalformat = GL_R11F_G11F_B10F;
case GL_RGB8UI:
*internalformat = GL_RGB8;
break;
}

void pick_format(GLint internalformat, GLenum* type, GLenum* format) {
switch (internalformat) {
// GLES 3.2 format table
switch (*internalformat) {
// Unsized formats. In this case we always prefer the "byte" versions of them (meaning 32bit/24bit color)
case GL_RGB: *format=GL_RGB; *type = GL_UNSIGNED_BYTE; break;
case GL_RGBA: *format=GL_RGBA; *type = GL_UNSIGNED_BYTE; break;
Expand Down Expand Up @@ -133,25 +180,33 @@ void pick_format(GLint internalformat, GLenum* type, GLenum* format) {
case GL_RGBA16I: *format=GL_RGBA_INTEGER; *type=GL_SHORT; break;
case GL_RGBA32I: *format=GL_RGBA_INTEGER; *type=GL_INT; break;
case GL_RGBA32UI: *format=GL_RGBA_INTEGER; *type=GL_UNSIGNED_INT; break;
// Sized depth formats. Unsized formats handled before this function
// Sized depth formats
case GL_DEPTH_COMPONENT16: *format = GL_DEPTH_COMPONENT; *type = GL_UNSIGNED_SHORT; break;
case GL_DEPTH_COMPONENT24: *format = GL_DEPTH_COMPONENT; *type = GL_UNSIGNED_INT; break;
case GL_DEPTH_COMPONENT32F: *format = GL_DEPTH_COMPONENT; *type = GL_FLOAT; break;
case GL_DEPTH24_STENCIL8: *format = GL_DEPTH_STENCIL; *type = GL_UNSIGNED_INT_24_8; break;
case GL_DEPTH32F_STENCIL8: *format = GL_DEPTH_STENCIL; *type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV; break;
case GL_STENCIL_INDEX8: *format = GL_STENCIL_INDEX; *type = GL_UNSIGNED_BYTE; break;
default:
printf("LTW: pick_format fallthrough: %x\n", *internalformat);
}

}


INTERNAL void pick_internalformat(GLint *internalformat, GLenum* type, GLenum* format, GLvoid const** data) {
if(*data == NULL) {
// Appears that desktop GL completely discards type and format without data. Pick a correct (sized if unsized is unavailable)
// format for the d
pick_format(internalformat, type, format);
return;
}
// Compared to OpenGL ES, desktop OpenGL implicitly supports way more depth/RGB formats without explicit sizing.
// This function converts appropriate unsized formats to sized ones according to the type.
bool convert_data;
switch (*internalformat) {
case GL_DEPTH_COMPONENT32:
// 1.21.5 workaround: fix internalformat (not handled in ES drivers cause it's from GL 1.4)
// Work around by selecting the equivalent type (for float) or 24-bit (for int)
// Select the equivalent type (32f for float, 24 for int)
if(*type == GL_FLOAT) {
*internalformat = GL_DEPTH_COMPONENT32F;
} else {
Expand Down Expand Up @@ -264,12 +319,6 @@ INTERNAL void pick_internalformat(GLint *internalformat, GLenum* type, GLenum* f
}
break;
}
// GL applications do not have to supply valid data to "type" and "format" fields if they are not uploading any data
// So automatically pick the best options from ones available.
if(*data == NULL) {
pick_format(*internalformat, type, format);
return;
}
if(*data != NULL && convert_data) {
printf("LTW: we don't support format conversion at the moment. Sorry!\n");
}
Expand Down
2 changes: 1 addition & 1 deletion ltw/src/main/tinywrapper/glformats.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created by: artDev
* Copyright (c) 2025 artDev, SerpentSpirale, PojavLauncherTeam, Digital Genesis LLC.
* Copyright (c) 2025 artDev, SerpentSpirale, CADIndie.
* For use under LGPL-3.0
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ void GlslConvert::InitContext(struct gl_context* ctx, ApiTarget api, int vGlslVe
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxAtomicBuffers = 8;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxAtomicCounters = 8;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxImageUniforms = 8;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformBlocks = 12;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformBlocks = 64;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformBlocks = 64;
ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformBlocks = 64;

switch (ctx->Const.GLSLVersion) {
case 100:
Expand Down Expand Up @@ -505,23 +507,20 @@ void GlslConvert::InitContext(struct gl_context* ctx, ApiTarget api, int vGlslVe
ctx->Const.Program[MESA_SHADER_VERTEX].MaxCombinedUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */
ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 64;
ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformBlocks = 4;

ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits = 16;
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxCombinedUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents =
ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents;
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents = 128;
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformBlocks = 4;

ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 16;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxCombinedUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents =
ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformBlocks = 4;

ctx->Const.MaxCombinedTextureImageUnits =
ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits
Expand Down
Loading