Commit graph

21 commits

Author SHA1 Message Date
Dunedan
f43f4ae1b1
Update the pre-commit hooks
With v3.12.0 shfmt changed the behavior of the `--simplify` option to
ignore any EditorConfig when it's provided. Therefore, this option is
now moved to the EditorConfig as suggested by the shfmt author. See
https://github.com/mvdan/sh/issues/1173 for details.
2025-08-22 13:04:38 +02:00
Vladislav Belov
e27909e603
Fixes SPIR-V compilation for compute_skinning shader.
Currently we don't mix storage images and storage buffers in the same
shader. Also we don't sample textures when we use storage buffers.
In the future we need to avoid shifting descriptor sets.
2024-12-11 01:18:05 +01:00
Dunedan
d9740858f7
Look up location of spirv-reflect only once
Instead of looking up the location of spirv-reflect for every shader,
this is now being done once and cached for all shaders. This results in
shader compilation being slightly faster.
2024-10-25 09:24:43 +02:00
Dunedan
cdd2f3636a
Use spirv-opt to strip debug info
Instead of compiling SPIR-V shaders twice, once with debug info and once
without, this uses `spirv-opt` to remove the debug info from the SPIR-V
shaders with debug info. This results in notable performance gains, as
stripping the debug info from existing shaders is much faster than
compiling them.

As a result of this change the contents of the non-debug shaders change
once. That's because shaders with debug info contain much more
instructions and therefore more result ids. Stripping the debug
info from shaders results in different result ids being used as when
generating ones without debug info. While that doesn't result in a
difference in the functionality of the shaders, it's a difference in
their binary representation, causing their content hashs and therefore
file names to change. After that one-time change the result ids are
reproducible again.
2024-10-25 08:26:54 +02:00
Dunedan
6eb9a3308a
Define VkDescriptorType enum only once
Instead of redefining the VkDescriptorType enum for every shader, only
define it once. This avoids unnecessary computation and slightly
increases performance.
2024-10-21 09:02:38 +02:00
Dunedan
20cef3bce0
Fix compiling SPIR-V shaders on Windows
b2cdb1e6b4 broke compiling of SPIR-V shaders on Windows, as the output
of `spirv-reflect` contains CRLF as line separators there. This commit
fixes that.
2024-10-18 16:50:31 +02:00
Dunedan
b2cdb1e6b4
Improve YAML loading performance using libyaml
This adds optional support for loading the YAML reflection data using
`libyaml`, which is faster than PyYAML's pure Python implementation.
2024-10-17 17:52:08 +02:00
Dunedan
8e6cac8744
Deduplicate SPIR-V shaders across programs
This drops the program name from the SPIR-V shader file name, which
allows deduplicating shaders belonging to different programs. While that
has no significant impact on compilation performance it reduces the
number of required SPIR-V shaders.

One downside this has it that it's not directly visible from the file
name of a shader anymore to which program it belongs.
2024-10-17 17:02:22 +02:00
Dunedan
c4047b1cf2
Parallelize generation of SPIR-V shaders
For each program this parallelizes the generation of shaders by program
combinations. This leads to significantly faster shader generation on
systems with multiple CPU-cores. The resulting shaders are identical to
the ones prior to this change.
2024-10-05 07:29:43 +02:00
Dunedan
c101984445
Make SPIR-V file names reproducible
This ensures the file names of SPIR-V program combinations and shaders
are reproducible. Up to now they only were if the order of program
combinations in the rules.json didn't change, as the file names
contained the position of the program combination in the rules.json.
With this change files names of program combinations will be named based
on the details of the combination used to create them and the file names
of shaders will be based on their content respectively.

