Chris Healy
9ed5dcdc27
GPU: Use inversesqrt for light distance and half-vector calculations
...
Replace length()/normalize() with inversesqrt() pattern for better
performance on mobile GPUs. The inversesqrt instruction is a single
hardware operation, while length() requires sqrt(dot()) and normalize()
requires inversesqrt internally plus a multiply.
Changes:
1. Light distance calculation:
Before: distance = length(toLight); toLight /= distance;
After: distSq = dot(toLight, toLight);
invDist = inversesqrt(distSq);
distance = distSq * invDist;
toLight *= invDist;
2. Specular half-vector normalization:
Before: ldot = dot(normalize(toLight + vec3(0,0,1)), worldnormal);
After: halfVec = toLight + vec3(0,0,1);
halfInvLen = inversesqrt(dot(halfVec, halfVec));
ldot = dot(halfVec, worldnormal) * halfInvLen;
Also reuses distSq in attenuation calculation to avoid recomputing
distance*distance.
Offline shader compiler results (vertex shader with 4-light ubershader):
Mali (malioc):
G31 (Bifrost): 44.90 -> 40.50 cycles (-9.8%)
G52 (Bifrost): 14.97 -> 13.50 cycles (-9.8%)
G310 (Valhall): 13.88 -> 12.88 cycles (-7.2%)
G57 (Valhall): 7.60 -> 6.97 cycles (-8.3%)
PowerVR (Profiling Compilers):
Series 8 GE8300: 322 -> 302 ALU cycles (-6.2%)
Series 9 GM9445: 296 -> 280 ALU cycles (-5.4%)
Series B BXM: 560 -> 540 instructions (-3.6%)
Signed-off-by: Chris Healy <cphealy@gmail.com >
2026-03-08 19:13:41 -07:00
Henrik Rydgård
6cfea96e58
Remove D3D9 support, to make future changes easier
2025-06-10 15:07:16 +02:00
Henrik Rydgård
df6ed8cfc9
Do some cleanup of #includes in GPU
2024-12-18 13:57:26 +01:00
Henrik Rydgård
702e77454a
Hardware transform: Clamp the specular coefficient to 0.0 before taking the power.
2024-09-25 21:09:13 +02:00
Lubos
3154a5fac1
OpenXR - VR camera features on any platform
2024-08-07 09:25:12 +02:00
Henrik Rydgård
fab034d866
Fix minor difference between ubershader and specialized vshaders
2024-07-24 20:50:33 +02:00
Lubos
a9b5a4739e
Fix math of simple stereo
2024-06-25 16:06:03 +02:00
Luboš V
27152b1e47
OpenXR - Forgotten usages
2024-06-24 19:43:17 +02:00
Luboš V
dd9bc42b0a
OpenXR - Remove multiview from shader
2024-06-24 19:24:46 +02:00
Lubos
7b089effa0
OpenXR - Use single VR projection matrix
2024-06-03 18:29:06 +02:00
Henrik Rydgård
e3177ac870
Make some global string pointers const, not just the strings.
...
Minor cleanup.
2023-12-29 14:09:45 +01:00
Henrik Rydgård
0f3dca5cea
Revert a bad "optimization" I made in #18587
2023-12-25 12:03:09 +01:00
Henrik Rydgård
2238fab601
Minor lighting optimization in vshader
2023-12-20 14:47:49 +01:00
Herman Semenov
0748ce610f
[GPU/Common/D3D11/Directx9/GLES/Vulkan] Using reserve if possible
2023-12-15 14:08:22 +03:00
Henrik Rydgård
b42670cf59
Manually revert the rest of the lmode optimization
2023-05-09 18:44:24 +02:00
Henrik Rydgård
0babac5c5f
Manually revert "Remove LM flag from vshader too" ( #16718 )
...
Reverts #16718
Though maybe we can keep this one? Let's see.
2023-05-09 18:44:18 +02:00
Henrik Rydgård
f42c682d34
Revert "Merge pull request #16628 from hrydgard/remove-fog-fshader-flag"
...
This reverts commit 10dee90c83 , reversing
changes made to 34c11c8acf .
2023-05-08 22:01:38 +02:00
Unknown W. Brackets
9fcc1509e4
GPU: Correct depth clip/cull for zero scale.
2023-03-05 08:51:45 -08:00
Unknown W. Brackets
0f3f2e361f
GLES: More uint const paranoia.
...
We don't use indexing on GLES now, but better to stay consistent.
2023-01-12 17:41:55 -08:00
Henrik Rydgård
86f34c52a4
Revert bad shader optimization
2023-01-12 00:30:41 +01:00
Henrik Rydgård
ca63bb1e5b
Even more optimization/cleanup. Don't need to check ldot that we already know is >= 0.0.
2023-01-11 19:34:58 +01:00
Henrik Rydgård
965007d65b
Tighten up the lighting shader code a bit, hopefully eliminating a branch or two.
2023-01-11 19:29:02 +01:00
Henrik Rydgård
4c2a41cc83
Break out the attenuation term, too
2023-01-11 19:29:02 +01:00
Henrik Rydgård
a508f7e345
Shave a few instructions from lighting shaders by prenormalizing the light dir used for spotlights
2023-01-11 19:29:02 +01:00
Henrik Rydgård
7b62b4626f
Comment fixes
2023-01-11 15:29:52 +01:00
Henrik Rydgård
3b46409350
Vertex shaders: On platforms with uniform buffers, use indexing and loop for real over the lights.
...
Strangely, greatly speeds up pipeline creation on PowerVR.
2023-01-11 15:24:56 +01:00
Henrik Rydgård
3d376b0ab7
Remove the rather redundant DoTexture flag from vshaders.
...
Slightly reduces the number of unique vertex shaders but doesn't do much
for the pipeline count, as the fragment shader has a tex flag. Still
worth doing for the simplification.
2023-01-11 14:16:46 +01:00
Unknown W. Brackets
f09c09caa8
GLES: Avoid GLSL redefinition error.
2023-01-08 22:30:15 -08:00
Unknown W. Brackets
f49f7c6371
D3D9: Force branch usage for fog compute.
...
When using `[flatten]`/default, it picks the wrong value, seemingly always
taking the else case (even if the condition is changed or reversed.)
2023-01-06 17:25:04 -08:00
Unknown W. Brackets
81f4a76ac9
GPU: Don't bother with fog uniform in sw transform.
2023-01-06 17:24:44 -08:00
Unknown W. Brackets
f3acdb9da8
GLES: Avoid a shader constant error.
...
Some Adreno drivers interpret 0u as an integer.
2023-01-05 17:56:58 -08:00
Henrik Rydgård
a58bf45540
Removes LM flag from vshader in the common case, if ubershader is enabled.
2023-01-05 13:09:49 +01:00
Henrik Rydgård
4e30c5c0c6
Unbreak fog, oops.
...
Fixes #16722
2023-01-04 13:01:00 +01:00
Henrik Rydgård
b84e24cb89
Invert the nesting of specularIsZero and lmode conditions in VS.
2023-01-04 11:04:24 +01:00
Henrik Rydgård
ae383147db
Minor simplification in VS
2023-01-04 11:04:24 +01:00
Henrik Rydgård
18d00b0718
Remove lmode flag bit from fragment and geometry shaders
2023-01-04 11:04:23 +01:00
Henrik Rydgård
5cae5615ea
Use more unusual values as "fog-disabled".
2023-01-04 10:14:12 +01:00
Henrik Rydgård
26c748f959
Make fog-enable driven by uniform instead of fragment shader flag bit
2023-01-04 10:14:11 +01:00
Unknown W. Brackets
86d748fa0c
GLES: Use uint for uint shift amounts.
...
This seems to cause trouble for some Adreno drivers as well.
2023-01-02 14:37:38 -08:00
Unknown W. Brackets
2b4a182b46
GLES: Use hex for uint constants.
...
Apparently some Adreno drivers have issues (fixed in 2014):
https://developer.qualcomm.com/forum/qdn-forums/maximize-hardware/mobile-gaming-graphics-adreno/27945
2023-01-02 13:13:48 -08:00
Henrik Rydgård
26884150d7
Remove the 0th descriptor set, move everything else back to 0
2022-12-16 13:05:40 +01:00
Henrik Rydgård
7950a00c14
Headless buildfix. Crashfix in shader generator test.
2022-12-01 22:49:00 +01:00
Lubos
d466ae161a
OpenXR - HUD max scale fixed
2022-11-28 19:46:46 +01:00
Henrik Rydgård
7eee7f2573
Fix shader debug description issue.
2022-11-23 15:41:20 +01:00
Henrik Rydgård
8f103f3f47
Extract the Vulkan descriptor binding cleanup from #16345
2022-11-21 20:30:20 +01:00
Unknown W. Brackets
eae85836c9
GPU: Add a small error-compensation to depth clip.
...
This was causing a depth that should've calculated as zero to be clipped,
because the multiply and division resulted in a value that was off by
about 2 / pow(2, 24) in the negative direction.
2022-11-12 20:01:46 -08:00
Lubos
72d197fc47
Revert "OpenXR - Disable range culling properly"
...
This reverts commit d1dabd40ee .
2022-11-10 18:44:11 +01:00
Henrik Rydgård
c6084c16c3
Fix GLSL compilation issues on really old Adreno drivers.
...
They don't seem to accept unsigned integers as switch cases.
Fixes some stuff in #16295 , not sure if all of it.
2022-11-08 22:59:43 +01:00
Henrik Rydgård
87bd7aaccc
Merge pull request #16356 from lvonasek/cleanup_camera_control
...
OpenXR - Camera adjust using any controller
2022-11-08 12:28:44 +01:00
Henrik Rydgård
4e8f97d64d
Output shader descriptions directly in the source code
2022-11-08 00:21:08 +01:00