From 18eb8a07ba39a8aad1c75521cee027b9c9c72e40 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 00:58:20 +0100 Subject: clang-format --- src/gpu/demo_effects.cc | 30 +++++++------- src/gpu/demo_effects.h | 40 +++++++++--------- src/gpu/effect.cc | 75 +++++++++++++++++++--------------- src/gpu/effect.h | 51 +++++++++++++---------- src/gpu/gpu.cc | 106 +++++++++++++++++++++++++----------------------- src/gpu/gpu.h | 38 +++++++++-------- 6 files changed, 185 insertions(+), 155 deletions(-) (limited to 'src/gpu') diff --git a/src/gpu/demo_effects.cc b/src/gpu/demo_effects.cc index 77fb152..dbf5be8 100644 --- a/src/gpu/demo_effects.cc +++ b/src/gpu/demo_effects.cc @@ -11,7 +11,7 @@ // Helper to create a standard post-processing pipeline static WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPUTextureFormat format, - const char *shader_code) { + const char* shader_code) { WGPUShaderModuleDescriptor shader_desc = {}; WGPUShaderSourceWGSL wgsl_src = {}; wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; @@ -66,7 +66,7 @@ create_post_process_pipeline(WGPUDevice device, WGPUTextureFormat format, // --- SHADERS --- -const char *main_shader_wgsl = R"( +const char* main_shader_wgsl = R"( struct Uniforms { audio_peak: f32, aspect_ratio: f32, time: f32, }; @group(0) @binding(0) var uniforms: Uniforms; @vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4 { @@ -84,7 +84,7 @@ struct Uniforms { audio_peak: f32, aspect_ratio: f32, time: f32, }; return vec4(r+boost,g+boost,b+boost, 1.0); })"; -const char *particle_compute_wgsl = R"( +const char* particle_compute_wgsl = R"( struct Particle { pos: vec4, vel: vec4, rot: vec4, color: vec4, }; struct Uniforms { audio_peak: f32, aspect_ratio: f32, time: f32, beat: f32, }; @group(0) @binding(0) var particles: array; @@ -105,7 +105,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { particles[i] = p; })"; -const char *particle_render_wgsl = R"( +const char* particle_render_wgsl = R"( struct Particle { pos: vec4, vel: vec4, rot: vec4, color: vec4, }; struct Uniforms { audio_peak: f32, aspect_ratio: f32, time: f32, beat: f32, }; @group(0) @binding(0) var particles: array; @@ -124,7 +124,7 @@ struct VSOut { @builtin(position) pos: vec4, @location(0) color: vec4, @fragment fn fs_main(@location(0) color: vec4) -> @location(0) vec4 { return color; } )"; -const char *passthrough_shader_wgsl = R"( +const char* passthrough_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; @vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4 { @@ -135,7 +135,7 @@ const char *passthrough_shader_wgsl = R"( return textureSample(txt, smplr, p.xy / vec2(1280.0, 720.0)); })"; -const char *ellipse_shader_wgsl = R"( +const char* ellipse_shader_wgsl = R"( struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; @group(0) @binding(0) var uniforms: Uniforms; @vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4 { @@ -158,7 +158,7 @@ fn sdEllipse(p: vec2, ab: vec2) -> f32 { return mix(vec4(0.2, 0.8, 0.4, 1.0), vec4(0.0), smoothstep(0.0, 0.01, d)); })"; -const char *particle_spray_compute_wgsl = R"( +const char* particle_spray_compute_wgsl = R"( struct Particle { pos: vec4, vel: vec4, rot: vec4, color: vec4, }; struct Uniforms { intensity: f32, aspect_ratio: f32, time: f32, beat: f32, }; @group(0) @binding(0) var particles: array; @@ -180,7 +180,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { particles[i] = p; })"; -const char *gaussian_blur_shader_wgsl = R"( +const char* gaussian_blur_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; @group(0) @binding(2) var uniforms: Uniforms; @@ -199,7 +199,7 @@ struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; return res / 25.0; })"; -const char *solarize_shader_wgsl = R"( +const char* solarize_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; @group(0) @binding(2) var uniforms: Uniforms; @@ -216,7 +216,7 @@ struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; return col; })"; -const char *distort_shader_wgsl = R"( +const char* distort_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; @group(0) @binding(2) var uniforms: Uniforms; @@ -230,7 +230,7 @@ struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; return textureSample(txt, smplr, uv + vec2(dist, 0.0)); })"; -const char *chroma_aberration_shader_wgsl = R"( +const char* chroma_aberration_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; struct Uniforms { time: f32, beat: f32, intensity: f32, aspect_ratio: f32, }; @group(0) @binding(2) var uniforms: Uniforms; @@ -317,10 +317,11 @@ void ParticlesEffect::render(WGPURenderPassEncoder pass, float t, float b, // --- PostProcess Implementation Helper --- static void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, - WGPUBindGroup *bind_group, + WGPUBindGroup* bind_group, WGPUTextureView input_view, GpuBuffer uniforms) { - if (*bind_group) wgpuBindGroupRelease(*bind_group); + if (*bind_group) + wgpuBindGroupRelease(*bind_group); WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline, 0); WGPUSamplerDescriptor sd = {}; sd.magFilter = WGPUFilterMode_Linear; @@ -385,7 +386,8 @@ ParticleSprayEffect::ParticleSprayEffect(WGPUDevice device, WGPUQueue queue, gpu_create_buffer(device, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); std::vector init_p(NUM_PARTICLES); - for (auto &p : init_p) p.pos[3] = 0.0f; + for (Particle& p : init_p) + p.pos[3] = 0.0f; particles_buffer_ = gpu_create_buffer( device, sizeof(Particle) * NUM_PARTICLES, WGPUBufferUsage_Storage | WGPUBufferUsage_Vertex, init_p.data()); diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index 5db710e..160ce65 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -16,26 +16,26 @@ struct Particle { }; class HeptagonEffect : public Effect { -public: + public: HeptagonEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; -private: + private: WGPUQueue queue_; RenderPass pass_; GpuBuffer uniforms_; }; class ParticlesEffect : public Effect { -public: + public: ParticlesEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void compute(WGPUCommandEncoder encoder, float time, float beat, float intensity, float aspect_ratio) override; void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; -private: + private: WGPUQueue queue_; ComputePass compute_pass_; RenderPass render_pass_; @@ -44,30 +44,30 @@ private: }; class PassthroughEffect : public PostProcessEffect { -public: + public: PassthroughEffect(WGPUDevice device, WGPUTextureFormat format); void update_bind_group(WGPUTextureView input_view) override; -private: + private: WGPUDevice device_; GpuBuffer uniforms_; }; class MovingEllipseEffect : public Effect { -public: + public: MovingEllipseEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; -private: + private: WGPUQueue queue_; RenderPass pass_; GpuBuffer uniforms_; }; class ParticleSprayEffect : public Effect { -public: + public: ParticleSprayEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void compute(WGPUCommandEncoder encoder, float time, float beat, @@ -75,7 +75,7 @@ public: void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; -private: + private: WGPUQueue queue_; ComputePass compute_pass_; RenderPass render_pass_; @@ -84,59 +84,59 @@ private: }; class GaussianBlurEffect : public PostProcessEffect { -public: + public: GaussianBlurEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; -private: + private: WGPUDevice device_; WGPUQueue queue_; GpuBuffer uniforms_; }; class SolarizeEffect : public PostProcessEffect { -public: + public: SolarizeEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; -private: + private: WGPUDevice device_; WGPUQueue queue_; GpuBuffer uniforms_; }; class DistortEffect : public PostProcessEffect { -public: + public: DistortEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; -private: + private: WGPUDevice device_; WGPUQueue queue_; GpuBuffer uniforms_; }; class ChromaAberrationEffect : public PostProcessEffect { -public: + public: ChromaAberrationEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; -private: + private: WGPUDevice device_; WGPUQueue queue_; GpuBuffer uniforms_; }; // Auto-generated function to populate the timeline -void LoadTimeline(MainSequence &main_seq, WGPUDevice device, WGPUQueue queue, - WGPUTextureFormat format); \ No newline at end of file +void LoadTimeline(MainSequence& main_seq, WGPUDevice device, WGPUQueue queue, + WGPUTextureFormat format); diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 86390a9..64bd053 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -19,8 +19,8 @@ void PostProcessEffect::render(WGPURenderPassEncoder pass, float, float, float, } // --- Sequence Implementation --- -void Sequence::init(MainSequence *demo) { - for (auto &item : items_) { +void Sequence::init(MainSequence* demo) { + for (SequenceItem& item : items_) { if (!item.effect->is_initialized) { item.effect->init(demo); item.effect->is_initialized = true; @@ -35,16 +35,17 @@ void Sequence::add_effect(std::shared_ptr effect, float start_time, } void Sequence::sort_items() { - if (is_sorted_) return; + if (is_sorted_) + return; std::sort(items_.begin(), items_.end(), - [](const SequenceItem &a, const SequenceItem &b) { + [](const SequenceItem& a, const SequenceItem& b) { return a.priority < b.priority; }); is_sorted_ = true; } void Sequence::update_active_list(float seq_time) { - for (auto &item : items_) { + for (SequenceItem& item : items_) { bool should_be_active = (seq_time >= item.start_time && seq_time < item.end_time); @@ -59,10 +60,10 @@ void Sequence::update_active_list(float seq_time) { } void Sequence::collect_active_effects( - std::vector &scene_effects, - std::vector &post_effects) { + std::vector& scene_effects, + std::vector& post_effects) { sort_items(); - for (auto &item : items_) { + for (SequenceItem& item : items_) { if (item.active) { if (item.effect->is_post_process()) { post_effects.push_back(&item); @@ -74,7 +75,7 @@ void Sequence::collect_active_effects( } void Sequence::reset() { - for (auto &item : items_) { + for (SequenceItem& item : items_) { if (item.active) { item.effect->end(); item.active = false; @@ -129,14 +130,16 @@ void MainSequence::init(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f, create_framebuffers(width, height); passthrough_effect_ = std::make_unique(device, format); - for (auto &entry : sequences_) { entry.seq->init(this); } + for (ActiveSequence& entry : sequences_) { + entry.seq->init(this); + } } void MainSequence::add_sequence(std::shared_ptr seq, float start_time, int priority) { sequences_.push_back({seq, start_time, priority}); std::sort(sequences_.begin(), sequences_.end(), - [](const ActiveSequence &a, const ActiveSequence &b) { + [](const ActiveSequence& a, const ActiveSequence& b) { return a.priority < b.priority; }); } @@ -145,9 +148,9 @@ void MainSequence::render_frame(float global_time, float beat, float peak, float aspect_ratio, WGPUSurface surface) { WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr); - std::vector scene_effects; - std::vector post_effects; - for (auto &entry : sequences_) { + std::vector scene_effects; + std::vector post_effects; + for (ActiveSequence& entry : sequences_) { if (global_time >= entry.start_time) { float seq_time = global_time - entry.start_time; entry.seq->update_active_list(seq_time); @@ -155,16 +158,16 @@ void MainSequence::render_frame(float global_time, float beat, float peak, } } std::sort(scene_effects.begin(), scene_effects.end(), - [](const SequenceItem *a, const SequenceItem *b) { + [](const SequenceItem* a, const SequenceItem* b) { return a->priority < b->priority; }); std::sort(post_effects.begin(), post_effects.end(), - [](const SequenceItem *a, const SequenceItem *b) { + [](const SequenceItem* a, const SequenceItem* b) { return a->priority < b->priority; }); // 1. Compute - for (const auto &item : scene_effects) { + for (const SequenceItem* item : scene_effects) { item->effect->compute(encoder, global_time - item->start_time, beat, peak, aspect_ratio); } @@ -178,12 +181,12 @@ void MainSequence::render_frame(float global_time, float beat, float peak, scene_attachment.clearValue = {0, 0, 0, 1}; #if !defined(DEMO_CROSS_COMPILE_WIN32) scene_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; -#endif +#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ WGPURenderPassDescriptor scene_desc = {.colorAttachmentCount = 1, .colorAttachments = &scene_attachment}; WGPURenderPassEncoder scene_pass = wgpuCommandEncoderBeginRenderPass(encoder, &scene_desc); - for (const auto &item : scene_effects) { + for (const SequenceItem* item : scene_effects) { item->effect->render(scene_pass, global_time - item->start_time, beat, peak, aspect_ratio); } @@ -205,7 +208,7 @@ void MainSequence::render_frame(float global_time, float beat, float peak, final_attachment.storeOp = WGPUStoreOp_Store; #if !defined(DEMO_CROSS_COMPILE_WIN32) final_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; -#endif +#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ WGPURenderPassDescriptor final_desc = { .colorAttachmentCount = 1, .colorAttachments = &final_attachment}; WGPURenderPassEncoder final_pass = @@ -228,8 +231,8 @@ void MainSequence::render_frame(float global_time, float beat, float peak, : framebuffer_view_a_); } - PostProcessEffect *pp = - static_cast(post_effects[i]->effect.get()); + PostProcessEffect* pp = + (PostProcessEffect*)(post_effects[i]->effect.get()); pp->update_bind_group(current_input); WGPURenderPassColorAttachment pp_attachment = {}; @@ -239,7 +242,7 @@ void MainSequence::render_frame(float global_time, float beat, float peak, pp_attachment.storeOp = WGPUStoreOp_Store; #if !defined(DEMO_CROSS_COMPILE_WIN32) pp_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; -#endif +#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ WGPURenderPassDescriptor pp_desc = {.colorAttachmentCount = 1, .colorAttachments = &pp_attachment}; WGPURenderPassEncoder pp_pass = @@ -262,14 +265,20 @@ void MainSequence::render_frame(float global_time, float beat, float peak, } void MainSequence::shutdown() { - if (framebuffer_view_a_) wgpuTextureViewRelease(framebuffer_view_a_); - if (framebuffer_a_) wgpuTextureRelease(framebuffer_a_); - if (framebuffer_view_b_) wgpuTextureViewRelease(framebuffer_view_b_); - if (framebuffer_b_) wgpuTextureRelease(framebuffer_b_); - for (auto &entry : sequences_) { entry.seq->reset(); } + if (framebuffer_view_a_) + wgpuTextureViewRelease(framebuffer_view_a_); + if (framebuffer_a_) + wgpuTextureRelease(framebuffer_a_); + if (framebuffer_view_b_) + wgpuTextureViewRelease(framebuffer_view_b_); + if (framebuffer_b_) + wgpuTextureRelease(framebuffer_b_); + for (ActiveSequence& entry : sequences_) { + entry.seq->reset(); + } } -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void MainSequence::simulate_until(float target_time, float step_rate) { const float bpm = 128.0f; const float aspect_ratio = 16.0f / 9.0f; @@ -277,14 +286,14 @@ void MainSequence::simulate_until(float target_time, float step_rate) { WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr); float beat = fmodf(t * bpm / 60.0f, 1.0f); - std::vector scene_effects, post_effects; - for (auto &entry : sequences_) { + std::vector scene_effects, post_effects; + for (ActiveSequence& entry : sequences_) { if (t >= entry.start_time) { entry.seq->update_active_list(t - entry.start_time); entry.seq->collect_active_effects(scene_effects, post_effects); } } - for (const auto &item : scene_effects) { + for (const SequenceItem* item : scene_effects) { item->effect->compute(encoder, t - item->start_time, beat, 0.0f, aspect_ratio); } @@ -292,4 +301,4 @@ void MainSequence::simulate_until(float target_time, float step_rate) { wgpuQueueSubmit(queue, 1, &commands); } } -#endif +#endif /* !defined(STRIP_ALL) */ diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 0b791a3..ee90fa4 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -7,16 +7,19 @@ #include #else #include -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ class MainSequence; class PostProcessEffect; class Effect { -public: + public: virtual ~Effect() = default; - virtual void init(MainSequence *demo) { (void)demo; } - virtual void start() {} + virtual void init(MainSequence* demo) { + (void)demo; + } + virtual void start() { + } virtual void compute(WGPUCommandEncoder encoder, float time, float beat, float intensity, float aspect_ratio) { (void)encoder; @@ -27,20 +30,26 @@ public: } virtual void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) = 0; - virtual void end() {} + virtual void end() { + } bool is_initialized = false; - virtual bool is_post_process() const { return false; } + virtual bool is_post_process() const { + return false; + } }; class PostProcessEffect : public Effect { -public: - bool is_post_process() const override { return true; } - void compute(WGPUCommandEncoder, float, float, float, float) override {} + public: + bool is_post_process() const override { + return true; + } + void compute(WGPUCommandEncoder, float, float, float, float) override { + } void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; virtual void update_bind_group(WGPUTextureView input_view) = 0; -protected: + protected: WGPURenderPipeline pipeline_ = nullptr; WGPUBindGroup bind_group_ = nullptr; }; @@ -54,24 +63,24 @@ struct SequenceItem { }; class Sequence { -public: + public: int priority = 0; // Render order of this sequence (higher = later/top) - void init(MainSequence *demo); + void init(MainSequence* demo); void add_effect(std::shared_ptr effect, float start_time, float end_time, int priority = 0); void update_active_list(float seq_time); - void collect_active_effects(std::vector &scene_effects, - std::vector &post_effects); + void collect_active_effects(std::vector& scene_effects, + std::vector& post_effects); void reset(); -private: + private: std::vector items_; bool is_sorted_ = false; void sort_items(); }; class MainSequence { -public: + public: MainSequence(); ~MainSequence(); WGPUDevice device; @@ -86,11 +95,11 @@ public: float aspect_ratio, WGPUSurface surface); void shutdown(); -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void simulate_until(float target_time, float step_rate); -#endif +#endif /* !defined(STRIP_ALL) */ -private: + private: struct ActiveSequence { std::shared_ptr seq; float start_time; @@ -103,10 +112,10 @@ private: WGPUTexture framebuffer_b_ = nullptr; WGPUTextureView framebuffer_view_b_ = nullptr; -public: // Made public for testing + public: // Made public for testing void init_test(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); -private: // Restore private access for other members + private: // Restore private access for other members std::unique_ptr passthrough_effect_; void create_framebuffers(int width, int height); diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index 8618280..a097efa 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -16,9 +16,9 @@ #include #include -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #include -#endif +#endif /* !defined(STRIP_ALL) */ // --- WebGPU Headers & Compatibility --- #if defined(DEMO_CROSS_COMPILE_WIN32) @@ -28,7 +28,7 @@ #define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ WGPUSurfaceGetCurrentTextureStatus_Success #define WGPUCallbackMode_WaitAnyOnly 0 -static void wgpuInstanceWaitAny(WGPUInstance instance, size_t, void *, +static void wgpuInstanceWaitAny(WGPUInstance instance, size_t, void*, uint64_t) { wgpuInstanceProcessEvents(instance); } @@ -40,7 +40,7 @@ static void set_error_callback(WGPUDevice device, WGPUUncapturedErrorCallback callback) { // Handled in descriptor for new API. } -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; @@ -54,7 +54,7 @@ static MainSequence g_main_sequence; // --- Helper Functions --- GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, - const void *data) { + const void* data) { WGPUBufferDescriptor desc = {}; desc.label = label_view("GpuBuffer"); desc.usage = (WGPUBufferUsage)usage; // Cast for C++ strictness with enums @@ -64,7 +64,7 @@ GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, WGPUBuffer buffer = wgpuDeviceCreateBuffer(device, &desc); if (data) { - void *ptr = wgpuBufferGetMappedRange(buffer, 0, size); + void* ptr = wgpuBufferGetMappedRange(buffer, 0, size); memcpy(ptr, data, size); wgpuBufferUnmap(buffer); } @@ -73,8 +73,8 @@ GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, } RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, - const char *shader_code, - ResourceBinding *bindings, int num_bindings) { + const char* shader_code, + ResourceBinding* bindings, int num_bindings) { RenderPass pass = {}; // Create Shader Module @@ -160,8 +160,8 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, return pass; } -ComputePass gpu_create_compute_pass(WGPUDevice device, const char *shader_code, - ResourceBinding *bindings, +ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, + ResourceBinding* bindings, int num_bindings) { ComputePass pass = {}; @@ -220,98 +220,98 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char *shader_code, // --- Main Init/Draw --- -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #if defined(DEMO_CROSS_COMPILE_WIN32) static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char *message, - void *userdata) { + WGPUAdapter adapter, const char* message, + void* userdata) { if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } else { printf("Request adapter failed: %s\n", message ? message : "Unknown"); } } static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char *message, - void *userdata) { + WGPUDevice device, const char* message, + void* userdata) { if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } else { printf("Request device failed: %s\n", message ? message : "Unknown"); } } -static void handle_device_error(WGPUErrorType type, const char *message, - void *userdata) { +static void handle_device_error(WGPUErrorType type, const char* message, + void* userdata) { printf("WebGPU Error: %s\n", message ? message : "Unknown"); } #else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } else { printf("Request adapter failed: %.*s\n", (int)message.length, message.data); } } static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } else { printf("Request device failed: %.*s\n", (int)message.length, message.data); } } -static void handle_device_error(const WGPUDevice *device, WGPUErrorType type, - WGPUStringView message, void *userdata, - void *userdata2) { +static void handle_device_error(const WGPUDevice* device, WGPUErrorType type, + WGPUStringView message, void* userdata, + void* userdata2) { (void)device; (void)userdata; (void)userdata2; printf("WebGPU Error: %.*s\n", (int)message.length, message.data); } -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ #else // STRIP_ALL versions #if defined(DEMO_CROSS_COMPILE_WIN32) static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char *message, - void *userdata) { + WGPUAdapter adapter, const char* message, + void* userdata) { if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } } static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char *message, - void *userdata) { + WGPUDevice device, const char* message, + void* userdata) { if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } } #else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } } static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } } -#endif -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ +#endif /* !defined(STRIP_ALL) */ -void gpu_init(GLFWwindow *window, int width, int height) { +void gpu_init(GLFWwindow* window, int width, int height) { g_instance = wgpuCreateInstance(nullptr); g_surface = platform_create_wgpu_surface(g_instance); @@ -328,15 +328,16 @@ void gpu_init(GLFWwindow *window, int width, int height) { adapter_cb.callback = handle_request_adapter; adapter_cb.userdata1 = &g_adapter; wgpuInstanceRequestAdapter(g_instance, &adapter_opts, adapter_cb); -#endif - while (!g_adapter) wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ + while (!g_adapter) + wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); WGPUDeviceDescriptor device_desc = {}; -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #if !defined(DEMO_CROSS_COMPILE_WIN32) device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error; -#endif -#endif +#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ +#endif /* !defined(STRIP_ALL) */ #if defined(DEMO_CROSS_COMPILE_WIN32) wgpuAdapterRequestDevice(g_adapter, &device_desc, handle_request_device, @@ -347,12 +348,13 @@ void gpu_init(GLFWwindow *window, int width, int height) { device_cb.callback = handle_request_device; device_cb.userdata1 = &g_device; wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb); -#endif - while (!g_device) wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ + while (!g_device) + wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); #if defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) set_error_callback(g_device, handle_device_error); -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) */ g_queue = wgpuDeviceGetQueue(g_device); @@ -378,10 +380,12 @@ void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat) { g_main_sequence.render_frame(time, beat, audio_peak, aspect_ratio, g_surface); } -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void gpu_simulate_until(float time) { g_main_sequence.simulate_until(time, 1.0f / 60.0f); } -#endif +#endif /* !defined(STRIP_ALL) */ -void gpu_shutdown() { g_main_sequence.shutdown(); } \ No newline at end of file +void gpu_shutdown() { + g_main_sequence.shutdown(); +} diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h index 062b822..8814cbc 100644 --- a/src/gpu/gpu.h +++ b/src/gpu/gpu.h @@ -16,9 +16,13 @@ #include -static inline const char *str_view(const char *str) { return str; } +static inline const char* str_view(const char* str) { + return str; +} -static inline const char *label_view(const char *str) { return str; } +static inline const char* label_view(const char* str) { + return str; +} #define WGPUSType_ShaderSourceWGSL WGPUSType_ShaderModuleWGSLDescriptor @@ -40,17 +44,19 @@ using WGPUShaderSourceWGSL = WGPUShaderModuleWGSLDescriptor; #include -static inline WGPUStringView str_view(const char *str) { - if (!str) return {nullptr, 0}; +static inline WGPUStringView str_view(const char* str) { + if (!str) + return {nullptr, 0}; return {str, strlen(str)}; } -static inline WGPUStringView label_view(const char *str) { +static inline WGPUStringView label_view(const char* str) { -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) - if (!str) return {nullptr, 0}; + if (!str) + return {nullptr, 0}; return {str, strlen(str)}; @@ -60,10 +66,10 @@ static inline WGPUStringView label_view(const char *str) { return {nullptr, 0}; -#endif +#endif /* !defined(STRIP_ALL) */ } -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ struct GLFWwindow; @@ -90,11 +96,11 @@ struct RenderPass { uint32_t instance_count; }; -void gpu_init(GLFWwindow *window, int width, int height); +void gpu_init(GLFWwindow* window, int width, int height); void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat); -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void gpu_simulate_until(float time); -#endif +#endif /* !defined(STRIP_ALL) */ void gpu_shutdown(); // Helper functions (exposed for internal/future use) @@ -105,12 +111,12 @@ struct ResourceBinding { }; GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, - const void *data = nullptr); -ComputePass gpu_create_compute_pass(WGPUDevice device, const char *shader_code, - ResourceBinding *bindings, + const void* data = nullptr); +ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, + ResourceBinding* bindings, int num_bindings); RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, // Needed for render pipeline - const char *shader_code, ResourceBinding *bindings, + const char* shader_code, ResourceBinding* bindings, int num_bindings); -- cgit v1.2.3