forked from juj/wasm_webgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_webgpu.cpp
180 lines (153 loc) · 5.44 KB
/
lib_webgpu.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
#include "lib_webgpu.h"
extern "C"
{
const char *wgpu_compilation_message_type_to_string(WGPU_COMPILATION_MESSAGE_TYPE type)
{
return type == WGPU_COMPILATION_MESSAGE_TYPE_WARNING ? "warning"
: (type == WGPU_COMPILATION_MESSAGE_TYPE_INFO ? "info" : "error");
}
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 = WGPU_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 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 = WGPU_PREDEFINED_COLOR_SPACE_SRGB,
.compositingAlphaMode = WGPU_CANVAS_COMPOSITING_ALPHA_MODE_OPAQUE,
.size = WGPU_EXTENT_3D_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_ALWAYS,
.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 = {
.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 = WGPU_PREDEFINED_COLOR_SPACE_SRGB,
.premultipliedAlpha = EM_FALSE
};
} // ~extern "C"