42 Commits
Author SHA1 Message Date
LibretroAdmin cab5004132 Video: build the pixel ubershaders by calls
The pixel ubershader is built with rslc's builder instead of printed as
text and parsed again, on every backend. Built and printed stages
compile to the same SPIR-V and DXBC words: each of the 108 uids with 30
random host configs, on Vulkan with and without subgroup reduction and
on D3D. For OpenGL, where framebuffer fetch blends and logic-ops in the
shader, each stage a GLSL 4.50, 3.30, ES 3.10 or ES 3.20 context can be
asked for compiles in glslangValidator.

Both pixel generators now declare their inputs in one place. The text
the ubershader was the last user of goes: the pixel shaders' common
header, the switch trees, the lighting function, the bitfieldExtract
header and the VS_OUTPUT members and their interpolation qualifiers.
2026-11-10 17:46:20 +01:00
LibretroAdmin f2f126da96 Video: build the vertex ubershaders by calls
The vertex ubershader is built through rslc's builder, as the
specialized vertex shader already is, so no GLSL is generated or
parsed for it on the compile workers.

The lighting function and the per-channel vertex lighting it shares
with the pixel ubershader, and bitfieldExtract for backends without it,
are builder pieces of their own. The text writers nothing uses any
more go: the vertex ubershader's, the line and point expansion, the
line offset, dolphin_isnan's and the output member assignment.

Metal's built shaders now get the same MSL header and fixups its
parsed ones do, so the ubershader lighting loop stays unrolled.

Built stages compile to the same words the text did for Vulkan and
D3D for every texgen count across random host configurations.
2026-11-10 08:19:30 +01:00
LibretroAdmin 1396da6572 Video: build the vertex shaders by calls
The specialized vertex shader is built through rslc's builder instead
of written as GLSL for each backend to parse back: Vulkan gets SPIR-V,
D3D its bytecode and OpenGL GLSL straight from the built stage, with no
text generated or parsed on the compile workers.

The pieces the pixel shaders and the ubershaders will build from too
are shared: the vertex uniforms block, dolphin_isnan, the line and
point expansion and the lighting functions. The text generator and the
lighting macros nothing used are gone.

Built stages compile to the same words the text did for Vulkan and
D3D across random uids and host configurations.
2026-11-10 07:48:29 +01:00
LibretroAdmin 4a43bd75ec Video: build the geometry shaders by calls
The geometry stage moves to the builder, on pieces the vertex and pixel
stages will share: VS_OUTPUT's layout and member copy, struct Light, the
geometry stage's uniforms and the line offset. Every primitive, texgen
count and host configuration compiles to the same SPIR-V and DXBC words
as its GLSL did, but one: under MSAA the GLSL put 'centroid in' inside
the VertexData blocks where the backend reports no binding layout, as
Vulkan and Direct3D 12 do, and rslc refuses that, so no geometry stage
compiled with MSAA there. The built stage marks those members centroid
(or sample) and compiles to what the GLSL with plain 'centroid' would.
2026-11-10 05:58:14 +01:00
LibretroAdmin 183b8d7ce6 VideoCommon: shader generators write through a C89 text builder
ShaderText is one growing block of chars with room kept in front for a
header. ShaderCode writes into it as it is or printf-style, without fmt
or std::string; the generators' string parameters, tables and switch
trees are plain C strings, and the UID enumerations fill arrays.
2026-11-07 21:48:29 +01:00
libretroadmin c878c0d818 remove LIBRETRO ifdefs 2026-11-07 14:23:51 +01:00
LibretroAdmin c11f067627 D3D, D3D12: geometry stages to bytecode with rslc; drop d3dcompiler
The geometry shader generator and the layered pass-through geometry
stage now write GLSL for Direct3D too, as for OpenGL and Vulkan, and the
vendored rslc compiles them to DXBC like the other stages. Direct3D
binds the geometry block at b0.

With every stage compiled by rslc, the runtime compiler is no longer
used: d3dcompiler_47.dll is not loaded, D3DCompile and its target table
are gone, and the core no longer needs the DLL on the system.

