载入中...
搜索中...
未找到
WebGpuGpgpu.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
5#include "gpgpu/GpuBuffer.h"
6#include "gpgpu/Sequence.h"
7
8#include <webgpu/webgpu_cpp.h>
9
10#include <array>
11#include <cstdint>
12#include <string>
13
14namespace eve::gpgpu {
15
16class WebGpuGpuBuffer;
17class WebGpuSequence;
18
24public:
29
31 void bindBuffer(int binding, GpuBuffer *buffer) override;
33 GpuBuffer *getBoundBuffer(int binding) const override;
34
36 void setFloat(int index, float value) override;
38 float getFloat(int index) const override;
39
41 void clearBindings() override;
42
43 wgpu::ComputePipeline pipeline;
44 wgpu::PipelineLayout pipelineLayout;
45 wgpu::BindGroupLayout setLayout;
46 wgpu::Buffer pushUbo;
47 bool ready = false;
48
49private:
50 std::array<GpuBuffer *, kMaxBindings> bindings_{};
51};
52
55public:
57 WebGpuGpuBuffer() = default;
59 ~WebGpuGpuBuffer() override;
60
62 int getSize() const override { return int(size_); }
64 std::string getUsage() const override { return usage_; }
65
67 void writeData(data::ByteData *data, int dstOffset = 0) override;
69 data::ByteData *readData(int srcOffset = 0, int size = -1) override;
70
72 void writeFloat32(int floatIndex, float value) override;
74 float readFloat32(int floatIndex) override;
76 void fillFloat32(float value) override;
77
79 void writeFloat32s(const float *data, int count, int startIndex = 0) override;
81 void readFloat32s(float *out, int count, int startIndex = 0) const override;
82
84 void uploadBytes(const void *src, uint64_t nbytes, uint64_t dstOffset = 0) override;
86 void downloadBytes(void *dst, uint64_t nbytes, uint64_t srcOffset = 0) const override;
88 GpuResidentBufferView residentView() const override;
89
90 wgpu::Buffer buffer;
91 uint64_t size_ = 0;
92 std::string usage_;
93};
94
95// Backend entry points (mirror gpgpu/vulkan/VulkanGpgpu.h).
97bool webgpuGpgpuReady();
101EVENGINE_API_WORLD WebGpuComputeShader *webgpuNewShaderFromSpirv(const std::vector<uint32_t> &spv);
103EVENGINE_API_WORLD WebGpuGpuBuffer *webgpuNewBuffer(int byteSize, const std::string &usage);
105EVENGINE_API_WORLD void webgpuDispatch(ComputeShader *shader, int groupsX, int groupsY, int groupsZ);
116 uint64_t nbytes, uint64_t dstOffset);
119 uint64_t nbytes, uint64_t srcOffset);
122 int groupsY, int groupsZ);
133
134} // namespace eve::gpgpu
std::string usage
#define EVENGINE_API_WORLD
Definition Export.h:109
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
eve::action::ActionVfxBinding binding
Object::Ptr value
Shader * shader
ScriptStructure out
int count
float size
Definition TreeMesh.cpp:158
uint32_t index
In-memory byte buffer implementing eve::Data (ref-counted).
Definition ByteData.h:13
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:20
Compute program for the WebGPU backend. Accepts WGSL source; GLSL/SPIR-V input is rejected (browsers ...
Definition WebGpuGpgpu.h:23
wgpu::BindGroupLayout setLayout
Definition WebGpuGpgpu.h:45
wgpu::PipelineLayout pipelineLayout
Definition WebGpuGpgpu.h:44
WebGpuComputeShader()=default
Constructs a WebGpuComputeShader.
wgpu::ComputePipeline pipeline
Definition WebGpuGpgpu.h:43
~WebGpuComputeShader() override
Releases WebGpuComputeShader resources.
Storage / staging buffer for the WebGPU backend.
Definition WebGpuGpgpu.h:54
WebGpuGpuBuffer()=default
Constructs a WebGpuGpuBuffer.
~WebGpuGpuBuffer() override
Releases WebGpuGpuBuffer resources.
std::string getUsage() const override
Returns the usage.
Definition WebGpuGpgpu.h:64
int getSize() const override
Byte length of the owned buffer.
Definition WebGpuGpgpu.h:62
Fluids module — interactive surface fluid simulation.
Definition Fluids.h:35
SequenceStatus
Observable lifecycle state of a reusable GPU command sequence.
Definition Sequence.h:14
void webgpuSequenceRecordDownload(WebGpuSequence *sequence, GpuBuffer *src, GpuBuffer *staging, uint64_t nbytes, uint64_t srcOffset)
Webgpu sequence record download.
bool webgpuSequenceReady(WebGpuSequence *sequence)
Webgpu sequence ready.
SequenceStatus webgpuSequencePoll(WebGpuSequence *sequence)
Webgpu sequence poll.
WebGpuGpuBuffer * webgpuNewBuffer(int byteSize, const std::string &usage)
Webgpu new buffer.
void webgpuSequenceBegin(WebGpuSequence *sequence)
Webgpu sequence begin.
bool webgpuGpgpuReady()
Webgpu gpgpu ready.
void webgpuSequenceDestroy(WebGpuSequence *sequence)
Webgpu sequence destroy.
WebGpuComputeShader * webgpuNewShaderFromSpirv(const std::vector< uint32_t > &spv)
Webgpu new shader from spirv.
SequenceStatus webgpuSequenceWait(WebGpuSequence *sequence)
Webgpu sequence wait.
WebGpuComputeShader * webgpuNewShaderFromWgsl(const std::string &wgsl)
Webgpu new shader from wgsl.
SequenceStatus webgpuSequenceStatus(const WebGpuSequence *sequence)
Webgpu sequence status.
void webgpuDispatch(ComputeShader *shader, int groupsX, int groupsY, int groupsZ)
Webgpu dispatch.
void webgpuSequenceRecordDispatch(WebGpuSequence *sequence, ComputeShader *shader, int groupsX, int groupsY, int groupsZ)
Webgpu sequence record dispatch.
WebGpuSequence * webgpuSequenceCreate()
Webgpu sequence create.
void webgpuSequenceRecordUpload(WebGpuSequence *sequence, GpuBuffer *dst, const void *src, uint64_t nbytes, uint64_t dstOffset)
Webgpu sequence record upload.
SequenceStatus webgpuSequenceSubmitAsync(WebGpuSequence *sequence)
Webgpu sequence submit async.
void webgpuSequenceSubmit(WebGpuSequence *sequence)
Webgpu sequence submit.
Transient backend buffer slice shared between sibling GPU modules. @ownership Non-owning; nativeHandl...