-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathGPUShaderModule.h
More file actions
65 lines (47 loc) · 1.72 KB
/
Copy pathGPUShaderModule.h
File metadata and controls
65 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <future>
#include <memory>
#include <string>
#include "Unions.h"
#include "RNFHybridObject.h"
#include "AsyncRunner.h"
#include "webgpu/webgpu_cpp.h"
#include "GPUCompilationInfo.h"
namespace rnwgpu {
namespace m = margelo;
class GPUShaderModule : public m::HybridObject {
public:
explicit GPUShaderModule(wgpu::ShaderModule instance,
std::shared_ptr<AsyncRunner> async,
std::string label)
: HybridObject("GPUShaderModule"), _instance(instance), _async(async),
_label(label) {}
public:
std::string getBrand() { return _name; }
std::future<std::shared_ptr<GPUCompilationInfo>> getCompilationInfo();
std::string getLabel() { return _label; }
void setLabel(const std::string &label) {
_label = label;
_instance.SetLabel(_label.c_str());
}
void loadHybridMethods() override {
registerHybridGetter("__brand", &GPUShaderModule::getBrand, this);
registerHybridMethod("getCompilationInfo",
&GPUShaderModule::getCompilationInfo, this);
registerHybridGetter("label", &GPUShaderModule::getLabel, this);
registerHybridSetter("label", &GPUShaderModule::setLabel, this);
}
inline const wgpu::ShaderModule get() { return _instance; }
size_t getMemoryPressure() override {
// Estimate memory usage for compiled shader module
// Shaders can vary widely, but a reasonable estimate is 8-16KB for typical
// shaders Complex shaders (with many uniforms, textures, or computations)
// can be much larger
return 12 * 1024; // 12KB estimate for average shader
}
private:
wgpu::ShaderModule _instance;
std::shared_ptr<AsyncRunner> _async;
std::string _label;
};
} // namespace rnwgpu