载入中...
搜索中...
未找到
ShaderSystem.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6
7#include <cstdint>
8#include <string>
9#include <vector>
10
11namespace eve::gpgpu {
12
13class Gpgpu;
14class GpuBuffer;
15class Sequence;
16
35public:
36 static constexpr int kMaxBindings = ComputeShader::kMaxBindings;
37 static constexpr int kDefaultLocalSize = 64;
38
40 ShaderSystem() = default;
43
44 ShaderSystem(const ShaderSystem &) = delete;
46
48 void setGpgpu(Gpgpu *gpu);
50 Gpgpu *getGpgpu() const { return gpu_; }
51
54 void setShaderSource(const std::string &glsl);
55
61 void setShader(ComputeShader *shader, bool takeOwnership = false);
62
64 ComputeShader *getShader() const { return shader_; }
65
67 void setLocalSize(int localSize);
69 int getLocalSize() const { return localSize_; }
70
73 GpuBuffer *ensureBuffer(int binding, int floatCount);
74
76 GpuBuffer *getBuffer(int binding) const;
77
84 void attachBuffer(int binding, GpuBuffer *buffer);
85
87 void upload(int binding, const float *data, int floatCount);
89 void download(int binding, float *out, int floatCount) const;
90
92 void uploadRange(int binding, const float *data, int floatCount, int startFloat);
94 void downloadRange(int binding, float *out, int floatCount, int startFloat) const;
95
97 uint64_t getUploadCount() const { return uploadCount_; }
99 uint64_t getDownloadCount() const { return downloadCount_; }
101 uint64_t getDispatchCount() const { return dispatchCount_; }
103 void resetStatistics();
104
107 void upload(int binding, const std::vector<float> &data);
109 std::vector<float> download(int binding, int floatCount) const;
110
112 void setFloat(int index, float value);
114 float getFloat(int index) const;
115
121 void dispatch(int entityCount, float dt = 0.f);
122
127 void recordDispatch(Sequence *sequence, int entityCount, float dt = 0.f);
128
130 void clearBuffers();
131
132private:
133 Gpgpu *gpu_ = nullptr;
134 ComputeShader *shader_ = nullptr;
135 bool ownsShader_ = false;
136 int localSize_ = kDefaultLocalSize;
137 GpuBuffer *buffers_[kMaxBindings]{};
138 bool ownsBuffer_[kMaxBindings]{};
139 uint64_t uploadCount_ = 0;
140 mutable uint64_t downloadCount_ = 0;
141 uint64_t dispatchCount_ = 0;
142};
143
144} // namespace eve::gpgpu
double value
#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
Shader * shader
uint32_t index
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
GPGPU module — compute shaders + storage buffers via the active Graphics backend. Uses the graphics q...
Definition Gpgpu.h:23
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:18
EVENGINE_API_WORLD public API.
Definition Sequence.h:41
EVENGINE_API_WORLD public API.
Gpgpu * getGpgpu() const
Returns the gpgpu.
ShaderSystem()=default
Shader system.
uint64_t getDispatchCount() const
Number of compute dispatches issued through this system.
int getLocalSize() const
Returns the local size.
ShaderSystem & operator=(const ShaderSystem &)=delete
ShaderSystem(const ShaderSystem &)=delete
ComputeShader * getShader() const
Returns the shader.
uint64_t getDownloadCount() const
Number of device-to-host downloads issued through this system.
uint64_t getUploadCount() const
Number of host-to-device uploads issued through this system.
Fluids module — interactive surface fluid simulation.
Definition Fluids.h:34