diff options
| author | skal <pascal.massimino@gmail.com> | 2026-05-21 08:10:47 +0200 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-05-21 08:10:47 +0200 |
| commit | d806027dcaeadcdd8d2febd88bc46b2fd2c465de (patch) | |
| tree | 30bc1ef9f40ccab7c00e31ee20e62bb86755fa26 /src/gpu | |
| parent | 680042a18c11ad5e58757e45b260745c2f52417f (diff) | |
Diffstat (limited to 'src/gpu')
| -rw-r--r-- | src/gpu/demo_effects.h | 6 | ||||
| -rw-r--r-- | src/gpu/effect.cc | 4 | ||||
| -rw-r--r-- | src/gpu/effect.h | 3 | ||||
| -rw-r--r-- | src/gpu/gpu.cc | 23 | ||||
| -rw-r--r-- | src/gpu/pipeline_builder.cc | 4 | ||||
| -rw-r--r-- | src/gpu/post_process_helper.cc | 4 | ||||
| -rw-r--r-- | src/gpu/post_process_helper.h | 3 | ||||
| -rw-r--r-- | src/gpu/sequence.cc | 8 | ||||
| -rw-r--r-- | src/gpu/sequence.h | 16 | ||||
| -rw-r--r-- | src/gpu/texture_manager.cc | 10 | ||||
| -rw-r--r-- | src/gpu/wgsl_effect.cc | 8 | ||||
| -rw-r--r-- | src/gpu/wgsl_effect.h | 12 |
12 files changed, 58 insertions, 43 deletions
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index 1f859bc..d67478e 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -22,6 +22,7 @@ #include "effects/gaussian_blur_effect.h" #include "effects/heptagon_effect.h" #include "effects/hybrid3_d_effect.h" +#include "effects/ntsc_effect.h" #include "effects/particles_effect.h" #include "effects/passthrough_effect.h" #include "effects/peak_meter_effect.h" @@ -30,12 +31,11 @@ #include "effects/scene1_effect.h" #include "effects/scene2_effect.h" #include "effects/scratch_effect.h" -#include "effects/ntsc_effect.h" // CNN v3 G-buffer + inference + debug view -#include "../../cnn_v3/src/gbuffer_effect.h" #include "../../cnn_v3/src/cnn_v3_effect.h" -#include "../../cnn_v3/src/gbuf_view_effect.h" #include "../../cnn_v3/src/gbuf_deferred_effect.h" +#include "../../cnn_v3/src/gbuf_view_effect.h" +#include "../../cnn_v3/src/gbuffer_effect.h" #include <memory> diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 2e93a11..d761b2d 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -59,8 +59,8 @@ void Effect::blit_input_to_output(WGPUCommandEncoder encoder, &extent); } -std::string Effect::find_downstream_output( - const std::vector<EffectDAGNode>& dag) const { +std::string +Effect::find_downstream_output(const std::vector<EffectDAGNode>& dag) const { for (const auto& node : dag) { for (const auto& in : node.input_nodes) { for (const auto& out : output_nodes_) { diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 47dd3c2..4c9b157 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -77,7 +77,8 @@ class Effect { // Returns output_nodes[0] of the first effect in |dag| whose input_nodes // intersect this effect's output_nodes_ (i.e. the first direct downstream // consumer). Returns "" if no such effect exists or it has no outputs. - std::string find_downstream_output(const std::vector<EffectDAGNode>& dag) const; + std::string + find_downstream_output(const std::vector<EffectDAGNode>& dag) const; // Helper: Run a fullscreen triangle pass (pipeline + bind_group → output) static void run_fullscreen_pass(WGPUCommandEncoder encoder, diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index f5f1515..3200655 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -138,14 +138,18 @@ WGPUShaderModule gpu_create_shader_module(WGPUDevice device, } WGPUSampler gpu_create_linear_sampler(WGPUDevice device) { - WGPUSampler s = SamplerCache::Get().get_or_create(device, SamplerCache::clamp()); - if (s) wgpuSamplerAddRef(s); // Caller owns a reference (for RAII wrappers) + WGPUSampler s = + SamplerCache::Get().get_or_create(device, SamplerCache::clamp()); + if (s) + wgpuSamplerAddRef(s); // Caller owns a reference (for RAII wrappers) return s; } WGPUSampler gpu_create_nearest_sampler(WGPUDevice device) { - WGPUSampler s = SamplerCache::Get().get_or_create(device, SamplerCache::nearest()); - if (s) wgpuSamplerAddRef(s); // Caller owns a reference (for RAII wrappers) + WGPUSampler s = + SamplerCache::Get().get_or_create(device, SamplerCache::nearest()); + if (s) + wgpuSamplerAddRef(s); // Caller owns a reference (for RAII wrappers) return s; } @@ -170,8 +174,8 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, // Compose shader to resolve #include directives std::string composed_shader = ShaderComposer::Get().Compose({}, shader_code); - WGPUShaderModule shader_module = - gpu_create_shader_module(device, composed_shader.c_str(), "render_shader"); + WGPUShaderModule shader_module = gpu_create_shader_module( + device, composed_shader.c_str(), "render_shader"); // Create Bind Group Layout & Bind Group std::vector<WGPUBindGroupLayoutEntry> bgl_entries; @@ -268,8 +272,8 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, // Compose shader to resolve #include directives std::string composed_shader = ShaderComposer::Get().Compose({}, shader_code); - WGPUShaderModule shader_module = - gpu_create_shader_module(device, composed_shader.c_str(), "compute_shader"); + WGPUShaderModule shader_module = gpu_create_shader_module( + device, composed_shader.c_str(), "compute_shader"); std::vector<WGPUBindGroupLayoutEntry> bgl_entries; std::vector<WGPUBindGroupEntry> bg_entries; @@ -379,7 +383,7 @@ void gpu_init(PlatformState* platform_state) { // Exclude GL backend: wgpu's WGL pixel-format selection panics under Wine. WGPUInstanceExtras win_extras = {}; win_extras.chain.sType = (WGPUSType)WGPUSType_InstanceExtras; - win_extras.backends = WGPUInstanceBackend_Primary; // Vulkan + DX12, no GL + win_extras.backends = WGPUInstanceBackend_Primary; // Vulkan + DX12, no GL WGPUInstanceDescriptor win_desc = {}; win_desc.nextInChain = (WGPUChainedStruct*)&win_extras; g_instance = wgpuCreateInstance(&win_desc); @@ -435,7 +439,6 @@ void gpu_init(PlatformState* platform_state) { wgpuSurfaceConfigure(g_surface, &g_config); InitShaderComposer(); - } void gpu_resize(int width, int height) { diff --git a/src/gpu/pipeline_builder.cc b/src/gpu/pipeline_builder.cc index acd2ae9..03eb9dd 100644 --- a/src/gpu/pipeline_builder.cc +++ b/src/gpu/pipeline_builder.cc @@ -16,8 +16,8 @@ RenderPipelineBuilder& RenderPipelineBuilder::shader(const char* wgsl, shader_text_ = compose ? ShaderComposer::Get().Compose({}, wgsl) : wgsl; if (device_ == nullptr) return *this; - shader_module_ = - gpu_create_shader_module(device_, shader_text_.c_str(), "pipeline_shader"); + shader_module_ = gpu_create_shader_module(device_, shader_text_.c_str(), + "pipeline_shader"); desc_.vertex.module = shader_module_; desc_.vertex.entryPoint = str_view("vs_main"); return *this; diff --git a/src/gpu/post_process_helper.cc b/src/gpu/post_process_helper.cc index 871a238..8e5bae2 100644 --- a/src/gpu/post_process_helper.cc +++ b/src/gpu/post_process_helper.cc @@ -40,8 +40,8 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, } // NOTE: create_post_process_pipeline_simple() was removed (zero callers). -// If a 3-binding pipeline is needed in the future, add a `bool use_effect_params` -// parameter to create_post_process_pipeline() instead. +// If a 3-binding pipeline is needed in the future, add a `bool +// use_effect_params` parameter to create_post_process_pipeline() instead. // Example: // WGPURenderPipeline p = create_post_process_pipeline(device, format, code); // // Then pass {nullptr, 0} as effect_params to pp_update_bind_group — diff --git a/src/gpu/post_process_helper.h b/src/gpu/post_process_helper.h index 8f2bd21..645ac4f 100644 --- a/src/gpu/post_process_helper.h +++ b/src/gpu/post_process_helper.h @@ -21,6 +21,7 @@ void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, WGPUBindGroup* bind_group, WGPUTextureView input_view, GpuBuffer uniforms, GpuBuffer effect_params); -// Upload a mat4 to a GPU buffer, transposing from C++ row-major to WGSL column-major. +// Upload a mat4 to a GPU buffer, transposing from C++ row-major to WGSL +// column-major. void gpu_upload_mat4(WGPUQueue queue, WGPUBuffer buffer, size_t offset, const mat4& m); diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc index c81a912..f0e0356 100644 --- a/src/gpu/sequence.cc +++ b/src/gpu/sequence.cc @@ -226,10 +226,10 @@ void NodeRegistry::create_texture(Node& node) { view_desc.mipLevelCount = 1; view_desc.baseArrayLayer = 0; view_desc.arrayLayerCount = 1; - view_desc.aspect = (node.type == NodeType::DEPTH24 || - node.type == NodeType::GBUF_DEPTH32) - ? WGPUTextureAspect_DepthOnly - : WGPUTextureAspect_All; + view_desc.aspect = + (node.type == NodeType::DEPTH24 || node.type == NodeType::GBUF_DEPTH32) + ? WGPUTextureAspect_DepthOnly + : WGPUTextureAspect_All; node.view = wgpuTextureCreateView(node.texture, &view_desc); FATAL_CHECK(node.view != nullptr, "Failed to create texture view\n"); diff --git a/src/gpu/sequence.h b/src/gpu/sequence.h index 51c8af1..ee0260d 100644 --- a/src/gpu/sequence.h +++ b/src/gpu/sequence.h @@ -19,9 +19,11 @@ enum class NodeType { DEPTH24, COMPUTE_F32, // G-buffer types for CNN v3 - GBUF_ALBEDO, // rgba16float: RENDER_ATTACHMENT | TEXTURE_BINDING | STORAGE_BINDING | COPY_SRC - GBUF_DEPTH32, // depth32float: RENDER_ATTACHMENT | TEXTURE_BINDING | COPY_SRC - GBUF_R8, // rgba8unorm (4ch for compat): STORAGE_BINDING | TEXTURE_BINDING | RENDER_ATTACHMENT + GBUF_ALBEDO, // rgba16float: RENDER_ATTACHMENT | TEXTURE_BINDING | + // STORAGE_BINDING | COPY_SRC + GBUF_DEPTH32, // depth32float: RENDER_ATTACHMENT | TEXTURE_BINDING | COPY_SRC + GBUF_R8, // rgba8unorm (4ch for compat): STORAGE_BINDING | TEXTURE_BINDING | + // RENDER_ATTACHMENT GBUF_RGBA32UINT, // rgba32uint: STORAGE_BINDING | TEXTURE_BINDING }; @@ -69,8 +71,12 @@ class NodeRegistry { void set_external_view(const std::string& name, WGPUTextureView view); - int default_width() const { return default_width_; } - int default_height() const { return default_height_; } + int default_width() const { + return default_width_; + } + int default_height() const { + return default_height_; + } private: WGPUDevice device_; diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc index 20e215d..9e42841 100644 --- a/src/gpu/texture_manager.cc +++ b/src/gpu/texture_manager.cc @@ -285,10 +285,12 @@ void TextureManager::dispatch_compute(const std::string& func_name, wgpuTextureViewRelease(target_view); } -void TextureManager::create_gpu_procedural( - const std::string& name, const std::string& func_name, - const char* shader_code, const GpuProceduralParams& params, - const void* uniform_data, size_t uniform_size) { +void TextureManager::create_gpu_procedural(const std::string& name, + const std::string& func_name, + const char* shader_code, + const GpuProceduralParams& params, + const void* uniform_data, + size_t uniform_size) { get_or_create_compute_pipeline(func_name, shader_code, uniform_size); TextureWithView tv = gpu_create_storage_texture_2d( diff --git a/src/gpu/wgsl_effect.cc b/src/gpu/wgsl_effect.cc index 4f658a5..4c5f7e2 100644 --- a/src/gpu/wgsl_effect.cc +++ b/src/gpu/wgsl_effect.cc @@ -13,8 +13,7 @@ WgslEffect::WgslEffect(const GpuContext& ctx, WgslEffectParams initial_params, WgslSamplerType sampler_type) : Effect(ctx, inputs, outputs, start_time, end_time), - effect_params(initial_params), - load_op_(load_op) { + effect_params(initial_params), load_op_(load_op) { HEADLESS_RETURN_IF_NULL(ctx_.device); if (sampler_type == WgslSamplerType::Nearest) @@ -23,9 +22,8 @@ WgslEffect::WgslEffect(const GpuContext& ctx, create_linear_sampler(); params_buffer_.init(ctx_.device); - pipeline_.set(create_post_process_pipeline(ctx_.device, - WGPUTextureFormat_RGBA8Unorm, - shader_code)); + pipeline_.set(create_post_process_pipeline( + ctx_.device, WGPUTextureFormat_RGBA8Unorm, shader_code)); } void WgslEffect::render(WGPUCommandEncoder encoder, diff --git a/src/gpu/wgsl_effect.h b/src/gpu/wgsl_effect.h index f487ef7..49e97c5 100644 --- a/src/gpu/wgsl_effect.h +++ b/src/gpu/wgsl_effect.h @@ -11,12 +11,16 @@ // effect_params.p — 4 generic floats (strength, scale, etc.) // effect_params.c — color or secondary vec4 struct WgslEffectParams { - float p[4]; // vec4: generic float params - float c[4]; // vec4: color / secondary params + float p[4]; // vec4: generic float params + float c[4]; // vec4: color / secondary params }; -static_assert(sizeof(WgslEffectParams) == 32, "WgslEffectParams must be 32 bytes"); +static_assert(sizeof(WgslEffectParams) == 32, + "WgslEffectParams must be 32 bytes"); -enum class WgslSamplerType { Linear, Nearest }; +enum class WgslSamplerType { + Linear, + Nearest +}; class WgslEffect : public Effect { public: |