GenerateVSOutputMembers loses its Direct3D geometry-stage case and its
HLSL semantics, which only the HLSL generators used.
2026-11-06 18:09:39 +01:00
LibretroAdmin f073fc9448 Remove glslang and SPIRV-Cross
Every backend compiles its shaders through rslc now: the two submodules,
VideoCommon/Spirv.cpp and their build go.
2026-11-06 14:12:01 +01:00
Craig Carnell 492f485c67 libretro: fix shader cache when changing supportsBindingLayout option 2026-10-16 16:25:04 +01:00
Martino Fontana a14c88ba67 Remove unused imports
Yellow squiggly lines begone!
Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes.
If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed.
The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports.
Not everything is removed, but the cleanup should be substantial enough.
Because this done on Linux, code that isn't used on it is mostly untouched.
(Hopefully no open PR is depending on these imports...)
2026-01-25 16:12:15 +01:00
iwubcode 8e253518e6 VideoCommon: move to a 'process_fragment()' function to simplify custom shaders and provide a direct override of the tev stage logic 2025-03-22 15:22:00 -05:00
Jordan Woyak c18c039089 VideoCommon: Move backend_info out of VideoConfig struct. 2025-03-09 01:42:45 -06:00
iwubcode 9d28c371e7 VideoCommon: allow custom shaders to set the alpha value for use when blending is enabled 2024-04-28 18:15:27 -05:00
JosJuice ba99d17ac0 VideoCommon: Fix custom shader constants on GLES 2023-08-22 19:38:18 +02:00
iwubcode 931a8aa413 VideoCommon: add milliseconds elapsed time value to pixel shaders as a uniform to be able to support animation effects in custom shaders 2023-08-20 18:53:27 -05:00
iwubcode 0da5cf60a8 VideoCommon: add custom pixel shader definition and custom shader header to shadergen common as it will be used by both the special and uber shader variant of pixel shaders 2023-08-20 18:53:27 -05:00
Dentomologist ad6e95afb4 D3D: Restore workaround for erroneous NaN optimization
The HLSL compiler incorrectly decides isnan can't be true, so this
workaround was originally added in 52c82733 but lost during the
conversion to SPIR-V.
2023-02-25 16:27:30 -08:00
TellowKrinkle f25a0b43b6 VideoCommon: Fix stereoscopic 3D on OpenGL < 4.3 (macOS) 2023-02-14 18:25:33 +01:00
Pokechu22 f3df3a7727 PixelShaderGen: Clamp texture layer when using manual texture sampling with stereoscopic 3D
Otherwise, texelFetch() will use an out-of-bounds layer for game textures (that have 1 layer; EFB copies have 2 layers in stereoscopic 3D mode), which is undefined behavior (often resulting in a black image). The fast texture sampling path uses texture(), which always clamps (see https://www.khronos.org/opengl/wiki/Array_Texture#Access_in_shaders), so it was unaffected by this difference.
2022-12-27 13:45:13 -08:00
TellowKrinkle b567f3afcf VideoCommon: Move repeated point/line expansion code to ShaderGenCommon 2022-10-22 20:13:24 -05:00
TellowKrinkle 68f49df0f8 VideoCommon: Add vertex shader point and line expansion 2022-10-22 20:13:24 -05:00
TellowKrinkle 4c629c2bee VideoCommon: Add dynamic vertex loader to ubershaders 2022-09-19 16:28:23 -05:00
TellowKrinkle 716c0980d7 VideoBackends: Add Metal renderer 2022-07-21 20:44:19 -05:00
iwubcode 5dd2704416 D3D / VideoCommon: generate HLSL from SPIRV 2022-06-24 18:09:53 -05:00
OatmealDome 4e12d6e871 ShaderGenCommon: Add bit for LOD bias 2021-12-28 02:10:39 -05:00
Pokechu22 bdcfb31187 VideoCommon: Handle custom texture sizes correctly
Specifically, when using Manual Texture Sampling, if textures sizes don't match the size the game specifies, things previously broke.  That can happen with custom textures, and also with scaled EFB copies at non-native IRs.  It breaks most obviously by not scaling the texture coordinates (so only part of the texture shows up), but the hardware wrapping functionality also assumes texture sizes are a power of 2 (or else it will behave weirdly in a way that matches how hardware behaves weirdly).  The fix is to provide alternative texture wrapping logic when custom texture sizes are possible.
2021-11-17 21:28:36 -08:00
Pokechu22andJosJuice 93eea7cb13 VideoCommon: Add option to use old behavior (Fast Texture Sampling)
Co-authored-by: JosJuice <[email protected]>
2021-11-17 21:27:32 -08:00
Pokechu22 d2041b4c2a VideoCommon: Add signed version of BitfieldExtract 2021-11-17 20:04:33 -08:00
Pokechu22 555a93057c VideoCommon: Allow BitfieldExtract in specialized shaders 2021-11-17 20:04:33 -08:00
Pokechu22 52c82733f6 Use custom isnan implementation to avoid HLSL optimizer issues
This adjusts the NaN replacement logic introduced in #9928 to work around the HLSL compiler optimizing away calls to isnan, which caused that functionality to not work with ubershaders on D3D11 and D3D12 (it did work with specialized shaders, despite a warning being logged for both; that warning is also now gone).  Note that the `D3DCOMPILE_IEEE_STRICTNESS` flag did not solve this issue, despite the warning suggesting that it might.

Suggested by @kayru and @jamiehayes.
2021-09-07 19:04:40 -07:00
Pokechu22 b6d2938731 Recompile shaders when 'Enable API Validation Layers' is toggled 2021-07-28 21:35:36 -07:00
Pierre Bourdon e149ad4f0a treewide: convert GPLv2+ license info to SPDX tags
SPDX standardizes how source code conveys its copyright and licensing
information. See https://spdx.github.io/spdx-spec/1-rationale/ . SPDX
tags are adopted in many large projects, including things like the Linux
kernel.
2021-07-05 04:35:56 +02:00
Lioncash a5b28f1f07 ShaderGenCommon: Rename WriteFmt() to Write()
Now that we've converted all of the shader generators over to using fmt,
we can drop the old Write() member function and perform a rename
operation on the WriteFmt() to turn it into the new Write() function.

All changes within this are the removal of a <cstdarg> header, since the
previous printf-based Write() required it, and renaming. No functional
changes are made at all.
2020-11-09 02:31:49 -05:00
Lioncash 86f8768268 VideoCommon/ShaderGenCommon: Make template functions regular functions
These are only ever used with ShaderCode instances and nothing else.
Given that, we can convert these helper functions to expect that type of
object as an argument and remove the need for templates, improving
compiler throughput a marginal amount, as the template instantiation
process doesn't need to be performed.

We can also move the definitions of these functions into the cpp file,
which allows us to remove a few inclusions from the ShaderGenCommon
header. This uncovered a few instances of indirect inclusions being
relied upon in other source files.

One other benefit is this allows changes to be made to the definitions
of the functions without needing to recompile all translation units that
make use of these functions, making change testing a little quicker.

Moving the definitions into the cpp file also allows us to completely
hide DefineOutputMember() from external view, given it's only ever used
inside of GenerateVSOutputMembers().
2020-05-25 21:12:29 -04:00
Lioncash 6fbbc2683e VideoCommon: Make use of fmt outside of shader generators
Migrates most of VideoCommon over to using fmt, with the exception being
the shader generator code. The shader generators are quite large and
have more corner cases to deal with in terms of conversion (shaders have
braces in them, so we need to make sure to escape them).

Because of the large amount of code that would need to be converted, the
conversion of VideoCommon will be in two parts:

- This change (which converts over the general case string formatting),
- A follow up change that will specifically deal with converting over
  the shader generators.
2019-11-23 16:00:45 -05:00
Stenzek f039149198 Move most backend functionality to VideoCommon 2019-02-19 16:57:54 +10:00
Stenzek 640bfb8135 VideoConfig: Add a field for indicating logic op support in the backend 2018-05-26 00:07:20 +10:00
Stenzek dec0c3bce8 Move shader caches to VideoCommon 2018-03-10 15:56:30 +10:00
Jonathan Hamilton 29a9ed043b Implement dual-source blending in shader
For some GLES drivers that don't support dual-source blending, but do
support GL_EXT_shader_framebuffer_fetch, this might be useful.
2018-01-05 09:56:46 -08:00
Lioncash 5337e58284 VideoConfig: Make StereoMode an enum class
Makes for more strongly-typed identifiers (and doesn't pollute
surrounding namespaces)
2017-11-18 23:19:53 -05:00
Stenzek 7d78cf0f6f ShaderGen: Implement pixel ubershaders 2017-07-30 17:43:59 +10:00
Stenzek 3ea9d86faa ShaderGen: Pass host config to shader generation functions
Also moves the host config checks to common.
2017-07-20 17:54:33 +10:00