mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #101443 from Repiteo/ci/replace-pytest
CI: Replace pytest with pre-commit hook
This commit is contained in:
commit
ac13efc822
20 changed files with 462 additions and 749 deletions
25
.github/workflows/static_checks.yml
vendored
25
.github/workflows/static_checks.yml
vendored
|
@ -13,15 +13,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
|
|
||||||
- name: Install APT dependencies
|
# This needs to happen before Python and npm execution; it must happen before any extra files are written.
|
||||||
|
- name: .gitignore checks (gitignore_check.sh)
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
bash ./misc/scripts/gitignore_check.sh
|
||||||
sudo apt install -y libxml2-utils
|
|
||||||
|
|
||||||
- name: Install Python dependencies and general setup
|
|
||||||
run: |
|
|
||||||
pip3 install pytest==7.1.2
|
|
||||||
git config diff.wsErrorHighlight all
|
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
env:
|
env:
|
||||||
|
@ -32,27 +27,17 @@ jobs:
|
||||||
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
|
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
|
||||||
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
|
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
|
||||||
fi
|
fi
|
||||||
echo "$files" >> changed.txt
|
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
|
||||||
cat changed.txt
|
|
||||||
files=$(echo "$files" | grep -v 'thirdparty' | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
|
|
||||||
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
|
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
|
||||||
|
|
||||||
# This needs to happen before Python and npm execution; it must happen before any extra files are written.
|
|
||||||
- name: .gitignore checks (gitignore_check.sh)
|
|
||||||
run: |
|
|
||||||
bash ./misc/scripts/gitignore_check.sh
|
|
||||||
|
|
||||||
- name: Style checks via pre-commit
|
- name: Style checks via pre-commit
|
||||||
uses: pre-commit/action@v3.0.1
|
uses: pre-commit/action@v3.0.1
|
||||||
with:
|
with:
|
||||||
extra_args: --files ${{ env.CHANGED_FILES }}
|
extra_args: --files ${{ env.CHANGED_FILES }}
|
||||||
|
|
||||||
- name: Python builders checks via pytest
|
|
||||||
run: |
|
|
||||||
pytest ./tests/python_build
|
|
||||||
|
|
||||||
- name: Class reference schema checks
|
- name: Class reference schema checks
|
||||||
run: |
|
run: |
|
||||||
|
sudo apt install -y libxml2-utils
|
||||||
xmllint --quiet --noout --schema doc/class.xsd doc/classes/*.xml modules/*/doc_classes/*.xml platform/*/doc_classes/*.xml
|
xmllint --quiet --noout --schema doc/class.xsd doc/classes/*.xml modules/*/doc_classes/*.xml platform/*/doc_classes/*.xml
|
||||||
|
|
||||||
- name: Run C compiler on `gdextension_interface.h`
|
- name: Run C compiler on `gdextension_interface.h`
|
||||||
|
|
|
@ -16,12 +16,10 @@ repos:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java)$
|
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java)$
|
||||||
types_or: [text]
|
types_or: [text]
|
||||||
exclude: ^tests/python_build/.*
|
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
name: clang-format-glsl
|
name: clang-format-glsl
|
||||||
files: \.glsl$
|
files: \.glsl$
|
||||||
types_or: [text]
|
types_or: [text]
|
||||||
exclude: ^tests/python_build/.*
|
|
||||||
args: [-style=file:misc/utility/clang_format_glsl.yml]
|
args: [-style=file:misc/utility/clang_format_glsl.yml]
|
||||||
|
|
||||||
- repo: https://github.com/pocc/pre-commit-hooks
|
- repo: https://github.com/pocc/pre-commit-hooks
|
||||||
|
@ -31,7 +29,6 @@ repos:
|
||||||
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java|glsl)$
|
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java|glsl)$
|
||||||
args: [--fix, --quiet, --use-color]
|
args: [--fix, --quiet, --use-color]
|
||||||
types_or: [text]
|
types_or: [text]
|
||||||
exclude: ^tests/python_build/.*
|
|
||||||
additional_dependencies: [clang-tidy==19.1.0]
|
additional_dependencies: [clang-tidy==19.1.0]
|
||||||
require_serial: true
|
require_serial: true
|
||||||
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`
|
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`
|
||||||
|
@ -88,6 +85,13 @@ repos:
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
files: ^(doc/classes|.*/doc_classes)/.*\.xml$
|
files: ^(doc/classes|.*/doc_classes)/.*\.xml$
|
||||||
|
|
||||||
|
- id: validate-builders
|
||||||
|
name: validate-builders
|
||||||
|
language: python
|
||||||
|
entry: python tests/python_build/validate_builders.py
|
||||||
|
pass_filenames: false
|
||||||
|
files: ^(gles3|glsl)_builders\.py$
|
||||||
|
|
||||||
- id: eslint
|
- id: eslint
|
||||||
name: eslint
|
name: eslint
|
||||||
language: node
|
language: node
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
"""Functions used to generate source files during build time"""
|
"""Functions used to generate source files during build time"""
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from methods import print_error, to_raw_cstring
|
from methods import generated_wrapper, print_error, to_raw_cstring
|
||||||
|
|
||||||
|
|
||||||
class GLES3HeaderStruct:
|
class GLES3HeaderStruct:
|
||||||
|
@ -189,212 +188,165 @@ def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct,
|
||||||
return header_data
|
return header_data
|
||||||
|
|
||||||
|
|
||||||
def build_gles3_header(
|
def build_gles3_header(filename: str, shader: str) -> None:
|
||||||
filename: str,
|
include_file_in_gles3_header(shader, header_data := GLES3HeaderStruct(), 0)
|
||||||
include: str,
|
out_file_class = (
|
||||||
class_suffix: str,
|
os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderGLES3"
|
||||||
optional_output_filename: Optional[str] = None,
|
)
|
||||||
header_data: Optional[GLES3HeaderStruct] = None,
|
|
||||||
):
|
|
||||||
header_data = header_data or GLES3HeaderStruct()
|
|
||||||
include_file_in_gles3_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
with generated_wrapper(filename) as file:
|
||||||
out_file = filename + ".gen.h"
|
|
||||||
else:
|
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
|
||||||
defspec = 0
|
defspec = 0
|
||||||
defvariant = ""
|
defvariant = ""
|
||||||
|
|
||||||
fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
|
file.write(f"""\
|
||||||
fd.write("#pragma once\n")
|
#include "drivers/gles3/shader_gles3.h"
|
||||||
|
|
||||||
out_file_base = out_file
|
class {out_file_class} : public ShaderGLES3 {{
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
public:
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
""")
|
||||||
|
|
||||||
out_file_class = (
|
|
||||||
out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
|
|
||||||
)
|
|
||||||
fd.write("\n\n")
|
|
||||||
fd.write('#include "' + include + '"\n\n\n')
|
|
||||||
fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
|
|
||||||
|
|
||||||
fd.write("public:\n\n")
|
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write("\tenum Uniforms {\n")
|
uniforms = ",\n\t\t".join(uniform.upper() for uniform in header_data.uniforms)
|
||||||
for x in header_data.uniforms:
|
file.write(f"""\
|
||||||
fd.write("\t\t" + x.upper() + ",\n")
|
enum Uniforms {{
|
||||||
fd.write("\t};\n\n")
|
{uniforms},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.variant_names:
|
if header_data.variant_names:
|
||||||
fd.write("\tenum ShaderVariant {\n")
|
variant_names = ",\n\t\t".join(name for name in header_data.variant_names)
|
||||||
for x in header_data.variant_names:
|
|
||||||
fd.write("\t\t" + x + ",\n")
|
|
||||||
fd.write("\t};\n\n")
|
|
||||||
else:
|
else:
|
||||||
fd.write("\tenum ShaderVariant { DEFAULT };\n\n")
|
variant_names = "DEFAULT"
|
||||||
defvariant = " = DEFAULT"
|
defvariant = " = DEFAULT"
|
||||||
|
file.write(f"""\
|
||||||
|
enum ShaderVariant {{
|
||||||
|
{variant_names},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.specialization_names:
|
if header_data.specialization_names:
|
||||||
fd.write("\tenum Specializations {\n")
|
specialization_names = ",\n\t\t".join(
|
||||||
counter = 0
|
f"{name.upper()} = {1 << index}" for index, name in enumerate(header_data.specialization_names)
|
||||||
for x in header_data.specialization_names:
|
|
||||||
fd.write("\t\t" + x.upper() + "=" + str(1 << counter) + ",\n")
|
|
||||||
counter += 1
|
|
||||||
fd.write("\t};\n\n")
|
|
||||||
|
|
||||||
for i in range(len(header_data.specialization_names)):
|
|
||||||
defval = header_data.specialization_values[i].strip()
|
|
||||||
if defval.upper() == "TRUE" or defval == "1":
|
|
||||||
defspec |= 1 << i
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { return _version_bind_shader(p_version,p_variant,p_specialization); }\n\n"
|
|
||||||
)
|
)
|
||||||
|
file.write(f"""\
|
||||||
|
enum Specializations {{
|
||||||
|
{specialization_names},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
for index, specialization_value in enumerate(header_data.specialization_values):
|
||||||
|
if specialization_value.strip().upper() in ["TRUE", "1"]:
|
||||||
|
defspec |= 1 << index
|
||||||
|
|
||||||
|
file.write(f"""\
|
||||||
|
_FORCE_INLINE_ bool version_bind_shader(RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
return _version_bind_shader(p_version, p_variant, p_specialization);
|
||||||
|
}}
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write(
|
file.write(f"""\
|
||||||
"\t_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform,RID p_version,ShaderVariant p_variant"
|
_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
+ defvariant
|
return _version_get_uniform(p_uniform, p_version, p_variant, p_specialization);
|
||||||
+ ",uint64_t p_specialization="
|
}}
|
||||||
+ str(defspec)
|
|
||||||
+ ") { return _version_get_uniform(p_uniform,p_version,p_variant,p_specialization); }\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
/* clang-format off */
|
||||||
"\t#define _FU if (version_get_uniform(p_uniform,p_version,p_variant,p_specialization)<0) return; \n\n "
|
#define TRY_GET_UNIFORM if (version_get_uniform(p_uniform, p_version, p_variant, p_specialization) < 0) return
|
||||||
)
|
/* clang-format on */
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color& p_color,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,col); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2& p_vec2,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec2[2]={float(p_vec2.x),float(p_vec2.y)}; glUniform2fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i& p_vec2,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLint vec2[2]={GLint(p_vec2.x),GLint(p_vec2.y)}; glUniform2iv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3& p_vec3,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec3[3]={float(p_vec3.x),float(p_vec3.y),float(p_vec3.z)}; glUniform3fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec3); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector4& p_vec4,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec4[4]={float(p_vec4.x),float(p_vec4.y),float(p_vec4.z),float(p_vec4.w)}; glUniform4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec4); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform2f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform3f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform4f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c,p_d); }\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
"""\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D& p_transform,RID p_version,ShaderVariant p_variant"""
|
TRY_GET_UNIFORM;
|
||||||
+ defvariant
|
glUniform1f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
+ """,uint64_t p_specialization="""
|
}}
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color &p_color, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat col[4] = {{ p_color.r, p_color.g, p_color.b, p_color.a }};
|
||||||
|
glUniform4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, col);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2 &p_vec2, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec2[2] = {{ float(p_vec2.x), float(p_vec2.y) }};
|
||||||
|
glUniform2fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec2);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i &p_vec2, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLint vec2[2] = {{ GLint(p_vec2.x), GLint(p_vec2.y) }};
|
||||||
|
glUniform2iv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec2);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3 &p_vec3, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec3[3] = {{ float(p_vec3.x), float(p_vec3.y), float(p_vec3.z) }};
|
||||||
|
glUniform3fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec3);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector4 &p_vec4, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec4[4] = {{ float(p_vec4.x), float(p_vec4.y), float(p_vec4.z), float(p_vec4.w) }};
|
||||||
|
glUniform4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec4);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform2f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform3f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b, p_c);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform4f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b, p_c, p_d);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D &p_transform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
const Transform3D &tr = p_transform;
|
const Transform3D &tr = p_transform;
|
||||||
|
|
||||||
GLfloat matrix[16]={ /* build a 16x16 matrix */
|
GLfloat matrix[16] = {{ /* build a 16x16 matrix */
|
||||||
(GLfloat)tr.basis.rows[0][0],
|
(GLfloat)tr.basis.rows[0][0],
|
||||||
(GLfloat)tr.basis.rows[1][0],
|
(GLfloat)tr.basis.rows[1][0],
|
||||||
(GLfloat)tr.basis.rows[2][0],
|
(GLfloat)tr.basis.rows[2][0],
|
||||||
|
@ -411,25 +363,16 @@ def build_gles3_header(
|
||||||
(GLfloat)tr.origin.y,
|
(GLfloat)tr.origin.y,
|
||||||
(GLfloat)tr.origin.z,
|
(GLfloat)tr.origin.z,
|
||||||
(GLfloat)1
|
(GLfloat)1
|
||||||
};
|
}};
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
|
}}
|
||||||
|
|
||||||
}
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D &p_transform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D& p_transform,RID p_version,ShaderVariant p_variant"""
|
|
||||||
+ defvariant
|
|
||||||
+ """,uint64_t p_specialization="""
|
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
const Transform2D &tr = p_transform;
|
const Transform2D &tr = p_transform;
|
||||||
|
|
||||||
GLfloat matrix[16]={ /* build a 16x16 matrix */
|
GLfloat matrix[16] = {{ /* build a 16x16 matrix */
|
||||||
(GLfloat)tr.columns[0][0],
|
(GLfloat)tr.columns[0][0],
|
||||||
(GLfloat)tr.columns[0][1],
|
(GLfloat)tr.columns[0][1],
|
||||||
(GLfloat)0,
|
(GLfloat)0,
|
||||||
|
@ -446,142 +389,132 @@ def build_gles3_header(
|
||||||
(GLfloat)tr.columns[2][1],
|
(GLfloat)tr.columns[2][1],
|
||||||
(GLfloat)0,
|
(GLfloat)0,
|
||||||
(GLfloat)1
|
(GLfloat)1
|
||||||
};
|
}};
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
|
}}
|
||||||
|
|
||||||
}
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection &p_matrix, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix, RID p_version, ShaderVariant p_variant"""
|
|
||||||
+ defvariant
|
|
||||||
+ """,uint64_t p_specialization="""
|
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
GLfloat matrix[16];
|
GLfloat matrix[16];
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {{
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {{
|
||||||
matrix[i * 4 + j] = p_matrix.columns[i][j];
|
matrix[i * 4 + j] = p_matrix.columns[i][j];
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
}"""
|
}}
|
||||||
)
|
|
||||||
|
|
||||||
fd.write("\n\n#undef _FU\n\n\n")
|
#undef TRY_GET_UNIFORM
|
||||||
|
|
||||||
fd.write("protected:\n\n")
|
""")
|
||||||
|
|
||||||
fd.write("\tvirtual void _init() override {\n\n")
|
file.write("""\
|
||||||
|
protected:
|
||||||
|
virtual void _init() override {
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write("\t\tstatic const char* _uniform_strings[]={\n")
|
uniforms = ",\n\t\t\t".join(f'"{uniform}"' for uniform in header_data.uniforms)
|
||||||
if header_data.uniforms:
|
file.write(f"""\
|
||||||
for x in header_data.uniforms:
|
static const char *_uniform_strings[] = {{
|
||||||
fd.write('\t\t\t"' + x + '",\n')
|
{uniforms}
|
||||||
fd.write("\t\t};\n\n")
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic const char **_uniform_strings=nullptr;\n")
|
file.write("""\
|
||||||
|
static const char **_uniform_strings = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
variant_count = 1
|
if header_data.variant_defines:
|
||||||
if len(header_data.variant_defines) > 0:
|
|
||||||
fd.write("\t\tstatic const char* _variant_defines[]={\n")
|
|
||||||
for x in header_data.variant_defines:
|
|
||||||
fd.write('\t\t\t"' + x + '",\n')
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
variant_count = len(header_data.variant_defines)
|
variant_count = len(header_data.variant_defines)
|
||||||
|
variant_defines = ",\n\t\t\t".join(f'"{define}"' for define in header_data.variant_defines)
|
||||||
|
file.write(f"""\
|
||||||
|
static const char *_variant_defines[] = {{
|
||||||
|
{variant_defines},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write('\t\tstatic const char **_variant_defines[]={" "};\n')
|
variant_count = 1
|
||||||
|
file.write("""\
|
||||||
|
static const char **_variant_defines[] = {" "};
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.texunits:
|
if header_data.texunits:
|
||||||
fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
|
texunits = ",\n\t\t\t".join(f'{{ "{name}", {texunit} }}' for name, texunit in header_data.texunits)
|
||||||
for x in header_data.texunits:
|
file.write(f"""\
|
||||||
fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
|
static TexUnitPair _texunit_pairs[] = {{
|
||||||
fd.write("\t\t};\n\n")
|
{texunits},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic TexUnitPair *_texunit_pairs=nullptr;\n")
|
file.write("""\
|
||||||
|
static TexUnitPair *_texunit_pairs = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.ubos:
|
if header_data.ubos:
|
||||||
fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
|
ubos = ",\n\t\t\t".join(f'{{ "{name}", {ubo} }}' for name, ubo in header_data.ubos)
|
||||||
for x in header_data.ubos:
|
file.write(f"""\
|
||||||
fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
|
static UBOPair _ubo_pairs[] = {{
|
||||||
fd.write("\t\t};\n\n")
|
{ubos},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic UBOPair *_ubo_pairs=nullptr;\n")
|
file.write("""\
|
||||||
|
static UBOPair *_ubo_pairs = nullptr;
|
||||||
specializations_found = []
|
""")
|
||||||
|
|
||||||
if header_data.specialization_names:
|
if header_data.specialization_names:
|
||||||
fd.write("\t\tstatic Specialization _spec_pairs[]={\n")
|
specializations = ",\n\t\t\t".join(
|
||||||
for i in range(len(header_data.specialization_names)):
|
f'{{ "{name}", {"true" if header_data.specialization_values[index].strip().upper() in ["TRUE", "1"] else "false"} }}'
|
||||||
defval = header_data.specialization_values[i].strip()
|
for index, name in enumerate(header_data.specialization_names)
|
||||||
if defval.upper() == "TRUE" or defval == "1":
|
)
|
||||||
defval = "true"
|
file.write(f"""\
|
||||||
|
static Specialization _spec_pairs[] = {{
|
||||||
|
{specializations},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
defval = "false"
|
file.write("""\
|
||||||
|
static Specialization *_spec_pairs = nullptr;
|
||||||
fd.write('\t\t\t{"' + header_data.specialization_names[i] + '",' + defval + "},\n")
|
""")
|
||||||
specializations_found.append(header_data.specialization_names[i])
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
else:
|
|
||||||
fd.write("\t\tstatic Specialization *_spec_pairs=nullptr;\n")
|
|
||||||
|
|
||||||
feedback_count = 0
|
|
||||||
|
|
||||||
if header_data.feedbacks:
|
if header_data.feedbacks:
|
||||||
fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
|
feedbacks = ",\n\t\t\t".join(
|
||||||
for x in header_data.feedbacks:
|
f'{{ "{name}", {0 if spec not in header_data.specialization_names else (1 << header_data.specialization_names.index(spec))} }}'
|
||||||
name = x[0]
|
for name, spec in header_data.feedbacks
|
||||||
spec = x[1]
|
|
||||||
if spec in specializations_found:
|
|
||||||
fd.write('\t\t\t{"' + name + '",' + str(1 << specializations_found.index(spec)) + "},\n")
|
|
||||||
else:
|
|
||||||
fd.write('\t\t\t{"' + name + '",0},\n')
|
|
||||||
|
|
||||||
feedback_count += 1
|
|
||||||
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
else:
|
|
||||||
fd.write("\t\tstatic const Feedback* _feedbacks=nullptr;\n")
|
|
||||||
|
|
||||||
fd.write("\t\tstatic const char _vertex_code[]={\n")
|
|
||||||
fd.write(to_raw_cstring(header_data.vertex_lines))
|
|
||||||
fd.write("\n\t\t};\n\n")
|
|
||||||
|
|
||||||
fd.write("\t\tstatic const char _fragment_code[]={\n")
|
|
||||||
fd.write(to_raw_cstring(header_data.fragment_lines))
|
|
||||||
fd.write("\n\t\t};\n\n")
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
'\t\t_setup(_vertex_code,_fragment_code,"'
|
|
||||||
+ out_file_class
|
|
||||||
+ '",'
|
|
||||||
+ str(len(header_data.uniforms))
|
|
||||||
+ ",_uniform_strings,"
|
|
||||||
+ str(len(header_data.ubos))
|
|
||||||
+ ",_ubo_pairs,"
|
|
||||||
+ str(feedback_count)
|
|
||||||
+ ",_feedbacks,"
|
|
||||||
+ str(len(header_data.texunits))
|
|
||||||
+ ",_texunit_pairs,"
|
|
||||||
+ str(len(header_data.specialization_names))
|
|
||||||
+ ",_spec_pairs,"
|
|
||||||
+ str(variant_count)
|
|
||||||
+ ",_variant_defines);\n"
|
|
||||||
)
|
)
|
||||||
|
file.write(f"""\
|
||||||
|
static const Feedback _feedbacks[] = {{
|
||||||
|
{feedbacks},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
file.write("""\
|
||||||
|
static const Feedback *_feedbacks = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
fd.write("\t}\n\n")
|
file.write(f"""\
|
||||||
|
static const char _vertex_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.vertex_lines)}
|
||||||
|
}};
|
||||||
|
|
||||||
fd.write("};\n")
|
static const char _fragment_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.fragment_lines)}
|
||||||
|
}};
|
||||||
|
|
||||||
|
_setup(_vertex_code, _fragment_code, "{out_file_class}",
|
||||||
|
{len(header_data.uniforms)}, _uniform_strings, {len(header_data.ubos)}, _ubo_pairs,
|
||||||
|
{len(header_data.feedbacks)}, _feedbacks, {len(header_data.texunits)}, _texunit_pairs,
|
||||||
|
{len(header_data.specialization_names)}, _spec_pairs, {variant_count}, _variant_defines);
|
||||||
|
}}
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def build_gles3_headers(target, source, env):
|
def build_gles3_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
|
build_gles3_header(f"{src}.gen.h", str(src))
|
||||||
|
|
109
glsl_builders.py
109
glsl_builders.py
|
@ -1,9 +1,8 @@
|
||||||
"""Functions used to generate source files during build time"""
|
"""Functions used to generate source files during build time"""
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from methods import print_error, to_raw_cstring
|
from methods import generated_wrapper, print_error, to_raw_cstring
|
||||||
|
|
||||||
|
|
||||||
class RDHeaderStruct:
|
class RDHeaderStruct:
|
||||||
|
@ -92,61 +91,49 @@ def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth:
|
||||||
return header_data
|
return header_data
|
||||||
|
|
||||||
|
|
||||||
def build_rd_header(
|
def build_rd_header(filename: str, shader: str) -> None:
|
||||||
filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RDHeaderStruct] = None
|
include_file_in_rd_header(shader, header_data := RDHeaderStruct(), 0)
|
||||||
) -> None:
|
class_name = os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
||||||
header_data = header_data or RDHeaderStruct()
|
|
||||||
include_file_in_rd_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
|
||||||
out_file = filename + ".gen.h"
|
|
||||||
else:
|
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
out_file_base = out_file
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
|
||||||
out_file_class = out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
|
||||||
|
|
||||||
if header_data.compute_lines:
|
|
||||||
body_parts = [
|
|
||||||
"static const char _compute_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.compute_lines),
|
|
||||||
f'setup(nullptr, nullptr, _compute_code, "{out_file_class}");',
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
body_parts = [
|
|
||||||
"static const char _vertex_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.vertex_lines),
|
|
||||||
"static const char _fragment_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.fragment_lines),
|
|
||||||
f'setup(_vertex_code, _fragment_code, nullptr, "{out_file_class}");',
|
|
||||||
]
|
|
||||||
|
|
||||||
body_content = "\n\t\t".join(body_parts)
|
|
||||||
|
|
||||||
# Intended curly brackets are doubled so f-string doesn't eat them up.
|
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
with generated_wrapper(filename) as file:
|
||||||
|
file.write(f"""\
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class {out_file_class} : public ShaderRD {{
|
class {class_name} : public ShaderRD {{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
{class_name}() {{
|
||||||
|
""")
|
||||||
|
|
||||||
{out_file_class}() {{
|
if header_data.compute_lines:
|
||||||
|
file.write(f"""\
|
||||||
|
static const char *_vertex_code = nullptr;
|
||||||
|
static const char *_fragment_code = nullptr;
|
||||||
|
static const char _compute_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.compute_lines)}
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
file.write(f"""\
|
||||||
|
static const char _vertex_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.vertex_lines)}
|
||||||
|
}};
|
||||||
|
static const char _fragment_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.fragment_lines)}
|
||||||
|
}};
|
||||||
|
static const char *_compute_code = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
{body_content}
|
file.write(f"""\
|
||||||
|
setup(_vertex_code, _fragment_code, _compute_code, "{class_name}");
|
||||||
}}
|
}}
|
||||||
}};
|
}};
|
||||||
"""
|
""")
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
|
||||||
fd.write(shader_template)
|
|
||||||
|
|
||||||
|
|
||||||
def build_rd_headers(target, source, env):
|
def build_rd_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_rd_header(filename=str(x))
|
build_rd_header(f"{src}.gen.h", str(src))
|
||||||
|
|
||||||
|
|
||||||
class RAWHeaderStruct:
|
class RAWHeaderStruct:
|
||||||
|
@ -171,34 +158,18 @@ def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, dept
|
||||||
line = fs.readline()
|
line = fs.readline()
|
||||||
|
|
||||||
|
|
||||||
def build_raw_header(
|
def build_raw_header(filename: str, shader: str) -> None:
|
||||||
filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RAWHeaderStruct] = None
|
include_file_in_raw_header(shader, header_data := RAWHeaderStruct(), 0)
|
||||||
):
|
|
||||||
header_data = header_data or RAWHeaderStruct()
|
|
||||||
include_file_in_raw_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
with generated_wrapper(filename) as file:
|
||||||
out_file = filename + ".gen.h"
|
file.write(f"""\
|
||||||
else:
|
static const char {os.path.basename(shader).replace(".glsl", "_shader_glsl")}[] = {{
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
out_file_base = out_file.replace(".glsl.gen.h", "_shader_glsl")
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
|
||||||
|
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char {out_file_base}[] = {{
|
|
||||||
{to_raw_cstring(header_data.code)}
|
{to_raw_cstring(header_data.code)}
|
||||||
}};
|
}};
|
||||||
"""
|
""")
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as f:
|
|
||||||
f.write(shader_template)
|
|
||||||
|
|
||||||
|
|
||||||
def build_raw_headers(target, source, env):
|
def build_raw_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_raw_header(filename=str(x))
|
build_raw_header(f"{src}.gen.h", str(src))
|
||||||
|
|
|
@ -1503,13 +1503,13 @@ def generated_wrapper(
|
||||||
unassigned, the value is determined by file extension.
|
unassigned, the value is determined by file extension.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if guard is None:
|
|
||||||
guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
|
|
||||||
|
|
||||||
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
||||||
|
if not path.endswith(".out"): # For test output, we only care about the content.
|
||||||
file.write(generate_copyright_header(path))
|
file.write(generate_copyright_header(path))
|
||||||
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
||||||
|
|
||||||
|
if guard is None:
|
||||||
|
guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
|
||||||
if guard:
|
if guard:
|
||||||
file.write("#pragma once\n\n")
|
file.write("#pragma once\n\n")
|
||||||
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
CWD = Path(__file__).parent
|
|
||||||
ROOT = CWD.parent.parent
|
|
||||||
# append directory with build files to sys.path to import them
|
|
||||||
sys.path.append(str(ROOT))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def shader_files(request):
|
|
||||||
shader_path = request.param
|
|
||||||
|
|
||||||
res = {
|
|
||||||
"path_input": str(CWD / "fixtures" / f"{shader_path}.glsl"),
|
|
||||||
"path_output": str(CWD / "fixtures" / f"{shader_path}.glsl.gen.h"),
|
|
||||||
"path_expected_full": str(CWD / "fixtures" / f"{shader_path}_expected_full.glsl"),
|
|
||||||
"path_expected_parts": str(CWD / "fixtures" / f"{shader_path}_expected_parts.json"),
|
|
||||||
}
|
|
||||||
yield res
|
|
||||||
|
|
||||||
if not os.getenv("PYTEST_KEEP_GENERATED_FILES"):
|
|
||||||
os.remove(res["path_output"])
|
|
64
tests/python_build/fixtures/gles3/vertex_fragment.out
Normal file
64
tests/python_build/fixtures/gles3/vertex_fragment.out
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#include "drivers/gles3/shader_gles3.h"
|
||||||
|
|
||||||
|
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
|
||||||
|
public:
|
||||||
|
enum ShaderVariant {
|
||||||
|
MODE_NINEPATCH,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Specializations {
|
||||||
|
DISABLE_LIGHTING = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
_FORCE_INLINE_ bool version_bind_shader(RID p_version, ShaderVariant p_variant, uint64_t p_specialization = 0) {
|
||||||
|
return _version_bind_shader(p_version, p_variant, p_specialization);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void _init() override {
|
||||||
|
static const char **_uniform_strings = nullptr;
|
||||||
|
static const char *_variant_defines[] = {
|
||||||
|
"#define USE_NINEPATCH",
|
||||||
|
};
|
||||||
|
static TexUnitPair *_texunit_pairs = nullptr;
|
||||||
|
static UBOPair *_ubo_pairs = nullptr;
|
||||||
|
static Specialization _spec_pairs[] = {
|
||||||
|
{ "DISABLE_LIGHTING", false },
|
||||||
|
};
|
||||||
|
static const Feedback *_feedbacks = nullptr;
|
||||||
|
static const char _vertex_code[] = {
|
||||||
|
R"<!>(
|
||||||
|
precision highp float;
|
||||||
|
precision highp int;
|
||||||
|
|
||||||
|
layout(location = 0) in highp vec3 vertex;
|
||||||
|
|
||||||
|
out highp vec4 position_interp;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
position_interp = vec4(vertex.x,1,0,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
)<!>"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _fragment_code[] = {
|
||||||
|
R"<!>(
|
||||||
|
precision highp float;
|
||||||
|
precision highp int;
|
||||||
|
|
||||||
|
in highp vec4 position_interp;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
highp float depth = ((position_interp.z / position_interp.w) + 1.0);
|
||||||
|
frag_color = vec4(depth);
|
||||||
|
}
|
||||||
|
)<!>"
|
||||||
|
};
|
||||||
|
|
||||||
|
_setup(_vertex_code, _fragment_code, "VertexFragmentShaderGLES3",
|
||||||
|
0, _uniform_strings, 0, _ubo_pairs,
|
||||||
|
0, _feedbacks, 0, _texunit_pairs,
|
||||||
|
1, _spec_pairs, 1, _variant_defines);
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,71 +0,0 @@
|
||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "drivers/gles3/shader_gles3.h"
|
|
||||||
|
|
||||||
|
|
||||||
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum ShaderVariant {
|
|
||||||
MODE_NINEPATCH,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Specializations {
|
|
||||||
DISABLE_LIGHTING=1,
|
|
||||||
};
|
|
||||||
|
|
||||||
_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant,uint64_t p_specialization=0) { return _version_bind_shader(p_version,p_variant,p_specialization); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual void _init() override {
|
|
||||||
|
|
||||||
static const char **_uniform_strings=nullptr;
|
|
||||||
static const char* _variant_defines[]={
|
|
||||||
"#define USE_NINEPATCH",
|
|
||||||
};
|
|
||||||
|
|
||||||
static TexUnitPair *_texunit_pairs=nullptr;
|
|
||||||
static UBOPair *_ubo_pairs=nullptr;
|
|
||||||
static Specialization _spec_pairs[]={
|
|
||||||
{"DISABLE_LIGHTING",false},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const Feedback* _feedbacks=nullptr;
|
|
||||||
static const char _vertex_code[]={
|
|
||||||
R"<!>(
|
|
||||||
precision highp float;
|
|
||||||
precision highp int;
|
|
||||||
|
|
||||||
layout(location = 0) in highp vec3 vertex;
|
|
||||||
|
|
||||||
out highp vec4 position_interp;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
position_interp = vec4(vertex.x,1,0,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
)<!>"
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char _fragment_code[]={
|
|
||||||
R"<!>(
|
|
||||||
precision highp float;
|
|
||||||
precision highp int;
|
|
||||||
|
|
||||||
in highp vec4 position_interp;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
highp float depth = ((position_interp.z / position_interp.w) + 1.0);
|
|
||||||
frag_color = vec4(depth);
|
|
||||||
}
|
|
||||||
)<!>"
|
|
||||||
};
|
|
||||||
|
|
||||||
_setup(_vertex_code,_fragment_code,"VertexFragmentShaderGLES3",0,_uniform_strings,0,_ubo_pairs,0,_feedbacks,0,_texunit_pairs,1,_spec_pairs,1,_variant_defines);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
|
@ -1,53 +0,0 @@
|
||||||
{
|
|
||||||
"vertex_lines": [
|
|
||||||
"",
|
|
||||||
"precision highp float;",
|
|
||||||
"precision highp int;",
|
|
||||||
"",
|
|
||||||
"layout(location = 0) in highp vec3 vertex;",
|
|
||||||
"",
|
|
||||||
"out highp vec4 position_interp;",
|
|
||||||
"",
|
|
||||||
"void main() {",
|
|
||||||
"\tposition_interp = vec4(vertex.x,1,0,1);",
|
|
||||||
"}",
|
|
||||||
""
|
|
||||||
],
|
|
||||||
"fragment_lines": [
|
|
||||||
"",
|
|
||||||
"precision highp float;",
|
|
||||||
"precision highp int;",
|
|
||||||
"",
|
|
||||||
"in highp vec4 position_interp;",
|
|
||||||
"",
|
|
||||||
"void main() {",
|
|
||||||
"\thighp float depth = ((position_interp.z / position_interp.w) + 1.0);",
|
|
||||||
"\tfrag_color = vec4(depth);",
|
|
||||||
"}"
|
|
||||||
],
|
|
||||||
"uniforms": [],
|
|
||||||
"fbos": [],
|
|
||||||
"texunits": [],
|
|
||||||
"texunit_names": [],
|
|
||||||
"ubos": [],
|
|
||||||
"ubo_names": [],
|
|
||||||
"feedbacks": [],
|
|
||||||
"vertex_included_files": [],
|
|
||||||
"fragment_included_files": [],
|
|
||||||
"reading": "fragment",
|
|
||||||
"line_offset": 33,
|
|
||||||
"vertex_offset": 10,
|
|
||||||
"fragment_offset": 23,
|
|
||||||
"variant_defines": [
|
|
||||||
"#define USE_NINEPATCH"
|
|
||||||
],
|
|
||||||
"variant_names": [
|
|
||||||
"MODE_NINEPATCH"
|
|
||||||
],
|
|
||||||
"specialization_names": [
|
|
||||||
"DISABLE_LIGHTING"
|
|
||||||
],
|
|
||||||
"specialization_values": [
|
|
||||||
" false\n"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,6 +1,3 @@
|
||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char compute_shader_glsl[] = {
|
static const char compute_shader_glsl[] = {
|
||||||
R"<!>(#[compute]
|
R"<!>(#[compute]
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"code": "#[compute]\n\n#version 450\n\n#VERSION_DEFINES\n\n\n#define M_PI 3.14159265359\n\nvoid main() {\n\tvec3 static_light = vec3(0, 1, 0);\n}\n"
|
|
||||||
}
|
|
|
@ -1,6 +1,3 @@
|
||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char vertex_fragment_shader_glsl[] = {
|
static const char vertex_fragment_shader_glsl[] = {
|
||||||
R"<!>(#[versions]
|
R"<!>(#[versions]
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"code": "#[versions]\n\nlines = \"#define MODE_LINES\";\n\n#[vertex]\n\n#version 450\n\n#VERSION_DEFINES\n\nlayout(location = 0) out vec3 uv_interp;\n\nvoid main() {\n\n#ifdef MODE_LINES\n\tuv_interp = vec3(0,0,1);\n#endif\n}\n\n#[fragment]\n\n#version 450\n\n#VERSION_DEFINES\n\n#define M_PI 3.14159265359\n\nlayout(location = 0) out vec4 dst_color;\n\nvoid main() {\n\tdst_color = vec4(1,1,0,0);\n}\n"
|
|
||||||
}
|
|
|
@ -1,14 +1,10 @@
|
||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class ComputeShaderRD : public ShaderRD {
|
class ComputeShaderRD : public ShaderRD {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ComputeShaderRD() {
|
ComputeShaderRD() {
|
||||||
|
static const char *_vertex_code = nullptr;
|
||||||
|
static const char *_fragment_code = nullptr;
|
||||||
static const char _compute_code[] = {
|
static const char _compute_code[] = {
|
||||||
R"<!>(
|
R"<!>(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -24,6 +20,6 @@ void main() {
|
||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
|
setup(_vertex_code, _fragment_code, _compute_code, "ComputeShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"vertex_lines": [],
|
|
||||||
"fragment_lines": [],
|
|
||||||
"compute_lines": [
|
|
||||||
"",
|
|
||||||
"#version 450",
|
|
||||||
"",
|
|
||||||
"#VERSION_DEFINES",
|
|
||||||
"",
|
|
||||||
"#define BLOCK_SIZE 8",
|
|
||||||
"",
|
|
||||||
"#define M_PI 3.14159265359",
|
|
||||||
"",
|
|
||||||
"void main() {",
|
|
||||||
"\tuint t = BLOCK_SIZE + 1;",
|
|
||||||
"}"
|
|
||||||
],
|
|
||||||
"vertex_included_files": [],
|
|
||||||
"fragment_included_files": [],
|
|
||||||
"compute_included_files": [
|
|
||||||
"tests/python_build/fixtures/rd_glsl/_included.glsl"
|
|
||||||
],
|
|
||||||
"reading": "compute",
|
|
||||||
"line_offset": 13,
|
|
||||||
"vertex_offset": 0,
|
|
||||||
"fragment_offset": 0,
|
|
||||||
"compute_offset": 1
|
|
||||||
}
|
|
|
@ -1,14 +1,8 @@
|
||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class VertexFragmentShaderRD : public ShaderRD {
|
class VertexFragmentShaderRD : public ShaderRD {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VertexFragmentShaderRD() {
|
VertexFragmentShaderRD() {
|
||||||
|
|
||||||
static const char _vertex_code[] = {
|
static const char _vertex_code[] = {
|
||||||
R"<!>(
|
R"<!>(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -38,6 +32,7 @@ void main() {
|
||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
setup(_vertex_code, _fragment_code, nullptr, "VertexFragmentShaderRD");
|
static const char *_compute_code = nullptr;
|
||||||
|
setup(_vertex_code, _fragment_code, _compute_code, "VertexFragmentShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,40 +0,0 @@
|
||||||
{
|
|
||||||
"vertex_lines": [
|
|
||||||
"",
|
|
||||||
"#version 450",
|
|
||||||
"",
|
|
||||||
"#VERSION_DEFINES",
|
|
||||||
"",
|
|
||||||
"#define M_PI 3.14159265359",
|
|
||||||
"",
|
|
||||||
"layout(location = 0) out vec2 uv_interp;",
|
|
||||||
"",
|
|
||||||
"void main() {",
|
|
||||||
"\tuv_interp = vec2(0, 1);",
|
|
||||||
"}",
|
|
||||||
""
|
|
||||||
],
|
|
||||||
"fragment_lines": [
|
|
||||||
"",
|
|
||||||
"#version 450",
|
|
||||||
"",
|
|
||||||
"#VERSION_DEFINES",
|
|
||||||
"",
|
|
||||||
"layout(location = 0) in vec2 uv_interp;",
|
|
||||||
"",
|
|
||||||
"void main() {",
|
|
||||||
"\tuv_interp = vec2(1, 0);",
|
|
||||||
"}"
|
|
||||||
],
|
|
||||||
"compute_lines": [],
|
|
||||||
"vertex_included_files": [
|
|
||||||
"tests/python_build/fixtures/rd_glsl/_included.glsl"
|
|
||||||
],
|
|
||||||
"fragment_included_files": [],
|
|
||||||
"compute_included_files": [],
|
|
||||||
"reading": "fragment",
|
|
||||||
"line_offset": 25,
|
|
||||||
"vertex_offset": 1,
|
|
||||||
"fragment_offset": 15,
|
|
||||||
"compute_offset": 0
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
import json
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from gles3_builders import GLES3HeaderStruct, build_gles3_header
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
["shader_files", "builder", "header_struct"],
|
|
||||||
[
|
|
||||||
("gles3/vertex_fragment", build_gles3_header, GLES3HeaderStruct),
|
|
||||||
],
|
|
||||||
indirect=["shader_files"],
|
|
||||||
)
|
|
||||||
def test_gles3_builder(shader_files, builder, header_struct):
|
|
||||||
header = header_struct()
|
|
||||||
|
|
||||||
builder(shader_files["path_input"], "drivers/gles3/shader_gles3.h", "GLES3", header_data=header)
|
|
||||||
|
|
||||||
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
|
|
||||||
expected_parts = json.load(f)
|
|
||||||
assert expected_parts == header.__dict__
|
|
||||||
|
|
||||||
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
|
|
||||||
actual_output = f.read()
|
|
||||||
assert actual_output
|
|
||||||
|
|
||||||
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
|
|
||||||
expected_output = f.read()
|
|
||||||
|
|
||||||
assert actual_output == expected_output
|
|
|
@ -1,37 +0,0 @@
|
||||||
import json
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from glsl_builders import RAWHeaderStruct, RDHeaderStruct, build_raw_header, build_rd_header
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
[
|
|
||||||
"shader_files",
|
|
||||||
"builder",
|
|
||||||
"header_struct",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
("glsl/vertex_fragment", build_raw_header, RAWHeaderStruct),
|
|
||||||
("glsl/compute", build_raw_header, RAWHeaderStruct),
|
|
||||||
("rd_glsl/vertex_fragment", build_rd_header, RDHeaderStruct),
|
|
||||||
("rd_glsl/compute", build_rd_header, RDHeaderStruct),
|
|
||||||
],
|
|
||||||
indirect=["shader_files"],
|
|
||||||
)
|
|
||||||
def test_glsl_builder(shader_files, builder, header_struct):
|
|
||||||
header = header_struct()
|
|
||||||
builder(shader_files["path_input"], header_data=header)
|
|
||||||
|
|
||||||
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
|
|
||||||
expected_parts = json.load(f)
|
|
||||||
assert expected_parts == header.__dict__
|
|
||||||
|
|
||||||
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
|
|
||||||
actual_output = f.read()
|
|
||||||
assert actual_output
|
|
||||||
|
|
||||||
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
|
|
||||||
expected_output = f.read()
|
|
||||||
|
|
||||||
assert actual_output == expected_output
|
|
63
tests/python_build/validate_builders.py
Normal file
63
tests/python_build/validate_builders.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
if __name__ != "__main__":
|
||||||
|
raise ImportError(f"{__name__} should not be used as a module.")
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from typing import Any, Callable
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../"))
|
||||||
|
|
||||||
|
from gles3_builders import build_gles3_header
|
||||||
|
from glsl_builders import build_raw_header, build_rd_header
|
||||||
|
|
||||||
|
FUNC_PATH_KWARGS: list[tuple[Callable[..., None], str, dict[str, Any]]] = [
|
||||||
|
(
|
||||||
|
build_gles3_header,
|
||||||
|
"tests/python_build/fixtures/gles3/vertex_fragment.out",
|
||||||
|
{"shader": "tests/python_build/fixtures/gles3/vertex_fragment.glsl"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
build_raw_header,
|
||||||
|
"tests/python_build/fixtures/glsl/compute.out",
|
||||||
|
{"shader": "tests/python_build/fixtures/glsl/compute.glsl"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
build_raw_header,
|
||||||
|
"tests/python_build/fixtures/glsl/vertex_fragment.out",
|
||||||
|
{"shader": "tests/python_build/fixtures/glsl/vertex_fragment.glsl"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
build_rd_header,
|
||||||
|
"tests/python_build/fixtures/rd_glsl/compute.out",
|
||||||
|
{"shader": "tests/python_build/fixtures/rd_glsl/compute.glsl"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
build_rd_header,
|
||||||
|
"tests/python_build/fixtures/rd_glsl/vertex_fragment.out",
|
||||||
|
{"shader": "tests/python_build/fixtures/rd_glsl/vertex_fragment.glsl"},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
ret = 0
|
||||||
|
|
||||||
|
for func, path, kwargs in FUNC_PATH_KWARGS:
|
||||||
|
if os.path.exists(out_path := os.path.abspath(path)):
|
||||||
|
with open(out_path, "rb") as file:
|
||||||
|
raw = file.read()
|
||||||
|
func(path, **kwargs)
|
||||||
|
with open(out_path, "rb") as file:
|
||||||
|
if raw != file.read():
|
||||||
|
ret += 1
|
||||||
|
else:
|
||||||
|
func(path, **kwargs)
|
||||||
|
ret += 1
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
sys.exit(main())
|
Loading…
Add table
Add a link
Reference in a new issue