|
Img2Num C++ (Internal Developer Docs) dev
API Documentation
|
Reusable RAII helpers for WebGPU/Dawn compute work. More...
#include "internal/gpu.h"#include "internal/log.h"#include <cstddef>#include <cstdint>#include <cstring>#include <initializer_list>#include <mutex>#include <stdexcept>#include <string>#include <type_traits>#include <unordered_map>#include <vector>#include <webgpu/webgpu_cpp.h>
Include dependency graph for gpu_utils.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Classes | |
| class | gpu::Buffer< T > |
| RAII wrapper around a wgpu::Buffer with compile-time type safety. More... | |
| class | gpu::Texture |
| RAII wrapper around a wgpu::Texture with upload and aligned readback. More... | |
| struct | gpu::BindEntry |
| A single entry for bind-group construction. More... | |
Functions | |
| wgpu::ComputePipeline | gpu::cached_pipeline (const std::string &shader_id, const std::string &label) |
| Get or create a compute pipeline, caching by shader ID. | |
| const void * | gpu::map_and_wait (wgpu::Buffer &buffer, size_t size) |
Block until a MapAsync on buffer completes. | |
| wgpu::BindGroup | gpu::make_bind_group (const wgpu::ComputePipeline &pipeline, uint32_t group_index, const std::vector< BindEntry > &entries) |
| Build a wgpu::BindGroup from a pipeline layout and a list of entries. | |
| void | gpu::encode_pass (wgpu::CommandEncoder &encoder, const wgpu::ComputePipeline &pipeline, const wgpu::BindGroup &bind_group, uint32_t groups_x, uint32_t groups_y=1, uint32_t groups_z=1) |
| Encode a compute pass into an existing command encoder. | |
| void | gpu::dispatch (const wgpu::ComputePipeline &pipeline, const wgpu::BindGroup &bind_group, uint32_t groups_x, uint32_t groups_y=1, uint32_t groups_z=1) |
| Encode, finish, and submit a single compute dispatch. | |
| uint32_t | gpu::workgroup_count (uint32_t total_size, uint32_t workgroup_size=16) |
Compute the number of workgroups needed to cover total_size with workgroups of workgroup_size. | |
Variables | |
| static constexpr uint8_t | gpu::COLOR_SPACE_CIELAB {0} |
| Color space selector constants previously duplicated in each kernel. | |
| static constexpr uint8_t | gpu::COLOR_SPACE_RGB {1} |
Reusable RAII helpers for WebGPU/Dawn compute work.
This layer sits on top of the GPU singleton (gpu.h) and eliminates boilerplate that every compute kernel otherwise duplicates:
All helpers live in the gpu namespace and are internal to the library.
Definition in file gpu_utils.h.
|
inline |
Get or create a compute pipeline, caching by shader ID.
GPU::createPipeline() recreates the shader module and pipeline on every call. This wrapper memoizes the result so that repeated calls with the same shader_id return the cached pipeline instantly.
| shader_id | The embedded shader identifier (e.g. "bilateral_filter_rgb"). |
| label | Debug label for the pipeline. |
Definition at line 62 of file gpu_utils.h.
References gpu::cached_pipeline().
Referenced by gpu::cached_pipeline().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Encode, finish, and submit a single compute dispatch.
Convenience for kernels that only need one pass.
| pipeline | The compute pipeline to run. |
| bind_group | The bind group for this pass. |
| groups_x | Number of workgroups in X. |
| groups_y | Number of workgroups in Y (default 1). |
| groups_z | Number of workgroups in Z (default 1). |
Definition at line 523 of file gpu_utils.h.
References gpu::dispatch(), and gpu::encode_pass().
Referenced by gpu::dispatch().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Encode a compute pass into an existing command encoder.
Use this for multi-pass work (e.g. bilateral filter with color conversion).
| encoder | Existing command encoder to append to. |
| pipeline | The compute pipeline to run. |
| bind_group | The bind group for this pass. |
| groups_x | Number of workgroups in X. |
| groups_y | Number of workgroups in Y (default 1). |
| groups_z | Number of workgroups in Z (default 1). |
Definition at line 502 of file gpu_utils.h.
References gpu::encode_pass().
Referenced by gpu::dispatch(), and gpu::encode_pass().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Build a wgpu::BindGroup from a pipeline layout and a list of entries.
| pipeline | The compute pipeline (used to get the bind group layout). |
| group_index | Which bind group index (usually 0). |
| entries | List of BindEntry objects. |
Definition at line 459 of file gpu_utils.h.
References gpu::make_bind_group().
Referenced by gpu::make_bind_group().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Block until a MapAsync on buffer completes.
Works on both native Dawn and Emscripten (ASYNCIFY). Returns the pointer from GetConstMappedRange.
| buffer | The buffer to map (must have MapRead usage). |
| size | Number of bytes to map. |
| std::runtime_error | if the mapping fails. |
Definition at line 90 of file gpu_utils.h.
References gpu::map_and_wait().
Referenced by gpu::map_and_wait(), gpu::Buffer< T >::read(), and gpu::Texture::read().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Compute the number of workgroups needed to cover total_size with workgroups of workgroup_size.
Equivalent to (total_size + workgroup_size - 1) / workgroup_size.
Definition at line 541 of file gpu_utils.h.
References gpu::workgroup_count().
Referenced by gpu::workgroup_count().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticconstexpr |
Color space selector constants previously duplicated in each kernel.
Definition at line 45 of file gpu_utils.h.
|
staticconstexpr |
Definition at line 46 of file gpu_utils.h.