Selaa lähdekoodia

Merge pull request #101443 from Repiteo/ci/replace-pytest

CI: Replace pytest with pre-commit hook
Thaddeus Crews 4 kuukautta sitten
vanhempi
commit
ac13efc822

+ 5 - 20
.github/workflows/static_checks.yml

@@ -13,15 +13,10 @@ jobs:
         with:
           fetch-depth: 2
 
-      - name: Install APT dependencies
-        run: |
-          sudo apt update
-          sudo apt install -y libxml2-utils
-
-      - name: Install Python dependencies and general setup
+      # 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: |
-          pip3 install pytest==7.1.2
-          git config diff.wsErrorHighlight all
+          bash ./misc/scripts/gitignore_check.sh
 
       - name: Get changed files
         env:
@@ -32,27 +27,17 @@ jobs:
           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)
           fi
-          echo "$files" >> changed.txt
-          cat changed.txt
-          files=$(echo "$files" | grep -v 'thirdparty' | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
+          files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
           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
         uses: pre-commit/[email protected]
         with:
           extra_args: --files ${{ env.CHANGED_FILES }}
 
-      - name: Python builders checks via pytest
-        run: |
-          pytest ./tests/python_build
-
       - name: Class reference schema checks
         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
 
       - name: Run C compiler on `gdextension_interface.h`

+ 8 - 4
.pre-commit-config.yaml

@@ -16,12 +16,10 @@ repos:
       - id: clang-format
         files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java)$
         types_or: [text]
-        exclude: ^tests/python_build/.*
       - id: clang-format
         name: clang-format-glsl
         files: \.glsl$
         types_or: [text]
-        exclude: ^tests/python_build/.*
         args: [-style=file:misc/utility/clang_format_glsl.yml]
 
   - 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)$
         args: [--fix, --quiet, --use-color]
         types_or: [text]
