summaryrefslogtreecommitdiff
path: root/src/tests/test_post_process_helper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_post_process_helper.cc')
-rw-r--r--src/tests/test_post_process_helper.cc81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/tests/test_post_process_helper.cc b/src/tests/test_post_process_helper.cc
index c1c5591..c009bc2 100644
--- a/src/tests/test_post_process_helper.cc
+++ b/src/tests/test_post_process_helper.cc
@@ -2,12 +2,12 @@
// It tests post-processing helper functions (pipeline and bind group creation).
// Validates that helpers can create valid WebGPU resources.
-#if !defined(STRIP_ALL) // Test code only - zero size impact on final binary
+#if !defined(STRIP_ALL) // Test code only - zero size impact on final binary
-#include "webgpu_test_fixture.h"
-#include "offscreen_render_target.h"
#include "gpu/demo_effects.h"
#include "gpu/gpu.h"
+#include "offscreen_render_target.h"
+#include "webgpu_test_fixture.h"
#include <cassert>
#include <cstdio>
@@ -16,16 +16,18 @@ extern WGPURenderPipeline create_post_process_pipeline(WGPUDevice device,
WGPUTextureFormat format,
const char* shader_code);
extern void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline,
- WGPUBindGroup* bind_group, WGPUTextureView input_view,
+ WGPUBindGroup* bind_group,
+ WGPUTextureView input_view,
GpuBuffer uniforms);
-// Helper: Create a texture suitable for post-processing (both render target and texture binding)
-static WGPUTexture create_post_process_texture(WGPUDevice device, int width, int height,
+// Helper: Create a texture suitable for post-processing (both render target and
+// texture binding)
+static WGPUTexture create_post_process_texture(WGPUDevice device, int width,
+ int height,
WGPUTextureFormat format) {
const WGPUTextureDescriptor texture_desc = {
.usage = WGPUTextureUsage_RenderAttachment |
- WGPUTextureUsage_TextureBinding |
- WGPUTextureUsage_CopySrc,
+ WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopySrc,
.dimension = WGPUTextureDimension_2D,
.size = {static_cast<uint32_t>(width), static_cast<uint32_t>(height), 1},
.format = format,
@@ -36,7 +38,8 @@ static WGPUTexture create_post_process_texture(WGPUDevice device, int width, int
}
// Helper: Create texture view
-static WGPUTextureView create_texture_view(WGPUTexture texture, WGPUTextureFormat format) {
+static WGPUTextureView create_texture_view(WGPUTexture texture,
+ WGPUTextureFormat format) {
const WGPUTextureViewDescriptor view_desc = {
.format = format,
.dimension = WGPUTextureViewDimension_2D,
@@ -105,24 +108,26 @@ static void test_bind_group_creation() {
assert(pipeline != nullptr && "Pipeline required for bind group test");
// Create input texture with TEXTURE_BINDING usage
- WGPUTexture input_texture = create_post_process_texture(
- fixture.device(), 256, 256, fixture.format());
- WGPUTextureView input_view = create_texture_view(input_texture, fixture.format());
+ WGPUTexture input_texture =
+ create_post_process_texture(fixture.device(), 256, 256, fixture.format());
+ WGPUTextureView input_view =
+ create_texture_view(input_texture, fixture.format());
// Create uniform buffer
const WGPUBufferDescriptor uniform_desc = {
.usage = WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst,
- .size = 16, // vec4<f32>
+ .size = 16, // vec4<f32>
};
- WGPUBuffer uniform_buffer = wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
+ WGPUBuffer uniform_buffer =
+ wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
assert(uniform_buffer != nullptr && "Uniform buffer should be created");
GpuBuffer uniforms = {uniform_buffer, 16};
// Test bind group creation
WGPUBindGroup bind_group = nullptr;
- pp_update_bind_group(fixture.device(), pipeline, &bind_group,
- input_view, uniforms);
+ pp_update_bind_group(fixture.device(), pipeline, &bind_group, input_view,
+ uniforms);
assert(bind_group != nullptr && "Bind group should be created successfully");
fprintf(stdout, " ✓ Bind group created successfully\n");
@@ -149,31 +154,32 @@ static void test_bind_group_update() {
WGPURenderPipeline pipeline = create_post_process_pipeline(
fixture.device(), fixture.format(), test_shader);
- WGPUTexture texture1 = create_post_process_texture(
- fixture.device(), 256, 256, fixture.format());
+ WGPUTexture texture1 =
+ create_post_process_texture(fixture.device(), 256, 256, fixture.format());
WGPUTextureView view1 = create_texture_view(texture1, fixture.format());
- WGPUTexture texture2 = create_post_process_texture(
- fixture.device(), 512, 512, fixture.format());
+ WGPUTexture texture2 =
+ create_post_process_texture(fixture.device(), 512, 512, fixture.format());
WGPUTextureView view2 = create_texture_view(texture2, fixture.format());
const WGPUBufferDescriptor uniform_desc = {
.usage = WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst,
.size = 16,
};
- WGPUBuffer uniform_buffer = wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
+ WGPUBuffer uniform_buffer =
+ wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
GpuBuffer uniforms = {uniform_buffer, 16};
// Create initial bind group
WGPUBindGroup bind_group = nullptr;
- pp_update_bind_group(fixture.device(), pipeline, &bind_group,
- view1, uniforms);
+ pp_update_bind_group(fixture.device(), pipeline, &bind_group, view1,
+ uniforms);
assert(bind_group != nullptr && "Initial bind group should be created");
fprintf(stdout, " ✓ Initial bind group created\n");
// Update bind group (should release old and create new)
- pp_update_bind_group(fixture.device(), pipeline, &bind_group,
- view2, uniforms);
+ pp_update_bind_group(fixture.device(), pipeline, &bind_group, view2,
+ uniforms);
assert(bind_group != nullptr && "Updated bind group should be created");
fprintf(stdout, " ✓ Bind group updated successfully\n");
@@ -204,31 +210,35 @@ static void test_full_setup() {
assert(pipeline != nullptr && "Pipeline creation failed");
// Create input texture (with TEXTURE_BINDING usage)
- WGPUTexture input_texture = create_post_process_texture(
- fixture.device(), 256, 256, fixture.format());
- WGPUTextureView input_view = create_texture_view(input_texture, fixture.format());
+ WGPUTexture input_texture =
+ create_post_process_texture(fixture.device(), 256, 256, fixture.format());
+ WGPUTextureView input_view =
+ create_texture_view(input_texture, fixture.format());
// Create output texture (can use OffscreenRenderTarget for this)
- OffscreenRenderTarget output_target(fixture.instance(), fixture.device(), 256, 256);
+ OffscreenRenderTarget output_target(fixture.instance(), fixture.device(), 256,
+ 256);
const WGPUBufferDescriptor uniform_desc = {
.usage = WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst,
.size = 16,
};
- WGPUBuffer uniform_buffer = wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
+ WGPUBuffer uniform_buffer =
+ wgpuDeviceCreateBuffer(fixture.device(), &uniform_desc);
GpuBuffer uniforms = {uniform_buffer, 16};
// Create bind group
WGPUBindGroup bind_group = nullptr;
- pp_update_bind_group(fixture.device(), pipeline, &bind_group,
- input_view, uniforms);
+ pp_update_bind_group(fixture.device(), pipeline, &bind_group, input_view,
+ uniforms);
assert(bind_group != nullptr && "Bind group creation failed");
fprintf(stdout, " ✓ Pipeline and bind group ready\n");
// Test render pass setup (smoke test - just verify we can create a pass)
const WGPUCommandEncoderDescriptor enc_desc = {};
- WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(fixture.device(), &enc_desc);
+ WGPUCommandEncoder encoder =
+ wgpuDeviceCreateCommandEncoder(fixture.device(), &enc_desc);
WGPURenderPassColorAttachment color_attachment = {};
gpu_init_color_attachment(color_attachment, output_target.view());
@@ -237,7 +247,8 @@ static void test_full_setup() {
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
// Set pipeline and bind group
wgpuRenderPassEncoderSetPipeline(pass, pipeline);
@@ -277,4 +288,4 @@ int main() {
return 0;
}
-#endif /* !defined(STRIP_ALL) */
+#endif /* !defined(STRIP_ALL) */