summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/effect.cc15
-rw-r--r--src/gpu/effect.h6
-rw-r--r--src/gpu/pipeline_builder.cc10
-rw-r--r--src/gpu/pipeline_builder.h4
-rw-r--r--src/gpu/sequence.cc15
-rw-r--r--src/gpu/sequence.h4
-rw-r--r--src/gpu/shader_composer.cc8
-rw-r--r--src/gpu/texture_readback.cc20
-rw-r--r--src/gpu/wgpu_resource.h28
9 files changed, 60 insertions, 50 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index a94b4a0..4230021 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -19,11 +19,10 @@ Effect::Effect(const GpuContext& ctx, const std::vector<std::string>& inputs,
}
void Effect::dispatch_render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Check if effect is active at current time
- const bool active =
- (params.time >= start_time_ && params.time < end_time_);
+ const bool active = (params.time >= start_time_ && params.time < end_time_);
// Auto-passthrough for 1:1 input/output effects outside active range
if (!active && input_nodes_.size() == 1 && output_nodes_.size() == 1) {
@@ -32,11 +31,12 @@ void Effect::dispatch_render(WGPUCommandEncoder encoder,
uniforms_buffer_.update(ctx_.queue, params);
render(encoder, params, nodes);
}
- // Multi-output effects: output undefined when inactive (validated at compile time)
+ // Multi-output effects: output undefined when inactive (validated at compile
+ // time)
}
void Effect::blit_input_to_output(WGPUCommandEncoder encoder,
- NodeRegistry& nodes) {
+ NodeRegistry& nodes) {
HEADLESS_RETURN_IF_NULL(encoder);
WGPUTexture src = nodes.get_texture(input_nodes_[0]);
@@ -52,8 +52,7 @@ void Effect::blit_input_to_output(WGPUCommandEncoder encoder,
GpuTextureCopyInfo dst_copy = {
.texture = dst, .mipLevel = 0, .origin = {0, 0, 0}};
- WGPUExtent3D extent = {(unsigned int)(width_),
- (unsigned int)(height_), 1};
+ WGPUExtent3D extent = {(unsigned int)(width_), (unsigned int)(height_), 1};
wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy,
&extent);
diff --git a/src/gpu/effect.h b/src/gpu/effect.h
index bfd5743..8055783 100644
--- a/src/gpu/effect.h
+++ b/src/gpu/effect.h
@@ -54,7 +54,8 @@ class Effect {
int height_ = 720;
// Common resources (initialized automatically in base class)
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_; // Auto-updated in dispatch_render()
+ UniformBuffer<UniformsSequenceParams>
+ uniforms_buffer_; // Auto-updated in dispatch_render()
Sampler sampler_;
Texture dummy_texture_;
TextureView dummy_texture_view_;
@@ -65,7 +66,8 @@ class Effect {
// Helper: Create nearest sampler (call in subclass constructor if needed)
void create_nearest_sampler();
- // Helper: Create dummy texture for scene effects (call in subclass constructor if needed)
+ // Helper: Create dummy texture for scene effects (call in subclass
+ // constructor if needed)
void create_dummy_scene_texture();
private:
diff --git a/src/gpu/pipeline_builder.cc b/src/gpu/pipeline_builder.cc
index b3fa5f8..ea4a272 100644
--- a/src/gpu/pipeline_builder.cc
+++ b/src/gpu/pipeline_builder.cc
@@ -11,7 +11,7 @@ RenderPipelineBuilder::RenderPipelineBuilder(WGPUDevice device)
}
RenderPipelineBuilder& RenderPipelineBuilder::shader(const char* wgsl,
- bool compose) {
+ bool compose) {
shader_text_ = compose ? ShaderComposer::Get().Compose({}, wgsl) : wgsl;
if (device_ == nullptr)
return *this;
@@ -26,8 +26,8 @@ RenderPipelineBuilder& RenderPipelineBuilder::shader(const char* wgsl,
return *this;
}
-RenderPipelineBuilder& RenderPipelineBuilder::bind_group_layout(
- WGPUBindGroupLayout layout) {
+RenderPipelineBuilder&
+RenderPipelineBuilder::bind_group_layout(WGPUBindGroupLayout layout) {
layouts_.push_back(layout);
return *this;
}
@@ -48,8 +48,8 @@ RenderPipelineBuilder& RenderPipelineBuilder::blend_alpha() {
return *this;
}
-RenderPipelineBuilder& RenderPipelineBuilder::depth(
- WGPUTextureFormat depth_fmt) {
+RenderPipelineBuilder&
+RenderPipelineBuilder::depth(WGPUTextureFormat depth_fmt) {
has_depth_ = true;
depth_.format = depth_fmt;
depth_.depthWriteEnabled = WGPUOptionalBool_True;
diff --git a/src/gpu/pipeline_builder.h b/src/gpu/pipeline_builder.h
index 9fd76f9..24b4e8b 100644
--- a/src/gpu/pipeline_builder.h
+++ b/src/gpu/pipeline_builder.h
@@ -34,8 +34,8 @@ class RenderPipelineBuilder {
RenderPipelineBuilder& bind_group_layout(WGPUBindGroupLayout layout);
RenderPipelineBuilder& format(WGPUTextureFormat fmt);
RenderPipelineBuilder& blend_alpha();
- RenderPipelineBuilder& depth(
- WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus);
+ RenderPipelineBuilder&
+ depth(WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus);
RenderPipelineBuilder& cull_back();
WGPURenderPipeline build();
};
diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc
index 783f3df..1e3be6c 100644
--- a/src/gpu/sequence.cc
+++ b/src/gpu/sequence.cc
@@ -30,7 +30,8 @@ NodeRegistry::NodeRegistry(WGPUDevice device, int default_width,
NodeRegistry::~NodeRegistry() {
for (auto& [name, node] : nodes_) {
- if (node.texture == nullptr) continue; // External view, not owned
+ if (node.texture == nullptr)
+ continue; // External view, not owned
if (node.view) {
wgpuTextureViewRelease(node.view);
}
@@ -107,7 +108,8 @@ void NodeRegistry::resize(int width, int height) {
default_height_ = height;
for (auto& [name, node] : nodes_) {
- if (node.texture == nullptr) continue; // External view, not owned
+ if (node.texture == nullptr)
+ continue; // External view, not owned
// Release old texture
if (node.view) {
wgpuTextureViewRelease(node.view);
@@ -184,8 +186,7 @@ void NodeRegistry::create_texture(Node& node) {
WGPUTextureDescriptor desc = {};
desc.usage = usage;
desc.dimension = WGPUTextureDimension_2D;
- desc.size = {(unsigned int)(node.width),
- (unsigned int)(node.height), 1};
+ desc.size = {(unsigned int)(node.width), (unsigned int)(node.height), 1};
desc.format = format;
desc.mipLevelCount = 1;
desc.sampleCount = 1;
@@ -218,10 +219,8 @@ Sequence::Sequence(const GpuContext& ctx, int width, int height)
void Sequence::preprocess(float seq_time, float beat_time, float beat_phase,
float audio_intensity) {
- params_.resolution = {(float)(width_),
- (float)(height_)};
- params_.aspect_ratio =
- (float)(width_) / (float)(height_);
+ params_.resolution = {(float)(width_), (float)(height_)};
+ params_.aspect_ratio = (float)(width_) / (float)(height_);
params_.time = seq_time;
params_.beat_time = beat_time;
params_.beat_phase = beat_phase;
diff --git a/src/gpu/sequence.h b/src/gpu/sequence.h
index 2ad0a8f..a515d1f 100644
--- a/src/gpu/sequence.h
+++ b/src/gpu/sequence.h
@@ -15,7 +15,7 @@
class Effect;
enum class NodeType {
- U8X4_NORM, // RGBAu8 (default Source/Sink)
+ U8X4_NORM, // RGBAu8 (default Source/Sink)
F32X4,
F16X8,
DEPTH24,
@@ -38,7 +38,7 @@ struct UniformsSequenceParams {
float beat_time; // Musical beats
float beat_phase; // Fractional beat 0.0-1.0
float audio_intensity;
- float noise; // Random value [0..1]
+ float noise; // Random value [0..1]
};
static_assert(sizeof(UniformsSequenceParams) == 32,
"UniformsSequenceParams must be 32 bytes for WGSL alignment");
diff --git a/src/gpu/shader_composer.cc b/src/gpu/shader_composer.cc
index be311dd..d871c5e 100644
--- a/src/gpu/shader_composer.cc
+++ b/src/gpu/shader_composer.cc
@@ -50,8 +50,9 @@ void ShaderComposer::ResolveRecursive(const std::string& source,
std::string suggestion;
for (const auto& [sname, _] : snippets_) {
auto slash = sname.rfind('/');
- std::string basename =
- (slash == std::string::npos) ? sname : sname.substr(slash + 1);
+ std::string basename = (slash == std::string::npos)
+ ? sname
+ : sname.substr(slash + 1);
if (basename == name) {
suggestion = sname;
break;
@@ -133,7 +134,8 @@ void ShaderComposer::VerifyIncludes() const {
}
}
if (!missing.empty()) {
- fprintf(stderr, "ERROR: Unregistered shader snippets referenced in #include:\n");
+ fprintf(stderr,
+ "ERROR: Unregistered shader snippets referenced in #include:\n");
for (const auto& name : missing) {
std::string suggestion;
for (const auto& [sname, _] : snippets_) {
diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc
index 211beed..e512428 100644
--- a/src/gpu/texture_readback.cc
+++ b/src/gpu/texture_readback.cc
@@ -56,8 +56,7 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
},
};
- const WGPUExtent3D copy_size = {(uint32_t)(width),
- (uint32_t)(height), 1};
+ const WGPUExtent3D copy_size = {(uint32_t)(width), (uint32_t)(height), 1};
wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, &copy_size);
@@ -117,8 +116,8 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
}
// Copy data from mapped buffer (handle row padding)
- const uint8_t* mapped_data = (const uint8_t*)(
- wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
+ const uint8_t* mapped_data =
+ (const uint8_t*)(wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
if (mapped_data) {
// If rows are aligned, copy row by row to remove padding
if (aligned_bytes_per_row != unaligned_bytes_per_row) {
@@ -212,8 +211,7 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
.rowsPerImage = (uint32_t)(height),
},
};
- const WGPUExtent3D copy_size = {(uint32_t)(width),
- (uint32_t)(height), 1};
+ const WGPUExtent3D copy_size = {(uint32_t)(width), (uint32_t)(height), 1};
wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, &copy_size);
WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr);
@@ -259,15 +257,15 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
}
// Convert FP16 to U8 ([-1,1] → [0,255])
- const uint16_t* mapped_data = (const uint16_t*)(
- wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
+ const uint16_t* mapped_data =
+ (const uint16_t*)(wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
std::vector<uint8_t> pixels(width * height * 4);
if (mapped_data) {
for (int y = 0; y < height; ++y) {
- const uint16_t* src_row = (const uint16_t*)(
- (const uint8_t*)(mapped_data) +
- y * aligned_bytes_per_row);
+ const uint16_t* src_row =
+ (const uint16_t*)((const uint8_t*)(mapped_data) +
+ y * aligned_bytes_per_row);
for (int x = 0; x < width; ++x) {
float r = fp16_to_float(src_row[x * 4 + 0]);
float g = fp16_to_float(src_row[x * 4 + 1]);
diff --git a/src/gpu/wgpu_resource.h b/src/gpu/wgpu_resource.h
index e448b18..e12aa45 100644
--- a/src/gpu/wgpu_resource.h
+++ b/src/gpu/wgpu_resource.h
@@ -11,11 +11,14 @@
#include "platform/platform.h"
#include "util/fatal_error.h"
-template<typename T, void(*Release)(T)>
-class WGPUResource {
+template <typename T, void (*Release)(T)> class WGPUResource {
public:
- WGPUResource() : ptr_(nullptr) {}
- ~WGPUResource() { if (ptr_) Release(ptr_); }
+ WGPUResource() : ptr_(nullptr) {
+ }
+ ~WGPUResource() {
+ if (ptr_)
+ Release(ptr_);
+ }
void set(T ptr) {
FATAL_ASSERT(ptr_ == nullptr);
@@ -23,12 +26,17 @@ class WGPUResource {
}
void replace(T ptr) {
- if (ptr_) Release(ptr_);
+ if (ptr_)
+ Release(ptr_);
ptr_ = ptr;
}
- T get() const { return ptr_; }
- T* get_address() { return &ptr_; }
+ T get() const {
+ return ptr_;
+ }
+ T* get_address() {
+ return &ptr_;
+ }
private:
T ptr_;
@@ -37,8 +45,10 @@ class WGPUResource {
};
using BindGroup = WGPUResource<WGPUBindGroup, wgpuBindGroupRelease>;
-using RenderPipeline = WGPUResource<WGPURenderPipeline, wgpuRenderPipelineRelease>;
-using ComputePipeline = WGPUResource<WGPUComputePipeline, wgpuComputePipelineRelease>;
+using RenderPipeline =
+ WGPUResource<WGPURenderPipeline, wgpuRenderPipelineRelease>;
+using ComputePipeline =
+ WGPUResource<WGPUComputePipeline, wgpuComputePipelineRelease>;
using Sampler = WGPUResource<WGPUSampler, wgpuSamplerRelease>;
using Texture = WGPUResource<WGPUTexture, wgpuTextureRelease>;
using TextureView = WGPUResource<WGPUTextureView, wgpuTextureViewRelease>;