Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_pass.hpp File Reference

Typed custom GPU passes on Pulp's shared Dawn device. More...

#include <pulp/render/gpu_capabilities.hpp>
#include <pulp/render/gpu_surface.hpp>
#include <pulp/render/wgsl_diagnostics.hpp>
#include <pulp/runtime/result.hpp>
#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

Go to the source code of this file.

Classes

struct  pulp::render::GpuError
struct  pulp::render::GpuTextureDesc
class  pulp::render::GpuTexture
struct  pulp::render::GpuBufferDesc
class  pulp::render::GpuBuffer
struct  pulp::render::GpuSamplerDesc
class  pulp::render::GpuSampler
class  pulp::render::GpuShaderModule
 A compiled WGSL module. More...
struct  pulp::render::GpuVertexAttribute
struct  pulp::render::GpuVertexBufferLayout
struct  pulp::render::GpuColorTargetDesc
struct  pulp::render::GpuDepthStateDesc
struct  pulp::render::GpuRenderPipelineDesc
class  pulp::render::GpuRenderPipeline
struct  pulp::render::GpuComputePipelineDesc
class  pulp::render::GpuComputePipeline
struct  pulp::render::GpuBinding
 One entry of a bind group: a buffer range, a texture or a sampler. More...
class  pulp::render::GpuBindGroup
struct  pulp::render::GpuTargetDesc
struct  pulp::render::GpuPixels
 Tightly packed pixels read back from a target, rows top to bottom. More...
class  pulp::render::GpuTarget
 Offscreen color target (and optional depth) with CPU readback. More...
class  pulp::render::GpuDevice
 Typed handle to the device a GpuSurface owns. Copies share it. More...
struct  pulp::render::GpuColorAttachment
struct  pulp::render::GpuRenderPassDesc
class  pulp::render::GpuRenderPass
 An open render pass. More...
class  pulp::render::GpuComputePass
 An open compute pass. Same rules as GpuRenderPass. More...
class  pulp::render::GpuSubmission
 Completion of one submitted frame. More...
class  pulp::render::GpuFrame
 One command encoder's worth of passes, submitted once. More...

Namespaces

namespace  pulp
namespace  pulp::canvas
namespace  pulp::render
namespace  pulp::render::detail

Typedefs

template<typename T>
using pulp::render::GpuResult = runtime::Result<T, GpuError>
using pulp::render::GpuStatus = runtime::Result<void, GpuError>
 Success is a default-constructed value.

Enumerations

enum class  pulp::render::GpuTextureUsage : std::uint32_t {
  pulp::render::none = 0 , pulp::render::copy_src = 1u << 0 , pulp::render::copy_dst = 1u << 1 , pulp::render::sampled = 1u << 2 ,
  pulp::render::storage = 1u << 3 , pulp::render::render_target = 1u << 4
}
 Texture usage bits. Values match WebGPU's GPUTextureUsage. More...
enum class  pulp::render::GpuBufferUsage : std::uint32_t {
  pulp::render::none = 0 , pulp::render::map_read = 1u << 0 , pulp::render::map_write = 1u << 1 , pulp::render::copy_src = 1u << 2 ,
  pulp::render::copy_dst = 1u << 3 , pulp::render::index = 1u << 4 , pulp::render::vertex = 1u << 5 , pulp::render::uniform = 1u << 6 ,
  pulp::render::storage = 1u << 7
}
 Buffer usage bits. Values match WebGPU's GPUBufferUsage. More...
enum class  pulp::render::GpuVertexFormat : std::uint8_t {
  pulp::render::float32 , pulp::render::float32x2 , pulp::render::float32x3 , pulp::render::float32x4 ,
  pulp::render::uint32 , pulp::render::sint32 , pulp::render::unorm8x4
}
enum class  pulp::render::GpuBlend : std::uint8_t { pulp::render::replace , pulp::render::alpha , pulp::render::premultiplied , pulp::render::additive }
enum class  pulp::render::GpuPrimitiveTopology : std::uint8_t {
  pulp::render::triangle_list , pulp::render::triangle_strip , pulp::render::line_list , pulp::render::line_strip ,
  pulp::render::point_list
}
enum class  pulp::render::GpuCullMode : std::uint8_t { pulp::render::none , pulp::render::front , pulp::render::back }
enum class  pulp::render::GpuCompare : std::uint8_t {
  pulp::render::never , pulp::render::less , pulp::render::less_equal , pulp::render::greater ,
  pulp::render::greater_equal , pulp::render::equal , pulp::render::not_equal , pulp::render::always
}
enum class  pulp::render::GpuSubmissionStatus : std::uint8_t { pulp::render::pending , pulp::render::succeeded , pulp::render::failed }

Functions

std::string_view pulp::render::gpu_error_kind_name (GpuError::Kind kind)
constexpr GpuTextureUsage pulp::render::operator| (GpuTextureUsage a, GpuTextureUsage b)
constexpr bool pulp::render::has_usage (GpuTextureUsage set, GpuTextureUsage bit)
constexpr GpuBufferUsage pulp::render::operator| (GpuBufferUsage a, GpuBufferUsage b)
constexpr bool pulp::render::has_usage (GpuBufferUsage set, GpuBufferUsage bit)
GpuStatus pulp::render::draw_gpu_texture (canvas::Canvas &canvas, const GpuTexture &texture, float x, float y, float w, float h)
 Draw texture into the canvas rectangle (x, y, w, h).

Detailed Description

Typed custom GPU passes on Pulp's shared Dawn device.

A View that needs its own WGSL draws records render or compute passes on the same wgpu::Device Skia Graphite draws the UI with, then composites the result through the canvas:

auto device = GpuDevice::from_surface(*host.gpu_surface()); // once auto shader = device->create_shader_module(kMyWgsl, "glow"); // once auto pipeline = device->create_render_pipeline({...}); // once auto target = device->create_target({.width = w, .height = h});

// per frame, inside View::paint(): { GpuFrame frame(*device, "glow"); auto pass = frame.render_pass(GpuRenderPassDesc::for_target(*target, {0, 0, 0, 1})); pass.set_pipeline(*pipeline); pass.draw(3); pass.end(); frame.submit(); } draw_gpu_texture(canvas, target->color(), 0, 0, w, h);

The header names no Dawn type. Every object is a reference-counted handle to state that lives in the implementation; copies share it.

Ownership and ordering rules (all load-bearing):

  • GpuSurface owns the Dawn instance, device and queue. A GpuDevice and every object created from it must be released before that surface is destroyed: the native instance does not outlive its surface, so a later call is a use-after-free in Dawn, not an error.
  • Pulp never touches Skia Graphite's command encoders or the swapchain texture. A GpuFrame records into its own encoder and submits to the shared queue. Submit it before drawing its output: the queue runs submissions in order, and Graphite submits the UI frame only when the canvas frame ends, after paint() returns.
  • All device work here runs under WebGPU error scopes, so a mistake in a custom pass comes back as a GpuError instead of reaching the device's uncaptured-error callback, which other device users (the GPU-audio provider, for one) treat as poisoning their own work.
  • Single-threaded: create, record and submit on one thread, normally the UI thread that paints.
  • Pipelines use WebGPU's automatic (layout: auto) bind group layouts; GpuDevice::create_bind_group() reads group N's layout from the pipeline.
  • Device loss is reported, not hidden: every call checks the device's lost state and fails with GpuError::Kind::device_lost. Recreate the GpuDevice from the new surface after the host rebuilds it.