Commit Graph

25 Commits

Author SHA1 Message Date
Campbell Barton
600f803922 Cleanup: pass string as a const reference 2024-11-26 12:41:29 +11:00
Clément Foucault
29b3df7504 GPU: GLSL compilation as C++ for draw intern shaders
Allow compilation of shaders using C++ for linting and
IDE support.

Related #127983

Pull Request: https://projects.blender.org/blender/blender/pulls/130193
2024-11-13 12:32:39 +01:00
Clément Foucault
5c80fb17e0 GPU: Add support for shader assert
This allows to use `assert()` directly inside shader source.

The current implementation is just replacing it with a printf
that gives some information about the location of the assert.

It is not that much more helpful than a printf with a condition.
What is useful is that they are disabled by default. So they
can be sprinkle around and only turned on during debugging.

Adding shader name inside the assert report is not trivial and
could be added later (the shader name is only known at compile
time which is too late for string parsing).

Adding which drawcall produced the assert isn't trivial either.
It would require flushing the printf buffer for each drawcall
which might force synchronization and remove bugs.

Pull Request: https://projects.blender.org/blender/blender/pulls/129728
2024-11-06 20:29:01 +01:00
Clément Foucault
f38827802a Fix: GPU: Broken shader printf support
Was using wrong type of data offset and not removing
the quote when outputing the strings.
2024-10-16 17:01:17 +02:00
Campbell Barton
5a561c6aeb Cleanup: spelling in comments 2024-10-16 21:10:49 +11:00
Clément Foucault
c91baf1cdd GPU: GLSL Preprocess: Avoid parsing includes as string
Remove them before string parsing
2024-10-16 10:30:35 +02:00
Clément Foucault
4ba944b15a GPU: GLSL Preprocess: Always remove quotes
We cannot do this for the MSL files. Also
they are written in MSL which should not be
processed. So use datatoc for them.

Also add quote linting for GLSL files.
2024-10-16 09:08:51 +02:00
Clément Foucault
7110890b09 GPU: GLSL preprocessor: Only do function parsing on library files 2024-10-16 09:08:51 +02:00
Clément Foucault
fcae6f2fc4 Fix: GPU: GLSL preprocessor not using binary output stream
This was adding a lot of CLRF newlines on windows which
in turn caused the new runtime parsing to fail.
2024-10-15 22:56:32 +02:00
Clément Foucault
39d5013c6e GPU: Use filename hash for line directive instead of path
This ensures same values on all systems.
2024-10-15 22:26:08 +02:00
Clément Foucault
c1f4394b14 GPU: Use 32bit hash in static_strings_suffix
Also make sure to use stoul for parsing it.
2024-10-15 22:26:08 +02:00
Clément Foucault
c41326a296 Cleanup: GPU: GLSL Preprocessor: Use raw strings and remove template 2024-10-15 20:16:45 +02:00
Clément Foucault
cf9da6f642 GPU: Move global scope constant linting to preprocessor
# Conflicts:
#	source/blender/gpu/glsl_preprocess/glsl_preprocess.hh
2024-10-15 20:16:45 +02:00
Clément Foucault
62826931b0 GPU: Move more linting and processing of GLSL to compile time
The goal is to reduce the startup time cost of
all of these parsing and string replacement.

All comments are now stripped at compile time.
This comment check added noticeable slowdown at
startup in debug builds and during preprocessing.

Put all metadatas between start and end token.
Use very simple parsing using `StringRef` and
hash all identifiers.

Move all the complexity to the preprocessor that
massagess the metadata into a well expected input
to the runtime parser.

All identifiers are compile time hashed so that no string
comparison is made at runtime.

Speed up the source loading:
- from 10ms to 1.6ms (6.25x speedup) in release
- from 194ms to 6ms (32.3x speedup) in debug

Follow up #129009

Pull Request: https://projects.blender.org/blender/blender/pulls/128927
2024-10-15 19:47:30 +02:00
Campbell Barton
aa6742897e Cleanup: spelling in comments 2024-10-15 16:22:38 +11:00
Campbell Barton
bd299cad72 Cleanup: quiet unused argument warnings 2024-10-14 12:12:20 +11:00
Clément Foucault
191b347f58 Cleanup: GPU: Use function parameters instead of template 2024-10-12 14:21:51 +02:00
Clément Foucault
d9aad850b0 GPU: GLSL preprocess: Remove invalidly processed header
Add assert in the preprocessor that these file don't get
processed.
2024-10-12 14:21:51 +02:00
Clément Foucault
1c0247c871 Cleanup: GPU: Preprocessor: Use report callback on processing functions 2024-10-11 18:52:34 +02:00
Clément Foucault
300ea9f083 GPU: GLSL: Strip comment at compile time
This speeds up the preprocessor and
will allow for faster load time.

# Conflicts:
#	source/blender/gpu/glsl_preprocess/glsl_preprocess.cc
2024-10-11 11:15:52 +02:00
Campbell Barton
f3c2deac3e Cleanup: replace U+00A0 with space
Using ASCII space is sufficient in source.
2024-10-09 16:34:39 +11:00
Campbell Barton
2e881eacd1 Cleanup: spelling in comments 2024-10-08 09:54:29 +11:00
Clément Foucault
9c0321ae9b Metal: Simplify MSL translation
Move most of the string preprocessing used for MSL
compatibility to `glsl_preprocess`.

Enforce some changes like matrix constructor and
array constructor to the GLSL codebase. This is
for C++ compatibility.

Additionally reduce the amount of code duplication
inside the compatibility code.

Pull Request: https://projects.blender.org/blender/blender/pulls/128634
2024-10-07 12:54:10 +02:00
Clément Foucault
7e5bc58649 GPU: Change GLSL include directive
This changes the include directive to use the standard C preprocessor
`#include` directive.

The regex to applied to all glsl sources is:
`pragma BLENDER_REQUIRE\((\w+\.glsl)\)`
`include "$1"`

This allow C++ linter to parse the code and allow easier codebase
traversal.

However there is a small catch. While it does work like a standard
include directive when the code is treated as C++, it doesn't when
compiled by our shader backends. In this case, we still use our
dependency concatenation approach instead of file injection.

This means that included files will always be prepended when compiled
to GLSL and a file cannot be appended more than once.

This is why all GLSL lib file should have the `#pragma once` directive
and always be included at the start of the file.

These requirements are actually already enforced by our code-style
in practice.

On the implementation, the source needed to be mutated to comment
the `#pragma once` and `#include`. This is needed to avoid GLSL
compiler error out as this is an extension that not all vendor
supports.

Rel #127983
Pull Request: https://projects.blender.org/blender/blender/pulls/128076
2024-10-04 15:48:22 +02:00
Clément Foucault
0bfd5e3536 GPU: Add GLSL preprocessor
This splits the GLSL processing into its own file
as it will grow in complexity.

Removes the complexity from `datatoc` and chain them
during the build process.

Rel #128076

Pull Request: https://projects.blender.org/blender/blender/pulls/128261
2024-10-04 11:33:21 +02:00