-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathGPURenderBundleEncoder.h
More file actions
109 lines (92 loc) · 4.11 KB
/
GPURenderBundleEncoder.h
File metadata and controls
109 lines (92 loc) · 4.11 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <memory>
#include <optional>
#include <string>
#include <variant>
#include <vector>
#include "Unions.h"
#include "RNFHybridObject.h"
#include "webgpu/webgpu_cpp.h"
#include "GPUBindGroup.h"
#include "GPUBuffer.h"
#include "GPURenderBundle.h"
#include "GPURenderBundleDescriptor.h"
#include "GPURenderPipeline.h"
namespace rnwgpu {
namespace m = margelo;
class GPURenderBundleEncoder : public m::HybridObject {
public:
explicit GPURenderBundleEncoder(wgpu::RenderBundleEncoder instance,
std::string label)
: HybridObject("GPURenderBundleEncoder"), _instance(instance),
_label(label) {}
public:
std::string getBrand() { return _name; }
std::shared_ptr<GPURenderBundle>
finish(std::optional<std::shared_ptr<GPURenderBundleDescriptor>> descriptor);
void pushDebugGroup(std::string groupLabel);
void popDebugGroup();
void insertDebugMarker(std::string markerLabel);
void setBindGroup(
uint32_t index,
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
std::optional<std::vector<uint32_t>> dynamicOffsets);
void setPipeline(std::shared_ptr<GPURenderPipeline> pipeline);
void setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
wgpu::IndexFormat indexFormat,
std::optional<uint64_t> offset,
std::optional<uint64_t> size);
void setVertexBuffer(
uint32_t slot,
std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
std::optional<uint64_t> offset, std::optional<uint64_t> size);
void draw(uint32_t vertexCount, std::optional<uint32_t> instanceCount,
std::optional<uint32_t> firstVertex,
std::optional<uint32_t> firstInstance);
void drawIndexed(uint32_t indexCount, std::optional<uint32_t> instanceCount,
std::optional<uint32_t> firstIndex,
std::optional<double> baseVertex,
std::optional<uint32_t> firstInstance);
void drawIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
uint64_t indirectOffset);
void drawIndexedIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
uint64_t indirectOffset);
std::string getLabel() { return _label; }
void setLabel(const std::string &label) {
_label = label;
_instance.SetLabel(_label.c_str());
}
void loadHybridMethods() override {
registerHybridGetter("__brand", &GPURenderBundleEncoder::getBrand, this);
registerHybridMethod("finish", &GPURenderBundleEncoder::finish, this);
registerHybridMethod("pushDebugGroup",
&GPURenderBundleEncoder::pushDebugGroup, this);
registerHybridMethod("popDebugGroup",
&GPURenderBundleEncoder::popDebugGroup, this);
registerHybridMethod("insertDebugMarker",
&GPURenderBundleEncoder::insertDebugMarker, this);
registerHybridMethod("setBindGroup", &GPURenderBundleEncoder::setBindGroup,
this);
registerHybridMethod("setPipeline", &GPURenderBundleEncoder::setPipeline,
this);
registerHybridMethod("setIndexBuffer",
&GPURenderBundleEncoder::setIndexBuffer, this);
registerHybridMethod("setVertexBuffer",
&GPURenderBundleEncoder::setVertexBuffer, this);
registerHybridMethod("draw", &GPURenderBundleEncoder::draw, this);
registerHybridMethod("drawIndexed", &GPURenderBundleEncoder::drawIndexed,
this);
registerHybridMethod("drawIndirect", &GPURenderBundleEncoder::drawIndirect,
this);
registerHybridMethod("drawIndexedIndirect",
&GPURenderBundleEncoder::drawIndexedIndirect, this);
registerHybridGetter("label", &GPURenderBundleEncoder::getLabel, this);
registerHybridSetter("label", &GPURenderBundleEncoder::setLabel, this);
}
inline const wgpu::RenderBundleEncoder get() { return _instance; }
size_t getMemoryPressure() override { return 1024 * 1024; }
private:
wgpu::RenderBundleEncoder _instance;
std::string _label;
};
} // namespace rnwgpu