summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/3d/test_3d_render.cc6
-rw-r--r--src/tests/audio/test_fft.cc16
-rw-r--r--src/tests/gpu/test_cnn_v3_parity.cc194
-rw-r--r--src/tests/gpu/test_demo_effects.cc15
-rw-r--r--src/tests/gpu/test_effect_base.cc33
-rw-r--r--src/tests/gpu/test_shader_composer.cc3
-rw-r--r--src/tests/util/test_ans.cc24
-rw-r--r--src/tests/util/test_procedural.cc10
8 files changed, 163 insertions, 138 deletions
diff --git a/src/tests/3d/test_3d_render.cc b/src/tests/3d/test_3d_render.cc
index ef799ec..3a440be 100644
--- a/src/tests/3d/test_3d_render.cc
+++ b/src/tests/3d/test_3d_render.cc
@@ -105,7 +105,8 @@ bool gen_periodic_noise(uint8_t* buffer, int w, int h, const float* params,
// Wrapper: fBm noise → normal map
bool gen_fbm_normalmap(uint8_t* buffer, int w, int h, const float* params,
int num_params) {
- (void)params; (void)num_params;
+ (void)params;
+ (void)num_params;
float fbm_params[] = {0.0f, 4.0f, 1.0f, 0.5f, 5.0f};
if (!procedural::gen_perlin(buffer, w, h, fbm_params, 5))
return false;
@@ -140,7 +141,8 @@ int main(int argc, char** argv) {
InitShaderComposer();
- g_renderer.set_direct_render(true); // Renders to surface, no post-process flip
+ g_renderer.set_direct_render(
+ true); // Renders to surface, no post-process flip
g_renderer.init(g_device, g_queue, g_format);
g_renderer.resize(platform_state.width, platform_state.height);
diff --git a/src/tests/audio/test_fft.cc b/src/tests/audio/test_fft.cc
index 2d47aa0..a34d203 100644
--- a/src/tests/audio/test_fft.cc
+++ b/src/tests/audio/test_fft.cc
@@ -39,7 +39,7 @@ static void idct_reference(const float* input, float* output, size_t N) {
// Reference direct DFT matching fft_forward convention (e^{+j} sign).
// fft_radix2 with direction=+1 computes X[k] = sum x[n] * e^{+j*2*pi*k*n/N}.
static void dft_reference(const float* real_in, const float* imag_in,
- float* real_out, float* imag_out, size_t N) {
+ float* real_out, float* imag_out, size_t N) {
const float PI = 3.14159265358979323846f;
for (size_t k = 0; k < N; k++) {
real_out[k] = 0.0f;
@@ -68,7 +68,8 @@ static bool arrays_match(const float* a, const float* b, size_t N,
// Test B: fft_forward small N=4 — all 4 unit impulses vs direct DFT
static void test_b_fft_radix2_small_n() {
- printf("Test B: fft_forward N=4 (unit impulses vs direct DFT, tol=1e-5)...\n");
+ printf(
+ "Test B: fft_forward N=4 (unit impulses vs direct DFT, tol=1e-5)...\n");
const size_t N = 4;
const float tolerance = 1e-5f;
@@ -117,8 +118,7 @@ static void test_c_twiddle_accumulation() {
if (k >= 128 && k < 256) {
const float wr_direct = cosf(angle * (float)k);
const float wi_direct = sinf(angle * (float)k);
- const float err =
- fabsf(wr_iter - wr_direct) + fabsf(wi_iter - wi_direct);
+ const float err = fabsf(wr_iter - wr_direct) + fabsf(wi_iter - wi_direct);
if (err > max_err) {
max_err = err;
max_err_k = k;
@@ -129,9 +129,8 @@ static void test_c_twiddle_accumulation() {
wi_iter = wr_old * wi_delta + wi_iter * wr_delta;
}
- printf(
- " ✓ iterative twiddle drift at k=128..255: max_err=%.2e at k=%zu\n",
- (double)max_err, max_err_k);
+ printf(" ✓ iterative twiddle drift at k=128..255: max_err=%.2e at k=%zu\n",
+ (double)max_err, max_err_k);
printf(" ✓ fixed code uses cosf/sinf directly — no accumulation\n");
printf("Test C: PASSED ✓\n\n");
}
@@ -279,7 +278,8 @@ static void test_idct_correctness() {
assert(arrays_match(output_ref, output_fft, N));
printf(" ✓ Single bin test passed\n");
- // Mixed spectrum: IDCT→DCT round-trip (dct_fft and idct_fft are mutual inverses)
+ // Mixed spectrum: IDCT→DCT round-trip (dct_fft and idct_fft are mutual
+ // inverses)
for (size_t i = 0; i < N; i++) {
input[i] = sinf(i * 0.1f) * cosf(i * 0.05f) + cosf(i * 0.03f);
}
diff --git a/src/tests/gpu/test_cnn_v3_parity.cc b/src/tests/gpu/test_cnn_v3_parity.cc
index 4fada5d..9663b09 100644
--- a/src/tests/gpu/test_cnn_v3_parity.cc
+++ b/src/tests/gpu/test_cnn_v3_parity.cc
@@ -4,10 +4,10 @@
// 2. Random-weight test: output must match Python-generated test vectors
// (within 1/255 per pixel)
+#include "../../cnn_v3/test_vectors.h"
#include "../common/webgpu_test_fixture.h"
#include "cnn_v3/src/cnn_v3_effect.h"
#include "gpu/sequence.h"
-#include "../../cnn_v3/test_vectors.h"
#include <cassert>
#include <cmath>
@@ -20,37 +20,46 @@
static float fp16_bits_to_f32(uint16_t h) {
uint32_t sign = (h & 0x8000u) << 16;
- uint32_t exp = (h & 0x7C00u) >> 10;
+ uint32_t exp = (h & 0x7C00u) >> 10;
uint32_t mant = (h & 0x03FFu);
if (exp == 0 && mant == 0) {
- float r; uint32_t b = sign; __builtin_memcpy(&r, &b, 4); return r;
+ float r;
+ uint32_t b = sign;
+ __builtin_memcpy(&r, &b, 4);
+ return r;
}
if (exp == 31) {
uint32_t b = sign | 0x7F800000u | (mant << 13);
- float r; __builtin_memcpy(&r, &b, 4); return r;
+ float r;
+ __builtin_memcpy(&r, &b, 4);
+ return r;
}
uint32_t b = sign | ((exp + 112) << 23) | (mant << 13);
- float r; __builtin_memcpy(&r, &b, 4); return r;
+ float r;
+ __builtin_memcpy(&r, &b, 4);
+ return r;
}
// ---------------------------------------------------------------------------
// Raw RGBA16Float readback → flat array of f32 (one per channel per pixel)
// ---------------------------------------------------------------------------
-struct MapState { bool done = false; WGPUMapAsyncStatus status; };
+struct MapState {
+ bool done = false;
+ WGPUMapAsyncStatus status;
+};
static std::vector<float> readback_rgba16float(WGPUDevice device,
- WGPUQueue queue,
- WGPUTexture tex,
- int W, int H) {
- const uint32_t bytes_per_px = 8; // 4 × f16
- const uint32_t unaligned_bpr = (uint32_t)(W * bytes_per_px);
- const uint32_t aligned_bpr = ((unaligned_bpr + 255u) / 256u) * 256u;
- const size_t buf_size = aligned_bpr * (size_t)H;
+ WGPUQueue queue, WGPUTexture tex,
+ int W, int H) {
+ const uint32_t bytes_per_px = 8; // 4 × f16
+ const uint32_t unaligned_bpr = (uint32_t)(W * bytes_per_px);
+ const uint32_t aligned_bpr = ((unaligned_bpr + 255u) / 256u) * 256u;
+ const size_t buf_size = aligned_bpr * (size_t)H;
WGPUBufferDescriptor bd = {};
bd.usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_MapRead;
- bd.size = buf_size;
+ bd.size = buf_size;
WGPUBuffer staging = wgpuDeviceCreateBuffer(device, &bd);
WGPUCommandEncoder enc = wgpuDeviceCreateCommandEncoder(device, nullptr);
@@ -58,9 +67,9 @@ static std::vector<float> readback_rgba16float(WGPUDevice device,
src.texture = tex;
WGPUTexelCopyBufferInfo dst = {};
dst.buffer = staging;
- dst.layout.bytesPerRow = aligned_bpr;
+ dst.layout.bytesPerRow = aligned_bpr;
dst.layout.rowsPerImage = (uint32_t)H;
- WGPUExtent3D extent = { (uint32_t)W, (uint32_t)H, 1 };
+ WGPUExtent3D extent = {(uint32_t)W, (uint32_t)H, 1};
wgpuCommandEncoderCopyTextureToBuffer(enc, &src, &dst, &extent);
WGPUCommandBuffer cmds = wgpuCommandEncoderFinish(enc, nullptr);
wgpuQueueSubmit(queue, 1, &cmds);
@@ -73,7 +82,8 @@ static std::vector<float> readback_rgba16float(WGPUDevice device,
mi.mode = WGPUCallbackMode_AllowProcessEvents;
mi.callback = [](WGPUMapAsyncStatus s, WGPUStringView, void* u, void*) {
auto* st = (MapState*)u;
- st->status = s; st->done = true;
+ st->status = s;
+ st->done = true;
};
mi.userdata1 = &ms;
wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buf_size, mi);
@@ -82,16 +92,15 @@ static std::vector<float> readback_rgba16float(WGPUDevice device,
std::vector<float> result(W * H * 4, 0.0f);
if (ms.done && ms.status == WGPUMapAsyncStatus_Success) {
- const uint8_t* mapped = (const uint8_t*)wgpuBufferGetConstMappedRange(
- staging, 0, buf_size);
+ const uint8_t* mapped =
+ (const uint8_t*)wgpuBufferGetConstMappedRange(staging, 0, buf_size);
if (mapped) {
for (int y = 0; y < H; ++y) {
const uint16_t* row =
(const uint16_t*)(mapped + (size_t)y * aligned_bpr);
for (int x = 0; x < W; ++x) {
for (int c = 0; c < 4; ++c) {
- result[(y * W + x) * 4 + c] =
- fp16_bits_to_f32(row[x * 4 + c]);
+ result[(y * W + x) * 4 + c] = fp16_bits_to_f32(row[x * 4 + c]);
}
}
}
@@ -107,17 +116,17 @@ static std::vector<float> readback_rgba16float(WGPUDevice device,
// ---------------------------------------------------------------------------
static std::vector<float> readback_rgba32uint_8ch(WGPUDevice device,
- WGPUQueue queue,
- WGPUTexture tex,
- int W, int H) {
- const uint32_t bytes_per_px = 16; // 4 × u32
- const uint32_t unaligned_bpr = (uint32_t)(W * bytes_per_px);
- const uint32_t aligned_bpr = ((unaligned_bpr + 255u) / 256u) * 256u;
- const size_t buf_size = aligned_bpr * (size_t)H;
+ WGPUQueue queue,
+ WGPUTexture tex, int W,
+ int H) {
+ const uint32_t bytes_per_px = 16; // 4 × u32
+ const uint32_t unaligned_bpr = (uint32_t)(W * bytes_per_px);
+ const uint32_t aligned_bpr = ((unaligned_bpr + 255u) / 256u) * 256u;
+ const size_t buf_size = aligned_bpr * (size_t)H;
WGPUBufferDescriptor bd = {};
bd.usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_MapRead;
- bd.size = buf_size;
+ bd.size = buf_size;
WGPUBuffer staging = wgpuDeviceCreateBuffer(device, &bd);
WGPUCommandEncoder enc = wgpuDeviceCreateCommandEncoder(device, nullptr);
@@ -125,9 +134,9 @@ static std::vector<float> readback_rgba32uint_8ch(WGPUDevice device,
src.texture = tex;
WGPUTexelCopyBufferInfo dst = {};
dst.buffer = staging;
- dst.layout.bytesPerRow = aligned_bpr;
+ dst.layout.bytesPerRow = aligned_bpr;
dst.layout.rowsPerImage = (uint32_t)H;
- WGPUExtent3D extent = { (uint32_t)W, (uint32_t)H, 1 };
+ WGPUExtent3D extent = {(uint32_t)W, (uint32_t)H, 1};
wgpuCommandEncoderCopyTextureToBuffer(enc, &src, &dst, &extent);
WGPUCommandBuffer cmds = wgpuCommandEncoderFinish(enc, nullptr);
wgpuQueueSubmit(queue, 1, &cmds);
@@ -140,7 +149,8 @@ static std::vector<float> readback_rgba32uint_8ch(WGPUDevice device,
mi.mode = WGPUCallbackMode_AllowProcessEvents;
mi.callback = [](WGPUMapAsyncStatus s, WGPUStringView, void* u, void*) {
auto* st = (MapState*)u;
- st->status = s; st->done = true;
+ st->status = s;
+ st->done = true;
};
mi.userdata1 = &ms;
wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buf_size, mi);
@@ -149,8 +159,8 @@ static std::vector<float> readback_rgba32uint_8ch(WGPUDevice device,
std::vector<float> result(W * H * 8, 0.0f);
if (ms.done && ms.status == WGPUMapAsyncStatus_Success) {
- const uint8_t* mapped = (const uint8_t*)wgpuBufferGetConstMappedRange(
- staging, 0, buf_size);
+ const uint8_t* mapped =
+ (const uint8_t*)wgpuBufferGetConstMappedRange(staging, 0, buf_size);
if (mapped) {
for (int y = 0; y < H; ++y) {
const uint32_t* row =
@@ -178,31 +188,31 @@ static std::vector<float> readback_rgba32uint_8ch(WGPUDevice device,
static WGPUTexture make_feat_tex(WGPUDevice dev, int W, int H) {
WGPUTextureDescriptor d = {};
- d.format = WGPUTextureFormat_RGBA32Uint;
- d.usage = WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst;
- d.dimension = WGPUTextureDimension_2D;
- d.size = { (uint32_t)W, (uint32_t)H, 1 };
+ d.format = WGPUTextureFormat_RGBA32Uint;
+ d.usage = WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst;
+ d.dimension = WGPUTextureDimension_2D;
+ d.size = {(uint32_t)W, (uint32_t)H, 1};
d.mipLevelCount = 1;
- d.sampleCount = 1;
+ d.sampleCount = 1;
return wgpuDeviceCreateTexture(dev, &d);
}
static WGPUTexture make_output_tex(WGPUDevice dev, int W, int H) {
WGPUTextureDescriptor d = {};
- d.format = WGPUTextureFormat_RGBA16Float;
- d.usage = WGPUTextureUsage_StorageBinding | WGPUTextureUsage_CopySrc;
- d.dimension = WGPUTextureDimension_2D;
- d.size = { (uint32_t)W, (uint32_t)H, 1 };
+ d.format = WGPUTextureFormat_RGBA16Float;
+ d.usage = WGPUTextureUsage_StorageBinding | WGPUTextureUsage_CopySrc;
+ d.dimension = WGPUTextureDimension_2D;
+ d.size = {(uint32_t)W, (uint32_t)H, 1};
d.mipLevelCount = 1;
- d.sampleCount = 1;
+ d.sampleCount = 1;
return wgpuDeviceCreateTexture(dev, &d);
}
static WGPUTextureView make_view(WGPUTexture tex, WGPUTextureFormat fmt) {
WGPUTextureViewDescriptor d = {};
- d.format = fmt;
- d.dimension = WGPUTextureViewDimension_2D;
- d.mipLevelCount = 1;
+ d.format = fmt;
+ d.dimension = WGPUTextureViewDimension_2D;
+ d.mipLevelCount = 1;
d.arrayLayerCount = 1;
return wgpuTextureCreateView(tex, &d);
}
@@ -211,38 +221,36 @@ static WGPUTextureView make_view(WGPUTexture tex, WGPUTextureFormat fmt) {
// Run one CNN v3 forward pass and return output pixels
// ---------------------------------------------------------------------------
-static std::vector<float> run_cnn_v3(WebGPUTestFixture& fixture,
- int W, int H,
- const uint32_t* feat0_u32, // W*H*4
- const uint32_t* feat1_u32, // W*H*4
- const uint32_t* weights_u32, // (TOTAL_F16+1)/2
- uint32_t weights_bytes,
- std::vector<float>* enc0_out = nullptr,
- std::vector<float>* dec1_out = nullptr) {
+static std::vector<float>
+run_cnn_v3(WebGPUTestFixture& fixture, int W, int H,
+ const uint32_t* feat0_u32, // W*H*4
+ const uint32_t* feat1_u32, // W*H*4
+ const uint32_t* weights_u32, // (TOTAL_F16+1)/2
+ uint32_t weights_bytes, std::vector<float>* enc0_out = nullptr,
+ std::vector<float>* dec1_out = nullptr) {
GpuContext ctx = fixture.ctx();
// Create input textures manually (with CopyDst for upload)
WGPUTexture feat0_tex = make_feat_tex(ctx.device, W, H);
WGPUTexture feat1_tex = make_feat_tex(ctx.device, W, H);
- WGPUTexture out_tex = make_output_tex(ctx.device, W, H);
+ WGPUTexture out_tex = make_output_tex(ctx.device, W, H);
WGPUTextureView feat0_view =
make_view(feat0_tex, WGPUTextureFormat_RGBA32Uint);
WGPUTextureView feat1_view =
make_view(feat1_tex, WGPUTextureFormat_RGBA32Uint);
- WGPUTextureView out_view =
- make_view(out_tex, WGPUTextureFormat_RGBA16Float);
+ WGPUTextureView out_view = make_view(out_tex, WGPUTextureFormat_RGBA16Float);
// Upload feat texture data
auto upload_tex = [&](WGPUTexture tex, const uint32_t* data) {
WGPUTexelCopyTextureInfo dst_tex = {};
dst_tex.texture = tex;
WGPUTexelCopyBufferLayout layout = {};
- layout.bytesPerRow = (uint32_t)(W * 16); // 4 u32 per pixel
+ layout.bytesPerRow = (uint32_t)(W * 16); // 4 u32 per pixel
layout.rowsPerImage = (uint32_t)H;
- WGPUExtent3D ext = { (uint32_t)W, (uint32_t)H, 1 };
- wgpuQueueWriteTexture(ctx.queue, &dst_tex, data,
- (size_t)(W * H * 16), &layout, &ext);
+ WGPUExtent3D ext = {(uint32_t)W, (uint32_t)H, 1};
+ wgpuQueueWriteTexture(ctx.queue, &dst_tex, data, (size_t)(W * H * 16),
+ &layout, &ext);
};
upload_tex(feat0_tex, feat0_u32);
upload_tex(feat1_tex, feat1_u32);
@@ -267,10 +275,9 @@ static std::vector<float> run_cnn_v3(WebGPUTestFixture& fixture,
}
// Run 5 compute passes
- WGPUCommandEncoder enc =
- wgpuDeviceCreateCommandEncoder(ctx.device, nullptr);
+ WGPUCommandEncoder enc = wgpuDeviceCreateCommandEncoder(ctx.device, nullptr);
UniformsSequenceParams params = {};
- params.resolution = { (float)W, (float)H };
+ params.resolution = {(float)W, (float)H};
params.aspect_ratio = 1.0f;
effect.render(enc, params, registry);
@@ -292,7 +299,8 @@ static std::vector<float> run_cnn_v3(WebGPUTestFixture& fixture,
if (dec1_out) {
// dec1 is rgba32uint, 8ch (pack2x16float), half-res
WGPUTexture dec1_tex = registry.get_texture("cnn3_out_dec1");
- *dec1_out = readback_rgba32uint_8ch(ctx.device, ctx.queue, dec1_tex, W / 2, H / 2);
+ *dec1_out =
+ readback_rgba32uint_8ch(ctx.device, ctx.queue, dec1_tex, W / 2, H / 2);
}
// Cleanup
@@ -326,9 +334,8 @@ static int test_zero_weights() {
std::vector<uint32_t> feat0(W * H * 4, 0u);
std::vector<uint32_t> feat1(W * H * 4, 0u);
- auto pixels = run_cnn_v3(fixture, W, H,
- feat0.data(), feat1.data(),
- nullptr, 0); // null = zero weights (default)
+ auto pixels = run_cnn_v3(fixture, W, H, feat0.data(), feat1.data(), nullptr,
+ 0); // null = zero weights (default)
// Expected: sigmoid(0) = 0.5 exactly
const float expected = 0.5f;
@@ -360,14 +367,12 @@ static int test_random_weights() {
InitShaderComposer();
const int W = kCnnV3TestW, H = kCnnV3TestH;
- const uint32_t weights_bytes =
- (uint32_t)sizeof(kCnnV3TestWeightsU32);
+ const uint32_t weights_bytes = (uint32_t)sizeof(kCnnV3TestWeightsU32);
std::vector<float> enc0_pixels, dec1_pixels;
- auto pixels = run_cnn_v3(fixture, W, H,
- kCnnV3TestFeat0U32, kCnnV3TestFeat1U32,
- kCnnV3TestWeightsU32, weights_bytes,
- &enc0_pixels, &dec1_pixels);
+ auto pixels = run_cnn_v3(fixture, W, H, kCnnV3TestFeat0U32,
+ kCnnV3TestFeat1U32, kCnnV3TestWeightsU32,
+ weights_bytes, &enc0_pixels, &dec1_pixels);
// Check enc0 layer first (8ch, rgba32uint)
const float tol = 1.0f / 255.0f;
@@ -376,15 +381,18 @@ static int test_random_weights() {
for (int i = 0; i < W * H * 8; ++i) {
float ref = fp16_bits_to_f32(kCnnV3ExpectedEnc0U16[i]);
float err = fabsf(enc0_pixels[i] - ref);
- if (err > enc0_max_err) { enc0_max_err = err; enc0_worst = i; }
+ if (err > enc0_max_err) {
+ enc0_max_err = err;
+ enc0_worst = i;
+ }
}
bool enc0_ok = (enc0_max_err <= tol);
if (!enc0_ok) {
int px = enc0_worst / 8, ch = enc0_worst % 8;
- fprintf(stderr, " ✗ enc0 mismatch: max_err=%.5f > %.5f at px=%d ch=%d"
+ fprintf(stderr,
+ " ✗ enc0 mismatch: max_err=%.5f > %.5f at px=%d ch=%d"
" gpu=%.5f ref=%.5f\n",
- enc0_max_err, tol, px, ch,
- enc0_pixels[enc0_worst],
+ enc0_max_err, tol, px, ch, enc0_pixels[enc0_worst],
fp16_bits_to_f32(kCnnV3ExpectedEnc0U16[enc0_worst]));
} else {
fprintf(stdout, " ✓ enc0: max_err=%.2e OK\n", enc0_max_err);
@@ -397,15 +405,18 @@ static int test_random_weights() {
for (int i = 0; i < dec1_n; ++i) {
float ref = fp16_bits_to_f32(kCnnV3ExpectedDec1U16[i]);
float err = fabsf(dec1_pixels[i] - ref);
- if (err > dec1_max_err) { dec1_max_err = err; dec1_worst = i; }
+ if (err > dec1_max_err) {
+ dec1_max_err = err;
+ dec1_worst = i;
+ }
}
bool dec1_ok = (dec1_max_err <= tol);
if (!dec1_ok) {
int px = dec1_worst / 8, ch = dec1_worst % 8;
- fprintf(stderr, " ✗ dec1 mismatch: max_err=%.5f > %.5f at px=%d ch=%d"
+ fprintf(stderr,
+ " ✗ dec1 mismatch: max_err=%.5f > %.5f at px=%d ch=%d"
" gpu=%.5f ref=%.5f\n",
- dec1_max_err, tol, px, ch,
- dec1_pixels[dec1_worst],
+ dec1_max_err, tol, px, ch, dec1_pixels[dec1_worst],
fp16_bits_to_f32(kCnnV3ExpectedDec1U16[dec1_worst]));
} else {
fprintf(stdout, " ✓ dec1: max_err=%.2e OK\n", dec1_max_err);
@@ -418,16 +429,19 @@ static int test_random_weights() {
for (int i = 0; i < n; ++i) {
float ref = fp16_bits_to_f32(kCnnV3ExpectedOutputU16[i]);
float err = fabsf(pixels[i] - ref);
- if (err > max_err) { max_err = err; worst = i; }
+ if (err > max_err) {
+ max_err = err;
+ worst = i;
+ }
}
bool out_ok = (max_err <= tol);
if (!out_ok) {
int px = worst / 4, ch = worst % 4;
- fprintf(stderr, " ✗ random_weights: max_err=%.5f > %.5f at px=%d ch=%d"
+ fprintf(stderr,
+ " ✗ random_weights: max_err=%.5f > %.5f at px=%d ch=%d"
" gpu=%.5f ref=%.5f\n",
- max_err, tol, px, ch,
- pixels[worst],
+ max_err, tol, px, ch, pixels[worst],
fp16_bits_to_f32(kCnnV3ExpectedOutputU16[worst]));
} else {
fprintf(stdout, " ✓ random_weights: max_err=%.2e OK\n", max_err);
@@ -442,8 +456,10 @@ static int test_random_weights() {
int main() {
int pass = 0, total = 0;
- ++total; pass += test_zero_weights();
- ++total; pass += test_random_weights();
+ ++total;
+ pass += test_zero_weights();
+ ++total;
+ pass += test_random_weights();
fprintf(stdout, "\nCNN v3 parity: %d/%d passed\n", pass, total);
return (pass == total) ? 0 : 1;
diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc
index 1bb89f9..fa1ac87 100644
--- a/src/tests/gpu/test_demo_effects.cc
+++ b/src/tests/gpu/test_demo_effects.cc
@@ -73,9 +73,9 @@ static void test_effects() {
{"Scratch", std::make_shared<Scratch>(
fixture.ctx(), std::vector<std::string>{"source"},
std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
- {"Ntsc", std::make_shared<Ntsc>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Ntsc",
+ std::make_shared<Ntsc>(fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
{"NtscYiq", std::make_shared<NtscYiq>(
fixture.ctx(), std::vector<std::string>{"source"},
std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
@@ -86,18 +86,15 @@ static void test_effects() {
1000.0f)},
{"CNNv3Effect",
std::make_shared<CNNv3Effect>(
- fixture.ctx(),
- std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
+ fixture.ctx(), std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
std::vector<std::string>{"cnn_v3_output"}, 0.0f, 1000.0f)},
{"GBufViewEffect",
std::make_shared<GBufViewEffect>(
- fixture.ctx(),
- std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
+ fixture.ctx(), std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
std::vector<std::string>{"gbuf_view_out"}, 0.0f, 1000.0f)},
{"GBufDeferredEffect",
std::make_shared<GBufDeferredEffect>(
- fixture.ctx(),
- std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
+ fixture.ctx(), std::vector<std::string>{"gbuf_feat0", "gbuf_feat1"},
std::vector<std::string>{"gbuf_deferred_out"}, 0.0f, 1000.0f)},
};
diff --git a/src/tests/gpu/test_effect_base.cc b/src/tests/gpu/test_effect_base.cc
index ad7bca3..57d0504 100644
--- a/src/tests/gpu/test_effect_base.cc
+++ b/src/tests/gpu/test_effect_base.cc
@@ -214,12 +214,15 @@ class WireDagTestEffect : public Effect {
public:
WireDagTestEffect(const GpuContext& ctx, std::vector<std::string> ins,
std::vector<std::string> outs)
- : Effect(ctx, std::move(ins), std::move(outs), 0.0f, 1000.0f) {}
+ : Effect(ctx, std::move(ins), std::move(outs), 0.0f, 1000.0f) {
+ }
void render(WGPUCommandEncoder, const UniformsSequenceParams&,
- NodeRegistry&) override {}
+ NodeRegistry&) override {
+ }
- std::string call_find_downstream(const std::vector<EffectDAGNode>& dag) const {
+ std::string
+ call_find_downstream(const std::vector<EffectDAGNode>& dag) const {
return find_downstream_output(dag);
}
@@ -239,12 +242,12 @@ static void test_find_downstream_output() {
return;
}
- auto a = std::make_shared<WireDagTestEffect>(
- fixture.ctx(), std::vector<std::string>{"src"},
- std::vector<std::string>{"mid"});
- auto b = std::make_shared<WireDagTestEffect>(
- fixture.ctx(), std::vector<std::string>{"mid"},
- std::vector<std::string>{"out"});
+ auto a = std::make_shared<WireDagTestEffect>(fixture.ctx(),
+ std::vector<std::string>{"src"},
+ std::vector<std::string>{"mid"});
+ auto b = std::make_shared<WireDagTestEffect>(fixture.ctx(),
+ std::vector<std::string>{"mid"},
+ std::vector<std::string>{"out"});
auto c = std::make_shared<WireDagTestEffect>(
fixture.ctx(), std::vector<std::string>{"out"},
std::vector<std::string>{"final"});
@@ -304,7 +307,8 @@ static void test_find_downstream_output() {
a->wire_dag(dag_to_sink);
assert(a->wired_to == "sink" &&
"base helper returns sink — caller must guard");
- fprintf(stdout, " ✓ sink downstream: find returns 'sink', caller must guard\n");
+ fprintf(stdout,
+ " ✓ sink downstream: find returns 'sink', caller must guard\n");
}
// Test 8: wire_dag called automatically by init_effect_nodes
@@ -326,13 +330,12 @@ static void test_wire_dag_called_by_sequence() {
class TestSequence : public Sequence {
public:
- TestSequence(const GpuContext& ctx,
- std::shared_ptr<Effect> up,
+ TestSequence(const GpuContext& ctx, std::shared_ptr<Effect> up,
std::shared_ptr<Effect> down)
: Sequence(ctx, 256, 256) {
- effect_dag_.push_back({up, {"source"}, {"mid"}, 0});
- effect_dag_.push_back({down, {"mid"}, {"sink"}, 1});
- init_effect_nodes(); // triggers wire_dag on both effects
+ effect_dag_.push_back({up, {"source"}, {"mid"}, 0});
+ effect_dag_.push_back({down, {"mid"}, {"sink"}, 1});
+ init_effect_nodes(); // triggers wire_dag on both effects
}
};
diff --git a/src/tests/gpu/test_shader_composer.cc b/src/tests/gpu/test_shader_composer.cc
index 2f87e57..8d1f7c7 100644
--- a/src/tests/gpu/test_shader_composer.cc
+++ b/src/tests/gpu/test_shader_composer.cc
@@ -52,8 +52,7 @@ void test_asset_composition() {
assert(snippet_a_code != nullptr);
sc.RegisterSnippet("TEST_WGSL", std::string(snippet_a_code, snippet_a_size));
- std::string main_code =
- "fn main() -> f32 { return test_wgsl(); }";
+ std::string main_code = "fn main() -> f32 { return test_wgsl(); }";
std::string result = sc.Compose({"TEST_WGSL"}, main_code);
assert(result.find("fn snippet_a()") != std::string::npos);
diff --git a/src/tests/util/test_ans.cc b/src/tests/util/test_ans.cc
index 108c46d..d8cc85c 100644
--- a/src/tests/util/test_ans.cc
+++ b/src/tests/util/test_ans.cc
@@ -15,8 +15,7 @@
namespace {
bool RoundtripCheck(const std::vector<uint8_t>& input,
- const uint32_t* initial_counts,
- const char* label) {
+ const uint32_t* initial_counts, const char* label) {
std::vector<uint8_t> compressed;
if (!ans::Encode(input.data(), input.size(), &compressed, initial_counts)) {
fprintf(stderr, "[%s] Encode failed\n", label);
@@ -47,7 +46,8 @@ bool RoundtripCheck(const std::vector<uint8_t>& input,
void TestRoundtripVariants() {
std::mt19937 rng_uniform(12345);
std::vector<uint8_t> random_uniform(64 * 1024);
- for (auto& b : random_uniform) b = (uint8_t)(rng_uniform() & 0xff);
+ for (auto& b : random_uniform)
+ b = (uint8_t)(rng_uniform() & 0xff);
std::mt19937 rng_skewed(67890);
std::vector<uint8_t> random_skewed(32 * 1024);
@@ -66,7 +66,7 @@ void TestRoundtripVariants() {
" return textureSample(tex, smplr, uv);\n"
"}\n";
std::vector<uint8_t> ascii_block;
- for (int i = 0; i < 50; ++i) { // cross chunk boundary
+ for (int i = 0; i < 50; ++i) { // cross chunk boundary
ascii_block.insert(ascii_block.end(), ascii, ascii + std::strlen(ascii));
}
@@ -124,7 +124,8 @@ void TestRejection() {
// 1) Mismatched models.
{
std::vector<uint8_t> v(4096);
- for (auto& b : v) b = (uint8_t)('a' + (rng() % 26));
+ for (auto& b : v)
+ b = (uint8_t)('a' + (rng() % 26));
uint32_t hist[256] = {};
ans::Histogram(v.data(), v.size(), hist);
@@ -141,10 +142,11 @@ void TestRejection() {
// 2) Corruption.
{
std::vector<uint8_t> v(2048);
- for (auto& b : v) b = (uint8_t)(rng() & 0xff);
+ for (auto& b : v)
+ b = (uint8_t)(rng() & 0xff);
std::vector<uint8_t> encoded;
assert(ans::Encode(v.data(), v.size(), &encoded, nullptr));
- encoded[encoded.size() / 2] ^= 0x55; // flip a payload byte
+ encoded[encoded.size() / 2] ^= 0x55; // flip a payload byte
std::vector<uint8_t> decoded(v.size());
size_t decoded_size = 0;
@@ -156,7 +158,8 @@ void TestRejection() {
// 3) Truncation.
{
std::vector<uint8_t> v(4096);
- for (size_t i = 0; i < v.size(); ++i) v[i] = (uint8_t)i;
+ for (size_t i = 0; i < v.size(); ++i)
+ v[i] = (uint8_t)i;
std::vector<uint8_t> encoded;
assert(ans::Encode(v.data(), v.size(), &encoded, nullptr));
encoded.resize(encoded.size() - 8);
@@ -173,11 +176,10 @@ void TestPeekSize() {
std::vector<uint8_t> v(1234, 'Q');
std::vector<uint8_t> encoded;
assert(ans::Encode(v.data(), v.size(), &encoded, nullptr));
- assert(ans::PeekUncompressedSize(encoded.data(), encoded.size()) ==
- v.size());
+ assert(ans::PeekUncompressedSize(encoded.data(), encoded.size()) == v.size());
}
-} // namespace
+} // namespace
int main() {
TestRoundtripVariants();
diff --git a/src/tests/util/test_procedural.cc b/src/tests/util/test_procedural.cc
index c6616ad..355f70c 100644
--- a/src/tests/util/test_procedural.cc
+++ b/src/tests/util/test_procedural.cc
@@ -165,7 +165,10 @@ void test_voronoi() {
bool nonzero = false;
for (size_t i = 0; i < buffer.size(); i += 4) {
- if (buffer[i] > 0) { nonzero = true; break; }
+ if (buffer[i] > 0) {
+ nonzero = true;
+ break;
+ }
}
assert(nonzero);
@@ -204,7 +207,10 @@ void test_normalmap() {
// (non-flat normals expected)
bool has_normal_variation = false;
for (size_t i = 0; i < buffer.size(); i += 4) {
- if (buffer[i] != 128) { has_normal_variation = true; break; }
+ if (buffer[i] != 128) {
+ has_normal_variation = true;
+ break;
+ }
}
assert(has_normal_variation);