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.
@@ -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: i } of uniforms) {
108
- add(i, { binding, visibility: 7, buffer: { type: 'uniform' } }, { binding, resource: { buffer } })
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: i } of storages) {
111
- add(i, { binding, visibility: 6, buffer: { type: 'storage' } }, { binding, resource: { buffer } })
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: i, sampler, view } of textures) {
114
- add(i, { binding: b, visibility: 2, sampler: {} }, { binding: b, resource: sampler })
115
- add(i, { binding: b + 1, visibility: 2, texture: {} }, { binding: b + 1, resource: view })
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
- return device.createRenderPipeline({
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
- layout: device.createPipelineLayout({ bindGroupLayouts }),
137
- primitive: { topology: 'triangle-list' },
138
- depthStencil: {
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: GPUTexture) => {
188
- return {
189
- colorAttachments: [{ view: c.getCurrentTexture().createView(), clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: 'clear', storeOp: 'store' }],
190
- depthStencilAttachment: { view: depthTexture.createView(), depthClearValue: 1.0, depthLoadOp: 'clear', depthStoreOp: 'store' },
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
  /**