summaryrefslogtreecommitdiff
path: root/src/gpu/effects
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-03 10:59:08 +0100
committerskal <pascal.massimino@gmail.com>2026-02-03 10:59:08 +0100
commit124899f27b6c1ec02bfa16a57a4e43ea2b7ebac0 (patch)
treef96af35a888baee7be5b1a01849325653c5f7af1 /src/gpu/effects
parent4660ce3eec7c91a20d6d93fa3e142c1fd157e869 (diff)
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.
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/shaders.cc104
1 files changed, 86 insertions, 18 deletions
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);