forked from juj/wasm_webgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_webgpu_cpp20.cpp
219 lines (185 loc) · 6.61 KB
/
lib_webgpu_cpp20.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "lib_webgpu.h"
// Default initializers for WebGPU descriptors, using C++11 standard.
// Only add either this file or lib_webgpu_cpp11.cpp to your project, but not both.
#ifdef __cplusplus
extern "C" {
#endif
const WGpuRequestAdapterOptions WGPU_REQUEST_ADAPTER_OPTIONS_DEFAULT_INITIALIZER = {
};
const WGpuDeviceDescriptor WGPU_DEVICE_DESCRIPTOR_DEFAULT_INITIALIZER = {
};
const WGpuTextureDescriptor WGPU_TEXTURE_DESCRIPTOR_DEFAULT_INITIALIZER = {
.height = 1,
.depthOrArrayLayers = 1,
.mipLevelCount = 1,
.sampleCount = 1,
.dimension = WGPU_TEXTURE_DIMENSION_2D
};
const WGpuTextureViewDescriptor WGPU_TEXTURE_VIEW_DESCRIPTOR_DEFAULT_INITIALIZER = {
.aspect = WGPU_TEXTURE_ASPECT_ALL,
.baseMipLevel = 0,
.baseArrayLayer = 0
};
const WGpuExternalTextureDescriptor WGPU_EXTERNAL_TEXTURE_DESCRIPTOR_DEFAULT_INITIALIZER = {
.colorSpace = HTML_PREDEFINED_COLOR_SPACE_SRGB
};
const WGpuSamplerDescriptor WGPU_SAMPLER_DESCRIPTOR_DEFAULT_INITIALIZER = {
.addressModeU = WGPU_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeV = WGPU_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeW = WGPU_ADDRESS_MODE_CLAMP_TO_EDGE,
.magFilter = WGPU_FILTER_MODE_NEAREST,
.minFilter = WGPU_FILTER_MODE_NEAREST,
.mipmapFilter = WGPU_MIPMAP_FILTER_MODE_NEAREST,
.lodMinClamp = 0,
.lodMaxClamp = 32,
.maxAnisotropy = 1
};
const WGpuBindGroupLayoutEntry WGPU_BUFFER_BINDING_LAYOUT_ENTRY_DEFAULT_INITIALIZER = {
};
const WGpuBufferBindingLayout WGPU_BUFFER_BINDING_LAYOUT_DEFAULT_INITIALIZER = {
.type = WGPU_BUFFER_BINDING_TYPE_UNIFORM,
.hasDynamicOffset = EM_FALSE,
.minBindingSize = 0
};
const WGpuSamplerBindingLayout WGPU_SAMPLER_BINDING_LAYOUT_DEFAULT_INITIALIZER = {
.type = WGPU_SAMPLER_BINDING_TYPE_FILTERING
};
const WGpuTextureBindingLayout WGPU_TEXTURE_BINDING_LAYOUT_DEFAULT_INITIALIZER = {
.sampleType = WGPU_TEXTURE_SAMPLE_TYPE_FLOAT,
.viewDimension = WGPU_TEXTURE_VIEW_DIMENSION_2D,
};
const WGpuBindGroupEntry WGPU_BIND_GROUP_ENTRY_DEFAULT_INITIALIZER = {
};
const WGpuShaderModuleCompilationHint WGPU_SHADER_MODULE_COMPILATION_HINT_DEFAULT_INITIALIZER = {
};
const WGpuCommandEncoderDescriptor WGPU_COMMAND_ENCODER_DESCRIPTOR_DEFAULT_INITIALIZER = {
};
const WGpuImageCopyBuffer WGPU_IMAGE_COPY_BUFFER_DEFAULT_INITIALIZER = {};
const WGpuComputePassTimestampWrites WGPU_COMPUTE_PASS_TIMESTAMP_WRITES_DEFAULT_INITIALIZER = {
.querySet = 0,
.beginningOfPassWriteIndex = -1,
.endOfPassWriteIndex = -1
};
const WGpuComputePassDescriptor WGPU_COMPUTE_PASS_DESCRIPTOR_DEFAULT_INITIALIZER = {
.timestampWrites = WGPU_COMPUTE_PASS_TIMESTAMP_WRITES_DEFAULT_INITIALIZER
};
const WGpuRenderPassDepthStencilAttachment WGPU_RENDER_PASS_DEPTH_STENCIL_ATTACHMENT_DEFAULT_INITIALIZER = {
.view = 0,
.depthLoadOp = WGPU_LOAD_OP_LOAD,
.depthClearValue = WGPU_NAN,
.depthStoreOp = WGPU_STORE_OP_UNDEFINED,
.depthReadOnly = false,
.stencilLoadOp = WGPU_LOAD_OP_LOAD,
.stencilClearValue = 0,
.stencilStoreOp = WGPU_STORE_OP_UNDEFINED,
.stencilReadOnly = false
};
const WGpuStorageTextureBindingLayout WGPU_STORAGE_TEXTURE_BINDING_LAYOUT_DEFAULT_INITIALIZER = {
.access = WGPU_STORAGE_TEXTURE_ACCESS_WRITE_ONLY,
.viewDimension = WGPU_TEXTURE_VIEW_DIMENSION_2D
};
const WGpuCanvasConfiguration WGPU_CANVAS_CONFIGURATION_DEFAULT_INITIALIZER = {
.usage = WGPU_TEXTURE_USAGE_RENDER_ATTACHMENT,
.colorSpace = HTML_PREDEFINED_COLOR_SPACE_SRGB,
.alphaMode = WGPU_CANVAS_ALPHA_MODE_OPAQUE,
};
const WGpuRenderPassTimestampWrites WGPU_RENDER_PASS_TIMESTAMP_WRITES_DEFAULT_INITIALIZER = {
.querySet = 0,
.beginningOfPassWriteIndex = -1,
.endOfPassWriteIndex = -1
};
const WGpuRenderPassDescriptor WGPU_RENDER_PASS_DESCRIPTOR_DEFAULT_INITIALIZER = {
.numColorAttachments = 0,
.colorAttachments = 0,
.depthStencilAttachment = WGPU_RENDER_PASS_DEPTH_STENCIL_ATTACHMENT_DEFAULT_INITIALIZER,
.occlusionQuerySet = 0,
.maxDrawCount = 0,
.timestampWrites = WGPU_RENDER_PASS_TIMESTAMP_WRITES_DEFAULT_INITIALIZER
};
const WGpuColorTargetState WGPU_COLOR_TARGET_STATE_DEFAULT_INITIALIZER = {
.blend = (WGpuBlendState) {
.color = (WGpuBlendComponent) {
.operation = WGPU_BLEND_OPERATION_DISABLED, // Color blending is disabled by default. Set to WGPU_BLEND_OPERATION_ADD to enable.
.srcFactor = WGPU_BLEND_FACTOR_SRC,
.dstFactor = WGPU_BLEND_FACTOR_ONE_MINUS_SRC
},
.alpha = (WGpuBlendComponent) {
.operation = WGPU_BLEND_OPERATION_ADD, // If blending is enabled, default to copying src alpha. (no blend in alpha value)
.srcFactor = WGPU_BLEND_FACTOR_ONE,
.dstFactor = WGPU_BLEND_FACTOR_ZERO
},
},
.writeMask = WGPU_COLOR_WRITE_ALL
};
const WGpuRenderPipelineDescriptor WGPU_RENDER_PIPELINE_DESCRIPTOR_DEFAULT_INITIALIZER = {
.primitive = (WGpuPrimitiveState) {
.topology = WGPU_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.frontFace = WGPU_FRONT_FACE_CCW,
.cullMode = WGPU_CULL_MODE_NONE
},
.depthStencil = (WGpuDepthStencilState) {
.depthCompare = WGPU_COMPARE_FUNCTION_INVALID,
.stencilReadMask = 0xFFFFFFFFu,
.stencilWriteMask = 0xFFFFFFFFu,
.stencilFront = (WGpuStencilFaceState) {
.compare = WGPU_COMPARE_FUNCTION_ALWAYS,
.failOp = WGPU_STENCIL_OPERATION_KEEP,
.depthFailOp = WGPU_STENCIL_OPERATION_KEEP,
.passOp = WGPU_STENCIL_OPERATION_KEEP
},
.stencilBack = (WGpuStencilFaceState) {
.compare = WGPU_COMPARE_FUNCTION_ALWAYS,
.failOp = WGPU_STENCIL_OPERATION_KEEP,
.depthFailOp = WGPU_STENCIL_OPERATION_KEEP,
.passOp = WGPU_STENCIL_OPERATION_KEEP
},
},
.multisample = (WGpuMultisampleState) {
.count = 1,
.mask = 0xFFFFFFFFu,
},
};
extern const WGpuExtent3D WGPU_EXTENT_3D_DEFAULT_INITIALIZER = {
.height = 1,
.depthOrArrayLayers = 1
};
extern const WGpuRenderPassColorAttachment WGPU_RENDER_PASS_COLOR_ATTACHMENT_DEFAULT_INITIALIZER = {
.depthSlice = -1,
.storeOp = WGPU_STORE_OP_STORE,
.loadOp = WGPU_LOAD_OP_LOAD,
.clearValue = (WGpuColor) {
.r = 0.0,
.g = 0.0,
.b = 0.0,
.a = 1.0,
}
};
extern const WGpuImageCopyExternalImage WGPU_IMAGE_COPY_EXTERNAL_IMAGE_DEFAULT_INITIALIZER = {
.origin = (WGpuOrigin2D) {
.x = 0,
.y = 0
}
};
extern const WGpuImageCopyTexture WGPU_IMAGE_COPY_TEXTURE_DEFAULT_INITIALIZER = {
.mipLevel = 0,
.origin = (WGpuOrigin3D) {
.x = 0,
.y = 0,
.z = 0
},
.aspect = WGPU_TEXTURE_ASPECT_ALL
};
extern const WGpuImageCopyTextureTagged WGPU_IMAGE_COPY_TEXTURE_TAGGED_DEFAULT_INITIALIZER = {
.mipLevel = 0,
.origin = (WGpuOrigin3D) {
.x = 0,
.y = 0,
.z = 0
},
.aspect = WGPU_TEXTURE_ASPECT_ALL,
.colorSpace = HTML_PREDEFINED_COLOR_SPACE_SRGB,
.premultipliedAlpha = EM_FALSE
};
#ifdef __cplusplus
} // ~extern "C"
#endif