From 124899f27b6c1ec02bfa16a57a4e43ea2b7ebac0 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 3 Feb 2026 10:59:08 +0100 Subject: test(shader): Add ShaderComposer and WGSL asset validation tests (Task #26) Implemented comprehensive unit tests for ShaderComposer and a validation test for production WGSL shader assets. This ensures the shader asset pipeline is robust and that all shaders contain required entry points and snippets. Also improved InitShaderComposer to be more robust during testing. --- src/gpu/effects/shaders.cc | 104 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 18 deletions(-) (limited to 'src/gpu/effects/shaders.cc') diff --git a/src/gpu/effects/shaders.cc b/src/gpu/effects/shaders.cc index 6b37869..cd516cd 100644 --- a/src/gpu/effects/shaders.cc +++ b/src/gpu/effects/shaders.cc @@ -2,39 +2,107 @@ // It defines WGSL shader code for various effects. #include "../demo_effects.h" + + + +#if defined(USE_TEST_ASSETS) + +#include "test_assets.h" + +#else + #include "generated/assets.h" + +#endif + + + #include "gpu/effects/shader_composer.h" + #include "util/asset_manager.h" + + void InitShaderComposer() { + auto& sc = ShaderComposer::Get(); - sc.RegisterSnippet("common_uniforms", - (const char*)GetAsset(AssetId::ASSET_SHADER_COMMON_UNIFORMS)); - sc.RegisterSnippet("sdf_primitives", - (const char*)GetAsset(AssetId::ASSET_SHADER_SDF_PRIMITIVES)); - sc.RegisterSnippet("lighting", - (const char*)GetAsset(AssetId::ASSET_SHADER_LIGHTING)); - sc.RegisterSnippet("ray_box", - (const char*)GetAsset(AssetId::ASSET_SHADER_RAY_BOX)); + + + auto register_if_exists = [&](const char* name, AssetId id) { + + size_t size; + + const char* data = (const char*)GetAsset(id, &size); + + if (data) { + + sc.RegisterSnippet(name, std::string(data, size)); + + } + + }; + + + + register_if_exists("common_uniforms", AssetId::ASSET_SHADER_COMMON_UNIFORMS); + + register_if_exists("sdf_primitives", AssetId::ASSET_SHADER_SDF_PRIMITIVES); + + register_if_exists("lighting", AssetId::ASSET_SHADER_LIGHTING); + + register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX); + } -const char* main_shader_wgsl = (const char*)GetAsset(AssetId::ASSET_SHADER_MAIN); + + +// Helper to get asset string or empty string + +static const char* SafeGetAsset(AssetId id) { + + const uint8_t* data = GetAsset(id); + + return data ? (const char*)data : ""; + +} + + + +const char* main_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_MAIN); + const char* particle_compute_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE); + + SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE); + const char* particle_render_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER); + + SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER); + const char* passthrough_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_PASSTHROUGH); + + SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH); + const char* ellipse_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_ELLIPSE); + + SafeGetAsset(AssetId::ASSET_SHADER_ELLIPSE); + const char* particle_spray_compute_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_SPRAY_COMPUTE); + + SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_SPRAY_COMPUTE); + const char* gaussian_blur_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR); + + SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR); + const char* solarize_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_SOLARIZE); + + SafeGetAsset(AssetId::ASSET_SHADER_SOLARIZE); + const char* distort_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_DISTORT); + + SafeGetAsset(AssetId::ASSET_SHADER_DISTORT); + const char* chroma_aberration_shader_wgsl = - (const char*)GetAsset(AssetId::ASSET_SHADER_CHROMA_ABERRATION); \ No newline at end of file + + SafeGetAsset(AssetId::ASSET_SHADER_CHROMA_ABERRATION); -- cgit v1.2.3