Skip to content

Commit 0315f31

Browse files
committed
Merge pull request #98327 from clayjohn/revert-shader-float
Revert "Fix GPUParticles are not rendered for older AMD GPUs with OpenGL+Angle"
2 parents be70c2f + 940e9c2 commit 0315f31

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

drivers/gles3/shader_gles3.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ void ShaderGLES3::_build_variant_code(StringBuilder &builder, uint32_t p_variant
168168
builder.append("#version 300 es\n");
169169
}
170170

171+
if (GLES3::Config::get_singleton()->polyfill_half2float) {
172+
builder.append("#define USE_HALF2FLOAT\n");
173+
}
174+
171175
for (int i = 0; i < specialization_count; i++) {
172176
if (p_specialization & (uint64_t(1) << uint64_t(i))) {
173177
builder.append("#define " + String(specializations[i].name) + "\n");

drivers/gles3/shaders/stdlib_inc.glsl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
21
// Compatibility renames. These are exposed with the "godot_" prefix
32
// to work around two distinct Adreno bugs:
43
// 1. Some Adreno devices expose ES310 functions in ES300 shaders.
54
// Internally, we must use the "godot_" prefix, but user shaders
65
// will be mapped automatically.
76
// 2. Adreno 3XX devices have poor implementations of the other packing
8-
// functions, so we just use our own everywhere to keep it simple.
7+
// functions, so we just use our own there to keep it simple.
98

9+
#ifdef USE_HALF2FLOAT
1010
// Floating point pack/unpack functions are part of the GLSL ES 300 specification used by web and mobile.
11+
// It appears to be safe to expose these on mobile, but when running through ANGLE this appears to break.
1112
uint float2half(uint f) {
12-
uint b = f + uint(0x00001000);
13-
uint e = (b & uint(0x7F800000)) >> 23;
14-
uint m = b & uint(0x007FFFFF);
15-
return (b & uint(0x80000000)) >> uint(16) | uint(e > uint(112)) * ((((e - uint(112)) << uint(10)) & uint(0x7C00)) | m >> uint(13)) | (uint(e < uint(113)) & uint(e > uint(101))) * ((((uint(0x007FF000) + m) >> (uint(125) - e)) + uint(1)) >> uint(1)) | uint(e > uint(143)) * uint(0x7FFF);
13+
uint e = f & uint(0x7f800000);
14+
if (e <= uint(0x38000000)) {
15+
return uint(0);
16+
} else {
17+
return ((f >> uint(16)) & uint(0x8000)) |
18+
(((e - uint(0x38000000)) >> uint(13)) & uint(0x7c00)) |
19+
((f >> uint(13)) & uint(0x03ff));
20+
}
1621
}
1722

1823
uint half2float(uint h) {
19-
uint e = (h & uint(0x7C00)) >> uint(10);
20-
uint m = (h & uint(0x03FF)) << uint(13);
21-
uint v = m >> uint(23);
22-
return (h & uint(0x8000)) << uint(16) | uint(e != uint(0)) * ((e + uint(112)) << uint(23) | m) | (uint(e == uint(0)) & uint(m != uint(0))) * ((v - uint(37)) << uint(23) | ((m << (uint(150) - v)) & uint(0x007FE000)));
24+
uint h_e = h & uint(0x7c00);
25+
return ((h & uint(0x8000)) << uint(16)) | uint((h_e >> uint(10)) != uint(0)) * (((h_e + uint(0x1c000)) << uint(13)) | ((h & uint(0x03ff)) << uint(13)));
2326
}
2427

2528
uint godot_packHalf2x16(vec2 v) {
@@ -50,6 +53,17 @@ vec2 godot_unpackSnorm2x16(uint p) {
5053
return clamp((v - 32767.0) * vec2(0.00003051851), vec2(-1.0), vec2(1.0));
5154
}
5255

56+
#define packHalf2x16 godot_packHalf2x16
57+
#define unpackHalf2x16 godot_unpackHalf2x16
58+
#define packUnorm2x16 godot_packUnorm2x16
59+
#define unpackUnorm2x16 godot_unpackUnorm2x16
60+
#define packSnorm2x16 godot_packSnorm2x16
61+
#define unpackSnorm2x16 godot_unpackSnorm2x16
62+
63+
#endif // USE_HALF2FLOAT
64+
65+
// Always expose these as they are ES310 functions and not available in ES300 or GLSL 330.
66+
5367
uint godot_packUnorm4x8(vec4 v) {
5468
uvec4 uv = uvec4(round(clamp(v, vec4(0.0), vec4(1.0)) * 255.0));
5569
return uv.x | (uv.y << uint(8)) | (uv.z << uint(16)) | (uv.w << uint(24));
@@ -73,9 +87,3 @@ vec4 godot_unpackSnorm4x8(uint p) {
7387
#define unpackUnorm4x8 godot_unpackUnorm4x8
7488
#define packSnorm4x8 godot_packSnorm4x8
7589
#define unpackSnorm4x8 godot_unpackSnorm4x8
76-
#define packHalf2x16 godot_packHalf2x16
77-
#define unpackHalf2x16 godot_unpackHalf2x16
78-
#define packUnorm2x16 godot_packUnorm2x16
79-
#define unpackUnorm2x16 godot_unpackUnorm2x16
80-
#define packSnorm2x16 godot_packSnorm2x16
81-
#define unpackSnorm2x16 godot_unpackSnorm2x16

drivers/gles3/storage/config.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ Config::Config() {
231231
} else if (rendering_device_name == "PowerVR Rogue GE8320") {
232232
disable_transform_feedback_shader_cache = true;
233233
}
234+
235+
if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
236+
polyfill_half2float = false;
237+
}
238+
#ifdef WEB_ENABLED
239+
polyfill_half2float = false;
240+
#endif
234241
}
235242

236243
Config::~Config() {

drivers/gles3/storage/config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ class Config {
9595
bool multiview_supported = false;
9696
bool external_texture_supported = false;
9797

98-
// Adreno 3XX compatibility
99-
bool disable_particles_workaround = false; // set to 'true' to disable 'GPUParticles'
98+
// Adreno 3XX compatibility.
99+
bool disable_particles_workaround = false; // Set to 'true' to disable 'GPUParticles'.
100100
bool flip_xy_workaround = false;
101101

102-
// PowerVR GE 8320 workaround
102+
// PowerVR GE 8320 workaround.
103103
bool disable_transform_feedback_shader_cache = false;
104104

105+
// ANGLE shader workaround.
106+
bool polyfill_half2float = true;
107+
105108
#ifdef ANDROID_ENABLED
106109
PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC eglFramebufferTextureMultiviewOVR = nullptr;
107110
PFNGLTEXSTORAGE3DMULTISAMPLEPROC eglTexStorage3DMultisample = nullptr;

0 commit comments

Comments
 (0)