46 Commits

Author SHA1 Message Date
Henrik Rydgård 83d82dcf66 Shader depal: Don't generate a big switch in the shader, generate specialized shaders instead. 2026-06-10 12:22:11 +02:00
Henrik Rydgård f55adcc3a1 Apply a small depth bias to simulate rounding of Z. Fix min/max clip plane math 2026-05-30 19:07:58 +02:00
Henrik Rydgård cb2f5bf945 UI shaders: Convert the first shader to being generated 2026-05-18 14:11:39 +02:00
Henrik Rydgård 8dc3e8ed14 Add depthMinusOneToOne to specify GL's ridiculous behavior 2026-05-14 22:13:04 +02:00
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 4d6905672e Bunch more linting 2024-10-10 11:57:10 +02: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 96a5c52037 Vulkan: Reserve descriptor set 0 for frame-global data, move everything else to set 1 2022-10-28 09:39:56 +02:00
Henrik Rydgård 15d4495f76 Pass shadergen tests 2022-10-27 11:05:59 +02:00
Henrik Rydgård 2a1526c352 Address feedback 2022-10-27 11:05:59 +02:00
Henrik Rydgård 390a136cb5 Stereo now works through shader depal too 2022-10-27 11:05:59 +02:00
Henrik Rydgård 91259aaad7 Always use array textures for framebuffers in Vulkan for simplicity. 2022-10-27 11:05:58 +02:00
Henrik Rydgård 2bea495981 wip 2022-10-27 11:05:58 +02:00
Henrik Rydgård 80e1db07a7 Minor ShaderWriter refactor, prep for later changes 2022-10-24 17:45:18 +02:00
Henrik Rydgård ecf2797173 Minor refactor of ShaderWriter flags. Extracted from the stereo PR 2022-10-23 21:57:01 +02:00
Henrik Rydgård 3af86ec6f7 Make it possible to specify extensions for Vulkan in the ShaderWriter 2022-10-22 17:46:57 +02:00
Unknown W. Brackets 87171cef98 GPU: Add geometry path for shader writer.
Not yet used.
2022-10-01 12:45:43 -07:00
Unknown W. Brackets 59a489f883 Draw: Add COLOR1 semantic. 2022-10-01 12:14:46 -07:00
Henrik Rydgård 3e7f6b57aa Shadergen issues found by the test 2022-09-11 16:52:33 +02:00
Henrik Rydgård 9bd8b11bf8 Implement shader depal for D3D11. 2022-09-11 13:41:17 +02:00
Henrik Rydgård ca24f1b9aa Fixes for D3D11 2022-08-21 09:58:58 +02:00
Henrik Rydgård 31fe0fc39e Remove some unnecessary bool returns. 2022-08-16 11:23:34 +02:00
Henrik Rydgård 252550fbd2 Enable framebuffer depth blits through raster. Fixes games like Jeanne D'Arc on D3D9. 2022-08-09 20:00:32 +02:00
Henrik Rydgård 852c395fb7 Texcoord attrs must be called a_texcoord0, this should be fixed. Oh well.
Also small fix for depth in float-depal.
2022-08-09 16:07:02 +02:00
Henrik Rydgård 83fd8a2fd8 Convert depal shaders to use the ShaderWriter. Add tests for depal shaders. 2022-08-09 15:32:27 +02:00
Henrik Rydgård 92a3d45340 Lock out shaderDepal from D3D for now, will implement later. 2022-08-06 18:27:03 +02:00
Henrik Rydgård 8aebf0dca4 Port the OpenGL depal path to thin3d 2022-08-06 18:27:02 +02:00
Henrik Rydgård b71c745275 ShaderWriter: Fix GLSL 1.0 output 2022-08-06 18:19:11 +02:00
Henrik Rydgård 6ca47076e7 Delete the Vulkan implementation of DrawActiveTexture, fixups to shader gen 2022-08-03 14:12:55 +02:00
Henrik Rydgård d26e637bb8 Bufferless path for D3D11/Vulkan
Though we still bind the buffer for simplicity..
2022-08-03 13:33:53 +02:00
Henrik Rydgård 269bff9c0b Get D3D shaders to build (though not working correctly) 2022-08-03 13:31:15 +02:00
Henrik Rydgård 787de81437 Switch to ShaderWriter. Works in OpenGL 2022-08-03 13:31:15 +02:00
Unknown W. Brackets 2479d52202 Global: Reduce includes of common headers.
In many places, string, map, or Common.h were included but not needed.
2022-01-30 16:35:33 -08:00
Henrik Rydgård 3245f54dc1 Optimize the rotation a bit (limit to VK/D3D11, mat2 instead of mat4) 2021-10-31 13:44:54 +01:00
Unknown W. Brackets cd6be61d98 Common: Correct some formatting type mismatches. 2021-01-01 15:43:13 -08:00
Henrik Rydgård f3ebd6553d Turn off vertex range culling in bezier/spline calls.
When we do lower res tess than the real PSP, we cant trust the game to not cause range culling to kick in.

Fixes #11692
2020-12-13 16:04:16 +01:00
Henrik Rydgård 29b2f2c4ef Better GLSL version handling. Now specify the latest version supported by the device.
Correct the version check for our own implementations of packUnorm4x8 etc.
2020-11-16 23:30:07 +01:00
Henrik Rydgård 34efa1281b More consistent use of GLSL precision modifiers, now use them in Vulkan too.
Might help #13464 ?
2020-11-10 22:42:41 +01:00
Henrik Rydgård d99cba7308 Outrun on OpenGL: Fix weird purple highlight seen on some devices
mediump int is just not enough.
2020-11-10 22:01:57 +01:00
Henrik Rydgård 50619af71d Fix HLSL shader gen issue 2020-11-09 09:10:44 +01:00
Henrik Rydgård 6310af25fa Get shader color write masking going on all backends. 2020-11-08 23:45:47 +01:00
Henrik Rydgård 96c36d5c10 More work on reinterpret. Get Vulkan running 2020-11-08 11:32:55 +01:00
Henrik Rydgård f2e315b9a6 More shadergen work
Buildfix
2020-11-08 11:32:53 +01:00
Henrik Rydgård 19b4febbbf More reinterpret shader gen and test work.
More work on reinterpret

Buildsystem fixes
2020-11-08 10:41:20 +01:00
Henrik Rydgård 733a152c54 Move ShaderWriter to Common/GPU, along with some stuff from ShaderCommon.h. 2020-11-04 09:18:35 +01:00