upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/shader_library_test.cpp
diff options
context:
space:
mode:
authorTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
committerTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
commitbeffaa9a476ca1b3dfd9cfa55e39eafbb1f5eec6 (patch)
tree32877805bf4eb46d9a89d5753db6b5a2b06dc845 /runtime/test/shader_library_test.cpp
parentf29ca7bacae9507f83e8c56abdb604bd4efb4cf1 (diff)
parenta73a57e1339be072baf5522351c8ec7f1482b56b (diff)
Merge main into fix/null-descriptor-generated-dir
Diffstat (limited to 'runtime/test/shader_library_test.cpp')
-rw-r--r--runtime/test/shader_library_test.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/runtime/test/shader_library_test.cpp b/runtime/test/shader_library_test.cpp
index 2448ab7b8..ee49c48eb 100644
--- a/runtime/test/shader_library_test.cpp
+++ b/runtime/test/shader_library_test.cpp
@@ -820,6 +820,80 @@ int main() {
820 std::filesystem::remove_all(dir); 820 std::filesystem::remove_all(dir);
821 } 821 }
822 822
823 // The descriptor-table layout marker (`descriptor_table` in each module's meta, descriptor_table.h): absent is
824 // the old plain layout. The kind word is additive - a tagged module reads it, a plain one ignores it and reads
825 // the index at the same place - so one tagged module needs the tagged layout however many plain ones a merged or
826 // partial index holds; counting entries would let a plain majority hand every tagged module an all-zero kind, and
827 // every image read through another dimension's array would fall back. LEONIDA_DESCRIPTOR_TABLE overrides in the
828 // device, through descriptor_table_layout_from_env.
829 {
830 const auto root = dir / "table_layouts";
831 const auto write_index = [](const std::filesystem::path& folder, const std::string& modules) {
832 std::filesystem::create_directories(folder);
833 std::ofstream index(folder / "index.json", std::ios::binary);
834 index << "{" << modules << "}";
835 };
836 const auto module = [](const char* name, const char* marker) {
837 std::string out = "{\"stage\": \"vs\", \"fssm_sha256\": \"" + std::string(name) + "\"";
838 if (marker) out += ", \"descriptor_table\": \"" + std::string(marker) + "\"";
839 return out + "}";
840 };
841 const auto census = [](const ShaderLibrary& library, std::size_t tagged, std::size_t plain) {
842 return library.descriptor_table_census().tagged == tagged &&
843 library.descriptor_table_census().plain == plain;
844 };
845
846 // A library translated before the kind word (or with --descriptor-table plain) is plain.
847 write_index(root, "\"a\": " + module("aa", nullptr) + ", \"b\": " + module("bb", nullptr));
848 ShaderLibrary all_plain;
849 CHECK(all_plain.load(root.string(), &error));
850 CHECK(census(all_plain, 0, 2) &&
851 all_plain.descriptor_table_layout() == DescriptorTableLayout::plain);
852
853 write_index(root, "\"a\": " + module("aa", "tagged") + ", \"b\": " + module("bb", "tagged"));
854 ShaderLibrary all_tagged;
855 CHECK(all_tagged.load(root.string(), &error));
856 CHECK(census(all_tagged, 2, 0) &&
857 all_tagged.descriptor_table_layout() == DescriptorTableLayout::tagged);
858
859 // One tagged module among plain ones: the tagged layout (the old vote gave the plain majority's choice and
860 // every image of another dimension fell back).
861 write_index(root, "\"a\": " + module("aa", "tagged") + ", \"b\": " + module("bb", nullptr) + ", \"c\": " +
862 module("cc", "plain") + ", \"d\": " + module("dd", nullptr));
863 ShaderLibrary tagged_minority;
864 CHECK(tagged_minority.load(root.string(), &error));
865 CHECK(census(tagged_minority, 1, 3) &&
866 tagged_minority.descriptor_table_layout() == DescriptorTableLayout::tagged);
867
868 write_index(root, "\"a\": " + module("aa", nullptr) + ", \"b\": " + module("bb", "tagged"));
869 ShaderLibrary tied;
870 CHECK(tied.load(root.string(), &error));
871 CHECK(census(tied, 1, 1) && tied.descriptor_table_layout() == DescriptorTableLayout::tagged);
872
873 // A sub-index's marker counts too, and loading a folder replaces the census rather than adding to it.
874 write_index(root, "\"a\": " + module("aa", nullptr) + ", \"b\": " + module("bb", nullptr));
875 write_index(root / "fspx", "\"upscaler\": " + module("cc", "tagged"));
876 ShaderLibrary sub_index;
877 CHECK(sub_index.load(root.string(), &error));
878 CHECK(census(sub_index, 1, 2) && sub_index.descriptor_table_layout() == DescriptorTableLayout::tagged);
879 CHECK(sub_index.load(root.string(), &error) && census(sub_index, 1, 2)); // reload, not accumulate
880 std::filesystem::remove_all(root / "fspx");
881 CHECK(sub_index.load(root.string(), &error) && census(sub_index, 0, 2) &&
882 sub_index.descriptor_table_layout() == DescriptorTableLayout::plain);
883
884 // LEONIDA_DESCRIPTOR_TABLE: an exact layout name wins over the vote; anything else is ignored, and a refused
885 // value leaves the caller's layout alone.
886 DescriptorTableLayout chosen = DescriptorTableLayout::tagged;
887 CHECK(descriptor_table_layout_from_env("plain", &chosen) && chosen == DescriptorTableLayout::plain);
888 CHECK(descriptor_table_layout_from_env("tagged", &chosen) && chosen == DescriptorTableLayout::tagged);
889 CHECK(!descriptor_table_layout_from_env(nullptr, &chosen));
890 CHECK(!descriptor_table_layout_from_env("", &chosen));
891 CHECK(!descriptor_table_layout_from_env("Plain", &chosen));
892 CHECK(!descriptor_table_layout_from_env("other", &chosen));
893 CHECK(chosen == DescriptorTableLayout::tagged);
894 std::filesystem::remove_all(dir);
895 }
896
823 if (const int line = fspx_checks()) return line; 897 if (const int line = fspx_checks()) return line;
824 898
825 // FSPX entries: found by fspx_code_sha256, in the main index or in <dir>/fspx/index.json (named "fspx/<name>"). 899 // FSPX entries: found by fspx_code_sha256, in the main index or in <dir>/fspx/index.json (named "fspx/<name>").