Extract renderer shader catalog

This commit is contained in:
2026-06-01 17:36:25 +02:00
parent ad255a6ddf
commit d61c7f37c3
7 changed files with 204 additions and 55 deletions

View File

@@ -1,6 +1,8 @@
#include "renderer_api/renderer_api.h"
#include "renderer_api/shader_catalog.h"
#include "test_harness.h"
#include <array>
#include <string_view>
using pp::foundation::StatusCode;
@@ -22,12 +24,15 @@ using pp::renderer::TextureFormat;
using pp::renderer::Viewport;
using pp::renderer::max_shader_source_bytes;
using pp::renderer::max_texture_dimension;
using pp::renderer::panopainter_shader_catalog;
using pp::renderer::primitive_topology_name;
using pp::renderer::ShaderCatalogEntry;
using pp::renderer::texture_byte_size;
using pp::renderer::texture_format_name;
using pp::renderer::validate_extent;
using pp::renderer::validate_mesh_desc;
using pp::renderer::validate_readback_region;
using pp::renderer::validate_shader_catalog;
using pp::renderer::validate_shader_program_desc;
using pp::renderer::validate_viewport;
@@ -274,6 +279,65 @@ void validates_shader_program_descriptors(pp::tests::Harness& h)
PP_EXPECT(h, excessive_source_status.code == StatusCode::out_of_range);
}
void validates_panopainter_shader_catalog(pp::tests::Harness& h)
{
const auto catalog = panopainter_shader_catalog();
PP_EXPECT(h, catalog.size() == 25U);
PP_EXPECT(h, validate_shader_catalog(catalog).ok());
PP_EXPECT(h, catalog.front().name == std::string_view("texture"));
PP_EXPECT(h, catalog.front().path == std::string_view("data/shaders/texture.glsl"));
PP_EXPECT(h, catalog.back().name == std::string_view("bakeuv"));
PP_EXPECT(h, catalog.back().path == std::string_view("data/shaders/bake-uv.glsl"));
bool found_stroke = false;
bool found_brush_stroke = false;
bool found_equirect = false;
for (const auto& entry : catalog) {
found_stroke = found_stroke || std::string_view(entry.name) == "stroke";
found_brush_stroke = found_brush_stroke || std::string_view(entry.name) == "brush-stroke";
found_equirect = found_equirect || std::string_view(entry.name) == "equirect";
}
PP_EXPECT(h, found_stroke);
PP_EXPECT(h, found_brush_stroke);
PP_EXPECT(h, found_equirect);
}
void rejects_invalid_shader_catalogs(pp::tests::Harness& h)
{
const std::array<ShaderCatalogEntry, 2> duplicated {
ShaderCatalogEntry { .name = "texture", .path = "data/shaders/texture.glsl" },
ShaderCatalogEntry { .name = "texture", .path = "data/shaders/texture-alpha.glsl" },
};
const std::array<ShaderCatalogEntry, 1> missing_name {
ShaderCatalogEntry { .name = "", .path = "data/shaders/texture.glsl" },
};
const std::array<ShaderCatalogEntry, 1> missing_path {
ShaderCatalogEntry { .name = "texture", .path = "" },
};
const std::array<ShaderCatalogEntry, 1> wrong_extension {
ShaderCatalogEntry { .name = "texture", .path = "data/shaders/texture.txt" },
};
const auto empty = validate_shader_catalog({});
const auto duplicate = validate_shader_catalog(duplicated);
const auto no_name = validate_shader_catalog(missing_name);
const auto no_path = validate_shader_catalog(missing_path);
const auto bad_extension = validate_shader_catalog(wrong_extension);
PP_EXPECT(h, !empty.ok());
PP_EXPECT(h, empty.code == StatusCode::invalid_argument);
PP_EXPECT(h, !duplicate.ok());
PP_EXPECT(h, duplicate.code == StatusCode::invalid_argument);
PP_EXPECT(h, !no_name.ok());
PP_EXPECT(h, no_name.code == StatusCode::invalid_argument);
PP_EXPECT(h, !no_path.ok());
PP_EXPECT(h, no_path.code == StatusCode::invalid_argument);
PP_EXPECT(h, !bad_extension.ok());
PP_EXPECT(h, bad_extension.code == StatusCode::invalid_argument);
}
void renderer_interfaces_support_backend_neutral_dispatch(pp::tests::Harness& h)
{
FakeRenderDevice device;
@@ -310,6 +374,8 @@ int main()
harness.run("validates_readback_bounds", validates_readback_bounds);
harness.run("validates_viewports_and_mesh_descriptors", validates_viewports_and_mesh_descriptors);
harness.run("validates_shader_program_descriptors", validates_shader_program_descriptors);
harness.run("validates_panopainter_shader_catalog", validates_panopainter_shader_catalog);
harness.run("rejects_invalid_shader_catalogs", rejects_invalid_shader_catalogs);
harness.run("renderer_interfaces_support_backend_neutral_dispatch", renderer_interfaces_support_backend_neutral_dispatch);
return harness.finish();
}