glre 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1017 -29
- package/dist/addons.d.ts +3 -2
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +27 -26
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +8 -5
- package/dist/node.cjs +42 -42
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +3 -2
- package/dist/node.js +13 -13
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +27 -26
- package/dist/solid.d.ts +27 -26
- package/package.json +1 -1
- package/src/helpers.ts +2 -2
- package/src/index.ts +5 -3
- package/src/node/types.ts +0 -2
- package/src/node/utils/infer.ts +11 -12
- package/src/node/utils/parse.ts +5 -5
- package/src/types.ts +6 -4
- package/src/webgl/compute.ts +4 -4
- package/src/webgl/graphic.ts +6 -6
- package/src/webgpu/compute.ts +5 -5
- package/src/webgpu/graphic.ts +15 -27
- package/src/webgpu/index.ts +36 -17
- package/src/webgpu/utils.ts +23 -27
package/src/webgpu/utils.ts
CHANGED
|
@@ -104,15 +104,15 @@ const createBindGroup = (device: GPUDevice, uniforms: IUniforms, textures: IText
|
|
|
104
104
|
layouts.push(layout)
|
|
105
105
|
bindings.push(binding)
|
|
106
106
|
}
|
|
107
|
-
for (const { binding, buffer, group
|
|
108
|
-
add(
|
|
107
|
+
for (const { binding, buffer, group } of uniforms) {
|
|
108
|
+
add(group, { binding, visibility: 7, buffer: { type: 'uniform' } }, { binding, resource: { buffer } })
|
|
109
109
|
}
|
|
110
|
-
for (const { binding, buffer, group
|
|
111
|
-
add(
|
|
110
|
+
for (const { binding, buffer, group } of storages) {
|
|
111
|
+
add(group, { binding, visibility: 6, buffer: { type: 'storage' } }, { binding, resource: { buffer } })
|
|
112
112
|
}
|
|
113
|
-
for (const { binding: b, group
|
|
114
|
-
add(
|
|
115
|
-
add(
|
|
113
|
+
for (const { binding: b, group, sampler, view } of textures) {
|
|
114
|
+
add(group, { binding: b, visibility: 2, sampler: {} }, { binding: b, resource: sampler })
|
|
115
|
+
add(group, { binding: b + 1, visibility: 2, texture: {} }, { binding: b + 1, resource: view })
|
|
116
116
|
}
|
|
117
117
|
for (const [i, { layouts, bindings }] of groups) {
|
|
118
118
|
ret.bindGroupLayouts[i] = device.createBindGroupLayout({ entries: layouts })
|
|
@@ -121,8 +121,10 @@ const createBindGroup = (device: GPUDevice, uniforms: IUniforms, textures: IText
|
|
|
121
121
|
return ret
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const createPipeline = (device: GPUDevice, format: GPUTextureFormat, bufferLayouts: GPUVertexBufferLayout[], bindGroupLayouts: GPUBindGroupLayout[], vs: string, fs: string) => {
|
|
125
|
-
|
|
124
|
+
const createPipeline = (device: GPUDevice, format: GPUTextureFormat, bufferLayouts: GPUVertexBufferLayout[], bindGroupLayouts: GPUBindGroupLayout[], vs: string, fs: string, isDepth: boolean) => {
|
|
125
|
+
const config: GPURenderPipelineDescriptor = {
|
|
126
|
+
primitive: { topology: 'triangle-list' },
|
|
127
|
+
layout: device.createPipelineLayout({ bindGroupLayouts }),
|
|
126
128
|
vertex: {
|
|
127
129
|
module: device.createShaderModule({ label: 'vert', code: vs.trim() }),
|
|
128
130
|
entryPoint: 'main',
|
|
@@ -133,14 +135,9 @@ const createPipeline = (device: GPUDevice, format: GPUTextureFormat, bufferLayou
|
|
|
133
135
|
entryPoint: 'main',
|
|
134
136
|
targets: [{ format }],
|
|
135
137
|
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
depthWriteEnabled: true,
|
|
140
|
-
depthCompare: 'less',
|
|
141
|
-
format: 'depth24plus',
|
|
142
|
-
},
|
|
143
|
-
})
|
|
138
|
+
}
|
|
139
|
+
if (isDepth) config.depthStencil = { depthWriteEnabled: true, depthCompare: 'less', format: 'depth24plus' }
|
|
140
|
+
return device.createRenderPipeline(config)
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
const createComputePipeline = (device: GPUDevice, bindGroupLayouts: GPUBindGroupLayout[], cs: string) => {
|
|
@@ -154,11 +151,11 @@ const createComputePipeline = (device: GPUDevice, bindGroupLayouts: GPUBindGroup
|
|
|
154
151
|
})
|
|
155
152
|
}
|
|
156
153
|
|
|
157
|
-
export const updatePipeline = (device: GPUDevice, format: GPUTextureFormat, attribs: IAttribs, uniforms: IUniforms, textures: ITextures, storages: IStorages, fs: string, cs: string, vs: string) => {
|
|
154
|
+
export const updatePipeline = (device: GPUDevice, format: GPUTextureFormat, attribs: IAttribs, uniforms: IUniforms, textures: ITextures, storages: IStorages, fs: string, cs: string, vs: string, isDepth: boolean) => {
|
|
158
155
|
const { vertexBuffers, bufferLayouts } = createVertexBuffers(attribs)
|
|
159
156
|
const { bindGroups, bindGroupLayouts } = createBindGroup(device, uniforms, textures, storages)
|
|
160
157
|
const computePipeline = createComputePipeline(device, bindGroupLayouts, cs)
|
|
161
|
-
const graphicPipeline = createPipeline(device, format, bufferLayouts, bindGroupLayouts, vs, fs)
|
|
158
|
+
const graphicPipeline = createPipeline(device, format, bufferLayouts, bindGroupLayouts, vs, fs, isDepth)
|
|
162
159
|
return { bindGroups, vertexBuffers, computePipeline, graphicPipeline }
|
|
163
160
|
}
|
|
164
161
|
|
|
@@ -166,9 +163,9 @@ export const updatePipeline = (device: GPUDevice, format: GPUTextureFormat, attr
|
|
|
166
163
|
* buffers
|
|
167
164
|
*/
|
|
168
165
|
const bufferUsage = (type: 'uniform' | 'storage' | 'attrib') => {
|
|
169
|
-
if (type === 'uniform') return 72 // GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
170
|
-
if (type === 'attrib') return 40 // GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
171
|
-
return 140 // GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST
|
|
166
|
+
if (type === 'uniform') return 72 // 72 is GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
167
|
+
if (type === 'attrib') return 40 // 40 is GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
168
|
+
return 140 // 140 is GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST
|
|
172
169
|
}
|
|
173
170
|
|
|
174
171
|
export const createBuffer = (device: GPUDevice, array: number[] | Float32Array, type: 'uniform' | 'storage' | 'attrib') => {
|
|
@@ -184,11 +181,10 @@ export const updateBuffer = (device: GPUDevice, value: number[] | Float32Array,
|
|
|
184
181
|
device.queue.writeBuffer(buffer, 0, array as GPUAllowSharedBufferSource)
|
|
185
182
|
}
|
|
186
183
|
|
|
187
|
-
export const createDescriptor = (c: GPUCanvasContext, depthTexture
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} as GPURenderPassDescriptor
|
|
184
|
+
export const createDescriptor = (c: GPUCanvasContext, depthTexture?: GPUTexture) => {
|
|
185
|
+
const ret: GPURenderPassDescriptor = { colorAttachments: [{ view: c.getCurrentTexture().createView(), clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: 'clear', storeOp: 'store' }] }
|
|
186
|
+
if (depthTexture) ret.depthStencilAttachment = { view: depthTexture.createView(), depthClearValue: 1.0, depthLoadOp: 'clear', depthStoreOp: 'store' }
|
|
187
|
+
return ret
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
/**
|