Changing the file names avoids wrong shaders when partially rebuilding
them after a new combination for a program got added in between the
other combinations in rules.json and removes the need for keeping track
of identical shaders in the script. It's also a preparation for being
able to build shaders in parallel, while also keeping the result
reproducible.
2024-10-01 16:58:03 +02:00
Ralph Sennhauser
cf909a81db Add support for vendored spirv-reflect to compile.py
The script build-archive.sh sets a variable SPIRV_REFLECT, even respects
it if it's set in env but without support from the compile.py script for
it there isn't much point.

This commit adds support SPIRV_REFLECT in compile.py and and adds a
fallback to use vendored spirv-reflect for when the envvar is unset and
the tool can't be found in PATH

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2024-09-24 18:45:22 +02:00
Dunedan
0ea6d32fa5
Enable various ruff rules
This commit enables a bunch of unrelated ruff rules, which only require
minimal changes to the code base to enable them.

The rules enabled by this commit are:

- check the use of datetime objects without timezone (DTZ005)
- check the performance of try-except in loops (PERF203)
- check the number of function arguments (PLR0913)
- check for mutable class defaults (RUF012)
- check for the use of secure hashing algorithms (S324)
- check for raising base exceptions (TRY002)
- check for raising other exceptions where TypeErrors should be raised
  (TRY004)
2024-09-21 20:54:30 +02:00
Dunedan
265ed76131
Simplify check for identical shaders
Previously when checking if two SPIR-V shaders are identical the
hashs of their file content would be compared and afterwards their
(unhashed) file contents as well. Comparing the file contents isn't
necessary, as the hash function used is a cryptographic one, which
guarantees the hash can be used as a representative of the hashed data.
2024-09-21 20:39:59 +02:00
Dunedan
230c7ca27d
Add EditorConfig options for Python
While the desired options for indent size and style are Python's
defaults, let's make it explicit by specifying it in the EditorConfig.

As part of this, this also removes unnecessary inline formatting options
for Python files.
2024-09-17 11:03:15 +02:00
Dunedan
8c7cc7373d
Fix variable names in SPIRV compile.py 2024-09-13 11:04:06 +02:00
Dunedan
f2bef8388a
Use UTF-8 as encoding when working with files
This explicitly uses UTF-8 encoding when reading or writing files with
Python. This is necessary as the default locale varies between
operating systems.
2024-08-29 07:22:46 +02:00
Dunedan
ea647067f0
Enable ruff rules to check for ambiguous code
This enables some ruff rules to check for ambiguous and dead Python
code, which might cause unintended side-effects.

The enabled rules are:

- a bunch of rules related to shadowing of builtin structures (A)
- a bunch of rules checking for unused arguments (ARG)
- a rule checking for useless expressions (B018)
- a rule checking for unbound loop variables (B023)
- a rule checking redefined function parameters (PLR1704)
2024-08-27 19:28:11 +02:00
Dunedan
e36c6a31fe
Enable additional ruff rules
In the ruff config file added in #6954 explicitly selecting the ruff
rules to check was missed, resulting in ruff only checking a very small
subset of its available rules. That hasn't been desired, so this is the
first of a series of commits enabling more rules. In this PR all rules
whose violations can be either automatically fixed by ruff or are
trivial to fix manually get enabled. For the follow up PRs it's intended
to focus on one area of rules per PR to gradually improve the Python
code quality.
2024-08-25 06:29:39 +02:00
Dunedan
c49d4eedd0
Lint and format Python files using ruff
To improve quality und uniformity of the included Python code this
lints and formats the included Python files with ruff.
2024-08-24 10:54:26 +02:00
vladislavbelov
5214a4c073 Fixes SPIRV compile script for newer versions of spirv-reflect.
Differential Revision: https://code.wildfiregames.com/D5123
This was SVN commit r27845.
2023-09-20 17:25:14 +00:00
vladislavbelov
3ceeedf169 Adds script to generate SPIR-V from GLSL shaders. Refs #6636
Tested By: Stan
Differential Revision: https://code.wildfiregames.com/D4969
This was SVN commit r27627.
2023-05-02 17:31:28 +00:00