载入中...
搜索中...
未找到
ShaderSystem.h
浏览该文件的文档.
1#pragma once
2
4
5#include <cstdint>
6#include <string>
7#include <vector>
8
9namespace eve::gpgpu {
10
11class Gpgpu;
12class GpuBuffer;
13
31public:
33 static constexpr int kDefaultLocalSize = 64;
34
35 ShaderSystem() = default;
37
38 ShaderSystem(const ShaderSystem &) = delete;
40
41 void setGpgpu(Gpgpu *gpu);
42 Gpgpu *getGpgpu() const { return gpu_; }
43
45 void setShaderSource(const std::string &glsl);
46
51 void setShader(ComputeShader *shader, bool takeOwnership = false);
52
53 ComputeShader *getShader() const { return shader_; }
54
55 void setLocalSize(int localSize);
56 int getLocalSize() const { return localSize_; }
57
59 GpuBuffer *ensureBuffer(int binding, int floatCount);
60
61 GpuBuffer *getBuffer(int binding) const;
62
63 void upload(int binding, const float *data, int floatCount);
64 void download(int binding, float *out, int floatCount) const;
65
67 void upload(int binding, const std::vector<float> &data);
68 std::vector<float> download(int binding, int floatCount) const;
69
70 void setFloat(int index, float value);
71 float getFloat(int index) const;
72
77 void dispatch(int entityCount, float dt = 0.f);
78
79 void clearBuffers();
80
81private:
82 Gpgpu *gpu_ = nullptr;
83 ComputeShader *shader_ = nullptr;
84 bool ownsShader_ = false;
85 int localSize_ = kDefaultLocalSize;
86 GpuBuffer *buffers_[kMaxBindings]{};
87 bool ownsBuffer_[kMaxBindings]{};
88};
89
90} // namespace eve::gpgpu
std::string value
Shader * shader
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
static constexpr int kMaxBindings
GPGPU module — compute shaders + storage buffers via the active Graphics backend. Uses the graphics q...
Definition Gpgpu.h:20
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:16
Gpgpu * getGpgpu() const
GpuBuffer * getBuffer(int binding) const
void upload(int binding, const float *data, int floatCount)
GpuBuffer * ensureBuffer(int binding, int floatCount)
void dispatch(int entityCount, float dt=0.f)
static constexpr int kMaxBindings
static constexpr int kDefaultLocalSize
void download(int binding, float *out, int floatCount) const
void setFloat(int index, float value)
float getFloat(int index) const
ShaderSystem & operator=(const ShaderSystem &)=delete
void setShaderSource(const std::string &glsl)
void setLocalSize(int localSize)
void setGpgpu(Gpgpu *gpu)
ShaderSystem(const ShaderSystem &)=delete
ComputeShader * getShader() const
void setShader(ComputeShader *shader, bool takeOwnership=false)