-        exclude: ^tests/python_build/.*
         additional_dependencies: [clang-tidy==19.1.0]
         require_serial: true
         stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`
@@ -48,7 +45,7 @@ repos:
         types_or: [text]
 
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.14.1  # Latest version that supports Python 3.8
+    rev: v1.14.1 # Latest version that supports Python 3.8
     hooks:
       - id: mypy
         files: \.py$
@@ -88,6 +85,13 @@ repos:
         pass_filenames: false
         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
         name: eslint
         language: node

+ 292 - 359
gles3_builders.py

@@ -1,9 +1,8 @@
 """Functions used to generate source files during build time"""
 
 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:
@@ -189,399 +188,333 @@ def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct,
     return header_data
 
 
-def build_gles3_header(
-    filename: str,
-    include: str,
-    class_suffix: str,
-    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)
+def build_gles3_header(filename: str, shader: str) -> None:
+    include_file_in_gles3_header(shader, header_data := GLES3HeaderStruct(), 0)
+    out_file_class = (
+        os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderGLES3"
+    )
 
-    if optional_output_filename is None:
-        out_file = filename + ".gen.h"
-    else:
-        out_file = optional_output_filename
-
-    with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
+    with generated_wrapper(filename) as file:
         defspec = 0
         defvariant = ""
 
-        fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
-        fd.write("#pragma once\n")
-
-        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(".", "") + "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")
+        file.write(f"""\
+#include "drivers/gles3/shader_gles3.h"
 
-        fd.write("public:\n\n")
+class {out_file_class} : public ShaderGLES3 {{
+public:
+""")
 
         if header_data.uniforms:
-            fd.write("\tenum Uniforms {\n")
-            for x in header_data.uniforms:
-                fd.write("\t\t" + x.upper() + ",\n")
-            fd.write("\t};\n\n")
+            uniforms = ",\n\t\t".join(uniform.upper() for uniform in header_data.uniforms)
+            file.write(f"""\
+	enum Uniforms {{
+		{uniforms},
+	}};
+
+""")
 
         if header_data.variant_names:
-            fd.write("\tenum ShaderVariant {\n")
-            for x in header_data.variant_names:
-                fd.write("\t\t" + x + ",\n")
-            fd.write("\t};\n\n")
+            variant_names = ",\n\t\t".join(name for name in header_data.variant_names)
         else:
-            fd.write("\tenum ShaderVariant { DEFAULT };\n\n")
-            defvariant = "=DEFAULT"
-
-        if header_data.specialization_names:
-            fd.write("\tenum Specializations {\n")
-            counter = 0
-            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"
-        )
+            variant_names = "DEFAULT"
+            defvariant = " = DEFAULT"
+        file.write(f"""\
+	enum ShaderVariant {{
+		{variant_names},
+	}};
 
-        if header_data.uniforms:
-            fd.write(
-                "\t_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform,RID p_version,ShaderVariant p_variant"
-                + defvariant
-                + ",uint64_t p_specialization="
-                + str(defspec)
-                + ") { return _version_get_uniform(p_uniform,p_version,p_variant,p_specialization); }\n\n"
-            )
+""")
 
-            fd.write(
-                "\t#define _FU if (version_get_uniform(p_uniform,p_version,p_variant,p_specialization)<0) return; \n\n "
-            )
-            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(
-                """\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D& p_transform,RID p_version,ShaderVariant p_variant"""
-                + defvariant
-                + """,uint64_t p_specialization="""
-                + str(defspec)
-                + """) {  _FU
-
-                const Transform3D &tr = p_transform;
-
-                GLfloat matrix[16]={ /* build a 16x16 matrix */
-                    (GLfloat)tr.basis.rows[0][0],
-                    (GLfloat)tr.basis.rows[1][0],
-                    (GLfloat)tr.basis.rows[2][0],
-                    (GLfloat)0,
-                    (GLfloat)tr.basis.rows[0][1],
-                    (GLfloat)tr.basis.rows[1][1],
-                    (GLfloat)tr.basis.rows[2][1],
-                    (GLfloat)0,
-                    (GLfloat)tr.basis.rows[0][2],
-                    (GLfloat)tr.basis.rows[1][2],
-                    (GLfloat)tr.basis.rows[2][2],
-                    (GLfloat)0,
-                    (GLfloat)tr.origin.x,
-                    (GLfloat)tr.origin.y,
-                    (GLfloat)tr.origin.z,
-                    (GLfloat)1
-                };
-
-                        glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
-
-            }
-
-            """
-            )
-
-            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;
-
-            GLfloat matrix[16]={ /* build a 16x16 matrix */
-                (GLfloat)tr.columns[0][0],
-                (GLfloat)tr.columns[0][1],
-                (GLfloat)0,
-                (GLfloat)0,
-                (GLfloat)tr.columns[1][0],
-                (GLfloat)tr.columns[1][1],
-                (GLfloat)0,
-                (GLfloat)0,
-                (GLfloat)0,
-                (GLfloat)0,
-                (GLfloat)1,
-                (GLfloat)0,
-                (GLfloat)tr.columns[2][0],
-                (GLfloat)tr.columns[2][1],
-                (GLfloat)0,
-                (GLfloat)1
-            };
-
-                glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
-
-            }
-
-            """
+        if header_data.specialization_names:
+            specialization_names = ",\n\t\t".join(
+                f"{name.upper()} = {1 << index}" for index, name in enumerate(header_data.specialization_names)
             )
+            file.write(f"""\
+	enum Specializations {{
+		{specialization_names},
+	}};
 
-            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
+""")
+        for index, specialization_value in enumerate(header_data.specialization_values):
+            if specialization_value.strip().upper() in ["TRUE", "1"]:
+                defspec |= 1 << index
 
-                GLfloat matrix[16];
+        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);
+	}}
 
-                for (int i = 0; i < 4; i++) {
-                    for (int j = 0; j < 4; 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);
-        }"""
-            )
-
-            fd.write("\n\n#undef _FU\n\n\n")
-
-        fd.write("protected:\n\n")
-
-        fd.write("\tvirtual void _init() override {\n\n")
+        if header_data.uniforms:
+            file.write(f"""\
+	_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
+		return _version_get_uniform(p_uniform, p_version, p_variant, p_specialization);
+	}}
+
+	/* clang-format off */
+#define TRY_GET_UNIFORM if (version_get_uniform(p_uniform, p_version, p_variant, p_specialization) < 0) return
+	/* clang-format on */
+
+	_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float 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, 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;
+
+		GLfloat matrix[16] = {{ /* build a 16x16 matrix */
+			(GLfloat)tr.basis.rows[0][0],
+			(GLfloat)tr.basis.rows[1][0],
+			(GLfloat)tr.basis.rows[2][0],
+			(GLfloat)0,
+			(GLfloat)tr.basis.rows[0][1],
+			(GLfloat)tr.basis.rows[1][1],
+			(GLfloat)tr.basis.rows[2][1],
+			(GLfloat)0,
+			(GLfloat)tr.basis.rows[0][2],
+			(GLfloat)tr.basis.rows[1][2],
+			(GLfloat)tr.basis.rows[2][2],
+			(GLfloat)0,
+			(GLfloat)tr.origin.x,
+			(GLfloat)tr.origin.y,
+			(GLfloat)tr.origin.z,
+			(GLfloat)1
+		}};
+
+		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;
+		const Transform2D &tr = p_transform;
+
+		GLfloat matrix[16] = {{ /* build a 16x16 matrix */
+			(GLfloat)tr.columns[0][0],
+			(GLfloat)tr.columns[0][1],
+			(GLfloat)0,
+			(GLfloat)0,
+			(GLfloat)tr.columns[1][0],
+			(GLfloat)tr.columns[1][1],
+			(GLfloat)0,
+			(GLfloat)0,
+			(GLfloat)0,
+			(GLfloat)0,
+			(GLfloat)1,
+			(GLfloat)0,
+			(GLfloat)tr.columns[2][0],
+			(GLfloat)tr.columns[2][1],
+			(GLfloat)0,
+			(GLfloat)1
+		}};
+
+		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;
+		GLfloat matrix[16];
+
+		for (int i = 0; i < 4; i++) {{
+			for (int j = 0; j < 4; 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);
+	}}
+
+#undef TRY_GET_UNIFORM
+
+""")
+
+        file.write("""\
+protected:
+	virtual void _init() override {
+""")
 
         if header_data.uniforms:
-            fd.write("\t\tstatic const char* _uniform_strings[]={\n")
-            if header_data.uniforms:
-                for x in header_data.uniforms:
-                    fd.write('\t\t\t"' + x + '",\n')
-            fd.write("\t\t};\n\n")
+            uniforms = ",\n\t\t\t".join(f'"{uniform}"' for uniform in header_data.uniforms)
+            file.write(f"""\
+		static const char *_uniform_strings[] = {{
+			{uniforms}
+		}};
+""")
         else:
-            fd.write("\t\tstatic const char **_uniform_strings=nullptr;\n")
-
-        variant_count = 1
-        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")
+            file.write("""\
+		static const char **_uniform_strings = nullptr;
+""")
+
+        if 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:
-            fd.write('\t\tstatic const char **_variant_defines[]={" "};\n')
+            variant_count = 1
+            file.write("""\
+		static const char **_variant_defines[] = {" "};
+""")
 
         if header_data.texunits:
-            fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
-            for x in header_data.texunits:
-                fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
-            fd.write("\t\t};\n\n")
+            texunits = ",\n\t\t\t".join(f'{{ "{name}", {texunit} }}' for name, texunit in header_data.texunits)
+            file.write(f"""\
+		static TexUnitPair _texunit_pairs[] = {{
+			{texunits},
+		}};
+""")
         else:
-            fd.write("\t\tstatic TexUnitPair *_texunit_pairs=nullptr;\n")
+            file.write("""\
+		static TexUnitPair *_texunit_pairs = nullptr;
+""")
 
         if header_data.ubos:
-            fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
-            for x in header_data.ubos:
-                fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
-            fd.write("\t\t};\n\n")
+            ubos = ",\n\t\t\t".join(f'{{ "{name}", {ubo} }}' for name, ubo in header_data.ubos)
+            file.write(f"""\
+		static UBOPair _ubo_pairs[] = {{
+			{ubos},
+		}};
+""")
         else:
-            fd.write("\t\tstatic UBOPair *_ubo_pairs=nullptr;\n")
-
-        specializations_found = []
+            file.write("""\
+		static UBOPair *_ubo_pairs = nullptr;
+""")
 
         if header_data.specialization_names:
-            fd.write("\t\tstatic Specialization _spec_pairs[]={\n")
-            for i in range(len(header_data.specialization_names)):
-                defval = header_data.specialization_values[i].strip()
-                if defval.upper() == "TRUE" or defval == "1":
-                    defval = "true"
-                else:
-                    defval = "false"
-
-                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")
+            specializations = ",\n\t\t\t".join(
+                f'{{ "{name}", {"true" if header_data.specialization_values[index].strip().upper() in ["TRUE", "1"] else "false"} }}'
+                for index, name in enumerate(header_data.specialization_names)
+            )
+            file.write(f"""\
+		static Specialization _spec_pairs[] = {{
+			{specializations},
+		}};
+""")
         else:
-            fd.write("\t\tstatic Specialization *_spec_pairs=nullptr;\n")
-
-        feedback_count = 0
+            file.write("""\
+		static Specialization *_spec_pairs = nullptr;
+""")
 
         if header_data.feedbacks:
-            fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
-            for x in header_data.feedbacks:
-                name = x[0]
-                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')
+            feedbacks = ",\n\t\t\t".join(
+                f'{{ "{name}", {0 if spec not in header_data.specialization_names else (1 << header_data.specialization_names.index(spec))} }}'
+                for name, spec in header_data.feedbacks
+            )
+            file.write(f"""\
+		static const Feedback _feedbacks[] = {{
+			{feedbacks},
+		}};
+""")
+        else:
+            file.write("""\
+		static const Feedback *_feedbacks = nullptr;
+""")
 
-                feedback_count += 1
+        file.write(f"""\
+		static const char _vertex_code[] = {{
+{to_raw_cstring(header_data.vertex_lines)}
+		}};
 
-            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"
-        )
-
-        fd.write("\t}\n\n")
-
-        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):
     env.NoCache(target)
-    for x in source:
-        build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
+    for src in source:
+        build_gles3_header(f"{src}.gen.h", str(src))

+ 42 - 71
glsl_builders.py

@@ -1,9 +1,8 @@
 """Functions used to generate source files during build time"""
 
 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:
@@ -92,61 +91,49 @@ def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth:
     return header_data
 
 
-def build_rd_header(
-    filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RDHeaderStruct] = None
-) -> None:
-    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
+def build_rd_header(filename: str, shader: str) -> None:
+    include_file_in_rd_header(shader, header_data := RDHeaderStruct(), 0)
+    class_name = os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderRD"
 
+    with generated_wrapper(filename) as file:
+        file.write(f"""\
 #include "servers/rendering/renderer_rd/shader_rd.h"
 
-class {out_file_class} : public ShaderRD {{
-
+class {class_name} : public ShaderRD {{
 public:
-
-	{out_file_class}() {{
-
-		{body_content}
+	{class_name}() {{
+""")
+
+        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;
+""")
+
+        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):
     env.NoCache(target)
-    for x in source:
-        build_rd_header(filename=str(x))
+    for src in source:
+        build_rd_header(f"{src}.gen.h", str(src))
 
 
 class RAWHeaderStruct:
@@ -171,34 +158,18 @@ def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, dept
             line = fs.readline()
 
 
-def build_raw_header(
-    filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RAWHeaderStruct] = None
-):
-    header_data = header_data or RAWHeaderStruct()
-    include_file_in_raw_header(filename, header_data, 0)
+def build_raw_header(filename: str, shader: str) -> None:
+    include_file_in_raw_header(shader, header_data := RAWHeaderStruct(), 0)
 
-    if optional_output_filename is None:
-        out_file = filename + ".gen.h"
-    else:
-        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}[] = {{
+    with generated_wrapper(filename) as file:
+        file.write(f"""\
+static const char {os.path.basename(shader).replace(".glsl", "_shader_glsl")}[] = {{
 {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):
     env.NoCache(target)
-    for x in source:
-        build_raw_header(filename=str(x))
+    for src in source:
+        build_raw_header(f"{src}.gen.h", str(src))

+ 8 - 8
methods.py

@@ -1503,15 +1503,15 @@ def generated_wrapper(
     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:
-        file.write(generate_copyright_header(path))
-        file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
-
-        if guard:
-            file.write("#pragma once\n\n")
+        if not path.endswith(".out"):  # For test output, we only care about the content.
+            file.write(generate_copyright_header(path))
+            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:
+                file.write("#pragma once\n\n")
 
         with StringIO(newline="\n") as str_io:
             yield str_io

+ 0 - 26
tests/python_build/conftest.py

@@ -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))
-
-
[email protected]
-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 - 0
tests/python_build/fixtures/gles3/vertex_fragment.out

@@ -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);
+	}
+};

+ 0 - 71
tests/python_build/fixtures/gles3/vertex_fragment_expected_full.glsl

@@ -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);
-	}
-
-};

+ 0 - 53
tests/python_build/fixtures/gles3/vertex_fragment_expected_parts.json

@@ -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"
-  ]
-}

+ 0 - 3
tests/python_build/fixtures/glsl/compute_expected_full.glsl → tests/python_build/fixtures/glsl/compute.out

@@ -1,6 +1,3 @@
-/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
-#pragma once
-
 static const char compute_shader_glsl[] = {
 R"<!>(#[compute]
 

+ 0 - 3
tests/python_build/fixtures/glsl/compute_expected_parts.json

@@ -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"
-}

+ 0 - 3
tests/python_build/fixtures/glsl/vertex_fragment_expected_full.glsl → tests/python_build/fixtures/glsl/vertex_fragment.out

@@ -1,6 +1,3 @@
-/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
-#pragma once
-
 static const char vertex_fragment_shader_glsl[] = {
 R"<!>(#[versions]
 

+ 0 - 3
tests/python_build/fixtures/glsl/vertex_fragment_expected_parts.json

@@ -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"
-}

+ 3 - 7
tests/python_build/fixtures/rd_glsl/compute_expected_full.glsl → tests/python_build/fixtures/rd_glsl/compute.out

@@ -1,14 +1,10 @@
-/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
-#pragma once
-
 #include "servers/rendering/renderer_rd/shader_rd.h"
 
 class ComputeShaderRD : public ShaderRD {
-
 public:
-
 	ComputeShaderRD() {
-
+		static const char *_vertex_code = nullptr;
+		static const char *_fragment_code = nullptr;
 		static const char _compute_code[] = {
 R"<!>(
 #version 450
@@ -24,6 +20,6 @@ void main() {
 }
 )<!>"
 		};
-		setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
+		setup(_vertex_code, _fragment_code, _compute_code, "ComputeShaderRD");
 	}
 };

+ 0 - 28
tests/python_build/fixtures/rd_glsl/compute_expected_parts.json

@@ -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
-}

+ 2 - 7
tests/python_build/fixtures/rd_glsl/vertex_fragment_expected_full.glsl → tests/python_build/fixtures/rd_glsl/vertex_fragment.out

@@ -1,14 +1,8 @@
-/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
-#pragma once
-
 #include "servers/rendering/renderer_rd/shader_rd.h"
 
 class VertexFragmentShaderRD : public ShaderRD {
-
 public:
-
 	VertexFragmentShaderRD() {
-
 		static const char _vertex_code[] = {
 R"<!>(
 #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");
 	}
 };

+ 0 - 40
tests/python_build/fixtures/rd_glsl/vertex_fragment_expected_parts.json

@@ -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
-}

+ 0 - 31
tests/python_build/test_gles3_builder.py

@@ -1,31 +0,0 @@
-import json
-
-import pytest
-
-from gles3_builders import GLES3HeaderStruct, build_gles3_header
-
-
[email protected](
-    ["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

+ 0 - 37
tests/python_build/test_glsl_builder.py

@@ -1,37 +0,0 @@
-import json
-
-import pytest
-
-from glsl_builders import RAWHeaderStruct, RDHeaderStruct, build_raw_header, build_rd_header
-
-
[email protected](
-    [
-        "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 - 0
tests/python_build/validate_builders.py

@@ -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())